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

                          int16_t *exponents, int end_pos2)

{

    int s_index;

    int i;

    int last_pos, bits_left;

    VLC *vlc;

    int end_pos = FFMIN(end_pos2, s->gb.size_in_bits);



    /* low frequencies (called big values) */

    s_index = 0;

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

        int j, k, l, linbits;

        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) * 2 * j);

            s_index += 2 * j;

            continue;

        }



        /* read huffcode and compute each couple */

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

            int exponent, x, y;

            int v;

            int pos = get_bits_count(&s->gb);



            if (pos >= end_pos){

//                av_log(NULL, AV_LOG_ERROR, "pos: %d %d %d %d\n", pos, end_pos, end_pos2, s_index);

                switch_buffer(s, &pos, &end_pos, &end_pos2);

//                av_log(NULL, AV_LOG_ERROR, "new pos: %d %d\n", pos, end_pos);

                if (pos >= 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;

            }



            exponent= exponents[s_index];



            av_dlog(s->avctx, "region=%d n=%d x=%d y=%d exp=%d\n",

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

            if (y & 16) {

                x = y >> 5;

                y = y & 0x0f;

                if (x < 15) {

                    READ_FLIP_SIGN(g->sb_hybrid + s_index, RENAME(expval_table)[exponent] + x)

                } else {

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

                    v  = l3_unscale(x, exponent);

                    if (get_bits1(&s->gb))

                        v = -v;

                    g->sb_hybrid[s_index] = v;

                }

                if (y < 15) {

                    READ_FLIP_SIGN(g->sb_hybrid + s_index + 1, RENAME(expval_table)[exponent] + y)

                } else {

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

                    v  = l3_unscale(y, exponent);

                    if (get_bits1(&s->gb))

                        v = -v;

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

                }

            } else {

                x = y >> 5;

                y = y & 0x0f;

                x += y;

                if (x < 15) {

                    READ_FLIP_SIGN(g->sb_hybrid + s_index + !!y, RENAME(expval_table)[exponent] + x)

                } else {

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

                    v  = l3_unscale(x, exponent);

                    if (get_bits1(&s->gb))

                        v = -v;

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

                }

                g->sb_hybrid[s_index + !y] = 0;

            }

            s_index += 2;

        }

    }



    /* high frequencies */

    vlc = &huff_quad_vlc[g->count1table_select];

    last_pos = 0;

    while (s_index <= 572) {

        int pos, code;

        pos = get_bits_count(&s->gb);

        if (pos >= end_pos) {

            if (pos > end_pos2 && last_pos) {

                /* some encoders generate an incorrect size for this

                   part. We must go back into the data */

                s_index -= 4;

                skip_bits_long(&s->gb, last_pos - pos);

                av_log(s->avctx, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos);

                if(s->err_recognition & AV_EF_BITSTREAM)

                    s_index=0;

                break;

            }

//                av_log(NULL, AV_LOG_ERROR, "pos2: %d %d %d %d\n", pos, end_pos, end_pos2, s_index);

            switch_buffer(s, &pos, &end_pos, &end_pos2);

//                av_log(NULL, AV_LOG_ERROR, "new pos2: %d %d %d\n", pos, end_pos, s_index);

            if (pos >= end_pos)

                break;

        }

        last_pos = pos;



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

        av_dlog(s->avctx, "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) {

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

            int v;

            int pos = s_index + idxtab[code];

            code   ^= 8 >> idxtab[code];

            READ_FLIP_SIGN(g->sb_hybrid + pos, RENAME(exp_table)+exponents[pos])

        }

        s_index += 4;

    }

    /* skip extension bits */

    bits_left = end_pos2 - get_bits_count(&s->gb);

