libavcodec/snow.c:2500: error: Buffer Overrun L1
  Offset: 8 Size: 4 by call to `ff_epzs_motion_search`.

libavcodec/snow.c:2500:20: Call
2498.         init_ref(c, current_data, s->last_picture[ref].data, NULL, block_w*x, block_w*y, 0);
2499. 
2500.         ref_score= ff_epzs_motion_search(&s->m, &ref_mx, &ref_my, P, 0, /*ref_index*/ 0, last_mv,
                         ^
2501.                                          (1<<16)>>shift, level-LOG2_MB_SIZE+4, block_w);
2502. 

libavcodec/motion_est_template.c:1153:1: Parameter `ref_index`
  1151. 
  1152. //this function is dedicated to the braindamaged gcc
  1153. inline int ff_epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr,
        ^
  1154.                              int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
  1155.                              int ref_mv_scale, int size, int h)

libavcodec/motion_est_template.c:1160:16: Call
  1158. //FIXME convert other functions in the same way if faster
  1159.     if(c->flags==0 && h==16 && size==0){
  1160.         return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, 0, 0, 16);
                       ^
  1161. //    case FLAG_QPEL:
  1162. //        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:1036:1: Parameter `ref_index`
    1034.    optimal mv.
    1035.  */
    1036. static av_always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx_ptr, int *my_ptr,
          ^
    1037.                              int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
    1038.                              int ref_mv_scale, int flags, int size, int h)

libavcodec/motion_est_template.c:1070:11: Call
    1068. 
    1069.     assert(cmpf);
    1070.     dmin= cmp(s, 0, 0, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
                    ^
    1071.     map[0]= map_generation;
    1072.     score_map[0]= dmin;

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

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

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

libavcodec/motion_est.c:235:16: Call
        233.                       me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){
        234.     if(flags&FLAG_DIRECT){
        235.         return cmp_direct_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&FLAG_QPEL);
                            ^
        236.     }else{
        237.         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:107:1: <Length trace>
105. }
106. 
107. static av_always_inline int cmp_direct_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
     ^
