static int estimate_motion_b(MpegEncContext *s, int mb_x, int mb_y,

                             int16_t (*mv_table)[2], int ref_index, int f_code)

{

    MotionEstContext * const c= &s->me;

    int mx = 0, my = 0, dmin = 0;

    int P[10][2];

    const int shift= 1+s->quarter_sample;

    const int mot_stride = s->mb_stride;

    const int mot_xy = mb_y*mot_stride + mb_x;

    uint8_t * const mv_penalty= c->mv_penalty[f_code] + MAX_MV;

    int mv_scale;



    c->penalty_factor    = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp);

    c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp);

    c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp);

    c->current_mv_penalty= mv_penalty;



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



    if (s->motion_est != FF_ME_ZERO) {

        P_LEFT[0] = mv_table[mot_xy - 1][0];

        P_LEFT[1] = mv_table[mot_xy - 1][1];



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



        /* special case for first line */

        if (!s->first_slice_line) {

            P_TOP[0]      = mv_table[mot_xy - mot_stride    ][0];

            P_TOP[1]      = mv_table[mot_xy - mot_stride    ][1];

            P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1][0];

            P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1][1];

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

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

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

        c->pred_y = P_LEFT[1];



        if(mv_table == s->b_forw_mv_table){

            mv_scale= (s->pb_time<<16) / (s->pp_time<<shift);

        }else{

            mv_scale= ((s->pb_time - s->pp_time)<<16) / (s->pp_time<<shift);

        }



        dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, ref_index, s->p_mv_table, mv_scale, 0, 16);

    }



    dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, ref_index, 0, 16);



    if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)

        dmin= get_mb_score(s, mx, my, 0, ref_index, 0, 16, 1);



//    s->mb_type[mb_y*s->mb_width + mb_x]= mb_type;

    mv_table[mot_xy][0]= mx;

    mv_table[mot_xy][1]= my;



    return dmin;

}

static int estimate_motion_b(MpegEncContext *s, int mb_x, int mb_y,

                             int16_t (*mv_table)[2], int ref_index, int f_code)

{

    MotionEstContext * const c= &s->me;

    int mx = 0, my = 0, dmin = 0;

    int P[10][2];

    const int shift= 1+s->quarter_sample;

    const int mot_stride = s->mb_stride;

    const int mot_xy = mb_y*mot_stride + mb_x;

    uint8_t * const mv_penalty= c->mv_penalty[f_code] + MAX_MV;

    int mv_scale;



    c->penalty_factor    = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp);

    c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp);

    c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp);

    c->current_mv_penalty= mv_penalty;



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



    if (s->motion_est != FF_ME_ZERO) {

        P_LEFT[0] = mv_table[mot_xy - 1][0];

        P_LEFT[1] = mv_table[mot_xy - 1][1];



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



        

        if (!s->first_slice_line) {

            P_TOP[0]      = mv_table[mot_xy - mot_stride    ][0];

            P_TOP[1]      = mv_table[mot_xy - mot_stride    ][1];

            P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1][0];

            P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1][1];

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

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

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

        c->pred_y = P_LEFT[1];



        if(mv_table == s->b_forw_mv_table){

            mv_scale= (s->pb_time<<16) / (s->pp_time<<shift);

        }else{

            mv_scale= ((s->pb_time - s->pp_time)<<16) / (s->pp_time<<shift);

        }



        dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, ref_index, s->p_mv_table, mv_scale, 0, 16);

    }



    dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, ref_index, 0, 16);



    if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)

        dmin= get_mb_score(s, mx, my, 0, ref_index, 0, 16, 1);





    mv_table[mot_xy][0]= mx;

    mv_table[mot_xy][1]= my;



    return dmin;

}

static int FUNC_0(MpegEncContext *VAR_0, int VAR_1, int VAR_2,

                             VAR_3 (*mv_table)[2], int VAR_4, int VAR_5)

