int ff_pre_estimate_p_frame_motion(MpegEncContext * s,

                                    int mb_x, int mb_y)

{

    int mx, my, range, dmin;

    int xmin, ymin, xmax, ymax;

    int rel_xmin, rel_ymin, rel_xmax, rel_ymax;

    int pred_x=0, pred_y=0;

    int P[10][2];

    const int shift= 1+s->quarter_sample;

    uint16_t * const mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV;

    const int mv_stride= s->mb_width + 2;

    const int xy= mb_x + 1 + (mb_y + 1)*mv_stride;

    

    assert(s->quarter_sample==0 || s->quarter_sample==1);



    s->me.pre_penalty_factor    = get_penalty_factor(s, s->avctx->me_pre_cmp);



    get_limits(s, &range, &xmin, &ymin, &xmax, &ymax, s->f_code);

    rel_xmin= xmin - mb_x*16;

    rel_xmax= xmax - mb_x*16;

    rel_ymin= ymin - mb_y*16;

    rel_ymax= ymax - mb_y*16;

    s->me.skip=0;



    P_LEFT[0]       = s->p_mv_table[xy + 1][0];

    P_LEFT[1]       = s->p_mv_table[xy + 1][1];



    if(P_LEFT[0]       < (rel_xmin<<shift)) P_LEFT[0]       = (rel_xmin<<shift);



    /* special case for first line */

    if (mb_y == s->mb_height-1) {

        pred_x= P_LEFT[0];

        pred_y= P_LEFT[1];

        P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]=

        P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0; //FIXME 

    } else {

        P_TOP[0]      = s->p_mv_table[xy + mv_stride    ][0];

        P_TOP[1]      = s->p_mv_table[xy + mv_stride    ][1];

        P_TOPRIGHT[0] = s->p_mv_table[xy + mv_stride - 1][0];

        P_TOPRIGHT[1] = s->p_mv_table[xy + mv_stride - 1][1];

        if(P_TOP[1]      < (rel_ymin<<shift)) P_TOP[1]     = (rel_ymin<<shift);

        if(P_TOPRIGHT[0] > (rel_xmax<<shift)) P_TOPRIGHT[0]= (rel_xmax<<shift);

        if(P_TOPRIGHT[1] < (rel_ymin<<shift)) P_TOPRIGHT[1]= (rel_ymin<<shift);

    

        P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);

        P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);



        pred_x = P_MEDIAN[0];

        pred_y = P_MEDIAN[1];

    }

    dmin = s->me.pre_motion_search(s, 0, &mx, &my, P, pred_x, pred_y, rel_xmin, rel_ymin, rel_xmax, rel_ymax, 

                                   &s->last_picture, s->p_mv_table, (1<<16)>>shift, mv_penalty);



    s->p_mv_table[xy][0] = mx<<shift;

    s->p_mv_table[xy][1] = my<<shift;

    

    return dmin;

}

int ff_pre_estimate_p_frame_motion(MpegEncContext * s,

                                    int mb_x, int mb_y)

