static av_always_inline int small_diamond_search(MpegEncContext * s, int *best, int dmin,

                                       int src_index, int ref_index, int const penalty_factor,

                                       int size, int h, int flags)

{

    MotionEstContext * const c= &s->me;

    me_cmp_func cmpf, chroma_cmpf;

    int next_dir=-1;

    LOAD_COMMON

    LOAD_COMMON2

    unsigned map_generation = c->map_generation;



    cmpf        = s->mecc.me_cmp[size];

    chroma_cmpf = s->mecc.me_cmp[size + 1];



    { /* ensure that the best point is in the MAP as h/qpel refinement needs it */

        const unsigned key = (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;

        const int index= ((best[1]<<ME_MAP_SHIFT) + best[0])&(ME_MAP_SIZE-1);

        if(map[index]!=key){ //this will be executed only very rarey

            score_map[index]= cmp(s, best[0], best[1], 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);

            map[index]= key;

        }

    }



    for(;;){

        int d;

        const int dir= next_dir;

        const int x= best[0];

        const int y= best[1];

        next_dir=-1;



        if(dir!=2 && x>xmin) CHECK_MV_DIR(x-1, y  , 0)

        if(dir!=3 && y>ymin) CHECK_MV_DIR(x  , y-1, 1)

        if(dir!=0 && x<xmax) CHECK_MV_DIR(x+1, y  , 2)

        if(dir!=1 && y<ymax) CHECK_MV_DIR(x  , y+1, 3)



        if(next_dir==-1){

            return dmin;

        }

    }

}

static av_always_inline int small_diamond_search(MpegEncContext * s, int *best, int dmin,

                                       int src_index, int ref_index, int const penalty_factor,

                                       int size, int h, int flags)

{

    MotionEstContext * const c= &s->me;

    me_cmp_func cmpf, chroma_cmpf;

    int next_dir=-1;

    LOAD_COMMON

    LOAD_COMMON2

    unsigned map_generation = c->map_generation;



    cmpf        = s->mecc.me_cmp[size];

    chroma_cmpf = s->mecc.me_cmp[size + 1];



    { 

        const unsigned key = (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;

        const int index= ((best[1]<<ME_MAP_SHIFT) + best[0])&(ME_MAP_SIZE-1);

        if(map[index]!=key){ 

            score_map[index]= cmp(s, best[0], best[1], 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);

            map[index]= key;

        }

    }



    for(;;){

        int d;

        const int dir= next_dir;

        const int x= best[0];

        const int y= best[1];

        next_dir=-1;



        if(dir!=2 && x>xmin) CHECK_MV_DIR(x-1, y  , 0)

        if(dir!=3 && y>ymin) CHECK_MV_DIR(x  , y-1, 1)

        if(dir!=0 && x<xmax) CHECK_MV_DIR(x+1, y  , 2)

        if(dir!=1 && y<ymax) CHECK_MV_DIR(x  , y+1, 3)



        if(next_dir==-1){

            return dmin;

        }

    }

}

        const unsigned key = (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;         const int index= ((best[1]<<ME_MAP_SHIFT) + best[0])&(ME_MAP_SIZE-1);
static av_always_inline int FUNC_0(MpegEncContext * s, int *best, int dmin,

                                       int src_index, int ref_index, int const penalty_factor,

                                       int size, int h, int flags)

{

    MotionEstContext * const c= &s->me;

    me_cmp_func cmpf, chroma_cmpf;

    int VAR_0=-1;

    LOAD_COMMON

    LOAD_COMMON2

    unsigned map_generation = c->map_generation;



    cmpf        = s->mecc.me_cmp[size];

    chroma_cmpf = s->mecc.me_cmp[size + 1];



    { 

        const unsigned VAR_1 = (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;

        const int VAR_2= ((best[1]<<ME_MAP_SHIFT) + best[0])&(ME_MAP_SIZE-1);

        if(map[VAR_2]!=VAR_1){ 

            score_map[VAR_2]= cmp(s, best[0], best[1], 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);

            map[VAR_2]= VAR_1;

        }

    }



    for(;;){

        int VAR_3;

        const int VAR_4= VAR_0;

        const int VAR_5= best[0];

        const int VAR_6= best[1];

        VAR_0=-1;



        if(VAR_4!=2 && VAR_5>xmin) CHECK_MV_DIR(VAR_5-1, VAR_6  , 0)

        if(VAR_4!=3 && VAR_6>ymin) CHECK_MV_DIR(VAR_5  , VAR_6-1, 1)

        if(VAR_4!=0 && VAR_5<xmax) CHECK_MV_DIR(VAR_5+1, VAR_6  , 2)

        if(VAR_4!=1 && VAR_6<ymax) CHECK_MV_DIR(VAR_5  , VAR_6+1, 3)



        if(VAR_0==-1){

            return dmin;

        }

    }

}

static av_always_inline int FUNC_0(MpegEncContext * s, int *best, int dmin,
int src_index, int ref_index, int const penalty_factor,
int size, int h, int flags)
{ MotionEstContext * const c= &s->me; me_cmp_func cmpf, chroma_cmpf; int VAR_0=-1; LOAD_COMMON
LOAD_COMMON2
unsigned map_generation = c->map_generation; cmpf        = s->mecc.me_cmp[size]; chroma_cmpf = s->mecc.me_cmp[size + 1]; { const unsigned VAR_1 = (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation; const int VAR_2= ((best[1]<<ME_MAP_SHIFT) + best[0])&(ME_MAP_SIZE-1); if(map[VAR_2]!=VAR_1){ score_map[VAR_2]= cmp(s, best[0], best[1], 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags); map[VAR_2]= VAR_1; } } for(;;){ int VAR_3; const int VAR_4= VAR_0; const int VAR_5= best[0]; const int VAR_6= best[1]; VAR_0=-1; if(VAR_4!=2 && VAR_5>xmin) CHECK_MV_DIR(VAR_5-1, VAR_6  , 0)
if(VAR_4!=3 && VAR_6>ymin) CHECK_MV_DIR(VAR_5  , VAR_6-1, 1)
if(VAR_4!=0 && VAR_5<xmax) CHECK_MV_DIR(VAR_5+1, VAR_6  , 2)
if(VAR_4!=1 && VAR_6<ymax) CHECK_MV_DIR(VAR_5  , VAR_6+1, 3)
if(VAR_0==-1){ return dmin; } } }