libavcodec/motion_est.c:1520: error: Buffer Overrun L1
  Offset: 10 (⇐ 2 + 8) Size: 4 by call to `estimate_motion_b`.

libavcodec/motion_est.c:1520:12: Call
1518. 
1519.     c->skip=0;
1520.     bmin = estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code) +
                 ^
1521.            2 * penalty_factor;
1522.     ff_dlog(s, " %d %d ", s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]);

libavcodec/motion_est.c:1098:1: Parameter `ref_index`
  1096. }
  1097. 
  1098. static int estimate_motion_b(MpegEncContext *s, int mb_x, int mb_y,
        ^
  1099.                              int16_t (*mv_table)[2], int ref_index, int f_code)
  1100. {

libavcodec/motion_est.c:1153:16: Call
  1151.         }
  1152. 
  1153.         dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, ref_index, s->p_mv_table, mv_scale, 0, 16);
                       ^
  1154. 
  1155.         break;

libavcodec/motion_est_template.c:976:1: Parameter `ref_index`
    974. 
    975. //this function is dedicated to the braindamaged gcc
    976. int ff_epzs_motion_search(MpegEncContext *s, int *mx_ptr, int *my_ptr,
         ^
    977.                           int P[10][2], int src_index, int ref_index,
    978.                           int16_t (*last_mv)[2], int ref_mv_scale,

libavcodec/motion_est_template.c:984:16: Call
    982. //FIXME convert other functions in the same way if faster
    983.     if(c->flags==0 && h==16 && size==0){
    984.         return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, 0, 0, 16);
                        ^
    985. //    case FLAG_QPEL:
    986. //        return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, FLAG_QPEL);

libavcodec/motion_est_template.c:859:1: Parameter `ref_index`
      857.    optimal mv.
      858.  */
      859. static av_always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx_ptr, int *my_ptr,
           ^
      860.                              int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
      861.                              int ref_mv_scale, int flags, int size, int h)

libavcodec/motion_est_template.c:966:11: Call
      964. 
      965. //check(best[0],best[1],0, b0)
      966.     dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
                     ^
      967. 
      968. //check(best[0],best[1],0, b1)

libavcodec/motion_est_template.c:831:1: Parameter `ref_index`
        829. }
        830. 
        831. static av_always_inline int diamond_search(MpegEncContext * s, int *best, int dmin,
             ^
        832.                                        int src_index, int ref_index, int const penalty_factor,
        833.                                        int size, int h, int flags){

libavcodec/motion_est_template.c:844:26: Call
        842.         return          full_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
        843.     else if(c->dia_size>768)
        844.         return           umh_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
                                      ^
        845.     else if(c->dia_size>512)
        846.         return           hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, c->dia_size&0xFF);

libavcodec/motion_est_template.c:573:1: Parameter `ref_index`
          571. }
          572. 
          573. static int umh_search(MpegEncContext * s, int *best, int dmin,
               ^
          574.                                        int src_index, int ref_index, int const penalty_factor,
          575.                                        int size, int h, int flags)

libavcodec/motion_est_template.c:595:9: Call
          593.     y= best[1];
          594.     for(x2=FFMAX(x-dia_size+1, xmin); x2<=FFMIN(x+dia_size-1,xmax); x2+=2){
          595.         CHECK_MV(x2, y);
                       ^
          596.     }
          597.     for(y2=FFMAX(y-dia_size/2+1, ymin); y2<=FFMIN(y+dia_size/2-1,ymax); y2+=2){

libavcodec/motion_est.c:256:1: Parameter `ref_index`
            254.     against a proposed motion-compensated prediction of that block
            255.  */
            256. static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
                 ^
            257.                       const int size, const int h, int ref_index, int src_index,
            258.                       me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){

libavcodec/motion_est.c:265:16: Call
            263.     }else if(av_builtin_constant_p(subx) && av_builtin_constant_p(suby)
            264.        && subx==0 && suby==0){
            265.         return cmp_fpel_internal(s,x,y,size,h,ref_index,src_index, cmp_func, chroma_cmp_func,flags);
                                ^
            266.     }else{
            267.         return cmp_internal(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags);

libavcodec/motion_est.c:233:1: Parameter `ref_index`
              231. }
              232. 
              233. static int cmp_fpel_internal(MpegEncContext *s, const int x, const int y,
                   ^
              234.                       const int size, const int h, int ref_index, int src_index,
              235.                       me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){

libavcodec/motion_est.c:237:16: Call
              235.                       me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){
              236.     if(flags&FLAG_DIRECT){
              237.         return cmp_direct_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&FLAG_QPEL);
                                  ^
              238.     }else{
              239.         return cmp_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0, flags&FLAG_CHROMA);

