static int epzs_motion_search(MpegEncContext * s,

                             int *mx_ptr, int *my_ptr,

                             int P[5][2], int pred_x, int pred_y,

                             int xmin, int ymin, int xmax, int ymax)

{

    int best[2]={0, 0};

    int d, dmin; 

    UINT8 *new_pic, *old_pic;

    const int pic_stride= s->linesize;

    const int pic_xy= (s->mb_y*pic_stride + s->mb_x)*16;

    UINT16 *mv_penalty= s->mv_penalty[s->f_code] + MAX_MV; // f_code of the prev frame

    int quant= s->qscale; // qscale of the prev frame

    const int shift= 1+s->quarter_sample;



    new_pic = s->new_picture[0] + pic_xy;

    old_pic = s->last_picture[0] + pic_xy;

//printf("%d %d %d %d\n", xmin, ymin, xmax, ymax);

    

    dmin = pix_abs16x16(new_pic, old_pic, pic_stride, 16);

    if(dmin<Z_THRESHOLD){

        *mx_ptr= 0;

        *my_ptr= 0;

//printf("Z");

        return dmin;

    }



    /* first line */

    if ((s->mb_y == 0 || s->first_slice_line || s->first_gob_line)) {

        CHECK_MV(P[1][0]>>shift, P[1][1]>>shift)

    }else{

        CHECK_MV(P[4][0]>>shift, P[4][1]>>shift)

        if(dmin<Z_THRESHOLD){

            *mx_ptr= P[4][0]>>shift;

            *my_ptr= P[4][1]>>shift;

//printf("M\n");

            return dmin;

        }

        CHECK_MV(P[1][0]>>shift, P[1][1]>>shift)

        CHECK_MV(P[2][0]>>shift, P[2][1]>>shift)

        CHECK_MV(P[3][0]>>shift, P[3][1]>>shift)

    }

    CHECK_MV(P[0][0]>>shift, P[0][1]>>shift)



    dmin= small_diamond_search(s, best, dmin, new_pic, old_pic, pic_stride, 

                               pred_x, pred_y, mv_penalty, quant, xmin, ymin, xmax, ymax, shift);

    *mx_ptr= best[0];

    *my_ptr= best[1];    



//    printf("%d %d %d \n", best[0], best[1], dmin);



    return dmin;

}

static int epzs_motion_search(MpegEncContext * s,

                             int *mx_ptr, int *my_ptr,

                             int P[5][2], int pred_x, int pred_y,

                             int xmin, int ymin, int xmax, int ymax)

{

    int best[2]={0, 0};

    int d, dmin; 

    UINT8 *new_pic, *old_pic;

    const int pic_stride= s->linesize;

    const int pic_xy= (s->mb_y*pic_stride + s->mb_x)*16;

    UINT16 *mv_penalty= s->mv_penalty[s->f_code] + MAX_MV; 

    int quant= s->qscale; 

    const int shift= 1+s->quarter_sample;



    new_pic = s->new_picture[0] + pic_xy;

    old_pic = s->last_picture[0] + pic_xy;



    

    dmin = pix_abs16x16(new_pic, old_pic, pic_stride, 16);

    if(dmin<Z_THRESHOLD){

        *mx_ptr= 0;

        *my_ptr= 0;



        return dmin;

    }



    

    if ((s->mb_y == 0 || s->first_slice_line || s->first_gob_line)) {

        CHECK_MV(P[1][0]>>shift, P[1][1]>>shift)

    }else{

        CHECK_MV(P[4][0]>>shift, P[4][1]>>shift)

        if(dmin<Z_THRESHOLD){

            *mx_ptr= P[4][0]>>shift;

            *my_ptr= P[4][1]>>shift;



            return dmin;

        }

        CHECK_MV(P[1][0]>>shift, P[1][1]>>shift)

        CHECK_MV(P[2][0]>>shift, P[2][1]>>shift)

        CHECK_MV(P[3][0]>>shift, P[3][1]>>shift)

    }

    CHECK_MV(P[0][0]>>shift, P[0][1]>>shift)



    dmin= small_diamond_search(s, best, dmin, new_pic, old_pic, pic_stride, 

                               pred_x, pred_y, mv_penalty, quant, xmin, ymin, xmax, ymax, shift);

    *mx_ptr= best[0];

    *my_ptr= best[1];    







    return dmin;

}

    dmin= small_diamond_search(s, best, dmin, new_pic, old_pic, pic_stride,                                 pred_x, pred_y, mv_penalty, quant, xmin, ymin, xmax, ymax, shift);
static int FUNC_0(MpegEncContext * VAR_0,

                             int *VAR_1, int *VAR_2,

                             int VAR_3[5][2], int VAR_4, int VAR_5,

                             int VAR_6, int VAR_7, int VAR_8, int VAR_9)

