static int16_t long_term_filter(DSPContext *dsp, int pitch_delay_int,

                                const int16_t* residual, int16_t *residual_filt,

                                int subframe_size)

{

    int i, k, tmp, tmp2;

    int sum;

    int L_temp0;

    int L_temp1;

    int64_t L64_temp0;

    int64_t L64_temp1;

    int16_t shift;

    int corr_int_num, corr_int_den;



    int ener;

    int16_t sh_ener;



    int16_t gain_num,gain_den; //selected signal's gain numerator and denominator

    int16_t sh_gain_num, sh_gain_den;

    int gain_num_square;



    int16_t gain_long_num,gain_long_den; //filtered through long interpolation filter signal's gain numerator and denominator

    int16_t sh_gain_long_num, sh_gain_long_den;



    int16_t best_delay_int, best_delay_frac;



    int16_t delayed_signal_offset;

    int lt_filt_factor_a, lt_filt_factor_b;



    int16_t * selected_signal;

    const int16_t * selected_signal_const; //Necessary to avoid compiler warning



    int16_t sig_scaled[SUBFRAME_SIZE + RES_PREV_DATA_SIZE];

    int16_t delayed_signal[ANALYZED_FRAC_DELAYS][SUBFRAME_SIZE+1];

    int corr_den[ANALYZED_FRAC_DELAYS][2];



    tmp = 0;

    for(i=0; i<subframe_size + RES_PREV_DATA_SIZE; i++)

        tmp |= FFABS(residual[i]);



    if(!tmp)

        shift = 3;

    else

        shift = av_log2(tmp) - 11;



    if (shift > 0)

        for (i = 0; i < subframe_size + RES_PREV_DATA_SIZE; i++)

            sig_scaled[i] = residual[i] >> shift;

    else

        for (i = 0; i < subframe_size + RES_PREV_DATA_SIZE; i++)

            sig_scaled[i] = residual[i] << -shift;



    /* Start of best delay searching code */

    gain_num = 0;



    ener = dsp->scalarproduct_int16(sig_scaled + RES_PREV_DATA_SIZE,

                                    sig_scaled + RES_PREV_DATA_SIZE,

                                    subframe_size);

    if (ener) {

        sh_ener = FFMAX(av_log2(ener) - 14, 0);

        ener >>= sh_ener;

        /* Search for best pitch delay.



                       sum{ r(n) * r(k,n) ] }^2

           R'(k)^2 := -------------------------

                       sum{ r(k,n) * r(k,n) }





           R(T)    :=  sum{ r(n) * r(n-T) ] }





           where

           r(n-T) is integer delayed signal with delay T

           r(k,n) is non-integer delayed signal with integer delay best_delay

           and fractional delay k */



        /* Find integer delay best_delay which maximizes correlation R(T).



           This is also equals to numerator of R'(0),

           since the fine search (second step) is done with 1/8

           precision around best_delay. */

        corr_int_num = 0;

        best_delay_int = pitch_delay_int - 1;

        for (i = pitch_delay_int - 1; i <= pitch_delay_int + 1; i++) {

            sum = dsp->scalarproduct_int16(sig_scaled + RES_PREV_DATA_SIZE,

                                           sig_scaled + RES_PREV_DATA_SIZE - i,

                                           subframe_size);

            if (sum > corr_int_num) {

                corr_int_num = sum;

                best_delay_int = i;

            }

        }

        if (corr_int_num) {

            /* Compute denominator of pseudo-normalized correlation R'(0). */

            corr_int_den = dsp->scalarproduct_int16(sig_scaled - best_delay_int + RES_PREV_DATA_SIZE,

                                                    sig_scaled - best_delay_int + RES_PREV_DATA_SIZE,

                                                    subframe_size);



            /* Compute signals with non-integer delay k (with 1/8 precision),

               where k is in [0;6] range.

               Entire delay is qual to best_delay+(k+1)/8

               This is archieved by applying an interpolation filter of

               legth 33 to source signal. */

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

                ff_acelp_interpolate(&delayed_signal[k][0],

                                     &sig_scaled[RES_PREV_DATA_SIZE - best_delay_int],

                                     ff_g729_interp_filt_short,

                                     ANALYZED_FRAC_DELAYS+1,

                                     8 - k - 1,

                                     SHORT_INT_FILT_LEN,

                                     subframe_size + 1);

            }



            /* Compute denominator of pseudo-normalized correlation R'(k).



                 corr_den[k][0] is square root of R'(k) denominator, for int(T) == int(T0)

                 corr_den[k][1] is square root of R'(k) denominator, for int(T) == int(T0)+1



              Also compute maximum value of above denominators over all k. */

            tmp = corr_int_den;

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

                sum = dsp->scalarproduct_int16(&delayed_signal[k][1],

                                               &delayed_signal[k][1],

                                               subframe_size - 1);

                corr_den[k][0] = sum + delayed_signal[k][0            ] * delayed_signal[k][0            ];

                corr_den[k][1] = sum + delayed_signal[k][subframe_size] * delayed_signal[k][subframe_size];



                tmp = FFMAX3(tmp, corr_den[k][0], corr_den[k][1]);

            }



            sh_gain_den = av_log2(tmp) - 14;

            if (sh_gain_den >= 0) {



                sh_gain_num =  FFMAX(sh_gain_den, sh_ener);

                /* Loop through all k and find delay that maximizes

                   R'(k) correlation.

                   Search is done in [int(T0)-1; intT(0)+1] range

                   with 1/8 precision. */

                delayed_signal_offset = 1;

                best_delay_frac = 0;

                gain_den = corr_int_den >> sh_gain_den;

                gain_num = corr_int_num >> sh_gain_num;

                gain_num_square = gain_num * gain_num;

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

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

                        int16_t gain_num_short, gain_den_short;

                        int gain_num_short_square;

                        /* Compute numerator of pseudo-normalized

                           correlation R'(k). */

                        sum = dsp->scalarproduct_int16(&delayed_signal[k][i],

                                                       sig_scaled + RES_PREV_DATA_SIZE,

                                                       subframe_size);

                        gain_num_short = FFMAX(sum >> sh_gain_num, 0);



                        /*

                                      gain_num_short_square                gain_num_square

                           R'(T)^2 = -----------------------, max R'(T)^2= --------------

                                           den                                 gain_den

                        */

                        gain_num_short_square = gain_num_short * gain_num_short;

                        gain_den_short = corr_den[k][i] >> sh_gain_den;



                        tmp = MULL(gain_num_short_square, gain_den, FRAC_BITS);

                        tmp2 = MULL(gain_num_square, gain_den_short, FRAC_BITS);



                        // R'(T)^2 > max R'(T)^2

                        if (tmp > tmp2) {

                            gain_num = gain_num_short;

                            gain_den = gain_den_short;

                            gain_num_square = gain_num_short_square;

                            delayed_signal_offset = i;

                            best_delay_frac = k + 1;

                        }

                    }

                }



                /*

                       R'(T)^2

                  2 * --------- < 1

                        R(0)

                */

                L64_temp0 =  (int64_t)gain_num_square  << ((sh_gain_num << 1) + 1);

                L64_temp1 = ((int64_t)gain_den * ener) << (sh_gain_den + sh_ener);

                if (L64_temp0 < L64_temp1)

                    gain_num = 0;

            } // if(sh_gain_den >= 0)

        } // if(corr_int_num)

    } // if(ener)

    /* End of best delay searching code  */



    if (!gain_num) {

        memcpy(residual_filt, residual + RES_PREV_DATA_SIZE, subframe_size * sizeof(int16_t));



        /* Long-term prediction gain is less than 3dB. Long-term postfilter is disabled. */

        return 0;

    }

    if (best_delay_frac) {

        /* Recompute delayed signal with an interpolation filter of length 129. */

        ff_acelp_interpolate(residual_filt,

                             &sig_scaled[RES_PREV_DATA_SIZE - best_delay_int + delayed_signal_offset],

                             ff_g729_interp_filt_long,

                             ANALYZED_FRAC_DELAYS + 1,

                             8 - best_delay_frac,

                             LONG_INT_FILT_LEN,

                             subframe_size + 1);

        /* Compute R'(k) correlation's numerator. */

        sum = dsp->scalarproduct_int16(residual_filt,

                                       sig_scaled + RES_PREV_DATA_SIZE,

                                       subframe_size);



        if (sum < 0) {

            gain_long_num = 0;

            sh_gain_long_num = 0;

        } else {

            tmp = FFMAX(av_log2(sum) - 14, 0);

            sum >>= tmp;

            gain_long_num = sum;

            sh_gain_long_num = tmp;

        }



        /* Compute R'(k) correlation's denominator. */

        sum = dsp->scalarproduct_int16(residual_filt, residual_filt, subframe_size);



        tmp = FFMAX(av_log2(sum) - 14, 0);

        sum >>= tmp;

        gain_long_den = sum;

        sh_gain_long_den = tmp;



        /* Select between original and delayed signal.

           Delayed signal will be selected if it increases R'(k)

           correlation. */

        L_temp0 = gain_num * gain_num;

        L_temp0 = MULL(L_temp0, gain_long_den, FRAC_BITS);



        L_temp1 = gain_long_num * gain_long_num;

        L_temp1 = MULL(L_temp1, gain_den, FRAC_BITS);



        tmp = ((sh_gain_long_num - sh_gain_num) << 1) - (sh_gain_long_den - sh_gain_den);

        if (tmp > 0)

            L_temp0 >>= tmp;

        else

            L_temp1 >>= -tmp;



        /* Check if longer filter increases the values of R'(k). */

        if (L_temp1 > L_temp0) {

            /* Select long filter. */

            selected_signal = residual_filt;

            gain_num = gain_long_num;

            gain_den = gain_long_den;

            sh_gain_num = sh_gain_long_num;

            sh_gain_den = sh_gain_long_den;

        } else

            /* Select short filter. */

            selected_signal = &delayed_signal[best_delay_frac-1][delayed_signal_offset];



        /* Rescale selected signal to original value. */

        if (shift > 0)

            for (i = 0; i < subframe_size; i++)

                selected_signal[i] <<= shift;

        else

            for (i = 0; i < subframe_size; i++)

                selected_signal[i] >>= -shift;



        /* necessary to avoid compiler warning */

        selected_signal_const = selected_signal;

    } // if(best_delay_frac)

    else

        selected_signal_const = residual + RES_PREV_DATA_SIZE - (best_delay_int + 1 - delayed_signal_offset);

