static inline int svq3_mc_dir(SVQ3Context *s, int size, int mode,

                              int dir, int avg)

{

    int i, j, k, mx, my, dx, dy, x, y;

    const int part_width    = ((size & 5) == 4) ? 4 : 16 >> (size & 1);

    const int part_height   = 16 >> ((unsigned)(size + 1) / 3);

    const int extra_width   = (mode == PREDICT_MODE) ? -16 * 6 : 0;

    const int h_edge_pos    = 6 * (s->h_edge_pos - part_width)  - extra_width;

    const int v_edge_pos    = 6 * (s->v_edge_pos - part_height) - extra_width;



    for (i = 0; i < 16; i += part_height)

        for (j = 0; j < 16; j += part_width) {

            const int b_xy = (4 * s->mb_x + (j >> 2)) +

                             (4 * s->mb_y + (i >> 2)) * s->b_stride;

            int dxy;

            x = 16 * s->mb_x + j;

            y = 16 * s->mb_y + i;

            k = (j >> 2 & 1) + (i >> 1 & 2) +

                (j >> 1 & 4) + (i      & 8);



            if (mode != PREDICT_MODE) {

                svq3_pred_motion(s, k, part_width >> 2, dir, 1, &mx, &my);

            } else {

                mx = s->next_pic->motion_val[0][b_xy][0] << 1;

                my = s->next_pic->motion_val[0][b_xy][1] << 1;



                if (dir == 0) {

                    mx = mx * s->frame_num_offset /

                         s->prev_frame_num_offset + 1 >> 1;

                    my = my * s->frame_num_offset /

                         s->prev_frame_num_offset + 1 >> 1;

                } else {

                    mx = mx * (s->frame_num_offset - s->prev_frame_num_offset) /

                         s->prev_frame_num_offset + 1 >> 1;

                    my = my * (s->frame_num_offset - s->prev_frame_num_offset) /

                         s->prev_frame_num_offset + 1 >> 1;

                }

            }



            /* clip motion vector prediction to frame border */

            mx = av_clip(mx, extra_width - 6 * x, h_edge_pos - 6 * x);

            my = av_clip(my, extra_width - 6 * y, v_edge_pos - 6 * y);



            /* get (optional) motion vector differential */

            if (mode == PREDICT_MODE) {

                dx = dy = 0;

            } else {

                dy = get_interleaved_se_golomb(&s->gb_slice);

                dx = get_interleaved_se_golomb(&s->gb_slice);



                if (dx != (int16_t)dx || dy != (int16_t)dy) {

                    av_log(s->avctx, AV_LOG_ERROR, "invalid MV vlc\n");

                    return -1;

                }

            }



            /* compute motion vector */

            if (mode == THIRDPEL_MODE) {

                int fx, fy;

                mx  = (mx + 1 >> 1) + dx;

                my  = (my + 1 >> 1) + dy;

                fx  = (unsigned)(mx + 0x30000) / 3 - 0x10000;

                fy  = (unsigned)(my + 0x30000) / 3 - 0x10000;

                dxy = (mx - 3 * fx) + 4 * (my - 3 * fy);



                svq3_mc_dir_part(s, x, y, part_width, part_height,

                                 fx, fy, dxy, 1, dir, avg);

                mx += mx;

                my += my;

            } else if (mode == HALFPEL_MODE || mode == PREDICT_MODE) {

                mx  = (unsigned)(mx + 1 + 0x30000) / 3 + dx - 0x10000;

                my  = (unsigned)(my + 1 + 0x30000) / 3 + dy - 0x10000;

                dxy = (mx & 1) + 2 * (my & 1);



                svq3_mc_dir_part(s, x, y, part_width, part_height,

                                 mx >> 1, my >> 1, dxy, 0, dir, avg);

                mx *= 3;

                my *= 3;

            } else {

                mx = (unsigned)(mx + 3 + 0x60000) / 6 + dx - 0x10000;

                my = (unsigned)(my + 3 + 0x60000) / 6 + dy - 0x10000;



                svq3_mc_dir_part(s, x, y, part_width, part_height,

                                 mx, my, 0, 0, dir, avg);

                mx *= 6;

                my *= 6;

            }



            /* update mv_cache */

            if (mode != PREDICT_MODE) {

                int32_t mv = pack16to32(mx, my);



                if (part_height == 8 && i < 8) {

                    AV_WN32A(s->mv_cache[dir][scan8[k] + 1 * 8], mv);



                    if (part_width == 8 && j < 8)

                        AV_WN32A(s->mv_cache[dir][scan8[k] + 1 + 1 * 8], mv);

                }

                if (part_width == 8 && j < 8)

                    AV_WN32A(s->mv_cache[dir][scan8[k] + 1], mv);

                if (part_width == 4 || part_height == 4)

                    AV_WN32A(s->mv_cache[dir][scan8[k]], mv);

            }



            /* write back motion vectors */

            fill_rectangle(s->cur_pic->motion_val[dir][b_xy],

                           part_width >> 2, part_height >> 2, s->b_stride,

                           pack16to32(mx, my), 4);

        }



    return 0;

}

