int ff_pre_estimate_p_frame_motion(MpegEncContext * s,

                                    int mb_x, int mb_y)

{

    MotionEstContext * const c= &s->me;

    int mx, my, dmin;

    int P[10][2];

    const int shift= 1+s->quarter_sample;

    const int xy= mb_x + mb_y*s->mb_stride;

    init_ref(c, s->new_picture.f.data, s->last_picture.f.data, NULL, 16*mb_x, 16*mb_y, 0);



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



    c->pre_penalty_factor    = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_pre_cmp);

    c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;



    get_limits(s, 16*mb_x, 16*mb_y);

    c->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]       < (c->xmin<<shift)) P_LEFT[0]       = (c->xmin<<shift);



    /* special case for first line */

    if (s->first_slice_line) {

        c->pred_x= P_LEFT[0];

        c->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 + s->mb_stride    ][0];

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

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

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

        if(P_TOP[1]      < (c->ymin<<shift)) P_TOP[1]     = (c->ymin<<shift);

        if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift);

        if(P_TOPRIGHT[1] < (c->ymin<<shift)) P_TOPRIGHT[1]= (c->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]);



        c->pred_x = P_MEDIAN[0];

        c->pred_y = P_MEDIAN[1];

    }



    dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16);



    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)

{

    MotionEstContext * const c= &s->me;

    int mx, my, dmin;

    int P[10][2];

    const int shift= 1+s->quarter_sample;

    const int xy= mb_x + mb_y*s->mb_stride;

    init_ref(c, s->new_picture.f.data, s->last_picture.f.data, NULL, 16*mb_x, 16*mb_y, 0);



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



    c->pre_penalty_factor    = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_pre_cmp);

    c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;



    get_limits(s, 16*mb_x, 16*mb_y);

    c->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]       < (c->xmin<<shift)) P_LEFT[0]       = (c->xmin<<shift);



    

    if (s->first_slice_line) {

        c->pred_x= P_LEFT[0];

        c->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 + s->mb_stride    ][0];

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

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

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

        if(P_TOP[1]      < (c->ymin<<shift)) P_TOP[1]     = (c->ymin<<shift);

        if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift);

        if(P_TOPRIGHT[1] < (c->ymin<<shift)) P_TOPRIGHT[1]= (c->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]);



        c->pred_x = P_MEDIAN[0];

        c->pred_y = P_MEDIAN[1];

    }



    dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16);



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

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



    return dmin;

}

    init_ref(c, s->new_picture.f.data, s->last_picture.f.data, NULL, 16*mb_x, 16*mb_y, 0);     init_ref(c, s->new_picture.f.data, s->last_picture.f.data, NULL, 16*mb_x, 16*mb_y, 0);
int FUNC_0(MpegEncContext * VAR_0,

                                    int VAR_1, int VAR_2)

