uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,

                             float *X, float *Y, int N, int b, uint32_t blocks,

                             float *lowband, int duration, float *lowband_out, int level,

                             float gain, float *lowband_scratch, int fill)

{

    const uint8_t *cache;

    int dualstereo, split;

    int imid = 0, iside = 0;

    //uint32_t N0 = N;

    int N_B;

    //int N_B0;

    int B0 = blocks;

    int time_divide = 0;

    int recombine = 0;

    int inv = 0;

    float mid = 0, side = 0;

    int longblocks = (B0 == 1);

    uint32_t cm = 0;



    //N_B0 = N_B = N / blocks;

    split = dualstereo = (Y != NULL);



    if (N == 1) {

        /* special case for one sample - the decoder's output will be +- 1.0f!!! */

        int i;

        float *x = X;

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

            if (f->remaining2 >= 1<<3) {

                ff_opus_rc_put_raw(rc, x[0] < 0, 1);

                f->remaining2 -= 1 << 3;

                b             -= 1 << 3;

            }

            x = Y;

        }

        if (lowband_out)

            lowband_out[0] = X[0];

        return 1;

    }



    if (!dualstereo && level == 0) {

        int tf_change = f->tf_change[band];

        int k;

        if (tf_change > 0)

            recombine = tf_change;

        /* Band recombining to increase frequency resolution */



        if (lowband &&

            (recombine || ((N_B & 1) == 0 && tf_change < 0) || B0 > 1)) {

            int j;

            for (j = 0; j < N; j++)

                lowband_scratch[j] = lowband[j];

            lowband = lowband_scratch;

        }



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

            celt_haar1(X, N >> k, 1 << k);

            fill = ff_celt_bit_interleave[fill & 0xF] | ff_celt_bit_interleave[fill >> 4] << 2;

        }

        blocks >>= recombine;

        N_B <<= recombine;



        /* Increasing the time resolution */

        while ((N_B & 1) == 0 && tf_change < 0) {

            celt_haar1(X, N_B, blocks);

            fill |= fill << blocks;

            blocks <<= 1;

            N_B >>= 1;

            time_divide++;

            tf_change++;

        }

        B0 = blocks;

        //N_B0 = N_B;



        /* Reorganize the samples in time order instead of frequency order */

        if (B0 > 1)

            celt_deinterleave_hadamard(f->scratch, X, N_B >> recombine,

                                       B0 << recombine, longblocks);

    }



    /* If we need 1.5 more bit than we can produce, split the band in two. */

    cache = ff_celt_cache_bits +

            ff_celt_cache_index[(duration + 1) * CELT_MAX_BANDS + band];

    if (!dualstereo && duration >= 0 && b > cache[cache[0]] + 12 && N > 2) {

        N >>= 1;

        Y = X + N;

        split = 1;

        duration -= 1;

        if (blocks == 1)

            fill = (fill & 1) | (fill << 1);

        blocks = (blocks + 1) >> 1;

    }



    if (split) {

        int qn;

        int itheta = celt_calc_theta(X, Y, dualstereo, N);

        int mbits, sbits, delta;

        int qalloc;

        int pulse_cap;

        int offset;

        int orig_fill;

        int tell;



        /* Decide on the resolution to give to the split parameter theta */

        pulse_cap = ff_celt_log_freq_range[band] + duration * 8;

        offset = (pulse_cap >> 1) - (dualstereo && N == 2 ? CELT_QTHETA_OFFSET_TWOPHASE :

                                                          CELT_QTHETA_OFFSET);

        qn = (dualstereo && band >= f->intensity_stereo) ? 1 :

             celt_compute_qn(N, b, offset, pulse_cap, dualstereo);

        tell = opus_rc_tell_frac(rc);



        if (qn != 1) {



            itheta = (itheta*qn + 8192) >> 14;



            /* Entropy coding of the angle. We use a uniform pdf for the

             * time split, a step for stereo, and a triangular one for the rest. */

            if (dualstereo && N > 2)

                ff_opus_rc_enc_uint_step(rc, itheta, qn / 2);

            else if (dualstereo || B0 > 1)

                ff_opus_rc_enc_uint(rc, itheta, qn + 1);

            else

                ff_opus_rc_enc_uint_tri(rc, itheta, qn);

            itheta = itheta * 16384 / qn;



            if (dualstereo) {

                if (itheta == 0)

                    celt_stereo_is_decouple(X, Y, f->block[0].lin_energy[band], f->block[1].lin_energy[band], N);

                else

                    celt_stereo_ms_decouple(X, Y, N);

            }

        } else if (dualstereo) {

             inv = itheta > 8192;

             if (inv)

             {

                int j;

                for (j=0;j<N;j++)

                   Y[j] = -Y[j];

             }

             celt_stereo_is_decouple(X, Y, f->block[0].lin_energy[band], f->block[1].lin_energy[band], N);



            if (b > 2 << 3 && f->remaining2 > 2 << 3) {

                ff_opus_rc_enc_log(rc, inv, 2);

            } else {

                inv = 0;

            }



            itheta = 0;

        }

        qalloc = opus_rc_tell_frac(rc) - tell;

        b -= qalloc;



        orig_fill = fill;

        if (itheta == 0) {

            imid = 32767;

            iside = 0;

            fill = av_mod_uintp2(fill, blocks);

            delta = -16384;

        } else if (itheta == 16384) {

            imid = 0;

            iside = 32767;

            fill &= ((1 << blocks) - 1) << blocks;

            delta = 16384;

        } else {

            imid = celt_cos(itheta);

            iside = celt_cos(16384-itheta);

            /* This is the mid vs side allocation that minimizes squared error

            in that band. */

            delta = ROUND_MUL16((N - 1) << 7, celt_log2tan(iside, imid));

        }



        mid  = imid  / 32768.0f;

        side = iside / 32768.0f;



        /* This is a special case for N=2 that only works for stereo and takes

        advantage of the fact that mid and side are orthogonal to encode

        the side with just one bit. */

        if (N == 2 && dualstereo) {

            int c;

            int sign = 0;

            float tmp;

            float *x2, *y2;

            mbits = b;

            /* Only need one bit for the side */

            sbits = (itheta != 0 && itheta != 16384) ? 1 << 3 : 0;

            mbits -= sbits;

            c = (itheta > 8192);

            f->remaining2 -= qalloc+sbits;



            x2 = c ? Y : X;

            y2 = c ? X : Y;

            if (sbits) {

                sign = x2[0]*y2[1] - x2[1]*y2[0] < 0;

                ff_opus_rc_put_raw(rc, sign, 1);

            }

            sign = 1 - 2 * sign;

            /* We use orig_fill here because we want to fold the side, but if

            itheta==16384, we'll have cleared the low bits of fill. */

            cm = ff_celt_encode_band(f, rc, band, x2, NULL, N, mbits, blocks,

                                     lowband, duration, lowband_out, level, gain,

                                     lowband_scratch, orig_fill);

            /* We don't split N=2 bands, so cm is either 1 or 0 (for a fold-collapse),

            and there's no need to worry about mixing with the other channel. */

            y2[0] = -sign * x2[1];

            y2[1] =  sign * x2[0];

            X[0] *= mid;

            X[1] *= mid;

            Y[0] *= side;

            Y[1] *= side;

            tmp = X[0];

            X[0] = tmp - Y[0];

            Y[0] = tmp + Y[0];

            tmp = X[1];

            X[1] = tmp - Y[1];

            Y[1] = tmp + Y[1];

        } else {

            /* "Normal" split code */

            float *next_lowband2     = NULL;

            float *next_lowband_out1 = NULL;

            int next_level = 0;

            int rebalance;



            /* Give more bits to low-energy MDCTs than they would

             * otherwise deserve */

            if (B0 > 1 && !dualstereo && (itheta & 0x3fff)) {

                if (itheta > 8192)

                    /* Rough approximation for pre-echo masking */

                    delta -= delta >> (4 - duration);

                else

                    /* Corresponds to a forward-masking slope of

                     * 1.5 dB per 10 ms */

                    delta = FFMIN(0, delta + (N << 3 >> (5 - duration)));

            }

            mbits = av_clip((b - delta) / 2, 0, b);

            sbits = b - mbits;

            f->remaining2 -= qalloc;



            if (lowband && !dualstereo)

                next_lowband2 = lowband + N; /* >32-bit split case */



            /* Only stereo needs to pass on lowband_out.

             * Otherwise, it's handled at the end */

            if (dualstereo)

                next_lowband_out1 = lowband_out;

            else

                next_level = level + 1;



            rebalance = f->remaining2;

            if (mbits >= sbits) {

                /* In stereo mode, we do not apply a scaling to the mid

                 * because we need the normalized mid for folding later */

                cm = ff_celt_encode_band(f, rc, band, X, NULL, N, mbits, blocks,

                                         lowband, duration, next_lowband_out1,

                                         next_level, dualstereo ? 1.0f : (gain * mid),

                                         lowband_scratch, fill);



                rebalance = mbits - (rebalance - f->remaining2);

                if (rebalance > 3 << 3 && itheta != 0)

                    sbits += rebalance - (3 << 3);



                /* For a stereo split, the high bits of fill are always zero,

                 * so no folding will be done to the side. */

                cm |= ff_celt_encode_band(f, rc, band, Y, NULL, N, sbits, blocks,

                                          next_lowband2, duration, NULL,

                                          next_level, gain * side, NULL,

                                          fill >> blocks) << ((B0 >> 1) & (dualstereo - 1));

            } else {

                /* For a stereo split, the high bits of fill are always zero,

                 * so no folding will be done to the side. */

                cm = ff_celt_encode_band(f, rc, band, Y, NULL, N, sbits, blocks,

                                         next_lowband2, duration, NULL,

                                         next_level, gain * side, NULL,

                                         fill >> blocks) << ((B0 >> 1) & (dualstereo - 1));



                rebalance = sbits - (rebalance - f->remaining2);

                if (rebalance > 3 << 3 && itheta != 16384)

                    mbits += rebalance - (3 << 3);



                /* In stereo mode, we do not apply a scaling to the mid because

                 * we need the normalized mid for folding later */

                cm |= ff_celt_encode_band(f, rc, band, X, NULL, N, mbits, blocks,

                                          lowband, duration, next_lowband_out1,

                                          next_level, dualstereo ? 1.0f : (gain * mid),

                                          lowband_scratch, fill);

            }

        }

    } else {

        /* This is the basic no-split case */

        uint32_t q         = celt_bits2pulses(cache, b);

        uint32_t curr_bits = celt_pulses2bits(cache, q);

        f->remaining2 -= curr_bits;



        /* Ensures we can never bust the budget */

        while (f->remaining2 < 0 && q > 0) {

            f->remaining2 += curr_bits;

            curr_bits      = celt_pulses2bits(cache, --q);

            f->remaining2 -= curr_bits;

        }



        if (q != 0) {

            /* Finally do the actual quantization */

            cm = celt_alg_quant(rc, X, N, (q < 8) ? q : (8 + (q & 7)) << ((q >> 3) - 1),

                                f->spread, blocks, gain);

        }

    }



    return cm;

}

uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,

                             float *X, float *Y, int N, int b, uint32_t blocks,

                             float *lowband, int duration, float *lowband_out, int level,

                             float gain, float *lowband_scratch, int fill)

{

    const uint8_t *cache;

    int dualstereo, split;

    int imid = 0, iside = 0;

    

    int N_B;

    

    int B0 = blocks;

    int time_divide = 0;

    int recombine = 0;

    int inv = 0;

    float mid = 0, side = 0;

    int longblocks = (B0 == 1);

    uint32_t cm = 0;



    

    split = dualstereo = (Y != NULL);



    if (N == 1) {

        

        int i;

        float *x = X;

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

            if (f->remaining2 >= 1<<3) {

                ff_opus_rc_put_raw(rc, x[0] < 0, 1);

                f->remaining2 -= 1 << 3;

                b             -= 1 << 3;

            }

            x = Y;

        }

        if (lowband_out)

            lowband_out[0] = X[0];

        return 1;

    }



    if (!dualstereo && level == 0) {

        int tf_change = f->tf_change[band];

        int k;

        if (tf_change > 0)

            recombine = tf_change;

        



        if (lowband &&

            (recombine || ((N_B & 1) == 0 && tf_change < 0) || B0 > 1)) {

            int j;

            for (j = 0; j < N; j++)

                lowband_scratch[j] = lowband[j];

            lowband = lowband_scratch;

        }



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

            celt_haar1(X, N >> k, 1 << k);

            fill = ff_celt_bit_interleave[fill & 0xF] | ff_celt_bit_interleave[fill >> 4] << 2;

        }

        blocks >>= recombine;

        N_B <<= recombine;



        

        while ((N_B & 1) == 0 && tf_change < 0) {

            celt_haar1(X, N_B, blocks);

            fill |= fill << blocks;

            blocks <<= 1;

            N_B >>= 1;

            time_divide++;

            tf_change++;

        }

        B0 = blocks;

        



        

        if (B0 > 1)

            celt_deinterleave_hadamard(f->scratch, X, N_B >> recombine,

                                       B0 << recombine, longblocks);

    }



    

    cache = ff_celt_cache_bits +

            ff_celt_cache_index[(duration + 1) * CELT_MAX_BANDS + band];

    if (!dualstereo && duration >= 0 && b > cache[cache[0]] + 12 && N > 2) {

        N >>= 1;

        Y = X + N;

        split = 1;

        duration -= 1;

        if (blocks == 1)

            fill = (fill & 1) | (fill << 1);

        blocks = (blocks + 1) >> 1;

    }



    if (split) {

        int qn;

        int itheta = celt_calc_theta(X, Y, dualstereo, N);

        int mbits, sbits, delta;

        int qalloc;

        int pulse_cap;

        int offset;

        int orig_fill;

        int tell;



        

        pulse_cap = ff_celt_log_freq_range[band] + duration * 8;

        offset = (pulse_cap >> 1) - (dualstereo && N == 2 ? CELT_QTHETA_OFFSET_TWOPHASE :

                                                          CELT_QTHETA_OFFSET);

        qn = (dualstereo && band >= f->intensity_stereo) ? 1 :

             celt_compute_qn(N, b, offset, pulse_cap, dualstereo);

        tell = opus_rc_tell_frac(rc);



        if (qn != 1) {



            itheta = (itheta*qn + 8192) >> 14;



            



            if (dualstereo && N > 2)

                ff_opus_rc_enc_uint_step(rc, itheta, qn / 2);

            else if (dualstereo || B0 > 1)

                ff_opus_rc_enc_uint(rc, itheta, qn + 1);

            else

                ff_opus_rc_enc_uint_tri(rc, itheta, qn);

            itheta = itheta * 16384 / qn;



            if (dualstereo) {

                if (itheta == 0)

                    celt_stereo_is_decouple(X, Y, f->block[0].lin_energy[band], f->block[1].lin_energy[band], N);

                else

                    celt_stereo_ms_decouple(X, Y, N);

            }

        } else if (dualstereo) {

             inv = itheta > 8192;

             if (inv)

             {

                int j;

                for (j=0;j<N;j++)

                   Y[j] = -Y[j];

             }

             celt_stereo_is_decouple(X, Y, f->block[0].lin_energy[band], f->block[1].lin_energy[band], N);



            if (b > 2 << 3 && f->remaining2 > 2 << 3) {

                ff_opus_rc_enc_log(rc, inv, 2);

            } else {

                inv = 0;

            }



            itheta = 0;

        }

        qalloc = opus_rc_tell_frac(rc) - tell;

        b -= qalloc;



        orig_fill = fill;

        if (itheta == 0) {

            imid = 32767;

            iside = 0;

            fill = av_mod_uintp2(fill, blocks);

            delta = -16384;

        } else if (itheta == 16384) {

            imid = 0;

            iside = 32767;

            fill &= ((1 << blocks) - 1) << blocks;

            delta = 16384;

        } else {

            imid = celt_cos(itheta);

            iside = celt_cos(16384-itheta);

            



            delta = ROUND_MUL16((N - 1) << 7, celt_log2tan(iside, imid));

        }



        mid  = imid  / 32768.0f;

        side = iside / 32768.0f;



        





        if (N == 2 && dualstereo) {

            int c;

            int sign = 0;

            float tmp;

            float *x2, *y2;

            mbits = b;

            

            sbits = (itheta != 0 && itheta != 16384) ? 1 << 3 : 0;

            mbits -= sbits;

            c = (itheta > 8192);

            f->remaining2 -= qalloc+sbits;



            x2 = c ? Y : X;

            y2 = c ? X : Y;

            if (sbits) {

                sign = x2[0]*y2[1] - x2[1]*y2[0] < 0;

                ff_opus_rc_put_raw(rc, sign, 1);

            }

            sign = 1 - 2 * sign;

            



            cm = ff_celt_encode_band(f, rc, band, x2, NULL, N, mbits, blocks,

                                     lowband, duration, lowband_out, level, gain,

                                     lowband_scratch, orig_fill);

            



            y2[0] = -sign * x2[1];

            y2[1] =  sign * x2[0];

            X[0] *= mid;

            X[1] *= mid;

            Y[0] *= side;

            Y[1] *= side;

            tmp = X[0];

            X[0] = tmp - Y[0];

            Y[0] = tmp + Y[0];

            tmp = X[1];

            X[1] = tmp - Y[1];

            Y[1] = tmp + Y[1];

        } else {

            

            float *next_lowband2     = NULL;

            float *next_lowband_out1 = NULL;

            int next_level = 0;

            int rebalance;



            



            if (B0 > 1 && !dualstereo && (itheta & 0x3fff)) {

                if (itheta > 8192)

                    

                    delta -= delta >> (4 - duration);

                else

                    



                    delta = FFMIN(0, delta + (N << 3 >> (5 - duration)));

            }

            mbits = av_clip((b - delta) / 2, 0, b);

            sbits = b - mbits;

            f->remaining2 -= qalloc;



            if (lowband && !dualstereo)

                next_lowband2 = lowband + N; 



            



            if (dualstereo)

                next_lowband_out1 = lowband_out;

            else

                next_level = level + 1;



            rebalance = f->remaining2;

            if (mbits >= sbits) {

                



                cm = ff_celt_encode_band(f, rc, band, X, NULL, N, mbits, blocks,

                                         lowband, duration, next_lowband_out1,

                                         next_level, dualstereo ? 1.0f : (gain * mid),

                                         lowband_scratch, fill);



                rebalance = mbits - (rebalance - f->remaining2);

                if (rebalance > 3 << 3 && itheta != 0)

                    sbits += rebalance - (3 << 3);



                



                cm |= ff_celt_encode_band(f, rc, band, Y, NULL, N, sbits, blocks,

                                          next_lowband2, duration, NULL,

                                          next_level, gain * side, NULL,

                                          fill >> blocks) << ((B0 >> 1) & (dualstereo - 1));

            } else {

                



                cm = ff_celt_encode_band(f, rc, band, Y, NULL, N, sbits, blocks,

                                         next_lowband2, duration, NULL,

                                         next_level, gain * side, NULL,

                                         fill >> blocks) << ((B0 >> 1) & (dualstereo - 1));



                rebalance = sbits - (rebalance - f->remaining2);

                if (rebalance > 3 << 3 && itheta != 16384)

                    mbits += rebalance - (3 << 3);



                



                cm |= ff_celt_encode_band(f, rc, band, X, NULL, N, mbits, blocks,

                                          lowband, duration, next_lowband_out1,

                                          next_level, dualstereo ? 1.0f : (gain * mid),

                                          lowband_scratch, fill);

            }

        }

    } else {

        

        uint32_t q         = celt_bits2pulses(cache, b);

        uint32_t curr_bits = celt_pulses2bits(cache, q);

        f->remaining2 -= curr_bits;



        

        while (f->remaining2 < 0 && q > 0) {

            f->remaining2 += curr_bits;

            curr_bits      = celt_pulses2bits(cache, --q);

            f->remaining2 -= curr_bits;

        }



        if (q != 0) {

            

            cm = celt_alg_quant(rc, X, N, (q < 8) ? q : (8 + (q & 7)) << ((q >> 3) - 1),

                                f->spread, blocks, gain);

        }

    }



    return cm;

}

    int N_B;
