static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce,

                                  int win, int group_len, const float lambda)

{

    BandCodingPath path[120][12];

    int w, swb, cb, start, size;

    int i, j;

    const int max_sfb  = sce->ics.max_sfb;

    const int run_bits = sce->ics.num_windows == 1 ? 5 : 3;

    const int run_esc  = (1 << run_bits) - 1;

    int idx, ppos, count;

    int stackrun[120], stackcb[120], stack_len;

    float next_minbits = INFINITY;

    int next_mincb = 0;



    abs_pow34_v(s->scoefs, sce->coeffs, 1024);

    start = win*128;

    for (cb = 0; cb < 12; cb++) {

        path[0][cb].cost     = run_bits+4;

        path[0][cb].prev_idx = -1;

        path[0][cb].run      = 0;

    }

    for (swb = 0; swb < max_sfb; swb++) {

        size = sce->ics.swb_sizes[swb];

        if (sce->zeroes[win*16 + swb]) {

            float cost_stay_here = path[swb][0].cost;

            float cost_get_here  = next_minbits + run_bits + 4;

            if (   run_value_bits[sce->ics.num_windows == 8][path[swb][0].run]

                != run_value_bits[sce->ics.num_windows == 8][path[swb][0].run+1])

                cost_stay_here += run_bits;

            if (cost_get_here < cost_stay_here) {

                path[swb+1][0].prev_idx = next_mincb;

                path[swb+1][0].cost     = cost_get_here;

                path[swb+1][0].run      = 1;

            } else {

                path[swb+1][0].prev_idx = 0;

                path[swb+1][0].cost     = cost_stay_here;

                path[swb+1][0].run      = path[swb][0].run + 1;

            }

            next_minbits = path[swb+1][0].cost;

            next_mincb = 0;

            for (cb = 1; cb < 12; cb++) {

                path[swb+1][cb].cost = 61450;

                path[swb+1][cb].prev_idx = -1;

                path[swb+1][cb].run = 0;

            }

        } else {

            float minbits = next_minbits;

            int mincb = next_mincb;

            int startcb = sce->band_type[win*16+swb];

            next_minbits = INFINITY;

            next_mincb = 0;

            for (cb = 0; cb < startcb; cb++) {

                path[swb+1][cb].cost = 61450;

                path[swb+1][cb].prev_idx = -1;

                path[swb+1][cb].run = 0;

            }

            for (cb = startcb; cb < 12; cb++) {

                float cost_stay_here, cost_get_here;

                float bits = 0.0f;

                for (w = 0; w < group_len; w++) {

                    bits += quantize_band_cost(s, sce->coeffs + start + w*128,

                                               s->scoefs + start + w*128, size,

                                               sce->sf_idx[(win+w)*16+swb], cb,

                                               0, INFINITY, NULL);

                }

                cost_stay_here = path[swb][cb].cost + bits;

                cost_get_here  = minbits            + bits + run_bits + 4;

                if (   run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run]

                    != run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run+1])

                    cost_stay_here += run_bits;

                if (cost_get_here < cost_stay_here) {

                    path[swb+1][cb].prev_idx = mincb;

                    path[swb+1][cb].cost     = cost_get_here;

                    path[swb+1][cb].run      = 1;

                } else {

                    path[swb+1][cb].prev_idx = cb;

                    path[swb+1][cb].cost     = cost_stay_here;

                    path[swb+1][cb].run      = path[swb][cb].run + 1;

                }

                if (path[swb+1][cb].cost < next_minbits) {

                    next_minbits = path[swb+1][cb].cost;

                    next_mincb = cb;

                }

            }

        }

        start += sce->ics.swb_sizes[swb];

    }



    //convert resulting path from backward-linked list

    stack_len = 0;

    idx       = 0;

    for (cb = 1; cb < 12; cb++)

        if (path[max_sfb][cb].cost < path[max_sfb][idx].cost)

            idx = cb;

    ppos = max_sfb;

    while (ppos > 0) {

        av_assert1(idx >= 0);

        cb = idx;

        stackrun[stack_len] = path[ppos][cb].run;

        stackcb [stack_len] = cb;

        idx = path[ppos-path[ppos][cb].run+1][cb].prev_idx;

        ppos -= path[ppos][cb].run;

        stack_len++;

    }

    //perform actual band info encoding

    start = 0;

    for (i = stack_len - 1; i >= 0; i--) {

        put_bits(&s->pb, 4, stackcb[i]);

        count = stackrun[i];

        memset(sce->zeroes + win*16 + start, !stackcb[i], count);

        //XXX: memset when band_type is also uint8_t

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

            sce->band_type[win*16 + start] =  stackcb[i];

            start++;

        }

        while (count >= run_esc) {

            put_bits(&s->pb, run_bits, run_esc);

            count -= run_esc;

        }

        put_bits(&s->pb, run_bits, count);

    }

}

