static void residue_encode(vorbis_enc_context *venc, vorbis_enc_residue *rc,

                           PutBitContext *pb, float *coeffs, int samples,

                           int real_ch)

{

    int pass, i, j, p, k;

    int psize      = rc->partition_size;

    int partitions = (rc->end - rc->begin) / psize;

    int channels   = (rc->type == 2) ? 1 : real_ch;

    int classes[MAX_CHANNELS][NUM_RESIDUE_PARTITIONS];

    int classwords = venc->codebooks[rc->classbook].ndimentions;



    assert(rc->type == 2);

    assert(real_ch == 2);

    for (p = 0; p < partitions; p++) {

        float max1 = 0., max2 = 0.;

        int s = rc->begin + p * psize;

        for (k = s; k < s + psize; k += 2) {

            max1 = FFMAX(max1, fabs(coeffs[          k / real_ch]));

            max2 = FFMAX(max2, fabs(coeffs[samples + k / real_ch]));

        }



        for (i = 0; i < rc->classifications - 1; i++)

            if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1])

                break;

        classes[0][p] = i;

    }



    for (pass = 0; pass < 8; pass++) {

        p = 0;

        while (p < partitions) {

            if (pass == 0)

                for (j = 0; j < channels; j++) {

                    vorbis_enc_codebook * book = &venc->codebooks[rc->classbook];

                    int entry = 0;

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

                        entry *= rc->classifications;

                        entry += classes[j][p + i];

                    }

                    put_codeword(pb, book, entry);

                }

            for (i = 0; i < classwords && p < partitions; i++, p++) {

                for (j = 0; j < channels; j++) {

                    int nbook = rc->books[classes[j][p]][pass];

                    vorbis_enc_codebook * book = &venc->codebooks[nbook];

                    float *buf = coeffs + samples*j + rc->begin + p*psize;

                    if (nbook == -1)

                        continue;



                    assert(rc->type == 0 || rc->type == 2);

                    assert(!(psize % book->ndimentions));



                    if (rc->type == 0) {

                        for (k = 0; k < psize; k += book->ndimentions) {

                            float *a = put_vector(book, pb, &buf[k]);

                            int l;

                            for (l = 0; l < book->ndimentions; l++)

                                buf[k + l] -= a[l];

                        }

                    } else {

                        int s = rc->begin + p * psize, a1, b1;

                        a1 = (s % real_ch) * samples;

                        b1 =  s / real_ch;

                        s  = real_ch * samples;

                        for (k = 0; k < psize; k += book->ndimentions) {

                            int dim, a2 = a1, b2 = b1;

                            float vec[MAX_CODEBOOK_DIM], *pv = vec;

                            for (dim = book->ndimentions; dim--; ) {

                                *pv++ = coeffs[a2 + b2];

                                if ((a2 += samples) == s) {

                                    a2 = 0;

                                    b2++;

                                }

                            }

                            pv = put_vector(book, pb, vec);

                            for (dim = book->ndimentions; dim--; ) {

                                coeffs[a1 + b1] -= *pv++;

                                if ((a1 += samples) == s) {

                                    a1 = 0;

                                    b1++;

                                }

                            }

                        }

                    }

                }

            }

        }

    }

}

static void residue_encode(vorbis_enc_context *venc, vorbis_enc_residue *rc,

                           PutBitContext *pb, float *coeffs, int samples,

                           int real_ch)

