void ff_aac_search_for_ltp(AACEncContext *s, SingleChannelElement *sce,

                           int common_window)

{

    int w, g, w2, i, start = 0, count = 0;

    int saved_bits = -(15 + FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB));

    float *C34 = &s->scoefs[128*0], *PCD = &s->scoefs[128*1];

    float *PCD34 = &s->scoefs[128*2];

    const int max_ltp = FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB);



    if (sce->ics.window_sequence[0] == EIGHT_SHORT_SEQUENCE) {

        if (sce->ics.ltp.lag) {

            memset(&sce->lcoeffs[0], 0.0f, 3072*sizeof(sce->lcoeffs[0]));

            memset(&sce->ics.ltp, 0, sizeof(LongTermPrediction));

        }

        return;

    }



    if (!sce->ics.ltp.lag)

        return;



    for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {

        start = 0;

        for (g = 0;  g < sce->ics.num_swb; g++) {

            int bits1 = 0, bits2 = 0;

            float dist1 = 0.0f, dist2 = 0.0f;

            if (w*16+g > max_ltp) {

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

                continue;

            }

            for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {

                int bits_tmp1, bits_tmp2;

                FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];

                for (i = 0; i < sce->ics.swb_sizes[g]; i++)

                    PCD[i] = sce->coeffs[start+(w+w2)*128+i] - sce->lcoeffs[start+(w+w2)*128+i];

                abs_pow34_v(C34,  &sce->coeffs[start+(w+w2)*128],  sce->ics.swb_sizes[g]);

                abs_pow34_v(PCD34, PCD, sce->ics.swb_sizes[g]);

                dist1 += quantize_band_cost(s, &sce->coeffs[start+(w+w2)*128], C34, sce->ics.swb_sizes[g],

                                            sce->sf_idx[(w+w2)*16+g], sce->band_type[(w+w2)*16+g],

                                            s->lambda/band->threshold, INFINITY, &bits_tmp1, NULL, 0);

                dist2 += quantize_band_cost(s, PCD, PCD34, sce->ics.swb_sizes[g],

                                            sce->sf_idx[(w+w2)*16+g],

                                            sce->band_type[(w+w2)*16+g],

                                            s->lambda/band->threshold, INFINITY, &bits_tmp2, NULL, 0);

                bits1 += bits_tmp1;

                bits2 += bits_tmp2;

            }

            if (dist2 < dist1 && bits2 < bits1) {

                for (w2 = 0; w2 < sce->ics.group_len[w]; w2++)

                    for (i = 0; i < sce->ics.swb_sizes[g]; i++)

                        sce->coeffs[start+(w+w2)*128+i] -= sce->lcoeffs[start+(w+w2)*128+i];

                sce->ics.ltp.used[w*16+g] = 1;

                saved_bits += bits1 - bits2;

                count++;

            }

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

        }

    }



    sce->ics.ltp.present = !!count && (saved_bits >= 0);

    sce->ics.predictor_present = !!sce->ics.ltp.present;



    /* Reset any marked sfbs */

    if (!sce->ics.ltp.present && !!count) {

        for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {

            start = 0;

            for (g = 0;  g < sce->ics.num_swb; g++) {

                if (sce->ics.ltp.used[w*16+g]) {

                    for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {

                        for (i = 0; i < sce->ics.swb_sizes[g]; i++) {

                            sce->coeffs[start+(w+w2)*128+i] += sce->lcoeffs[start+(w+w2)*128+i];

                        }

                    }

                }

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

            }

        }

    }

}

void ff_aac_search_for_ltp(AACEncContext *s, SingleChannelElement *sce,

                           int common_window)

