static int mp_decode_layer3(MPADecodeContext *s)

{

    int nb_granules, main_data_begin;

    int gr, ch, blocksplit_flag, i, j, k, n, bits_pos;

    GranuleDef *g;

    int16_t exponents[576]; //FIXME try INTFLOAT



    /* read side info */

    if (s->lsf) {

        main_data_begin = get_bits(&s->gb, 8);

        skip_bits(&s->gb, s->nb_channels);

        nb_granules = 1;

    } else {

        main_data_begin = get_bits(&s->gb, 9);

        if (s->nb_channels == 2)

            skip_bits(&s->gb, 3);

        else

            skip_bits(&s->gb, 5);

        nb_granules = 2;

        for (ch = 0; ch < s->nb_channels; ch++) {

            s->granules[ch][0].scfsi = 0;/* all scale factors are transmitted */

            s->granules[ch][1].scfsi = get_bits(&s->gb, 4);

        }

    }



    for (gr = 0; gr < nb_granules; gr++) {

        for (ch = 0; ch < s->nb_channels; ch++) {

            av_dlog(s->avctx, "gr=%d ch=%d: side_info\n", gr, ch);

            g = &s->granules[ch][gr];

            g->part2_3_length = get_bits(&s->gb, 12);

            g->big_values     = get_bits(&s->gb,  9);

            if (g->big_values > 288) {

                av_log(s->avctx, AV_LOG_ERROR, "big_values too big\n");

                return AVERROR_INVALIDDATA;

            }



            g->global_gain = get_bits(&s->gb, 8);

            /* if MS stereo only is selected, we precompute the

               1/sqrt(2) renormalization factor */

            if ((s->mode_ext & (MODE_EXT_MS_STEREO | MODE_EXT_I_STEREO)) ==

                MODE_EXT_MS_STEREO)

                g->global_gain -= 2;

            if (s->lsf)

                g->scalefac_compress = get_bits(&s->gb, 9);

            else

                g->scalefac_compress = get_bits(&s->gb, 4);

            blocksplit_flag = get_bits1(&s->gb);

            if (blocksplit_flag) {

                g->block_type = get_bits(&s->gb, 2);

                if (g->block_type == 0) {

                    av_log(s->avctx, AV_LOG_ERROR, "invalid block type\n");

                    return AVERROR_INVALIDDATA;

                }

                g->switch_point = get_bits1(&s->gb);

                for (i = 0; i < 2; i++)

                    g->table_select[i] = get_bits(&s->gb, 5);

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

                    g->subblock_gain[i] = get_bits(&s->gb, 3);

                ff_init_short_region(s, g);

            } else {

                int region_address1, region_address2;

                g->block_type = 0;

                g->switch_point = 0;

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

                    g->table_select[i] = get_bits(&s->gb, 5);

                /* compute huffman coded region sizes */

                region_address1 = get_bits(&s->gb, 4);

                region_address2 = get_bits(&s->gb, 3);

                av_dlog(s->avctx, "region1=%d region2=%d\n",

                        region_address1, region_address2);

                ff_init_long_region(s, g, region_address1, region_address2);

            }

            ff_region_offset2size(g);

            ff_compute_band_indexes(s, g);



            g->preflag = 0;

            if (!s->lsf)

                g->preflag = get_bits1(&s->gb);

            g->scalefac_scale     = get_bits1(&s->gb);

            g->count1table_select = get_bits1(&s->gb);

            av_dlog(s->avctx, "block_type=%d switch_point=%d\n",

                    g->block_type, g->switch_point);

        }

    }



    if (!s->adu_mode) {

        const uint8_t *ptr = s->gb.buffer + (get_bits_count(&s->gb)>>3);

        assert((get_bits_count(&s->gb) & 7) == 0);

        /* now we get bits from the main_data_begin offset */

        av_dlog(s->avctx, "seekback: %d\n", main_data_begin);

    //av_log(NULL, AV_LOG_ERROR, "backstep:%d, lastbuf:%d\n", main_data_begin, s->last_buf_size);



        memcpy(s->last_buf + s->last_buf_size, ptr, EXTRABYTES);

        s->in_gb = s->gb;

        init_get_bits(&s->gb, s->last_buf, s->last_buf_size*8);

#if !UNCHECKED_BITSTREAM_READER

        s->gb.size_in_bits_plus8 += EXTRABYTES * 8;

#endif

        s->last_buf_size <<= 3;

        for (gr = 0, ch = 0; gr < nb_granules && (s->last_buf_size >> 3) < main_data_begin; gr++, ch = 0) {

            for (; ch < s->nb_channels && (s->last_buf_size >> 3) < main_data_begin; ch++) {

                g = &s->granules[ch][gr];

                s->last_buf_size += g->part2_3_length;

                memset(g->sb_hybrid, 0, sizeof(g->sb_hybrid));

            }

        }

        skip_bits_long(&s->gb, s->last_buf_size - 8 * main_data_begin);

        if (get_bits_count(&s->gb) >= s->gb.size_in_bits && s->in_gb.buffer) {

            skip_bits_long(&s->in_gb, get_bits_count(&s->gb) - s->gb.size_in_bits);

            s->gb           = s->in_gb;

            s->in_gb.buffer = NULL;

        }

    } else {

        gr = ch = 0;

    }



    for (; gr < nb_granules; gr++, ch = 0) {

        for (; ch < s->nb_channels; ch++) {

            g = &s->granules[ch][gr];

            bits_pos = get_bits_count(&s->gb);



            if (!s->lsf) {

                uint8_t *sc;

                int slen, slen1, slen2;



                /* MPEG1 scale factors */

                slen1 = slen_table[0][g->scalefac_compress];

                slen2 = slen_table[1][g->scalefac_compress];

                av_dlog(s->avctx, "slen1=%d slen2=%d\n", slen1, slen2);

                if (g->block_type == 2) {

                    n = g->switch_point ? 17 : 18;

                    j = 0;

                    if (slen1) {

                        for (i = 0; i < n; i++)

                            g->scale_factors[j++] = get_bits(&s->gb, slen1);

                    } else {

                        for (i = 0; i < n; i++)

                            g->scale_factors[j++] = 0;

                    }

                    if (slen2) {

                        for (i = 0; i < 18; i++)

                            g->scale_factors[j++] = get_bits(&s->gb, slen2);

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

                            g->scale_factors[j++] = 0;

                    } else {

                        for (i = 0; i < 21; i++)

                            g->scale_factors[j++] = 0;

                    }

                } else {

                    sc = s->granules[ch][0].scale_factors;

                    j = 0;

                    for (k = 0; k < 4; k++) {

                        n = k == 0 ? 6 : 5;

                        if ((g->scfsi & (0x8 >> k)) == 0) {

                            slen = (k < 2) ? slen1 : slen2;

                            if (slen) {

                                for (i = 0; i < n; i++)

                                    g->scale_factors[j++] = get_bits(&s->gb, slen);

                            } else {

                                for (i = 0; i < n; i++)

                                    g->scale_factors[j++] = 0;

                            }

                        } else {

                            /* simply copy from last granule */

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

                                g->scale_factors[j] = sc[j];

                                j++;

                            }

                        }

                    }

                    g->scale_factors[j++] = 0;

                }

            } else {

                int tindex, tindex2, slen[4], sl, sf;



                /* LSF scale factors */

                if (g->block_type == 2)

                    tindex = g->switch_point ? 2 : 1;

                else

                    tindex = 0;



                sf = g->scalefac_compress;

                if ((s->mode_ext & MODE_EXT_I_STEREO) && ch == 1) {

                    /* intensity stereo case */

                    sf >>= 1;

                    if (sf < 180) {

                        lsf_sf_expand(slen, sf, 6, 6, 0);

                        tindex2 = 3;

                    } else if (sf < 244) {

                        lsf_sf_expand(slen, sf - 180, 4, 4, 0);

                        tindex2 = 4;

                    } else {

                        lsf_sf_expand(slen, sf - 244, 3, 0, 0);

                        tindex2 = 5;

                    }

                } else {

                    /* normal case */

                    if (sf < 400) {

                        lsf_sf_expand(slen, sf, 5, 4, 4);

                        tindex2 = 0;

                    } else if (sf < 500) {

                        lsf_sf_expand(slen, sf - 400, 5, 4, 0);

                        tindex2 = 1;

                    } else {

                        lsf_sf_expand(slen, sf - 500, 3, 0, 0);

                        tindex2 = 2;

                        g->preflag = 1;

                    }

                }



                j = 0;

                for (k = 0; k < 4; k++) {

                    n  = lsf_nsf_table[tindex2][tindex][k];

                    sl = slen[k];

                    if (sl) {

                        for (i = 0; i < n; i++)

                            g->scale_factors[j++] = get_bits(&s->gb, sl);

                    } else {

                        for (i = 0; i < n; i++)

                            g->scale_factors[j++] = 0;

                    }

                }

                /* XXX: should compute exact size */

                for (; j < 40; j++)

                    g->scale_factors[j] = 0;

            }



            exponents_from_scale_factors(s, g, exponents);



            /* read Huffman coded residue */

            huffman_decode(s, g, exponents, bits_pos + g->part2_3_length);

        } /* ch */



        if (s->nb_channels == 2)

            compute_stereo(s, &s->granules[0][gr], &s->granules[1][gr]);



        for (ch = 0; ch < s->nb_channels; ch++) {

            g = &s->granules[ch][gr];



            reorder_block(s, g);

            compute_antialias(s, g);

            compute_imdct(s, g, &s->sb_samples[ch][18 * gr][0], s->mdct_buf[ch]);

        }

    } /* gr */

    if (get_bits_count(&s->gb) < 0)

        skip_bits_long(&s->gb, -get_bits_count(&s->gb));

    return nb_granules * 18;

}

