static int epzs_motion_search4(MpegEncContext * s, int block,

                             int *mx_ptr, int *my_ptr,

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

                             int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture)

{

    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*2 + (block>>1))*pic_stride + s->mb_x*2 + (block&1))*8;

    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 = ref_picture + pic_xy;

   

    dmin = pix_abs8x8(new_pic, old_pic, pic_stride);



    /* first line */

    if ((s->mb_y == 0 || s->first_slice_line || s->first_gob_line) && block<2) {

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

    }else{

        CHECK_MV4(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_MV4(P[1][0]>>shift, P[1][1]>>shift)

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

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

    }

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

    CHECK_MV4(P[5][0]>>shift, P[5][1]>>shift)



//check(best[0],best[1],0, b0)

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

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

//check(best[0],best[1],0, b1)

    *mx_ptr= best[0];

    *my_ptr= best[1];    



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

    return dmin;

}

static int epzs_motion_search4(MpegEncContext * s, int block,

                             int *mx_ptr, int *my_ptr,

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

                             int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture)

{

    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*2 + (block>>1))*pic_stride + s->mb_x*2 + (block&1))*8;

    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 = ref_picture + pic_xy;

   

    dmin = pix_abs8x8(new_pic, old_pic, pic_stride);



    

    if ((s->mb_y == 0 || s->first_slice_line || s->first_gob_line) && block<2) {

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

    }else{

        CHECK_MV4(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_MV4(P[1][0]>>shift, P[1][1]>>shift)

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

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

    }

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

    CHECK_MV4(P[5][0]>>shift, P[5][1]>>shift)





    dmin= small_diamond_search4MV(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;

}

static int FUNC_0(MpegEncContext * VAR_0, int VAR_1,

                             int *VAR_2, int *VAR_3,

                             int VAR_4[6][2], int VAR_5, int VAR_6,

                             int VAR_7, int VAR_8, int VAR_9, int VAR_10, uint8_t *VAR_11)

{

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

    int VAR_13, VAR_14; 

    UINT8 *new_pic, *old_pic;

    const int VAR_15= VAR_0->linesize;

    const int VAR_16= ((VAR_0->mb_y*2 + (VAR_1>>1))*VAR_15 + VAR_0->mb_x*2 + (VAR_1&1))*8;

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

    int VAR_17= VAR_0->qscale; 

    const int VAR_18= 1+VAR_0->quarter_sample;



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

    old_pic = VAR_11 + VAR_16;

   

    VAR_14 = pix_abs8x8(new_pic, old_pic, VAR_15);



    

    if ((VAR_0->mb_y == 0 || VAR_0->first_slice_line || VAR_0->first_gob_line) && VAR_1<2) {

        CHECK_MV4(VAR_4[1][0]>>VAR_18, VAR_4[1][1]>>VAR_18)

    }else{

        CHECK_MV4(VAR_4[4][0]>>VAR_18, VAR_4[4][1]>>VAR_18)

        if(VAR_14<Z_THRESHOLD){

            *VAR_2= VAR_4[4][0]>>VAR_18;

            *VAR_3= VAR_4[4][1]>>VAR_18;



            return VAR_14;

        }

        CHECK_MV4(VAR_4[1][0]>>VAR_18, VAR_4[1][1]>>VAR_18)

        CHECK_MV4(VAR_4[2][0]>>VAR_18, VAR_4[2][1]>>VAR_18)

        CHECK_MV4(VAR_4[3][0]>>VAR_18, VAR_4[3][1]>>VAR_18)

    }

    CHECK_MV4(VAR_4[0][0]>>VAR_18, VAR_4[0][1]>>VAR_18)

    CHECK_MV4(VAR_4[5][0]>>VAR_18, VAR_4[5][1]>>VAR_18)





    VAR_14= small_diamond_search4MV(VAR_0, VAR_12, VAR_14, new_pic, old_pic, VAR_15, 

                                   VAR_5, VAR_6, mv_penalty, VAR_17, VAR_7, VAR_8, VAR_9, VAR_10, VAR_18);



    *VAR_2= VAR_12[0];

    *VAR_3= VAR_12[1];    





    return VAR_14;

}

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