static int decode_residual(const H264Context *h, H264SliceContext *sl,

                           GetBitContext *gb, int16_t *block, int n,

                           const uint8_t *scantable, const uint32_t *qmul,

                           int max_coeff)

{

    static const int coeff_token_table_index[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3};

    int level[16];

    int zeros_left, coeff_token, total_coeff, i, trailing_ones, run_before;



    //FIXME put trailing_onex into the context



    if(max_coeff <= 8){

        if (max_coeff == 4)

            coeff_token = get_vlc2(gb, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1);

        else

            coeff_token = get_vlc2(gb, chroma422_dc_coeff_token_vlc.table, CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 1);

        total_coeff= coeff_token>>2;

    }else{

        if(n >= LUMA_DC_BLOCK_INDEX){

            total_coeff= pred_non_zero_count(h, sl, (n - LUMA_DC_BLOCK_INDEX)*16);

            coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2);

            total_coeff= coeff_token>>2;

        }else{

            total_coeff= pred_non_zero_count(h, sl, n);

            coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2);

            total_coeff= coeff_token>>2;

        }

    }

    sl->non_zero_count_cache[scan8[n]] = total_coeff;



    //FIXME set last_non_zero?



    if(total_coeff==0)

        return 0;

    if(total_coeff > (unsigned)max_coeff) {

        av_log(h->avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", sl->mb_x, sl->mb_y, total_coeff);

        return -1;

    }



    trailing_ones= coeff_token&3;

    ff_tlog(h->avctx, "trailing:%d, total:%d\n", trailing_ones, total_coeff);

    assert(total_coeff<=16);



    i = show_bits(gb, 3);

    skip_bits(gb, trailing_ones);

    level[0] = 1-((i&4)>>1);

    level[1] = 1-((i&2)   );

    level[2] = 1-((i&1)<<1);



    if(trailing_ones<total_coeff) {

        int mask, prefix;

        int suffix_length = total_coeff > 10 & trailing_ones < 3;

        int bitsi= show_bits(gb, LEVEL_TAB_BITS);

        int level_code= cavlc_level_tab[suffix_length][bitsi][0];



        skip_bits(gb, cavlc_level_tab[suffix_length][bitsi][1]);

        if(level_code >= 100){

            prefix= level_code - 100;

            if(prefix == LEVEL_TAB_BITS)

                prefix += get_level_prefix(gb);



            //first coefficient has suffix_length equal to 0 or 1

            if(prefix<14){ //FIXME try to build a large unified VLC table for all this

                if(suffix_length)

                    level_code= (prefix<<1) + get_bits1(gb); //part

                else

                    level_code= prefix; //part

            }else if(prefix==14){

                if(suffix_length)

                    level_code= (prefix<<1) + get_bits1(gb); //part

                else

                    level_code= prefix + get_bits(gb, 4); //part

            }else{

                level_code= 30 + get_bits(gb, prefix-3); //part

                if(prefix>=16){

                    if(prefix > 25+3){

                        av_log(h->avctx, AV_LOG_ERROR, "Invalid level prefix\n");

                        return -1;

                    }

                    level_code += (1<<(prefix-3))-4096;

                }

            }



            if(trailing_ones < 3) level_code += 2;



            suffix_length = 2;

            mask= -(level_code&1);

            level[trailing_ones]= (((2+level_code)>>1) ^ mask) - mask;

        }else{

            level_code += ((level_code>>31)|1) & -(trailing_ones < 3);



            suffix_length = 1 + (level_code + 3U > 6U);

            level[trailing_ones]= level_code;

        }



        //remaining coefficients have suffix_length > 0

        for(i=trailing_ones+1;i<total_coeff;i++) {

            static const unsigned int suffix_limit[7] = {0,3,6,12,24,48,INT_MAX };

            int bitsi= show_bits(gb, LEVEL_TAB_BITS);

            level_code= cavlc_level_tab[suffix_length][bitsi][0];



            skip_bits(gb, cavlc_level_tab[suffix_length][bitsi][1]);

            if(level_code >= 100){

                prefix= level_code - 100;

                if(prefix == LEVEL_TAB_BITS){

                    prefix += get_level_prefix(gb);

                }

                if(prefix<15){

                    level_code = (prefix<<suffix_length) + get_bits(gb, suffix_length);

                }else{

                    level_code = (15<<suffix_length) + get_bits(gb, prefix-3);

                    if(prefix>=16)

                        level_code += (1<<(prefix-3))-4096;

                }

                mask= -(level_code&1);

                level_code= (((2+level_code)>>1) ^ mask) - mask;

            }

            level[i]= level_code;

            suffix_length+= suffix_limit[suffix_length] + level_code > 2U*suffix_limit[suffix_length];

        }

    }



    if(total_coeff == max_coeff)

        zeros_left=0;

    else{

        if (max_coeff <= 8) {

            if (max_coeff == 4)

                zeros_left = get_vlc2(gb, chroma_dc_total_zeros_vlc[total_coeff - 1].table,

                                      CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1);

            else

                zeros_left = get_vlc2(gb, chroma422_dc_total_zeros_vlc[total_coeff - 1].table,

                                      CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 1);

        } else {

            zeros_left= get_vlc2(gb, total_zeros_vlc[total_coeff - 1].table, TOTAL_ZEROS_VLC_BITS, 1);

        }

    }



#define STORE_BLOCK(type) \

    scantable += zeros_left + total_coeff - 1; \

    if(n >= LUMA_DC_BLOCK_INDEX){ \

        ((type*)block)[*scantable] = level[0]; \

        for(i=1;i<total_coeff && zeros_left > 0;i++) { \

            if(zeros_left < 7) \

                run_before= get_vlc2(gb, run_vlc[zeros_left - 1].table, RUN_VLC_BITS, 1); \

            else \

                run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \

            zeros_left -= run_before; \

            scantable -= 1 + run_before; \

            ((type*)block)[*scantable]= level[i]; \

        } \

        for(;i<total_coeff;i++) { \

            scantable--; \

            ((type*)block)[*scantable]= level[i]; \

        } \

    }else{ \

        ((type*)block)[*scantable] = ((int)(level[0] * qmul[*scantable] + 32))>>6; \

        for(i=1;i<total_coeff && zeros_left > 0;i++) { \

            if(zeros_left < 7) \

                run_before= get_vlc2(gb, run_vlc[zeros_left - 1].table, RUN_VLC_BITS, 1); \

            else \

                run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \

            zeros_left -= run_before; \

            scantable -= 1 + run_before; \

            ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \

        } \

        for(;i<total_coeff;i++) { \

            scantable--; \

            ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \

        } \

    }



    if (zeros_left < 0) {

        av_log(h->avctx, AV_LOG_ERROR,

               "negative number of zero coeffs at %d %d\n", sl->mb_x, sl->mb_y);

        return AVERROR_INVALIDDATA;

    }



    if (h->pixel_shift) {

        STORE_BLOCK(int32_t)

    } else {

        STORE_BLOCK(int16_t)

    }



    return 0;

}