{

    MotionEstContext * const c= &VAR_0->me;

    int VAR_3, VAR_4, VAR_5;

    int VAR_6[10][2];

    const int VAR_7= 1+VAR_0->quarter_sample;

    const int VAR_8= VAR_1 + VAR_2*VAR_0->mb_stride;

    init_ref(c, VAR_0->new_picture.f.data, VAR_0->last_picture.f.data, NULL, 16*VAR_1, 16*VAR_2, 0);



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



    c->pre_penalty_factor    = get_penalty_factor(VAR_0->lambda, VAR_0->lambda2, c->avctx->me_pre_cmp);

    c->current_mv_penalty= c->mv_penalty[VAR_0->f_code] + MAX_MV;



    get_limits(VAR_0, 16*VAR_1, 16*VAR_2);

    c->skip=0;



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

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



    if(P_LEFT[0]       < (c->xmin<<VAR_7)) P_LEFT[0]       = (c->xmin<<VAR_7);



    

    if (VAR_0->first_slice_line) {

        c->pred_x= P_LEFT[0];

        c->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]      = VAR_0->p_mv_table[VAR_8 + VAR_0->mb_stride    ][0];

        P_TOP[1]      = VAR_0->p_mv_table[VAR_8 + VAR_0->mb_stride    ][1];

        P_TOPRIGHT[0] = VAR_0->p_mv_table[VAR_8 + VAR_0->mb_stride - 1][0];

        P_TOPRIGHT[1] = VAR_0->p_mv_table[VAR_8 + VAR_0->mb_stride - 1][1];

        if(P_TOP[1]      < (c->ymin<<VAR_7)) P_TOP[1]     = (c->ymin<<VAR_7);

        if(P_TOPRIGHT[0] > (c->xmax<<VAR_7)) P_TOPRIGHT[0]= (c->xmax<<VAR_7);

        if(P_TOPRIGHT[1] < (c->ymin<<VAR_7)) P_TOPRIGHT[1]= (c->ymin<<VAR_7);



        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]);



        c->pred_x = P_MEDIAN[0];

        c->pred_y = P_MEDIAN[1];

    }



    VAR_5 = ff_epzs_motion_search(VAR_0, &VAR_3, &VAR_4, VAR_6, 0, 0, VAR_0->p_mv_table, (1<<16)>>VAR_7, 0, 16);



    VAR_0->p_mv_table[VAR_8][0] = VAR_3<<VAR_7;

    VAR_0->p_mv_table[VAR_8][1] = VAR_4<<VAR_7;



    return VAR_5;

}

int FUNC_0(MpegEncContext * VAR_0,
int VAR_1, int VAR_2)
{ MotionEstContext * const c= &VAR_0->me; int VAR_3, VAR_4, VAR_5; int VAR_6[10][2]; const int VAR_7= 1+VAR_0->quarter_sample; const int VAR_8= VAR_1 + VAR_2*VAR_0->mb_stride; init_ref(c, VAR_0->new_picture.f.data, VAR_0->last_picture.f.data, NULL, 16*VAR_1, 16*VAR_2, 0); assert(VAR_0->quarter_sample==0 || VAR_0->quarter_sample==1); c->pre_penalty_factor    = get_penalty_factor(VAR_0->lambda, VAR_0->lambda2, c->avctx->me_pre_cmp); c->current_mv_penalty= c->mv_penalty[VAR_0->f_code] + MAX_MV; get_limits(VAR_0, 16*VAR_1, 16*VAR_2); c->skip=0; P_LEFT[0]       = VAR_0->p_mv_table[VAR_8 + 1][0]; P_LEFT[1]       = VAR_0->p_mv_table[VAR_8 + 1][1]; if(P_LEFT[0]       < (c->xmin<<VAR_7)) P_LEFT[0]       = (c->xmin<<VAR_7); if (VAR_0->first_slice_line) { c->pred_x= P_LEFT[0]; c->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]      = VAR_0->p_mv_table[VAR_8 + VAR_0->mb_stride    ][0]; P_TOP[1]      = VAR_0->p_mv_table[VAR_8 + VAR_0->mb_stride    ][1]; P_TOPRIGHT[0] = VAR_0->p_mv_table[VAR_8 + VAR_0->mb_stride - 1][0]; P_TOPRIGHT[1] = VAR_0->p_mv_table[VAR_8 + VAR_0->mb_stride - 1][1]; if(P_TOP[1]      < (c->ymin<<VAR_7)) P_TOP[1]     = (c->ymin<<VAR_7); if(P_TOPRIGHT[0] > (c->xmax<<VAR_7)) P_TOPRIGHT[0]= (c->xmax<<VAR_7); if(P_TOPRIGHT[1] < (c->ymin<<VAR_7)) P_TOPRIGHT[1]= (c->ymin<<VAR_7); 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]); c->pred_x = P_MEDIAN[0]; c->pred_y = P_MEDIAN[1]; } VAR_5 = ff_epzs_motion_search(VAR_0, &VAR_3, &VAR_4, VAR_6, 0, 0, VAR_0->p_mv_table, (1<<16)>>VAR_7, 0, 16); VAR_0->p_mv_table[VAR_8][0] = VAR_3<<VAR_7; VAR_0->p_mv_table[VAR_8][1] = VAR_4<<VAR_7; return VAR_5; }