#ifdef G729_BITEXACT

    tmp = sh_gain_num - sh_gain_den;

    if (tmp > 0)

        gain_den >>= tmp;

    else

        gain_num >>= -tmp;



    if (gain_num > gain_den)

        lt_filt_factor_a = MIN_LT_FILT_FACTOR_A;

    else {

        gain_num >>= 2;

        gain_den >>= 1;

        lt_filt_factor_a = (gain_den << 15) / (gain_den + gain_num);

    }

#else

    L64_temp0 = ((int64_t)gain_num) << (sh_gain_num - 1);

    L64_temp1 = ((int64_t)gain_den) << sh_gain_den;

    lt_filt_factor_a = FFMAX((L64_temp1 << 15) / (L64_temp1 + L64_temp0), MIN_LT_FILT_FACTOR_A);

#endif



    /* Filter through selected filter. */

    lt_filt_factor_b = 32767 - lt_filt_factor_a + 1;



    ff_acelp_weighted_vector_sum(residual_filt, residual + RES_PREV_DATA_SIZE,

                                 selected_signal_const,

                                 lt_filt_factor_a, lt_filt_factor_b,

                                 1<<14, 15, subframe_size);



    // Long-term prediction gain is larger than 3dB.

    return 1;

}

static int16_t long_term_filter(DSPContext *dsp, int pitch_delay_int,

                                const int16_t* residual, int16_t *residual_filt,

                                int subframe_size)