static int decode_residual(const H264Context *h, H264SliceContext *sl,

                           GetBitContext *gb, int16_t *block, int n,

                           const uint8_t *scantable, const uint32_t *qmul,

                           int max_coeff)

{

    static const int coeff_token_table_index[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3};

    int level[16];

    int zeros_left, coeff_token, total_coeff, i, trailing_ones, run_before;



    



    if(max_coeff <= 8){

        if (max_coeff == 4)

            coeff_token = get_vlc2(gb, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1);

        else

            coeff_token = get_vlc2(gb, chroma422_dc_coeff_token_vlc.table, CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 1);

        total_coeff= coeff_token>>2;

    }else{

        if(n >= LUMA_DC_BLOCK_INDEX){

            total_coeff= pred_non_zero_count(h, sl, (n - LUMA_DC_BLOCK_INDEX)*16);

            coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2);

            total_coeff= coeff_token>>2;

        }else{

            total_coeff= pred_non_zero_count(h, sl, n);

            coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2);

            total_coeff= coeff_token>>2;

        }

    }

    sl->non_zero_count_cache[scan8[n]] = total_coeff;



    



    if(total_coeff==0)

        return 0;

    if(total_coeff > (unsigned)max_coeff) {

        av_log(h->avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", sl->mb_x, sl->mb_y, total_coeff);

        return -1;

    }



    trailing_ones= coeff_token&3;

    ff_tlog(h->avctx, "trailing:%d, total:%d\n", trailing_ones, total_coeff);

    assert(total_coeff<=16);



    i = show_bits(gb, 3);

    skip_bits(gb, trailing_ones);

    level[0] = 1-((i&4)>>1);

    level[1] = 1-((i&2)   );

    level[2] = 1-((i&1)<<1);



    if(trailing_ones<total_coeff) {

        int mask, prefix;

        int suffix_length = total_coeff > 10 & trailing_ones < 3;

        int bitsi= show_bits(gb, LEVEL_TAB_BITS);

        int level_code= cavlc_level_tab[suffix_length][bitsi][0];



        skip_bits(gb, cavlc_level_tab[suffix_length][bitsi][1]);

        if(level_code >= 100){

            prefix= level_code - 100;

            if(prefix == LEVEL_TAB_BITS)

                prefix += get_level_prefix(gb);



            

            if(prefix<14){ 

                if(suffix_length)

                    level_code= (prefix<<1) + get_bits1(gb); 

                else

                    level_code= prefix; 

            }else if(prefix==14){

                if(suffix_length)

                    level_code= (prefix<<1) + get_bits1(gb); 

                else

                    level_code= prefix + get_bits(gb, 4); 

            }else{

                level_code= 30 + get_bits(gb, prefix-3); 

                if(prefix>=16){

                    if(prefix > 25+3){

                        av_log(h->avctx, AV_LOG_ERROR, "Invalid level prefix\n");

                        return -1;

                    }

                    level_code += (1<<(prefix-3))-4096;

                }

            }



            if(trailing_ones < 3) level_code += 2;



            suffix_length = 2;

            mask= -(level_code&1);

            level[trailing_ones]= (((2+level_code)>>1) ^ mask) - mask;

        }else{

            level_code += ((level_code>>31)|1) & -(trailing_ones < 3);



            suffix_length = 1 + (level_code + 3U > 6U);

            level[trailing_ones]= level_code;

        }



        

        for(i=trailing_ones+1;i<total_coeff;i++) {

            static const unsigned int suffix_limit[7] = {0,3,6,12,24,48,INT_MAX };

            int bitsi= show_bits(gb, LEVEL_TAB_BITS);

            level_code= cavlc_level_tab[suffix_length][bitsi][0];



            skip_bits(gb, cavlc_level_tab[suffix_length][bitsi][1]);

            if(level_code >= 100){

                prefix= level_code - 100;

                if(prefix == LEVEL_TAB_BITS){

                    prefix += get_level_prefix(gb);

                }

                if(prefix<15){

                    level_code = (prefix<<suffix_length) + get_bits(gb, suffix_length);

                }else{

                    level_code = (15<<suffix_length) + get_bits(gb, prefix-3);

                    if(prefix>=16)

                        level_code += (1<<(prefix-3))-4096;

                }

                mask= -(level_code&1);

                level_code= (((2+level_code)>>1) ^ mask) - mask;

            }

            level[i]= level_code;

            suffix_length+= suffix_limit[suffix_length] + level_code > 2U*suffix_limit[suffix_length];

        }

    }



    if(total_coeff == max_coeff)

        zeros_left=0;

    else{

        if (max_coeff <= 8) {

            if (max_coeff == 4)

                zeros_left = get_vlc2(gb, chroma_dc_total_zeros_vlc[total_coeff - 1].table,

                                      CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1);

            else

                zeros_left = get_vlc2(gb, chroma422_dc_total_zeros_vlc[total_coeff - 1].table,

                                      CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 1);

        } else {

            zeros_left= get_vlc2(gb, total_zeros_vlc[total_coeff - 1].table, TOTAL_ZEROS_VLC_BITS, 1);

        }

    }



#define STORE_BLOCK(type) \

    scantable += zeros_left + total_coeff - 1; \

    if(n >= LUMA_DC_BLOCK_INDEX){ \

        ((type*)block)[*scantable] = level[0]; \

        for(i=1;i<total_coeff && zeros_left > 0;i++) { \

            if(zeros_left < 7) \

                run_before= get_vlc2(gb, run_vlc[zeros_left - 1].table, RUN_VLC_BITS, 1); \

            else \

                run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \

            zeros_left -= run_before; \

            scantable -= 1 + run_before; \

            ((type*)block)[*scantable]= level[i]; \

        } \

        for(;i<total_coeff;i++) { \

            scantable--; \

            ((type*)block)[*scantable]= level[i]; \

        } \

    }else{ \

        ((type*)block)[*scantable] = ((int)(level[0] * qmul[*scantable] + 32))>>6; \

        for(i=1;i<total_coeff && zeros_left > 0;i++) { \

            if(zeros_left < 7) \

                run_before= get_vlc2(gb, run_vlc[zeros_left - 1].table, RUN_VLC_BITS, 1); \

            else \

                run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \

            zeros_left -= run_before; \

            scantable -= 1 + run_before; \

            ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \

        } \

        for(;i<total_coeff;i++) { \

            scantable--; \

            ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \

        } \

    }



    if (zeros_left < 0) {

        av_log(h->avctx, AV_LOG_ERROR,

               "negative number of zero coeffs at %d %d\n", sl->mb_x, sl->mb_y);

        return AVERROR_INVALIDDATA;

    }



    if (h->pixel_shift) {

        STORE_BLOCK(int32_t)

    } else {

        STORE_BLOCK(int16_t)

    }



    return 0;

}

            else \             else \
