static inline int halfpel_motion_search(MpegEncContext * s,

				  int *mx_ptr, int *my_ptr, int dmin,

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

                                  int pred_x, int pred_y, uint8_t *ref_picture)

{

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

    const int quant= s->qscale;

    int pen_x, pen_y;

    int mx, my, mx1, my1, d, xx, yy, dminh;

    UINT8 *pix, *ptr;



    mx = *mx_ptr;

    my = *my_ptr;

    ptr = ref_picture + (my * s->linesize) + mx;



    xx = 16 * s->mb_x;

    yy = 16 * s->mb_y;

    pix =  s->new_picture[0] + (yy * s->linesize) + xx;

    

    dminh = dmin;



    if (mx > xmin && mx < xmax && 

        my > ymin && my < ymax) {



        mx= mx1= 2*(mx - xx);

        my= my1= 2*(my - yy);

        if(dmin < Z_THRESHOLD && mx==0 && my==0){

            *mx_ptr = 0;

            *my_ptr = 0;

            return dmin;

        }

        

        pen_x= pred_x + mx;

        pen_y= pred_y + my;



        ptr-= s->linesize;

        CHECK_HALF_MV(xy2, -1, -1)

        CHECK_HALF_MV(y2 ,  0, -1)

        CHECK_HALF_MV(xy2, +1, -1)

        

        ptr+= s->linesize;

        CHECK_HALF_MV(x2 , -1,  0)

        CHECK_HALF_MV(x2 , +1,  0)

        CHECK_HALF_MV(xy2, -1, +1)

        CHECK_HALF_MV(y2 ,  0, +1)

        CHECK_HALF_MV(xy2, +1, +1)



    }else{

        mx= 2*(mx - xx);

        my= 2*(my - yy);

    }



    *mx_ptr = mx;

    *my_ptr = my;

    return dminh;

}

static inline int halfpel_motion_search(MpegEncContext * s,

				  int *mx_ptr, int *my_ptr, int dmin,

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

                                  int pred_x, int pred_y, uint8_t *ref_picture)

{

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

    const int quant= s->qscale;

    int pen_x, pen_y;

    int mx, my, mx1, my1, d, xx, yy, dminh;

    UINT8 *pix, *ptr;



    mx = *mx_ptr;

    my = *my_ptr;

    ptr = ref_picture + (my * s->linesize) + mx;



    xx = 16 * s->mb_x;

    yy = 16 * s->mb_y;

    pix =  s->new_picture[0] + (yy * s->linesize) + xx;

    

    dminh = dmin;



    if (mx > xmin && mx < xmax && 

        my > ymin && my < ymax) {



        mx= mx1= 2*(mx - xx);

        my= my1= 2*(my - yy);

        if(dmin < Z_THRESHOLD && mx==0 && my==0){

            *mx_ptr = 0;

            *my_ptr = 0;

            return dmin;

        }

        

        pen_x= pred_x + mx;

        pen_y= pred_y + my;



        ptr-= s->linesize;

        CHECK_HALF_MV(xy2, -1, -1)

        CHECK_HALF_MV(y2 ,  0, -1)

        CHECK_HALF_MV(xy2, +1, -1)

        

        ptr+= s->linesize;

        CHECK_HALF_MV(x2 , -1,  0)

        CHECK_HALF_MV(x2 , +1,  0)

        CHECK_HALF_MV(xy2, -1, +1)

        CHECK_HALF_MV(y2 ,  0, +1)

        CHECK_HALF_MV(xy2, +1, +1)



    }else{

        mx= 2*(mx - xx);

        my= 2*(my - yy);

    }



    *mx_ptr = mx;

    *my_ptr = my;

    return dminh;

}

static inline int FUNC_0(MpegEncContext * VAR_0,

				  int *VAR_1, int *VAR_2, int VAR_3,

				  int VAR_4, int VAR_5, int VAR_6, int VAR_7,

                                  int VAR_8, int VAR_9, uint8_t *VAR_10)