static int mp_decode_layer3(MPADecodeContext *s)

{

    int nb_granules, main_data_begin;

    int gr, ch, blocksplit_flag, i, j, k, n, bits_pos;

    GranuleDef *g;

    int16_t exponents[576]; 



    

    if (s->lsf) {

        main_data_begin = get_bits(&s->gb, 8);

        skip_bits(&s->gb, s->nb_channels);

        nb_granules = 1;

    } else {

        main_data_begin = get_bits(&s->gb, 9);

        if (s->nb_channels == 2)

            skip_bits(&s->gb, 3);

        else

            skip_bits(&s->gb, 5);

        nb_granules = 2;

        for (ch = 0; ch < s->nb_channels; ch++) {

            s->granules[ch][0].scfsi = 0;

            s->granules[ch][1].scfsi = get_bits(&s->gb, 4);

        }

    }



    for (gr = 0; gr < nb_granules; gr++) {

        for (ch = 0; ch < s->nb_channels; ch++) {

            av_dlog(s->avctx, "gr=%d ch=%d: side_info\n", gr, ch);

            g = &s->granules[ch][gr];

            g->part2_3_length = get_bits(&s->gb, 12);

            g->big_values     = get_bits(&s->gb,  9);

            if (g->big_values > 288) {

                av_log(s->avctx, AV_LOG_ERROR, "big_values too big\n");

                return AVERROR_INVALIDDATA;

            }



            g->global_gain = get_bits(&s->gb, 8);

            



            if ((s->mode_ext & (MODE_EXT_MS_STEREO | MODE_EXT_I_STEREO)) ==

                MODE_EXT_MS_STEREO)

                g->global_gain -= 2;

            if (s->lsf)

                g->scalefac_compress = get_bits(&s->gb, 9);

            else

                g->scalefac_compress = get_bits(&s->gb, 4);

            blocksplit_flag = get_bits1(&s->gb);

            if (blocksplit_flag) {

                g->block_type = get_bits(&s->gb, 2);

                if (g->block_type == 0) {

                    av_log(s->avctx, AV_LOG_ERROR, "invalid block type\n");

                    return AVERROR_INVALIDDATA;

                }

                g->switch_point = get_bits1(&s->gb);

                for (i = 0; i < 2; i++)

                    g->table_select[i] = get_bits(&s->gb, 5);

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

                    g->subblock_gain[i] = get_bits(&s->gb, 3);

                ff_init_short_region(s, g);

            } else {

                int region_address1, region_address2;

                g->block_type = 0;

                g->switch_point = 0;

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

                    g->table_select[i] = get_bits(&s->gb, 5);

                

                region_address1 = get_bits(&s->gb, 4);

                region_address2 = get_bits(&s->gb, 3);

                av_dlog(s->avctx, "region1=%d region2=%d\n",

                        region_address1, region_address2);

                ff_init_long_region(s, g, region_address1, region_address2);

            }

            ff_region_offset2size(g);

            ff_compute_band_indexes(s, g);



            g->preflag = 0;

            if (!s->lsf)

                g->preflag = get_bits1(&s->gb);

            g->scalefac_scale     = get_bits1(&s->gb);

            g->count1table_select = get_bits1(&s->gb);

            av_dlog(s->avctx, "block_type=%d switch_point=%d\n",

                    g->block_type, g->switch_point);

        }

    }



    if (!s->adu_mode) {

        const uint8_t *ptr = s->gb.buffer + (get_bits_count(&s->gb)>>3);

        assert((get_bits_count(&s->gb) & 7) == 0);

        

        av_dlog(s->avctx, "seekback: %d\n", main_data_begin);

    



        memcpy(s->last_buf + s->last_buf_size, ptr, EXTRABYTES);

        s->in_gb = s->gb;

        init_get_bits(&s->gb, s->last_buf, s->last_buf_size*8);

#if !UNCHECKED_BITSTREAM_READER

        s->gb.size_in_bits_plus8 += EXTRABYTES * 8;

#endif

        s->last_buf_size <<= 3;

        for (gr = 0, ch = 0; gr < nb_granules && (s->last_buf_size >> 3) < main_data_begin; gr++, ch = 0) {

            for (; ch < s->nb_channels && (s->last_buf_size >> 3) < main_data_begin; ch++) {

                g = &s->granules[ch][gr];

                s->last_buf_size += g->part2_3_length;

                memset(g->sb_hybrid, 0, sizeof(g->sb_hybrid));

            }

        }

        skip_bits_long(&s->gb, s->last_buf_size - 8 * main_data_begin);

        if (get_bits_count(&s->gb) >= s->gb.size_in_bits && s->in_gb.buffer) {

            skip_bits_long(&s->in_gb, get_bits_count(&s->gb) - s->gb.size_in_bits);

            s->gb           = s->in_gb;

            s->in_gb.buffer = NULL;

        }

    } else {

        gr = ch = 0;

    }



    for (; gr < nb_granules; gr++, ch = 0) {

        for (; ch < s->nb_channels; ch++) {

            g = &s->granules[ch][gr];

            bits_pos = get_bits_count(&s->gb);



            if (!s->lsf) {

                uint8_t *sc;

                int slen, slen1, slen2;



                

                slen1 = slen_table[0][g->scalefac_compress];

                slen2 = slen_table[1][g->scalefac_compress];

                av_dlog(s->avctx, "slen1=%d slen2=%d\n", slen1, slen2);

                if (g->block_type == 2) {

                    n = g->switch_point ? 17 : 18;

                    j = 0;

                    if (slen1) {

                        for (i = 0; i < n; i++)

                            g->scale_factors[j++] = get_bits(&s->gb, slen1);

                    } else {

                        for (i = 0; i < n; i++)

                            g->scale_factors[j++] = 0;

                    }

                    if (slen2) {

                        for (i = 0; i < 18; i++)

                            g->scale_factors[j++] = get_bits(&s->gb, slen2);

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

                            g->scale_factors[j++] = 0;

                    } else {

                        for (i = 0; i < 21; i++)

                            g->scale_factors[j++] = 0;

                    }

                } else {

                    sc = s->granules[ch][0].scale_factors;

                    j = 0;

                    for (k = 0; k < 4; k++) {

                        n = k == 0 ? 6 : 5;

                        if ((g->scfsi & (0x8 >> k)) == 0) {

                            slen = (k < 2) ? slen1 : slen2;

                            if (slen) {

                                for (i = 0; i < n; i++)

                                    g->scale_factors[j++] = get_bits(&s->gb, slen);

                            } else {

                                for (i = 0; i < n; i++)

                                    g->scale_factors[j++] = 0;

                            }

                        } else {

                            

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

                                g->scale_factors[j] = sc[j];

                                j++;

                            }

                        }

                    }

                    g->scale_factors[j++] = 0;

                }

            } else {

                int tindex, tindex2, slen[4], sl, sf;



                

                if (g->block_type == 2)

                    tindex = g->switch_point ? 2 : 1;

                else

                    tindex = 0;



                sf = g->scalefac_compress;

                if ((s->mode_ext & MODE_EXT_I_STEREO) && ch == 1) {

                    

                    sf >>= 1;

                    if (sf < 180) {

                        lsf_sf_expand(slen, sf, 6, 6, 0);

                        tindex2 = 3;

                    } else if (sf < 244) {

                        lsf_sf_expand(slen, sf - 180, 4, 4, 0);

                        tindex2 = 4;

                    } else {

                        lsf_sf_expand(slen, sf - 244, 3, 0, 0);

                        tindex2 = 5;

                    }

                } else {

                    

                    if (sf < 400) {

                        lsf_sf_expand(slen, sf, 5, 4, 4);

                        tindex2 = 0;

                    } else if (sf < 500) {

                        lsf_sf_expand(slen, sf - 400, 5, 4, 0);

                        tindex2 = 1;

                    } else {

                        lsf_sf_expand(slen, sf - 500, 3, 0, 0);

                        tindex2 = 2;

                        g->preflag = 1;

                    }

                }



                j = 0;

                for (k = 0; k < 4; k++) {

                    n  = lsf_nsf_table[tindex2][tindex][k];

                    sl = slen[k];

                    if (sl) {

                        for (i = 0; i < n; i++)

                            g->scale_factors[j++] = get_bits(&s->gb, sl);

                    } else {

                        for (i = 0; i < n; i++)

                            g->scale_factors[j++] = 0;

                    }

                }

                

                for (; j < 40; j++)

                    g->scale_factors[j] = 0;

            }



            exponents_from_scale_factors(s, g, exponents);



            

            huffman_decode(s, g, exponents, bits_pos + g->part2_3_length);

        } 



        if (s->nb_channels == 2)

            compute_stereo(s, &s->granules[0][gr], &s->granules[1][gr]);



        for (ch = 0; ch < s->nb_channels; ch++) {

            g = &s->granules[ch][gr];



            reorder_block(s, g);

            compute_antialias(s, g);

            compute_imdct(s, g, &s->sb_samples[ch][18 * gr][0], s->mdct_buf[ch]);

        }

    } 

    if (get_bits_count(&s->gb) < 0)

        skip_bits_long(&s->gb, -get_bits_count(&s->gb));

    return nb_granules * 18;

}

        for (gr = 0, ch = 0; gr < nb_granules && (s->last_buf_size >> 3) < main_data_begin; gr++, ch = 0) {             for (; ch < s->nb_channels && (s->last_buf_size >> 3) < main_data_begin; ch++) {         skip_bits_long(&s->gb, s->last_buf_size - 8 * main_data_begin);         if (get_bits_count(&s->gb) >= s->gb.size_in_bits && s->in_gb.buffer) {             skip_bits_long(&s->in_gb, get_bits_count(&s->gb) - s->gb.size_in_bits);         gr = ch = 0;     for (; gr < nb_granules; gr++, ch = 0) {         for (; ch < s->nb_channels; ch++) {
static int FUNC_0(MPADecodeContext *VAR_0)

{

    int VAR_1, VAR_2;

    int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10;

    GranuleDef *g;

    int16_t exponents[576]; 



    

    if (VAR_0->lsf) {

        VAR_2 = get_bits(&VAR_0->gb, 8);

        skip_bits(&VAR_0->gb, VAR_0->nb_channels);

        VAR_1 = 1;

    } else {

        VAR_2 = get_bits(&VAR_0->gb, 9);

        if (VAR_0->nb_channels == 2)

            skip_bits(&VAR_0->gb, 3);

        else

            skip_bits(&VAR_0->gb, 5);

        VAR_1 = 2;

        for (VAR_4 = 0; VAR_4 < VAR_0->nb_channels; VAR_4++) {

            VAR_0->granules[VAR_4][0].scfsi = 0;

            VAR_0->granules[VAR_4][1].scfsi = get_bits(&VAR_0->gb, 4);

        }

    }



    for (VAR_3 = 0; VAR_3 < VAR_1; VAR_3++) {

        for (VAR_4 = 0; VAR_4 < VAR_0->nb_channels; VAR_4++) {

            av_dlog(VAR_0->avctx, "VAR_3=%d VAR_4=%d: side_info\VAR_9", VAR_3, VAR_4);

            g = &VAR_0->granules[VAR_4][VAR_3];

            g->part2_3_length = get_bits(&VAR_0->gb, 12);

            g->big_values     = get_bits(&VAR_0->gb,  9);

            if (g->big_values > 288) {

                av_log(VAR_0->avctx, AV_LOG_ERROR, "big_values too big\VAR_9");

                return AVERROR_INVALIDDATA;

            }



            g->global_gain = get_bits(&VAR_0->gb, 8);

            



            if ((VAR_0->mode_ext & (MODE_EXT_MS_STEREO | MODE_EXT_I_STEREO)) ==

                MODE_EXT_MS_STEREO)

                g->global_gain -= 2;

            if (VAR_0->lsf)

                g->scalefac_compress = get_bits(&VAR_0->gb, 9);

            else

                g->scalefac_compress = get_bits(&VAR_0->gb, 4);

            VAR_5 = get_bits1(&VAR_0->gb);

            if (VAR_5) {

                g->block_type = get_bits(&VAR_0->gb, 2);

                if (g->block_type == 0) {

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "invalid block type\VAR_9");

                    return AVERROR_INVALIDDATA;

                }

                g->switch_point = get_bits1(&VAR_0->gb);

                for (VAR_6 = 0; VAR_6 < 2; VAR_6++)

                    g->table_select[VAR_6] = get_bits(&VAR_0->gb, 5);

                for (VAR_6 = 0; VAR_6 < 3; VAR_6++)

                    g->subblock_gain[VAR_6] = get_bits(&VAR_0->gb, 3);

                ff_init_short_region(VAR_0, g);

            } else {

                int region_address1, region_address2;

                g->block_type = 0;

                g->switch_point = 0;

                for (VAR_6 = 0; VAR_6 < 3; VAR_6++)

                    g->table_select[VAR_6] = get_bits(&VAR_0->gb, 5);

                

                region_address1 = get_bits(&VAR_0->gb, 4);

                region_address2 = get_bits(&VAR_0->gb, 3);

                av_dlog(VAR_0->avctx, "region1=%d region2=%d\VAR_9",

                        region_address1, region_address2);

                ff_init_long_region(VAR_0, g, region_address1, region_address2);

            }

            ff_region_offset2size(g);

            ff_compute_band_indexes(VAR_0, g);



            g->preflag = 0;

            if (!VAR_0->lsf)

                g->preflag = get_bits1(&VAR_0->gb);

            g->scalefac_scale     = get_bits1(&VAR_0->gb);

            g->count1table_select = get_bits1(&VAR_0->gb);

            av_dlog(VAR_0->avctx, "block_type=%d switch_point=%d\VAR_9",

                    g->block_type, g->switch_point);

        }

    }



    if (!VAR_0->adu_mode) {

        const uint8_t *VAR_11 = VAR_0->gb.buffer + (get_bits_count(&VAR_0->gb)>>3);

        assert((get_bits_count(&VAR_0->gb) & 7) == 0);

        

        av_dlog(VAR_0->avctx, "seekback: %d\VAR_9", VAR_2);

    



        memcpy(VAR_0->last_buf + VAR_0->last_buf_size, VAR_11, EXTRABYTES);

        VAR_0->in_gb = VAR_0->gb;

        init_get_bits(&VAR_0->gb, VAR_0->last_buf, VAR_0->last_buf_size*8);

#if !UNCHECKED_BITSTREAM_READER

        VAR_0->gb.size_in_bits_plus8 += EXTRABYTES * 8;

#endif

        VAR_0->last_buf_size <<= 3;

        for (VAR_3 = 0, VAR_4 = 0; VAR_3 < VAR_1 && (VAR_0->last_buf_size >> 3) < VAR_2; VAR_3++, VAR_4 = 0) {

            for (; VAR_4 < VAR_0->nb_channels && (VAR_0->last_buf_size >> 3) < VAR_2; VAR_4++) {

                g = &VAR_0->granules[VAR_4][VAR_3];

                VAR_0->last_buf_size += g->part2_3_length;

                memset(g->sb_hybrid, 0, sizeof(g->sb_hybrid));

            }

        }

        skip_bits_long(&VAR_0->gb, VAR_0->last_buf_size - 8 * VAR_2);

        if (get_bits_count(&VAR_0->gb) >= VAR_0->gb.size_in_bits && VAR_0->in_gb.buffer) {

            skip_bits_long(&VAR_0->in_gb, get_bits_count(&VAR_0->gb) - VAR_0->gb.size_in_bits);

            VAR_0->gb           = VAR_0->in_gb;

            VAR_0->in_gb.buffer = NULL;

        }

    } else {

        VAR_3 = VAR_4 = 0;

    }



    for (; VAR_3 < VAR_1; VAR_3++, VAR_4 = 0) {

        for (; VAR_4 < VAR_0->nb_channels; VAR_4++) {

            g = &VAR_0->granules[VAR_4][VAR_3];

            VAR_10 = get_bits_count(&VAR_0->gb);



            if (!VAR_0->lsf) {

                uint8_t *sc;

                int slen, slen1, slen2;



                

                slen1 = slen_table[0][g->scalefac_compress];

                slen2 = slen_table[1][g->scalefac_compress];

                av_dlog(VAR_0->avctx, "slen1=%d slen2=%d\VAR_9", slen1, slen2);

                if (g->block_type == 2) {

                    VAR_9 = g->switch_point ? 17 : 18;

                    VAR_7 = 0;

                    if (slen1) {

                        for (VAR_6 = 0; VAR_6 < VAR_9; VAR_6++)

                            g->scale_factors[VAR_7++] = get_bits(&VAR_0->gb, slen1);

                    } else {

                        for (VAR_6 = 0; VAR_6 < VAR_9; VAR_6++)

                            g->scale_factors[VAR_7++] = 0;

                    }

                    if (slen2) {

                        for (VAR_6 = 0; VAR_6 < 18; VAR_6++)

                            g->scale_factors[VAR_7++] = get_bits(&VAR_0->gb, slen2);

                        for (VAR_6 = 0; VAR_6 < 3; VAR_6++)

                            g->scale_factors[VAR_7++] = 0;

                    } else {

                        for (VAR_6 = 0; VAR_6 < 21; VAR_6++)

                            g->scale_factors[VAR_7++] = 0;

                    }

                } else {

                    sc = VAR_0->granules[VAR_4][0].scale_factors;

                    VAR_7 = 0;

                    for (VAR_8 = 0; VAR_8 < 4; VAR_8++) {

                        VAR_9 = VAR_8 == 0 ? 6 : 5;

                        if ((g->scfsi & (0x8 >> VAR_8)) == 0) {

                            slen = (VAR_8 < 2) ? slen1 : slen2;

                            if (slen) {

                                for (VAR_6 = 0; VAR_6 < VAR_9; VAR_6++)

                                    g->scale_factors[VAR_7++] = get_bits(&VAR_0->gb, slen);

                            } else {

                                for (VAR_6 = 0; VAR_6 < VAR_9; VAR_6++)

                                    g->scale_factors[VAR_7++] = 0;

                            }

                        } else {

                            

                            for (VAR_6 = 0; VAR_6 < VAR_9; VAR_6++) {

                                g->scale_factors[VAR_7] = sc[VAR_7];

                                VAR_7++;

                            }

                        }

                    }

                    g->scale_factors[VAR_7++] = 0;

                }

            } else {

                int tindex, tindex2, slen[4], sl, sf;



                

                if (g->block_type == 2)

                    tindex = g->switch_point ? 2 : 1;

                else

                    tindex = 0;



                sf = g->scalefac_compress;

                if ((VAR_0->mode_ext & MODE_EXT_I_STEREO) && VAR_4 == 1) {

                    

                    sf >>= 1;

                    if (sf < 180) {

                        lsf_sf_expand(slen, sf, 6, 6, 0);

                        tindex2 = 3;

                    } else if (sf < 244) {

                        lsf_sf_expand(slen, sf - 180, 4, 4, 0);

                        tindex2 = 4;

                    } else {

                        lsf_sf_expand(slen, sf - 244, 3, 0, 0);

                        tindex2 = 5;

                    }

                } else {

                    

                    if (sf < 400) {

                        lsf_sf_expand(slen, sf, 5, 4, 4);

                        tindex2 = 0;

                    } else if (sf < 500) {

                        lsf_sf_expand(slen, sf - 400, 5, 4, 0);

                        tindex2 = 1;

                    } else {

                        lsf_sf_expand(slen, sf - 500, 3, 0, 0);

                        tindex2 = 2;

                        g->preflag = 1;

                    }

                }



                VAR_7 = 0;

                for (VAR_8 = 0; VAR_8 < 4; VAR_8++) {

                    VAR_9  = lsf_nsf_table[tindex2][tindex][VAR_8];

                    sl = slen[VAR_8];

                    if (sl) {

                        for (VAR_6 = 0; VAR_6 < VAR_9; VAR_6++)

                            g->scale_factors[VAR_7++] = get_bits(&VAR_0->gb, sl);

                    } else {

                        for (VAR_6 = 0; VAR_6 < VAR_9; VAR_6++)

                            g->scale_factors[VAR_7++] = 0;

                    }

                }

                

                for (; VAR_7 < 40; VAR_7++)

                    g->scale_factors[VAR_7] = 0;

            }



            exponents_from_scale_factors(VAR_0, g, exponents);



            

            huffman_decode(VAR_0, g, exponents, VAR_10 + g->part2_3_length);

        } 



        if (VAR_0->nb_channels == 2)

            compute_stereo(VAR_0, &VAR_0->granules[0][VAR_3], &VAR_0->granules[1][VAR_3]);



        for (VAR_4 = 0; VAR_4 < VAR_0->nb_channels; VAR_4++) {

            g = &VAR_0->granules[VAR_4][VAR_3];



            reorder_block(VAR_0, g);

            compute_antialias(VAR_0, g);

            compute_imdct(VAR_0, g, &VAR_0->sb_samples[VAR_4][18 * VAR_3][0], VAR_0->mdct_buf[VAR_4]);

        }

    } 

    if (get_bits_count(&VAR_0->gb) < 0)

        skip_bits_long(&VAR_0->gb, -get_bits_count(&VAR_0->gb));

    return VAR_1 * 18;

}

static int FUNC_0(MPADecodeContext *VAR_0)
{ int VAR_1, VAR_2; int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10; GranuleDef *g; int16_t exponents[576]; if (VAR_0->lsf) { VAR_2 = get_bits(&VAR_0->gb, 8); skip_bits(&VAR_0->gb, VAR_0->nb_channels); VAR_1 = 1; } else { VAR_2 = get_bits(&VAR_0->gb, 9); if (VAR_0->nb_channels == 2)
skip_bits(&VAR_0->gb, 3); else
skip_bits(&VAR_0->gb, 5); VAR_1 = 2; for (VAR_4 = 0; VAR_4 < VAR_0->nb_channels; VAR_4++) { VAR_0->granules[VAR_4][0].scfsi = 0; VAR_0->granules[VAR_4][1].scfsi = get_bits(&VAR_0->gb, 4); } } for (VAR_3 = 0; VAR_3 < VAR_1; VAR_3++) { for (VAR_4 = 0; VAR_4 < VAR_0->nb_channels; VAR_4++) { av_dlog(VAR_0->avctx, "VAR_3=%d VAR_4=%d: side_info\VAR_9", VAR_3, VAR_4); g = &VAR_0->granules[VAR_4][VAR_3]; g->part2_3_length = get_bits(&VAR_0->gb, 12); g->big_values     = get_bits(&VAR_0->gb,  9); if (g->big_values > 288) { av_log(VAR_0->avctx, AV_LOG_ERROR, "big_values too big\VAR_9"); return AVERROR_INVALIDDATA; } g->global_gain = get_bits(&VAR_0->gb, 8); if ((VAR_0->mode_ext & (MODE_EXT_MS_STEREO | MODE_EXT_I_STEREO)) ==
MODE_EXT_MS_STEREO)
g->global_gain -= 2; if (VAR_0->lsf)
g->scalefac_compress = get_bits(&VAR_0->gb, 9); else
g->scalefac_compress = get_bits(&VAR_0->gb, 4); VAR_5 = get_bits1(&VAR_0->gb); if (VAR_5) { g->block_type = get_bits(&VAR_0->gb, 2); if (g->block_type == 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "invalid block type\VAR_9"); return AVERROR_INVALIDDATA; } g->switch_point = get_bits1(&VAR_0->gb); for (VAR_6 = 0; VAR_6 < 2; VAR_6++) g->table_select[VAR_6] = get_bits(&VAR_0->gb, 5); for (VAR_6 = 0; VAR_6 < 3; VAR_6++) g->subblock_gain[VAR_6] = get_bits(&VAR_0->gb, 3); ff_init_short_region(VAR_0, g); } else { int region_address1, region_address2; g->block_type = 0; g->switch_point = 0; for (VAR_6 = 0; VAR_6 < 3; VAR_6++) g->table_select[VAR_6] = get_bits(&VAR_0->gb, 5); region_address1 = get_bits(&VAR_0->gb, 4); region_address2 = get_bits(&VAR_0->gb, 3); av_dlog(VAR_0->avctx, "region1=%d region2=%d\VAR_9",
region_address1, region_address2); ff_init_long_region(VAR_0, g, region_address1, region_address2); } ff_region_offset2size(g); ff_compute_band_indexes(VAR_0, g); g->preflag = 0; if (!VAR_0->lsf)
g->preflag = get_bits1(&VAR_0->gb); g->scalefac_scale     = get_bits1(&VAR_0->gb); g->count1table_select = get_bits1(&VAR_0->gb); av_dlog(VAR_0->avctx, "block_type=%d switch_point=%d\VAR_9",
g->block_type, g->switch_point); } } if (!VAR_0->adu_mode) { const uint8_t *VAR_11 = VAR_0->gb.buffer + (get_bits_count(&VAR_0->gb)>>3); assert((get_bits_count(&VAR_0->gb) & 7) == 0); av_dlog(VAR_0->avctx, "seekback: %d\VAR_9", VAR_2); memcpy(VAR_0->last_buf + VAR_0->last_buf_size, VAR_11, EXTRABYTES); VAR_0->in_gb = VAR_0->gb; init_get_bits(&VAR_0->gb, VAR_0->last_buf, VAR_0->last_buf_size*8); #if !UNCHECKED_BITSTREAM_READER
VAR_0->gb.size_in_bits_plus8 += EXTRABYTES * 8; #endif
VAR_0->last_buf_size <<= 3; for (VAR_3 = 0, VAR_4 = 0; VAR_3 < VAR_1 && (VAR_0->last_buf_size >> 3) < VAR_2; VAR_3++, VAR_4 = 0) { for (; VAR_4 < VAR_0->nb_channels && (VAR_0->last_buf_size >> 3) < VAR_2; VAR_4++) { g = &VAR_0->granules[VAR_4][VAR_3]; VAR_0->last_buf_size += g->part2_3_length; memset(g->sb_hybrid, 0, sizeof(g->sb_hybrid)); } } skip_bits_long(&VAR_0->gb, VAR_0->last_buf_size - 8 * VAR_2); if (get_bits_count(&VAR_0->gb) >= VAR_0->gb.size_in_bits && VAR_0->in_gb.buffer) { skip_bits_long(&VAR_0->in_gb, get_bits_count(&VAR_0->gb) - VAR_0->gb.size_in_bits); VAR_0->gb           = VAR_0->in_gb; VAR_0->in_gb.buffer = NULL; } } else { VAR_3 = VAR_4 = 0; } for (; VAR_3 < VAR_1; VAR_3++, VAR_4 = 0) { for (; VAR_4 < VAR_0->nb_channels; VAR_4++) { g = &VAR_0->granules[VAR_4][VAR_3]; VAR_10 = get_bits_count(&VAR_0->gb); if (!VAR_0->lsf) { uint8_t *sc; int slen, slen1, slen2; slen1 = slen_table[0][g->scalefac_compress]; slen2 = slen_table[1][g->scalefac_compress]; av_dlog(VAR_0->avctx, "slen1=%d slen2=%d\VAR_9", slen1, slen2); if (g->block_type == 2) { VAR_9 = g->switch_point ? 17 : 18; VAR_7 = 0; if (slen1) { for (VAR_6 = 0; VAR_6 < VAR_9; VAR_6++) g->scale_factors[VAR_7++] = get_bits(&VAR_0->gb, slen1); } else { for (VAR_6 = 0; VAR_6 < VAR_9; VAR_6++) g->scale_factors[VAR_7++] = 0; } if (slen2) { for (VAR_6 = 0; VAR_6 < 18; VAR_6++) g->scale_factors[VAR_7++] = get_bits(&VAR_0->gb, slen2); for (VAR_6 = 0; VAR_6 < 3; VAR_6++) g->scale_factors[VAR_7++] = 0; } else { for (VAR_6 = 0; VAR_6 < 21; VAR_6++) g->scale_factors[VAR_7++] = 0; } } else { sc = VAR_0->granules[VAR_4][0].scale_factors; VAR_7 = 0; for (VAR_8 = 0; VAR_8 < 4; VAR_8++) { VAR_9 = VAR_8 == 0 ? 6 : 5; if ((g->scfsi & (0x8 >> VAR_8)) == 0) { slen = (VAR_8 < 2) ? slen1 : slen2; if (slen) { for (VAR_6 = 0; VAR_6 < VAR_9; VAR_6++) g->scale_factors[VAR_7++] = get_bits(&VAR_0->gb, slen); } else { for (VAR_6 = 0; VAR_6 < VAR_9; VAR_6++) g->scale_factors[VAR_7++] = 0; } } else { for (VAR_6 = 0; VAR_6 < VAR_9; VAR_6++) { g->scale_factors[VAR_7] = sc[VAR_7]; VAR_7++; } } } g->scale_factors[VAR_7++] = 0; } } else { int tindex, tindex2, slen[4], sl, sf; if (g->block_type == 2)
tindex = g->switch_point ? 2 : 1; else
tindex = 0; sf = g->scalefac_compress; if ((VAR_0->mode_ext & MODE_EXT_I_STEREO) && VAR_4 == 1) { sf >>= 1; if (sf < 180) { lsf_sf_expand(slen, sf, 6, 6, 0); tindex2 = 3; } else if (sf < 244) { lsf_sf_expand(slen, sf - 180, 4, 4, 0); tindex2 = 4; } else { lsf_sf_expand(slen, sf - 244, 3, 0, 0); tindex2 = 5; } } else { if (sf < 400) { lsf_sf_expand(slen, sf, 5, 4, 4); tindex2 = 0; } else if (sf < 500) { lsf_sf_expand(slen, sf - 400, 5, 4, 0); tindex2 = 1; } else { lsf_sf_expand(slen, sf - 500, 3, 0, 0); tindex2 = 2; g->preflag = 1; } } VAR_7 = 0; for (VAR_8 = 0; VAR_8 < 4; VAR_8++) { VAR_9  = lsf_nsf_table[tindex2][tindex][VAR_8]; sl = slen[VAR_8]; if (sl) { for (VAR_6 = 0; VAR_6 < VAR_9; VAR_6++) g->scale_factors[VAR_7++] = get_bits(&VAR_0->gb, sl); } else { for (VAR_6 = 0; VAR_6 < VAR_9; VAR_6++) g->scale_factors[VAR_7++] = 0; } } for (; VAR_7 < 40; VAR_7++) g->scale_factors[VAR_7] = 0; } exponents_from_scale_factors(VAR_0, g, exponents); huffman_decode(VAR_0, g, exponents, VAR_10 + g->part2_3_length); } if (VAR_0->nb_channels == 2)
compute_stereo(VAR_0, &VAR_0->granules[0][VAR_3], &VAR_0->granules[1][VAR_3]); for (VAR_4 = 0; VAR_4 < VAR_0->nb_channels; VAR_4++) { g = &VAR_0->granules[VAR_4][VAR_3]; reorder_block(VAR_0, g); compute_antialias(VAR_0, g); compute_imdct(VAR_0, g, &VAR_0->sb_samples[VAR_4][18 * VAR_3][0], VAR_0->mdct_buf[VAR_4]); } } if (get_bits_count(&VAR_0->gb) < 0)
skip_bits_long(&VAR_0->gb, -get_bits_count(&VAR_0->gb)); return VAR_1 * 18; }