static inline int svq3_mc_dir(SVQ3Context *s, int size, int mode,

                              int dir, int avg)

{

    int i, j, k, mx, my, dx, dy, x, y;

    const int part_width    = ((size & 5) == 4) ? 4 : 16 >> (size & 1);

    const int part_height   = 16 >> ((unsigned)(size + 1) / 3);

    const int extra_width   = (mode == PREDICT_MODE) ? -16 * 6 : 0;

    const int h_edge_pos    = 6 * (s->h_edge_pos - part_width)  - extra_width;

    const int v_edge_pos    = 6 * (s->v_edge_pos - part_height) - extra_width;



    for (i = 0; i < 16; i += part_height)

        for (j = 0; j < 16; j += part_width) {

            const int b_xy = (4 * s->mb_x + (j >> 2)) +

                             (4 * s->mb_y + (i >> 2)) * s->b_stride;

            int dxy;

            x = 16 * s->mb_x + j;

            y = 16 * s->mb_y + i;

            k = (j >> 2 & 1) + (i >> 1 & 2) +

                (j >> 1 & 4) + (i      & 8);



            if (mode != PREDICT_MODE) {

                svq3_pred_motion(s, k, part_width >> 2, dir, 1, &mx, &my);

            } else {

                mx = s->next_pic->motion_val[0][b_xy][0] << 1;

                my = s->next_pic->motion_val[0][b_xy][1] << 1;



                if (dir == 0) {

                    mx = mx * s->frame_num_offset /

                         s->prev_frame_num_offset + 1 >> 1;

                    my = my * s->frame_num_offset /

                         s->prev_frame_num_offset + 1 >> 1;

                } else {

                    mx = mx * (s->frame_num_offset - s->prev_frame_num_offset) /

                         s->prev_frame_num_offset + 1 >> 1;

                    my = my * (s->frame_num_offset - s->prev_frame_num_offset) /

                         s->prev_frame_num_offset + 1 >> 1;

                }

            }



            

            mx = av_clip(mx, extra_width - 6 * x, h_edge_pos - 6 * x);

            my = av_clip(my, extra_width - 6 * y, v_edge_pos - 6 * y);



            

            if (mode == PREDICT_MODE) {

                dx = dy = 0;

            } else {

                dy = get_interleaved_se_golomb(&s->gb_slice);

                dx = get_interleaved_se_golomb(&s->gb_slice);



                if (dx != (int16_t)dx || dy != (int16_t)dy) {

                    av_log(s->avctx, AV_LOG_ERROR, "invalid MV vlc\n");

                    return -1;

                }

            }



            

            if (mode == THIRDPEL_MODE) {

                int fx, fy;

                mx  = (mx + 1 >> 1) + dx;

                my  = (my + 1 >> 1) + dy;

                fx  = (unsigned)(mx + 0x30000) / 3 - 0x10000;

                fy  = (unsigned)(my + 0x30000) / 3 - 0x10000;

                dxy = (mx - 3 * fx) + 4 * (my - 3 * fy);



                svq3_mc_dir_part(s, x, y, part_width, part_height,

                                 fx, fy, dxy, 1, dir, avg);

                mx += mx;

                my += my;

            } else if (mode == HALFPEL_MODE || mode == PREDICT_MODE) {

                mx  = (unsigned)(mx + 1 + 0x30000) / 3 + dx - 0x10000;

                my  = (unsigned)(my + 1 + 0x30000) / 3 + dy - 0x10000;

                dxy = (mx & 1) + 2 * (my & 1);



                svq3_mc_dir_part(s, x, y, part_width, part_height,

                                 mx >> 1, my >> 1, dxy, 0, dir, avg);

                mx *= 3;

                my *= 3;

            } else {

                mx = (unsigned)(mx + 3 + 0x60000) / 6 + dx - 0x10000;

                my = (unsigned)(my + 3 + 0x60000) / 6 + dy - 0x10000;



                svq3_mc_dir_part(s, x, y, part_width, part_height,

                                 mx, my, 0, 0, dir, avg);

                mx *= 6;

                my *= 6;

            }



            

            if (mode != PREDICT_MODE) {

                int32_t mv = pack16to32(mx, my);



                if (part_height == 8 && i < 8) {

                    AV_WN32A(s->mv_cache[dir][scan8[k] + 1 * 8], mv);



                    if (part_width == 8 && j < 8)

                        AV_WN32A(s->mv_cache[dir][scan8[k] + 1 + 1 * 8], mv);

                }

                if (part_width == 8 && j < 8)

                    AV_WN32A(s->mv_cache[dir][scan8[k] + 1], mv);

                if (part_width == 4 || part_height == 4)

                    AV_WN32A(s->mv_cache[dir][scan8[k]], mv);

            }



            

            fill_rectangle(s->cur_pic->motion_val[dir][b_xy],

                           part_width >> 2, part_height >> 2, s->b_stride,

                           pack16to32(mx, my), 4);

        }



    return 0;

}

                mx = s->next_pic->motion_val[0][b_xy][0] << 1;                 my = s->next_pic->motion_val[0][b_xy][1] << 1;
