static int huffman_decode(MPADecodeContext *s, GranuleDef *g,

                          int16_t *exponents, int end_pos)

{

    int s_index;

    int linbits, code, x, y, l, v, i, j, k, pos;

    int last_pos;

    VLC *vlc;



    /* low frequencies (called big values) */

    s_index = 0;

    for(i=0;i<3;i++) {

        j = g->region_size[i];

        if (j == 0)

            continue;

        /* select vlc table */

        k = g->table_select[i];

        l = mpa_huff_data[k][0];

        linbits = mpa_huff_data[k][1];

        vlc = &huff_vlc[l];



        if(!l){

            memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid)*j);

            s_index += 2*j;

            continue;

        }



        /* read huffcode and compute each couple */

        for(;j>0;j--) {

            int exponent;



            if (get_bits_count(&s->gb) >= end_pos)

                break;

            y = get_vlc2(&s->gb, vlc->table, 7, 3);



            if(!y){

                g->sb_hybrid[s_index  ] =

                g->sb_hybrid[s_index+1] = 0;

                s_index += 2;

                continue;

            }



            x = y >> 4;

            y = y & 0x0f;

            exponent= exponents[s_index];



            dprintf("region=%d n=%d x=%d y=%d exp=%d\n",

                    i, g->region_size[i] - j, x, y, exponent);

            if (x) {

#if 0

                if (x == 15)

                    x += get_bitsz(&s->gb, linbits);

                v = l3_unscale(x, exponent);

#else

                if (x < 15){

                    v = expval_table[ exponent + 400 ][ x ];

//                      v = expval_table[ (exponent&3) + 400 ][ x ] >> FFMIN(0 - (exponent>>2), 31);

                }else{

                    x += get_bitsz(&s->gb, linbits);

                    v = l3_unscale(x, exponent);

                }

#endif

                if (get_bits1(&s->gb))

                    v = -v;

            } else {

                v = 0;

            }

            g->sb_hybrid[s_index++] = v;

            if (y) {

#if 0

                if (y == 15)

                    y += get_bitsz(&s->gb, linbits);

                v = l3_unscale(y, exponent);

#else

                if (y < 15){

                    v = expval_table[ exponent + 400 ][ y ];

                }else{

                    y += get_bitsz(&s->gb, linbits);

                    v = l3_unscale(y, exponent);

                }

#endif

                if (get_bits1(&s->gb))

                    v = -v;

            } else {

                v = 0;

            }

            g->sb_hybrid[s_index++] = v;

        }

    }



    /* high frequencies */

    vlc = &huff_quad_vlc[g->count1table_select];

    last_pos=0;

    while (s_index <= 572) {

        pos = get_bits_count(&s->gb);

        if (pos >= end_pos) {

            if (pos > end_pos && last_pos){

                /* some encoders generate an incorrect size for this

                   part. We must go back into the data */

                s_index -= 4;

                init_get_bits(&s->gb, s->gb.buffer + 4*(last_pos>>5), s->gb.size_in_bits - (last_pos&(~31)));

                skip_bits(&s->gb, last_pos&31);

            }

            break;

        }

        last_pos= pos;



        code = get_vlc2(&s->gb, vlc->table, vlc->bits, 1);

        dprintf("t=%d code=%d\n", g->count1table_select, code);

        g->sb_hybrid[s_index+0]=

        g->sb_hybrid[s_index+1]=

        g->sb_hybrid[s_index+2]=

        g->sb_hybrid[s_index+3]= 0;

        while(code){

            const static int idxtab[16]={3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0};

            int pos= s_index+idxtab[code];

            code ^= 8>>idxtab[code];

            v = exp_table[ exponents[pos] + 400];

            if(get_bits1(&s->gb))

                v = -v;

            g->sb_hybrid[pos] = v;

        }

        s_index+=4;

    }

    memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid)*(576 - s_index));

    return 0;

}

static int huffman_decode(MPADecodeContext *s, GranuleDef *g,

                          int16_t *exponents, int end_pos)