uint32_t FUNC_0(CeltFrame *f, OpusRangeCoder *rc, const int band,

                             float *X, float *Y, int N, int b, uint32_t blocks,

                             float *lowband, int duration, float *lowband_out, int level,

                             float gain, float *lowband_scratch, int fill)

{

    const uint8_t *VAR_0;

    int VAR_1, VAR_2;

    int VAR_3 = 0, VAR_4 = 0;

    

    int VAR_5;

    

    int VAR_6 = blocks;

    int VAR_7 = 0;

    int VAR_8 = 0;

    int VAR_9 = 0;

    float VAR_10 = 0, VAR_11 = 0;

    int VAR_12 = (VAR_6 == 1);

    uint32_t cm = 0;



    

    VAR_2 = VAR_1 = (Y != NULL);



    if (N == 1) {

        

        int VAR_13;

        float *VAR_14 = X;

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

            if (f->remaining2 >= 1<<3) {

                ff_opus_rc_put_raw(rc, VAR_14[0] < 0, 1);

                f->remaining2 -= 1 << 3;

                b             -= 1 << 3;

            }

            VAR_14 = Y;

        }

        if (lowband_out)

            lowband_out[0] = X[0];

        return 1;

    }



    if (!VAR_1 && level == 0) {

        int VAR_15 = f->VAR_15[band];

        int VAR_16;

        if (VAR_15 > 0)

            VAR_8 = VAR_15;

        



        if (lowband &&

            (VAR_8 || ((VAR_5 & 1) == 0 && VAR_15 < 0) || VAR_6 > 1)) {

            int VAR_28;

            for (VAR_28 = 0; VAR_28 < N; VAR_28++)

                lowband_scratch[VAR_28] = lowband[VAR_28];

            lowband = lowband_scratch;

        }



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

            celt_haar1(X, N >> VAR_16, 1 << VAR_16);

            fill = ff_celt_bit_interleave[fill & 0xF] | ff_celt_bit_interleave[fill >> 4] << 2;

        }

        blocks >>= VAR_8;

        VAR_5 <<= VAR_8;



        

        while ((VAR_5 & 1) == 0 && VAR_15 < 0) {

            celt_haar1(X, VAR_5, blocks);

            fill |= fill << blocks;

            blocks <<= 1;

            VAR_5 >>= 1;

            VAR_7++;

            VAR_15++;

        }

        VAR_6 = blocks;

        



        

        if (VAR_6 > 1)

            celt_deinterleave_hadamard(f->scratch, X, VAR_5 >> VAR_8,

                                       VAR_6 << VAR_8, VAR_12);

    }



    

    VAR_0 = ff_celt_cache_bits +

            ff_celt_cache_index[(duration + 1) * CELT_MAX_BANDS + band];

    if (!VAR_1 && duration >= 0 && b > VAR_0[VAR_0[0]] + 12 && N > 2) {

        N >>= 1;

        Y = X + N;

        VAR_2 = 1;

        duration -= 1;

        if (blocks == 1)

            fill = (fill & 1) | (fill << 1);

        blocks = (blocks + 1) >> 1;

    }



    if (VAR_2) {

        int VAR_18;

        int VAR_19 = celt_calc_theta(X, Y, VAR_1, N);

        int VAR_20, VAR_21, VAR_22;

        int VAR_23;

        int VAR_24;

        int VAR_25;

        int VAR_26;

        int VAR_27;



        

        VAR_24 = ff_celt_log_freq_range[band] + duration * 8;

        VAR_25 = (VAR_24 >> 1) - (VAR_1 && N == 2 ? CELT_QTHETA_OFFSET_TWOPHASE :

                                                          CELT_QTHETA_OFFSET);

        VAR_18 = (VAR_1 && band >= f->intensity_stereo) ? 1 :

             celt_compute_qn(N, b, VAR_25, VAR_24, VAR_1);

        VAR_27 = opus_rc_tell_frac(rc);



        if (VAR_18 != 1) {



            VAR_19 = (VAR_19*VAR_18 + 8192) >> 14;



            



            if (VAR_1 && N > 2)

                ff_opus_rc_enc_uint_step(rc, VAR_19, VAR_18 / 2);

            else if (VAR_1 || VAR_6 > 1)

                ff_opus_rc_enc_uint(rc, VAR_19, VAR_18 + 1);

            else

                ff_opus_rc_enc_uint_tri(rc, VAR_19, VAR_18);

            VAR_19 = VAR_19 * 16384 / VAR_18;



            if (VAR_1) {

                if (VAR_19 == 0)

                    celt_stereo_is_decouple(X, Y, f->block[0].lin_energy[band], f->block[1].lin_energy[band], N);

                else

                    celt_stereo_ms_decouple(X, Y, N);

            }

        } else if (VAR_1) {

             VAR_9 = VAR_19 > 8192;

             if (VAR_9)

             {

                int VAR_28;

                for (VAR_28=0;VAR_28<N;VAR_28++)

                   Y[VAR_28] = -Y[VAR_28];

             }

             celt_stereo_is_decouple(X, Y, f->block[0].lin_energy[band], f->block[1].lin_energy[band], N);



            if (b > 2 << 3 && f->remaining2 > 2 << 3) {

                ff_opus_rc_enc_log(rc, VAR_9, 2);

            } else {

                VAR_9 = 0;

            }



            VAR_19 = 0;

        }

        VAR_23 = opus_rc_tell_frac(rc) - VAR_27;

        b -= VAR_23;



        VAR_26 = fill;

        if (VAR_19 == 0) {

            VAR_3 = 32767;

            VAR_4 = 0;

            fill = av_mod_uintp2(fill, blocks);

            VAR_22 = -16384;

        } else if (VAR_19 == 16384) {

            VAR_3 = 0;

            VAR_4 = 32767;

            fill &= ((1 << blocks) - 1) << blocks;

            VAR_22 = 16384;

        } else {

            VAR_3 = celt_cos(VAR_19);

            VAR_4 = celt_cos(16384-VAR_19);

            



            VAR_22 = ROUND_MUL16((N - 1) << 7, celt_log2tan(VAR_4, VAR_3));

        }



        VAR_10  = VAR_3  / 32768.0f;

        VAR_11 = VAR_4 / 32768.0f;



        





        if (N == 2 && VAR_1) {

            int VAR_28;

            int VAR_29 = 0;

            float VAR_30;

            float *VAR_31, *VAR_32;

            VAR_20 = b;

            

            VAR_21 = (VAR_19 != 0 && VAR_19 != 16384) ? 1 << 3 : 0;

            VAR_20 -= VAR_21;

            VAR_28 = (VAR_19 > 8192);

            f->remaining2 -= VAR_23+VAR_21;



            VAR_31 = VAR_28 ? Y : X;

            VAR_32 = VAR_28 ? X : Y;

            if (VAR_21) {

                VAR_29 = VAR_31[0]*VAR_32[1] - VAR_31[1]*VAR_32[0] < 0;

                ff_opus_rc_put_raw(rc, VAR_29, 1);

            }

            VAR_29 = 1 - 2 * VAR_29;

            



            cm = FUNC_0(f, rc, band, VAR_31, NULL, N, VAR_20, blocks,

                                     lowband, duration, lowband_out, level, gain,

                                     lowband_scratch, VAR_26);

            



            VAR_32[0] = -VAR_29 * VAR_31[1];

            VAR_32[1] =  VAR_29 * VAR_31[0];

            X[0] *= VAR_10;

            X[1] *= VAR_10;

            Y[0] *= VAR_11;

            Y[1] *= VAR_11;

            VAR_30 = X[0];

            X[0] = VAR_30 - Y[0];

            Y[0] = VAR_30 + Y[0];

            VAR_30 = X[1];

            X[1] = VAR_30 - Y[1];

            Y[1] = VAR_30 + Y[1];

        } else {

            

            float *VAR_33     = NULL;

            float *VAR_34 = NULL;

            int VAR_35 = 0;

            int VAR_36;



            



            if (VAR_6 > 1 && !VAR_1 && (VAR_19 & 0x3fff)) {

                if (VAR_19 > 8192)

                    

                    VAR_22 -= VAR_22 >> (4 - duration);

                else

                    



                    VAR_22 = FFMIN(0, VAR_22 + (N << 3 >> (5 - duration)));

            }

            VAR_20 = av_clip((b - VAR_22) / 2, 0, b);

            VAR_21 = b - VAR_20;

            f->remaining2 -= VAR_23;



            if (lowband && !VAR_1)

                VAR_33 = lowband + N; 



            



            if (VAR_1)

                VAR_34 = lowband_out;

            else

                VAR_35 = level + 1;



            VAR_36 = f->remaining2;

            if (VAR_20 >= VAR_21) {

                



                cm = FUNC_0(f, rc, band, X, NULL, N, VAR_20, blocks,

                                         lowband, duration, VAR_34,

                                         VAR_35, VAR_1 ? 1.0f : (gain * VAR_10),

                                         lowband_scratch, fill);



                VAR_36 = VAR_20 - (VAR_36 - f->remaining2);

                if (VAR_36 > 3 << 3 && VAR_19 != 0)

                    VAR_21 += VAR_36 - (3 << 3);



                



                cm |= FUNC_0(f, rc, band, Y, NULL, N, VAR_21, blocks,

                                          VAR_33, duration, NULL,

                                          VAR_35, gain * VAR_11, NULL,

                                          fill >> blocks) << ((VAR_6 >> 1) & (VAR_1 - 1));

            } else {

                



                cm = FUNC_0(f, rc, band, Y, NULL, N, VAR_21, blocks,

                                         VAR_33, duration, NULL,

                                         VAR_35, gain * VAR_11, NULL,

                                         fill >> blocks) << ((VAR_6 >> 1) & (VAR_1 - 1));



                VAR_36 = VAR_21 - (VAR_36 - f->remaining2);

                if (VAR_36 > 3 << 3 && VAR_19 != 16384)

                    VAR_20 += VAR_36 - (3 << 3);



                



                cm |= FUNC_0(f, rc, band, X, NULL, N, VAR_20, blocks,

                                          lowband, duration, VAR_34,

                                          VAR_35, VAR_1 ? 1.0f : (gain * VAR_10),

                                          lowband_scratch, fill);

            }

        }

    } else {

        

        uint32_t q         = celt_bits2pulses(VAR_0, b);

        uint32_t curr_bits = celt_pulses2bits(VAR_0, q);

        f->remaining2 -= curr_bits;



        

        while (f->remaining2 < 0 && q > 0) {

            f->remaining2 += curr_bits;

            curr_bits      = celt_pulses2bits(VAR_0, --q);

            f->remaining2 -= curr_bits;

        }



        if (q != 0) {

            

            cm = celt_alg_quant(rc, X, N, (q < 8) ? q : (8 + (q & 7)) << ((q >> 3) - 1),

                                f->spread, blocks, gain);

        }

    }



    return cm;

}

