static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir, int avg)

{

    MpegEncContext *s = &v->s;

    uint8_t *srcY;

    int dxy, mx, my, src_x, src_y;

    int off;

    int fieldmv = (v->fcm == ILACE_FRAME) ? v->blk_mv_type[s->block_index[n]] : 0;

    int v_edge_pos = s->v_edge_pos >> v->field_mode;

    uint8_t (*luty)[256];

    int use_ic;



    if ((!v->field_mode ||

         (v->ref_field_type[dir] == 1 && v->cur_field_type == 1)) &&

        !v->s.last_picture.f.data[0])

        return;



    mx = s->mv[dir][n][0];

    my = s->mv[dir][n][1];



    if (!dir) {

        if (v->field_mode && (v->cur_field_type != v->ref_field_type[dir]) && v->second_field) {

            srcY = s->current_picture.f.data[0];

            luty = v->curr_luty;

            use_ic = v->curr_use_ic;

        } else {

            srcY = s->last_picture.f.data[0];

            luty = v->last_luty;

            use_ic = v->last_use_ic;

        }

    } else {

        srcY = s->next_picture.f.data[0];

        luty = v->next_luty;

        use_ic = v->next_use_ic;

    }



    if (!srcY) {

        av_log(v->s.avctx, AV_LOG_ERROR, "Referenced frame missing.\n");

        return;

    }



    if (v->field_mode) {

        if (v->cur_field_type != v->ref_field_type[dir])

            my = my - 2 + 4 * v->cur_field_type;

    }



    if (s->pict_type == AV_PICTURE_TYPE_P && n == 3 && v->field_mode) {

        int same_count = 0, opp_count = 0, k;

        int chosen_mv[2][4][2], f;

        int tx, ty;

        for (k = 0; k < 4; k++) {

            f = v->mv_f[0][s->block_index[k] + v->blocks_off];

            chosen_mv[f][f ? opp_count : same_count][0] = s->mv[0][k][0];

            chosen_mv[f][f ? opp_count : same_count][1] = s->mv[0][k][1];

            opp_count  += f;

            same_count += 1 - f;

        }

        f = opp_count > same_count;

        switch (f ? opp_count : same_count) {

        case 4:

            tx = median4(chosen_mv[f][0][0], chosen_mv[f][1][0],

                         chosen_mv[f][2][0], chosen_mv[f][3][0]);

            ty = median4(chosen_mv[f][0][1], chosen_mv[f][1][1],

                         chosen_mv[f][2][1], chosen_mv[f][3][1]);

            break;

        case 3:

            tx = mid_pred(chosen_mv[f][0][0], chosen_mv[f][1][0], chosen_mv[f][2][0]);

            ty = mid_pred(chosen_mv[f][0][1], chosen_mv[f][1][1], chosen_mv[f][2][1]);

            break;

        case 2:

            tx = (chosen_mv[f][0][0] + chosen_mv[f][1][0]) / 2;

            ty = (chosen_mv[f][0][1] + chosen_mv[f][1][1]) / 2;

            break;

        }

        s->current_picture.motion_val[1][s->block_index[0] + v->blocks_off][0] = tx;

        s->current_picture.motion_val[1][s->block_index[0] + v->blocks_off][1] = ty;

        for (k = 0; k < 4; k++)

            v->mv_f[1][s->block_index[k] + v->blocks_off] = f;

    }



    if (v->fcm == ILACE_FRAME) {  // not sure if needed for other types of picture

        int qx, qy;

        int width  = s->avctx->coded_width;

        int height = s->avctx->coded_height >> 1;

        if (s->pict_type == AV_PICTURE_TYPE_P) {

            s->current_picture.motion_val[1][s->block_index[n] + v->blocks_off][0] = mx;

            s->current_picture.motion_val[1][s->block_index[n] + v->blocks_off][1] = my;

        }

        qx = (s->mb_x * 16) + (mx >> 2);

        qy = (s->mb_y *  8) + (my >> 3);



        if (qx < -17)

            mx -= 4 * (qx + 17);

        else if (qx > width)

            mx -= 4 * (qx - width);

        if (qy < -18)

            my -= 8 * (qy + 18);

        else if (qy > height + 1)

            my -= 8 * (qy - height - 1);

    }



    if ((v->fcm == ILACE_FRAME) && fieldmv)

        off = ((n > 1) ? s->linesize : 0) + (n & 1) * 8;

    else

        off = s->linesize * 4 * (n & 2) + (n & 1) * 8;



    src_x = s->mb_x * 16 + (n & 1) * 8 + (mx >> 2);

    if (!fieldmv)

        src_y = s->mb_y * 16 + (n & 2) * 4 + (my >> 2);

    else

        src_y = s->mb_y * 16 + ((n > 1) ? 1 : 0) + (my >> 2);



    if (v->profile != PROFILE_ADVANCED) {

        src_x = av_clip(src_x, -16, s->mb_width  * 16);

        src_y = av_clip(src_y, -16, s->mb_height * 16);

    } else {

        src_x = av_clip(src_x, -17, s->avctx->coded_width);

        if (v->fcm == ILACE_FRAME) {

            if (src_y & 1)

                src_y = av_clip(src_y, -17, s->avctx->coded_height + 1);

            else

                src_y = av_clip(src_y, -18, s->avctx->coded_height);

        } else {

            src_y = av_clip(src_y, -18, s->avctx->coded_height + 1);

        }

    }



    srcY += src_y * s->linesize + src_x;

    if (v->field_mode && v->ref_field_type[dir])

        srcY += s->current_picture_ptr->f.linesize[0];



    if (fieldmv && !(src_y & 1))

        v_edge_pos--;

    if (fieldmv && (src_y & 1) && src_y < 4)

        src_y--;

    if (v->rangeredfrm || use_ic

        || s->h_edge_pos < 13 || v_edge_pos < 23

        || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx & 3) - 8 - s->mspel * 2

        || (unsigned)(src_y - (s->mspel << fieldmv)) > v_edge_pos - (my & 3) - ((8 + s->mspel * 2) << fieldmv)) {

        srcY -= s->mspel * (1 + (s->linesize << fieldmv));

        /* check emulate edge stride and offset */

        s->vdsp.emulated_edge_mc(s->edge_emu_buffer, srcY,

                                 s->linesize, s->linesize,

                                 9 + s->mspel * 2, (9 + s->mspel * 2) << fieldmv,

                                 src_x - s->mspel, src_y - (s->mspel << fieldmv),

                                 s->h_edge_pos, v_edge_pos);

        srcY = s->edge_emu_buffer;

        /* if we deal with range reduction we need to scale source blocks */

        if (v->rangeredfrm) {

            int i, j;

            uint8_t *src;



            src = srcY;

            for (j = 0; j < 9 + s->mspel * 2; j++) {

                for (i = 0; i < 9 + s->mspel * 2; i++)

                    src[i] = ((src[i] - 128) >> 1) + 128;

                src += s->linesize << fieldmv;

            }

        }

        /* if we deal with intensity compensation we need to scale source blocks */

        if (use_ic) {

            int i, j;

            uint8_t *src;



            src = srcY;

            for (j = 0; j < 9 + s->mspel * 2; j++) {

                int f = v->field_mode ? v->ref_field_type[dir] : (((j<<fieldmv)+src_y - (s->mspel << fieldmv)) & 1);

                for (i = 0; i < 9 + s->mspel * 2; i++)

                    src[i] = luty[f][src[i]];

                src += s->linesize << fieldmv;

            }

        }

        srcY += s->mspel * (1 + (s->linesize << fieldmv));

    }



    if (s->mspel) {

        dxy = ((my & 3) << 2) | (mx & 3);

        if (avg)

            v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize << fieldmv, v->rnd);

        else

            v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize << fieldmv, v->rnd);

    } else { // hpel mc - always used for luma

        dxy = (my & 2) | ((mx & 2) >> 1);

        if (!v->rnd)

            s->hdsp.put_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);

        else

            s->hdsp.put_no_rnd_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);

    }

}