{

    int s_index;

    int linbits, code, x, y, l, v, i, j, k, pos;

    int last_pos;

    VLC *vlc;



    

    s_index = 0;

    for(i=0;i<3;i++) {

        j = g->region_size[i];

        if (j == 0)

            continue;

        

        k = g->table_select[i];

        l = mpa_huff_data[k][0];

        linbits = mpa_huff_data[k][1];

        vlc = &huff_vlc[l];



        if(!l){

            memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid)*j);

            s_index += 2*j;

            continue;

        }



        

        for(;j>0;j--) {

            int exponent;



            if (get_bits_count(&s->gb) >= end_pos)

                break;

            y = get_vlc2(&s->gb, vlc->table, 7, 3);



            if(!y){

                g->sb_hybrid[s_index  ] =

                g->sb_hybrid[s_index+1] = 0;

                s_index += 2;

                continue;

            }



            x = y >> 4;

            y = y & 0x0f;

            exponent= exponents[s_index];



            dprintf("region=%d n=%d x=%d y=%d exp=%d\n",

                    i, g->region_size[i] - j, x, y, exponent);

            if (x) {

#if 0

                if (x == 15)

                    x += get_bitsz(&s->gb, linbits);

                v = l3_unscale(x, exponent);

#else

                if (x < 15){

                    v = expval_table[ exponent + 400 ][ x ];



                }else{

                    x += get_bitsz(&s->gb, linbits);

                    v = l3_unscale(x, exponent);

                }

#endif

                if (get_bits1(&s->gb))

                    v = -v;

            } else {

                v = 0;

            }

            g->sb_hybrid[s_index++] = v;

            if (y) {

#if 0

                if (y == 15)

                    y += get_bitsz(&s->gb, linbits);

                v = l3_unscale(y, exponent);

#else

                if (y < 15){

                    v = expval_table[ exponent + 400 ][ y ];

                }else{

                    y += get_bitsz(&s->gb, linbits);

                    v = l3_unscale(y, exponent);

                }

#endif

                if (get_bits1(&s->gb))

                    v = -v;

            } else {

                v = 0;

            }

            g->sb_hybrid[s_index++] = v;

        }

    }



    

    vlc = &huff_quad_vlc[g->count1table_select];

    last_pos=0;

    while (s_index <= 572) {

        pos = get_bits_count(&s->gb);

        if (pos >= end_pos) {

            if (pos > end_pos && last_pos){

                



                s_index -= 4;

                init_get_bits(&s->gb, s->gb.buffer + 4*(last_pos>>5), s->gb.size_in_bits - (last_pos&(~31)));

                skip_bits(&s->gb, last_pos&31);

            }

            break;

        }

        last_pos= pos;



        code = get_vlc2(&s->gb, vlc->table, vlc->bits, 1);

        dprintf("t=%d code=%d\n", g->count1table_select, code);

        g->sb_hybrid[s_index+0]=

        g->sb_hybrid[s_index+1]=

        g->sb_hybrid[s_index+2]=

        g->sb_hybrid[s_index+3]= 0;

        while(code){

            const static int idxtab[16]={3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0};

            int pos= s_index+idxtab[code];

            code ^= 8>>idxtab[code];

            v = exp_table[ exponents[pos] + 400];

            if(get_bits1(&s->gb))

                v = -v;

            g->sb_hybrid[pos] = v;

        }

        s_index+=4;

    }

    memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid)*(576 - s_index));

    return 0;

}

static int FUNC_0(MPADecodeContext *VAR_0, GranuleDef *VAR_1,

                          int16_t *VAR_2, int VAR_3)

