static inline int get_amv(Mpeg4DecContext *ctx, int n)

{

    MpegEncContext *s = &ctx->m;

    int x, y, mb_v, sum, dx, dy, shift;

    int len     = 1 << (s->f_code + 4);

    const int a = s->sprite_warping_accuracy;



    if (s->workaround_bugs & FF_BUG_AMV)

        len >>= s->quarter_sample;



    if (s->real_sprite_warping_points == 1) {

        if (ctx->divx_version == 500 && ctx->divx_build == 413)

            sum = s->sprite_offset[0][n] / (1 << (a - s->quarter_sample));

        else

            sum = RSHIFT(s->sprite_offset[0][n] << s->quarter_sample, a);

    } else {

        dx    = s->sprite_delta[n][0];

        dy    = s->sprite_delta[n][1];

        shift = ctx->sprite_shift[0];

        if (n)

            dy -= 1 << (shift + a + 1);

        else

            dx -= 1 << (shift + a + 1);

        mb_v = s->sprite_offset[0][n] + dx * s->mb_x * 16 + dy * s->mb_y * 16;



        sum = 0;

        for (y = 0; y < 16; y++) {

            int v;



            v = mb_v + dy * y;

            // FIXME optimize

            for (x = 0; x < 16; x++) {

                sum += v >> shift;

                v   += dx;

            }

        }

        sum = RSHIFT(sum, a + 8 - s->quarter_sample);

    }



    if (sum < -len)

        sum = -len;

    else if (sum >= len)

        sum = len - 1;



    return sum;

}

static inline int get_amv(Mpeg4DecContext *ctx, int n)

{

    MpegEncContext *s = &ctx->m;

    int x, y, mb_v, sum, dx, dy, shift;

    int len     = 1 << (s->f_code + 4);

    const int a = s->sprite_warping_accuracy;



    if (s->workaround_bugs & FF_BUG_AMV)

        len >>= s->quarter_sample;



    if (s->real_sprite_warping_points == 1) {

        if (ctx->divx_version == 500 && ctx->divx_build == 413)

            sum = s->sprite_offset[0][n] / (1 << (a - s->quarter_sample));

        else

            sum = RSHIFT(s->sprite_offset[0][n] << s->quarter_sample, a);

    } else {

        dx    = s->sprite_delta[n][0];

        dy    = s->sprite_delta[n][1];

        shift = ctx->sprite_shift[0];

        if (n)

            dy -= 1 << (shift + a + 1);

        else

            dx -= 1 << (shift + a + 1);

        mb_v = s->sprite_offset[0][n] + dx * s->mb_x * 16 + dy * s->mb_y * 16;



        sum = 0;

        for (y = 0; y < 16; y++) {

            int v;



            v = mb_v + dy * y;

            

            for (x = 0; x < 16; x++) {

                sum += v >> shift;

                v   += dx;

            }

        }

        sum = RSHIFT(sum, a + 8 - s->quarter_sample);

    }



    if (sum < -len)

        sum = -len;

    else if (sum >= len)

        sum = len - 1;



    return sum;

}

            sum = RSHIFT(s->sprite_offset[0][n] << s->quarter_sample, a);
static inline int FUNC_0(Mpeg4DecContext *VAR_0, int VAR_1)

{

    MpegEncContext *s = &VAR_0->m;

    int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8;

    int VAR_9     = 1 << (s->f_code + 4);

    const int VAR_10 = s->sprite_warping_accuracy;



    if (s->workaround_bugs & FF_BUG_AMV)

        VAR_9 >>= s->quarter_sample;



    if (s->real_sprite_warping_points == 1) {

        if (VAR_0->divx_version == 500 && VAR_0->divx_build == 413)

            VAR_5 = s->sprite_offset[0][VAR_1] / (1 << (VAR_10 - s->quarter_sample));

        else

            VAR_5 = RSHIFT(s->sprite_offset[0][VAR_1] << s->quarter_sample, VAR_10);

    } else {

        VAR_6    = s->sprite_delta[VAR_1][0];

        VAR_7    = s->sprite_delta[VAR_1][1];

        VAR_8 = VAR_0->sprite_shift[0];

        if (VAR_1)

            VAR_7 -= 1 << (VAR_8 + VAR_10 + 1);

        else

            VAR_6 -= 1 << (VAR_8 + VAR_10 + 1);

        VAR_4 = s->sprite_offset[0][VAR_1] + VAR_6 * s->mb_x * 16 + VAR_7 * s->mb_y * 16;



        VAR_5 = 0;

        for (VAR_3 = 0; VAR_3 < 16; VAR_3++) {

            int VAR_11;



            VAR_11 = VAR_4 + VAR_7 * VAR_3;

            

            for (VAR_2 = 0; VAR_2 < 16; VAR_2++) {

                VAR_5 += VAR_11 >> VAR_8;

                VAR_11   += VAR_6;

            }

        }

        VAR_5 = RSHIFT(VAR_5, VAR_10 + 8 - s->quarter_sample);

    }



    if (VAR_5 < -VAR_9)

        VAR_5 = -VAR_9;

    else if (VAR_5 >= VAR_9)

        VAR_5 = VAR_9 - 1;



    return VAR_5;

}

static inline int FUNC_0(Mpeg4DecContext *VAR_0, int VAR_1)
{ MpegEncContext *s = &VAR_0->m; int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8; int VAR_9     = 1 << (s->f_code + 4); const int VAR_10 = s->sprite_warping_accuracy; if (s->workaround_bugs & FF_BUG_AMV)
VAR_9 >>= s->quarter_sample; if (s->real_sprite_warping_points == 1) { if (VAR_0->divx_version == 500 && VAR_0->divx_build == 413)
VAR_5 = s->sprite_offset[0][VAR_1] / (1 << (VAR_10 - s->quarter_sample)); else
VAR_5 = RSHIFT(s->sprite_offset[0][VAR_1] << s->quarter_sample, VAR_10); } else { VAR_6    = s->sprite_delta[VAR_1][0]; VAR_7    = s->sprite_delta[VAR_1][1]; VAR_8 = VAR_0->sprite_shift[0]; if (VAR_1)
VAR_7 -= 1 << (VAR_8 + VAR_10 + 1); else
VAR_6 -= 1 << (VAR_8 + VAR_10 + 1); VAR_4 = s->sprite_offset[0][VAR_1] + VAR_6 * s->mb_x * 16 + VAR_7 * s->mb_y * 16; VAR_5 = 0; for (VAR_3 = 0; VAR_3 < 16; VAR_3++) { int VAR_11; VAR_11 = VAR_4 + VAR_7 * VAR_3; for (VAR_2 = 0; VAR_2 < 16; VAR_2++) { VAR_5 += VAR_11 >> VAR_8; VAR_11   += VAR_6; } } VAR_5 = RSHIFT(VAR_5, VAR_10 + 8 - s->quarter_sample); } if (VAR_5 < -VAR_9)
VAR_5 = -VAR_9; else if (VAR_5 >= VAR_9)
VAR_5 = VAR_9 - 1; return VAR_5; }