static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir, int avg)

{

    MpegEncContext *s = &v->s;

    uint8_t *srcY;

    int dxy, mx, my, src_x, src_y;

    int off;

    int fieldmv = (v->fcm == ILACE_FRAME) ? v->blk_mv_type[s->block_index[n]] : 0;

    int v_edge_pos = s->v_edge_pos >> v->field_mode;

    uint8_t (*luty)[256];

    int use_ic;



    if ((!v->field_mode ||

         (v->ref_field_type[dir] == 1 && v->cur_field_type == 1)) &&

        !v->s.last_picture.f.data[0])

        return;



    mx = s->mv[dir][n][0];

    my = s->mv[dir][n][1];



    if (!dir) {

        if (v->field_mode && (v->cur_field_type != v->ref_field_type[dir]) && v->second_field) {

            srcY = s->current_picture.f.data[0];

            luty = v->curr_luty;

            use_ic = v->curr_use_ic;

        } else {

            srcY = s->last_picture.f.data[0];

            luty = v->last_luty;

            use_ic = v->last_use_ic;

        }

    } else {

        srcY = s->next_picture.f.data[0];

        luty = v->next_luty;

        use_ic = v->next_use_ic;

    }



    if (!srcY) {

        av_log(v->s.avctx, AV_LOG_ERROR, "Referenced frame missing.\n");

        return;

    }



    if (v->field_mode) {

        if (v->cur_field_type != v->ref_field_type[dir])

            my = my - 2 + 4 * v->cur_field_type;

    }



    if (s->pict_type == AV_PICTURE_TYPE_P && n == 3 && v->field_mode) {

        int same_count = 0, opp_count = 0, k;

        int chosen_mv[2][4][2], f;

        int tx, ty;

        for (k = 0; k < 4; k++) {

            f = v->mv_f[0][s->block_index[k] + v->blocks_off];

            chosen_mv[f][f ? opp_count : same_count][0] = s->mv[0][k][0];

            chosen_mv[f][f ? opp_count : same_count][1] = s->mv[0][k][1];

            opp_count  += f;

            same_count += 1 - f;

        }

        f = opp_count > same_count;

        switch (f ? opp_count : same_count) {

        case 4:

            tx = median4(chosen_mv[f][0][0], chosen_mv[f][1][0],

                         chosen_mv[f][2][0], chosen_mv[f][3][0]);

            ty = median4(chosen_mv[f][0][1], chosen_mv[f][1][1],

                         chosen_mv[f][2][1], chosen_mv[f][3][1]);

            break;

        case 3:

            tx = mid_pred(chosen_mv[f][0][0], chosen_mv[f][1][0], chosen_mv[f][2][0]);

            ty = mid_pred(chosen_mv[f][0][1], chosen_mv[f][1][1], chosen_mv[f][2][1]);

            break;

        case 2:

            tx = (chosen_mv[f][0][0] + chosen_mv[f][1][0]) / 2;

            ty = (chosen_mv[f][0][1] + chosen_mv[f][1][1]) / 2;

            break;

        }

        s->current_picture.motion_val[1][s->block_index[0] + v->blocks_off][0] = tx;

        s->current_picture.motion_val[1][s->block_index[0] + v->blocks_off][1] = ty;

        for (k = 0; k < 4; k++)

            v->mv_f[1][s->block_index[k] + v->blocks_off] = f;

    }



    if (v->fcm == ILACE_FRAME) {  

        int qx, qy;

        int width  = s->avctx->coded_width;

        int height = s->avctx->coded_height >> 1;

        if (s->pict_type == AV_PICTURE_TYPE_P) {

            s->current_picture.motion_val[1][s->block_index[n] + v->blocks_off][0] = mx;

            s->current_picture.motion_val[1][s->block_index[n] + v->blocks_off][1] = my;

        }

        qx = (s->mb_x * 16) + (mx >> 2);

        qy = (s->mb_y *  8) + (my >> 3);



        if (qx < -17)

            mx -= 4 * (qx + 17);

        else if (qx > width)

            mx -= 4 * (qx - width);

        if (qy < -18)

            my -= 8 * (qy + 18);

        else if (qy > height + 1)

            my -= 8 * (qy - height - 1);

    }



    if ((v->fcm == ILACE_FRAME) && fieldmv)

        off = ((n > 1) ? s->linesize : 0) + (n & 1) * 8;

    else

        off = s->linesize * 4 * (n & 2) + (n & 1) * 8;



    src_x = s->mb_x * 16 + (n & 1) * 8 + (mx >> 2);

    if (!fieldmv)

        src_y = s->mb_y * 16 + (n & 2) * 4 + (my >> 2);

    else

        src_y = s->mb_y * 16 + ((n > 1) ? 1 : 0) + (my >> 2);



    if (v->profile != PROFILE_ADVANCED) {

        src_x = av_clip(src_x, -16, s->mb_width  * 16);

        src_y = av_clip(src_y, -16, s->mb_height * 16);

    } else {

        src_x = av_clip(src_x, -17, s->avctx->coded_width);

        if (v->fcm == ILACE_FRAME) {

            if (src_y & 1)

                src_y = av_clip(src_y, -17, s->avctx->coded_height + 1);

            else

                src_y = av_clip(src_y, -18, s->avctx->coded_height);

        } else {

            src_y = av_clip(src_y, -18, s->avctx->coded_height + 1);

        }

    }



    srcY += src_y * s->linesize + src_x;

    if (v->field_mode && v->ref_field_type[dir])

        srcY += s->current_picture_ptr->f.linesize[0];



    if (fieldmv && !(src_y & 1))

        v_edge_pos--;

    if (fieldmv && (src_y & 1) && src_y < 4)

        src_y--;

    if (v->rangeredfrm || use_ic

        || s->h_edge_pos < 13 || v_edge_pos < 23

        || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx & 3) - 8 - s->mspel * 2

        || (unsigned)(src_y - (s->mspel << fieldmv)) > v_edge_pos - (my & 3) - ((8 + s->mspel * 2) << fieldmv)) {

        srcY -= s->mspel * (1 + (s->linesize << fieldmv));

        

        s->vdsp.emulated_edge_mc(s->edge_emu_buffer, srcY,

                                 s->linesize, s->linesize,

                                 9 + s->mspel * 2, (9 + s->mspel * 2) << fieldmv,

                                 src_x - s->mspel, src_y - (s->mspel << fieldmv),

                                 s->h_edge_pos, v_edge_pos);

        srcY = s->edge_emu_buffer;

        

        if (v->rangeredfrm) {

            int i, j;

            uint8_t *src;



            src = srcY;

            for (j = 0; j < 9 + s->mspel * 2; j++) {

                for (i = 0; i < 9 + s->mspel * 2; i++)

                    src[i] = ((src[i] - 128) >> 1) + 128;

                src += s->linesize << fieldmv;

            }

        }

        

        if (use_ic) {

            int i, j;

            uint8_t *src;



            src = srcY;

            for (j = 0; j < 9 + s->mspel * 2; j++) {

                int f = v->field_mode ? v->ref_field_type[dir] : (((j<<fieldmv)+src_y - (s->mspel << fieldmv)) & 1);

                for (i = 0; i < 9 + s->mspel * 2; i++)

                    src[i] = luty[f][src[i]];

                src += s->linesize << fieldmv;

            }

        }

        srcY += s->mspel * (1 + (s->linesize << fieldmv));

    }



    if (s->mspel) {

        dxy = ((my & 3) << 2) | (mx & 3);

        if (avg)

            v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize << fieldmv, v->rnd);

        else

            v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize << fieldmv, v->rnd);

    } else { 

        dxy = (my & 2) | ((mx & 2) >> 1);

        if (!v->rnd)

            s->hdsp.put_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);

        else

            s->hdsp.put_no_rnd_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);

    }

}

        !v->s.last_picture.f.data[0])             srcY = s->current_picture.f.data[0];             srcY = s->last_picture.f.data[0];         srcY = s->next_picture.f.data[0];         srcY += s->current_picture_ptr->f.linesize[0];         !v->s.last_picture.f.data[0])             srcY = s->current_picture.f.data[0];             srcY = s->last_picture.f.data[0];         srcY = s->next_picture.f.data[0];         srcY += s->current_picture_ptr->f.linesize[0];         srcY += s->current_picture_ptr->f.linesize[0];