{

    int w, g, w2, i, start = 0, count = 0;

    int saved_bits = -(15 + FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB));

    float *C34 = &s->scoefs[128*0], *PCD = &s->scoefs[128*1];

    float *PCD34 = &s->scoefs[128*2];

    const int max_ltp = FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB);



    if (sce->ics.window_sequence[0] == EIGHT_SHORT_SEQUENCE) {

        if (sce->ics.ltp.lag) {

            memset(&sce->lcoeffs[0], 0.0f, 3072*sizeof(sce->lcoeffs[0]));

            memset(&sce->ics.ltp, 0, sizeof(LongTermPrediction));

        }

        return;

    }



    if (!sce->ics.ltp.lag)

        return;



    for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {

        start = 0;

        for (g = 0;  g < sce->ics.num_swb; g++) {

            int bits1 = 0, bits2 = 0;

            float dist1 = 0.0f, dist2 = 0.0f;

            if (w*16+g > max_ltp) {

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

                continue;

            }

            for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {

                int bits_tmp1, bits_tmp2;

                FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];

                for (i = 0; i < sce->ics.swb_sizes[g]; i++)

                    PCD[i] = sce->coeffs[start+(w+w2)*128+i] - sce->lcoeffs[start+(w+w2)*128+i];

                abs_pow34_v(C34,  &sce->coeffs[start+(w+w2)*128],  sce->ics.swb_sizes[g]);

                abs_pow34_v(PCD34, PCD, sce->ics.swb_sizes[g]);

                dist1 += quantize_band_cost(s, &sce->coeffs[start+(w+w2)*128], C34, sce->ics.swb_sizes[g],

                                            sce->sf_idx[(w+w2)*16+g], sce->band_type[(w+w2)*16+g],

                                            s->lambda/band->threshold, INFINITY, &bits_tmp1, NULL, 0);

                dist2 += quantize_band_cost(s, PCD, PCD34, sce->ics.swb_sizes[g],

                                            sce->sf_idx[(w+w2)*16+g],

                                            sce->band_type[(w+w2)*16+g],

                                            s->lambda/band->threshold, INFINITY, &bits_tmp2, NULL, 0);

                bits1 += bits_tmp1;

                bits2 += bits_tmp2;

            }

            if (dist2 < dist1 && bits2 < bits1) {

                for (w2 = 0; w2 < sce->ics.group_len[w]; w2++)

                    for (i = 0; i < sce->ics.swb_sizes[g]; i++)

                        sce->coeffs[start+(w+w2)*128+i] -= sce->lcoeffs[start+(w+w2)*128+i];

                sce->ics.ltp.used[w*16+g] = 1;

                saved_bits += bits1 - bits2;

                count++;

            }

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

        }

    }



    sce->ics.ltp.present = !!count && (saved_bits >= 0);

    sce->ics.predictor_present = !!sce->ics.ltp.present;



    

    if (!sce->ics.ltp.present && !!count) {

        for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {

            start = 0;

            for (g = 0;  g < sce->ics.num_swb; g++) {

                if (sce->ics.ltp.used[w*16+g]) {

                    for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {

                        for (i = 0; i < sce->ics.swb_sizes[g]; i++) {

                            sce->coeffs[start+(w+w2)*128+i] += sce->lcoeffs[start+(w+w2)*128+i];

                        }

                    }

                }

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

            }

        }

    }

}

            memset(&sce->lcoeffs[0], 0.0f, 3072*sizeof(sce->lcoeffs[0]));
void FUNC_0(AACEncContext *VAR_0, SingleChannelElement *VAR_1,

                           int VAR_2)