uint32_t FUNC_0(CeltFrame *f, OpusRangeCoder *rc, const int band,
float *X, float *Y, int N, int b, uint32_t blocks,
float *lowband, int duration, float *lowband_out, int level,
float gain, float *lowband_scratch, int fill)
{ const uint8_t *VAR_0; int VAR_1, VAR_2; int VAR_3 = 0, VAR_4 = 0; int VAR_5; int VAR_6 = blocks; int VAR_7 = 0; int VAR_8 = 0; int VAR_9 = 0; float VAR_10 = 0, VAR_11 = 0; int VAR_12 = (VAR_6 == 1); uint32_t cm = 0; VAR_2 = VAR_1 = (Y != NULL); if (N == 1) { int VAR_13; float *VAR_14 = X; for (VAR_13 = 0; VAR_13 <= VAR_1; VAR_13++) { if (f->remaining2 >= 1<<3) { ff_opus_rc_put_raw(rc, VAR_14[0] < 0, 1); f->remaining2 -= 1 << 3; b             -= 1 << 3; } VAR_14 = Y; } if (lowband_out)
lowband_out[0] = X[0]; return 1; } if (!VAR_1 && level == 0) { int VAR_15 = f->VAR_15[band]; int VAR_16; if (VAR_15 > 0)
VAR_8 = VAR_15; if (lowband &&
(VAR_8 || ((VAR_5 & 1) == 0 && VAR_15 < 0) || VAR_6 > 1)) { int VAR_28; for (VAR_28 = 0; VAR_28 < N; VAR_28++) lowband_scratch[VAR_28] = lowband[VAR_28]; lowband = lowband_scratch; } for (VAR_16 = 0; VAR_16 < VAR_8; VAR_16++) { celt_haar1(X, N >> VAR_16, 1 << VAR_16); fill = ff_celt_bit_interleave[fill & 0xF] | ff_celt_bit_interleave[fill >> 4] << 2; } blocks >>= VAR_8; VAR_5 <<= VAR_8; while ((VAR_5 & 1) == 0 && VAR_15 < 0) { celt_haar1(X, VAR_5, blocks); fill |= fill << blocks; blocks <<= 1; VAR_5 >>= 1; VAR_7++; VAR_15++; } VAR_6 = blocks; if (VAR_6 > 1)
celt_deinterleave_hadamard(f->scratch, X, VAR_5 >> VAR_8,
VAR_6 << VAR_8, VAR_12); } VAR_0 = ff_celt_cache_bits +
ff_celt_cache_index[(duration + 1) * CELT_MAX_BANDS + band]; if (!VAR_1 && duration >= 0 && b > VAR_0[VAR_0[0]] + 12 && N > 2) { N >>= 1; Y = X + N; VAR_2 = 1; duration -= 1; if (blocks == 1)
fill = (fill & 1) | (fill << 1); blocks = (blocks + 1) >> 1; } if (VAR_2) { int VAR_18; int VAR_19 = celt_calc_theta(X, Y, VAR_1, N); int VAR_20, VAR_21, VAR_22; int VAR_23; int VAR_24; int VAR_25; int VAR_26; int VAR_27; VAR_24 = ff_celt_log_freq_range[band] + duration * 8; VAR_25 = (VAR_24 >> 1) - (VAR_1 && N == 2 ? CELT_QTHETA_OFFSET_TWOPHASE :
CELT_QTHETA_OFFSET); VAR_18 = (VAR_1 && band >= f->intensity_stereo) ? 1 :
celt_compute_qn(N, b, VAR_25, VAR_24, VAR_1); VAR_27 = opus_rc_tell_frac(rc); if (VAR_18 != 1) { VAR_19 = (VAR_19*VAR_18 + 8192) >> 14; if (VAR_1 && N > 2)
ff_opus_rc_enc_uint_step(rc, VAR_19, VAR_18 / 2); else if (VAR_1 || VAR_6 > 1)
ff_opus_rc_enc_uint(rc, VAR_19, VAR_18 + 1); else
ff_opus_rc_enc_uint_tri(rc, VAR_19, VAR_18); VAR_19 = VAR_19 * 16384 / VAR_18; if (VAR_1) { if (VAR_19 == 0)
celt_stereo_is_decouple(X, Y, f->block[0].lin_energy[band], f->block[1].lin_energy[band], N); else
celt_stereo_ms_decouple(X, Y, N); } } else if (VAR_1) { VAR_9 = VAR_19 > 8192; if (VAR_9)
{ int VAR_28; for (VAR_28=0;VAR_28<N;VAR_28++) Y[VAR_28] = -Y[VAR_28]; } celt_stereo_is_decouple(X, Y, f->block[0].lin_energy[band], f->block[1].lin_energy[band], N); if (b > 2 << 3 && f->remaining2 > 2 << 3) { ff_opus_rc_enc_log(rc, VAR_9, 2); } else { VAR_9 = 0; } VAR_19 = 0; } VAR_23 = opus_rc_tell_frac(rc) - VAR_27; b -= VAR_23; VAR_26 = fill; if (VAR_19 == 0) { VAR_3 = 32767; VAR_4 = 0; fill = av_mod_uintp2(fill, blocks); VAR_22 = -16384; } else if (VAR_19 == 16384) { VAR_3 = 0; VAR_4 = 32767; fill &= ((1 << blocks) - 1) << blocks; VAR_22 = 16384; } else { VAR_3 = celt_cos(VAR_19); VAR_4 = celt_cos(16384-VAR_19); VAR_22 = ROUND_MUL16((N - 1) << 7, celt_log2tan(VAR_4, VAR_3)); } VAR_10  = VAR_3  / 32768.0f; VAR_11 = VAR_4 / 32768.0f; if (N == 2 && VAR_1) { int VAR_28; int VAR_29 = 0; float VAR_30; float *VAR_31, *VAR_32; VAR_20 = b; VAR_21 = (VAR_19 != 0 && VAR_19 != 16384) ? 1 << 3 : 0; VAR_20 -= VAR_21; VAR_28 = (VAR_19 > 8192); f->remaining2 -= VAR_23+VAR_21; VAR_31 = VAR_28 ? Y : X; VAR_32 = VAR_28 ? X : Y; if (VAR_21) { VAR_29 = VAR_31[0]*VAR_32[1] - VAR_31[1]*VAR_32[0] < 0; ff_opus_rc_put_raw(rc, VAR_29, 1); } VAR_29 = 1 - 2 * VAR_29; cm = FUNC_0(f, rc, band, VAR_31, NULL, N, VAR_20, blocks,
lowband, duration, lowband_out, level, gain,
lowband_scratch, VAR_26); VAR_32[0] = -VAR_29 * VAR_31[1]; VAR_32[1] =  VAR_29 * VAR_31[0]; X[0] *= VAR_10; X[1] *= VAR_10; Y[0] *= VAR_11; Y[1] *= VAR_11; VAR_30 = X[0]; X[0] = VAR_30 - Y[0]; Y[0] = VAR_30 + Y[0]; VAR_30 = X[1]; X[1] = VAR_30 - Y[1]; Y[1] = VAR_30 + Y[1]; } else { float *VAR_33     = NULL; float *VAR_34 = NULL; int VAR_35 = 0; int VAR_36; if (VAR_6 > 1 && !VAR_1 && (VAR_19 & 0x3fff)) { if (VAR_19 > 8192)
VAR_22 -= VAR_22 >> (4 - duration); else
VAR_22 = FFMIN(0, VAR_22 + (N << 3 >> (5 - duration))); } VAR_20 = av_clip((b - VAR_22) / 2, 0, b); VAR_21 = b - VAR_20; f->remaining2 -= VAR_23; if (lowband && !VAR_1)
VAR_33 = lowband + N; if (VAR_1)
VAR_34 = lowband_out; else
VAR_35 = level + 1; VAR_36 = f->remaining2; if (VAR_20 >= VAR_21) { cm = FUNC_0(f, rc, band, X, NULL, N, VAR_20, blocks,
lowband, duration, VAR_34,
VAR_35, VAR_1 ? 1.0f : (gain * VAR_10),
lowband_scratch, fill); VAR_36 = VAR_20 - (VAR_36 - f->remaining2); if (VAR_36 > 3 << 3 && VAR_19 != 0)
VAR_21 += VAR_36 - (3 << 3); cm |= FUNC_0(f, rc, band, Y, NULL, N, VAR_21, blocks,
VAR_33, duration, NULL,
VAR_35, gain * VAR_11, NULL,
fill >> blocks) << ((VAR_6 >> 1) & (VAR_1 - 1)); } else { cm = FUNC_0(f, rc, band, Y, NULL, N, VAR_21, blocks,
VAR_33, duration, NULL,
VAR_35, gain * VAR_11, NULL,
fill >> blocks) << ((VAR_6 >> 1) & (VAR_1 - 1)); VAR_36 = VAR_21 - (VAR_36 - f->remaining2); if (VAR_36 > 3 << 3 && VAR_19 != 16384)
VAR_20 += VAR_36 - (3 << 3); cm |= FUNC_0(f, rc, band, X, NULL, N, VAR_20, blocks,
lowband, duration, VAR_34,
VAR_35, VAR_1 ? 1.0f : (gain * VAR_10),
lowband_scratch, fill); } } } else { uint32_t q         = celt_bits2pulses(VAR_0, b); uint32_t curr_bits = celt_pulses2bits(VAR_0, q); f->remaining2 -= curr_bits; while (f->remaining2 < 0 && q > 0) { f->remaining2 += curr_bits; curr_bits      = celt_pulses2bits(VAR_0, --q); f->remaining2 -= curr_bits; } if (q != 0) { cm = celt_alg_quant(rc, X, N, (q < 8) ? q : (8 + (q & 7)) << ((q >> 3) - 1),
f->spread, blocks, gain); } } return cm; }