static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff){

    MpegEncContext * const s = &h->s;

    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, (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, 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;

        }

    }

    h->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->s.avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", s->mb_x, s->mb_y, total_coeff);

        return -1;

    }



    trailing_ones= coeff_token&3;

    tprintf(h->s.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->s.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 (h->pixel_shift) {

        STORE_BLOCK(int32_t)

    } else {

        STORE_BLOCK(int16_t)

    }



    if(zeros_left<0){

        av_log(h->s.avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", s->mb_x, s->mb_y);

        return -1;

    }



    return 0;

}

static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff){

    MpegEncContext * const s = &h->s;

    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, (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, 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;

        }

    }

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



    



    if(total_coeff==0)

        return 0;

    if(total_coeff > (unsigned)max_coeff) {

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

        return -1;

    }



    trailing_ones= coeff_token&3;

    tprintf(h->s.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->s.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 (h->pixel_shift) {

        STORE_BLOCK(int32_t)

    } else {

        STORE_BLOCK(int16_t)

    }



    if(zeros_left<0){

        av_log(h->s.avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", s->mb_x, s->mb_y);

        return -1;

    }



    return 0;

}

    if(zeros_left<0){         av_log(h->s.avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", s->mb_x, s->mb_y);         return -1;
static int FUNC_0(H264Context *VAR_0, GetBitContext *VAR_1, DCTELEM *VAR_2, int VAR_3, const uint8_t *VAR_4, const uint32_t *VAR_5, int VAR_6){

    MpegEncContext * const s = &VAR_0->s;

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

    int VAR_8[16];

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



    



    if(VAR_6 <= 8){

        if (VAR_6 == 4)

            VAR_10 = get_vlc2(VAR_1, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1);

        else

            VAR_10 = get_vlc2(VAR_1, chroma422_dc_coeff_token_vlc.table, CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 1);

        VAR_11= VAR_10>>2;

    }else{

        if(VAR_3 >= LUMA_DC_BLOCK_INDEX){

            VAR_11= pred_non_zero_count(VAR_0, (VAR_3 - LUMA_DC_BLOCK_INDEX)*16);

            VAR_10= get_vlc2(VAR_1, coeff_token_vlc[ VAR_7[VAR_11] ].table, COEFF_TOKEN_VLC_BITS, 2);

            VAR_11= VAR_10>>2;

        }else{

            VAR_11= pred_non_zero_count(VAR_0, VAR_3);

            VAR_10= get_vlc2(VAR_1, coeff_token_vlc[ VAR_7[VAR_11] ].table, COEFF_TOKEN_VLC_BITS, 2);

            VAR_11= VAR_10>>2;

        }

    }

    VAR_0->non_zero_count_cache[ scan8[VAR_3] ]= VAR_11;



    



    if(VAR_11==0)

        return 0;

    if(VAR_11 > (unsigned)VAR_6) {

        av_log(VAR_0->s.avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (VAR_11=%d)\VAR_3", s->mb_x, s->mb_y, VAR_11);

        return -1;

    }



    VAR_13= VAR_10&3;

    tprintf(VAR_0->s.avctx, "trailing:%d, total:%d\VAR_3", VAR_13, VAR_11);

    assert(VAR_11<=16);



    VAR_12 = show_bits(VAR_1, 3);

    skip_bits(VAR_1, VAR_13);

    VAR_8[0] = 1-((VAR_12&4)>>1);

    VAR_8[1] = 1-((VAR_12&2)   );

    VAR_8[2] = 1-((VAR_12&1)<<1);



    if(VAR_13<VAR_11) {

        int VAR_15, VAR_16;

        int VAR_17 = VAR_11 > 10 & VAR_13 < 3;

        int VAR_21= show_bits(VAR_1, LEVEL_TAB_BITS);

        int VAR_19= cavlc_level_tab[VAR_17][VAR_21][0];



        skip_bits(VAR_1, cavlc_level_tab[VAR_17][VAR_21][1]);

        if(VAR_19 >= 100){

            VAR_16= VAR_19 - 100;

            if(VAR_16 == LEVEL_TAB_BITS)

                VAR_16 += get_level_prefix(VAR_1);



            

            if(VAR_16<14){ 

                if(VAR_17)

                    VAR_19= (VAR_16<<1) + get_bits1(VAR_1); 

                else

                    VAR_19= VAR_16; 

            }else if(VAR_16==14){

                if(VAR_17)

                    VAR_19= (VAR_16<<1) + get_bits1(VAR_1); 

                else

                    VAR_19= VAR_16 + get_bits(VAR_1, 4); 

            }else{

                VAR_19= 30 + get_bits(VAR_1, VAR_16-3); 

                if(VAR_16>=16){

                    if(VAR_16 > 25+3){

                        av_log(VAR_0->s.avctx, AV_LOG_ERROR, "Invalid VAR_8 VAR_16\VAR_3");

                        return -1;

                    }

                    VAR_19 += (1<<(VAR_16-3))-4096;

                }

            }



            if(VAR_13 < 3) VAR_19 += 2;



            VAR_17 = 2;

            VAR_15= -(VAR_19&1);

            VAR_8[VAR_13]= (((2+VAR_19)>>1) ^ VAR_15) - VAR_15;

        }else{

            VAR_19 += ((VAR_19>>31)|1) & -(VAR_13 < 3);



            VAR_17 = 1 + (VAR_19 + 3U > 6U);

            VAR_8[VAR_13]= VAR_19;

        }



        

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

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

            int VAR_21= show_bits(VAR_1, LEVEL_TAB_BITS);

            VAR_19= cavlc_level_tab[VAR_17][VAR_21][0];



            skip_bits(VAR_1, cavlc_level_tab[VAR_17][VAR_21][1]);

            if(VAR_19 >= 100){

                VAR_16= VAR_19 - 100;

                if(VAR_16 == LEVEL_TAB_BITS){

                    VAR_16 += get_level_prefix(VAR_1);

                }

                if(VAR_16<15){

                    VAR_19 = (VAR_16<<VAR_17) + get_bits(VAR_1, VAR_17);

                }else{

                    VAR_19 = (15<<VAR_17) + get_bits(VAR_1, VAR_16-3);

                    if(VAR_16>=16)

                        VAR_19 += (1<<(VAR_16-3))-4096;

                }

                VAR_15= -(VAR_19&1);

                VAR_19= (((2+VAR_19)>>1) ^ VAR_15) - VAR_15;

            }

            VAR_8[VAR_12]= VAR_19;

            VAR_17+= VAR_20[VAR_17] + VAR_19 > 2U*VAR_20[VAR_17];

        }

    }



    if(VAR_11 == VAR_6)

        VAR_9=0;

    else{

        if (VAR_6 <= 8) {

            if (VAR_6 == 4)

                VAR_9 = get_vlc2(VAR_1, chroma_dc_total_zeros_vlc[VAR_11 - 1].table,

                                      CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1);

            else

                VAR_9 = get_vlc2(VAR_1, chroma422_dc_total_zeros_vlc[VAR_11 - 1].table,

                                      CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 1);

        } else {

            VAR_9= get_vlc2(VAR_1, total_zeros_vlc[VAR_11 - 1].table, TOTAL_ZEROS_VLC_BITS, 1);

        }

    }



#define STORE_BLOCK(type) \

    VAR_4 += VAR_9 + VAR_11 - 1; \

    if(VAR_3 >= LUMA_DC_BLOCK_INDEX){ \

        ((type*)VAR_2)[*VAR_4] = VAR_8[0]; \

        for(VAR_12=1;VAR_12<VAR_11 && VAR_9 > 0;VAR_12++) { \

            if(VAR_9 < 7) \

                VAR_14= get_vlc2(VAR_1, run_vlc[VAR_9 - 1].table, RUN_VLC_BITS, 1); \

            else \

                VAR_14= get_vlc2(VAR_1, run7_vlc.table, RUN7_VLC_BITS, 2); \

            VAR_9 -= VAR_14; \

            VAR_4 -= 1 + VAR_14; \

            ((type*)VAR_2)[*VAR_4]= VAR_8[VAR_12]; \

        } \

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

            VAR_4--; \

            ((type*)VAR_2)[*VAR_4]= VAR_8[VAR_12]; \

        } \

    }else{ \

        ((type*)VAR_2)[*VAR_4] = ((int)(VAR_8[0] * VAR_5[*VAR_4] + 32))>>6; \

        for(VAR_12=1;VAR_12<VAR_11 && VAR_9 > 0;VAR_12++) { \

            if(VAR_9 < 7) \

                VAR_14= get_vlc2(VAR_1, run_vlc[VAR_9 - 1].table, RUN_VLC_BITS, 1); \

            else \

                VAR_14= get_vlc2(VAR_1, run7_vlc.table, RUN7_VLC_BITS, 2); \

            VAR_9 -= VAR_14; \

            VAR_4 -= 1 + VAR_14; \

            ((type*)VAR_2)[*VAR_4]= ((int)(VAR_8[VAR_12] * VAR_5[*VAR_4] + 32))>>6; \

        } \

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

            VAR_4--; \

            ((type*)VAR_2)[*VAR_4]= ((int)(VAR_8[VAR_12] * VAR_5[*VAR_4] + 32))>>6; \

        } \

    }



    if (VAR_0->pixel_shift) {

        STORE_BLOCK(int32_t)

    } else {

        STORE_BLOCK(int16_t)

    }



    if(VAR_9<0){

        av_log(VAR_0->s.avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\VAR_3", s->mb_x, s->mb_y);

        return -1;

    }



    return 0;

}

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