{

    int i, k, tmp, tmp2;

    int sum;

    int L_temp0;

    int L_temp1;

    int64_t L64_temp0;

    int64_t L64_temp1;

    int16_t shift;

    int corr_int_num, corr_int_den;



    int ener;

    int16_t sh_ener;



    int16_t gain_num,gain_den; 

    int16_t sh_gain_num, sh_gain_den;

    int gain_num_square;



    int16_t gain_long_num,gain_long_den; 

    int16_t sh_gain_long_num, sh_gain_long_den;



    int16_t best_delay_int, best_delay_frac;



    int16_t delayed_signal_offset;

    int lt_filt_factor_a, lt_filt_factor_b;



    int16_t * selected_signal;

    const int16_t * selected_signal_const; 



    int16_t sig_scaled[SUBFRAME_SIZE + RES_PREV_DATA_SIZE];

    int16_t delayed_signal[ANALYZED_FRAC_DELAYS][SUBFRAME_SIZE+1];

    int corr_den[ANALYZED_FRAC_DELAYS][2];



    tmp = 0;

    for(i=0; i<subframe_size + RES_PREV_DATA_SIZE; i++)

        tmp |= FFABS(residual[i]);



    if(!tmp)

        shift = 3;

    else

        shift = av_log2(tmp) - 11;



    if (shift > 0)

        for (i = 0; i < subframe_size + RES_PREV_DATA_SIZE; i++)

            sig_scaled[i] = residual[i] >> shift;

    else

        for (i = 0; i < subframe_size + RES_PREV_DATA_SIZE; i++)

            sig_scaled[i] = residual[i] << -shift;



    

    gain_num = 0;



    ener = dsp->scalarproduct_int16(sig_scaled + RES_PREV_DATA_SIZE,

                                    sig_scaled + RES_PREV_DATA_SIZE,

                                    subframe_size);

    if (ener) {

        sh_ener = FFMAX(av_log2(ener) - 14, 0);

        ener >>= sh_ener;

        





























        









        corr_int_num = 0;

        best_delay_int = pitch_delay_int - 1;

        for (i = pitch_delay_int - 1; i <= pitch_delay_int + 1; i++) {

            sum = dsp->scalarproduct_int16(sig_scaled + RES_PREV_DATA_SIZE,

                                           sig_scaled + RES_PREV_DATA_SIZE - i,

                                           subframe_size);

            if (sum > corr_int_num) {

                corr_int_num = sum;

                best_delay_int = i;

            }

        }

        if (corr_int_num) {

            

            corr_int_den = dsp->scalarproduct_int16(sig_scaled - best_delay_int + RES_PREV_DATA_SIZE,

                                                    sig_scaled - best_delay_int + RES_PREV_DATA_SIZE,

                                                    subframe_size);



            









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

                ff_acelp_interpolate(&delayed_signal[k][0],

                                     &sig_scaled[RES_PREV_DATA_SIZE - best_delay_int],

                                     ff_g729_interp_filt_short,

                                     ANALYZED_FRAC_DELAYS+1,

                                     8 - k - 1,

                                     SHORT_INT_FILT_LEN,

                                     subframe_size + 1);

            }



            











            tmp = corr_int_den;

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

                sum = dsp->scalarproduct_int16(&delayed_signal[k][1],

                                               &delayed_signal[k][1],

                                               subframe_size - 1);

                corr_den[k][0] = sum + delayed_signal[k][0            ] * delayed_signal[k][0            ];

                corr_den[k][1] = sum + delayed_signal[k][subframe_size] * delayed_signal[k][subframe_size];



                tmp = FFMAX3(tmp, corr_den[k][0], corr_den[k][1]);

            }



            sh_gain_den = av_log2(tmp) - 14;

            if (sh_gain_den >= 0) {



                sh_gain_num =  FFMAX(sh_gain_den, sh_ener);

                







                delayed_signal_offset = 1;

                best_delay_frac = 0;

                gain_den = corr_int_den >> sh_gain_den;

                gain_num = corr_int_num >> sh_gain_num;

                gain_num_square = gain_num * gain_num;

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

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

                        int16_t gain_num_short, gain_den_short;

                        int gain_num_short_square;

                        



                        sum = dsp->scalarproduct_int16(&delayed_signal[k][i],

                                                       sig_scaled + RES_PREV_DATA_SIZE,

                                                       subframe_size);

                        gain_num_short = FFMAX(sum >> sh_gain_num, 0);



                        









                        gain_num_short_square = gain_num_short * gain_num_short;

                        gain_den_short = corr_den[k][i] >> sh_gain_den;



                        tmp = MULL(gain_num_short_square, gain_den, FRAC_BITS);

                        tmp2 = MULL(gain_num_square, gain_den_short, FRAC_BITS);



                        

                        if (tmp > tmp2) {

                            gain_num = gain_num_short;

                            gain_den = gain_den_short;

                            gain_num_square = gain_num_short_square;

                            delayed_signal_offset = i;

                            best_delay_frac = k + 1;

                        }

                    }

                }



                









                L64_temp0 =  (int64_t)gain_num_square  << ((sh_gain_num << 1) + 1);

                L64_temp1 = ((int64_t)gain_den * ener) << (sh_gain_den + sh_ener);

                if (L64_temp0 < L64_temp1)

                    gain_num = 0;

            } 

        } 

    } 

    



    if (!gain_num) {

        memcpy(residual_filt, residual + RES_PREV_DATA_SIZE, subframe_size * sizeof(int16_t));



        

        return 0;

    }

    if (best_delay_frac) {

        

        ff_acelp_interpolate(residual_filt,

                             &sig_scaled[RES_PREV_DATA_SIZE - best_delay_int + delayed_signal_offset],

                             ff_g729_interp_filt_long,

                             ANALYZED_FRAC_DELAYS + 1,

                             8 - best_delay_frac,

                             LONG_INT_FILT_LEN,

                             subframe_size + 1);

        

        sum = dsp->scalarproduct_int16(residual_filt,

                                       sig_scaled + RES_PREV_DATA_SIZE,

                                       subframe_size);



        if (sum < 0) {

            gain_long_num = 0;

            sh_gain_long_num = 0;

        } else {

            tmp = FFMAX(av_log2(sum) - 14, 0);

            sum >>= tmp;

            gain_long_num = sum;

            sh_gain_long_num = tmp;

        }



        

        sum = dsp->scalarproduct_int16(residual_filt, residual_filt, subframe_size);



        tmp = FFMAX(av_log2(sum) - 14, 0);

        sum >>= tmp;

        gain_long_den = sum;

        sh_gain_long_den = tmp;



        





        L_temp0 = gain_num * gain_num;

        L_temp0 = MULL(L_temp0, gain_long_den, FRAC_BITS);



        L_temp1 = gain_long_num * gain_long_num;

        L_temp1 = MULL(L_temp1, gain_den, FRAC_BITS);



        tmp = ((sh_gain_long_num - sh_gain_num) << 1) - (sh_gain_long_den - sh_gain_den);

        if (tmp > 0)

            L_temp0 >>= tmp;

        else

            L_temp1 >>= -tmp;



        

        if (L_temp1 > L_temp0) {

            

            selected_signal = residual_filt;

            gain_num = gain_long_num;

            gain_den = gain_long_den;

            sh_gain_num = sh_gain_long_num;

            sh_gain_den = sh_gain_long_den;

        } else

            

            selected_signal = &delayed_signal[best_delay_frac-1][delayed_signal_offset];



        

        if (shift > 0)

            for (i = 0; i < subframe_size; i++)

                selected_signal[i] <<= shift;

        else

            for (i = 0; i < subframe_size; i++)

                selected_signal[i] >>= -shift;



        

        selected_signal_const = selected_signal;

    } 

    else

        selected_signal_const = residual + RES_PREV_DATA_SIZE - (best_delay_int + 1 - delayed_signal_offset);