static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce,

                                  int win, int group_len, const float lambda)

{

    BandCodingPath path[120][12];

    int w, swb, cb, start, size;

    int i, j;

    const int max_sfb  = sce->ics.max_sfb;

    const int run_bits = sce->ics.num_windows == 1 ? 5 : 3;

    const int run_esc  = (1 << run_bits) - 1;

    int idx, ppos, count;

    int stackrun[120], stackcb[120], stack_len;

    float next_minbits = INFINITY;

    int next_mincb = 0;



    abs_pow34_v(s->scoefs, sce->coeffs, 1024);

    start = win*128;

    for (cb = 0; cb < 12; cb++) {

        path[0][cb].cost     = run_bits+4;

        path[0][cb].prev_idx = -1;

        path[0][cb].run      = 0;

    }

    for (swb = 0; swb < max_sfb; swb++) {

        size = sce->ics.swb_sizes[swb];

        if (sce->zeroes[win*16 + swb]) {

            float cost_stay_here = path[swb][0].cost;

            float cost_get_here  = next_minbits + run_bits + 4;

            if (   run_value_bits[sce->ics.num_windows == 8][path[swb][0].run]

                != run_value_bits[sce->ics.num_windows == 8][path[swb][0].run+1])

                cost_stay_here += run_bits;

            if (cost_get_here < cost_stay_here) {

                path[swb+1][0].prev_idx = next_mincb;

                path[swb+1][0].cost     = cost_get_here;

                path[swb+1][0].run      = 1;

            } else {

                path[swb+1][0].prev_idx = 0;

                path[swb+1][0].cost     = cost_stay_here;

                path[swb+1][0].run      = path[swb][0].run + 1;

            }

            next_minbits = path[swb+1][0].cost;

            next_mincb = 0;

            for (cb = 1; cb < 12; cb++) {

                path[swb+1][cb].cost = 61450;

                path[swb+1][cb].prev_idx = -1;

                path[swb+1][cb].run = 0;

            }

        } else {

            float minbits = next_minbits;

            int mincb = next_mincb;

            int startcb = sce->band_type[win*16+swb];

            next_minbits = INFINITY;

            next_mincb = 0;

            for (cb = 0; cb < startcb; cb++) {

                path[swb+1][cb].cost = 61450;

                path[swb+1][cb].prev_idx = -1;

                path[swb+1][cb].run = 0;

            }

            for (cb = startcb; cb < 12; cb++) {

                float cost_stay_here, cost_get_here;

                float bits = 0.0f;

                for (w = 0; w < group_len; w++) {

                    bits += quantize_band_cost(s, sce->coeffs + start + w*128,

                                               s->scoefs + start + w*128, size,

                                               sce->sf_idx[(win+w)*16+swb], cb,

                                               0, INFINITY, NULL);

                }

                cost_stay_here = path[swb][cb].cost + bits;

                cost_get_here  = minbits            + bits + run_bits + 4;

                if (   run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run]

                    != run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run+1])

                    cost_stay_here += run_bits;

                if (cost_get_here < cost_stay_here) {

                    path[swb+1][cb].prev_idx = mincb;

                    path[swb+1][cb].cost     = cost_get_here;

                    path[swb+1][cb].run      = 1;

                } else {

                    path[swb+1][cb].prev_idx = cb;

                    path[swb+1][cb].cost     = cost_stay_here;

                    path[swb+1][cb].run      = path[swb][cb].run + 1;

                }

                if (path[swb+1][cb].cost < next_minbits) {

                    next_minbits = path[swb+1][cb].cost;

                    next_mincb = cb;

                }

            }

        }

        start += sce->ics.swb_sizes[swb];

    }



    

    stack_len = 0;

    idx       = 0;

    for (cb = 1; cb < 12; cb++)

        if (path[max_sfb][cb].cost < path[max_sfb][idx].cost)

            idx = cb;

    ppos = max_sfb;

    while (ppos > 0) {

        av_assert1(idx >= 0);

        cb = idx;

        stackrun[stack_len] = path[ppos][cb].run;

        stackcb [stack_len] = cb;

        idx = path[ppos-path[ppos][cb].run+1][cb].prev_idx;

        ppos -= path[ppos][cb].run;

        stack_len++;

    }

    

    start = 0;

    for (i = stack_len - 1; i >= 0; i--) {

        put_bits(&s->pb, 4, stackcb[i]);

        count = stackrun[i];

        memset(sce->zeroes + win*16 + start, !stackcb[i], count);

        

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

            sce->band_type[win*16 + start] =  stackcb[i];

            start++;

        }

        while (count >= run_esc) {

            put_bits(&s->pb, run_bits, run_esc);

            count -= run_esc;

        }

        put_bits(&s->pb, run_bits, count);

    }

}

    BandCodingPath path[120][12];     for (cb = 0; cb < 12; cb++) {     for (cb = 1; cb < 12; cb++)         put_bits(&s->pb, 4, stackcb[i]);         memset(sce->zeroes + win*16 + start, !stackcb[i], count);             sce->band_type[win*16 + start] =  stackcb[i];     BandCodingPath path[120][12];     for (cb = 0; cb < 12; cb++) {             for (cb = 1; cb < 12; cb++) {             for (cb = startcb; cb < 12; cb++) {                                                sce->sf_idx[(win+w)*16+swb], cb,     for (cb = 1; cb < 12; cb++)         put_bits(&s->pb, 4, stackcb[i]);         memset(sce->zeroes + win*16 + start, !stackcb[i], count);             sce->band_type[win*16 + start] =  stackcb[i];
static void FUNC_0(AACEncContext *VAR_0, SingleChannelElement *VAR_1,

                                  int VAR_2, int VAR_3, const float VAR_4)

{

    BandCodingPath path[120][12];

    int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9;

    int VAR_10, VAR_11;

    const int VAR_12  = VAR_1->ics.VAR_12;

    const int VAR_13 = VAR_1->ics.num_windows == 1 ? 5 : 3;

    const int VAR_14  = (1 << VAR_13) - 1;

    int VAR_15, VAR_16, VAR_17;

    int VAR_18[120], VAR_19[120], VAR_20;

    float VAR_21 = INFINITY;

    int VAR_22 = 0;



    abs_pow34_v(VAR_0->scoefs, VAR_1->coeffs, 1024);

    VAR_8 = VAR_2*128;

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

        path[0][VAR_7].cost     = VAR_13+4;

        path[0][VAR_7].prev_idx = -1;

        path[0][VAR_7].run      = 0;

    }

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

        VAR_9 = VAR_1->ics.swb_sizes[VAR_6];

        if (VAR_1->zeroes[VAR_2*16 + VAR_6]) {

            float VAR_28 = path[VAR_6][0].cost;

            float VAR_28  = VAR_21 + VAR_13 + 4;

            if (   run_value_bits[VAR_1->ics.num_windows == 8][path[VAR_6][0].run]

                != run_value_bits[VAR_1->ics.num_windows == 8][path[VAR_6][0].run+1])

                VAR_28 += VAR_13;

            if (VAR_28 < VAR_28) {

                path[VAR_6+1][0].prev_idx = VAR_22;

                path[VAR_6+1][0].cost     = VAR_28;

                path[VAR_6+1][0].run      = 1;

            } else {

                path[VAR_6+1][0].prev_idx = 0;

                path[VAR_6+1][0].cost     = VAR_28;

                path[VAR_6+1][0].run      = path[VAR_6][0].run + 1;

            }

            VAR_21 = path[VAR_6+1][0].cost;

            VAR_22 = 0;

            for (VAR_7 = 1; VAR_7 < 12; VAR_7++) {

                path[VAR_6+1][VAR_7].cost = 61450;

                path[VAR_6+1][VAR_7].prev_idx = -1;

                path[VAR_6+1][VAR_7].run = 0;

            }

        } else {

            float VAR_25 = VAR_21;

            int VAR_26 = VAR_22;

            int VAR_27 = VAR_1->band_type[VAR_2*16+VAR_6];

            VAR_21 = INFINITY;

            VAR_22 = 0;

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

                path[VAR_6+1][VAR_7].cost = 61450;

                path[VAR_6+1][VAR_7].prev_idx = -1;

                path[VAR_6+1][VAR_7].run = 0;

            }

            for (VAR_7 = VAR_27; VAR_7 < 12; VAR_7++) {

                float VAR_28, VAR_28;

                float VAR_28 = 0.0f;

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

                    VAR_28 += quantize_band_cost(VAR_0, VAR_1->coeffs + VAR_8 + VAR_5*128,

                                               VAR_0->scoefs + VAR_8 + VAR_5*128, VAR_9,

                                               VAR_1->sf_idx[(VAR_2+VAR_5)*16+VAR_6], VAR_7,

                                               0, INFINITY, NULL);

                }

                VAR_28 = path[VAR_6][VAR_7].cost + VAR_28;

                VAR_28  = VAR_25            + VAR_28 + VAR_13 + 4;

                if (   run_value_bits[VAR_1->ics.num_windows == 8][path[VAR_6][VAR_7].run]

                    != run_value_bits[VAR_1->ics.num_windows == 8][path[VAR_6][VAR_7].run+1])

                    VAR_28 += VAR_13;

                if (VAR_28 < VAR_28) {

                    path[VAR_6+1][VAR_7].prev_idx = VAR_26;

                    path[VAR_6+1][VAR_7].cost     = VAR_28;

                    path[VAR_6+1][VAR_7].run      = 1;

                } else {

                    path[VAR_6+1][VAR_7].prev_idx = VAR_7;

                    path[VAR_6+1][VAR_7].cost     = VAR_28;

                    path[VAR_6+1][VAR_7].run      = path[VAR_6][VAR_7].run + 1;

                }

                if (path[VAR_6+1][VAR_7].cost < VAR_21) {

                    VAR_21 = path[VAR_6+1][VAR_7].cost;

                    VAR_22 = VAR_7;

                }

            }

        }

        VAR_8 += VAR_1->ics.swb_sizes[VAR_6];

    }



    

    VAR_20 = 0;

    VAR_15       = 0;

    for (VAR_7 = 1; VAR_7 < 12; VAR_7++)

        if (path[VAR_12][VAR_7].cost < path[VAR_12][VAR_15].cost)

            VAR_15 = VAR_7;

    VAR_16 = VAR_12;

    while (VAR_16 > 0) {

        av_assert1(VAR_15 >= 0);

        VAR_7 = VAR_15;

        VAR_18[VAR_20] = path[VAR_16][VAR_7].run;

        VAR_19 [VAR_20] = VAR_7;

        VAR_15 = path[VAR_16-path[VAR_16][VAR_7].run+1][VAR_7].prev_idx;

        VAR_16 -= path[VAR_16][VAR_7].run;

        VAR_20++;

    }

    

    VAR_8 = 0;

    for (VAR_10 = VAR_20 - 1; VAR_10 >= 0; VAR_10--) {

        put_bits(&VAR_0->pb, 4, VAR_19[VAR_10]);

        VAR_17 = VAR_18[VAR_10];

        memset(VAR_1->zeroes + VAR_2*16 + VAR_8, !VAR_19[VAR_10], VAR_17);

        

        for (VAR_11 = 0; VAR_11 < VAR_17; VAR_11++) {

            VAR_1->band_type[VAR_2*16 + VAR_8] =  VAR_19[VAR_10];

            VAR_8++;

        }

        while (VAR_17 >= VAR_14) {

            put_bits(&VAR_0->pb, VAR_13, VAR_14);

            VAR_17 -= VAR_14;

        }

        put_bits(&VAR_0->pb, VAR_13, VAR_17);

    }

}

