libavcodec/h264_cavlc.c:1120: error: Buffer Overrun L1
  Offset: -1 Size: 2 by call to `decode_luma_residual`.

libavcodec/h264_cavlc.c:1120:20: Call
1118.         }
1119. 
1120.         if ((ret = decode_luma_residual(h, sl, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 0)) < 0 ) {
                         ^
1121.             return -1;
1122.         }

libavcodec/h264_cavlc.c:628:1: <Offset trace>
626. }
627. 
628. static av_always_inline
     ^
629. int decode_luma_residual(const H264Context *h, H264SliceContext *sl,
630.                          GetBitContext *gb, const uint8_t *scan,

libavcodec/h264_cavlc.c:628:1: Parameter `p`
  626. }
  627. 
  628. static av_always_inline
       ^
  629. int decode_luma_residual(const H264Context *h, H264SliceContext *sl,
  630.                          GetBitContext *gb, const uint8_t *scan,

libavcodec/h264_cavlc.c:628:1: <Length trace>
626. }
627. 
628. static av_always_inline
     ^
629. int decode_luma_residual(const H264Context *h, H264SliceContext *sl,
630.                          GetBitContext *gb, const uint8_t *scan,

libavcodec/h264_cavlc.c:628:1: Parameter `sl->chroma_qp[*]`
  626. }
  627. 
  628. static av_always_inline
       ^
  629. int decode_luma_residual(const H264Context *h, H264SliceContext *sl,
  630.                          GetBitContext *gb, const uint8_t *scan,

libavcodec/h264_cavlc.c:635:40: Array access: Offset: -1 Size: 2 by call to `decode_luma_residual` 
  633. {
  634.     int i4x4, i8x8;
  635.     int qscale = p == 0 ? sl->qscale : sl->chroma_qp[p - 1];
                                              ^
  636.     if(IS_INTRA16x16(mb_type)){
  637.         AV_ZERO128(sl->mb_luma_dc[p]+0);

static av_always_inline
int decode_luma_residual(const H264Context *h, H264SliceContext *sl,
                         GetBitContext *gb, const uint8_t *scan,
                         const uint8_t *scan8x8, int pixel_shift,
                         int mb_type, int cbp, int p)
{
    int i4x4, i8x8;
    int qscale = p == 0 ? sl->qscale : sl->chroma_qp[p - 1];
    if(IS_INTRA16x16(mb_type)){
        AV_ZERO128(sl->mb_luma_dc[p]+0);
        AV_ZERO128(sl->mb_luma_dc[p]+8);
        AV_ZERO128(sl->mb_luma_dc[p]+16);
        AV_ZERO128(sl->mb_luma_dc[p]+24);
        if (decode_residual(h, sl, gb, sl->mb_luma_dc[p], LUMA_DC_BLOCK_INDEX + p, scan, NULL, 16) < 0) {
            return -1;
        }
        assert((cbp&15) == 0 || (cbp&15) == 15);
        if(cbp&15){
            for(i8x8=0; i8x8<4; i8x8++){
                for(i4x4=0; i4x4<4; i4x4++){
                    const int index= i4x4 + 4*i8x8 + p*16;
                    if( decode_residual(h, sl, gb, sl->mb + (16*index << pixel_shift),
                        index, scan + 1, h->ps.pps->dequant4_coeff[p][qscale], 15) < 0 ){
                        return -1;
                    }
                }
            }
            return 0xf;
        }else{
            fill_rectangle(&sl->non_zero_count_cache[scan8[p*16]], 4, 4, 8, 0, 1);
            return 0;
        }
    }else{
        int cqm = (IS_INTRA( mb_type ) ? 0:3)+p;
        int new_cbp = 0;
        for(i8x8=0; i8x8<4; i8x8++){
            if(cbp & (1<<i8x8)){
                if(IS_8x8DCT(mb_type)){
                    int16_t *buf = &sl->mb[64*i8x8+256*p << pixel_shift];
                    uint8_t *nnz;
                    for(i4x4=0; i4x4<4; i4x4++){
                        const int index= i4x4 + 4*i8x8 + p*16;
                        if( decode_residual(h, sl, gb, buf, index, scan8x8+16*i4x4,
                                            h->ps.pps->dequant8_coeff[cqm][qscale], 16) < 0 )
                            return -1;
                    }
                    nnz = &sl->non_zero_count_cache[scan8[4 * i8x8 + p * 16]];
                    nnz[0] += nnz[1] + nnz[8] + nnz[9];
                    new_cbp |= !!nnz[0] << i8x8;
                }else{
                    for(i4x4=0; i4x4<4; i4x4++){
                        const int index= i4x4 + 4*i8x8 + p*16;
                        if( decode_residual(h, sl, gb, sl->mb + (16*index << pixel_shift), index,
                                            scan, h->ps.pps->dequant4_coeff[cqm][qscale], 16) < 0 ){
                            return -1;
                        }
                        new_cbp |= sl->non_zero_count_cache[scan8[index]] << i8x8;
                    }
                }
            }else{
                uint8_t * const nnz = &sl->non_zero_count_cache[scan8[4 * i8x8 + p * 16]];
                nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0;
            }
        }
        return new_cbp;
    }
}
['int ff_h264_decode_mb_cavlc(const H264Context *h, H264SliceContext *sl)\n{\n    int mb_xy;\n    int partition_count;\n    unsigned int mb_type, cbp;\n    int dct8x8_allowed= h->ps.pps->transform_8x8_mode;\n    int decode_chroma = h->ps.sps->chroma_format_idc == 1 || h->ps.sps->chroma_format_idc == 2;\n    const int pixel_shift = h->pixel_shift;\n    mb_xy = sl->mb_xy = sl->mb_x + sl->mb_y*h->mb_stride;\n    cbp = 0;\n    if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {\n        if (sl->mb_skip_run == -1)\n            sl->mb_skip_run = get_ue_golomb(&sl->gb);\n        if (sl->mb_skip_run--) {\n            if (FRAME_MBAFF(h) && (sl->mb_y & 1) == 0) {\n                if (sl->mb_skip_run == 0)\n                    sl->mb_mbaff = sl->mb_field_decoding_flag = get_bits1(&sl->gb);\n            }\n            decode_mb_skip(h, sl);\n            return 0;\n        }\n    }\n    if (FRAME_MBAFF(h)) {\n        if ((sl->mb_y & 1) == 0)\n            sl->mb_mbaff = sl->mb_field_decoding_flag = get_bits1(&sl->gb);\n    }\n    sl->prev_mb_skipped = 0;\n    mb_type= get_ue_golomb(&sl->gb);\n    if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {\n        if(mb_type < 23){\n            partition_count = ff_h264_b_mb_type_info[mb_type].partition_count;\n            mb_type         = ff_h264_b_mb_type_info[mb_type].type;\n        }else{\n            mb_type -= 23;\n            goto decode_intra_mb;\n        }\n    } else if (sl->slice_type_nos == AV_PICTURE_TYPE_P) {\n        if(mb_type < 5){\n            partition_count = ff_h264_p_mb_type_info[mb_type].partition_count;\n            mb_type         = ff_h264_p_mb_type_info[mb_type].type;\n        }else{\n            mb_type -= 5;\n            goto decode_intra_mb;\n        }\n    }else{\n       assert(sl->slice_type_nos == AV_PICTURE_TYPE_I);\n        if (sl->slice_type == AV_PICTURE_TYPE_SI && mb_type)\n            mb_type--;\ndecode_intra_mb:\n        if(mb_type > 25){\n            av_log(h->avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\\n", mb_type, av_get_picture_type_char(sl->slice_type), sl->mb_x, sl->mb_y);\n            return -1;\n        }\n        partition_count=0;\n        cbp                      = ff_h264_i_mb_type_info[mb_type].cbp;\n        sl->intra16x16_pred_mode = ff_h264_i_mb_type_info[mb_type].pred_mode;\n        mb_type                  = ff_h264_i_mb_type_info[mb_type].type;\n    }\n    if (MB_FIELD(sl))\n        mb_type |= MB_TYPE_INTERLACED;\n    h->slice_table[mb_xy] = sl->slice_num;\n    if(IS_INTRA_PCM(mb_type)){\n        const int mb_size = ff_h264_mb_sizes[h->ps.sps->chroma_format_idc] *\n                            h->ps.sps->bit_depth_luma;\n        sl->intra_pcm_ptr = align_get_bits(&sl->gb);\n        if (get_bits_left(&sl->gb) < mb_size) {\n            av_log(h->avctx, AV_LOG_ERROR, "Not enough data for an intra PCM block.\\n");\n            return AVERROR_INVALIDDATA;\n        }\n        skip_bits_long(&sl->gb, mb_size);\n        h->cur_pic.qscale_table[mb_xy] = 0;\n        memset(h->non_zero_count[mb_xy], 16, 48);\n        h->cur_pic.mb_type[mb_xy] = mb_type;\n        return 0;\n    }\n    fill_decode_neighbors(h, sl, mb_type);\n    fill_decode_caches(h, sl, mb_type);\n    if(IS_INTRA(mb_type)){\n        int pred_mode;\n        if(IS_INTRA4x4(mb_type)){\n            int i;\n            int di = 1;\n            if(dct8x8_allowed && get_bits1(&sl->gb)){\n                mb_type |= MB_TYPE_8x8DCT;\n                di = 4;\n            }\n            for(i=0; i<16; i+=di){\n                int mode = pred_intra_mode(h, sl, i);\n                if(!get_bits1(&sl->gb)){\n                    const int rem_mode= get_bits(&sl->gb, 3);\n                    mode = rem_mode + (rem_mode >= mode);\n                }\n                if(di==4)\n                    fill_rectangle(&sl->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1);\n                else\n                    sl->intra4x4_pred_mode_cache[scan8[i]] = mode;\n            }\n            write_back_intra_pred_mode(h, sl);\n            if (ff_h264_check_intra4x4_pred_mode(sl->intra4x4_pred_mode_cache, h->avctx,\n                                                 sl->top_samples_available, sl->left_samples_available) < 0)\n                return -1;\n        }else{\n            sl->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(h->avctx, sl->top_samples_available,\n                                                                     sl->left_samples_available, sl->intra16x16_pred_mode, 0);\n            if (sl->intra16x16_pred_mode < 0)\n                return -1;\n        }\n        if(decode_chroma){\n            pred_mode= ff_h264_check_intra_pred_mode(h->avctx, sl->top_samples_available,\n                                                     sl->left_samples_available, get_ue_golomb_31(&sl->gb), 1);\n            if(pred_mode < 0)\n                return -1;\n            sl->chroma_pred_mode = pred_mode;\n        } else {\n            sl->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 (sl->slice_type_nos == AV_PICTURE_TYPE_B) {\n            for(i=0; i<4; i++){\n                sl->sub_mb_type[i]= get_ue_golomb_31(&sl->gb);\n                if(sl->sub_mb_type[i] >=13){\n                    av_log(h->avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\\n", sl->sub_mb_type[i], sl->mb_x, sl->mb_y);\n                    return -1;\n                }\n                sub_partition_count[i] = ff_h264_b_sub_mb_type_info[sl->sub_mb_type[i]].partition_count;\n                sl->sub_mb_type[i]     = ff_h264_b_sub_mb_type_info[sl->sub_mb_type[i]].type;\n            }\n            if( IS_DIRECT(sl->sub_mb_type[0]|sl->sub_mb_type[1]|sl->sub_mb_type[2]|sl->sub_mb_type[3])) {\n                ff_h264_pred_direct_motion(h, sl, &mb_type);\n                sl->ref_cache[0][scan8[4]] =\n                sl->ref_cache[1][scan8[4]] =\n                sl->ref_cache[0][scan8[12]] =\n                sl->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;\n            }\n        }else{\n            assert(sl->slice_type_nos == AV_PICTURE_TYPE_P);\n            for(i=0; i<4; i++){\n                sl->sub_mb_type[i]= get_ue_golomb_31(&sl->gb);\n                if(sl->sub_mb_type[i] >=4){\n                    av_log(h->avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\\n", sl->sub_mb_type[i], sl->mb_x, sl->mb_y);\n                    return -1;\n                }\n                sub_partition_count[i] = ff_h264_p_sub_mb_type_info[sl->sub_mb_type[i]].partition_count;\n                sl->sub_mb_type[i]     = ff_h264_p_sub_mb_type_info[sl->sub_mb_type[i]].type;\n            }\n        }\n        for (list = 0; list < sl->list_count; list++) {\n            int ref_count = IS_REF0(mb_type) ? 1 : sl->ref_count[list] << MB_MBAFF(sl);\n            for(i=0; i<4; i++){\n                if(IS_DIRECT(sl->sub_mb_type[i])) continue;\n                if(IS_DIR(sl->sub_mb_type[i], 0, list)){\n                    unsigned int tmp;\n                    if(ref_count == 1){\n                        tmp= 0;\n                    }else if(ref_count == 2){\n                        tmp= get_bits1(&sl->gb)^1;\n                    }else{\n                        tmp= get_ue_golomb_31(&sl->gb);\n                        if(tmp>=ref_count){\n                            av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\\n", tmp);\n                            return -1;\n                        }\n                    }\n                    ref[list][i]= tmp;\n                }else{\n                    ref[list][i] = -1;\n                }\n            }\n        }\n        if(dct8x8_allowed)\n            dct8x8_allowed = get_dct8x8_allowed(h, sl);\n        for (list = 0; list < sl->list_count; list++) {\n            for(i=0; i<4; i++){\n                if(IS_DIRECT(sl->sub_mb_type[i])) {\n                    sl->ref_cache[list][ scan8[4*i] ] = sl->ref_cache[list][ scan8[4*i]+1 ];\n                    continue;\n                }\n                sl->ref_cache[list][ scan8[4*i]   ]=sl->ref_cache[list][ scan8[4*i]+1 ]=\n                sl->ref_cache[list][ scan8[4*i]+8 ]=sl->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];\n                if(IS_DIR(sl->sub_mb_type[i], 0, list)){\n                    const int sub_mb_type= sl->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 mx, my;\n                        const int index= 4*i + block_width*j;\n                        int16_t (* mv_cache)[2]= &sl->mv_cache[list][ scan8[index] ];\n                        pred_motion(h, sl, index, block_width, list, sl->ref_cache[list][ scan8[index] ], &mx, &my);\n                        mx += get_se_golomb(&sl->gb);\n                        my += get_se_golomb(&sl->gb);\n                        ff_tlog(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                        }else if(IS_SUB_8X4(sub_mb_type)){\n                            mv_cache[ 1 ][0]= mx;\n                            mv_cache[ 1 ][1]= my;\n                        }else if(IS_SUB_4X8(sub_mb_type)){\n                            mv_cache[ 8 ][0]= mx;\n                            mv_cache[ 8 ][1]= my;\n                        }\n                        mv_cache[ 0 ][0]= mx;\n                        mv_cache[ 0 ][1]= my;\n                    }\n                }else{\n                    uint32_t *p= (uint32_t *)&sl->mv_cache[list][ scan8[4*i] ][0];\n                    p[0] = p[1]=\n                    p[8] = p[9]= 0;\n                }\n            }\n        }\n    }else if(IS_DIRECT(mb_type)){\n        ff_h264_pred_direct_motion(h, sl, &mb_type);\n        dct8x8_allowed &= h->ps.sps->direct_8x8_inference_flag;\n    }else{\n        int list, mx, my, i;\n        if(IS_16X16(mb_type)){\n            for (list = 0; list < sl->list_count; list++) {\n                    unsigned int val;\n                    if(IS_DIR(mb_type, 0, list)){\n                        int rc = sl->ref_count[list] << MB_MBAFF(sl);\n                        if (rc == 1) {\n                            val= 0;\n                        } else if (rc == 2) {\n                            val= get_bits1(&sl->gb)^1;\n                        }else{\n                            val= get_ue_golomb_31(&sl->gb);\n                            if (val >= rc) {\n                                av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\\n", val);\n                                return -1;\n                            }\n                        }\n                    fill_rectangle(&sl->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 1);\n                    }\n            }\n            for (list = 0; list < sl->list_count; list++) {\n                if(IS_DIR(mb_type, 0, list)){\n                    pred_motion(h, sl, 0, 4, list, sl->ref_cache[list][ scan8[0] ], &mx, &my);\n                    mx += get_se_golomb(&sl->gb);\n                    my += get_se_golomb(&sl->gb);\n                    ff_tlog(h->avctx, "final mv:%d %d\\n", mx, my);\n                    fill_rectangle(sl->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 < sl->list_count; list++) {\n                    for(i=0; i<2; i++){\n                        unsigned int val;\n                        if(IS_DIR(mb_type, i, list)){\n                            int rc = sl->ref_count[list] << MB_MBAFF(sl);\n                            if (rc == 1) {\n                                val= 0;\n                            } else if (rc == 2) {\n                                val= get_bits1(&sl->gb)^1;\n                            }else{\n                                val= get_ue_golomb_31(&sl->gb);\n                                if (val >= rc) {\n                                    av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\\n", val);\n                                    return -1;\n                                }\n                            }\n                        }else\n                            val= LIST_NOT_USED&0xFF;\n                        fill_rectangle(&sl->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1);\n                    }\n            }\n            for (list = 0; list < sl->list_count; list++) {\n                for(i=0; i<2; i++){\n                    unsigned int val;\n                    if(IS_DIR(mb_type, i, list)){\n                        pred_16x8_motion(h, sl, 8*i, list, sl->ref_cache[list][scan8[0] + 16*i], &mx, &my);\n                        mx += get_se_golomb(&sl->gb);\n                        my += get_se_golomb(&sl->gb);\n                        ff_tlog(h->avctx, "final mv:%d %d\\n", mx, my);\n                        val= pack16to32(mx,my);\n                    }else\n                        val=0;\n                    fill_rectangle(sl->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 4);\n                }\n            }\n        }else{\n            assert(IS_8X16(mb_type));\n            for (list = 0; list < sl->list_count; list++) {\n                    for(i=0; i<2; i++){\n                        unsigned int val;\n                        if(IS_DIR(mb_type, i, list)){\n                            int rc = sl->ref_count[list] << MB_MBAFF(sl);\n                            if (rc == 1) {\n                                val= 0;\n                            } else if (rc == 2) {\n                                val= get_bits1(&sl->gb)^1;\n                            }else{\n                                val= get_ue_golomb_31(&sl->gb);\n                                if (val >= rc) {\n                                    av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\\n", val);\n                                    return -1;\n                                }\n                            }\n                        }else\n                            val= LIST_NOT_USED&0xFF;\n                        fill_rectangle(&sl->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1);\n                    }\n            }\n            for (list = 0; list < sl->list_count; list++) {\n                for(i=0; i<2; i++){\n                    unsigned int val;\n                    if(IS_DIR(mb_type, i, list)){\n                        pred_8x16_motion(h, sl, i*4, list, sl->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);\n                        mx += get_se_golomb(&sl->gb);\n                        my += get_se_golomb(&sl->gb);\n                        ff_tlog(h->avctx, "final mv:%d %d\\n", mx, my);\n                        val= pack16to32(mx,my);\n                    }else\n                        val=0;\n                    fill_rectangle(sl->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 4);\n                }\n            }\n        }\n    }\n    if(IS_INTER(mb_type))\n        write_back_motion(h, sl, mb_type);\n    if(!IS_INTRA16x16(mb_type)){\n        cbp= get_ue_golomb(&sl->gb);\n        if(decode_chroma){\n            if(cbp > 47){\n                av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\\n", cbp, sl->mb_x, sl->mb_y);\n                return -1;\n            }\n            if (IS_INTRA4x4(mb_type))\n                cbp = ff_h264_golomb_to_intra4x4_cbp[cbp];\n            else\n                cbp = ff_h264_golomb_to_inter_cbp[cbp];\n        }else{\n            if(cbp > 15){\n                av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\\n", cbp, sl->mb_x, sl->mb_y);\n                return -1;\n            }\n            if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp];\n            else                     cbp= golomb_to_inter_cbp_gray[cbp];\n        }\n    }\n    if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){\n        mb_type |= MB_TYPE_8x8DCT*get_bits1(&sl->gb);\n    }\n    sl->cbp=\n    h->cbp_table[mb_xy]= cbp;\n    h->cur_pic.mb_type[mb_xy] = mb_type;\n    if(cbp || IS_INTRA16x16(mb_type)){\n        int i4x4, i8x8, chroma_idx;\n        int dquant;\n        int ret;\n        GetBitContext *gb = &sl->gb;\n        const uint8_t *scan, *scan8x8;\n        const int max_qp = 51 + 6 * (h->ps.sps->bit_depth_luma - 8);\n        dquant= get_se_golomb(&sl->gb);\n        sl->qscale += dquant;\n        if (((unsigned)sl->qscale) > max_qp){\n            if (sl->qscale < 0) sl->qscale += max_qp + 1;\n            else                sl->qscale -= max_qp+1;\n            if (((unsigned)sl->qscale) > max_qp){\n                av_log(h->avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\\n", dquant, sl->mb_x, sl->mb_y);\n                return -1;\n            }\n        }\n        sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, sl->qscale);\n        sl->chroma_qp[1] = get_chroma_qp(h->ps.pps, 1, sl->qscale);\n        if(IS_INTERLACED(mb_type)){\n            scan8x8 = sl->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0;\n            scan    = sl->qscale ? h->field_scan : h->field_scan_q0;\n        }else{\n            scan8x8 = sl->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0;\n            scan    = sl->qscale ? h->zigzag_scan : h->zigzag_scan_q0;\n        }\n        if ((ret = decode_luma_residual(h, sl, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 0)) < 0 ) {\n            return -1;\n        }\n        h->cbp_table[mb_xy] |= ret << 12;\n        if (CHROMA444(h)) {\n            if (decode_luma_residual(h, sl, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 1) < 0 ) {\n                return -1;\n            }\n            if (decode_luma_residual(h, sl, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 2) < 0 ) {\n                return -1;\n            }\n        } else if (CHROMA422(h)) {\n            if(cbp&0x30){\n                for(chroma_idx=0; chroma_idx<2; chroma_idx++)\n                    if (decode_residual(h, sl, gb, sl->mb + ((256 + 16*16*chroma_idx) << pixel_shift),\n                                        CHROMA_DC_BLOCK_INDEX + chroma_idx, ff_h264_chroma422_dc_scan,\n                                        NULL, 8) < 0) {\n                        return -1;\n                    }\n            }\n            if(cbp&0x20){\n                for(chroma_idx=0; chroma_idx<2; chroma_idx++){\n                    const uint32_t *qmul = h->ps.pps->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][sl->chroma_qp[chroma_idx]];\n                    int16_t *mb = sl->mb + (16*(16 + 16*chroma_idx) << pixel_shift);\n                    for (i8x8 = 0; i8x8 < 2; i8x8++) {\n                        for (i4x4 = 0; i4x4 < 4; i4x4++) {\n                            const int index = 16 + 16*chroma_idx + 8*i8x8 + i4x4;\n                            if (decode_residual(h, sl, gb, mb, index, scan + 1, qmul, 15) < 0)\n                                return -1;\n                            mb += 16 << pixel_shift;\n                        }\n                    }\n                }\n            }else{\n                fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n                fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n            }\n        } else   {\n            if(cbp&0x30){\n                for(chroma_idx=0; chroma_idx<2; chroma_idx++)\n                    if (decode_residual(h, sl, gb, sl->mb + ((256 + 16 * 16 * chroma_idx) << pixel_shift),\n                                        CHROMA_DC_BLOCK_INDEX + chroma_idx, ff_h264_chroma_dc_scan, NULL, 4) < 0) {\n                        return -1;\n                    }\n            }\n            if(cbp&0x20){\n                for(chroma_idx=0; chroma_idx<2; chroma_idx++){\n                    const uint32_t *qmul = h->ps.pps->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][sl->chroma_qp[chroma_idx]];\n                    for(i4x4=0; i4x4<4; i4x4++){\n                        const int index= 16 + 16*chroma_idx + i4x4;\n                        if( decode_residual(h, sl, gb, sl->mb + (16*index << pixel_shift), index, scan + 1, qmul, 15) < 0){\n                            return -1;\n                        }\n                    }\n                }\n            }else{\n                fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n                fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n            }\n        }\n    }else{\n        fill_rectangle(&sl->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1);\n        fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n        fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n    }\n    h->cur_pic.qscale_table[mb_xy] = sl->qscale;\n    write_back_non_zero_count(h, sl);\n    return 0;\n}', 'static av_always_inline\nint decode_luma_residual(const H264Context *h, H264SliceContext *sl,\n                         GetBitContext *gb, const uint8_t *scan,\n                         const uint8_t *scan8x8, int pixel_shift,\n                         int mb_type, int cbp, int p)\n{\n    int i4x4, i8x8;\n    int qscale = p == 0 ? sl->qscale : sl->chroma_qp[p - 1];\n    if(IS_INTRA16x16(mb_type)){\n        AV_ZERO128(sl->mb_luma_dc[p]+0);\n        AV_ZERO128(sl->mb_luma_dc[p]+8);\n        AV_ZERO128(sl->mb_luma_dc[p]+16);\n        AV_ZERO128(sl->mb_luma_dc[p]+24);\n        if (decode_residual(h, sl, gb, sl->mb_luma_dc[p], LUMA_DC_BLOCK_INDEX + p, scan, NULL, 16) < 0) {\n            return -1;\n        }\n        assert((cbp&15) == 0 || (cbp&15) == 15);\n        if(cbp&15){\n            for(i8x8=0; i8x8<4; i8x8++){\n                for(i4x4=0; i4x4<4; i4x4++){\n                    const int index= i4x4 + 4*i8x8 + p*16;\n                    if( decode_residual(h, sl, gb, sl->mb + (16*index << pixel_shift),\n                        index, scan + 1, h->ps.pps->dequant4_coeff[p][qscale], 15) < 0 ){\n                        return -1;\n                    }\n                }\n            }\n            return 0xf;\n        }else{\n            fill_rectangle(&sl->non_zero_count_cache[scan8[p*16]], 4, 4, 8, 0, 1);\n            return 0;\n        }\n    }else{\n        int cqm = (IS_INTRA( mb_type ) ? 0:3)+p;\n        int new_cbp = 0;\n        for(i8x8=0; i8x8<4; i8x8++){\n            if(cbp & (1<<i8x8)){\n                if(IS_8x8DCT(mb_type)){\n                    int16_t *buf = &sl->mb[64*i8x8+256*p << pixel_shift];\n                    uint8_t *nnz;\n                    for(i4x4=0; i4x4<4; i4x4++){\n                        const int index= i4x4 + 4*i8x8 + p*16;\n                        if( decode_residual(h, sl, gb, buf, index, scan8x8+16*i4x4,\n                                            h->ps.pps->dequant8_coeff[cqm][qscale], 16) < 0 )\n                            return -1;\n                    }\n                    nnz = &sl->non_zero_count_cache[scan8[4 * i8x8 + p * 16]];\n                    nnz[0] += nnz[1] + nnz[8] + nnz[9];\n                    new_cbp |= !!nnz[0] << i8x8;\n                }else{\n                    for(i4x4=0; i4x4<4; i4x4++){\n                        const int index= i4x4 + 4*i8x8 + p*16;\n                        if( decode_residual(h, sl, gb, sl->mb + (16*index << pixel_shift), index,\n                                            scan, h->ps.pps->dequant4_coeff[cqm][qscale], 16) < 0 ){\n                            return -1;\n                        }\n                        new_cbp |= sl->non_zero_count_cache[scan8[index]] << i8x8;\n                    }\n                }\n            }else{\n                uint8_t * const nnz = &sl->non_zero_count_cache[scan8[4 * i8x8 + p * 16]];\n                nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0;\n            }\n        }\n        return new_cbp;\n    }\n}']