{

    int pass, i, j, p, k;

    int psize      = rc->partition_size;

    int partitions = (rc->end - rc->begin) / psize;

    int channels   = (rc->type == 2) ? 1 : real_ch;

    int classes[MAX_CHANNELS][NUM_RESIDUE_PARTITIONS];

    int classwords = venc->codebooks[rc->classbook].ndimentions;



    assert(rc->type == 2);

    assert(real_ch == 2);

    for (p = 0; p < partitions; p++) {

        float max1 = 0., max2 = 0.;

        int s = rc->begin + p * psize;

        for (k = s; k < s + psize; k += 2) {

            max1 = FFMAX(max1, fabs(coeffs[          k / real_ch]));

            max2 = FFMAX(max2, fabs(coeffs[samples + k / real_ch]));

        }



        for (i = 0; i < rc->classifications - 1; i++)

            if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1])

                break;

        classes[0][p] = i;

    }



    for (pass = 0; pass < 8; pass++) {

        p = 0;

        while (p < partitions) {

            if (pass == 0)

                for (j = 0; j < channels; j++) {

                    vorbis_enc_codebook * book = &venc->codebooks[rc->classbook];

                    int entry = 0;

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

                        entry *= rc->classifications;

                        entry += classes[j][p + i];

                    }

                    put_codeword(pb, book, entry);

                }

            for (i = 0; i < classwords && p < partitions; i++, p++) {

                for (j = 0; j < channels; j++) {

                    int nbook = rc->books[classes[j][p]][pass];

                    vorbis_enc_codebook * book = &venc->codebooks[nbook];

                    float *buf = coeffs + samples*j + rc->begin + p*psize;

                    if (nbook == -1)

                        continue;



                    assert(rc->type == 0 || rc->type == 2);

                    assert(!(psize % book->ndimentions));



                    if (rc->type == 0) {

                        for (k = 0; k < psize; k += book->ndimentions) {

                            float *a = put_vector(book, pb, &buf[k]);

                            int l;

                            for (l = 0; l < book->ndimentions; l++)

                                buf[k + l] -= a[l];

                        }

                    } else {

                        int s = rc->begin + p * psize, a1, b1;

                        a1 = (s % real_ch) * samples;

                        b1 =  s / real_ch;

                        s  = real_ch * samples;

                        for (k = 0; k < psize; k += book->ndimentions) {

                            int dim, a2 = a1, b2 = b1;

                            float vec[MAX_CODEBOOK_DIM], *pv = vec;

                            for (dim = book->ndimentions; dim--; ) {

                                *pv++ = coeffs[a2 + b2];

                                if ((a2 += samples) == s) {

                                    a2 = 0;

                                    b2++;

                                }

                            }

                            pv = put_vector(book, pb, vec);

                            for (dim = book->ndimentions; dim--; ) {

                                coeffs[a1 + b1] -= *pv++;

                                if ((a1 += samples) == s) {

                                    a1 = 0;

                                    b1++;

                                }

                            }

                        }

                    }

                }

            }

        }

    }

}

static void residue_encode(vorbis_enc_context *venc, vorbis_enc_residue *rc,                            PutBitContext *pb, float *coeffs, int samples,                            int real_ch)                     put_codeword(pb, book, entry);                             float *a = put_vector(book, pb, &buf[k]);
static void FUNC_0(vorbis_enc_context *VAR_0, vorbis_enc_residue *VAR_1,

                           PutBitContext *VAR_2, float *VAR_3, int VAR_4,

                           int VAR_5)

