static int epzs_motion_search4(MpegEncContext * s,
                             int *mx_ptr, int *my_ptr, int P[10][2],
                             int src_index, int ref_index, int16_t (*last_mv)[2],
                             int ref_mv_scale)
{
    MotionEstContext * const c= &s->me;
    int best[2]={0, 0};
    int d, dmin;
    int map_generation;
    const int penalty_factor= c->penalty_factor;
    const int size=1;
    const int h=8;
    const int ref_mv_stride= s->mb_stride;
    const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
    me_cmp_func cmpf, chroma_cmpf;
    LOAD_COMMON
    int flags= c->flags;
    LOAD_COMMON2
    cmpf= s->dsp.me_cmp[size];
    chroma_cmpf= s->dsp.me_cmp[size+1];
    map_generation= update_map_generation(c);
    dmin = 1000000;
    if (s->first_slice_line) {
        CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
        CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
                        (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
        CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
    }else{
        CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
        CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
        CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
        CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)
        CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
        CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
                        (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
    }
    if(dmin>64*4){
        CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
                        (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
        if(s->mb_y+1<s->end_mb_y)
            CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
                            (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
    }
    dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
    *mx_ptr= best[0];
    *my_ptr= best[1];
    return dmin;
}
['static int epzs_motion_search4(MpegEncContext * s,\n                             int *mx_ptr, int *my_ptr, int P[10][2],\n                             int src_index, int ref_index, int16_t (*last_mv)[2],\n                             int ref_mv_scale)\n{\n    MotionEstContext * const c= &s->me;\n    int best[2]={0, 0};\n    int d, dmin;\n    int map_generation;\n    const int penalty_factor= c->penalty_factor;\n    const int size=1;\n    const int h=8;\n    const int ref_mv_stride= s->mb_stride;\n    const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;\n    me_cmp_func cmpf, chroma_cmpf;\n    LOAD_COMMON\n    int flags= c->flags;\n    LOAD_COMMON2\n    cmpf= s->dsp.me_cmp[size];\n    chroma_cmpf= s->dsp.me_cmp[size+1];\n    map_generation= update_map_generation(c);\n    dmin = 1000000;\n    if (s->first_slice_line) {\n        CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)\n        CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,\n                        (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)\n        CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)\n    }else{\n        CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)\n        CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)\n        CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)\n        CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)\n        CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)\n        CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,\n                        (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)\n    }\n    if(dmin>64*4){\n        CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,\n                        (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)\n        if(s->mb_y+1<s->end_mb_y)\n            CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,\n                            (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)\n    }\n    dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n    *mx_ptr= best[0];\n    *my_ptr= best[1];\n    return dmin;\n}']