void ff_celt_quant_bands(CeltFrame *f, OpusRangeCoder *rc)

{

    float lowband_scratch[8 * 22];

    float norm1[2 * 8 * 100];

    float *norm2 = norm1 + 8 * 100;



    int totalbits = (f->framebits << 3) - f->anticollapse_needed;



    int update_lowband = 1;

    int lowband_offset = 0;



    int i, j;



    for (i = f->start_band; i < f->end_band; i++) {

        uint32_t cm[2] = { (1 << f->blocks) - 1, (1 << f->blocks) - 1 };

        int band_offset = ff_celt_freq_bands[i] << f->size;

        int band_size   = ff_celt_freq_range[i] << f->size;

        float *X = f->block[0].coeffs + band_offset;

        float *Y = (f->channels == 2) ? f->block[1].coeffs + band_offset : NULL;

        float *norm_loc1, *norm_loc2;



        int consumed = opus_rc_tell_frac(rc);

        int effective_lowband = -1;

        int b = 0;



        /* Compute how many bits we want to allocate to this band */

        if (i != f->start_band)

            f->remaining -= consumed;

        f->remaining2 = totalbits - consumed - 1;

        if (i <= f->coded_bands - 1) {

            int curr_balance = f->remaining / FFMIN(3, f->coded_bands-i);

            b = av_clip_uintp2(FFMIN(f->remaining2 + 1, f->pulses[i] + curr_balance), 14);

        }



        if ((ff_celt_freq_bands[i] - ff_celt_freq_range[i] >= ff_celt_freq_bands[f->start_band] ||

            i == f->start_band + 1) && (update_lowband || lowband_offset == 0))

            lowband_offset = i;



        if (i == f->start_band + 1) {

            /* Special Hybrid Folding (RFC 8251 section 9). Copy the first band into

            the second to ensure the second band never has to use the LCG. */

            int offset = 8 * ff_celt_freq_bands[i];

            int count = 8 * (ff_celt_freq_range[i] - ff_celt_freq_range[i-1]);



            memcpy(&norm1[offset], &norm1[offset - count], count * sizeof(float));



            if (f->channels == 2)

                memcpy(&norm2[offset], &norm2[offset - count], count * sizeof(float));

        }



        /* Get a conservative estimate of the collapse_mask's for the bands we're

           going to be folding from. */

        if (lowband_offset != 0 && (f->spread != CELT_SPREAD_AGGRESSIVE ||

                                    f->blocks > 1 || f->tf_change[i] < 0)) {

            int foldstart, foldend;



            /* This ensures we never repeat spectral content within one band */

            effective_lowband = FFMAX(ff_celt_freq_bands[f->start_band],

                                      ff_celt_freq_bands[lowband_offset] - ff_celt_freq_range[i]);

            foldstart = lowband_offset;

            while (ff_celt_freq_bands[--foldstart] > effective_lowband);

            foldend = lowband_offset - 1;

            while (++foldend < i && ff_celt_freq_bands[foldend] < effective_lowband + ff_celt_freq_range[i]);



            cm[0] = cm[1] = 0;

            for (j = foldstart; j < foldend; j++) {

                cm[0] |= f->block[0].collapse_masks[j];

                cm[1] |= f->block[f->channels - 1].collapse_masks[j];

            }

        }



        if (f->dual_stereo && i == f->intensity_stereo) {

            /* Switch off dual stereo to do intensity */

            f->dual_stereo = 0;

            for (j = ff_celt_freq_bands[f->start_band] << f->size; j < band_offset; j++)

                norm1[j] = (norm1[j] + norm2[j]) / 2;

        }



        norm_loc1 = effective_lowband != -1 ? norm1 + (effective_lowband << f->size) : NULL;

        norm_loc2 = effective_lowband != -1 ? norm2 + (effective_lowband << f->size) : NULL;



        if (f->dual_stereo) {

            cm[0] = f->pvq->quant_band(f->pvq, f, rc, i, X, NULL, band_size, b >> 1,

                                       f->blocks, norm_loc1, f->size,

                                       norm1 + band_offset, 0, 1.0f,

                                       lowband_scratch, cm[0]);



            cm[1] = f->pvq->quant_band(f->pvq, f, rc, i, Y, NULL, band_size, b >> 1,

                                       f->blocks, norm_loc2, f->size,

                                       norm2 + band_offset, 0, 1.0f,

                                       lowband_scratch, cm[1]);

        } else {

            cm[0] = f->pvq->quant_band(f->pvq, f, rc, i, X,    Y, band_size, b >> 0,

                                       f->blocks, norm_loc1, f->size,

                                       norm1 + band_offset, 0, 1.0f,

                                       lowband_scratch, cm[0] | cm[1]);

            cm[1] = cm[0];

        }



        f->block[0].collapse_masks[i]               = (uint8_t)cm[0];

        f->block[f->channels - 1].collapse_masks[i] = (uint8_t)cm[1];

        f->remaining += f->pulses[i] + consumed;



        /* Update the folding position only as long as we have 1 bit/sample depth */

        update_lowband = (b > band_size << 3);

    }

}