{

    int VAR_6, VAR_7, VAR_8, VAR_9, VAR_10;

    int VAR_11      = VAR_1->partition_size;

    int VAR_12 = (VAR_1->end - VAR_1->begin) / VAR_11;

    int VAR_13   = (VAR_1->type == 2) ? 1 : VAR_5;

    int VAR_14[MAX_CHANNELS][NUM_RESIDUE_PARTITIONS];

    int VAR_15 = VAR_0->codebooks[VAR_1->classbook].ndimentions;



    assert(VAR_1->type == 2);

    assert(VAR_5 == 2);

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

        float VAR_16 = 0., VAR_17 = 0.;

        int VAR_24 = VAR_1->begin + VAR_9 * VAR_11;

        for (VAR_10 = VAR_24; VAR_10 < VAR_24 + VAR_11; VAR_10 += 2) {

            VAR_16 = FFMAX(VAR_16, fabs(VAR_3[          VAR_10 / VAR_5]));

            VAR_17 = FFMAX(VAR_17, fabs(VAR_3[VAR_4 + VAR_10 / VAR_5]));

        }



        for (VAR_7 = 0; VAR_7 < VAR_1->classifications - 1; VAR_7++)

            if (VAR_16 < VAR_1->maxes[VAR_7][0] && VAR_17 < VAR_1->maxes[VAR_7][1])

                break;

        VAR_14[0][VAR_9] = VAR_7;

    }



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

        VAR_9 = 0;

        while (VAR_9 < VAR_12) {

            if (VAR_6 == 0)

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

                    vorbis_enc_codebook * book = &VAR_0->codebooks[VAR_1->classbook];

                    int VAR_19 = 0;

                    for (VAR_7 = 0; VAR_7 < VAR_15; VAR_7++) {

                        VAR_19 *= VAR_1->classifications;

                        VAR_19 += VAR_14[VAR_8][VAR_9 + VAR_7];

                    }

                    put_codeword(VAR_2, book, VAR_19);

                }

            for (VAR_7 = 0; VAR_7 < VAR_15 && VAR_9 < VAR_12; VAR_7++, VAR_9++) {

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

                    int VAR_20 = VAR_1->books[VAR_14[VAR_8][VAR_9]][VAR_6];

                    vorbis_enc_codebook * book = &VAR_0->codebooks[VAR_20];

                    float *VAR_21 = VAR_3 + VAR_4*VAR_8 + VAR_1->begin + VAR_9*VAR_11;

                    if (VAR_20 == -1)

                        continue;



                    assert(VAR_1->type == 0 || VAR_1->type == 2);

                    assert(!(VAR_11 % book->ndimentions));



                    if (VAR_1->type == 0) {

                        for (VAR_10 = 0; VAR_10 < VAR_11; VAR_10 += book->ndimentions) {

                            float *VAR_22 = put_vector(book, VAR_2, &VAR_21[VAR_10]);

                            int VAR_23;

                            for (VAR_23 = 0; VAR_23 < book->ndimentions; VAR_23++)

                                VAR_21[VAR_10 + VAR_23] -= VAR_22[VAR_23];

                        }

                    } else {

                        int VAR_24 = VAR_1->begin + VAR_9 * VAR_11, VAR_24, VAR_25;

                        VAR_24 = (VAR_24 % VAR_5) * VAR_4;

                        VAR_25 =  VAR_24 / VAR_5;

                        VAR_24  = VAR_5 * VAR_4;

                        for (VAR_10 = 0; VAR_10 < VAR_11; VAR_10 += book->ndimentions) {

                            int VAR_26, VAR_27 = VAR_24, VAR_28 = VAR_25;

                            float VAR_29[MAX_CODEBOOK_DIM], *pv = VAR_29;

                            for (VAR_26 = book->ndimentions; VAR_26--; ) {

                                *pv++ = VAR_3[VAR_27 + VAR_28];

                                if ((VAR_27 += VAR_4) == VAR_24) {

                                    VAR_27 = 0;

                                    VAR_28++;

                                }

                            }

                            pv = put_vector(book, VAR_2, VAR_29);

                            for (VAR_26 = book->ndimentions; VAR_26--; ) {

                                VAR_3[VAR_24 + VAR_25] -= *pv++;

                                if ((VAR_24 += VAR_4) == VAR_24) {

                                    VAR_24 = 0;

                                    VAR_25++;

                                }

                            }

                        }

                    }

                }

            }

        }

    }

}

