libavcodec/motion_est.c:1890: error: Buffer Overrun L1
  Offset: 8 Size: 4 by call to `ff_estimate_motion_b`.

libavcodec/motion_est.c:1890:17: Call
1888.             if(type == CANDIDATE_MB_TYPE_FORWARD || type == CANDIDATE_MB_TYPE_BIDIR){
1889.                 c->skip=0;
1890.                 ff_estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code);
                      ^
1891.             }
1892.             if(type == CANDIDATE_MB_TYPE_BACKWARD || type == CANDIDATE_MB_TYPE_BIDIR){

libavcodec/motion_est.c:1481:1: Parameter `ref_index`
  1479. }
  1480. 
  1481. static int ff_estimate_motion_b(MpegEncContext * s,
        ^
  1482.                        int mb_x, int mb_y, int16_t (*mv_table)[2], int ref_index, int f_code)
  1483. {

libavcodec/motion_est.c:1564:15: Call
  1562. 
  1563.     if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)
  1564.         dmin= ff_get_mb_score(s, mx, my, 0, ref_index, 0, 16, 1);
                      ^
  1565. 
  1566. //printf("%d %d %d %d//", s->mb_x, s->mb_y, mx, my);

libavcodec/motion_est_template.c:235:1: Parameter `ref_index`
    233. }
    234. 
    235. inline int ff_get_mb_score(MpegEncContext * s, int mx, int my, int src_index,
         ^
    236.                                int ref_index, int size, int h, int add_rate)
    237. {

libavcodec/motion_est_template.c:257:8: Call
    255. //    assert(c->avctx->me_sub_cmp != c->avctx->mb_cmp);
    256. 
    257.     d= cmp(s, mx>>(qpel+1), my>>(qpel+1), mx&mask, my&mask, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
                ^
    258.     //FIXME check cbp before adding penalty for (0,0) vector
    259.     if(add_rate && (mx || my || size>0))

libavcodec/motion_est.c:108:1: <Length trace>
106.     against a proposed motion-compensated prediction of that block
107.  */
108. static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
     ^
109.                       const int size, const int h, int ref_index, int src_index,
110.                       me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){

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

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

libavcodec/motion_est.c:176:50: Array access: Offset: 8 Size: 4 by call to `ff_estimate_motion_b` 
      174. 
      175.                     c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16);
      176.                     c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16);
                                                            ^
      177.                 }
      178.             }

static av_always_inline int cmp(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, const int flags){
    MotionEstContext * const c= &s->me;
    const int stride= c->stride;
    const int uvstride= c->uvstride;
    const int qpel= flags&FLAG_QPEL;
    const int chroma= flags&FLAG_CHROMA;
    const int dxy= subx + (suby<<(1+qpel));
    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;
    if(flags&FLAG_DIRECT){
        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;
    }else{
        int uvdxy;
        if(dxy){
            if(qpel){
                c->qpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride);
                if(chroma){
                    int cx= hx/2;
                    int cy= hy/2;
                    cx= (cx>>1)|(cx&1);
                    cy= (cy>>1)|(cy&1);
                    uvdxy= (cx&1) + 2*(cy&1);
                }
            }else{
                c->hpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride, h);
                if(chroma)
                    uvdxy= dxy | (x&1) | (2*(y&1));
            }
            d = cmp_func(s, c->temp, src[0], stride, h);
        }else{
            d = cmp_func(s, src[0], ref[0] + x + y*stride, stride, h);
            if(chroma)
                uvdxy= (x&1) + 2*(y&1);
        }
        if(chroma){
            uint8_t * const uvtemp= c->temp + 16*stride;
            c->hpel_put[size+1][uvdxy](uvtemp  , ref[1] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);
            c->hpel_put[size+1][uvdxy](uvtemp+8, ref[2] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);
            d += chroma_cmp_func(s, uvtemp  , src[1], uvstride, h>>1);
            d += chroma_cmp_func(s, uvtemp+8, src[2], uvstride, h>>1);
        }
    }
#if 0
    if(full_pel){
        const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);
        score_map[index]= d;
    }
    d += (c->mv_penalty[hx - c->pred_x] + c->mv_penalty[hy - c->pred_y])*c->penalty_factor;