{

    int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7 = 0, VAR_8 = 0;

    int VAR_9 = -(15 + FFMIN(VAR_1->ics.max_sfb, MAX_LTP_LONG_SFB));

    float *VAR_10 = &VAR_0->scoefs[128*0], *VAR_11 = &VAR_0->scoefs[128*1];

    float *VAR_12 = &VAR_0->scoefs[128*2];

    const int VAR_13 = FFMIN(VAR_1->ics.max_sfb, MAX_LTP_LONG_SFB);



    if (VAR_1->ics.window_sequence[0] == EIGHT_SHORT_SEQUENCE) {

        if (VAR_1->ics.ltp.lag) {

            memset(&VAR_1->lcoeffs[0], 0.0f, 3072*sizeof(VAR_1->lcoeffs[0]));

            memset(&VAR_1->ics.ltp, 0, sizeof(LongTermPrediction));

        }

        return;

    }



    if (!VAR_1->ics.ltp.lag)

        return;



    for (VAR_3 = 0; VAR_3 < VAR_1->ics.num_windows; VAR_3 += VAR_1->ics.group_len[VAR_3]) {

        VAR_7 = 0;

        for (VAR_4 = 0;  VAR_4 < VAR_1->ics.num_swb; VAR_4++) {

            int bits1 = 0, bits2 = 0;

            float dist1 = 0.0f, dist2 = 0.0f;

            if (VAR_3*16+VAR_4 > VAR_13) {

                VAR_7 += VAR_1->ics.swb_sizes[VAR_4];

                continue;

            }

            for (VAR_5 = 0; VAR_5 < VAR_1->ics.group_len[VAR_3]; VAR_5++) {

                int bits_tmp1, bits_tmp2;

                FFPsyBand *band = &VAR_0->psy.ch[VAR_0->cur_channel].psy_bands[(VAR_3+VAR_5)*16+VAR_4];

                for (VAR_6 = 0; VAR_6 < VAR_1->ics.swb_sizes[VAR_4]; VAR_6++)

                    VAR_11[VAR_6] = VAR_1->coeffs[VAR_7+(VAR_3+VAR_5)*128+VAR_6] - VAR_1->lcoeffs[VAR_7+(VAR_3+VAR_5)*128+VAR_6];

                abs_pow34_v(VAR_10,  &VAR_1->coeffs[VAR_7+(VAR_3+VAR_5)*128],  VAR_1->ics.swb_sizes[VAR_4]);

                abs_pow34_v(VAR_12, VAR_11, VAR_1->ics.swb_sizes[VAR_4]);

                dist1 += quantize_band_cost(VAR_0, &VAR_1->coeffs[VAR_7+(VAR_3+VAR_5)*128], VAR_10, VAR_1->ics.swb_sizes[VAR_4],

                                            VAR_1->sf_idx[(VAR_3+VAR_5)*16+VAR_4], VAR_1->band_type[(VAR_3+VAR_5)*16+VAR_4],

                                            VAR_0->lambda/band->threshold, INFINITY, &bits_tmp1, NULL, 0);

                dist2 += quantize_band_cost(VAR_0, VAR_11, VAR_12, VAR_1->ics.swb_sizes[VAR_4],

                                            VAR_1->sf_idx[(VAR_3+VAR_5)*16+VAR_4],

                                            VAR_1->band_type[(VAR_3+VAR_5)*16+VAR_4],

                                            VAR_0->lambda/band->threshold, INFINITY, &bits_tmp2, NULL, 0);

                bits1 += bits_tmp1;

                bits2 += bits_tmp2;

            }

            if (dist2 < dist1 && bits2 < bits1) {

                for (VAR_5 = 0; VAR_5 < VAR_1->ics.group_len[VAR_3]; VAR_5++)

                    for (VAR_6 = 0; VAR_6 < VAR_1->ics.swb_sizes[VAR_4]; VAR_6++)

                        VAR_1->coeffs[VAR_7+(VAR_3+VAR_5)*128+VAR_6] -= VAR_1->lcoeffs[VAR_7+(VAR_3+VAR_5)*128+VAR_6];

                VAR_1->ics.ltp.used[VAR_3*16+VAR_4] = 1;

                VAR_9 += bits1 - bits2;

                VAR_8++;

            }

            VAR_7 += VAR_1->ics.swb_sizes[VAR_4];

        }

    }



    VAR_1->ics.ltp.present = !!VAR_8 && (VAR_9 >= 0);

    VAR_1->ics.predictor_present = !!VAR_1->ics.ltp.present;



    

    if (!VAR_1->ics.ltp.present && !!VAR_8) {

        for (VAR_3 = 0; VAR_3 < VAR_1->ics.num_windows; VAR_3 += VAR_1->ics.group_len[VAR_3]) {

            VAR_7 = 0;

            for (VAR_4 = 0;  VAR_4 < VAR_1->ics.num_swb; VAR_4++) {

                if (VAR_1->ics.ltp.used[VAR_3*16+VAR_4]) {

                    for (VAR_5 = 0; VAR_5 < VAR_1->ics.group_len[VAR_3]; VAR_5++) {

                        for (VAR_6 = 0; VAR_6 < VAR_1->ics.swb_sizes[VAR_4]; VAR_6++) {

                            VAR_1->coeffs[VAR_7+(VAR_3+VAR_5)*128+VAR_6] += VAR_1->lcoeffs[VAR_7+(VAR_3+VAR_5)*128+VAR_6];

                        }

                    }

                }

                VAR_7 += VAR_1->ics.swb_sizes[VAR_4];

            }

        }

    }

}