//av_log(NULL, AV_LOG_ERROR, "left:%d buf:%p\n", bits_left, s->in_gb.buffer);

    if (bits_left < 0 && (s->err_recognition & AV_EF_BITSTREAM)) {

        av_log(s->avctx, AV_LOG_ERROR, "bits_left=%d\n", bits_left);

        s_index=0;

    } else if (bits_left > 0 && (s->err_recognition & AV_EF_BUFFER)) {

        av_log(s->avctx, AV_LOG_ERROR, "bits_left=%d\n", bits_left);

        s_index = 0;

    }

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

    skip_bits_long(&s->gb, bits_left);



    i = get_bits_count(&s->gb);

    switch_buffer(s, &i, &end_pos, &end_pos2);



    return 0;

}

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

                          int16_t *exponents, int end_pos2)

{

    int s_index;

    int i;

    int last_pos, bits_left;

    VLC *vlc;

    int end_pos = FFMIN(end_pos2, s->gb.size_in_bits);



    

    s_index = 0;

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

        int j, k, l, linbits;

        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) * 2 * j);

            s_index += 2 * j;

            continue;

        }



        

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

            int exponent, x, y;

            int v;

            int pos = get_bits_count(&s->gb);



            if (pos >= end_pos){



                switch_buffer(s, &pos, &end_pos, &end_pos2);



                if (pos >= 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;

            }



            exponent= exponents[s_index];



            av_dlog(s->avctx, "region=%d n=%d x=%d y=%d exp=%d\n",

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

            if (y & 16) {

                x = y >> 5;

                y = y & 0x0f;

                if (x < 15) {

                    READ_FLIP_SIGN(g->sb_hybrid + s_index, RENAME(expval_table)[exponent] + x)

                } else {

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

                    v  = l3_unscale(x, exponent);

                    if (get_bits1(&s->gb))

                        v = -v;

                    g->sb_hybrid[s_index] = v;

                }

                if (y < 15) {

                    READ_FLIP_SIGN(g->sb_hybrid + s_index + 1, RENAME(expval_table)[exponent] + y)

                } else {

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

                    v  = l3_unscale(y, exponent);

                    if (get_bits1(&s->gb))

                        v = -v;

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

                }

            } else {

                x = y >> 5;

                y = y & 0x0f;

                x += y;

                if (x < 15) {

                    READ_FLIP_SIGN(g->sb_hybrid + s_index + !!y, RENAME(expval_table)[exponent] + x)

                } else {

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

                    v  = l3_unscale(x, exponent);

                    if (get_bits1(&s->gb))

                        v = -v;

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

                }

                g->sb_hybrid[s_index + !y] = 0;

            }

            s_index += 2;

        }

    }



    

    vlc = &huff_quad_vlc[g->count1table_select];

    last_pos = 0;

    while (s_index <= 572) {

        int pos, code;

        pos = get_bits_count(&s->gb);

        if (pos >= end_pos) {

            if (pos > end_pos2 && last_pos) {

                



                s_index -= 4;

                skip_bits_long(&s->gb, last_pos - pos);

                av_log(s->avctx, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos);

                if(s->err_recognition & AV_EF_BITSTREAM)

                    s_index=0;

                break;

            }



            switch_buffer(s, &pos, &end_pos, &end_pos2);



            if (pos >= end_pos)

                break;

        }

        last_pos = pos;



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

        av_dlog(s->avctx, "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) {

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

            int v;

            int pos = s_index + idxtab[code];

            code   ^= 8 >> idxtab[code];

            READ_FLIP_SIGN(g->sb_hybrid + pos, RENAME(exp_table)+exponents[pos])

        }

        s_index += 4;

    }

    

    bits_left = end_pos2 - get_bits_count(&s->gb);



    if (bits_left < 0 && (s->err_recognition & AV_EF_BITSTREAM)) {

        av_log(s->avctx, AV_LOG_ERROR, "bits_left=%d\n", bits_left);

        s_index=0;

    } else if (bits_left > 0 && (s->err_recognition & AV_EF_BUFFER)) {

        av_log(s->avctx, AV_LOG_ERROR, "bits_left=%d\n", bits_left);

        s_index = 0;

    }

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

    skip_bits_long(&s->gb, bits_left);



    i = get_bits_count(&s->gb);

    switch_buffer(s, &i, &end_pos, &end_pos2);



    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;

    int VAR_6, VAR_7;

    VLC *vlc;

    int VAR_8 = FFMIN(VAR_3, VAR_0->gb.size_in_bits);



    

    VAR_4 = 0;

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

        int VAR_9, VAR_10, VAR_11, VAR_12;

        VAR_9 = VAR_1->region_size[VAR_5];

        if (VAR_9 == 0)

            continue;

        

        VAR_10       = VAR_1->table_select[VAR_5];

        VAR_11       = mpa_huff_data[VAR_10][0];

        VAR_12 = mpa_huff_data[VAR_10][1];

        vlc     = &huff_vlc[VAR_11];



        if (!VAR_11) {

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

            VAR_4 += 2 * VAR_9;

            continue;

        }



        

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

            int VAR_13, VAR_14, VAR_15;

            int VAR_20;

            int VAR_20 = get_bits_count(&VAR_0->gb);



            if (VAR_20 >= VAR_8){



                switch_buffer(VAR_0, &VAR_20, &VAR_8, &VAR_3);



                if (VAR_20 >= VAR_8)

                    break;

            }

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



            if (!VAR_15) {

                VAR_1->sb_hybrid[VAR_4  ] =

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

                VAR_4 += 2;

                continue;

            }



            VAR_13= VAR_2[VAR_4];



            av_dlog(VAR_0->avctx, "region=%d n=%d VAR_14=%d VAR_15=%d exp=%d\n",

                    VAR_5, VAR_1->region_size[VAR_5] - VAR_9, VAR_14, VAR_15, VAR_13);

            if (VAR_15 & 16) {

                VAR_14 = VAR_15 >> 5;

                VAR_15 = VAR_15 & 0x0f;

                if (VAR_14 < 15) {

                    READ_FLIP_SIGN(VAR_1->sb_hybrid + VAR_4, RENAME(expval_table)[VAR_13] + VAR_14)

                } else {

                    VAR_14 += get_bitsz(&VAR_0->gb, VAR_12);

                    VAR_20  = l3_unscale(VAR_14, VAR_13);

                    if (get_bits1(&VAR_0->gb))

                        VAR_20 = -VAR_20;

                    VAR_1->sb_hybrid[VAR_4] = VAR_20;

                }

                if (VAR_15 < 15) {

                    READ_FLIP_SIGN(VAR_1->sb_hybrid + VAR_4 + 1, RENAME(expval_table)[VAR_13] + VAR_15)

                } else {

                    VAR_15 += get_bitsz(&VAR_0->gb, VAR_12);

                    VAR_20  = l3_unscale(VAR_15, VAR_13);

                    if (get_bits1(&VAR_0->gb))

                        VAR_20 = -VAR_20;

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

                }

            } else {

                VAR_14 = VAR_15 >> 5;

                VAR_15 = VAR_15 & 0x0f;

                VAR_14 += VAR_15;

                if (VAR_14 < 15) {

                    READ_FLIP_SIGN(VAR_1->sb_hybrid + VAR_4 + !!VAR_15, RENAME(expval_table)[VAR_13] + VAR_14)

                } else {

                    VAR_14 += get_bitsz(&VAR_0->gb, VAR_12);

                    VAR_20  = l3_unscale(VAR_14, VAR_13);

                    if (get_bits1(&VAR_0->gb))

                        VAR_20 = -VAR_20;

                    VAR_1->sb_hybrid[VAR_4+!!VAR_15] = VAR_20;

                }

                VAR_1->sb_hybrid[VAR_4 + !VAR_15] = 0;

            }

            VAR_4 += 2;

        }

    }



    

    vlc = &huff_quad_vlc[VAR_1->count1table_select];

    VAR_6 = 0;

    while (VAR_4 <= 572) {

        int VAR_20, VAR_18;

        VAR_20 = get_bits_count(&VAR_0->gb);

        if (VAR_20 >= VAR_8) {

            if (VAR_20 > VAR_3 && VAR_6) {

                



                VAR_4 -= 4;

                skip_bits_long(&VAR_0->gb, VAR_6 - VAR_20);

                av_log(VAR_0->avctx, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", VAR_6 - VAR_20, VAR_8-VAR_20, VAR_3-VAR_20);

                if(VAR_0->err_recognition & AV_EF_BITSTREAM)

                    VAR_4=0;

                break;

            }



            switch_buffer(VAR_0, &VAR_20, &VAR_8, &VAR_3);



            if (VAR_20 >= VAR_8)

                break;

        }

        VAR_6 = VAR_20;



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

        av_dlog(VAR_0->avctx, "t=%d VAR_18=%d\n", VAR_1->count1table_select, VAR_18);

        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_18) {

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

            int VAR_20;

            int VAR_20 = VAR_4 + VAR_19[VAR_18];

            VAR_18   ^= 8 >> VAR_19[VAR_18];

            READ_FLIP_SIGN(VAR_1->sb_hybrid + VAR_20, RENAME(exp_table)+VAR_2[VAR_20])

        }

        VAR_4 += 4;

    }

    

    VAR_7 = VAR_3 - get_bits_count(&VAR_0->gb);



    if (VAR_7 < 0 && (VAR_0->err_recognition & AV_EF_BITSTREAM)) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_7=%d\n", VAR_7);

        VAR_4=0;

    } else if (VAR_7 > 0 && (VAR_0->err_recognition & AV_EF_BUFFER)) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_7=%d\n", VAR_7);

        VAR_4 = 0;

    }

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

    skip_bits_long(&VAR_0->gb, VAR_7);



    VAR_5 = get_bits_count(&VAR_0->gb);

    switch_buffer(VAR_0, &VAR_5, &VAR_8, &VAR_3);



    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; int VAR_6, VAR_7; VLC *vlc; int VAR_8 = FFMIN(VAR_3, VAR_0->gb.size_in_bits); VAR_4 = 0; for (VAR_5 = 0; VAR_5 < 3; VAR_5++) { int VAR_9, VAR_10, VAR_11, VAR_12; VAR_9 = VAR_1->region_size[VAR_5]; if (VAR_9 == 0)
continue; VAR_10       = VAR_1->table_select[VAR_5]; VAR_11       = mpa_huff_data[VAR_10][0]; VAR_12 = mpa_huff_data[VAR_10][1]; vlc     = &huff_vlc[VAR_11]; if (!VAR_11) { memset(&VAR_1->sb_hybrid[VAR_4], 0, sizeof(*VAR_1->sb_hybrid) * 2 * VAR_9); VAR_4 += 2 * VAR_9; continue; } for (; VAR_9 > 0; VAR_9--) { int VAR_13, VAR_14, VAR_15; int VAR_20; int VAR_20 = get_bits_count(&VAR_0->gb); if (VAR_20 >= VAR_8){ switch_buffer(VAR_0, &VAR_20, &VAR_8, &VAR_3); if (VAR_20 >= VAR_8)
break; } VAR_15 = get_vlc2(&VAR_0->gb, vlc->table, 7, 3); if (!VAR_15) { VAR_1->sb_hybrid[VAR_4  ] =
VAR_1->sb_hybrid[VAR_4+1] = 0; VAR_4 += 2; continue; } VAR_13= VAR_2[VAR_4]; av_dlog(VAR_0->avctx, "region=%d n=%d VAR_14=%d VAR_15=%d exp=%d\n",
VAR_5, VAR_1->region_size[VAR_5] - VAR_9, VAR_14, VAR_15, VAR_13); if (VAR_15 & 16) { VAR_14 = VAR_15 >> 5; VAR_15 = VAR_15 & 0x0f; if (VAR_14 < 15) { READ_FLIP_SIGN(VAR_1->sb_hybrid + VAR_4, RENAME(expval_table)[VAR_13] + VAR_14)
} else { VAR_14 += get_bitsz(&VAR_0->gb, VAR_12); VAR_20  = l3_unscale(VAR_14, VAR_13); if (get_bits1(&VAR_0->gb))
VAR_20 = -VAR_20; VAR_1->sb_hybrid[VAR_4] = VAR_20; } if (VAR_15 < 15) { READ_FLIP_SIGN(VAR_1->sb_hybrid + VAR_4 + 1, RENAME(expval_table)[VAR_13] + VAR_15)
} else { VAR_15 += get_bitsz(&VAR_0->gb, VAR_12); VAR_20  = l3_unscale(VAR_15, VAR_13); if (get_bits1(&VAR_0->gb))
VAR_20 = -VAR_20; VAR_1->sb_hybrid[VAR_4+1] = VAR_20; } } else { VAR_14 = VAR_15 >> 5; VAR_15 = VAR_15 & 0x0f; VAR_14 += VAR_15; if (VAR_14 < 15) { READ_FLIP_SIGN(VAR_1->sb_hybrid + VAR_4 + !!VAR_15, RENAME(expval_table)[VAR_13] + VAR_14)
} else { VAR_14 += get_bitsz(&VAR_0->gb, VAR_12); VAR_20  = l3_unscale(VAR_14, VAR_13); if (get_bits1(&VAR_0->gb))
VAR_20 = -VAR_20; VAR_1->sb_hybrid[VAR_4+!!VAR_15] = VAR_20; } VAR_1->sb_hybrid[VAR_4 + !VAR_15] = 0; } VAR_4 += 2; } } vlc = &huff_quad_vlc[VAR_1->count1table_select]; VAR_6 = 0; while (VAR_4 <= 572) { int VAR_20, VAR_18; VAR_20 = get_bits_count(&VAR_0->gb); if (VAR_20 >= VAR_8) { if (VAR_20 > VAR_3 && VAR_6) { VAR_4 -= 4; skip_bits_long(&VAR_0->gb, VAR_6 - VAR_20); av_log(VAR_0->avctx, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", VAR_6 - VAR_20, VAR_8-VAR_20, VAR_3-VAR_20); if(VAR_0->err_recognition & AV_EF_BITSTREAM)
VAR_4=0; break; } switch_buffer(VAR_0, &VAR_20, &VAR_8, &VAR_3); if (VAR_20 >= VAR_8)
break; } VAR_6 = VAR_20; VAR_18 = get_vlc2(&VAR_0->gb, vlc->table, vlc->bits, 1); av_dlog(VAR_0->avctx, "t=%d VAR_18=%d\n", VAR_1->count1table_select, VAR_18); 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_18) { static const int VAR_19[16] = { 3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0 }; int VAR_20; int VAR_20 = VAR_4 + VAR_19[VAR_18]; VAR_18   ^= 8 >> VAR_19[VAR_18]; READ_FLIP_SIGN(VAR_1->sb_hybrid + VAR_20, RENAME(exp_table)+VAR_2[VAR_20])
} VAR_4 += 4; } VAR_7 = VAR_3 - get_bits_count(&VAR_0->gb); if (VAR_7 < 0 && (VAR_0->err_recognition & AV_EF_BITSTREAM)) { av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_7=%d\n", VAR_7); VAR_4=0; } else if (VAR_7 > 0 && (VAR_0->err_recognition & AV_EF_BUFFER)) { av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_7=%d\n", VAR_7); VAR_4 = 0; } memset(&VAR_1->sb_hybrid[VAR_4], 0, sizeof(*VAR_1->sb_hybrid) * (576 - VAR_4)); skip_bits_long(&VAR_0->gb, VAR_7); VAR_5 = get_bits_count(&VAR_0->gb); switch_buffer(VAR_0, &VAR_5, &VAR_8, &VAR_3); return 0; }