void ff_celt_quant_bands(CeltFrame *f, OpusRangeCoder *rc)

{

    float lowband_scratch[8 * 22];

    float norm1[2 * 8 * 100];

    float *norm2 = norm1 + 8 * 100;



    int totalbits = (f->framebits << 3) - f->anticollapse_needed;



    int update_lowband = 1;

    int lowband_offset = 0;



    int i, j;



    for (i = f->start_band; i < f->end_band; i++) {

        uint32_t cm[2] = { (1 << f->blocks) - 1, (1 << f->blocks) - 1 };

        int band_offset = ff_celt_freq_bands[i] << f->size;

        int band_size   = ff_celt_freq_range[i] << f->size;

        float *X = f->block[0].coeffs + band_offset;

        float *Y = (f->channels == 2) ? f->block[1].coeffs + band_offset : NULL;

        float *norm_loc1, *norm_loc2;



        int consumed = opus_rc_tell_frac(rc);

        int effective_lowband = -1;

        int b = 0;



        

        if (i != f->start_band)

            f->remaining -= consumed;

        f->remaining2 = totalbits - consumed - 1;

        if (i <= f->coded_bands - 1) {

            int curr_balance = f->remaining / FFMIN(3, f->coded_bands-i);

            b = av_clip_uintp2(FFMIN(f->remaining2 + 1, f->pulses[i] + curr_balance), 14);

        }



        if ((ff_celt_freq_bands[i] - ff_celt_freq_range[i] >= ff_celt_freq_bands[f->start_band] ||

            i == f->start_band + 1) && (update_lowband || lowband_offset == 0))

            lowband_offset = i;



        if (i == f->start_band + 1) {

            



            int offset = 8 * ff_celt_freq_bands[i];

            int count = 8 * (ff_celt_freq_range[i] - ff_celt_freq_range[i-1]);



            memcpy(&norm1[offset], &norm1[offset - count], count * sizeof(float));



            if (f->channels == 2)

                memcpy(&norm2[offset], &norm2[offset - count], count * sizeof(float));

        }



        



        if (lowband_offset != 0 && (f->spread != CELT_SPREAD_AGGRESSIVE ||

                                    f->blocks > 1 || f->tf_change[i] < 0)) {

            int foldstart, foldend;



            

            effective_lowband = FFMAX(ff_celt_freq_bands[f->start_band],

                                      ff_celt_freq_bands[lowband_offset] - ff_celt_freq_range[i]);

            foldstart = lowband_offset;

            while (ff_celt_freq_bands[--foldstart] > effective_lowband);

            foldend = lowband_offset - 1;

            while (++foldend < i && ff_celt_freq_bands[foldend] < effective_lowband + ff_celt_freq_range[i]);



            cm[0] = cm[1] = 0;

            for (j = foldstart; j < foldend; j++) {

                cm[0] |= f->block[0].collapse_masks[j];

                cm[1] |= f->block[f->channels - 1].collapse_masks[j];

            }

        }



        if (f->dual_stereo && i == f->intensity_stereo) {

            

            f->dual_stereo = 0;

            for (j = ff_celt_freq_bands[f->start_band] << f->size; j < band_offset; j++)

                norm1[j] = (norm1[j] + norm2[j]) / 2;

        }



        norm_loc1 = effective_lowband != -1 ? norm1 + (effective_lowband << f->size) : NULL;

        norm_loc2 = effective_lowband != -1 ? norm2 + (effective_lowband << f->size) : NULL;



        if (f->dual_stereo) {

            cm[0] = f->pvq->quant_band(f->pvq, f, rc, i, X, NULL, band_size, b >> 1,

                                       f->blocks, norm_loc1, f->size,

                                       norm1 + band_offset, 0, 1.0f,

                                       lowband_scratch, cm[0]);



            cm[1] = f->pvq->quant_band(f->pvq, f, rc, i, Y, NULL, band_size, b >> 1,

                                       f->blocks, norm_loc2, f->size,

                                       norm2 + band_offset, 0, 1.0f,

                                       lowband_scratch, cm[1]);

        } else {

            cm[0] = f->pvq->quant_band(f->pvq, f, rc, i, X,    Y, band_size, b >> 0,

                                       f->blocks, norm_loc1, f->size,

                                       norm1 + band_offset, 0, 1.0f,

                                       lowband_scratch, cm[0] | cm[1]);

            cm[1] = cm[0];

        }



        f->block[0].collapse_masks[i]               = (uint8_t)cm[0];

        f->block[f->channels - 1].collapse_masks[i] = (uint8_t)cm[1];

        f->remaining += f->pulses[i] + consumed;



        

        update_lowband = (b > band_size << 3);

    }

}

            int offset = 8 * ff_celt_freq_bands[i];             int count = 8 * (ff_celt_freq_range[i] - ff_celt_freq_range[i-1]);             memcpy(&norm1[offset], &norm1[offset - count], count * sizeof(float));                 memcpy(&norm2[offset], &norm2[offset - count], count * sizeof(float));
