static inline void silk_stabilize_lsf(int16_t nlsf[16], int order, const uint16_t min_delta[17])

{

    int pass, i;

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

        int k, min_diff = 0;

        for (i = 0; i < order+1; i++) {

            int low  = i != 0     ? nlsf[i-1] : 0;

            int high = i != order ? nlsf[i]   : 32768;

            int diff = (high - low) - (min_delta[i]);



            if (diff < min_diff) {

                min_diff = diff;

                k = i;



                if (pass == 20)

                    break;

            }

        }

        if (min_diff == 0) /* no issues; stabilized */

            return;



        /* wiggle one or two LSFs */

        if (k == 0) {

            /* repel away from lower bound */

            nlsf[0] = min_delta[0];

        } else if (k == order) {

            /* repel away from higher bound */

            nlsf[order-1] = 32768 - min_delta[order];

        } else {

            /* repel away from current position */

            int min_center = 0, max_center = 32768, center_val;



            /* lower extent */

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

                min_center += min_delta[i];

            min_center += min_delta[k] >> 1;



            /* upper extent */

            for (i = order; i > k; i--)

                max_center -= min_delta[k];

            max_center -= min_delta[k] >> 1;



            /* move apart */

            center_val = nlsf[k - 1] + nlsf[k];

            center_val = (center_val >> 1) + (center_val & 1); // rounded divide by 2

            center_val = FFMIN(max_center, FFMAX(min_center, center_val));



            nlsf[k - 1] = center_val - (min_delta[k] >> 1);

            nlsf[k]     = nlsf[k - 1] + min_delta[k];

        }

    }



    /* resort to the fall-back method, the standard method for LSF stabilization */



    /* sort; as the LSFs should be nearly sorted, use insertion sort */

    for (i = 1; i < order; i++) {

        int j, value = nlsf[i];

        for (j = i - 1; j >= 0 && nlsf[j] > value; j--)

            nlsf[j + 1] = nlsf[j];

        nlsf[j + 1] = value;

    }



    /* push forwards to increase distance */

    if (nlsf[0] < min_delta[0])

        nlsf[0] = min_delta[0];

    for (i = 1; i < order; i++)

        if (nlsf[i] < nlsf[i - 1] + min_delta[i])

            nlsf[i] = nlsf[i - 1] + min_delta[i];



    /* push backwards to increase distance */

    if (nlsf[order-1] > 32768 - min_delta[order])

        nlsf[order-1] = 32768 - min_delta[order];

    for (i = order-2; i >= 0; i--)

        if (nlsf[i] > nlsf[i + 1] - min_delta[i+1])

            nlsf[i] = nlsf[i + 1] - min_delta[i+1];



    return;

}

static inline void silk_stabilize_lsf(int16_t nlsf[16], int order, const uint16_t min_delta[17])

{

    int pass, i;

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

        int k, min_diff = 0;

        for (i = 0; i < order+1; i++) {

            int low  = i != 0     ? nlsf[i-1] : 0;

            int high = i != order ? nlsf[i]   : 32768;

            int diff = (high - low) - (min_delta[i]);



            if (diff < min_diff) {

                min_diff = diff;

                k = i;



                if (pass == 20)

                    break;

            }

        }

        if (min_diff == 0) 

            return;



        

        if (k == 0) {

            

            nlsf[0] = min_delta[0];

        } else if (k == order) {

            

            nlsf[order-1] = 32768 - min_delta[order];

        } else {

            

            int min_center = 0, max_center = 32768, center_val;



            

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

                min_center += min_delta[i];

            min_center += min_delta[k] >> 1;



            

            for (i = order; i > k; i--)

                max_center -= min_delta[k];

            max_center -= min_delta[k] >> 1;



            

            center_val = nlsf[k - 1] + nlsf[k];

            center_val = (center_val >> 1) + (center_val & 1); 

            center_val = FFMIN(max_center, FFMAX(min_center, center_val));



            nlsf[k - 1] = center_val - (min_delta[k] >> 1);

            nlsf[k]     = nlsf[k - 1] + min_delta[k];

        }

    }



    



    

    for (i = 1; i < order; i++) {

        int j, value = nlsf[i];

        for (j = i - 1; j >= 0 && nlsf[j] > value; j--)

            nlsf[j + 1] = nlsf[j];

        nlsf[j + 1] = value;

    }



    

    if (nlsf[0] < min_delta[0])

        nlsf[0] = min_delta[0];

    for (i = 1; i < order; i++)

        if (nlsf[i] < nlsf[i - 1] + min_delta[i])

            nlsf[i] = nlsf[i - 1] + min_delta[i];



    

    if (nlsf[order-1] > 32768 - min_delta[order])

        nlsf[order-1] = 32768 - min_delta[order];

    for (i = order-2; i >= 0; i--)

        if (nlsf[i] > nlsf[i + 1] - min_delta[i+1])

            nlsf[i] = nlsf[i + 1] - min_delta[i+1];



    return;

}