{

    int VAR_10[2]={0, 0};

    int VAR_11, VAR_12; 

    UINT8 *new_pic, *old_pic;

    const int VAR_13= VAR_0->linesize;

    const int VAR_14= (VAR_0->mb_y*VAR_13 + VAR_0->mb_x)*16;

    UINT16 *mv_penalty= VAR_0->mv_penalty[VAR_0->f_code] + MAX_MV; 

    int VAR_15= VAR_0->qscale; 

    const int VAR_16= 1+VAR_0->quarter_sample;



    new_pic = VAR_0->new_picture[0] + VAR_14;

    old_pic = VAR_0->last_picture[0] + VAR_14;



    

    VAR_12 = pix_abs16x16(new_pic, old_pic, VAR_13, 16);

    if(VAR_12<Z_THRESHOLD){

        *VAR_1= 0;

        *VAR_2= 0;



        return VAR_12;

    }



    

    if ((VAR_0->mb_y == 0 || VAR_0->first_slice_line || VAR_0->first_gob_line)) {

        CHECK_MV(VAR_3[1][0]>>VAR_16, VAR_3[1][1]>>VAR_16)

    }else{

        CHECK_MV(VAR_3[4][0]>>VAR_16, VAR_3[4][1]>>VAR_16)

        if(VAR_12<Z_THRESHOLD){

            *VAR_1= VAR_3[4][0]>>VAR_16;

            *VAR_2= VAR_3[4][1]>>VAR_16;



            return VAR_12;

        }

        CHECK_MV(VAR_3[1][0]>>VAR_16, VAR_3[1][1]>>VAR_16)

        CHECK_MV(VAR_3[2][0]>>VAR_16, VAR_3[2][1]>>VAR_16)

        CHECK_MV(VAR_3[3][0]>>VAR_16, VAR_3[3][1]>>VAR_16)

    }

    CHECK_MV(VAR_3[0][0]>>VAR_16, VAR_3[0][1]>>VAR_16)



    VAR_12= small_diamond_search(VAR_0, VAR_10, VAR_12, new_pic, old_pic, VAR_13, 

                               VAR_4, VAR_5, mv_penalty, VAR_15, VAR_6, VAR_7, VAR_8, VAR_9, VAR_16);

    *VAR_1= VAR_10[0];

    *VAR_2= VAR_10[1];    







    return VAR_12;

}

static int FUNC_0(MpegEncContext * VAR_0,
int *VAR_1, int *VAR_2,
int VAR_3[5][2], int VAR_4, int VAR_5,
int VAR_6, int VAR_7, int VAR_8, int VAR_9)
{ int VAR_10[2]={0, 0}; int VAR_11, VAR_12; UINT8 *new_pic, *old_pic; const int VAR_13= VAR_0->linesize; const int VAR_14= (VAR_0->mb_y*VAR_13 + VAR_0->mb_x)*16; UINT16 *mv_penalty= VAR_0->mv_penalty[VAR_0->f_code] + MAX_MV; int VAR_15= VAR_0->qscale; const int VAR_16= 1+VAR_0->quarter_sample; new_pic = VAR_0->new_picture[0] + VAR_14; old_pic = VAR_0->last_picture[0] + VAR_14; VAR_12 = pix_abs16x16(new_pic, old_pic, VAR_13, 16); if(VAR_12<Z_THRESHOLD){ *VAR_1= 0; *VAR_2= 0; return VAR_12; } if ((VAR_0->mb_y == 0 || VAR_0->first_slice_line || VAR_0->first_gob_line)) { CHECK_MV(VAR_3[1][0]>>VAR_16, VAR_3[1][1]>>VAR_16)
}else{ CHECK_MV(VAR_3[4][0]>>VAR_16, VAR_3[4][1]>>VAR_16)
if(VAR_12<Z_THRESHOLD){ *VAR_1= VAR_3[4][0]>>VAR_16; *VAR_2= VAR_3[4][1]>>VAR_16; return VAR_12; } CHECK_MV(VAR_3[1][0]>>VAR_16, VAR_3[1][1]>>VAR_16)
CHECK_MV(VAR_3[2][0]>>VAR_16, VAR_3[2][1]>>VAR_16)
CHECK_MV(VAR_3[3][0]>>VAR_16, VAR_3[3][1]>>VAR_16)
} CHECK_MV(VAR_3[0][0]>>VAR_16, VAR_3[0][1]>>VAR_16)
VAR_12= small_diamond_search(VAR_0, VAR_10, VAR_12, new_pic, old_pic, VAR_13,
VAR_4, VAR_5, mv_penalty, VAR_15, VAR_6, VAR_7, VAR_8, VAR_9, VAR_16); *VAR_1= VAR_10[0]; *VAR_2= VAR_10[1]; return VAR_12; }