static int FUNC_0(const H264Context *VAR_0, H264SliceContext *VAR_1,

                           GetBitContext *VAR_2, int16_t *VAR_3, int VAR_4,

                           const uint8_t *VAR_5, const uint32_t *VAR_6,

                           int VAR_7)

{

    static const int VAR_8[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3};

    int VAR_9[16];

    int VAR_10, VAR_11, VAR_12, VAR_13, VAR_14, VAR_15;



    



    if(VAR_7 <= 8){

        if (VAR_7 == 4)

            VAR_11 = get_vlc2(VAR_2, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1);

        else

            VAR_11 = get_vlc2(VAR_2, chroma422_dc_coeff_token_vlc.table, CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 1);

        VAR_12= VAR_11>>2;

    }else{

        if(VAR_4 >= LUMA_DC_BLOCK_INDEX){

            VAR_12= pred_non_zero_count(VAR_0, VAR_1, (VAR_4 - LUMA_DC_BLOCK_INDEX)*16);

            VAR_11= get_vlc2(VAR_2, coeff_token_vlc[ VAR_8[VAR_12] ].table, COEFF_TOKEN_VLC_BITS, 2);

            VAR_12= VAR_11>>2;

        }else{

            VAR_12= pred_non_zero_count(VAR_0, VAR_1, VAR_4);

            VAR_11= get_vlc2(VAR_2, coeff_token_vlc[ VAR_8[VAR_12] ].table, COEFF_TOKEN_VLC_BITS, 2);

            VAR_12= VAR_11>>2;

        }

    }

    VAR_1->non_zero_count_cache[scan8[VAR_4]] = VAR_12;



    



    if(VAR_12==0)

        return 0;

    if(VAR_12 > (unsigned)VAR_7) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (VAR_12=%d)\VAR_4", VAR_1->mb_x, VAR_1->mb_y, VAR_12);

        return -1;

    }



    VAR_14= VAR_11&3;

    ff_tlog(VAR_0->avctx, "trailing:%d, total:%d\VAR_4", VAR_14, VAR_12);

    assert(VAR_12<=16);



    VAR_13 = show_bits(VAR_2, 3);

    skip_bits(VAR_2, VAR_14);

    VAR_9[0] = 1-((VAR_13&4)>>1);

    VAR_9[1] = 1-((VAR_13&2)   );

    VAR_9[2] = 1-((VAR_13&1)<<1);



    if(VAR_14<VAR_12) {

        int VAR_16, VAR_17;

        int VAR_18 = VAR_12 > 10 & VAR_14 < 3;

        int VAR_22= show_bits(VAR_2, LEVEL_TAB_BITS);

        int VAR_20= cavlc_level_tab[VAR_18][VAR_22][0];



        skip_bits(VAR_2, cavlc_level_tab[VAR_18][VAR_22][1]);

        if(VAR_20 >= 100){

            VAR_17= VAR_20 - 100;

            if(VAR_17 == LEVEL_TAB_BITS)

                VAR_17 += get_level_prefix(VAR_2);



            

            if(VAR_17<14){ 

                if(VAR_18)

                    VAR_20= (VAR_17<<1) + get_bits1(VAR_2); 

                else

                    VAR_20= VAR_17; 

            }else if(VAR_17==14){

                if(VAR_18)

                    VAR_20= (VAR_17<<1) + get_bits1(VAR_2); 

                else

                    VAR_20= VAR_17 + get_bits(VAR_2, 4); 

            }else{

                VAR_20= 30 + get_bits(VAR_2, VAR_17-3); 

                if(VAR_17>=16){

                    if(VAR_17 > 25+3){

                        av_log(VAR_0->avctx, AV_LOG_ERROR, "Invalid VAR_9 VAR_17\VAR_4");

                        return -1;

                    }

                    VAR_20 += (1<<(VAR_17-3))-4096;

                }

            }



            if(VAR_14 < 3) VAR_20 += 2;



            VAR_18 = 2;

            VAR_16= -(VAR_20&1);

            VAR_9[VAR_14]= (((2+VAR_20)>>1) ^ VAR_16) - VAR_16;

        }else{

            VAR_20 += ((VAR_20>>31)|1) & -(VAR_14 < 3);



            VAR_18 = 1 + (VAR_20 + 3U > 6U);

            VAR_9[VAR_14]= VAR_20;

        }



        

        for(VAR_13=VAR_14+1;VAR_13<VAR_12;VAR_13++) {

            static const unsigned int VAR_21[7] = {0,3,6,12,24,48,INT_MAX };

            int VAR_22= show_bits(VAR_2, LEVEL_TAB_BITS);

            VAR_20= cavlc_level_tab[VAR_18][VAR_22][0];



            skip_bits(VAR_2, cavlc_level_tab[VAR_18][VAR_22][1]);

            if(VAR_20 >= 100){

                VAR_17= VAR_20 - 100;

                if(VAR_17 == LEVEL_TAB_BITS){

                    VAR_17 += get_level_prefix(VAR_2);

                }

                if(VAR_17<15){

                    VAR_20 = (VAR_17<<VAR_18) + get_bits(VAR_2, VAR_18);

                }else{

                    VAR_20 = (15<<VAR_18) + get_bits(VAR_2, VAR_17-3);

                    if(VAR_17>=16)

                        VAR_20 += (1<<(VAR_17-3))-4096;

                }

                VAR_16= -(VAR_20&1);

                VAR_20= (((2+VAR_20)>>1) ^ VAR_16) - VAR_16;

            }

            VAR_9[VAR_13]= VAR_20;

            VAR_18+= VAR_21[VAR_18] + VAR_20 > 2U*VAR_21[VAR_18];

        }

    }



    if(VAR_12 == VAR_7)

        VAR_10=0;

    else{

        if (VAR_7 <= 8) {

            if (VAR_7 == 4)

                VAR_10 = get_vlc2(VAR_2, chroma_dc_total_zeros_vlc[VAR_12 - 1].table,

                                      CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1);

            else

                VAR_10 = get_vlc2(VAR_2, chroma422_dc_total_zeros_vlc[VAR_12 - 1].table,

                                      CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 1);

        } else {

            VAR_10= get_vlc2(VAR_2, total_zeros_vlc[VAR_12 - 1].table, TOTAL_ZEROS_VLC_BITS, 1);

        }

    }



