libavcodec/h264_cabac.c:2356: error: Buffer Overrun L1
  Offset: -1 Size: 2 by call to `decode_cabac_luma_residual`.

libavcodec/h264_cabac.c:2356:9: Call
2354.             h->last_qscale_diff=0;
2355. 
2356.         decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 0);
              ^
2357.         if(CHROMA444){
2358.             decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 1);

libavcodec/h264_cabac.c:1827:1: <Offset trace>
1825. }
1826. 
1827. static av_always_inline void decode_cabac_luma_residual( H264Context *h, const uint8_t *scan, const uint8_t *scan8x8, int pixel_shift, int mb_type, int cbp, int p )
      ^
1828. {
1829.     static const uint8_t ctx_cat[4][3] = {{0,6,10},{1,7,11},{2,8,12},{5,9,13}};

libavcodec/h264_cabac.c:1827:1: Parameter `p`
  1825. }
  1826. 
  1827. static av_always_inline void decode_cabac_luma_residual( H264Context *h, const uint8_t *scan, const uint8_t *scan8x8, int pixel_shift, int mb_type, int cbp, int p )
        ^
  1828. {
  1829.     static const uint8_t ctx_cat[4][3] = {{0,6,10},{1,7,11},{2,8,12},{5,9,13}};

libavcodec/h264_cabac.c:1827:1: <Length trace>
1825. }
1826. 
1827. static av_always_inline void decode_cabac_luma_residual( H264Context *h, const uint8_t *scan, const uint8_t *scan8x8, int pixel_shift, int mb_type, int cbp, int p )
      ^