#ifdef G729_BITEXACT

    tmp = sh_gain_num - sh_gain_den;

    if (tmp > 0)

        gain_den >>= tmp;

    else

        gain_num >>= -tmp;



    if (gain_num > gain_den)

        lt_filt_factor_a = MIN_LT_FILT_FACTOR_A;

    else {

        gain_num >>= 2;

        gain_den >>= 1;

        lt_filt_factor_a = (gain_den << 15) / (gain_den + gain_num);

    }

#else

    L64_temp0 = ((int64_t)gain_num) << (sh_gain_num - 1);

    L64_temp1 = ((int64_t)gain_den) << sh_gain_den;

    lt_filt_factor_a = FFMAX((L64_temp1 << 15) / (L64_temp1 + L64_temp0), MIN_LT_FILT_FACTOR_A);

#endif



    

    lt_filt_factor_b = 32767 - lt_filt_factor_a + 1;



    ff_acelp_weighted_vector_sum(residual_filt, residual + RES_PREV_DATA_SIZE,

                                 selected_signal_const,

                                 lt_filt_factor_a, lt_filt_factor_b,

                                 1<<14, 15, subframe_size);



    

    return 1;

}

static int16_t FUNC_0(DSPContext *dsp, int pitch_delay_int,

                                const int16_t* residual, int16_t *residual_filt,

                                int subframe_size)