static void FUNC_0(VC1Context *VAR_0, int VAR_1, int VAR_2, int VAR_3)

{

    MpegEncContext *s = &VAR_0->s;

    uint8_t *srcY;

    int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8;

    int VAR_9;

    int VAR_10 = (VAR_0->fcm == ILACE_FRAME) ? VAR_0->blk_mv_type[s->block_index[VAR_1]] : 0;

    int VAR_11 = s->VAR_11 >> VAR_0->field_mode;

    uint8_t (*luty)[256];

    int VAR_12;



    if ((!VAR_0->field_mode ||

         (VAR_0->ref_field_type[VAR_2] == 1 && VAR_0->cur_field_type == 1)) &&

        !VAR_0->s.last_picture.VAR_17.data[0])

        return;



    VAR_5 = s->mv[VAR_2][VAR_1][0];

    VAR_6 = s->mv[VAR_2][VAR_1][1];



    if (!VAR_2) {

        if (VAR_0->field_mode && (VAR_0->cur_field_type != VAR_0->ref_field_type[VAR_2]) && VAR_0->second_field) {

            srcY = s->current_picture.VAR_17.data[0];

            luty = VAR_0->curr_luty;

            VAR_12 = VAR_0->curr_use_ic;

        } else {

            srcY = s->last_picture.VAR_17.data[0];

            luty = VAR_0->last_luty;

            VAR_12 = VAR_0->last_use_ic;

        }

    } else {

        srcY = s->next_picture.VAR_17.data[0];

        luty = VAR_0->next_luty;

        VAR_12 = VAR_0->next_use_ic;

    }



    if (!srcY) {

        av_log(VAR_0->s.avctx, AV_LOG_ERROR, "Referenced frame missing.\VAR_1");

        return;

    }



    if (VAR_0->field_mode) {

        if (VAR_0->cur_field_type != VAR_0->ref_field_type[VAR_2])

            VAR_6 = VAR_6 - 2 + 4 * VAR_0->cur_field_type;

    }



    if (s->pict_type == AV_PICTURE_TYPE_P && VAR_1 == 3 && VAR_0->field_mode) {

        int VAR_13 = 0, VAR_14 = 0, VAR_15;

        int VAR_16[2][4][2], VAR_17;

        int VAR_18, VAR_19;

        for (VAR_15 = 0; VAR_15 < 4; VAR_15++) {

            VAR_17 = VAR_0->mv_f[0][s->block_index[VAR_15] + VAR_0->blocks_off];

            VAR_16[VAR_17][VAR_17 ? VAR_14 : VAR_13][0] = s->mv[0][VAR_15][0];

            VAR_16[VAR_17][VAR_17 ? VAR_14 : VAR_13][1] = s->mv[0][VAR_15][1];

            VAR_14  += VAR_17;

            VAR_13 += 1 - VAR_17;

        }

        VAR_17 = VAR_14 > VAR_13;

        switch (VAR_17 ? VAR_14 : VAR_13) {

        case 4:

            VAR_18 = median4(VAR_16[VAR_17][0][0], VAR_16[VAR_17][1][0],

                         VAR_16[VAR_17][2][0], VAR_16[VAR_17][3][0]);

            VAR_19 = median4(VAR_16[VAR_17][0][1], VAR_16[VAR_17][1][1],

                         VAR_16[VAR_17][2][1], VAR_16[VAR_17][3][1]);

            break;

        case 3:

            VAR_18 = mid_pred(VAR_16[VAR_17][0][0], VAR_16[VAR_17][1][0], VAR_16[VAR_17][2][0]);

            VAR_19 = mid_pred(VAR_16[VAR_17][0][1], VAR_16[VAR_17][1][1], VAR_16[VAR_17][2][1]);

            break;

        case 2:

            VAR_18 = (VAR_16[VAR_17][0][0] + VAR_16[VAR_17][1][0]) / 2;

            VAR_19 = (VAR_16[VAR_17][0][1] + VAR_16[VAR_17][1][1]) / 2;

            break;

        }

        s->current_picture.motion_val[1][s->block_index[0] + VAR_0->blocks_off][0] = VAR_18;

        s->current_picture.motion_val[1][s->block_index[0] + VAR_0->blocks_off][1] = VAR_19;

        for (VAR_15 = 0; VAR_15 < 4; VAR_15++)

            VAR_0->mv_f[1][s->block_index[VAR_15] + VAR_0->blocks_off] = VAR_17;

    }



    if (VAR_0->fcm == ILACE_FRAME) {  

        int VAR_20, VAR_21;

        int VAR_22  = s->avctx->coded_width;

        int VAR_23 = s->avctx->coded_height >> 1;

        if (s->pict_type == AV_PICTURE_TYPE_P) {

            s->current_picture.motion_val[1][s->block_index[VAR_1] + VAR_0->blocks_off][0] = VAR_5;

            s->current_picture.motion_val[1][s->block_index[VAR_1] + VAR_0->blocks_off][1] = VAR_6;

        }

        VAR_20 = (s->mb_x * 16) + (VAR_5 >> 2);

        VAR_21 = (s->mb_y *  8) + (VAR_6 >> 3);



        if (VAR_20 < -17)

            VAR_5 -= 4 * (VAR_20 + 17);

        else if (VAR_20 > VAR_22)

            VAR_5 -= 4 * (VAR_20 - VAR_22);

        if (VAR_21 < -18)

            VAR_6 -= 8 * (VAR_21 + 18);

        else if (VAR_21 > VAR_23 + 1)

            VAR_6 -= 8 * (VAR_21 - VAR_23 - 1);

    }



    if ((VAR_0->fcm == ILACE_FRAME) && VAR_10)

        VAR_9 = ((VAR_1 > 1) ? s->linesize : 0) + (VAR_1 & 1) * 8;

    else

        VAR_9 = s->linesize * 4 * (VAR_1 & 2) + (VAR_1 & 1) * 8;



    VAR_7 = s->mb_x * 16 + (VAR_1 & 1) * 8 + (VAR_5 >> 2);

    if (!VAR_10)

        VAR_8 = s->mb_y * 16 + (VAR_1 & 2) * 4 + (VAR_6 >> 2);

    else

        VAR_8 = s->mb_y * 16 + ((VAR_1 > 1) ? 1 : 0) + (VAR_6 >> 2);



    if (VAR_0->profile != PROFILE_ADVANCED) {

        VAR_7 = av_clip(VAR_7, -16, s->mb_width  * 16);

        VAR_8 = av_clip(VAR_8, -16, s->mb_height * 16);

    } else {

        VAR_7 = av_clip(VAR_7, -17, s->avctx->coded_width);

        if (VAR_0->fcm == ILACE_FRAME) {

            if (VAR_8 & 1)

                VAR_8 = av_clip(VAR_8, -17, s->avctx->coded_height + 1);

            else

                VAR_8 = av_clip(VAR_8, -18, s->avctx->coded_height);

        } else {

            VAR_8 = av_clip(VAR_8, -18, s->avctx->coded_height + 1);

        }

    }



    srcY += VAR_8 * s->linesize + VAR_7;

    if (VAR_0->field_mode && VAR_0->ref_field_type[VAR_2])

        srcY += s->current_picture_ptr->VAR_17.linesize[0];



    if (VAR_10 && !(VAR_8 & 1))

        VAR_11--;

    if (VAR_10 && (VAR_8 & 1) && VAR_8 < 4)

        VAR_8--;

    if (VAR_0->rangeredfrm || VAR_12

        || s->h_edge_pos < 13 || VAR_11 < 23

        || (unsigned)(VAR_7 - s->mspel) > s->h_edge_pos - (VAR_5 & 3) - 8 - s->mspel * 2

        || (unsigned)(VAR_8 - (s->mspel << VAR_10)) > VAR_11 - (VAR_6 & 3) - ((8 + s->mspel * 2) << VAR_10)) {

        srcY -= s->mspel * (1 + (s->linesize << VAR_10));

        

        s->vdsp.emulated_edge_mc(s->edge_emu_buffer, srcY,

                                 s->linesize, s->linesize,

                                 9 + s->mspel * 2, (9 + s->mspel * 2) << VAR_10,

                                 VAR_7 - s->mspel, VAR_8 - (s->mspel << VAR_10),

                                 s->h_edge_pos, VAR_11);

        srcY = s->edge_emu_buffer;

        

        if (VAR_0->rangeredfrm) {

            int VAR_26, VAR_26;

            uint8_t *src;



            src = srcY;

            for (VAR_26 = 0; VAR_26 < 9 + s->mspel * 2; VAR_26++) {

                for (VAR_26 = 0; VAR_26 < 9 + s->mspel * 2; VAR_26++)

                    src[VAR_26] = ((src[VAR_26] - 128) >> 1) + 128;

                src += s->linesize << VAR_10;

            }

        }

        

        if (VAR_12) {

            int VAR_26, VAR_26;

            uint8_t *src;



            src = srcY;

            for (VAR_26 = 0; VAR_26 < 9 + s->mspel * 2; VAR_26++) {

                int VAR_17 = VAR_0->field_mode ? VAR_0->ref_field_type[VAR_2] : (((VAR_26<<VAR_10)+VAR_8 - (s->mspel << VAR_10)) & 1);

                for (VAR_26 = 0; VAR_26 < 9 + s->mspel * 2; VAR_26++)

                    src[VAR_26] = luty[VAR_17][src[VAR_26]];

                src += s->linesize << VAR_10;

            }

        }

        srcY += s->mspel * (1 + (s->linesize << VAR_10));

    }



    if (s->mspel) {

        VAR_4 = ((VAR_6 & 3) << 2) | (VAR_5 & 3);

        if (VAR_3)

            VAR_0->vc1dsp.avg_vc1_mspel_pixels_tab[VAR_4](s->dest[0] + VAR_9, srcY, s->linesize << VAR_10, VAR_0->rnd);

        else

            VAR_0->vc1dsp.put_vc1_mspel_pixels_tab[VAR_4](s->dest[0] + VAR_9, srcY, s->linesize << VAR_10, VAR_0->rnd);

    } else { 

        VAR_4 = (VAR_6 & 2) | ((VAR_5 & 2) >> 1);

        if (!VAR_0->rnd)

            s->hdsp.put_pixels_tab[1][VAR_4](s->dest[0] + VAR_9, srcY, s->linesize, 8);

        else

            s->hdsp.put_no_rnd_pixels_tab[1][VAR_4](s->dest[0] + VAR_9, srcY, s->linesize, 8);

    }

}