static inline int FUNC_0(SVQ3Context *VAR_0, int VAR_1, int VAR_2,

                              int VAR_3, int VAR_4)

{

    int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11, VAR_12, VAR_13;

    const int VAR_14    = ((VAR_1 & 5) == 4) ? 4 : 16 >> (VAR_1 & 1);

    const int VAR_15   = 16 >> ((unsigned)(VAR_1 + 1) / 3);

    const int VAR_16   = (VAR_2 == PREDICT_MODE) ? -16 * 6 : 0;

    const int VAR_17    = 6 * (VAR_0->VAR_17 - VAR_14)  - VAR_16;

    const int VAR_18    = 6 * (VAR_0->VAR_18 - VAR_15) - VAR_16;



    for (VAR_5 = 0; VAR_5 < 16; VAR_5 += VAR_15)

        for (VAR_6 = 0; VAR_6 < 16; VAR_6 += VAR_14) {

            const int VAR_19 = (4 * VAR_0->mb_x + (VAR_6 >> 2)) +

                             (4 * VAR_0->mb_y + (VAR_5 >> 2)) * VAR_0->b_stride;

            int VAR_20;

            VAR_12 = 16 * VAR_0->mb_x + VAR_6;

            VAR_13 = 16 * VAR_0->mb_y + VAR_5;

            VAR_7 = (VAR_6 >> 2 & 1) + (VAR_5 >> 1 & 2) +

                (VAR_6 >> 1 & 4) + (VAR_5      & 8);



            if (VAR_2 != PREDICT_MODE) {

                svq3_pred_motion(VAR_0, VAR_7, VAR_14 >> 2, VAR_3, 1, &VAR_8, &VAR_9);

            } else {

                VAR_8 = VAR_0->next_pic->motion_val[0][VAR_19][0] << 1;

                VAR_9 = VAR_0->next_pic->motion_val[0][VAR_19][1] << 1;



                if (VAR_3 == 0) {

                    VAR_8 = VAR_8 * VAR_0->frame_num_offset /

                         VAR_0->prev_frame_num_offset + 1 >> 1;

                    VAR_9 = VAR_9 * VAR_0->frame_num_offset /

                         VAR_0->prev_frame_num_offset + 1 >> 1;

                } else {

                    VAR_8 = VAR_8 * (VAR_0->frame_num_offset - VAR_0->prev_frame_num_offset) /

                         VAR_0->prev_frame_num_offset + 1 >> 1;

                    VAR_9 = VAR_9 * (VAR_0->frame_num_offset - VAR_0->prev_frame_num_offset) /

                         VAR_0->prev_frame_num_offset + 1 >> 1;

                }

            }



            

            VAR_8 = av_clip(VAR_8, VAR_16 - 6 * VAR_12, VAR_17 - 6 * VAR_12);

            VAR_9 = av_clip(VAR_9, VAR_16 - 6 * VAR_13, VAR_18 - 6 * VAR_13);



            

            if (VAR_2 == PREDICT_MODE) {

                VAR_10 = VAR_11 = 0;

            } else {

                VAR_11 = get_interleaved_se_golomb(&VAR_0->gb_slice);

                VAR_10 = get_interleaved_se_golomb(&VAR_0->gb_slice);



                if (VAR_10 != (int16_t)VAR_10 || VAR_11 != (int16_t)VAR_11) {

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "invalid MV vlc\n");

                    return -1;

                }

            }



            

            if (VAR_2 == THIRDPEL_MODE) {

                int VAR_21, VAR_22;

                VAR_8  = (VAR_8 + 1 >> 1) + VAR_10;

                VAR_9  = (VAR_9 + 1 >> 1) + VAR_11;

                VAR_21  = (unsigned)(VAR_8 + 0x30000) / 3 - 0x10000;

                VAR_22  = (unsigned)(VAR_9 + 0x30000) / 3 - 0x10000;

                VAR_20 = (VAR_8 - 3 * VAR_21) + 4 * (VAR_9 - 3 * VAR_22);



                svq3_mc_dir_part(VAR_0, VAR_12, VAR_13, VAR_14, VAR_15,

                                 VAR_21, VAR_22, VAR_20, 1, VAR_3, VAR_4);

                VAR_8 += VAR_8;

                VAR_9 += VAR_9;

            } else if (VAR_2 == HALFPEL_MODE || VAR_2 == PREDICT_MODE) {

                VAR_8  = (unsigned)(VAR_8 + 1 + 0x30000) / 3 + VAR_10 - 0x10000;

                VAR_9  = (unsigned)(VAR_9 + 1 + 0x30000) / 3 + VAR_11 - 0x10000;

                VAR_20 = (VAR_8 & 1) + 2 * (VAR_9 & 1);



                svq3_mc_dir_part(VAR_0, VAR_12, VAR_13, VAR_14, VAR_15,

                                 VAR_8 >> 1, VAR_9 >> 1, VAR_20, 0, VAR_3, VAR_4);

                VAR_8 *= 3;

                VAR_9 *= 3;

            } else {

                VAR_8 = (unsigned)(VAR_8 + 3 + 0x60000) / 6 + VAR_10 - 0x10000;

                VAR_9 = (unsigned)(VAR_9 + 3 + 0x60000) / 6 + VAR_11 - 0x10000;



                svq3_mc_dir_part(VAR_0, VAR_12, VAR_13, VAR_14, VAR_15,

                                 VAR_8, VAR_9, 0, 0, VAR_3, VAR_4);

                VAR_8 *= 6;

                VAR_9 *= 6;

            }



            

            if (VAR_2 != PREDICT_MODE) {

                int32_t mv = pack16to32(VAR_8, VAR_9);



                if (VAR_15 == 8 && VAR_5 < 8) {

                    AV_WN32A(VAR_0->mv_cache[VAR_3][scan8[VAR_7] + 1 * 8], mv);



                    if (VAR_14 == 8 && VAR_6 < 8)

                        AV_WN32A(VAR_0->mv_cache[VAR_3][scan8[VAR_7] + 1 + 1 * 8], mv);

                }

                if (VAR_14 == 8 && VAR_6 < 8)

                    AV_WN32A(VAR_0->mv_cache[VAR_3][scan8[VAR_7] + 1], mv);

                if (VAR_14 == 4 || VAR_15 == 4)

                    AV_WN32A(VAR_0->mv_cache[VAR_3][scan8[VAR_7]], mv);

            }



            

            fill_rectangle(VAR_0->cur_pic->motion_val[VAR_3][VAR_19],

                           VAR_14 >> 2, VAR_15 >> 2, VAR_0->b_stride,

                           pack16to32(VAR_8, VAR_9), 4);

        }



    return 0;

}