void FUNC_0(AACEncContext *VAR_0, SingleChannelElement *VAR_1,
int VAR_2)
{ int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7 = 0, VAR_8 = 0; int VAR_9 = -(15 + FFMIN(VAR_1->ics.max_sfb, MAX_LTP_LONG_SFB)); float *VAR_10 = &VAR_0->scoefs[128*0], *VAR_11 = &VAR_0->scoefs[128*1]; float *VAR_12 = &VAR_0->scoefs[128*2]; const int VAR_13 = FFMIN(VAR_1->ics.max_sfb, MAX_LTP_LONG_SFB); if (VAR_1->ics.window_sequence[0] == EIGHT_SHORT_SEQUENCE) { if (VAR_1->ics.ltp.lag) { memset(&VAR_1->lcoeffs[0], 0.0f, 3072*sizeof(VAR_1->lcoeffs[0])); memset(&VAR_1->ics.ltp, 0, sizeof(LongTermPrediction)); } return; } if (!VAR_1->ics.ltp.lag)
return; for (VAR_3 = 0; VAR_3 < VAR_1->ics.num_windows; VAR_3 += VAR_1->ics.group_len[VAR_3]) { VAR_7 = 0; for (VAR_4 = 0;  VAR_4 < VAR_1->ics.num_swb; VAR_4++) { int bits1 = 0, bits2 = 0; float dist1 = 0.0f, dist2 = 0.0f; if (VAR_3*16+VAR_4 > VAR_13) { VAR_7 += VAR_1->ics.swb_sizes[VAR_4]; continue; } for (VAR_5 = 0; VAR_5 < VAR_1->ics.group_len[VAR_3]; VAR_5++) { int bits_tmp1, bits_tmp2; FFPsyBand *band = &VAR_0->psy.ch[VAR_0->cur_channel].psy_bands[(VAR_3+VAR_5)*16+VAR_4]; for (VAR_6 = 0; VAR_6 < VAR_1->ics.swb_sizes[VAR_4]; VAR_6++) VAR_11[VAR_6] = VAR_1->coeffs[VAR_7+(VAR_3+VAR_5)*128+VAR_6] - VAR_1->lcoeffs[VAR_7+(VAR_3+VAR_5)*128+VAR_6]; abs_pow34_v(VAR_10,  &VAR_1->coeffs[VAR_7+(VAR_3+VAR_5)*128],  VAR_1->ics.swb_sizes[VAR_4]); abs_pow34_v(VAR_12, VAR_11, VAR_1->ics.swb_sizes[VAR_4]); dist1 += quantize_band_cost(VAR_0, &VAR_1->coeffs[VAR_7+(VAR_3+VAR_5)*128], VAR_10, VAR_1->ics.swb_sizes[VAR_4],
VAR_1->sf_idx[(VAR_3+VAR_5)*16+VAR_4], VAR_1->band_type[(VAR_3+VAR_5)*16+VAR_4],
VAR_0->lambda/band->threshold, INFINITY, &bits_tmp1, NULL, 0); dist2 += quantize_band_cost(VAR_0, VAR_11, VAR_12, VAR_1->ics.swb_sizes[VAR_4],
VAR_1->sf_idx[(VAR_3+VAR_5)*16+VAR_4],
VAR_1->band_type[(VAR_3+VAR_5)*16+VAR_4],
VAR_0->lambda/band->threshold, INFINITY, &bits_tmp2, NULL, 0); bits1 += bits_tmp1; bits2 += bits_tmp2; } if (dist2 < dist1 && bits2 < bits1) { for (VAR_5 = 0; VAR_5 < VAR_1->ics.group_len[VAR_3]; VAR_5++) for (VAR_6 = 0; VAR_6 < VAR_1->ics.swb_sizes[VAR_4]; VAR_6++) VAR_1->coeffs[VAR_7+(VAR_3+VAR_5)*128+VAR_6] -= VAR_1->lcoeffs[VAR_7+(VAR_3+VAR_5)*128+VAR_6]; VAR_1->ics.ltp.used[VAR_3*16+VAR_4] = 1; VAR_9 += bits1 - bits2; VAR_8++; } VAR_7 += VAR_1->ics.swb_sizes[VAR_4]; } } VAR_1->ics.ltp.present = !!VAR_8 && (VAR_9 >= 0); VAR_1->ics.predictor_present = !!VAR_1->ics.ltp.present; if (!VAR_1->ics.ltp.present && !!VAR_8) { for (VAR_3 = 0; VAR_3 < VAR_1->ics.num_windows; VAR_3 += VAR_1->ics.group_len[VAR_3]) { VAR_7 = 0; for (VAR_4 = 0;  VAR_4 < VAR_1->ics.num_swb; VAR_4++) { if (VAR_1->ics.ltp.used[VAR_3*16+VAR_4]) { for (VAR_5 = 0; VAR_5 < VAR_1->ics.group_len[VAR_3]; VAR_5++) { for (VAR_6 = 0; VAR_6 < VAR_1->ics.swb_sizes[VAR_4]; VAR_6++) { VAR_1->coeffs[VAR_7+(VAR_3+VAR_5)*128+VAR_6] += VAR_1->lcoeffs[VAR_7+(VAR_3+VAR_5)*128+VAR_6]; } } } VAR_7 += VAR_1->ics.swb_sizes[VAR_4]; } } } }