static void FUNC_0(VC1Context *VAR_0, int VAR_1, int VAR_2, int VAR_3)
{ MpegEncContext *s = &VAR_0->s; uint8_t *srcY; int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8; int VAR_9; int VAR_10 = (VAR_0->fcm == ILACE_FRAME) ? VAR_0->blk_mv_type[s->block_index[VAR_1]] : 0; int VAR_11 = s->VAR_11 >> VAR_0->field_mode; uint8_t (*luty)[256]; int VAR_12; if ((!VAR_0->field_mode ||
(VAR_0->ref_field_type[VAR_2] == 1 && VAR_0->cur_field_type == 1)) &&
!VAR_0->s.last_picture.VAR_17.data[0])
return; VAR_5 = s->mv[VAR_2][VAR_1][0]; VAR_6 = s->mv[VAR_2][VAR_1][1]; if (!VAR_2) { if (VAR_0->field_mode && (VAR_0->cur_field_type != VAR_0->ref_field_type[VAR_2]) && VAR_0->second_field) { srcY = s->current_picture.VAR_17.data[0]; luty = VAR_0->curr_luty; VAR_12 = VAR_0->curr_use_ic; } else { srcY = s->last_picture.VAR_17.data[0]; luty = VAR_0->last_luty; VAR_12 = VAR_0->last_use_ic; } } else { srcY = s->next_picture.VAR_17.data[0]; luty = VAR_0->next_luty; VAR_12 = VAR_0->next_use_ic; } if (!srcY) { av_log(VAR_0->s.avctx, AV_LOG_ERROR, "Referenced frame missing.\VAR_1"); return; } if (VAR_0->field_mode) { if (VAR_0->cur_field_type != VAR_0->ref_field_type[VAR_2])
VAR_6 = VAR_6 - 2 + 4 * VAR_0->cur_field_type; } if (s->pict_type == AV_PICTURE_TYPE_P && VAR_1 == 3 && VAR_0->field_mode) { int VAR_13 = 0, VAR_14 = 0, VAR_15; int VAR_16[2][4][2], VAR_17; int VAR_18, VAR_19; for (VAR_15 = 0; VAR_15 < 4; VAR_15++) { VAR_17 = VAR_0->mv_f[0][s->block_index[VAR_15] + VAR_0->blocks_off]; VAR_16[VAR_17][VAR_17 ? VAR_14 : VAR_13][0] = s->mv[0][VAR_15][0]; VAR_16[VAR_17][VAR_17 ? VAR_14 : VAR_13][1] = s->mv[0][VAR_15][1]; VAR_14  += VAR_17; VAR_13 += 1 - VAR_17; } VAR_17 = VAR_14 > VAR_13; switch (VAR_17 ? VAR_14 : VAR_13) { case 4:
VAR_18 = median4(VAR_16[VAR_17][0][0], VAR_16[VAR_17][1][0],
VAR_16[VAR_17][2][0], VAR_16[VAR_17][3][0]); VAR_19 = median4(VAR_16[VAR_17][0][1], VAR_16[VAR_17][1][1],
VAR_16[VAR_17][2][1], VAR_16[VAR_17][3][1]); break; case 3:
VAR_18 = mid_pred(VAR_16[VAR_17][0][0], VAR_16[VAR_17][1][0], VAR_16[VAR_17][2][0]); VAR_19 = mid_pred(VAR_16[VAR_17][0][1], VAR_16[VAR_17][1][1], VAR_16[VAR_17][2][1]); break; case 2:
VAR_18 = (VAR_16[VAR_17][0][0] + VAR_16[VAR_17][1][0]) / 2; VAR_19 = (VAR_16[VAR_17][0][1] + VAR_16[VAR_17][1][1]) / 2; break; } s->current_picture.motion_val[1][s->block_index[0] + VAR_0->blocks_off][0] = VAR_18; s->current_picture.motion_val[1][s->block_index[0] + VAR_0->blocks_off][1] = VAR_19; for (VAR_15 = 0; VAR_15 < 4; VAR_15++) VAR_0->mv_f[1][s->block_index[VAR_15] + VAR_0->blocks_off] = VAR_17; } if (VAR_0->fcm == ILACE_FRAME) { int VAR_20, VAR_21; int VAR_22  = s->avctx->coded_width; int VAR_23 = s->avctx->coded_height >> 1; if (s->pict_type == AV_PICTURE_TYPE_P) { s->current_picture.motion_val[1][s->block_index[VAR_1] + VAR_0->blocks_off][0] = VAR_5; s->current_picture.motion_val[1][s->block_index[VAR_1] + VAR_0->blocks_off][1] = VAR_6; } VAR_20 = (s->mb_x * 16) + (VAR_5 >> 2); VAR_21 = (s->mb_y *  8) + (VAR_6 >> 3); if (VAR_20 < -17)
VAR_5 -= 4 * (VAR_20 + 17); else if (VAR_20 > VAR_22)
VAR_5 -= 4 * (VAR_20 - VAR_22); if (VAR_21 < -18)
VAR_6 -= 8 * (VAR_21 + 18); else if (VAR_21 > VAR_23 + 1)
VAR_6 -= 8 * (VAR_21 - VAR_23 - 1); } if ((VAR_0->fcm == ILACE_FRAME) && VAR_10)
VAR_9 = ((VAR_1 > 1) ? s->linesize : 0) + (VAR_1 & 1) * 8; else
VAR_9 = s->linesize * 4 * (VAR_1 & 2) + (VAR_1 & 1) * 8; VAR_7 = s->mb_x * 16 + (VAR_1 & 1) * 8 + (VAR_5 >> 2); if (!VAR_10)
VAR_8 = s->mb_y * 16 + (VAR_1 & 2) * 4 + (VAR_6 >> 2); else
VAR_8 = s->mb_y * 16 + ((VAR_1 > 1) ? 1 : 0) + (VAR_6 >> 2); if (VAR_0->profile != PROFILE_ADVANCED) { VAR_7 = av_clip(VAR_7, -16, s->mb_width  * 16); VAR_8 = av_clip(VAR_8, -16, s->mb_height * 16); } else { VAR_7 = av_clip(VAR_7, -17, s->avctx->coded_width); if (VAR_0->fcm == ILACE_FRAME) { if (VAR_8 & 1)
VAR_8 = av_clip(VAR_8, -17, s->avctx->coded_height + 1); else
VAR_8 = av_clip(VAR_8, -18, s->avctx->coded_height); } else { VAR_8 = av_clip(VAR_8, -18, s->avctx->coded_height + 1); } } srcY += VAR_8 * s->linesize + VAR_7; if (VAR_0->field_mode && VAR_0->ref_field_type[VAR_2])
srcY += s->current_picture_ptr->VAR_17.linesize[0]; if (VAR_10 && !(VAR_8 & 1))
VAR_11--; if (VAR_10 && (VAR_8 & 1) && VAR_8 < 4)
VAR_8--; if (VAR_0->rangeredfrm || VAR_12
|| s->h_edge_pos < 13 || VAR_11 < 23
|| (unsigned)(VAR_7 - s->mspel) > s->h_edge_pos - (VAR_5 & 3) - 8 - s->mspel * 2
|| (unsigned)(VAR_8 - (s->mspel << VAR_10)) > VAR_11 - (VAR_6 & 3) - ((8 + s->mspel * 2) << VAR_10)) { srcY -= s->mspel * (1 + (s->linesize << VAR_10)); s->vdsp.emulated_edge_mc(s->edge_emu_buffer, srcY,
s->linesize, s->linesize,
9 + s->mspel * 2, (9 + s->mspel * 2) << VAR_10,
VAR_7 - s->mspel, VAR_8 - (s->mspel << VAR_10),
s->h_edge_pos, VAR_11); srcY = s->edge_emu_buffer; if (VAR_0->rangeredfrm) { int VAR_26, VAR_26; uint8_t *src; src = srcY; for (VAR_26 = 0; VAR_26 < 9 + s->mspel * 2; VAR_26++) { for (VAR_26 = 0; VAR_26 < 9 + s->mspel * 2; VAR_26++) src[VAR_26] = ((src[VAR_26] - 128) >> 1) + 128; src += s->linesize << VAR_10; } } if (VAR_12) { int VAR_26, VAR_26; uint8_t *src; src = srcY; for (VAR_26 = 0; VAR_26 < 9 + s->mspel * 2; VAR_26++) { int VAR_17 = VAR_0->field_mode ? VAR_0->ref_field_type[VAR_2] : (((VAR_26<<VAR_10)+VAR_8 - (s->mspel << VAR_10)) & 1); for (VAR_26 = 0; VAR_26 < 9 + s->mspel * 2; VAR_26++) src[VAR_26] = luty[VAR_17][src[VAR_26]]; src += s->linesize << VAR_10; } } srcY += s->mspel * (1 + (s->linesize << VAR_10)); } if (s->mspel) { VAR_4 = ((VAR_6 & 3) << 2) | (VAR_5 & 3); if (VAR_3)
VAR_0->vc1dsp.avg_vc1_mspel_pixels_tab[VAR_4](s->dest[0] + VAR_9, srcY, s->linesize << VAR_10, VAR_0->rnd); else
VAR_0->vc1dsp.put_vc1_mspel_pixels_tab[VAR_4](s->dest[0] + VAR_9, srcY, s->linesize << VAR_10, VAR_0->rnd); } else { VAR_4 = (VAR_6 & 2) | ((VAR_5 & 2) >> 1); if (!VAR_0->rnd)
s->hdsp.put_pixels_tab[1][VAR_4](s->dest[0] + VAR_9, srcY, s->linesize, 8); else
s->hdsp.put_no_rnd_pixels_tab[1][VAR_4](s->dest[0] + VAR_9, srcY, s->linesize, 8); } }