static inline int FUNC_0(SVQ3Context *VAR_0, int VAR_1, int VAR_2,
int VAR_3, int VAR_4)
{ int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11, VAR_12, VAR_13; const int VAR_14    = ((VAR_1 & 5) == 4) ? 4 : 16 >> (VAR_1 & 1); const int VAR_15   = 16 >> ((unsigned)(VAR_1 + 1) / 3); const int VAR_16   = (VAR_2 == PREDICT_MODE) ? -16 * 6 : 0; const int VAR_17    = 6 * (VAR_0->VAR_17 - VAR_14)  - VAR_16; const int VAR_18    = 6 * (VAR_0->VAR_18 - VAR_15) - VAR_16; for (VAR_5 = 0; VAR_5 < 16; VAR_5 += VAR_15) for (VAR_6 = 0; VAR_6 < 16; VAR_6 += VAR_14) { const int VAR_19 = (4 * VAR_0->mb_x + (VAR_6 >> 2)) +
(4 * VAR_0->mb_y + (VAR_5 >> 2)) * VAR_0->b_stride; int VAR_20; VAR_12 = 16 * VAR_0->mb_x + VAR_6; VAR_13 = 16 * VAR_0->mb_y + VAR_5; VAR_7 = (VAR_6 >> 2 & 1) + (VAR_5 >> 1 & 2) +
(VAR_6 >> 1 & 4) + (VAR_5      & 8); if (VAR_2 != PREDICT_MODE) { svq3_pred_motion(VAR_0, VAR_7, VAR_14 >> 2, VAR_3, 1, &VAR_8, &VAR_9); } else { VAR_8 = VAR_0->next_pic->motion_val[0][VAR_19][0] << 1; VAR_9 = VAR_0->next_pic->motion_val[0][VAR_19][1] << 1; if (VAR_3 == 0) { VAR_8 = VAR_8 * VAR_0->frame_num_offset /
VAR_0->prev_frame_num_offset + 1 >> 1; VAR_9 = VAR_9 * VAR_0->frame_num_offset /
VAR_0->prev_frame_num_offset + 1 >> 1; } else { VAR_8 = VAR_8 * (VAR_0->frame_num_offset - VAR_0->prev_frame_num_offset) /
VAR_0->prev_frame_num_offset + 1 >> 1; VAR_9 = VAR_9 * (VAR_0->frame_num_offset - VAR_0->prev_frame_num_offset) /
VAR_0->prev_frame_num_offset + 1 >> 1; } } VAR_8 = av_clip(VAR_8, VAR_16 - 6 * VAR_12, VAR_17 - 6 * VAR_12); VAR_9 = av_clip(VAR_9, VAR_16 - 6 * VAR_13, VAR_18 - 6 * VAR_13); if (VAR_2 == PREDICT_MODE) { VAR_10 = VAR_11 = 0; } else { VAR_11 = get_interleaved_se_golomb(&VAR_0->gb_slice); VAR_10 = get_interleaved_se_golomb(&VAR_0->gb_slice); if (VAR_10 != (int16_t)VAR_10 || VAR_11 != (int16_t)VAR_11) { av_log(VAR_0->avctx, AV_LOG_ERROR, "invalid MV vlc\n"); return -1; } } if (VAR_2 == THIRDPEL_MODE) { int VAR_21, VAR_22; VAR_8  = (VAR_8 + 1 >> 1) + VAR_10; VAR_9  = (VAR_9 + 1 >> 1) + VAR_11; VAR_21  = (unsigned)(VAR_8 + 0x30000) / 3 - 0x10000; VAR_22  = (unsigned)(VAR_9 + 0x30000) / 3 - 0x10000; VAR_20 = (VAR_8 - 3 * VAR_21) + 4 * (VAR_9 - 3 * VAR_22); svq3_mc_dir_part(VAR_0, VAR_12, VAR_13, VAR_14, VAR_15,
VAR_21, VAR_22, VAR_20, 1, VAR_3, VAR_4); VAR_8 += VAR_8; VAR_9 += VAR_9; } else if (VAR_2 == HALFPEL_MODE || VAR_2 == PREDICT_MODE) { VAR_8  = (unsigned)(VAR_8 + 1 + 0x30000) / 3 + VAR_10 - 0x10000; VAR_9  = (unsigned)(VAR_9 + 1 + 0x30000) / 3 + VAR_11 - 0x10000; VAR_20 = (VAR_8 & 1) + 2 * (VAR_9 & 1); svq3_mc_dir_part(VAR_0, VAR_12, VAR_13, VAR_14, VAR_15,
VAR_8 >> 1, VAR_9 >> 1, VAR_20, 0, VAR_3, VAR_4); VAR_8 *= 3; VAR_9 *= 3; } else { VAR_8 = (unsigned)(VAR_8 + 3 + 0x60000) / 6 + VAR_10 - 0x10000; VAR_9 = (unsigned)(VAR_9 + 3 + 0x60000) / 6 + VAR_11 - 0x10000; svq3_mc_dir_part(VAR_0, VAR_12, VAR_13, VAR_14, VAR_15,
VAR_8, VAR_9, 0, 0, VAR_3, VAR_4); VAR_8 *= 6; VAR_9 *= 6; } if (VAR_2 != PREDICT_MODE) { int32_t mv = pack16to32(VAR_8, VAR_9); if (VAR_15 == 8 && VAR_5 < 8) { AV_WN32A(VAR_0->mv_cache[VAR_3][scan8[VAR_7] + 1 * 8], mv); if (VAR_14 == 8 && VAR_6 < 8)
AV_WN32A(VAR_0->mv_cache[VAR_3][scan8[VAR_7] + 1 + 1 * 8], mv); } if (VAR_14 == 8 && VAR_6 < 8)
AV_WN32A(VAR_0->mv_cache[VAR_3][scan8[VAR_7] + 1], mv); if (VAR_14 == 4 || VAR_15 == 4)
AV_WN32A(VAR_0->mv_cache[VAR_3][scan8[VAR_7]], mv); } fill_rectangle(VAR_0->cur_pic->motion_val[VAR_3][VAR_19],
VAR_14 >> 2, VAR_15 >> 2, VAR_0->b_stride,
pack16to32(VAR_8, VAR_9), 4); } return 0; }