108.                       const int size, const int h, int ref_index, int src_index,
109.                       me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel){

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

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

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

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;
}
['static int encode_q_branch(SnowContext *s, int level, int x, int y){\n    uint8_t p_buffer[1024];\n    uint8_t i_buffer[1024];\n    uint8_t p_state[sizeof(s->block_state)];\n    uint8_t i_state[sizeof(s->block_state)];\n    RangeCoder pc, ic;\n    uint8_t *pbbak= s->c.bytestream;\n    uint8_t *pbbak_start= s->c.bytestream_start;\n    int score, score2, iscore, i_len, p_len, block_s, sum, base_bits;\n    const int w= s->b_width  << s->block_max_depth;\n    const int h= s->b_height << s->block_max_depth;\n    const int rem_depth= s->block_max_depth - level;\n    const int index= (x + y*w) << rem_depth;\n    const int block_w= 1<<(LOG2_MB_SIZE - level);\n    int trx= (x+1)<<rem_depth;\n    int try= (y+1)<<rem_depth;\n    const BlockNode *left  = x ? &s->block[index-1] : &null_block;\n    const BlockNode *top   = y ? &s->block[index-w] : &null_block;\n    const BlockNode *right = trx<w ? &s->block[index+1] : &null_block;\n    const BlockNode *bottom= try<h ? &s->block[index+w] : &null_block;\n    const BlockNode *tl    = y && x ? &s->block[index-w-1] : left;\n    const BlockNode *tr    = y && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl;\n    int pl = left->color[0];\n    int pcb= left->color[1];\n    int pcr= left->color[2];\n    int pmx, pmy;\n    int mx=0, my=0;\n    int l,cr,cb;\n    const int stride= s->current_picture.linesize[0];\n    const int uvstride= s->current_picture.linesize[1];\n    uint8_t *current_data[3]= { s->input_picture.data[0] + (x + y*  stride)*block_w,\n                                s->input_picture.data[1] + (x + y*uvstride)*block_w/2,\n                                s->input_picture.data[2] + (x + y*uvstride)*block_w/2};\n    int P[10][2];\n    int16_t last_mv[3][2];\n    int qpel= !!(s->avctx->flags & CODEC_FLAG_QPEL);\n    const int shift= 1+qpel;\n    MotionEstContext *c= &s->m.me;\n    int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref);\n    int mx_context= av_log2(2*FFABS(left->mx - top->mx));\n    int my_context= av_log2(2*FFABS(left->my - top->my));\n    int s_context= 2*left->level + 2*top->level + tl->level + tr->level;\n    int ref, best_ref, ref_score, ref_mx, ref_my;\n    assert(sizeof(s->block_state) >= 256);\n    if(s->keyframe){\n        set_blocks(s, level, x, y, pl, pcb, pcr, 0, 0, 0, BLOCK_INTRA);\n        return 0;\n    }\n    P_LEFT[0]= left->mx;\n    P_LEFT[1]= left->my;\n    P_TOP [0]= top->mx;\n    P_TOP [1]= top->my;\n    P_TOPRIGHT[0]= tr->mx;\n    P_TOPRIGHT[1]= tr->my;\n    last_mv[0][0]= s->block[index].mx;\n    last_mv[0][1]= s->block[index].my;\n    last_mv[1][0]= right->mx;\n    last_mv[1][1]= right->my;\n    last_mv[2][0]= bottom->mx;\n    last_mv[2][1]= bottom->my;\n    s->m.mb_stride=2;\n    s->m.mb_x=\n    s->m.mb_y= 0;\n    c->skip= 0;\n    assert(c->  stride ==   stride);\n    assert(c->uvstride == uvstride);\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= c->mv_penalty[s->m.f_code=1] + MAX_MV;\n    c->xmin = - x*block_w - 16+3;\n    c->ymin = - y*block_w - 16+3;\n    c->xmax = - (x+1)*block_w + (w<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-3;\n    c->ymax = - (y+1)*block_w + (h<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-3;\n    if(P_LEFT[0]     > (c->xmax<<shift)) P_LEFT[0]    = (c->xmax<<shift);\n    if(P_LEFT[1]     > (c->ymax<<shift)) P_LEFT[1]    = (c->ymax<<shift);\n    if(P_TOP[0]      > (c->xmax<<shift)) P_TOP[0]     = (c->xmax<<shift);\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[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<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    if (!y) {\n        c->pred_x= P_LEFT[0];\n        c->pred_y= P_LEFT[1];\n    } else {\n        c->pred_x = P_MEDIAN[0];\n        c->pred_y = P_MEDIAN[1];\n    }\n    score= INT_MAX;\n    best_ref= 0;\n    for(ref=0; ref<s->ref_frames; ref++){\n        init_ref(c, current_data, s->last_picture[ref].data, NULL, block_w*x, block_w*y, 0);\n        ref_score= ff_epzs_motion_search(&s->m, &ref_mx, &ref_my, P, 0,   0, last_mv,\n                                         (1<<16)>>shift, level-LOG2_MB_SIZE+4, block_w);\n        assert(ref_mx >= c->xmin);\n        assert(ref_mx <= c->xmax);\n        assert(ref_my >= c->ymin);\n        assert(ref_my <= c->ymax);\n        ref_score= c->sub_motion_search(&s->m, &ref_mx, &ref_my, ref_score, 0, 0, level-LOG2_MB_SIZE+4, block_w);\n        ref_score= ff_get_mb_score(&s->m, ref_mx, ref_my, 0, 0, level-LOG2_MB_SIZE+4, block_w, 0);\n        ref_score+= 2*av_log2(2*ref)*c->penalty_factor;\n        if(s->ref_mvs[ref]){\n            s->ref_mvs[ref][index][0]= ref_mx;\n            s->ref_mvs[ref][index][1]= ref_my;\n            s->ref_scores[ref][index]= ref_score;\n        }\n        if(score > ref_score){\n            score= ref_score;\n            best_ref= ref;\n            mx= ref_mx;\n            my= ref_my;\n        }\n    }\n    base_bits= get_rac_count(&s->c) - 8*(s->c.bytestream - s->c.bytestream_start);\n    pc= s->c;\n    pc.bytestream_start=\n    pc.bytestream= p_buffer;\n    memcpy(p_state, s->block_state, sizeof(s->block_state));\n    if(level!=s->block_max_depth)\n        put_rac(&pc, &p_state[4 + s_context], 1);\n    put_rac(&pc, &p_state[1 + left->type + top->type], 0);\n    if(s->ref_frames > 1)\n        put_symbol(&pc, &p_state[128 + 1024 + 32*ref_context], best_ref, 0);\n    pred_mv(s, &pmx, &pmy, best_ref, left, top, tr);\n    put_symbol(&pc, &p_state[128 + 32*(mx_context + 16*!!best_ref)], mx - pmx, 1);\n    put_symbol(&pc, &p_state[128 + 32*(my_context + 16*!!best_ref)], my - pmy, 1);\n    p_len= pc.bytestream - pc.bytestream_start;\n    score += (s->lambda2*(get_rac_count(&pc)-base_bits))>>FF_LAMBDA_SHIFT;\n    block_s= block_w*block_w;\n    sum = pix_sum(current_data[0], stride, block_w);\n    l= (sum + block_s/2)/block_s;\n    iscore = pix_norm1(current_data[0], stride, block_w) - 2*l*sum + l*l*block_s;\n    block_s= block_w*block_w>>2;\n    sum = pix_sum(current_data[1], uvstride, block_w>>1);\n    cb= (sum + block_s/2)/block_s;\n    sum = pix_sum(current_data[2], uvstride, block_w>>1);\n    cr= (sum + block_s/2)/block_s;\n    ic= s->c;\n    ic.bytestream_start=\n    ic.bytestream= i_buffer;\n    memcpy(i_state, s->block_state, sizeof(s->block_state));\n    if(level!=s->block_max_depth)\n        put_rac(&ic, &i_state[4 + s_context], 1);\n    put_rac(&ic, &i_state[1 + left->type + top->type], 1);\n    put_symbol(&ic, &i_state[32],  l-pl , 1);\n    put_symbol(&ic, &i_state[64], cb-pcb, 1);\n    put_symbol(&ic, &i_state[96], cr-pcr, 1);\n    i_len= ic.bytestream - ic.bytestream_start;\n    iscore += (s->lambda2*(get_rac_count(&ic)-base_bits))>>FF_LAMBDA_SHIFT;\n    assert(iscore < 255*255*256 + s->lambda2*10);\n    assert(iscore >= 0);\n    assert(l>=0 && l<=255);\n    assert(pl>=0 && pl<=255);\n    if(level==0){\n        int varc= iscore >> 8;\n        int vard= score >> 8;\n        if (vard <= 64 || vard < varc)\n            c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc);\n        else\n            c->scene_change_score+= s->m.qscale;\n    }\n    if(level!=s->block_max_depth){\n        put_rac(&s->c, &s->block_state[4 + s_context], 0);\n        score2 = encode_q_branch(s, level+1, 2*x+0, 2*y+0);\n        score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+0);\n        score2+= encode_q_branch(s, level+1, 2*x+0, 2*y+1);\n        score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+1);\n        score2+= s->lambda2>>FF_LAMBDA_SHIFT;\n        if(score2 < score && score2 < iscore)\n            return score2;\n    }\n    if(iscore < score){\n        pred_mv(s, &pmx, &pmy, 0, left, top, tr);\n        memcpy(pbbak, i_buffer, i_len);\n        s->c= ic;\n        s->c.bytestream_start= pbbak_start;\n        s->c.bytestream= pbbak + i_len;\n        set_blocks(s, level, x, y, l, cb, cr, pmx, pmy, 0, BLOCK_INTRA);\n        memcpy(s->block_state, i_state, sizeof(s->block_state));\n        return iscore;\n    }else{\n        memcpy(pbbak, p_buffer, p_len);\n        s->c= pc;\n        s->c.bytestream_start= pbbak_start;\n        s->c.bytestream= pbbak + p_len;\n        set_blocks(s, level, x, y, pl, pcb, pcr, mx, my, best_ref, 0);\n        memcpy(s->block_state, p_state, sizeof(s->block_state));\n        return score;\n    }\n}', 'inline int ff_epzs_motion_search(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 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    int 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->dsp.me_pre_cmp[size];\n        chroma_cmpf= s->dsp.me_pre_cmp[size+1];\n    }else{\n        penalty_factor= c->penalty_factor;\n        cmpf= s->dsp.me_cmp[size];\n        chroma_cmpf= s->dsp.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 == FF_B_TYPE && !(c->flags & FLAG_DIRECT)) || s->flags&CODEC_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 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}']