{

    int mx, my, range, dmin;

    int xmin, ymin, xmax, ymax;

    int rel_xmin, rel_ymin, rel_xmax, rel_ymax;

    int pred_x=0, pred_y=0;

    int P[10][2];

    const int shift= 1+s->quarter_sample;

    uint16_t * const mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV;

    const int mv_stride= s->mb_width + 2;

    const int xy= mb_x + 1 + (mb_y + 1)*mv_stride;

    

    assert(s->quarter_sample==0 || s->quarter_sample==1);



    s->me.pre_penalty_factor    = get_penalty_factor(s, s->avctx->me_pre_cmp);



    get_limits(s, &range, &xmin, &ymin, &xmax, &ymax, s->f_code);

    rel_xmin= xmin - mb_x*16;

    rel_xmax= xmax - mb_x*16;

    rel_ymin= ymin - mb_y*16;

    rel_ymax= ymax - mb_y*16;

    s->me.skip=0;



    P_LEFT[0]       = s->p_mv_table[xy + 1][0];

    P_LEFT[1]       = s->p_mv_table[xy + 1][1];



    if(P_LEFT[0]       < (rel_xmin<<shift)) P_LEFT[0]       = (rel_xmin<<shift);



    

    if (mb_y == s->mb_height-1) {

        pred_x= P_LEFT[0];

        pred_y= P_LEFT[1];

        P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]=

        P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0; 

    } else {

        P_TOP[0]      = s->p_mv_table[xy + mv_stride    ][0];

        P_TOP[1]      = s->p_mv_table[xy + mv_stride    ][1];

        P_TOPRIGHT[0] = s->p_mv_table[xy + mv_stride - 1][0];

        P_TOPRIGHT[1] = s->p_mv_table[xy + mv_stride - 1][1];

        if(P_TOP[1]      < (rel_ymin<<shift)) P_TOP[1]     = (rel_ymin<<shift);

        if(P_TOPRIGHT[0] > (rel_xmax<<shift)) P_TOPRIGHT[0]= (rel_xmax<<shift);

        if(P_TOPRIGHT[1] < (rel_ymin<<shift)) P_TOPRIGHT[1]= (rel_ymin<<shift);

    

        P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);

        P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);



        pred_x = P_MEDIAN[0];

        pred_y = P_MEDIAN[1];

    }

    dmin = s->me.pre_motion_search(s, 0, &mx, &my, P, pred_x, pred_y, rel_xmin, rel_ymin, rel_xmax, rel_ymax, 

                                   &s->last_picture, s->p_mv_table, (1<<16)>>shift, mv_penalty);



    s->p_mv_table[xy][0] = mx<<shift;

    s->p_mv_table[xy][1] = my<<shift;

    

    return dmin;

}

int FUNC_0(MpegEncContext * VAR_0,

                                    int VAR_1, int VAR_2)

{

    int VAR_3, VAR_4, VAR_5, VAR_6;

    int VAR_7, VAR_8, VAR_9, VAR_10;

    int VAR_11, VAR_12, VAR_13, VAR_14;

    int VAR_15=0, VAR_16=0;

    int VAR_17[10][2];

    const int VAR_18= 1+VAR_0->quarter_sample;

    uint16_t * const mv_penalty= VAR_0->me.mv_penalty[VAR_0->f_code] + MAX_MV;

    const int VAR_19= VAR_0->mb_width + 2;

    const int VAR_20= VAR_1 + 1 + (VAR_2 + 1)*VAR_19;

    

    assert(VAR_0->quarter_sample==0 || VAR_0->quarter_sample==1);



    VAR_0->me.pre_penalty_factor    = get_penalty_factor(VAR_0, VAR_0->avctx->me_pre_cmp);



    get_limits(VAR_0, &VAR_5, &VAR_7, &VAR_8, &VAR_9, &VAR_10, VAR_0->f_code);

    VAR_11= VAR_7 - VAR_1*16;

    VAR_13= VAR_9 - VAR_1*16;

    VAR_12= VAR_8 - VAR_2*16;

    VAR_14= VAR_10 - VAR_2*16;

    VAR_0->me.skip=0;



    P_LEFT[0]       = VAR_0->p_mv_table[VAR_20 + 1][0];

    P_LEFT[1]       = VAR_0->p_mv_table[VAR_20 + 1][1];



    if(P_LEFT[0]       < (VAR_11<<VAR_18)) P_LEFT[0]       = (VAR_11<<VAR_18);



    

    if (VAR_2 == VAR_0->mb_height-1) {

        VAR_15= P_LEFT[0];

        VAR_16= P_LEFT[1];

        P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]=

        P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0; 

    } else {

        P_TOP[0]      = VAR_0->p_mv_table[VAR_20 + VAR_19    ][0];

        P_TOP[1]      = VAR_0->p_mv_table[VAR_20 + VAR_19    ][1];

        P_TOPRIGHT[0] = VAR_0->p_mv_table[VAR_20 + VAR_19 - 1][0];

        P_TOPRIGHT[1] = VAR_0->p_mv_table[VAR_20 + VAR_19 - 1][1];

        if(P_TOP[1]      < (VAR_12<<VAR_18)) P_TOP[1]     = (VAR_12<<VAR_18);

        if(P_TOPRIGHT[0] > (VAR_13<<VAR_18)) P_TOPRIGHT[0]= (VAR_13<<VAR_18);

        if(P_TOPRIGHT[1] < (VAR_12<<VAR_18)) P_TOPRIGHT[1]= (VAR_12<<VAR_18);

    

        P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);

        P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);



        VAR_15 = P_MEDIAN[0];

        VAR_16 = P_MEDIAN[1];

    }

    VAR_6 = VAR_0->me.pre_motion_search(VAR_0, 0, &VAR_3, &VAR_4, VAR_17, VAR_15, VAR_16, VAR_11, VAR_12, VAR_13, VAR_14, 

                                   &VAR_0->last_picture, VAR_0->p_mv_table, (1<<16)>>VAR_18, mv_penalty);



    VAR_0->p_mv_table[VAR_20][0] = VAR_3<<VAR_18;

    VAR_0->p_mv_table[VAR_20][1] = VAR_4<<VAR_18;

    

    return VAR_6;

}