{

    int VAR_4;

    int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11, VAR_12, VAR_13, VAR_18;

    int VAR_15;

    VLC *vlc;



    

    VAR_4 = 0;

    for(VAR_11=0;VAR_11<3;VAR_11++) {

        VAR_12 = VAR_1->region_size[VAR_11];

        if (VAR_12 == 0)

            continue;

        

        VAR_13 = VAR_1->table_select[VAR_11];

        VAR_9 = mpa_huff_data[VAR_13][0];

        VAR_5 = mpa_huff_data[VAR_13][1];

        vlc = &huff_vlc[VAR_9];



        if(!VAR_9){

            memset(&VAR_1->sb_hybrid[VAR_4], 0, sizeof(*VAR_1->sb_hybrid)*VAR_12);

            VAR_4 += 2*VAR_12;

            continue;

        }



        

        for(;VAR_12>0;VAR_12--) {

            int VAR_16;



            if (get_bits_count(&VAR_0->gb) >= VAR_3)

                break;

            VAR_8 = get_vlc2(&VAR_0->gb, vlc->table, 7, 3);



            if(!VAR_8){

                VAR_1->sb_hybrid[VAR_4  ] =

                VAR_1->sb_hybrid[VAR_4+1] = 0;

                VAR_4 += 2;

                continue;

            }



            VAR_7 = VAR_8 >> 4;

            VAR_8 = VAR_8 & 0x0f;

            VAR_16= VAR_2[VAR_4];



            dprintf("region=%d n=%d VAR_7=%d VAR_8=%d exp=%d\n",

                    VAR_11, VAR_1->region_size[VAR_11] - VAR_12, VAR_7, VAR_8, VAR_16);

            if (VAR_7) {

#if 0

                if (VAR_7 == 15)

                    VAR_7 += get_bitsz(&VAR_0->gb, VAR_5);

                VAR_10 = l3_unscale(VAR_7, VAR_16);

#else

                if (VAR_7 < 15){

                    VAR_10 = expval_table[ VAR_16 + 400 ][ VAR_7 ];



                }else{

                    VAR_7 += get_bitsz(&VAR_0->gb, VAR_5);

                    VAR_10 = l3_unscale(VAR_7, VAR_16);

                }

#endif

                if (get_bits1(&VAR_0->gb))

                    VAR_10 = -VAR_10;

            } else {

                VAR_10 = 0;

            }

            VAR_1->sb_hybrid[VAR_4++] = VAR_10;

            if (VAR_8) {

#if 0

                if (VAR_8 == 15)

                    VAR_8 += get_bitsz(&VAR_0->gb, VAR_5);

                VAR_10 = l3_unscale(VAR_8, VAR_16);

#else

                if (VAR_8 < 15){

                    VAR_10 = expval_table[ VAR_16 + 400 ][ VAR_8 ];

                }else{

                    VAR_8 += get_bitsz(&VAR_0->gb, VAR_5);

                    VAR_10 = l3_unscale(VAR_8, VAR_16);

                }

#endif

                if (get_bits1(&VAR_0->gb))

                    VAR_10 = -VAR_10;

            } else {

                VAR_10 = 0;

            }

            VAR_1->sb_hybrid[VAR_4++] = VAR_10;

        }

    }



    

    vlc = &huff_quad_vlc[VAR_1->count1table_select];

    VAR_15=0;

    while (VAR_4 <= 572) {

        VAR_18 = get_bits_count(&VAR_0->gb);

        if (VAR_18 >= VAR_3) {

            if (VAR_18 > VAR_3 && VAR_15){

                



                VAR_4 -= 4;

                init_get_bits(&VAR_0->gb, VAR_0->gb.buffer + 4*(VAR_15>>5), VAR_0->gb.size_in_bits - (VAR_15&(~31)));

                skip_bits(&VAR_0->gb, VAR_15&31);

            }

            break;

        }

        VAR_15= VAR_18;



        VAR_6 = get_vlc2(&VAR_0->gb, vlc->table, vlc->bits, 1);

        dprintf("t=%d VAR_6=%d\n", VAR_1->count1table_select, VAR_6);

        VAR_1->sb_hybrid[VAR_4+0]=

        VAR_1->sb_hybrid[VAR_4+1]=

        VAR_1->sb_hybrid[VAR_4+2]=

        VAR_1->sb_hybrid[VAR_4+3]= 0;

        while(VAR_6){

            const static int VAR_17[16]={3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0};

            int VAR_18= VAR_4+VAR_17[VAR_6];

            VAR_6 ^= 8>>VAR_17[VAR_6];

            VAR_10 = exp_table[ VAR_2[VAR_18] + 400];

            if(get_bits1(&VAR_0->gb))

                VAR_10 = -VAR_10;

            VAR_1->sb_hybrid[VAR_18] = VAR_10;

        }

        VAR_4+=4;

    }

    memset(&VAR_1->sb_hybrid[VAR_4], 0, sizeof(*VAR_1->sb_hybrid)*(576 - VAR_4));

    return 0;

}