#define STORE_BLOCK(type) \

    VAR_5 += VAR_10 + VAR_12 - 1; \

    if(VAR_4 >= LUMA_DC_BLOCK_INDEX){ \

        ((type*)VAR_3)[*VAR_5] = VAR_9[0]; \

        for(VAR_13=1;VAR_13<VAR_12 && VAR_10 > 0;VAR_13++) { \

            if(VAR_10 < 7) \

                VAR_15= get_vlc2(VAR_2, run_vlc[VAR_10 - 1].table, RUN_VLC_BITS, 1); \

            else \

                VAR_15= get_vlc2(VAR_2, run7_vlc.table, RUN7_VLC_BITS, 2); \

            VAR_10 -= VAR_15; \

            VAR_5 -= 1 + VAR_15; \

            ((type*)VAR_3)[*VAR_5]= VAR_9[VAR_13]; \

        } \

        for(;VAR_13<VAR_12;VAR_13++) { \

            VAR_5--; \

            ((type*)VAR_3)[*VAR_5]= VAR_9[VAR_13]; \

        } \

    }else{ \

        ((type*)VAR_3)[*VAR_5] = ((int)(VAR_9[0] * VAR_6[*VAR_5] + 32))>>6; \

        for(VAR_13=1;VAR_13<VAR_12 && VAR_10 > 0;VAR_13++) { \

            if(VAR_10 < 7) \

                VAR_15= get_vlc2(VAR_2, run_vlc[VAR_10 - 1].table, RUN_VLC_BITS, 1); \

            else \

                VAR_15= get_vlc2(VAR_2, run7_vlc.table, RUN7_VLC_BITS, 2); \

            VAR_10 -= VAR_15; \

            VAR_5 -= 1 + VAR_15; \

            ((type*)VAR_3)[*VAR_5]= ((int)(VAR_9[VAR_13] * VAR_6[*VAR_5] + 32))>>6; \

        } \

        for(;VAR_13<VAR_12;VAR_13++) { \

            VAR_5--; \

            ((type*)VAR_3)[*VAR_5]= ((int)(VAR_9[VAR_13] * VAR_6[*VAR_5] + 32))>>6; \

        } \

    }



    if (VAR_10 < 0) {

        av_log(VAR_0->avctx, AV_LOG_ERROR,

               "negative number of zero coeffs at %d %d\VAR_4", VAR_1->mb_x, VAR_1->mb_y);

        return AVERROR_INVALIDDATA;

    }



    if (VAR_0->pixel_shift) {

        STORE_BLOCK(int32_t)

    } else {

        STORE_BLOCK(int16_t)

    }



    return 0;

}