{

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

    const int VAR_11= VAR_0->qscale;

    int VAR_12, VAR_13;

    int VAR_14, VAR_15, VAR_16, VAR_17, VAR_18, VAR_19, VAR_20, VAR_21;

    UINT8 *pix, *ptr;



    VAR_14 = *VAR_1;

    VAR_15 = *VAR_2;

    ptr = VAR_10 + (VAR_15 * VAR_0->linesize) + VAR_14;



    VAR_19 = 16 * VAR_0->mb_x;

    VAR_20 = 16 * VAR_0->mb_y;

    pix =  VAR_0->new_picture[0] + (VAR_20 * VAR_0->linesize) + VAR_19;

    

    VAR_21 = VAR_3;



    if (VAR_14 > VAR_4 && VAR_14 < VAR_6 && 

        VAR_15 > VAR_5 && VAR_15 < VAR_7) {



        VAR_14= VAR_16= 2*(VAR_14 - VAR_19);

        VAR_15= VAR_17= 2*(VAR_15 - VAR_20);

        if(VAR_3 < Z_THRESHOLD && VAR_14==0 && VAR_15==0){

            *VAR_1 = 0;

            *VAR_2 = 0;

            return VAR_3;

        }

        

        VAR_12= VAR_8 + VAR_14;

        VAR_13= VAR_9 + VAR_15;



        ptr-= VAR_0->linesize;

        CHECK_HALF_MV(xy2, -1, -1)

        CHECK_HALF_MV(y2 ,  0, -1)

        CHECK_HALF_MV(xy2, +1, -1)

        

        ptr+= VAR_0->linesize;

        CHECK_HALF_MV(x2 , -1,  0)

        CHECK_HALF_MV(x2 , +1,  0)

        CHECK_HALF_MV(xy2, -1, +1)

        CHECK_HALF_MV(y2 ,  0, +1)

        CHECK_HALF_MV(xy2, +1, +1)



    }else{

        VAR_14= 2*(VAR_14 - VAR_19);

        VAR_15= 2*(VAR_15 - VAR_20);

    }



    *VAR_1 = VAR_14;

    *VAR_2 = VAR_15;

    return VAR_21;

}

static inline int FUNC_0(MpegEncContext * VAR_0,
int *VAR_1, int *VAR_2, int VAR_3,
int VAR_4, int VAR_5, int VAR_6, int VAR_7,
int VAR_8, int VAR_9, uint8_t *VAR_10)
{ UINT16 *mv_penalty= VAR_0->mv_penalty[VAR_0->f_code] + MAX_MV; const int VAR_11= VAR_0->qscale; int VAR_12, VAR_13; int VAR_14, VAR_15, VAR_16, VAR_17, VAR_18, VAR_19, VAR_20, VAR_21; UINT8 *pix, *ptr; VAR_14 = *VAR_1; VAR_15 = *VAR_2; ptr = VAR_10 + (VAR_15 * VAR_0->linesize) + VAR_14; VAR_19 = 16 * VAR_0->mb_x; VAR_20 = 16 * VAR_0->mb_y; pix =  VAR_0->new_picture[0] + (VAR_20 * VAR_0->linesize) + VAR_19; VAR_21 = VAR_3; if (VAR_14 > VAR_4 && VAR_14 < VAR_6 &&
VAR_15 > VAR_5 && VAR_15 < VAR_7) { VAR_14= VAR_16= 2*(VAR_14 - VAR_19); VAR_15= VAR_17= 2*(VAR_15 - VAR_20); if(VAR_3 < Z_THRESHOLD && VAR_14==0 && VAR_15==0){ *VAR_1 = 0; *VAR_2 = 0; return VAR_3; } VAR_12= VAR_8 + VAR_14; VAR_13= VAR_9 + VAR_15; ptr-= VAR_0->linesize; CHECK_HALF_MV(xy2, -1, -1)
CHECK_HALF_MV(y2 ,  0, -1)
CHECK_HALF_MV(xy2, +1, -1)
ptr+= VAR_0->linesize; CHECK_HALF_MV(x2 , -1,  0)
CHECK_HALF_MV(x2 , +1,  0)
CHECK_HALF_MV(xy2, -1, +1)
CHECK_HALF_MV(y2 ,  0, +1)
CHECK_HALF_MV(xy2, +1, +1)
}else{ VAR_14= 2*(VAR_14 - VAR_19); VAR_15= 2*(VAR_15 - VAR_20); } *VAR_1 = VAR_14; *VAR_2 = VAR_15; return VAR_21; }