void FUNC_0(CeltFrame *VAR_0, OpusRangeCoder *VAR_1)

{

    float VAR_2[8 * 22];

    float VAR_3[2 * 8 * 100];

    float *VAR_4 = VAR_3 + 8 * 100;



    int VAR_5 = (VAR_0->framebits << 3) - VAR_0->anticollapse_needed;



    int VAR_6 = 1;

    int VAR_7 = 0;



    int VAR_8, VAR_9;



    for (VAR_8 = VAR_0->start_band; VAR_8 < VAR_0->end_band; VAR_8++) {

        uint32_t cm[2] = { (1 << VAR_0->blocks) - 1, (1 << VAR_0->blocks) - 1 };

        int band_offset = ff_celt_freq_bands[VAR_8] << VAR_0->size;

        int band_size   = ff_celt_freq_range[VAR_8] << VAR_0->size;

        float *X = VAR_0->block[0].coeffs + band_offset;

        float *Y = (VAR_0->channels == 2) ? VAR_0->block[1].coeffs + band_offset : NULL;

        float *norm_loc1, *norm_loc2;



        int consumed = opus_rc_tell_frac(VAR_1);

        int effective_lowband = -1;

        int b = 0;



        

        if (VAR_8 != VAR_0->start_band)

            VAR_0->remaining -= consumed;

        VAR_0->remaining2 = VAR_5 - consumed - 1;

        if (VAR_8 <= VAR_0->coded_bands - 1) {

            int curr_balance = VAR_0->remaining / FFMIN(3, VAR_0->coded_bands-VAR_8);

            b = av_clip_uintp2(FFMIN(VAR_0->remaining2 + 1, VAR_0->pulses[VAR_8] + curr_balance), 14);

        }



        if ((ff_celt_freq_bands[VAR_8] - ff_celt_freq_range[VAR_8] >= ff_celt_freq_bands[VAR_0->start_band] ||

            VAR_8 == VAR_0->start_band + 1) && (VAR_6 || VAR_7 == 0))

            VAR_7 = VAR_8;



        if (VAR_8 == VAR_0->start_band + 1) {

            



            int offset = 8 * ff_celt_freq_bands[VAR_8];

            int count = 8 * (ff_celt_freq_range[VAR_8] - ff_celt_freq_range[VAR_8-1]);



            memcpy(&VAR_3[offset], &VAR_3[offset - count], count * sizeof(float));



            if (VAR_0->channels == 2)

                memcpy(&VAR_4[offset], &VAR_4[offset - count], count * sizeof(float));

        }



        



        if (VAR_7 != 0 && (VAR_0->spread != CELT_SPREAD_AGGRESSIVE ||

                                    VAR_0->blocks > 1 || VAR_0->tf_change[VAR_8] < 0)) {

            int foldstart, foldend;



            

            effective_lowband = FFMAX(ff_celt_freq_bands[VAR_0->start_band],

                                      ff_celt_freq_bands[VAR_7] - ff_celt_freq_range[VAR_8]);

            foldstart = VAR_7;

            while (ff_celt_freq_bands[--foldstart] > effective_lowband);

            foldend = VAR_7 - 1;

            while (++foldend < VAR_8 && ff_celt_freq_bands[foldend] < effective_lowband + ff_celt_freq_range[VAR_8]);



            cm[0] = cm[1] = 0;

            for (VAR_9 = foldstart; VAR_9 < foldend; VAR_9++) {

                cm[0] |= VAR_0->block[0].collapse_masks[VAR_9];

                cm[1] |= VAR_0->block[VAR_0->channels - 1].collapse_masks[VAR_9];

            }

        }



        if (VAR_0->dual_stereo && VAR_8 == VAR_0->intensity_stereo) {

            

            VAR_0->dual_stereo = 0;

            for (VAR_9 = ff_celt_freq_bands[VAR_0->start_band] << VAR_0->size; VAR_9 < band_offset; VAR_9++)

                VAR_3[VAR_9] = (VAR_3[VAR_9] + VAR_4[VAR_9]) / 2;

        }



        norm_loc1 = effective_lowband != -1 ? VAR_3 + (effective_lowband << VAR_0->size) : NULL;

        norm_loc2 = effective_lowband != -1 ? VAR_4 + (effective_lowband << VAR_0->size) : NULL;



        if (VAR_0->dual_stereo) {

            cm[0] = VAR_0->pvq->quant_band(VAR_0->pvq, VAR_0, VAR_1, VAR_8, X, NULL, band_size, b >> 1,

                                       VAR_0->blocks, norm_loc1, VAR_0->size,

                                       VAR_3 + band_offset, 0, 1.0f,

                                       VAR_2, cm[0]);



            cm[1] = VAR_0->pvq->quant_band(VAR_0->pvq, VAR_0, VAR_1, VAR_8, Y, NULL, band_size, b >> 1,

                                       VAR_0->blocks, norm_loc2, VAR_0->size,

                                       VAR_4 + band_offset, 0, 1.0f,

                                       VAR_2, cm[1]);

        } else {

            cm[0] = VAR_0->pvq->quant_band(VAR_0->pvq, VAR_0, VAR_1, VAR_8, X,    Y, band_size, b >> 0,

                                       VAR_0->blocks, norm_loc1, VAR_0->size,

                                       VAR_3 + band_offset, 0, 1.0f,

                                       VAR_2, cm[0] | cm[1]);

            cm[1] = cm[0];

        }



        VAR_0->block[0].collapse_masks[VAR_8]               = (uint8_t)cm[0];

        VAR_0->block[VAR_0->channels - 1].collapse_masks[VAR_8] = (uint8_t)cm[1];

        VAR_0->remaining += VAR_0->pulses[VAR_8] + consumed;



        

        VAR_6 = (b > band_size << 3);

    }

}