static inline void FUNC_0(int16_t VAR_0[16], int VAR_1, const uint16_t VAR_2[17])

{

    int VAR_3, VAR_4;

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

        int VAR_5, VAR_6 = 0;

        for (VAR_4 = 0; VAR_4 < VAR_1+1; VAR_4++) {

            int VAR_7  = VAR_4 != 0     ? VAR_0[VAR_4-1] : 0;

            int VAR_8 = VAR_4 != VAR_1 ? VAR_0[VAR_4]   : 32768;

            int VAR_9 = (VAR_8 - VAR_7) - (VAR_2[VAR_4]);



            if (VAR_9 < VAR_6) {

                VAR_6 = VAR_9;

                VAR_5 = VAR_4;



                if (VAR_3 == 20)

                    break;

            }

        }

        if (VAR_6 == 0) 

            return;



        

        if (VAR_5 == 0) {

            

            VAR_0[0] = VAR_2[0];

        } else if (VAR_5 == VAR_1) {

            

            VAR_0[VAR_1-1] = 32768 - VAR_2[VAR_1];

        } else {

            

            int VAR_10 = 0, VAR_11 = 32768, VAR_12;



            

            for (VAR_4 = 0; VAR_4 < VAR_5; VAR_4++)

                VAR_10 += VAR_2[VAR_4];

            VAR_10 += VAR_2[VAR_5] >> 1;



            

            for (VAR_4 = VAR_1; VAR_4 > VAR_5; VAR_4--)

                VAR_11 -= VAR_2[VAR_5];

            VAR_11 -= VAR_2[VAR_5] >> 1;



            

            VAR_12 = VAR_0[VAR_5 - 1] + VAR_0[VAR_5];

            VAR_12 = (VAR_12 >> 1) + (VAR_12 & 1); 

            VAR_12 = FFMIN(VAR_11, FFMAX(VAR_10, VAR_12));



            VAR_0[VAR_5 - 1] = VAR_12 - (VAR_2[VAR_5] >> 1);

            VAR_0[VAR_5]     = VAR_0[VAR_5 - 1] + VAR_2[VAR_5];

        }

    }



    



    

    for (VAR_4 = 1; VAR_4 < VAR_1; VAR_4++) {

        int VAR_13, VAR_14 = VAR_0[VAR_4];

        for (VAR_13 = VAR_4 - 1; VAR_13 >= 0 && VAR_0[VAR_13] > VAR_14; VAR_13--)

            VAR_0[VAR_13 + 1] = VAR_0[VAR_13];

        VAR_0[VAR_13 + 1] = VAR_14;

    }



    

    if (VAR_0[0] < VAR_2[0])

        VAR_0[0] = VAR_2[0];

    for (VAR_4 = 1; VAR_4 < VAR_1; VAR_4++)

        if (VAR_0[VAR_4] < VAR_0[VAR_4 - 1] + VAR_2[VAR_4])

            VAR_0[VAR_4] = VAR_0[VAR_4 - 1] + VAR_2[VAR_4];



    

    if (VAR_0[VAR_1-1] > 32768 - VAR_2[VAR_1])

        VAR_0[VAR_1-1] = 32768 - VAR_2[VAR_1];

    for (VAR_4 = VAR_1-2; VAR_4 >= 0; VAR_4--)

        if (VAR_0[VAR_4] > VAR_0[VAR_4 + 1] - VAR_2[VAR_4+1])

            VAR_0[VAR_4] = VAR_0[VAR_4 + 1] - VAR_2[VAR_4+1];



    return;

}