{

    MotionEstContext * const c= &VAR_0->me;

    int VAR_6 = 0, VAR_7 = 0, VAR_8 = 0;

    int VAR_9[10][2];

    const int VAR_10= 1+VAR_0->quarter_sample;

    const int VAR_11 = VAR_0->mb_stride;

    const int VAR_12 = VAR_2*VAR_11 + VAR_1;

    uint8_t * const mv_penalty= c->mv_penalty[VAR_5] + MAX_MV;

    int VAR_13;



    c->penalty_factor    = get_penalty_factor(VAR_0->lambda, VAR_0->lambda2, c->avctx->me_cmp);

    c->sub_penalty_factor= get_penalty_factor(VAR_0->lambda, VAR_0->lambda2, c->avctx->me_sub_cmp);

    c->mb_penalty_factor = get_penalty_factor(VAR_0->lambda, VAR_0->lambda2, c->avctx->mb_cmp);

    c->current_mv_penalty= mv_penalty;



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



    if (VAR_0->motion_est != FF_ME_ZERO) {

        P_LEFT[0] = mv_table[VAR_12 - 1][0];

        P_LEFT[1] = mv_table[VAR_12 - 1][1];



        if (P_LEFT[0] > (c->xmax << VAR_10)) P_LEFT[0] = (c->xmax << VAR_10);



        

        if (!VAR_0->first_slice_line) {

            P_TOP[0]      = mv_table[VAR_12 - VAR_11    ][0];

            P_TOP[1]      = mv_table[VAR_12 - VAR_11    ][1];

            P_TOPRIGHT[0] = mv_table[VAR_12 - VAR_11 + 1][0];

            P_TOPRIGHT[1] = mv_table[VAR_12 - VAR_11 + 1][1];

            if (P_TOP[1] > (c->ymax << VAR_10)) P_TOP[1] = (c->ymax << VAR_10);

            if (P_TOPRIGHT[0] < (c->xmin << VAR_10)) P_TOPRIGHT[0] = (c->xmin << VAR_10);

            if (P_TOPRIGHT[1] > (c->ymax << VAR_10)) P_TOPRIGHT[1] = (c->ymax << VAR_10);



            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_LEFT[0];

        c->pred_y = P_LEFT[1];



        if(mv_table == VAR_0->b_forw_mv_table){

            VAR_13= (VAR_0->pb_time<<16) / (VAR_0->pp_time<<VAR_10);

        }else{

            VAR_13= ((VAR_0->pb_time - VAR_0->pp_time)<<16) / (VAR_0->pp_time<<VAR_10);

        }



        VAR_8 = ff_epzs_motion_search(VAR_0, &VAR_6, &VAR_7, VAR_9, 0, VAR_4, VAR_0->p_mv_table, VAR_13, 0, 16);

    }



    VAR_8= c->sub_motion_search(VAR_0, &VAR_6, &VAR_7, VAR_8, 0, VAR_4, 0, 16);



    if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)

        VAR_8= get_mb_score(VAR_0, VAR_6, VAR_7, 0, VAR_4, 0, 16, 1);





    mv_table[VAR_12][0]= VAR_6;

    mv_table[VAR_12][1]= VAR_7;



    return VAR_8;

}

static int FUNC_0(MpegEncContext *VAR_0, int VAR_1, int VAR_2,
VAR_3 (*mv_table)[2], int VAR_4, int VAR_5)
{ MotionEstContext * const c= &VAR_0->me; int VAR_6 = 0, VAR_7 = 0, VAR_8 = 0; int VAR_9[10][2]; const int VAR_10= 1+VAR_0->quarter_sample; const int VAR_11 = VAR_0->mb_stride; const int VAR_12 = VAR_2*VAR_11 + VAR_1; uint8_t * const mv_penalty= c->mv_penalty[VAR_5] + MAX_MV; int VAR_13; c->penalty_factor    = get_penalty_factor(VAR_0->lambda, VAR_0->lambda2, c->avctx->me_cmp); c->sub_penalty_factor= get_penalty_factor(VAR_0->lambda, VAR_0->lambda2, c->avctx->me_sub_cmp); c->mb_penalty_factor = get_penalty_factor(VAR_0->lambda, VAR_0->lambda2, c->avctx->mb_cmp); c->current_mv_penalty= mv_penalty; get_limits(VAR_0, 16*VAR_1, 16*VAR_2); if (VAR_0->motion_est != FF_ME_ZERO) { P_LEFT[0] = mv_table[VAR_12 - 1][0]; P_LEFT[1] = mv_table[VAR_12 - 1][1]; if (P_LEFT[0] > (c->xmax << VAR_10)) P_LEFT[0] = (c->xmax << VAR_10); if (!VAR_0->first_slice_line) { P_TOP[0]      = mv_table[VAR_12 - VAR_11    ][0]; P_TOP[1]      = mv_table[VAR_12 - VAR_11    ][1]; P_TOPRIGHT[0] = mv_table[VAR_12 - VAR_11 + 1][0]; P_TOPRIGHT[1] = mv_table[VAR_12 - VAR_11 + 1][1]; if (P_TOP[1] > (c->ymax << VAR_10)) P_TOP[1] = (c->ymax << VAR_10); if (P_TOPRIGHT[0] < (c->xmin << VAR_10)) P_TOPRIGHT[0] = (c->xmin << VAR_10); if (P_TOPRIGHT[1] > (c->ymax << VAR_10)) P_TOPRIGHT[1] = (c->ymax << VAR_10); 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_LEFT[0]; c->pred_y = P_LEFT[1]; if(mv_table == VAR_0->b_forw_mv_table){ VAR_13= (VAR_0->pb_time<<16) / (VAR_0->pp_time<<VAR_10); }else{ VAR_13= ((VAR_0->pb_time - VAR_0->pp_time)<<16) / (VAR_0->pp_time<<VAR_10); } VAR_8 = ff_epzs_motion_search(VAR_0, &VAR_6, &VAR_7, VAR_9, 0, VAR_4, VAR_0->p_mv_table, VAR_13, 0, 16); } VAR_8= c->sub_motion_search(VAR_0, &VAR_6, &VAR_7, VAR_8, 0, VAR_4, 0, 16); if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)
VAR_8= get_mb_score(VAR_0, VAR_6, VAR_7, 0, VAR_4, 0, 16, 1); mv_table[VAR_12][0]= VAR_6; mv_table[VAR_12][1]= VAR_7; return VAR_8; }