static void FUNC_0(AACEncContext *VAR_0, SingleChannelElement *VAR_1,
int VAR_2, int VAR_3, const float VAR_4)
{ BandCodingPath path[120][12]; int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9; int VAR_10, VAR_11; const int VAR_12  = VAR_1->ics.VAR_12; const int VAR_13 = VAR_1->ics.num_windows == 1 ? 5 : 3; const int VAR_14  = (1 << VAR_13) - 1; int VAR_15, VAR_16, VAR_17; int VAR_18[120], VAR_19[120], VAR_20; float VAR_21 = INFINITY; int VAR_22 = 0; abs_pow34_v(VAR_0->scoefs, VAR_1->coeffs, 1024); VAR_8 = VAR_2*128; for (VAR_7 = 0; VAR_7 < 12; VAR_7++) { path[0][VAR_7].cost     = VAR_13+4; path[0][VAR_7].prev_idx = -1; path[0][VAR_7].run      = 0; } for (VAR_6 = 0; VAR_6 < VAR_12; VAR_6++) { VAR_9 = VAR_1->ics.swb_sizes[VAR_6]; if (VAR_1->zeroes[VAR_2*16 + VAR_6]) { float VAR_28 = path[VAR_6][0].cost; float VAR_28  = VAR_21 + VAR_13 + 4; if (   run_value_bits[VAR_1->ics.num_windows == 8][path[VAR_6][0].run]
!= run_value_bits[VAR_1->ics.num_windows == 8][path[VAR_6][0].run+1])
VAR_28 += VAR_13; if (VAR_28 < VAR_28) { path[VAR_6+1][0].prev_idx = VAR_22; path[VAR_6+1][0].cost     = VAR_28; path[VAR_6+1][0].run      = 1; } else { path[VAR_6+1][0].prev_idx = 0; path[VAR_6+1][0].cost     = VAR_28; path[VAR_6+1][0].run      = path[VAR_6][0].run + 1; } VAR_21 = path[VAR_6+1][0].cost; VAR_22 = 0; for (VAR_7 = 1; VAR_7 < 12; VAR_7++) { path[VAR_6+1][VAR_7].cost = 61450; path[VAR_6+1][VAR_7].prev_idx = -1; path[VAR_6+1][VAR_7].run = 0; } } else { float VAR_25 = VAR_21; int VAR_26 = VAR_22; int VAR_27 = VAR_1->band_type[VAR_2*16+VAR_6]; VAR_21 = INFINITY; VAR_22 = 0; for (VAR_7 = 0; VAR_7 < VAR_27; VAR_7++) { path[VAR_6+1][VAR_7].cost = 61450; path[VAR_6+1][VAR_7].prev_idx = -1; path[VAR_6+1][VAR_7].run = 0; } for (VAR_7 = VAR_27; VAR_7 < 12; VAR_7++) { float VAR_28, VAR_28; float VAR_28 = 0.0f; for (VAR_5 = 0; VAR_5 < VAR_3; VAR_5++) { VAR_28 += quantize_band_cost(VAR_0, VAR_1->coeffs + VAR_8 + VAR_5*128,
VAR_0->scoefs + VAR_8 + VAR_5*128, VAR_9,
VAR_1->sf_idx[(VAR_2+VAR_5)*16+VAR_6], VAR_7,
0, INFINITY, NULL); } VAR_28 = path[VAR_6][VAR_7].cost + VAR_28; VAR_28  = VAR_25            + VAR_28 + VAR_13 + 4; if (   run_value_bits[VAR_1->ics.num_windows == 8][path[VAR_6][VAR_7].run]
!= run_value_bits[VAR_1->ics.num_windows == 8][path[VAR_6][VAR_7].run+1])
VAR_28 += VAR_13; if (VAR_28 < VAR_28) { path[VAR_6+1][VAR_7].prev_idx = VAR_26; path[VAR_6+1][VAR_7].cost     = VAR_28; path[VAR_6+1][VAR_7].run      = 1; } else { path[VAR_6+1][VAR_7].prev_idx = VAR_7; path[VAR_6+1][VAR_7].cost     = VAR_28; path[VAR_6+1][VAR_7].run      = path[VAR_6][VAR_7].run + 1; } if (path[VAR_6+1][VAR_7].cost < VAR_21) { VAR_21 = path[VAR_6+1][VAR_7].cost; VAR_22 = VAR_7; } } } VAR_8 += VAR_1->ics.swb_sizes[VAR_6]; } VAR_20 = 0; VAR_15       = 0; for (VAR_7 = 1; VAR_7 < 12; VAR_7++) if (path[VAR_12][VAR_7].cost < path[VAR_12][VAR_15].cost)
VAR_15 = VAR_7; VAR_16 = VAR_12; while (VAR_16 > 0) { av_assert1(VAR_15 >= 0); VAR_7 = VAR_15; VAR_18[VAR_20] = path[VAR_16][VAR_7].run; VAR_19 [VAR_20] = VAR_7; VAR_15 = path[VAR_16-path[VAR_16][VAR_7].run+1][VAR_7].prev_idx; VAR_16 -= path[VAR_16][VAR_7].run; VAR_20++; } VAR_8 = 0; for (VAR_10 = VAR_20 - 1; VAR_10 >= 0; VAR_10--) { put_bits(&VAR_0->pb, 4, VAR_19[VAR_10]); VAR_17 = VAR_18[VAR_10]; memset(VAR_1->zeroes + VAR_2*16 + VAR_8, !VAR_19[VAR_10], VAR_17); for (VAR_11 = 0; VAR_11 < VAR_17; VAR_11++) { VAR_1->band_type[VAR_2*16 + VAR_8] =  VAR_19[VAR_10]; VAR_8++; } while (VAR_17 >= VAR_14) { put_bits(&VAR_0->pb, VAR_13, VAR_14); VAR_17 -= VAR_14; } put_bits(&VAR_0->pb, VAR_13, VAR_17); } }