static void FUNC_0(vorbis_enc_context *VAR_0, vorbis_enc_residue *VAR_1,
PutBitContext *VAR_2, float *VAR_3, int VAR_4,
int VAR_5)
{ int VAR_6, VAR_7, VAR_8, VAR_9, VAR_10; int VAR_11      = VAR_1->partition_size; int VAR_12 = (VAR_1->end - VAR_1->begin) / VAR_11; int VAR_13   = (VAR_1->type == 2) ? 1 : VAR_5; int VAR_14[MAX_CHANNELS][NUM_RESIDUE_PARTITIONS]; int VAR_15 = VAR_0->codebooks[VAR_1->classbook].ndimentions; assert(VAR_1->type == 2); assert(VAR_5 == 2); for (VAR_9 = 0; VAR_9 < VAR_12; VAR_9++) { float VAR_16 = 0., VAR_17 = 0.; int VAR_24 = VAR_1->begin + VAR_9 * VAR_11; for (VAR_10 = VAR_24; VAR_10 < VAR_24 + VAR_11; VAR_10 += 2) { VAR_16 = FFMAX(VAR_16, fabs(VAR_3[          VAR_10 / VAR_5])); VAR_17 = FFMAX(VAR_17, fabs(VAR_3[VAR_4 + VAR_10 / VAR_5])); } for (VAR_7 = 0; VAR_7 < VAR_1->classifications - 1; VAR_7++) if (VAR_16 < VAR_1->maxes[VAR_7][0] && VAR_17 < VAR_1->maxes[VAR_7][1])
break; VAR_14[0][VAR_9] = VAR_7; } for (VAR_6 = 0; VAR_6 < 8; VAR_6++) { VAR_9 = 0; while (VAR_9 < VAR_12) { if (VAR_6 == 0)
for (VAR_8 = 0; VAR_8 < VAR_13; VAR_8++) { vorbis_enc_codebook * book = &VAR_0->codebooks[VAR_1->classbook]; int VAR_19 = 0; for (VAR_7 = 0; VAR_7 < VAR_15; VAR_7++) { VAR_19 *= VAR_1->classifications; VAR_19 += VAR_14[VAR_8][VAR_9 + VAR_7]; } put_codeword(VAR_2, book, VAR_19); } for (VAR_7 = 0; VAR_7 < VAR_15 && VAR_9 < VAR_12; VAR_7++, VAR_9++) { for (VAR_8 = 0; VAR_8 < VAR_13; VAR_8++) { int VAR_20 = VAR_1->books[VAR_14[VAR_8][VAR_9]][VAR_6]; vorbis_enc_codebook * book = &VAR_0->codebooks[VAR_20]; float *VAR_21 = VAR_3 + VAR_4*VAR_8 + VAR_1->begin + VAR_9*VAR_11; if (VAR_20 == -1)
continue; assert(VAR_1->type == 0 || VAR_1->type == 2); assert(!(VAR_11 % book->ndimentions)); if (VAR_1->type == 0) { for (VAR_10 = 0; VAR_10 < VAR_11; VAR_10 += book->ndimentions) { float *VAR_22 = put_vector(book, VAR_2, &VAR_21[VAR_10]); int VAR_23; for (VAR_23 = 0; VAR_23 < book->ndimentions; VAR_23++) VAR_21[VAR_10 + VAR_23] -= VAR_22[VAR_23]; } } else { int VAR_24 = VAR_1->begin + VAR_9 * VAR_11, VAR_24, VAR_25; VAR_24 = (VAR_24 % VAR_5) * VAR_4; VAR_25 =  VAR_24 / VAR_5; VAR_24  = VAR_5 * VAR_4; for (VAR_10 = 0; VAR_10 < VAR_11; VAR_10 += book->ndimentions) { int VAR_26, VAR_27 = VAR_24, VAR_28 = VAR_25; float VAR_29[MAX_CODEBOOK_DIM], *pv = VAR_29; for (VAR_26 = book->ndimentions; VAR_26--; ) { *pv++ = VAR_3[VAR_27 + VAR_28]; if ((VAR_27 += VAR_4) == VAR_24) { VAR_27 = 0; VAR_28++; } } pv = put_vector(book, VAR_2, VAR_29); for (VAR_26 = book->ndimentions; VAR_26--; ) { VAR_3[VAR_24 + VAR_25] -= *pv++; if ((VAR_24 += VAR_4) == VAR_24) { VAR_24 = 0; VAR_25++; } } } } } } } } }