static int FUNC_0(MPADecodeContext *VAR_0, GranuleDef *VAR_1,
int16_t *VAR_2, int VAR_3)
{ int VAR_4; int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11, VAR_12, VAR_13, VAR_18; int VAR_15; VLC *vlc; VAR_4 = 0; for(VAR_11=0;VAR_11<3;VAR_11++) { VAR_12 = VAR_1->region_size[VAR_11]; if (VAR_12 == 0)
continue; VAR_13 = VAR_1->table_select[VAR_11]; VAR_9 = mpa_huff_data[VAR_13][0]; VAR_5 = mpa_huff_data[VAR_13][1]; vlc = &huff_vlc[VAR_9]; if(!VAR_9){ memset(&VAR_1->sb_hybrid[VAR_4], 0, sizeof(*VAR_1->sb_hybrid)*VAR_12); VAR_4 += 2*VAR_12; continue; } for(;VAR_12>0;VAR_12--) { int VAR_16; if (get_bits_count(&VAR_0->gb) >= VAR_3)
break; VAR_8 = get_vlc2(&VAR_0->gb, vlc->table, 7, 3); if(!VAR_8){ VAR_1->sb_hybrid[VAR_4  ] =
VAR_1->sb_hybrid[VAR_4+1] = 0; VAR_4 += 2; continue; } VAR_7 = VAR_8 >> 4; VAR_8 = VAR_8 & 0x0f; VAR_16= VAR_2[VAR_4]; dprintf("region=%d n=%d VAR_7=%d VAR_8=%d exp=%d\n",
VAR_11, VAR_1->region_size[VAR_11] - VAR_12, VAR_7, VAR_8, VAR_16); if (VAR_7) { #if 0
if (VAR_7 == 15)
VAR_7 += get_bitsz(&VAR_0->gb, VAR_5); VAR_10 = l3_unscale(VAR_7, VAR_16); #else
if (VAR_7 < 15){ VAR_10 = expval_table[ VAR_16 + 400 ][ VAR_7 ]; }else{ VAR_7 += get_bitsz(&VAR_0->gb, VAR_5); VAR_10 = l3_unscale(VAR_7, VAR_16); } #endif
if (get_bits1(&VAR_0->gb))
VAR_10 = -VAR_10; } else { VAR_10 = 0; } VAR_1->sb_hybrid[VAR_4++] = VAR_10; if (VAR_8) { #if 0
if (VAR_8 == 15)
VAR_8 += get_bitsz(&VAR_0->gb, VAR_5); VAR_10 = l3_unscale(VAR_8, VAR_16); #else
if (VAR_8 < 15){ VAR_10 = expval_table[ VAR_16 + 400 ][ VAR_8 ]; }else{ VAR_8 += get_bitsz(&VAR_0->gb, VAR_5); VAR_10 = l3_unscale(VAR_8, VAR_16); } #endif
if (get_bits1(&VAR_0->gb))
VAR_10 = -VAR_10; } else { VAR_10 = 0; } VAR_1->sb_hybrid[VAR_4++] = VAR_10; } } vlc = &huff_quad_vlc[VAR_1->count1table_select]; VAR_15=0; while (VAR_4 <= 572) { VAR_18 = get_bits_count(&VAR_0->gb); if (VAR_18 >= VAR_3) { if (VAR_18 > VAR_3 && VAR_15){ VAR_4 -= 4; init_get_bits(&VAR_0->gb, VAR_0->gb.buffer + 4*(VAR_15>>5), VAR_0->gb.size_in_bits - (VAR_15&(~31))); skip_bits(&VAR_0->gb, VAR_15&31); } break; } VAR_15= VAR_18; VAR_6 = get_vlc2(&VAR_0->gb, vlc->table, vlc->bits, 1); dprintf("t=%d VAR_6=%d\n", VAR_1->count1table_select, VAR_6); VAR_1->sb_hybrid[VAR_4+0]=
VAR_1->sb_hybrid[VAR_4+1]=
VAR_1->sb_hybrid[VAR_4+2]=
VAR_1->sb_hybrid[VAR_4+3]= 0; while(VAR_6){ const static int VAR_17[16]={3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0}; int VAR_18= VAR_4+VAR_17[VAR_6]; VAR_6 ^= 8>>VAR_17[VAR_6]; VAR_10 = exp_table[ VAR_2[VAR_18] + 400]; if(get_bits1(&VAR_0->gb))
VAR_10 = -VAR_10; VAR_1->sb_hybrid[VAR_18] = VAR_10; } VAR_4+=4; } memset(&VAR_1->sb_hybrid[VAR_4], 0, sizeof(*VAR_1->sb_hybrid)*(576 - VAR_4)); return 0; }