static int calc_bit_demand(AacPsyContext *ctx, float pe, int bits, int size,

                           int short_window)

{

    const float bitsave_slope  = short_window ? PSY_3GPP_SAVE_SLOPE_S  : PSY_3GPP_SAVE_SLOPE_L;

    const float bitsave_add    = short_window ? PSY_3GPP_SAVE_ADD_S    : PSY_3GPP_SAVE_ADD_L;

    const float bitspend_slope = short_window ? PSY_3GPP_SPEND_SLOPE_S : PSY_3GPP_SPEND_SLOPE_L;

    const float bitspend_add   = short_window ? PSY_3GPP_SPEND_ADD_S   : PSY_3GPP_SPEND_ADD_L;

    const float clip_low       = short_window ? PSY_3GPP_CLIP_LO_S     : PSY_3GPP_CLIP_LO_L;

    const float clip_high      = short_window ? PSY_3GPP_CLIP_HI_S     : PSY_3GPP_CLIP_HI_L;

    float clipped_pe, bit_save, bit_spend, bit_factor, fill_level;



    ctx->fill_level += ctx->frame_bits - bits;

    ctx->fill_level  = av_clip(ctx->fill_level, 0, size);

    fill_level = av_clipf((float)ctx->fill_level / size, clip_low, clip_high);

    clipped_pe = av_clipf(pe, ctx->pe.min, ctx->pe.max);

    bit_save   = (fill_level + bitsave_add) * bitsave_slope;

    assert(bit_save <= 0.3f && bit_save >= -0.05000001f);

    bit_spend  = (fill_level + bitspend_add) * bitspend_slope;

    assert(bit_spend <= 0.5f && bit_spend >= -0.1f);

    /* The bit factor graph in the spec is obviously incorrect.

     *      bit_spend + ((bit_spend - bit_spend))...

     * The reference encoder subtracts everything from 1, but also seems incorrect.

     *      1 - bit_save + ((bit_spend + bit_save))...

     * Hopefully below is correct.

     */

    bit_factor = 1.0f - bit_save + ((bit_spend - bit_save) / (ctx->pe.max - ctx->pe.min)) * (clipped_pe - ctx->pe.min);

    /* NOTE: The reference encoder attempts to center pe max/min around the current pe. */

    ctx->pe.max = FFMAX(pe, ctx->pe.max);

    ctx->pe.min = FFMIN(pe, ctx->pe.min);



    return FFMIN(ctx->frame_bits * bit_factor, ctx->frame_bits + size - bits);

}

static int calc_bit_demand(AacPsyContext *ctx, float pe, int bits, int size,

                           int short_window)

{

    const float bitsave_slope  = short_window ? PSY_3GPP_SAVE_SLOPE_S  : PSY_3GPP_SAVE_SLOPE_L;

    const float bitsave_add    = short_window ? PSY_3GPP_SAVE_ADD_S    : PSY_3GPP_SAVE_ADD_L;

    const float bitspend_slope = short_window ? PSY_3GPP_SPEND_SLOPE_S : PSY_3GPP_SPEND_SLOPE_L;

    const float bitspend_add   = short_window ? PSY_3GPP_SPEND_ADD_S   : PSY_3GPP_SPEND_ADD_L;

    const float clip_low       = short_window ? PSY_3GPP_CLIP_LO_S     : PSY_3GPP_CLIP_LO_L;

    const float clip_high      = short_window ? PSY_3GPP_CLIP_HI_S     : PSY_3GPP_CLIP_HI_L;

    float clipped_pe, bit_save, bit_spend, bit_factor, fill_level;



    ctx->fill_level += ctx->frame_bits - bits;

    ctx->fill_level  = av_clip(ctx->fill_level, 0, size);

    fill_level = av_clipf((float)ctx->fill_level / size, clip_low, clip_high);

    clipped_pe = av_clipf(pe, ctx->pe.min, ctx->pe.max);

    bit_save   = (fill_level + bitsave_add) * bitsave_slope;

    assert(bit_save <= 0.3f && bit_save >= -0.05000001f);

    bit_spend  = (fill_level + bitspend_add) * bitspend_slope;

    assert(bit_spend <= 0.5f && bit_spend >= -0.1f);

    











    bit_factor = 1.0f - bit_save + ((bit_spend - bit_save) / (ctx->pe.max - ctx->pe.min)) * (clipped_pe - ctx->pe.min);

    

    ctx->pe.max = FFMAX(pe, ctx->pe.max);

    ctx->pe.min = FFMIN(pe, ctx->pe.min);



    return FFMIN(ctx->frame_bits * bit_factor, ctx->frame_bits + size - bits);

}

    return FFMIN(ctx->frame_bits * bit_factor, ctx->frame_bits + size - bits);