1828. {
1829.     static const uint8_t ctx_cat[4][3] = {{0,6,10},{1,7,11},{2,8,12},{5,9,13}};

libavcodec/h264_cabac.c:1827:1: Parameter `h->chroma_qp[*]`
  1825. }
  1826. 
  1827. static av_always_inline void decode_cabac_luma_residual( H264Context *h, const uint8_t *scan, const uint8_t *scan8x8, int pixel_shift, int mb_type, int cbp, int p )
        ^
  1828. {
  1829.     static const uint8_t ctx_cat[4][3] = {{0,6,10},{1,7,11},{2,8,12},{5,9,13}};

libavcodec/h264_cabac.c:1832:39: Array access: Offset: -1 Size: 2 by call to `decode_cabac_luma_residual` 
  1830.     const uint32_t *qmul;
  1831.     int i8x8, i4x4;
  1832.     int qscale = p == 0 ? h->qscale : h->chroma_qp[p-1];
                                              ^
  1833.     if( IS_INTRA16x16( mb_type ) ) {
  1834.         AV_ZERO128(h->mb_luma_dc[p]+0);

static av_always_inline void decode_cabac_luma_residual( H264Context *h, const uint8_t *scan, const uint8_t *scan8x8, int pixel_shift, int mb_type, int cbp, int p )
{
    static const uint8_t ctx_cat[4][3] = {{0,6,10},{1,7,11},{2,8,12},{5,9,13}};
    const uint32_t *qmul;
    int i8x8, i4x4;
    int qscale = p == 0 ? h->qscale : h->chroma_qp[p-1];
    if( IS_INTRA16x16( mb_type ) ) {
        AV_ZERO128(h->mb_luma_dc[p]+0);
        AV_ZERO128(h->mb_luma_dc[p]+8);
        AV_ZERO128(h->mb_luma_dc[p]+16);
        AV_ZERO128(h->mb_luma_dc[p]+24);
        decode_cabac_residual_dc(h, h->mb_luma_dc[p], ctx_cat[0][p], LUMA_DC_BLOCK_INDEX+p, scan, 16);
        if( cbp&15 ) {
            qmul = h->dequant4_coeff[p][qscale];
            for( i4x4 = 0; i4x4 < 16; i4x4++ ) {
                const int index = 16*p + i4x4;
                decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[1][p], index, scan + 1, qmul, 15);
            }
        } else {
            fill_rectangle(&h->non_zero_count_cache[scan8[16*p]], 4, 4, 8, 0, 1);
        }
    } else {
        int cqm = (IS_INTRA( mb_type ) ? 0:3) + p;
        for( i8x8 = 0; i8x8 < 4; i8x8++ ) {
            if( cbp & (1<<i8x8) ) {
                if( IS_8x8DCT(mb_type) ) {
                    const int index = 16*p + 4*i8x8;
                    decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[3][p], index,
                                                scan8x8, h->dequant8_coeff[cqm][qscale], 64);
                } else {
                    qmul = h->dequant4_coeff[cqm][qscale];
                    for( i4x4 = 0; i4x4 < 4; i4x4++ ) {
                        const int index = 16*p + 4*i8x8 + i4x4;
                        decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[2][p], index, scan, qmul, 16);
                    }
                }
            } else {
                fill_rectangle(&h->non_zero_count_cache[scan8[4*i8x8+16*p]], 2, 2, 8, 0, 1);
            }
        }
    }
}
['int ff_h264_decode_mb_cabac(H264Context *h) {\n    int mb_xy;\n    int mb_type, partition_count, cbp = 0;\n    int dct8x8_allowed= h->pps.transform_8x8_mode;\n    int decode_chroma = h->sps.chroma_format_idc == 1 || h->sps.chroma_format_idc == 2;\n    const int pixel_shift = h->pixel_shift;\n    mb_xy = h->mb_xy = h->mb_x + h->mb_y*h->mb_stride;\n    tprintf(h->avctx, "pic:%d mb:%d/%d\\n", h->frame_num, h->mb_x, h->mb_y);\n    if( h->slice_type_nos != AV_PICTURE_TYPE_I ) {\n        int skip;\n        if( FRAME_MBAFF && (h->mb_y&1)==1 && h->prev_mb_skipped )\n            skip = h->next_mb_skipped;\n        else\n            skip = decode_cabac_mb_skip( h, h->mb_x, h->mb_y );\n        if( skip ) {\n            if( FRAME_MBAFF && (h->mb_y&1)==0 ){\n                h->cur_pic.f.mb_type[mb_xy] = MB_TYPE_SKIP;\n                h->next_mb_skipped = decode_cabac_mb_skip( h, h->mb_x, h->mb_y+1 );\n                if(!h->next_mb_skipped)\n                    h->mb_mbaff = h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);\n            }\n            decode_mb_skip(h);\n            h->cbp_table[mb_xy] = 0;\n            h->chroma_pred_mode_table[mb_xy] = 0;\n            h->last_qscale_diff = 0;\n            return 0;\n        }\n    }\n    if(FRAME_MBAFF){\n        if( (h->mb_y&1) == 0 )\n            h->mb_mbaff =\n            h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);\n    }\n    h->prev_mb_skipped = 0;\n    fill_decode_neighbors(h, -(MB_FIELD));\n    if( h->slice_type_nos == AV_PICTURE_TYPE_B ) {\n        int ctx = 0;\n        assert(h->slice_type_nos == AV_PICTURE_TYPE_B);\n        if( !IS_DIRECT( h->left_type[LTOP]-1 ) )\n            ctx++;\n        if( !IS_DIRECT( h->top_type-1 ) )\n            ctx++;\n        if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+ctx] ) ){\n            mb_type= 0;\n        }else if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+3] ) ) {\n            mb_type= 1 + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );\n        }else{\n            int bits;\n            bits = get_cabac_noinline( &h->cabac, &h->cabac_state[27+4] ) << 3;\n            bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 2;\n            bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 1;\n            bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );\n            if( bits < 8 ){\n                mb_type= bits + 3;\n            }else if( bits == 13 ){\n                mb_type= decode_cabac_intra_mb_type(h, 32, 0);\n                goto decode_intra_mb;\n            }else if( bits == 14 ){\n                mb_type= 11;\n            }else if( bits == 15 ){\n                mb_type= 22;\n            }else{\n                bits= ( bits<<1 ) + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );\n                mb_type= bits - 4;\n            }\n        }\n            partition_count= b_mb_type_info[mb_type].partition_count;\n            mb_type=         b_mb_type_info[mb_type].type;\n    } else if( h->slice_type_nos == AV_PICTURE_TYPE_P ) {\n        if( get_cabac_noinline( &h->cabac, &h->cabac_state[14] ) == 0 ) {\n            if( get_cabac_noinline( &h->cabac, &h->cabac_state[15] ) == 0 ) {\n                mb_type= 3 * get_cabac_noinline( &h->cabac, &h->cabac_state[16] );\n            } else {\n                mb_type= 2 - get_cabac_noinline( &h->cabac, &h->cabac_state[17] );\n            }\n            partition_count= p_mb_type_info[mb_type].partition_count;\n            mb_type=         p_mb_type_info[mb_type].type;\n        } else {\n            mb_type= decode_cabac_intra_mb_type(h, 17, 0);\n            goto decode_intra_mb;\n        }\n    } else {\n        mb_type= decode_cabac_intra_mb_type(h, 3, 1);\n        if(h->slice_type == AV_PICTURE_TYPE_SI && mb_type)\n            mb_type--;\n        assert(h->slice_type_nos == AV_PICTURE_TYPE_I);\ndecode_intra_mb:\n        partition_count = 0;\n        cbp= i_mb_type_info[mb_type].cbp;\n        h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode;\n        mb_type= i_mb_type_info[mb_type].type;\n    }\n    if(MB_FIELD)\n        mb_type |= MB_TYPE_INTERLACED;\n    h->slice_table[ mb_xy ]= h->slice_num;\n    if(IS_INTRA_PCM(mb_type)) {\n        const int mb_size = ff_h264_mb_sizes[h->sps.chroma_format_idc] *\n                            h->sps.bit_depth_luma >> 3;\n        const uint8_t *ptr;\n        ptr= h->cabac.bytestream;\n        if(h->cabac.low&0x1) ptr--;\n        if(CABAC_BITS==16){\n            if(h->cabac.low&0x1FF) ptr--;\n        }\n        if ((int) (h->cabac.bytestream_end - ptr) < mb_size)\n            return -1;\n        memcpy(h->mb, ptr, mb_size); ptr+=mb_size;\n        ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);\n        h->cbp_table[mb_xy] = 0xf7ef;\n        h->chroma_pred_mode_table[mb_xy] = 0;\n        h->cur_pic.f.qscale_table[mb_xy] = 0;\n        memset(h->non_zero_count[mb_xy], 16, 48);\n        h->cur_pic.f.mb_type[mb_xy] = mb_type;\n        h->last_qscale_diff = 0;\n        return 0;\n    }\n    fill_decode_caches(h, mb_type);\n    if( IS_INTRA( mb_type ) ) {\n        int i, pred_mode;\n        if( IS_INTRA4x4( mb_type ) ) {\n            if( dct8x8_allowed && get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] ) ) {\n                mb_type |= MB_TYPE_8x8DCT;\n                for( i = 0; i < 16; i+=4 ) {\n                    int pred = pred_intra_mode( h, i );\n                    int mode = decode_cabac_mb_intra4x4_pred_mode( h, pred );\n                    fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 );\n                }\n            } else {\n                for( i = 0; i < 16; i++ ) {\n                    int pred = pred_intra_mode( h, i );\n                    h->intra4x4_pred_mode_cache[ scan8[i] ] = decode_cabac_mb_intra4x4_pred_mode( h, pred );\n                    av_dlog(h->avctx, "i4x4 pred=%d mode=%d\\n", pred,\n                            h->intra4x4_pred_mode_cache[scan8[i]]);\n                }\n            }\n            write_back_intra_pred_mode(h);\n            if( ff_h264_check_intra4x4_pred_mode(h) < 0 ) return -1;\n        } else {\n            h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode( h, h->intra16x16_pred_mode, 0 );\n            if( h->intra16x16_pred_mode < 0 ) return -1;\n        }\n        if(decode_chroma){\n            h->chroma_pred_mode_table[mb_xy] =\n            pred_mode                        = decode_cabac_mb_chroma_pre_mode( h );\n            pred_mode= ff_h264_check_intra_pred_mode( h, pred_mode, 1 );\n            if( pred_mode < 0 ) return -1;\n            h->chroma_pred_mode= pred_mode;\n        } else {\n            h->chroma_pred_mode= DC_128_PRED8x8;\n        }\n    } else if( partition_count == 4 ) {\n        int i, j, sub_partition_count[4], list, ref[2][4];\n        if( h->slice_type_nos == AV_PICTURE_TYPE_B ) {\n            for( i = 0; i < 4; i++ ) {\n                h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h );\n                sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n                h->sub_mb_type[i]=      b_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n            }\n            if( IS_DIRECT(h->sub_mb_type[0] | h->sub_mb_type[1] |\n                          h->sub_mb_type[2] | h->sub_mb_type[3]) ) {\n                ff_h264_pred_direct_motion(h, &mb_type);\n                h->ref_cache[0][scan8[4]] =\n                h->ref_cache[1][scan8[4]] =\n                h->ref_cache[0][scan8[12]] =\n                h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;\n                    for( i = 0; i < 4; i++ )\n                        fill_rectangle( &h->direct_cache[scan8[4*i]], 2, 2, 8, (h->sub_mb_type[i]>>1)&0xFF, 1 );\n            }\n        } else {\n            for( i = 0; i < 4; i++ ) {\n                h->sub_mb_type[i] = decode_cabac_p_mb_sub_type( h );\n                sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n                h->sub_mb_type[i]=      p_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n            }\n        }\n        for( list = 0; list < h->list_count; list++ ) {\n                for( i = 0; i < 4; i++ ) {\n                    if(IS_DIRECT(h->sub_mb_type[i])) continue;\n                    if(IS_DIR(h->sub_mb_type[i], 0, list)){\n                        int rc = h->ref_count[list] << MB_MBAFF;\n                        if (rc > 1) {\n                            ref[list][i] = decode_cabac_mb_ref( h, list, 4*i );\n                            if (ref[list][i] >= (unsigned) rc) {\n                                av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref[list][i], rc);\n                                return -1;\n                            }\n                        }else\n                            ref[list][i] = 0;\n                    } else {\n                        ref[list][i] = -1;\n                    }\n                                                       h->ref_cache[list][ scan8[4*i]+1 ]=\n                    h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];\n                }\n        }\n        if(dct8x8_allowed)\n            dct8x8_allowed = get_dct8x8_allowed(h);\n        for(list=0; list<h->list_count; list++){\n            for(i=0; i<4; i++){\n                h->ref_cache[list][ scan8[4*i]   ]=h->ref_cache[list][ scan8[4*i]+1 ];\n                if(IS_DIRECT(h->sub_mb_type[i])){\n                    fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 2);\n                    continue;\n                }\n                if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){\n                    const int sub_mb_type= h->sub_mb_type[i];\n                    const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;\n                    for(j=0; j<sub_partition_count[i]; j++){\n                        int mpx, mpy;\n                        int mx, my;\n                        const int index= 4*i + block_width*j;\n                        int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];\n                        uint8_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ];\n                        pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my);\n                        DECODE_CABAC_MB_MVD( h, list, index)\n                        tprintf(h->avctx, "final mv:%d %d\\n", mx, my);\n                        if(IS_SUB_8X8(sub_mb_type)){\n                            mv_cache[ 1 ][0]=\n                            mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;\n                            mv_cache[ 1 ][1]=\n                            mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;\n                            mvd_cache[ 1 ][0]=\n                            mvd_cache[ 8 ][0]= mvd_cache[ 9 ][0]= mpx;\n                            mvd_cache[ 1 ][1]=\n                            mvd_cache[ 8 ][1]= mvd_cache[ 9 ][1]= mpy;\n                        }else if(IS_SUB_8X4(sub_mb_type)){\n                            mv_cache[ 1 ][0]= mx;\n                            mv_cache[ 1 ][1]= my;\n                            mvd_cache[ 1 ][0]=  mpx;\n                            mvd_cache[ 1 ][1]= mpy;\n                        }else if(IS_SUB_4X8(sub_mb_type)){\n                            mv_cache[ 8 ][0]= mx;\n                            mv_cache[ 8 ][1]= my;\n                            mvd_cache[ 8 ][0]= mpx;\n                            mvd_cache[ 8 ][1]= mpy;\n                        }\n                        mv_cache[ 0 ][0]= mx;\n                        mv_cache[ 0 ][1]= my;\n                        mvd_cache[ 0 ][0]= mpx;\n                        mvd_cache[ 0 ][1]= mpy;\n                    }\n                }else{\n                    fill_rectangle(h->mv_cache [list][ scan8[4*i] ], 2, 2, 8, 0, 4);\n                    fill_rectangle(h->mvd_cache[list][ scan8[4*i] ], 2, 2, 8, 0, 2);\n                }\n            }\n        }\n    } else if( IS_DIRECT(mb_type) ) {\n        ff_h264_pred_direct_motion(h, &mb_type);\n        fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 2);\n        fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 2);\n        dct8x8_allowed &= h->sps.direct_8x8_inference_flag;\n    } else {\n        int list, i;\n        if(IS_16X16(mb_type)){\n            for(list=0; list<h->list_count; list++){\n                if(IS_DIR(mb_type, 0, list)){\n                    int ref, rc = h->ref_count[list] << MB_MBAFF;\n                    if (rc > 1) {\n                        ref= decode_cabac_mb_ref(h, list, 0);\n                        if (ref >= (unsigned) rc) {\n                            av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, rc);\n                            return -1;\n                        }\n                    }else\n                        ref=0;\n                        fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, ref, 1);\n                }\n            }\n            for(list=0; list<h->list_count; list++){\n                if(IS_DIR(mb_type, 0, list)){\n                    int mx,my,mpx,mpy;\n                    pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);\n                    DECODE_CABAC_MB_MVD( h, list, 0)\n                    tprintf(h->avctx, "final mv:%d %d\\n", mx, my);\n                    fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack8to16(mpx,mpy), 2);\n                    fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);\n                }\n            }\n        }\n        else if(IS_16X8(mb_type)){\n            for(list=0; list<h->list_count; list++){\n                    for(i=0; i<2; i++){\n                        if(IS_DIR(mb_type, i, list)){\n                            int ref, rc = h->ref_count[list] << MB_MBAFF;\n                            if (rc > 1) {\n                                ref= decode_cabac_mb_ref( h, list, 8*i );\n                                if (ref >= (unsigned) rc) {\n                                    av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, rc);\n                                    return -1;\n                                }\n                            }else\n                                ref=0;\n                            fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1);\n                        }else\n                            fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1);\n                    }\n            }\n            for(list=0; list<h->list_count; list++){\n                for(i=0; i<2; i++){\n                    if(IS_DIR(mb_type, i, list)){\n                        int mx,my,mpx,mpy;\n                        pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my);\n                        DECODE_CABAC_MB_MVD( h, list, 8*i)\n                        tprintf(h->avctx, "final mv:%d %d\\n", mx, my);\n                        fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack8to16(mpx,mpy), 2);\n                        fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4);\n                    }else{\n                        fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 2);\n                        fill_rectangle(h-> mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4);\n                    }\n                }\n            }\n        }else{\n            assert(IS_8X16(mb_type));\n            for(list=0; list<h->list_count; list++){\n                    for(i=0; i<2; i++){\n                        if(IS_DIR(mb_type, i, list)){\n                            int ref, rc = h->ref_count[list] << MB_MBAFF;\n                            if (rc > 1) {\n                                ref= decode_cabac_mb_ref( h, list, 4*i );\n                                if (ref >= (unsigned) rc) {\n                                    av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, rc);\n                                    return -1;\n                                }\n                            }else\n                                ref=0;\n                            fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1);\n                        }else\n                            fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1);\n                    }\n            }\n            for(list=0; list<h->list_count; list++){\n                for(i=0; i<2; i++){\n                    if(IS_DIR(mb_type, i, list)){\n                        int mx,my,mpx,mpy;\n                        pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);\n                        DECODE_CABAC_MB_MVD( h, list, 4*i)\n                        tprintf(h->avctx, "final mv:%d %d\\n", mx, my);\n                        fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack8to16(mpx,mpy), 2);\n                        fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4);\n                    }else{\n                        fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 2);\n                        fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4);\n                    }\n                }\n            }\n        }\n    }\n   if( IS_INTER( mb_type ) ) {\n        h->chroma_pred_mode_table[mb_xy] = 0;\n        write_back_motion( h, mb_type );\n   }\n    if( !IS_INTRA16x16( mb_type ) ) {\n        cbp  = decode_cabac_mb_cbp_luma( h );\n        if(decode_chroma)\n            cbp |= decode_cabac_mb_cbp_chroma( h ) << 4;\n    }\n    h->cbp_table[mb_xy] = h->cbp = cbp;\n    if( dct8x8_allowed && (cbp&15) && !IS_INTRA( mb_type ) ) {\n        mb_type |= MB_TYPE_8x8DCT * get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] );\n    }\n    if (CHROMA444 && IS_8x8DCT(mb_type)){\n        int i;\n        uint8_t *nnz_cache = h->non_zero_count_cache;\n        for (i = 0; i < 2; i++){\n            if (h->left_type[LEFT(i)] && !IS_8x8DCT(h->left_type[LEFT(i)])){\n                nnz_cache[3+8* 1 + 2*8*i]=\n                nnz_cache[3+8* 2 + 2*8*i]=\n                nnz_cache[3+8* 6 + 2*8*i]=\n                nnz_cache[3+8* 7 + 2*8*i]=\n                nnz_cache[3+8*11 + 2*8*i]=\n                nnz_cache[3+8*12 + 2*8*i]= IS_INTRA(mb_type) ? 64 : 0;\n            }\n        }\n        if (h->top_type && !IS_8x8DCT(h->top_type)){\n            uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;\n            AV_WN32A(&nnz_cache[4+8* 0], top_empty);\n            AV_WN32A(&nnz_cache[4+8* 5], top_empty);\n            AV_WN32A(&nnz_cache[4+8*10], top_empty);\n        }\n    }\n    h->cur_pic.f.mb_type[mb_xy] = mb_type;\n    if( cbp || IS_INTRA16x16( mb_type ) ) {\n        const uint8_t *scan, *scan8x8;\n        const uint32_t *qmul;\n        if(IS_INTERLACED(mb_type)){\n            scan8x8= h->qscale ? h->field_scan8x8 : h->field_scan8x8_q0;\n            scan= h->qscale ? h->field_scan : h->field_scan_q0;\n        }else{\n            scan8x8= h->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0;\n            scan= h->qscale ? h->zigzag_scan : h->zigzag_scan_q0;\n        }\n        if(get_cabac_noinline( &h->cabac, &h->cabac_state[60 + (h->last_qscale_diff != 0)])){\n            int val = 1;\n            int ctx= 2;\n            const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8);\n            while( get_cabac_noinline( &h->cabac, &h->cabac_state[60 + ctx] ) ) {\n                ctx= 3;\n                val++;\n                if(val > 2*max_qp){\n                    av_log(h->avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\\n", h->mb_x, h->mb_y);\n                    return -1;\n                }\n            }\n            if( val&0x01 )\n                val=   (val + 1)>>1 ;\n            else\n                val= -((val + 1)>>1);\n            h->last_qscale_diff = val;\n            h->qscale += val;\n            if(((unsigned)h->qscale) > max_qp){\n                if(h->qscale<0) h->qscale+= max_qp+1;\n                else            h->qscale-= max_qp+1;\n            }\n            h->chroma_qp[0] = get_chroma_qp(h, 0, h->qscale);\n            h->chroma_qp[1] = get_chroma_qp(h, 1, h->qscale);\n        }else\n            h->last_qscale_diff=0;\n        decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 0);\n        if(CHROMA444){\n            decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 1);\n            decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 2);\n        } else if (CHROMA422) {\n            if( cbp&0x30 ){\n                int c;\n                for (c = 0; c < 2; c++)\n                    decode_cabac_residual_dc_422(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3,\n                                                 CHROMA_DC_BLOCK_INDEX + c,\n                                                 chroma422_dc_scan, 8);\n            }\n            if( cbp&0x20 ) {\n                int c, i, i8x8;\n                for( c = 0; c < 2; c++ ) {\n                    int16_t *mb = h->mb + (16*(16 + 16*c) << pixel_shift);\n                    qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]];\n                    for (i8x8 = 0; i8x8 < 2; i8x8++) {\n                        for (i = 0; i < 4; i++) {\n                            const int index = 16 + 16 * c + 8*i8x8 + i;\n                            decode_cabac_residual_nondc(h, mb, 4, index, scan + 1, qmul, 15);\n                            mb += 16<<pixel_shift;\n                        }\n                    }\n                }\n            } else {\n                fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n                fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n            }\n        } else   {\n            if( cbp&0x30 ){\n                int c;\n                for (c = 0; c < 2; c++)\n                    decode_cabac_residual_dc(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3, CHROMA_DC_BLOCK_INDEX+c, chroma_dc_scan, 4);\n            }\n            if( cbp&0x20 ) {\n                int c, i;\n                for( c = 0; c < 2; c++ ) {\n                    qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]];\n                    for( i = 0; i < 4; i++ ) {\n                        const int index = 16 + 16 * c + i;\n                        decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), 4, index, scan + 1, qmul, 15);\n                    }\n                }\n            } else {\n                fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n                fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n            }\n        }\n    } else {\n        fill_rectangle(&h->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1);\n        fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n        fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n        h->last_qscale_diff = 0;\n    }\n    h->cur_pic.f.qscale_table[mb_xy] = h->qscale;\n    write_back_non_zero_count(h);\n    return 0;\n}', 'static av_always_inline void decode_cabac_luma_residual( H264Context *h, const uint8_t *scan, const uint8_t *scan8x8, int pixel_shift, int mb_type, int cbp, int p )\n{\n    static const uint8_t ctx_cat[4][3] = {{0,6,10},{1,7,11},{2,8,12},{5,9,13}};\n    const uint32_t *qmul;\n    int i8x8, i4x4;\n    int qscale = p == 0 ? h->qscale : h->chroma_qp[p-1];\n    if( IS_INTRA16x16( mb_type ) ) {\n        AV_ZERO128(h->mb_luma_dc[p]+0);\n        AV_ZERO128(h->mb_luma_dc[p]+8);\n        AV_ZERO128(h->mb_luma_dc[p]+16);\n        AV_ZERO128(h->mb_luma_dc[p]+24);\n        decode_cabac_residual_dc(h, h->mb_luma_dc[p], ctx_cat[0][p], LUMA_DC_BLOCK_INDEX+p, scan, 16);\n        if( cbp&15 ) {\n            qmul = h->dequant4_coeff[p][qscale];\n            for( i4x4 = 0; i4x4 < 16; i4x4++ ) {\n                const int index = 16*p + i4x4;\n                decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[1][p], index, scan + 1, qmul, 15);\n            }\n        } else {\n            fill_rectangle(&h->non_zero_count_cache[scan8[16*p]], 4, 4, 8, 0, 1);\n        }\n    } else {\n        int cqm = (IS_INTRA( mb_type ) ? 0:3) + p;\n        for( i8x8 = 0; i8x8 < 4; i8x8++ ) {\n            if( cbp & (1<<i8x8) ) {\n                if( IS_8x8DCT(mb_type) ) {\n                    const int index = 16*p + 4*i8x8;\n                    decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[3][p], index,\n                                                scan8x8, h->dequant8_coeff[cqm][qscale], 64);\n                } else {\n                    qmul = h->dequant4_coeff[cqm][qscale];\n                    for( i4x4 = 0; i4x4 < 4; i4x4++ ) {\n                        const int index = 16*p + 4*i8x8 + i4x4;\n                        decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[2][p], index, scan, qmul, 16);\n                    }\n                }\n            } else {\n                fill_rectangle(&h->non_zero_count_cache[scan8[4*i8x8+16*p]], 2, 2, 8, 0, 1);\n            }\n        }\n    }\n}']