void FUNC_0(CeltFrame *VAR_0, OpusRangeCoder *VAR_1)
{ float VAR_2[8 * 22]; float VAR_3[2 * 8 * 100]; float *VAR_4 = VAR_3 + 8 * 100; int VAR_5 = (VAR_0->framebits << 3) - VAR_0->anticollapse_needed; int VAR_6 = 1; int VAR_7 = 0; int VAR_8, VAR_9; for (VAR_8 = VAR_0->start_band; VAR_8 < VAR_0->end_band; VAR_8++) { uint32_t cm[2] = { (1 << VAR_0->blocks) - 1, (1 << VAR_0->blocks) - 1 }; int band_offset = ff_celt_freq_bands[VAR_8] << VAR_0->size; int band_size   = ff_celt_freq_range[VAR_8] << VAR_0->size; float *X = VAR_0->block[0].coeffs + band_offset; float *Y = (VAR_0->channels == 2) ? VAR_0->block[1].coeffs + band_offset : NULL; float *norm_loc1, *norm_loc2; int consumed = opus_rc_tell_frac(VAR_1); int effective_lowband = -1; int b = 0; if (VAR_8 != VAR_0->start_band)
VAR_0->remaining -= consumed; VAR_0->remaining2 = VAR_5 - consumed - 1; if (VAR_8 <= VAR_0->coded_bands - 1) { int curr_balance = VAR_0->remaining / FFMIN(3, VAR_0->coded_bands-VAR_8); b = av_clip_uintp2(FFMIN(VAR_0->remaining2 + 1, VAR_0->pulses[VAR_8] + curr_balance), 14); } if ((ff_celt_freq_bands[VAR_8] - ff_celt_freq_range[VAR_8] >= ff_celt_freq_bands[VAR_0->start_band] ||
VAR_8 == VAR_0->start_band + 1) && (VAR_6 || VAR_7 == 0))
VAR_7 = VAR_8; if (VAR_8 == VAR_0->start_band + 1) { int offset = 8 * ff_celt_freq_bands[VAR_8]; int count = 8 * (ff_celt_freq_range[VAR_8] - ff_celt_freq_range[VAR_8-1]); memcpy(&VAR_3[offset], &VAR_3[offset - count], count * sizeof(float)); if (VAR_0->channels == 2)
memcpy(&VAR_4[offset], &VAR_4[offset - count], count * sizeof(float)); } if (VAR_7 != 0 && (VAR_0->spread != CELT_SPREAD_AGGRESSIVE ||
VAR_0->blocks > 1 || VAR_0->tf_change[VAR_8] < 0)) { int foldstart, foldend; effective_lowband = FFMAX(ff_celt_freq_bands[VAR_0->start_band],
ff_celt_freq_bands[VAR_7] - ff_celt_freq_range[VAR_8]); foldstart = VAR_7; while (ff_celt_freq_bands[--foldstart] > effective_lowband); foldend = VAR_7 - 1; while (++foldend < VAR_8 && ff_celt_freq_bands[foldend] < effective_lowband + ff_celt_freq_range[VAR_8]); cm[0] = cm[1] = 0; for (VAR_9 = foldstart; VAR_9 < foldend; VAR_9++) { cm[0] |= VAR_0->block[0].collapse_masks[VAR_9]; cm[1] |= VAR_0->block[VAR_0->channels - 1].collapse_masks[VAR_9]; } } if (VAR_0->dual_stereo && VAR_8 == VAR_0->intensity_stereo) { VAR_0->dual_stereo = 0; for (VAR_9 = ff_celt_freq_bands[VAR_0->start_band] << VAR_0->size; VAR_9 < band_offset; VAR_9++) VAR_3[VAR_9] = (VAR_3[VAR_9] + VAR_4[VAR_9]) / 2; } norm_loc1 = effective_lowband != -1 ? VAR_3 + (effective_lowband << VAR_0->size) : NULL; norm_loc2 = effective_lowband != -1 ? VAR_4 + (effective_lowband << VAR_0->size) : NULL; if (VAR_0->dual_stereo) { cm[0] = VAR_0->pvq->quant_band(VAR_0->pvq, VAR_0, VAR_1, VAR_8, X, NULL, band_size, b >> 1,
VAR_0->blocks, norm_loc1, VAR_0->size,
VAR_3 + band_offset, 0, 1.0f,
VAR_2, cm[0]); cm[1] = VAR_0->pvq->quant_band(VAR_0->pvq, VAR_0, VAR_1, VAR_8, Y, NULL, band_size, b >> 1,
VAR_0->blocks, norm_loc2, VAR_0->size,
VAR_4 + band_offset, 0, 1.0f,
VAR_2, cm[1]); } else { cm[0] = VAR_0->pvq->quant_band(VAR_0->pvq, VAR_0, VAR_1, VAR_8, X,    Y, band_size, b >> 0,
VAR_0->blocks, norm_loc1, VAR_0->size,
VAR_3 + band_offset, 0, 1.0f,
VAR_2, cm[0] | cm[1]); cm[1] = cm[0]; } VAR_0->block[0].collapse_masks[VAR_8]               = (uint8_t)cm[0]; VAR_0->block[VAR_0->channels - 1].collapse_masks[VAR_8] = (uint8_t)cm[1]; VAR_0->remaining += VAR_0->pulses[VAR_8] + consumed; VAR_6 = (b > band_size << 3); } }