static int FUNC_0(AacPsyContext *VAR_0, float VAR_1, int VAR_2, int VAR_3,

                           int VAR_4)

{

    const float VAR_5  = VAR_4 ? PSY_3GPP_SAVE_SLOPE_S  : PSY_3GPP_SAVE_SLOPE_L;

    const float VAR_6    = VAR_4 ? PSY_3GPP_SAVE_ADD_S    : PSY_3GPP_SAVE_ADD_L;

    const float VAR_7 = VAR_4 ? PSY_3GPP_SPEND_SLOPE_S : PSY_3GPP_SPEND_SLOPE_L;

    const float VAR_8   = VAR_4 ? PSY_3GPP_SPEND_ADD_S   : PSY_3GPP_SPEND_ADD_L;

    const float VAR_9       = VAR_4 ? PSY_3GPP_CLIP_LO_S     : PSY_3GPP_CLIP_LO_L;

    const float VAR_10      = VAR_4 ? PSY_3GPP_CLIP_HI_S     : PSY_3GPP_CLIP_HI_L;

    float VAR_11, VAR_12, VAR_13, VAR_14, VAR_15;



    VAR_0->VAR_15 += VAR_0->frame_bits - VAR_2;

    VAR_0->VAR_15  = av_clip(VAR_0->VAR_15, 0, VAR_3);

    VAR_15 = av_clipf((float)VAR_0->VAR_15 / VAR_3, VAR_9, VAR_10);

    VAR_11 = av_clipf(VAR_1, VAR_0->VAR_1.min, VAR_0->VAR_1.max);

    VAR_12   = (VAR_15 + VAR_6) * VAR_5;

    assert(VAR_12 <= 0.3f && VAR_12 >= -0.05000001f);

    VAR_13  = (VAR_15 + VAR_8) * VAR_7;

    assert(VAR_13 <= 0.5f && VAR_13 >= -0.1f);

    











    VAR_14 = 1.0f - VAR_12 + ((VAR_13 - VAR_12) / (VAR_0->VAR_1.max - VAR_0->VAR_1.min)) * (VAR_11 - VAR_0->VAR_1.min);

    

    VAR_0->VAR_1.max = FFMAX(VAR_1, VAR_0->VAR_1.max);

    VAR_0->VAR_1.min = FFMIN(VAR_1, VAR_0->VAR_1.min);



    return FFMIN(VAR_0->frame_bits * VAR_14, VAR_0->frame_bits + VAR_3 - VAR_2);

}

static int FUNC_0(AacPsyContext *VAR_0, float VAR_1, int VAR_2, int VAR_3,
int VAR_4)
{ const float VAR_5  = VAR_4 ? PSY_3GPP_SAVE_SLOPE_S  : PSY_3GPP_SAVE_SLOPE_L; const float VAR_6    = VAR_4 ? PSY_3GPP_SAVE_ADD_S    : PSY_3GPP_SAVE_ADD_L; const float VAR_7 = VAR_4 ? PSY_3GPP_SPEND_SLOPE_S : PSY_3GPP_SPEND_SLOPE_L; const float VAR_8   = VAR_4 ? PSY_3GPP_SPEND_ADD_S   : PSY_3GPP_SPEND_ADD_L; const float VAR_9       = VAR_4 ? PSY_3GPP_CLIP_LO_S     : PSY_3GPP_CLIP_LO_L; const float VAR_10      = VAR_4 ? PSY_3GPP_CLIP_HI_S     : PSY_3GPP_CLIP_HI_L; float VAR_11, VAR_12, VAR_13, VAR_14, VAR_15; VAR_0->VAR_15 += VAR_0->frame_bits - VAR_2; VAR_0->VAR_15  = av_clip(VAR_0->VAR_15, 0, VAR_3); VAR_15 = av_clipf((float)VAR_0->VAR_15 / VAR_3, VAR_9, VAR_10); VAR_11 = av_clipf(VAR_1, VAR_0->VAR_1.min, VAR_0->VAR_1.max); VAR_12   = (VAR_15 + VAR_6) * VAR_5; assert(VAR_12 <= 0.3f && VAR_12 >= -0.05000001f); VAR_13  = (VAR_15 + VAR_8) * VAR_7; assert(VAR_13 <= 0.5f && VAR_13 >= -0.1f); VAR_14 = 1.0f - VAR_12 + ((VAR_13 - VAR_12) / (VAR_0->VAR_1.max - VAR_0->VAR_1.min)) * (VAR_11 - VAR_0->VAR_1.min); VAR_0->VAR_1.max = FFMAX(VAR_1, VAR_0->VAR_1.max); VAR_0->VAR_1.min = FFMIN(VAR_1, VAR_0->VAR_1.min); return FFMIN(VAR_0->frame_bits * VAR_14, VAR_0->frame_bits + VAR_3 - VAR_2); }