static inline void FUNC_0(int16_t VAR_0[16], int VAR_1, const uint16_t VAR_2[17])
{ int VAR_3, VAR_4; for (VAR_3 = 0; VAR_3 < 20; VAR_3++) { int VAR_5, VAR_6 = 0; for (VAR_4 = 0; VAR_4 < VAR_1+1; VAR_4++) { int VAR_7  = VAR_4 != 0     ? VAR_0[VAR_4-1] : 0; int VAR_8 = VAR_4 != VAR_1 ? VAR_0[VAR_4]   : 32768; int VAR_9 = (VAR_8 - VAR_7) - (VAR_2[VAR_4]); if (VAR_9 < VAR_6) { VAR_6 = VAR_9; VAR_5 = VAR_4; if (VAR_3 == 20)
break; } } if (VAR_6 == 0)
return; if (VAR_5 == 0) { VAR_0[0] = VAR_2[0]; } else if (VAR_5 == VAR_1) { VAR_0[VAR_1-1] = 32768 - VAR_2[VAR_1]; } else { int VAR_10 = 0, VAR_11 = 32768, VAR_12; for (VAR_4 = 0; VAR_4 < VAR_5; VAR_4++) VAR_10 += VAR_2[VAR_4]; VAR_10 += VAR_2[VAR_5] >> 1; for (VAR_4 = VAR_1; VAR_4 > VAR_5; VAR_4--) VAR_11 -= VAR_2[VAR_5]; VAR_11 -= VAR_2[VAR_5] >> 1; VAR_12 = VAR_0[VAR_5 - 1] + VAR_0[VAR_5]; VAR_12 = (VAR_12 >> 1) + (VAR_12 & 1); VAR_12 = FFMIN(VAR_11, FFMAX(VAR_10, VAR_12)); VAR_0[VAR_5 - 1] = VAR_12 - (VAR_2[VAR_5] >> 1); VAR_0[VAR_5]     = VAR_0[VAR_5 - 1] + VAR_2[VAR_5]; } } for (VAR_4 = 1; VAR_4 < VAR_1; VAR_4++) { int VAR_13, VAR_14 = VAR_0[VAR_4]; for (VAR_13 = VAR_4 - 1; VAR_13 >= 0 && VAR_0[VAR_13] > VAR_14; VAR_13--) VAR_0[VAR_13 + 1] = VAR_0[VAR_13]; VAR_0[VAR_13 + 1] = VAR_14; } if (VAR_0[0] < VAR_2[0])
VAR_0[0] = VAR_2[0]; for (VAR_4 = 1; VAR_4 < VAR_1; VAR_4++) if (VAR_0[VAR_4] < VAR_0[VAR_4 - 1] + VAR_2[VAR_4])
VAR_0[VAR_4] = VAR_0[VAR_4 - 1] + VAR_2[VAR_4]; if (VAR_0[VAR_1-1] > 32768 - VAR_2[VAR_1])
VAR_0[VAR_1-1] = 32768 - VAR_2[VAR_1]; for (VAR_4 = VAR_1-2; VAR_4 >= 0; VAR_4--) if (VAR_0[VAR_4] > VAR_0[VAR_4 + 1] - VAR_2[VAR_4+1])
VAR_0[VAR_4] = VAR_0[VAR_4 + 1] - VAR_2[VAR_4+1]; return; }