{

    int VAR_0, VAR_1, VAR_2, VAR_3;

    int VAR_4;

    int VAR_5;

    int VAR_6;

    int64_t L64_temp0;

    int64_t L64_temp1;

    int16_t shift;

    int VAR_7, VAR_8;



    int VAR_9;

    int16_t sh_ener;



    int16_t gain_num,gain_den; 

    int16_t sh_gain_num, sh_gain_den;

    int VAR_10;



    int16_t gain_long_num,gain_long_den; 

    int16_t sh_gain_long_num, sh_gain_long_den;



    int16_t best_delay_int, best_delay_frac;



    int16_t delayed_signal_offset;

    int VAR_11, VAR_12;



    int16_t * selected_signal;

    const int16_t * VAR_13; 



    int16_t sig_scaled[SUBFRAME_SIZE + RES_PREV_DATA_SIZE];

    int16_t delayed_signal[ANALYZED_FRAC_DELAYS][SUBFRAME_SIZE+1];

    int VAR_14[ANALYZED_FRAC_DELAYS][2];



    VAR_2 = 0;

    for(VAR_0=0; VAR_0<subframe_size + RES_PREV_DATA_SIZE; VAR_0++)

        VAR_2 |= FFABS(residual[VAR_0]);



    if(!VAR_2)

        shift = 3;

    else

        shift = av_log2(VAR_2) - 11;



    if (shift > 0)

        for (VAR_0 = 0; VAR_0 < subframe_size + RES_PREV_DATA_SIZE; VAR_0++)

            sig_scaled[VAR_0] = residual[VAR_0] >> shift;

    else

        for (VAR_0 = 0; VAR_0 < subframe_size + RES_PREV_DATA_SIZE; VAR_0++)

            sig_scaled[VAR_0] = residual[VAR_0] << -shift;



    

    gain_num = 0;



    VAR_9 = dsp->scalarproduct_int16(sig_scaled + RES_PREV_DATA_SIZE,

                                    sig_scaled + RES_PREV_DATA_SIZE,

                                    subframe_size);

    if (VAR_9) {

        sh_ener = FFMAX(av_log2(VAR_9) - 14, 0);

        VAR_9 >>= sh_ener;

        





























        









        VAR_7 = 0;

        best_delay_int = pitch_delay_int - 1;

        for (VAR_0 = pitch_delay_int - 1; VAR_0 <= pitch_delay_int + 1; VAR_0++) {

            VAR_4 = dsp->scalarproduct_int16(sig_scaled + RES_PREV_DATA_SIZE,

                                           sig_scaled + RES_PREV_DATA_SIZE - VAR_0,

                                           subframe_size);

            if (VAR_4 > VAR_7) {

                VAR_7 = VAR_4;

                best_delay_int = VAR_0;

            }

        }

        if (VAR_7) {

            

            VAR_8 = dsp->scalarproduct_int16(sig_scaled - best_delay_int + RES_PREV_DATA_SIZE,

                                                    sig_scaled - best_delay_int + RES_PREV_DATA_SIZE,

                                                    subframe_size);



            









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

                ff_acelp_interpolate(&delayed_signal[VAR_1][0],

                                     &sig_scaled[RES_PREV_DATA_SIZE - best_delay_int],

                                     ff_g729_interp_filt_short,

                                     ANALYZED_FRAC_DELAYS+1,

                                     8 - VAR_1 - 1,

                                     SHORT_INT_FILT_LEN,

                                     subframe_size + 1);

            }



            











            VAR_2 = VAR_8;

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

                VAR_4 = dsp->scalarproduct_int16(&delayed_signal[VAR_1][1],

                                               &delayed_signal[VAR_1][1],

                                               subframe_size - 1);

                VAR_14[VAR_1][0] = VAR_4 + delayed_signal[VAR_1][0            ] * delayed_signal[VAR_1][0            ];

                VAR_14[VAR_1][1] = VAR_4 + delayed_signal[VAR_1][subframe_size] * delayed_signal[VAR_1][subframe_size];



                VAR_2 = FFMAX3(VAR_2, VAR_14[VAR_1][0], VAR_14[VAR_1][1]);

            }



            sh_gain_den = av_log2(VAR_2) - 14;

            if (sh_gain_den >= 0) {



                sh_gain_num =  FFMAX(sh_gain_den, sh_ener);

                







                delayed_signal_offset = 1;

                best_delay_frac = 0;

                gain_den = VAR_8 >> sh_gain_den;

                gain_num = VAR_7 >> sh_gain_num;

                VAR_10 = gain_num * gain_num;

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

                    for (VAR_0 = 0; VAR_0 < 2; VAR_0++) {

                        int16_t gain_num_short, gain_den_short;

                        int gain_num_short_square;

                        



                        VAR_4 = dsp->scalarproduct_int16(&delayed_signal[VAR_1][VAR_0],

                                                       sig_scaled + RES_PREV_DATA_SIZE,

                                                       subframe_size);

                        gain_num_short = FFMAX(VAR_4 >> sh_gain_num, 0);



                        









                        gain_num_short_square = gain_num_short * gain_num_short;

                        gain_den_short = VAR_14[VAR_1][VAR_0] >> sh_gain_den;



                        VAR_2 = MULL(gain_num_short_square, gain_den, FRAC_BITS);

                        VAR_3 = MULL(VAR_10, gain_den_short, FRAC_BITS);



                        

                        if (VAR_2 > VAR_3) {

                            gain_num = gain_num_short;

                            gain_den = gain_den_short;

                            VAR_10 = gain_num_short_square;

                            delayed_signal_offset = VAR_0;

                            best_delay_frac = VAR_1 + 1;

                        }

                    }

                }



                









                L64_temp0 =  (int64_t)VAR_10  << ((sh_gain_num << 1) + 1);

                L64_temp1 = ((int64_t)gain_den * VAR_9) << (sh_gain_den + sh_ener);

                if (L64_temp0 < L64_temp1)

                    gain_num = 0;

            } 

        } 

    } 

    



    if (!gain_num) {

        memcpy(residual_filt, residual + RES_PREV_DATA_SIZE, subframe_size * sizeof(int16_t));



        

        return 0;

    }

    if (best_delay_frac) {

        

        ff_acelp_interpolate(residual_filt,

                             &sig_scaled[RES_PREV_DATA_SIZE - best_delay_int + delayed_signal_offset],

                             ff_g729_interp_filt_long,

                             ANALYZED_FRAC_DELAYS + 1,

                             8 - best_delay_frac,

                             LONG_INT_FILT_LEN,

                             subframe_size + 1);

        

        VAR_4 = dsp->scalarproduct_int16(residual_filt,

                                       sig_scaled + RES_PREV_DATA_SIZE,

                                       subframe_size);



        if (VAR_4 < 0) {

            gain_long_num = 0;

            sh_gain_long_num = 0;

        } else {

            VAR_2 = FFMAX(av_log2(VAR_4) - 14, 0);

            VAR_4 >>= VAR_2;

            gain_long_num = VAR_4;

            sh_gain_long_num = VAR_2;

        }



        

        VAR_4 = dsp->scalarproduct_int16(residual_filt, residual_filt, subframe_size);



        VAR_2 = FFMAX(av_log2(VAR_4) - 14, 0);

        VAR_4 >>= VAR_2;

        gain_long_den = VAR_4;

        sh_gain_long_den = VAR_2;



        





        VAR_5 = gain_num * gain_num;

        VAR_5 = MULL(VAR_5, gain_long_den, FRAC_BITS);



        VAR_6 = gain_long_num * gain_long_num;

        VAR_6 = MULL(VAR_6, gain_den, FRAC_BITS);



        VAR_2 = ((sh_gain_long_num - sh_gain_num) << 1) - (sh_gain_long_den - sh_gain_den);

        if (VAR_2 > 0)

            VAR_5 >>= VAR_2;

        else

            VAR_6 >>= -VAR_2;



        

        if (VAR_6 > VAR_5) {

            

            selected_signal = residual_filt;

            gain_num = gain_long_num;

            gain_den = gain_long_den;

            sh_gain_num = sh_gain_long_num;

            sh_gain_den = sh_gain_long_den;

        } else

            

            selected_signal = &delayed_signal[best_delay_frac-1][delayed_signal_offset];



        

        if (shift > 0)

            for (VAR_0 = 0; VAR_0 < subframe_size; VAR_0++)

                selected_signal[VAR_0] <<= shift;

        else

            for (VAR_0 = 0; VAR_0 < subframe_size; VAR_0++)

                selected_signal[VAR_0] >>= -shift;



        

        VAR_13 = selected_signal;

    } 

    else

        VAR_13 = residual + RES_PREV_DATA_SIZE - (best_delay_int + 1 - delayed_signal_offset);