libavcodec/motion_est.c:109:1: <Length trace>
107. }
108. 
109. static av_always_inline int cmp_direct_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
     ^
110.                       const int size, const int h, int ref_index, int src_index,
111.                       me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel){

libavcodec/motion_est.c:109:1: Parameter `ref_index`
                107. }
                108. 
                109. static av_always_inline int cmp_direct_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
                     ^
                110.                       const int size, const int h, int ref_index, int src_index,
                111.                       me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel){

libavcodec/motion_est.c:116:5: Assignment
                114.     const int hx= subx + (x<<(1+qpel));
                115.     const int hy= suby + (y<<(1+qpel));
                116.     uint8_t * const * const ref= c->ref[ref_index];
                         ^
                117.     uint8_t * const * const src= c->src[src_index];
                118.     int d;

libavcodec/motion_est.c:172:50: Array access: Offset: 10 (⇐ 2 + 8) Size: 4 by call to `estimate_motion_b` 
                170. 
                171.                     c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16);
                172.                     c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16);
                                                                      ^
                173.                 }
                174.             }

static av_always_inline int cmp_direct_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
                      const int size, const int h, int ref_index, int src_index,
                      me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel){
    MotionEstContext * const c= &s->me;
    const int stride= c->stride;
    const int hx= subx + (x<<(1+qpel));
    const int hy= suby + (y<<(1+qpel));
    uint8_t * const * const ref= c->ref[ref_index];
    uint8_t * const * const src= c->src[src_index];
    int d;
        assert(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1));
        if(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1)){
            const int time_pp= s->pp_time;
            const int time_pb= s->pb_time;
            const int mask= 2*qpel+1;
            if(s->mv_type==MV_TYPE_8X8){
                int i;
                for(i=0; i<4; i++){
                    int fx = c->direct_basis_mv[i][0] + hx;
                    int fy = c->direct_basis_mv[i][1] + hy;
                    int bx = hx ? fx - c->co_located_mv[i][0] : c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(qpel+4));
                    int by = hy ? fy - c->co_located_mv[i][1] : c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(qpel+4));
                    int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));
                    int bxy= (bx&mask) + ((by&mask)<<(qpel+1));
                    uint8_t *dst= c->temp + 8*(i&1) + 8*stride*(i>>1);
                    if(qpel){
                        c->qpel_put[1][fxy](dst, ref[0] + (fx>>2) + (fy>>2)*stride, stride);
                        c->qpel_avg[1][bxy](dst, ref[8] + (bx>>2) + (by>>2)*stride, stride);
                    }else{
                        c->hpel_put[1][fxy](dst, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 8);
                        c->hpel_avg[1][bxy](dst, ref[8] + (bx>>1) + (by>>1)*stride, stride, 8);
                    }
                }
            }else{
                int fx = c->direct_basis_mv[0][0] + hx;
                int fy = c->direct_basis_mv[0][1] + hy;
                int bx = hx ? fx - c->co_located_mv[0][0] : (c->co_located_mv[0][0]*(time_pb - time_pp)/time_pp);
                int by = hy ? fy - c->co_located_mv[0][1] : (c->co_located_mv[0][1]*(time_pb - time_pp)/time_pp);
                int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));
                int bxy= (bx&mask) + ((by&mask)<<(qpel+1));
                if(qpel){
                    c->qpel_put[1][fxy](c->temp               , ref[0] + (fx>>2) + (fy>>2)*stride               , stride);
                    c->qpel_put[1][fxy](c->temp + 8           , ref[0] + (fx>>2) + (fy>>2)*stride + 8           , stride);
                    c->qpel_put[1][fxy](c->temp     + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride     + 8*stride, stride);
                    c->qpel_put[1][fxy](c->temp + 8 + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8 + 8*stride, stride);
                    c->qpel_avg[1][bxy](c->temp               , ref[8] + (bx>>2) + (by>>2)*stride               , stride);
                    c->qpel_avg[1][bxy](c->temp + 8           , ref[8] + (bx>>2) + (by>>2)*stride + 8           , stride);
                    c->qpel_avg[1][bxy](c->temp     + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride     + 8*stride, stride);
                    c->qpel_avg[1][bxy](c->temp + 8 + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8 + 8*stride, stride);
                }else{
                    assert((fx>>1) + 16*s->mb_x >= -16);
                    assert((fy>>1) + 16*s->mb_y >= -16);
                    assert((fx>>1) + 16*s->mb_x <= s->width);
                    assert((fy>>1) + 16*s->mb_y <= s->height);
                    assert((bx>>1) + 16*s->mb_x >= -16);
                    assert((by>>1) + 16*s->mb_y >= -16);
                    assert((bx>>1) + 16*s->mb_x <= s->width);
                    assert((by>>1) + 16*s->mb_y <= s->height);
                    c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16);
                    c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16);
                }
            }
            d = cmp_func(s, c->temp, src[0], stride, 16);
        }else
            d= 256*256*256*32;
    return d;
}
['void ff_estimate_b_frame_motion(MpegEncContext * s,\n                             int mb_x, int mb_y)\n{\n    MotionEstContext * const c= &s->me;\n    const int penalty_factor= c->mb_penalty_factor;\n    int fmin, bmin, dmin, fbmin, bimin, fimin;\n    int type=0;\n    const int xy = mb_y*s->mb_stride + mb_x;\n    init_ref(c, s->new_picture.f->data, s->last_picture.f->data,\n             s->next_picture.f->data, 16 * mb_x, 16 * mb_y, 2);\n    get_limits(s, 16*mb_x, 16*mb_y);\n    c->skip=0;\n    if (s->codec_id == AV_CODEC_ID_MPEG4 && s->next_picture.mbskip_table[xy]) {\n        int score= direct_search(s, mb_x, mb_y);\n        score= ((unsigned)(score*score + 128*256))>>16;\n        c->mc_mb_var_sum_temp += score;\n        s->current_picture.mc_mb_var[mb_y*s->mb_stride + mb_x] = score;\n        s->mb_type[mb_y*s->mb_stride + mb_x]= CANDIDATE_MB_TYPE_DIRECT0;\n        return;\n    }\n    if (s->codec_id == AV_CODEC_ID_MPEG4)\n        dmin= direct_search(s, mb_x, mb_y);\n    else\n        dmin= INT_MAX;\n    c->skip=0;\n    fmin = estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code) +\n           3 * penalty_factor;\n    c->skip=0;\n    bmin = estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code) +\n           2 * penalty_factor;\n    ff_dlog(s, " %d %d ", s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]);\n    c->skip=0;\n    fbmin= bidir_refine(s, mb_x, mb_y) + penalty_factor;\n    ff_dlog(s, "%d %d %d %d\\n", dmin, fmin, bmin, fbmin);\n    if(s->flags & CODEC_FLAG_INTERLACED_ME){\n        c->skip=0;\n        c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;\n        fimin= interlaced_search(s, 0,\n                                 s->b_field_mv_table[0], s->b_field_select_table[0],\n                                 s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1], 0);\n        c->current_mv_penalty= c->mv_penalty[s->b_code] + MAX_MV;\n        bimin= interlaced_search(s, 2,\n                                 s->b_field_mv_table[1], s->b_field_select_table[1],\n                                 s->b_back_mv_table[xy][0], s->b_back_mv_table[xy][1], 0);\n    }else\n        fimin= bimin= INT_MAX;\n    {\n        int score= fmin;\n        type = CANDIDATE_MB_TYPE_FORWARD;\n        if (dmin <= score){\n            score = dmin;\n            type = CANDIDATE_MB_TYPE_DIRECT;\n        }\n        if(bmin<score){\n            score=bmin;\n            type= CANDIDATE_MB_TYPE_BACKWARD;\n        }\n        if(fbmin<score){\n            score=fbmin;\n            type= CANDIDATE_MB_TYPE_BIDIR;\n        }\n        if(fimin<score){\n            score=fimin;\n            type= CANDIDATE_MB_TYPE_FORWARD_I;\n        }\n        if(bimin<score){\n            score=bimin;\n            type= CANDIDATE_MB_TYPE_BACKWARD_I;\n        }\n        score= ((unsigned)(score*score + 128*256))>>16;\n        c->mc_mb_var_sum_temp += score;\n        s->current_picture.mc_mb_var[mb_y*s->mb_stride + mb_x] = score;\n    }\n    if(c->avctx->mb_decision > FF_MB_DECISION_SIMPLE){\n        type= CANDIDATE_MB_TYPE_FORWARD | CANDIDATE_MB_TYPE_BACKWARD | CANDIDATE_MB_TYPE_BIDIR | CANDIDATE_MB_TYPE_DIRECT;\n        if(fimin < INT_MAX)\n            type |= CANDIDATE_MB_TYPE_FORWARD_I;\n        if(bimin < INT_MAX)\n            type |= CANDIDATE_MB_TYPE_BACKWARD_I;\n        if(fimin < INT_MAX && bimin < INT_MAX){\n            type |= CANDIDATE_MB_TYPE_BIDIR_I;\n        }\n        if(dmin>256*256*16) type&= ~CANDIDATE_MB_TYPE_DIRECT;\n        if (s->codec_id == AV_CODEC_ID_MPEG4 && type&CANDIDATE_MB_TYPE_DIRECT &&\n            s->mpv_flags & FF_MPV_FLAG_MV0 && *(uint32_t*)s->b_direct_mv_table[xy])\n            type |= CANDIDATE_MB_TYPE_DIRECT0;\n    }\n    s->mb_type[mb_y*s->mb_stride + mb_x]= type;\n}', 'static int estimate_motion_b(MpegEncContext *s, int mb_x, int mb_y,\n                             int16_t (*mv_table)[2], int ref_index, int f_code)\n{\n    MotionEstContext * const c= &s->me;\n    int mx, my, dmin;\n    int P[10][2];\n    const int shift= 1+s->quarter_sample;\n    const int mot_stride = s->mb_stride;\n    const int mot_xy = mb_y*mot_stride + mb_x;\n    uint8_t * const mv_penalty= c->mv_penalty[f_code] + MAX_MV;\n    int mv_scale;\n    c->penalty_factor    = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp);\n    c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp);\n    c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp);\n    c->current_mv_penalty= mv_penalty;\n    get_limits(s, 16*mb_x, 16*mb_y);\n    switch(s->me_method) {\n    case ME_ZERO:\n    default:\n        mx   = 0;\n        my   = 0;\n        dmin = 0;\n        break;\n    case ME_X1:\n    case ME_EPZS:\n        P_LEFT[0] = mv_table[mot_xy - 1][0];\n        P_LEFT[1] = mv_table[mot_xy - 1][1];\n        if (P_LEFT[0] > (c->xmax << shift)) P_LEFT[0] = (c->xmax << shift);\n        if (!s->first_slice_line) {\n            P_TOP[0]      = mv_table[mot_xy - mot_stride    ][0];\n            P_TOP[1]      = mv_table[mot_xy - mot_stride    ][1];\n            P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1][0];\n            P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1][1];\n            if (P_TOP[1] > (c->ymax << shift)) P_TOP[1] = (c->ymax << shift);\n            if (P_TOPRIGHT[0] < (c->xmin << shift)) P_TOPRIGHT[0] = (c->xmin << shift);\n            if (P_TOPRIGHT[1] > (c->ymax << shift)) P_TOPRIGHT[1] = (c->ymax << shift);\n            P_MEDIAN[0] = mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);\n            P_MEDIAN[1] = mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);\n        }\n        c->pred_x = P_LEFT[0];\n        c->pred_y = P_LEFT[1];\n        if(mv_table == s->b_forw_mv_table){\n            mv_scale= (s->pb_time<<16) / (s->pp_time<<shift);\n        }else{\n            mv_scale= ((s->pb_time - s->pp_time)<<16) / (s->pp_time<<shift);\n        }\n        dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, ref_index, s->p_mv_table, mv_scale, 0, 16);\n        break;\n    }\n    dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, ref_index, 0, 16);\n    if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)\n        dmin= get_mb_score(s, mx, my, 0, ref_index, 0, 16, 1);\n    mv_table[mot_xy][0]= mx;\n    mv_table[mot_xy][1]= my;\n    return dmin;\n}', 'int ff_epzs_motion_search(MpegEncContext *s, int *mx_ptr, int *my_ptr,\n                          int P[10][2], int src_index, int ref_index,\n                          int16_t (*last_mv)[2], int ref_mv_scale,\n                          int size, int h)\n{\n    MotionEstContext * const c= &s->me;\n    if(c->flags==0 && h==16 && size==0){\n        return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, 0, 0, 16);\n    }else{\n        return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, c->flags, size, h);\n    }\n}', 'static av_always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx_ptr, int *my_ptr,\n                             int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],\n                             int ref_mv_scale, int flags, int size, int h)\n{\n    MotionEstContext * const c= &s->me;\n    int best[2]={0, 0};\n    int d;\n    int dmin;\n    unsigned map_generation;\n    int penalty_factor;\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    LOAD_COMMON2\n    if(c->pre_pass){\n        penalty_factor= c->pre_penalty_factor;\n        cmpf           = s->mecc.me_pre_cmp[size];\n        chroma_cmpf    = s->mecc.me_pre_cmp[size + 1];\n    }else{\n        penalty_factor= c->penalty_factor;\n        cmpf           = s->mecc.me_cmp[size];\n        chroma_cmpf    = s->mecc.me_cmp[size + 1];\n    }\n    map_generation= update_map_generation(c);\n    assert(cmpf);\n    dmin= cmp(s, 0, 0, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\n    map[0]= map_generation;\n    score_map[0]= dmin;\n    if ((s->pict_type == AV_PICTURE_TYPE_B && !(c->flags & FLAG_DIRECT)) ||\n        s->mpv_flags & FF_MPV_FLAG_MV0)\n        dmin += (mv_penalty[pred_x] + mv_penalty[pred_y])*penalty_factor;\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    }else{\n        if(dmin<((h*h*s->avctx->mv0_threshold)>>8)\n                    && ( P_LEFT[0]    |P_LEFT[1]\n                        |P_TOP[0]     |P_TOP[1]\n                        |P_TOPRIGHT[0]|P_TOPRIGHT[1])==0){\n            *mx_ptr= 0;\n            *my_ptr= 0;\n            c->skip=1;\n            return dmin;\n        }\n        CHECK_MV(    P_MEDIAN[0] >>shift ,    P_MEDIAN[1] >>shift)\n        CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)  , (P_MEDIAN[1]>>shift)-1)\n        CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)  , (P_MEDIAN[1]>>shift)+1)\n        CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)-1, (P_MEDIAN[1]>>shift)  )\n        CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)+1, (P_MEDIAN[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_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    }\n    if(dmin>h*h*4){\n        if(c->pre_pass){\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->first_slice_line)\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        }else{\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    }\n    if(c->avctx->last_predictor_count){\n        const int count= c->avctx->last_predictor_count;\n        const int xstart= FFMAX(0, s->mb_x - count);\n        const int ystart= FFMAX(0, s->mb_y - count);\n        const int xend= FFMIN(s->mb_width , s->mb_x + count + 1);\n        const int yend= FFMIN(s->mb_height, s->mb_y + count + 1);\n        int mb_y;\n        for(mb_y=ystart; mb_y<yend; mb_y++){\n            int mb_x;\n            for(mb_x=xstart; mb_x<xend; mb_x++){\n                const int xy= mb_x + 1 + (mb_y + 1)*ref_mv_stride;\n                int mx= (last_mv[xy][0]*ref_mv_scale + (1<<15))>>16;\n                int my= (last_mv[xy][1]*ref_mv_scale + (1<<15))>>16;\n                if(mx>xmax || mx<xmin || my>ymax || my<ymin) continue;\n                CHECK_MV(mx,my)\n            }\n        }\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}', 'static av_always_inline int 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    MotionEstContext * const c= &s->me;\n    if(c->dia_size==-1)\n        return funny_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n    else if(c->dia_size<-1)\n        return   sab_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n    else if(c->dia_size<2)\n        return small_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n    else if(c->dia_size>1024)\n        return          full_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n    else if(c->dia_size>768)\n        return           umh_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n    else if(c->dia_size>512)\n        return           hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, c->dia_size&0xFF);\n    else if(c->dia_size>256)\n        return       l2s_dia_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n    else\n        return   var_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n}', 'static int umh_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    LOAD_COMMON\n    LOAD_COMMON2\n    unsigned map_generation = c->map_generation;\n    int x,y,x2,y2, i, j, d;\n    const int dia_size= c->dia_size&0xFE;\n    static const int hex[16][2]={{-4,-2}, {-4,-1}, {-4, 0}, {-4, 1}, {-4, 2},\n                                 { 4,-2}, { 4,-1}, { 4, 0}, { 4, 1}, { 4, 2},\n                                 {-2, 3}, { 0, 4}, { 2, 3},\n                                 {-2,-3}, { 0,-4}, { 2,-3},};\n    cmpf        = s->mecc.me_cmp[size];\n    chroma_cmpf = s->mecc.me_cmp[size + 1];\n    x= best[0];\n    y= best[1];\n    for(x2=FFMAX(x-dia_size+1, xmin); x2<=FFMIN(x+dia_size-1,xmax); x2+=2){\n        CHECK_MV(x2, y);\n    }\n    for(y2=FFMAX(y-dia_size/2+1, ymin); y2<=FFMIN(y+dia_size/2-1,ymax); y2+=2){\n        CHECK_MV(x, y2);\n    }\n    x= best[0];\n    y= best[1];\n    for(y2=FFMAX(y-2, ymin); y2<=FFMIN(y+2,ymax); y2++){\n        for(x2=FFMAX(x-2, xmin); x2<=FFMIN(x+2,xmax); x2++){\n            CHECK_MV(x2, y2);\n        }\n    }\n    for(j=1; j<=dia_size/4; j++){\n        for(i=0; i<16; i++){\n            CHECK_CLIPPED_MV(x+hex[i][0]*j, y+hex[i][1]*j);\n        }\n    }\n    return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, 2);\n}', 'static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby,\n                      const int size, const int h, int ref_index, int src_index,\n                      me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){\n    if(av_builtin_constant_p(flags) && av_builtin_constant_p(h) && av_builtin_constant_p(size)\n       && av_builtin_constant_p(subx) && av_builtin_constant_p(suby)\n       && flags==0 && h==16 && size==0 && subx==0 && suby==0){\n        return cmp_simple(s,x,y,ref_index,src_index, cmp_func, chroma_cmp_func);\n    }else if(av_builtin_constant_p(subx) && av_builtin_constant_p(suby)\n       && subx==0 && suby==0){\n        return cmp_fpel_internal(s,x,y,size,h,ref_index,src_index, cmp_func, chroma_cmp_func,flags);\n    }else{\n        return cmp_internal(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags);\n    }\n}', 'static int cmp_fpel_internal(MpegEncContext *s, const int x, const int y,\n                      const int size, const int h, int ref_index, int src_index,\n                      me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){\n    if(flags&FLAG_DIRECT){\n        return cmp_direct_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&FLAG_QPEL);\n    }else{\n        return cmp_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0, flags&FLAG_CHROMA);\n    }\n}', 'static av_always_inline int cmp_direct_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby,\n                      const int size, const int h, int ref_index, int src_index,\n                      me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel){\n    MotionEstContext * const c= &s->me;\n    const int stride= c->stride;\n    const int hx= subx + (x<<(1+qpel));\n    const int hy= suby + (y<<(1+qpel));\n    uint8_t * const * const ref= c->ref[ref_index];\n    uint8_t * const * const src= c->src[src_index];\n    int d;\n        assert(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1));\n        if(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1)){\n            const int time_pp= s->pp_time;\n            const int time_pb= s->pb_time;\n            const int mask= 2*qpel+1;\n            if(s->mv_type==MV_TYPE_8X8){\n                int i;\n                for(i=0; i<4; i++){\n                    int fx = c->direct_basis_mv[i][0] + hx;\n                    int fy = c->direct_basis_mv[i][1] + hy;\n                    int bx = hx ? fx - c->co_located_mv[i][0] : c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(qpel+4));\n                    int by = hy ? fy - c->co_located_mv[i][1] : c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(qpel+4));\n                    int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));\n                    int bxy= (bx&mask) + ((by&mask)<<(qpel+1));\n                    uint8_t *dst= c->temp + 8*(i&1) + 8*stride*(i>>1);\n                    if(qpel){\n                        c->qpel_put[1][fxy](dst, ref[0] + (fx>>2) + (fy>>2)*stride, stride);\n                        c->qpel_avg[1][bxy](dst, ref[8] + (bx>>2) + (by>>2)*stride, stride);\n                    }else{\n                        c->hpel_put[1][fxy](dst, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 8);\n                        c->hpel_avg[1][bxy](dst, ref[8] + (bx>>1) + (by>>1)*stride, stride, 8);\n                    }\n                }\n            }else{\n                int fx = c->direct_basis_mv[0][0] + hx;\n                int fy = c->direct_basis_mv[0][1] + hy;\n                int bx = hx ? fx - c->co_located_mv[0][0] : (c->co_located_mv[0][0]*(time_pb - time_pp)/time_pp);\n                int by = hy ? fy - c->co_located_mv[0][1] : (c->co_located_mv[0][1]*(time_pb - time_pp)/time_pp);\n                int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));\n                int bxy= (bx&mask) + ((by&mask)<<(qpel+1));\n                if(qpel){\n                    c->qpel_put[1][fxy](c->temp               , ref[0] + (fx>>2) + (fy>>2)*stride               , stride);\n                    c->qpel_put[1][fxy](c->temp + 8           , ref[0] + (fx>>2) + (fy>>2)*stride + 8           , stride);\n                    c->qpel_put[1][fxy](c->temp     + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride     + 8*stride, stride);\n                    c->qpel_put[1][fxy](c->temp + 8 + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8 + 8*stride, stride);\n                    c->qpel_avg[1][bxy](c->temp               , ref[8] + (bx>>2) + (by>>2)*stride               , stride);\n                    c->qpel_avg[1][bxy](c->temp + 8           , ref[8] + (bx>>2) + (by>>2)*stride + 8           , stride);\n                    c->qpel_avg[1][bxy](c->temp     + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride     + 8*stride, stride);\n                    c->qpel_avg[1][bxy](c->temp + 8 + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8 + 8*stride, stride);\n                }else{\n                    assert((fx>>1) + 16*s->mb_x >= -16);\n                    assert((fy>>1) + 16*s->mb_y >= -16);\n                    assert((fx>>1) + 16*s->mb_x <= s->width);\n                    assert((fy>>1) + 16*s->mb_y <= s->height);\n                    assert((bx>>1) + 16*s->mb_x >= -16);\n                    assert((by>>1) + 16*s->mb_y >= -16);\n                    assert((bx>>1) + 16*s->mb_x <= s->width);\n                    assert((by>>1) + 16*s->mb_y <= s->height);\n                    c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16);\n                    c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16);\n                }\n            }\n            d = cmp_func(s, c->temp, src[0], stride, 16);\n        }else\n            d= 256*256*256*32;\n    return d;\n}']