static int FUNC_0(const H264Context *VAR_0, H264SliceContext *VAR_1,
GetBitContext *VAR_2, int16_t *VAR_3, int VAR_4,
const uint8_t *VAR_5, const uint32_t *VAR_6,
int VAR_7)
{ static const int VAR_8[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3}; int VAR_9[16]; int VAR_10, VAR_11, VAR_12, VAR_13, VAR_14, VAR_15; if(VAR_7 <= 8){ if (VAR_7 == 4)
VAR_11 = get_vlc2(VAR_2, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1); else
VAR_11 = get_vlc2(VAR_2, chroma422_dc_coeff_token_vlc.table, CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 1); VAR_12= VAR_11>>2; }else{ if(VAR_4 >= LUMA_DC_BLOCK_INDEX){ VAR_12= pred_non_zero_count(VAR_0, VAR_1, (VAR_4 - LUMA_DC_BLOCK_INDEX)*16); VAR_11= get_vlc2(VAR_2, coeff_token_vlc[ VAR_8[VAR_12] ].table, COEFF_TOKEN_VLC_BITS, 2); VAR_12= VAR_11>>2; }else{ VAR_12= pred_non_zero_count(VAR_0, VAR_1, VAR_4); VAR_11= get_vlc2(VAR_2, coeff_token_vlc[ VAR_8[VAR_12] ].table, COEFF_TOKEN_VLC_BITS, 2); VAR_12= VAR_11>>2; } } VAR_1->non_zero_count_cache[scan8[VAR_4]] = VAR_12; if(VAR_12==0)
return 0; if(VAR_12 > (unsigned)VAR_7) { av_log(VAR_0->avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (VAR_12=%d)\VAR_4", VAR_1->mb_x, VAR_1->mb_y, VAR_12); return -1; } VAR_14= VAR_11&3; ff_tlog(VAR_0->avctx, "trailing:%d, total:%d\VAR_4", VAR_14, VAR_12); assert(VAR_12<=16); VAR_13 = show_bits(VAR_2, 3); skip_bits(VAR_2, VAR_14); VAR_9[0] = 1-((VAR_13&4)>>1); VAR_9[1] = 1-((VAR_13&2)   ); VAR_9[2] = 1-((VAR_13&1)<<1); if(VAR_14<VAR_12) { int VAR_16, VAR_17; int VAR_18 = VAR_12 > 10 & VAR_14 < 3; int VAR_22= show_bits(VAR_2, LEVEL_TAB_BITS); int VAR_20= cavlc_level_tab[VAR_18][VAR_22][0]; skip_bits(VAR_2, cavlc_level_tab[VAR_18][VAR_22][1]); if(VAR_20 >= 100){ VAR_17= VAR_20 - 100; if(VAR_17 == LEVEL_TAB_BITS)
VAR_17 += get_level_prefix(VAR_2); if(VAR_17<14){ if(VAR_18)
VAR_20= (VAR_17<<1) + get_bits1(VAR_2); else
VAR_20= VAR_17; }else if(VAR_17==14){ if(VAR_18)
VAR_20= (VAR_17<<1) + get_bits1(VAR_2); else
VAR_20= VAR_17 + get_bits(VAR_2, 4); }else{ VAR_20= 30 + get_bits(VAR_2, VAR_17-3); if(VAR_17>=16){ if(VAR_17 > 25+3){ av_log(VAR_0->avctx, AV_LOG_ERROR, "Invalid VAR_9 VAR_17\VAR_4"); return -1; } VAR_20 += (1<<(VAR_17-3))-4096; } } if(VAR_14 < 3) VAR_20 += 2; VAR_18 = 2; VAR_16= -(VAR_20&1); VAR_9[VAR_14]= (((2+VAR_20)>>1) ^ VAR_16) - VAR_16; }else{ VAR_20 += ((VAR_20>>31)|1) & -(VAR_14 < 3); VAR_18 = 1 + (VAR_20 + 3U > 6U); VAR_9[VAR_14]= VAR_20; } for(VAR_13=VAR_14+1;VAR_13<VAR_12;VAR_13++) { static const unsigned int VAR_21[7] = {0,3,6,12,24,48,INT_MAX }; int VAR_22= show_bits(VAR_2, LEVEL_TAB_BITS); VAR_20= cavlc_level_tab[VAR_18][VAR_22][0]; skip_bits(VAR_2, cavlc_level_tab[VAR_18][VAR_22][1]); if(VAR_20 >= 100){ VAR_17= VAR_20 - 100; if(VAR_17 == LEVEL_TAB_BITS){ VAR_17 += get_level_prefix(VAR_2); } if(VAR_17<15){ VAR_20 = (VAR_17<<VAR_18) + get_bits(VAR_2, VAR_18); }else{ VAR_20 = (15<<VAR_18) + get_bits(VAR_2, VAR_17-3); if(VAR_17>=16)
VAR_20 += (1<<(VAR_17-3))-4096; } VAR_16= -(VAR_20&1); VAR_20= (((2+VAR_20)>>1) ^ VAR_16) - VAR_16; } VAR_9[VAR_13]= VAR_20; VAR_18+= VAR_21[VAR_18] + VAR_20 > 2U*VAR_21[VAR_18]; } } if(VAR_12 == VAR_7)
VAR_10=0; else{ if (VAR_7 <= 8) { if (VAR_7 == 4)
VAR_10 = get_vlc2(VAR_2, chroma_dc_total_zeros_vlc[VAR_12 - 1].table,
CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1); else
VAR_10 = get_vlc2(VAR_2, chroma422_dc_total_zeros_vlc[VAR_12 - 1].table,
CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 1); } else { VAR_10= get_vlc2(VAR_2, total_zeros_vlc[VAR_12 - 1].table, TOTAL_ZEROS_VLC_BITS, 1); } } #define STORE_BLOCK(type) \
VAR_5 += VAR_10 + VAR_12 - 1; \ if(VAR_4 >= LUMA_DC_BLOCK_INDEX){ \ ((type*)VAR_3)[*VAR_5] = VAR_9[0]; \ for(VAR_13=1;VAR_13<VAR_12 && VAR_10 > 0;VAR_13++) { \ if(VAR_10 < 7) \
VAR_15= get_vlc2(VAR_2, run_vlc[VAR_10 - 1].table, RUN_VLC_BITS, 1); \ else \
VAR_15= get_vlc2(VAR_2, run7_vlc.table, RUN7_VLC_BITS, 2); \ VAR_10 -= VAR_15; \ VAR_5 -= 1 + VAR_15; \ ((type*)VAR_3)[*VAR_5]= VAR_9[VAR_13]; \ } \ for(;VAR_13<VAR_12;VAR_13++) { \ VAR_5--; \ ((type*)VAR_3)[*VAR_5]= VAR_9[VAR_13]; \ } \ }else{ \ ((type*)VAR_3)[*VAR_5] = ((int)(VAR_9[0] * VAR_6[*VAR_5] + 32))>>6; \ for(VAR_13=1;VAR_13<VAR_12 && VAR_10 > 0;VAR_13++) { \ if(VAR_10 < 7) \
VAR_15= get_vlc2(VAR_2, run_vlc[VAR_10 - 1].table, RUN_VLC_BITS, 1); \ else \
VAR_15= get_vlc2(VAR_2, run7_vlc.table, RUN7_VLC_BITS, 2); \ VAR_10 -= VAR_15; \ VAR_5 -= 1 + VAR_15; \ ((type*)VAR_3)[*VAR_5]= ((int)(VAR_9[VAR_13] * VAR_6[*VAR_5] + 32))>>6; \ } \ for(;VAR_13<VAR_12;VAR_13++) { \ VAR_5--; \ ((type*)VAR_3)[*VAR_5]= ((int)(VAR_9[VAR_13] * VAR_6[*VAR_5] + 32))>>6; \ } \ } if (VAR_10 < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"negative number of zero coeffs at %d %d\VAR_4", VAR_1->mb_x, VAR_1->mb_y); return AVERROR_INVALIDDATA; } if (VAR_0->pixel_shift) { STORE_BLOCK(int32_t)
} else { STORE_BLOCK(int16_t)
} return 0; }