int FUNC_0(MpegEncContext * VAR_0,
int VAR_1, int VAR_2)
{ int VAR_3, VAR_4, VAR_5, VAR_6; int VAR_7, VAR_8, VAR_9, VAR_10; int VAR_11, VAR_12, VAR_13, VAR_14; int VAR_15=0, VAR_16=0; int VAR_17[10][2]; const int VAR_18= 1+VAR_0->quarter_sample; uint16_t * const mv_penalty= VAR_0->me.mv_penalty[VAR_0->f_code] + MAX_MV; const int VAR_19= VAR_0->mb_width + 2; const int VAR_20= VAR_1 + 1 + (VAR_2 + 1)*VAR_19; assert(VAR_0->quarter_sample==0 || VAR_0->quarter_sample==1); VAR_0->me.pre_penalty_factor    = get_penalty_factor(VAR_0, VAR_0->avctx->me_pre_cmp); get_limits(VAR_0, &VAR_5, &VAR_7, &VAR_8, &VAR_9, &VAR_10, VAR_0->f_code); VAR_11= VAR_7 - VAR_1*16; VAR_13= VAR_9 - VAR_1*16; VAR_12= VAR_8 - VAR_2*16; VAR_14= VAR_10 - VAR_2*16; VAR_0->me.skip=0; P_LEFT[0]       = VAR_0->p_mv_table[VAR_20 + 1][0]; P_LEFT[1]       = VAR_0->p_mv_table[VAR_20 + 1][1]; if(P_LEFT[0]       < (VAR_11<<VAR_18)) P_LEFT[0]       = (VAR_11<<VAR_18); if (VAR_2 == VAR_0->mb_height-1) { VAR_15= P_LEFT[0]; VAR_16= P_LEFT[1]; P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]=
P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0; } else { P_TOP[0]      = VAR_0->p_mv_table[VAR_20 + VAR_19    ][0]; P_TOP[1]      = VAR_0->p_mv_table[VAR_20 + VAR_19    ][1]; P_TOPRIGHT[0] = VAR_0->p_mv_table[VAR_20 + VAR_19 - 1][0]; P_TOPRIGHT[1] = VAR_0->p_mv_table[VAR_20 + VAR_19 - 1][1]; if(P_TOP[1]      < (VAR_12<<VAR_18)) P_TOP[1]     = (VAR_12<<VAR_18); if(P_TOPRIGHT[0] > (VAR_13<<VAR_18)) P_TOPRIGHT[0]= (VAR_13<<VAR_18); if(P_TOPRIGHT[1] < (VAR_12<<VAR_18)) P_TOPRIGHT[1]= (VAR_12<<VAR_18); P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); VAR_15 = P_MEDIAN[0]; VAR_16 = P_MEDIAN[1]; } VAR_6 = VAR_0->me.pre_motion_search(VAR_0, 0, &VAR_3, &VAR_4, VAR_17, VAR_15, VAR_16, VAR_11, VAR_12, VAR_13, VAR_14,
&VAR_0->last_picture, VAR_0->p_mv_table, (1<<16)>>VAR_18, mv_penalty); VAR_0->p_mv_table[VAR_20][0] = VAR_3<<VAR_18; VAR_0->p_mv_table[VAR_20][1] = VAR_4<<VAR_18; return VAR_6; }