#endif
    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.data, s->last_picture.data, s->next_picture.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 == 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(c->avctx->me_threshold){\n        int vard= check_input_motion(s, mb_x, mb_y, 0);\n        if((vard+128)>>8 < c->avctx->me_threshold){\n             s->current_picture.mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8;\n            c->mc_mb_var_sum_temp += (vard+128)>>8;\n            return;\n        }\n        if((vard+128)>>8 < c->avctx->mb_threshold){\n            type= s->mb_type[mb_y*s->mb_stride + mb_x];\n            if(type == CANDIDATE_MB_TYPE_DIRECT){\n                direct_search(s, mb_x, mb_y);\n            }\n            if(type == CANDIDATE_MB_TYPE_FORWARD || type == CANDIDATE_MB_TYPE_BIDIR){\n                c->skip=0;\n                ff_estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code);\n            }\n            if(type == CANDIDATE_MB_TYPE_BACKWARD || type == CANDIDATE_MB_TYPE_BIDIR){\n                c->skip=0;\n                ff_estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code);\n            }\n            if(type == CANDIDATE_MB_TYPE_FORWARD_I || type == CANDIDATE_MB_TYPE_BIDIR_I){\n                c->skip=0;\n                c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;\n                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], 1);\n            }\n            if(type == CANDIDATE_MB_TYPE_BACKWARD_I || type == CANDIDATE_MB_TYPE_BIDIR_I){\n                c->skip=0;\n                c->current_mv_penalty= c->mv_penalty[s->b_code] + MAX_MV;\n                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], 1);\n            }\n            return;\n        }\n    }\n    if (s->codec_id == CODEC_ID_MPEG4)\n        dmin= direct_search(s, mb_x, mb_y);\n    else\n        dmin= INT_MAX;\n    c->skip=0;\n    fmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code) + 3*penalty_factor;\n    c->skip=0;\n    bmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code) + 2*penalty_factor;\n    c->skip=0;\n    fbmin= bidir_refine(s, mb_x, mb_y) + penalty_factor;\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 == CODEC_ID_MPEG4 && type&CANDIDATE_MB_TYPE_DIRECT && s->flags&CODEC_FLAG_MV0 && *(uint32_t*)s->b_direct_mv_table[xy])\n            type |= CANDIDATE_MB_TYPE_DIRECT0;\n#if 0\n        if(s->out_format == FMT_MPEG1)\n            type |= CANDIDATE_MB_TYPE_INTRA;\n#endif\n    }\n    s->mb_type[mb_y*s->mb_stride + mb_x]= type;\n}', 'static int ff_estimate_motion_b(MpegEncContext * s,\n                       int mb_x, int mb_y, 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        no_motion_search(s, &mx, &my);\n        dmin = 0;\n        mx-= mb_x*16;\n        my-= mb_y*16;\n        break;\n#if 0\n    case ME_FULL:\n        dmin = full_motion_search(s, &mx, &my, range, ref_picture);\n        mx-= mb_x*16;\n        my-= mb_y*16;\n        break;\n    case ME_LOG:\n        dmin = log_motion_search(s, &mx, &my, range / 2, ref_picture);\n        mx-= mb_x*16;\n        my-= mb_y*16;\n        break;\n    case ME_PHODS:\n        dmin = phods_motion_search(s, &mx, &my, range / 2, ref_picture);\n        mx-= mb_x*16;\n        my-= mb_y*16;\n        break;\n#endif\n    case ME_X1:\n    case ME_EPZS:\n       {\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        }\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= ff_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}', 'inline int ff_get_mb_score(MpegEncContext * s, int mx, int my, int src_index,\n                               int ref_index, int size, int h, int add_rate)\n{\n    MotionEstContext * const c= &s->me;\n    const int penalty_factor= c->mb_penalty_factor;\n    const int flags= c->mb_flags;\n    const int qpel= flags & FLAG_QPEL;\n    const int mask= 1+2*qpel;\n    me_cmp_func cmp_sub, chroma_cmp_sub;\n    int d;\n    LOAD_COMMON\n    cmp_sub= s->dsp.mb_cmp[size];\n    chroma_cmp_sub= s->dsp.mb_cmp[size+1];\n    d= cmp(s, mx>>(qpel+1), my>>(qpel+1), mx&mask, my&mask, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);\n    if(add_rate && (mx || my || size>0))\n        d += (mv_penalty[mx - pred_x] + mv_penalty[my - pred_y])*penalty_factor;\n    return d;\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    MotionEstContext * const c= &s->me;\n    const int stride= c->stride;\n    const int uvstride= c->uvstride;\n    const int qpel= flags&FLAG_QPEL;\n    const int chroma= flags&FLAG_CHROMA;\n    const int dxy= subx + (suby<<(1+qpel));\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    if(flags&FLAG_DIRECT){\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    }else{\n        int uvdxy;\n        if(dxy){\n            if(qpel){\n                c->qpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride);\n                if(chroma){\n                    int cx= hx/2;\n                    int cy= hy/2;\n                    cx= (cx>>1)|(cx&1);\n                    cy= (cy>>1)|(cy&1);\n                    uvdxy= (cx&1) + 2*(cy&1);\n                }\n            }else{\n                c->hpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride, h);\n                if(chroma)\n                    uvdxy= dxy | (x&1) | (2*(y&1));\n            }\n            d = cmp_func(s, c->temp, src[0], stride, h);\n        }else{\n            d = cmp_func(s, src[0], ref[0] + x + y*stride, stride, h);\n            if(chroma)\n                uvdxy= (x&1) + 2*(y&1);\n        }\n        if(chroma){\n            uint8_t * const uvtemp= c->temp + 16*stride;\n            c->hpel_put[size+1][uvdxy](uvtemp  , ref[1] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);\n            c->hpel_put[size+1][uvdxy](uvtemp+8, ref[2] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);\n            d += chroma_cmp_func(s, uvtemp  , src[1], uvstride, h>>1);\n            d += chroma_cmp_func(s, uvtemp+8, src[2], uvstride, h>>1);\n        }\n    }\n#if 0\n    if(full_pel){\n        const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\n        score_map[index]= d;\n    }\n    d += (c->mv_penalty[hx - c->pred_x] + c->mv_penalty[hy - c->pred_y])*c->penalty_factor;\n#endif\n    return d;\n}']