#ifdef G729_BITEXACT

    VAR_2 = sh_gain_num - sh_gain_den;

    if (VAR_2 > 0)

        gain_den >>= VAR_2;

    else

        gain_num >>= -VAR_2;



    if (gain_num > gain_den)

        VAR_11 = MIN_LT_FILT_FACTOR_A;

    else {

        gain_num >>= 2;

        gain_den >>= 1;

        VAR_11 = (gain_den << 15) / (gain_den + gain_num);

    }

#else

    L64_temp0 = ((int64_t)gain_num) << (sh_gain_num - 1);

    L64_temp1 = ((int64_t)gain_den) << sh_gain_den;

    VAR_11 = FFMAX((L64_temp1 << 15) / (L64_temp1 + L64_temp0), MIN_LT_FILT_FACTOR_A);

#endif



    

    VAR_12 = 32767 - VAR_11 + 1;



    ff_acelp_weighted_vector_sum(residual_filt, residual + RES_PREV_DATA_SIZE,

                                 VAR_13,

                                 VAR_11, VAR_12,

                                 1<<14, 15, subframe_size);



    

    return 1;

}

static int16_t FUNC_0(DSPContext *dsp, int pitch_delay_int,
const int16_t* residual, int16_t *residual_filt,
int subframe_size)
{ int VAR_0, VAR_1, VAR_2, VAR_3; int VAR_4; int VAR_5; int VAR_6; int64_t L64_temp0; int64_t L64_temp1; int16_t shift; int VAR_7, VAR_8; int VAR_9; int16_t sh_ener; int16_t gain_num,gain_den; int16_t sh_gain_num, sh_gain_den; int VAR_10; int16_t gain_long_num,gain_long_den; int16_t sh_gain_long_num, sh_gain_long_den; int16_t best_delay_int, best_delay_frac; int16_t delayed_signal_offset; int VAR_11, VAR_12; int16_t * selected_signal; const int16_t * VAR_13; int16_t sig_scaled[SUBFRAME_SIZE + RES_PREV_DATA_SIZE]; int16_t delayed_signal[ANALYZED_FRAC_DELAYS][SUBFRAME_SIZE+1]; int VAR_14[ANALYZED_FRAC_DELAYS][2]; VAR_2 = 0; for(VAR_0=0; VAR_0<subframe_size + RES_PREV_DATA_SIZE; VAR_0++) VAR_2 |= FFABS(residual[VAR_0]); if(!VAR_2)
shift = 3; else
shift = av_log2(VAR_2) - 11; if (shift > 0)
for (VAR_0 = 0; VAR_0 < subframe_size + RES_PREV_DATA_SIZE; VAR_0++) sig_scaled[VAR_0] = residual[VAR_0] >> shift; else
for (VAR_0 = 0; VAR_0 < subframe_size + RES_PREV_DATA_SIZE; VAR_0++) sig_scaled[VAR_0] = residual[VAR_0] << -shift; gain_num = 0; VAR_9 = dsp->scalarproduct_int16(sig_scaled + RES_PREV_DATA_SIZE,
sig_scaled + RES_PREV_DATA_SIZE,
subframe_size); if (VAR_9) { sh_ener = FFMAX(av_log2(VAR_9) - 14, 0); VAR_9 >>= sh_ener; VAR_7 = 0; best_delay_int = pitch_delay_int - 1; for (VAR_0 = pitch_delay_int - 1; VAR_0 <= pitch_delay_int + 1; VAR_0++) { VAR_4 = dsp->scalarproduct_int16(sig_scaled + RES_PREV_DATA_SIZE,
sig_scaled + RES_PREV_DATA_SIZE - VAR_0,
subframe_size); if (VAR_4 > VAR_7) { VAR_7 = VAR_4; best_delay_int = VAR_0; } } if (VAR_7) { VAR_8 = dsp->scalarproduct_int16(sig_scaled - best_delay_int + RES_PREV_DATA_SIZE,
sig_scaled - best_delay_int + RES_PREV_DATA_SIZE,
subframe_size); for (VAR_1 = 0; VAR_1 < ANALYZED_FRAC_DELAYS; VAR_1++) { ff_acelp_interpolate(&delayed_signal[VAR_1][0],
&sig_scaled[RES_PREV_DATA_SIZE - best_delay_int],
ff_g729_interp_filt_short,
ANALYZED_FRAC_DELAYS+1,
8 - VAR_1 - 1,
SHORT_INT_FILT_LEN,
subframe_size + 1); } VAR_2 = VAR_8; for (VAR_1 = 0; VAR_1 < ANALYZED_FRAC_DELAYS; VAR_1++) { VAR_4 = dsp->scalarproduct_int16(&delayed_signal[VAR_1][1],
&delayed_signal[VAR_1][1],
subframe_size - 1); VAR_14[VAR_1][0] = VAR_4 + delayed_signal[VAR_1][0            ] * delayed_signal[VAR_1][0            ]; VAR_14[VAR_1][1] = VAR_4 + delayed_signal[VAR_1][subframe_size] * delayed_signal[VAR_1][subframe_size]; VAR_2 = FFMAX3(VAR_2, VAR_14[VAR_1][0], VAR_14[VAR_1][1]); } sh_gain_den = av_log2(VAR_2) - 14; if (sh_gain_den >= 0) { sh_gain_num =  FFMAX(sh_gain_den, sh_ener); delayed_signal_offset = 1; best_delay_frac = 0; gain_den = VAR_8 >> sh_gain_den; gain_num = VAR_7 >> sh_gain_num; VAR_10 = gain_num * gain_num; for (VAR_1 = 0; VAR_1 < ANALYZED_FRAC_DELAYS; VAR_1++) { for (VAR_0 = 0; VAR_0 < 2; VAR_0++) { int16_t gain_num_short, gain_den_short; int gain_num_short_square; VAR_4 = dsp->scalarproduct_int16(&delayed_signal[VAR_1][VAR_0],
sig_scaled + RES_PREV_DATA_SIZE,
subframe_size); gain_num_short = FFMAX(VAR_4 >> sh_gain_num, 0); gain_num_short_square = gain_num_short * gain_num_short; gain_den_short = VAR_14[VAR_1][VAR_0] >> sh_gain_den; VAR_2 = MULL(gain_num_short_square, gain_den, FRAC_BITS); VAR_3 = MULL(VAR_10, gain_den_short, FRAC_BITS); if (VAR_2 > VAR_3) { gain_num = gain_num_short; gain_den = gain_den_short; VAR_10 = gain_num_short_square; delayed_signal_offset = VAR_0; best_delay_frac = VAR_1 + 1; } } } L64_temp0 =  (int64_t)VAR_10  << ((sh_gain_num << 1) + 1); L64_temp1 = ((int64_t)gain_den * VAR_9) << (sh_gain_den + sh_ener); if (L64_temp0 < L64_temp1)
gain_num = 0; } } } if (!gain_num) { memcpy(residual_filt, residual + RES_PREV_DATA_SIZE, subframe_size * sizeof(int16_t)); return 0; } if (best_delay_frac) { ff_acelp_interpolate(residual_filt,
&sig_scaled[RES_PREV_DATA_SIZE - best_delay_int + delayed_signal_offset],
ff_g729_interp_filt_long,
ANALYZED_FRAC_DELAYS + 1,
8 - best_delay_frac,
LONG_INT_FILT_LEN,
subframe_size + 1); VAR_4 = dsp->scalarproduct_int16(residual_filt,
sig_scaled + RES_PREV_DATA_SIZE,
subframe_size); if (VAR_4 < 0) { gain_long_num = 0; sh_gain_long_num = 0; } else { VAR_2 = FFMAX(av_log2(VAR_4) - 14, 0); VAR_4 >>= VAR_2; gain_long_num = VAR_4; sh_gain_long_num = VAR_2; } VAR_4 = dsp->scalarproduct_int16(residual_filt, residual_filt, subframe_size); VAR_2 = FFMAX(av_log2(VAR_4) - 14, 0); VAR_4 >>= VAR_2; gain_long_den = VAR_4; sh_gain_long_den = VAR_2; VAR_5 = gain_num * gain_num; VAR_5 = MULL(VAR_5, gain_long_den, FRAC_BITS); VAR_6 = gain_long_num * gain_long_num; VAR_6 = MULL(VAR_6, gain_den, FRAC_BITS); VAR_2 = ((sh_gain_long_num - sh_gain_num) << 1) - (sh_gain_long_den - sh_gain_den); if (VAR_2 > 0)
VAR_5 >>= VAR_2; else
VAR_6 >>= -VAR_2; if (VAR_6 > VAR_5) { selected_signal = residual_filt; gain_num = gain_long_num; gain_den = gain_long_den; sh_gain_num = sh_gain_long_num; sh_gain_den = sh_gain_long_den; } else selected_signal = &delayed_signal[best_delay_frac-1][delayed_signal_offset]; if (shift > 0)
for (VAR_0 = 0; VAR_0 < subframe_size; VAR_0++) selected_signal[VAR_0] <<= shift; else
for (VAR_0 = 0; VAR_0 < subframe_size; VAR_0++) selected_signal[VAR_0] >>= -shift; VAR_13 = selected_signal; } else
VAR_13 = residual + RES_PREV_DATA_SIZE - (best_delay_int + 1 - delayed_signal_offset); #ifdef G729_BITEXACT
VAR_2 = sh_gain_num - sh_gain_den; if (VAR_2 > 0)
gain_den >>= VAR_2; else
gain_num >>= -VAR_2; if (gain_num > gain_den)
VAR_11 = MIN_LT_FILT_FACTOR_A; else { gain_num >>= 2; gain_den >>= 1; VAR_11 = (gain_den << 15) / (gain_den + gain_num); } #else
L64_temp0 = ((int64_t)gain_num) << (sh_gain_num - 1); L64_temp1 = ((int64_t)gain_den) << sh_gain_den; VAR_11 = FFMAX((L64_temp1 << 15) / (L64_temp1 + L64_temp0), MIN_LT_FILT_FACTOR_A); #endif
VAR_12 = 32767 - VAR_11 + 1; ff_acelp_weighted_vector_sum(residual_filt, residual + RES_PREV_DATA_SIZE,
VAR_13,
VAR_11, VAR_12,
1<<14, 15, subframe_size); return 1; }