static int var_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 dia_size;
    LOAD_COMMON
    LOAD_COMMON2
    int map_generation= c->map_generation;
    cmpf= s->dsp.me_cmp[size];
    chroma_cmpf= s->dsp.me_cmp[size+1];
    for(dia_size=1; dia_size<=c->dia_size; dia_size++){
        int dir, start, end;
        const int x= best[0];
        const int y= best[1];
        start= FFMAX(0, y + dia_size - ymax);
        end  = FFMIN(dia_size, xmax - x + 1);
        for(dir= start; dir<end; dir++){
            int d;
            CHECK_MV(x + dir           , y + dia_size - dir);
        }
        start= FFMAX(0, x + dia_size - xmax);
        end  = FFMIN(dia_size, y - ymin + 1);
        for(dir= start; dir<end; dir++){
            int d;
            CHECK_MV(x + dia_size - dir, y - dir           );
        }
        start= FFMAX(0, -y + dia_size + ymin );
        end  = FFMIN(dia_size, x - xmin + 1);
        for(dir= start; dir<end; dir++){
            int d;
            CHECK_MV(x - dir           , y - dia_size + dir);
        }
        start= FFMAX(0, -x + dia_size + xmin );
        end  = FFMIN(dia_size, ymax - y + 1);
        for(dir= start; dir<end; dir++){
            int d;
            CHECK_MV(x - dia_size + dir, y + dir           );
        }
        if(x!=best[0] || y!=best[1])
            dia_size=0;
#if 0
{
int dx, dy, i;
static int stats[8*8];
dx= FFABS(x-best[0]);
dy= FFABS(y-best[1]);
stats[dy*8 + dx] ++;
if(256*256*256*64 % (stats[0]+1)==0){
    for(i=0; i<64; i++){
        if((i&7)==0) printf("\n");
        printf("%6d ", stats[i]);
    }
    printf("\n");
}
}
#endif
    }
    return dmin;
}
['static int var_diamond_search(MpegEncContext * s, int *best, int dmin,\n                                       int src_index, int ref_index, int const penalty_factor,\n                                       int size, int h, int flags)\n{\n    MotionEstContext * const c= &s->me;\n    me_cmp_func cmpf, chroma_cmpf;\n    int dia_size;\n    LOAD_COMMON\n    LOAD_COMMON2\n    int map_generation= c->map_generation;\n    cmpf= s->dsp.me_cmp[size];\n    chroma_cmpf= s->dsp.me_cmp[size+1];\n    for(dia_size=1; dia_size<=c->dia_size; dia_size++){\n        int dir, start, end;\n        const int x= best[0];\n        const int y= best[1];\n        start= FFMAX(0, y + dia_size - ymax);\n        end  = FFMIN(dia_size, xmax - x + 1);\n        for(dir= start; dir<end; dir++){\n            int d;\n            CHECK_MV(x + dir           , y + dia_size - dir);\n        }\n        start= FFMAX(0, x + dia_size - xmax);\n        end  = FFMIN(dia_size, y - ymin + 1);\n        for(dir= start; dir<end; dir++){\n            int d;\n            CHECK_MV(x + dia_size - dir, y - dir           );\n        }\n        start= FFMAX(0, -y + dia_size + ymin );\n        end  = FFMIN(dia_size, x - xmin + 1);\n        for(dir= start; dir<end; dir++){\n            int d;\n            CHECK_MV(x - dir           , y - dia_size + dir);\n        }\n        start= FFMAX(0, -x + dia_size + xmin );\n        end  = FFMIN(dia_size, ymax - y + 1);\n        for(dir= start; dir<end; dir++){\n            int d;\n            CHECK_MV(x - dia_size + dir, y + dir           );\n        }\n        if(x!=best[0] || y!=best[1])\n            dia_size=0;\n#if 0\n{\nint dx, dy, i;\nstatic int stats[8*8];\ndx= FFABS(x-best[0]);\ndy= FFABS(y-best[1]);\nstats[dy*8 + dx] ++;\nif(256*256*256*64 % (stats[0]+1)==0){\n    for(i=0; i<64; i++){\n        if((i&7)==0) printf("\\n");\n        printf("%6d ", stats[i]);\n    }\n    printf("\\n");\n}\n}\n#endif\n    }\n    return dmin;\n}']