#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double fabs(float);
int /*<<< orphan*/ quant_u_dec(int, float *, float, float, int);
void q_gain_dec(float *gain, int *gain_index, float GN_QLO, float GN_QUP,
                float GN_QLEV) {
  static float prev_gain = 0.0;
  static int prev_gain_err = 0;
  float temp, temp2;
  quant_u_dec(gain_index[1], &gain[1], GN_QLO, GN_QUP, GN_QLEV);
  if (gain_index[0] == 0) {
    if (fabs(gain[1] - prev_gain) > 5.0) {
      if (prev_gain_err == 0) {
        gain[1] = prev_gain;
      }
      prev_gain_err = 1;
    } else
      prev_gain_err = 0;
    gain[0] = 0.5 * (gain[1] + prev_gain);
  } else {
    prev_gain_err = 0;
    gain_index[0]--;
    if (prev_gain < gain[1]) {
      temp = prev_gain;
      temp2 = gain[1];
    } else {
      temp = gain[1];
      temp2 = prev_gain;
    }
    temp -= 6.0;
    temp2 += 6.0;
    if (temp < GN_QLO)
      temp = GN_QLO;
    if (temp2 > GN_QUP)
      temp2 = GN_QUP;
    quant_u_dec(gain_index[0], &gain[0], temp, temp2, 7);
  }
  prev_gain = gain[1];
}


x86 assembly (clang, -O0):
<q_gain_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movss  %xmm0,-0x14(%rbp)
movss  %xmm1,-0x18(%rbp)
movss  %xmm2,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x8(%rbp),%rsi
add    $0x4,%rsi
movss  -0x14(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
cvttss2si -0x1c(%rbp),%edx
call   1040 <quant_u_dec@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1200 <q_gain_dec+0xe0>
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
subss  0x2eb4(%rip),%xmm0
call   1030 <fabs@plt>
movsd  0xe7b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11c4 <q_gain_dec+0xa4>
cmpl   $0x0,0x2e9a(%rip)
jne    11b5 <q_gain_dec+0x95>
movss  0x2e88(%rip),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
movl   $0x1,0x2e79(%rip)
jmp    11ce <q_gain_dec+0xae>
movl   $0x0,0x2e6a(%rip)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
addss  0x2e55(%rip),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe25(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
jmp    12fa <q_gain_dec+0x1da>
movl   $0x0,0x2e2e(%rip)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
movss  0x2e17(%rip),%xmm1
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
ucomiss %xmm1,%xmm0
jbe    124f <q_gain_dec+0x12f>
movss  0x2dfd(%rip),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
movss  %xmm0,-0x24(%rbp)
jmp    126a <q_gain_dec+0x14a>
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  0x2dcf(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd85(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd67(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x20(%rbp),%xmm1
movss  -0x14(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    12c3 <q_gain_dec+0x1a3>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x24(%rbp),%xmm0
ucomiss -0x18(%rbp),%xmm0
jbe    12dc <q_gain_dec+0x1bc>
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
movss  -0x20(%rbp),%xmm0
movss  -0x24(%rbp),%xmm1
mov    $0x7,%edx
call   1040 <quant_u_dec@plt>
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
movss  %xmm0,0x2d29(%rip)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<q_gain_dec>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x4(%rsi),%edi
lea    0x4(%r15),%r14
cvttss2si %xmm2,%edx
mov    %r14,%rsi
movss  %xmm0,0x8(%rsp)
movss  %xmm1,0xc(%rsp)
call   1040 <quant_u_dec@plt>
mov    (%rbx),%edi
test   %edi,%edi
je     11b2 <q_gain_dec+0x92>
movb   $0x0,0x2edd(%rip)
add    $0xffffffff,%edi
mov    %edi,(%rbx)
movss  0x2ecc(%rip),%xmm0
movss  0x4(%r15),%xmm3
movaps %xmm0,%xmm2
minss  %xmm3,%xmm2
maxss  %xmm0,%xmm3
addss  0xe7f(%rip),%xmm2
addss  0xe7b(%rip),%xmm3
movss  0x8(%rsp),%xmm0
maxss  %xmm2,%xmm0
movss  0xc(%rsp),%xmm1
minss  %xmm3,%xmm1
mov    %r15,%rsi
mov    $0x7,%edx
call   1040 <quant_u_dec@plt>
movss  0x4(%r15),%xmm0
jmp    1212 <q_gain_dec+0xf2>
movss  (%r14),%xmm0
subss  0x2e75(%rip),%xmm0
call   1030 <fabs@plt>
ucomisd 0xe44(%rip),%xmm0
jbe    11e4 <q_gain_dec+0xc4>
cmpb   $0x0,0x2e63(%rip)
jne    11e4 <q_gain_dec+0xc4>
movss  0x2e55(%rip),%xmm1
movss  %xmm1,(%r14)
ucomisd 0xe24(%rip),%xmm0
seta   0x2e45(%rip)
movss  0x4(%r15),%xmm0
movss  0x2e33(%rip),%xmm1
addss  %xmm0,%xmm1
mulss  0xdfb(%rip),%xmm1
movss  %xmm1,(%r15)
movss  %xmm0,0x2e1a(%rip)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@q_gain_dec.prev_gain = internal global float 0.000000e+00
@q_gain_dec.prev_gain_err = internal global i32 0
define void @q_gain_dec(float* %0, i32* %1, float %2, float %3, float %4) {
%6 = alloca float*
%7 = alloca i32*
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
store float* %0, float** %6
store i32* %1, i32** %7
store float %2, float* %8
store float %3, float* %9
store float %4, float* %10
%13 = load i32*, i32** %7
%14 = getelementptr inbounds i32, i32* %13, i64 1
%15 = load i32, i32* %14
%16 = load float*, float** %6
%17 = getelementptr inbounds float, float* %16, i64 1
%18 = load float, float* %8
%19 = load float, float* %9
%20 = load float, float* %10
%21 = fptosi float %20 to i32
%22 = call i32 @quant_u_dec(i32 %15, float* %17, float %18, float %19, i32 %21)
%23 = load i32*, i32** %7
%24 = getelementptr inbounds i32, i32* %23, i64 0
%25 = load i32, i32* %24
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %55
27: ; preds = %5
%28 = load float*, float** %6
%29 = getelementptr inbounds float, float* %28, i64 1
%30 = load float, float* %29
%31 = load float, float* @q_gain_dec.prev_gain
%32 = fsub float %30, %31
%33 = call double @fabs(float %32)
%34 = fcmp ogt double %33, 5.000000e+00
br i1 %34, label %35, label %43
35: ; preds = %27
%36 = load i32, i32* @q_gain_dec.prev_gain_err
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load float, float* @q_gain_dec.prev_gain
%40 = load float*, float** %6
%41 = getelementptr inbounds float, float* %40, i64 1
store float %39, float* %41
br label %42
42: ; preds = %38, %35
store i32 1, i32* @q_gain_dec.prev_gain_err
br label %44
43: ; preds = %27
store i32 0, i32* @q_gain_dec.prev_gain_err
br label %44
44: ; preds = %43, %42
%45 = load float*, float** %6
%46 = getelementptr inbounds float, float* %45, i64 1
%47 = load float, float* %46
%48 = load float, float* @q_gain_dec.prev_gain
%49 = fadd float %47, %48
%50 = fpext float %49 to double
%51 = fmul double 5.000000e-01, %50
%52 = fptrunc double %51 to float
%53 = load float*, float** %6
%54 = getelementptr inbounds float, float* %53, i64 0
store float %52, float* %54
br label %104
55: ; preds = %5
store i32 0, i32* @q_gain_dec.prev_gain_err
%56 = load i32*, i32** %7
%57 = getelementptr inbounds i32, i32* %56, i64 0
%58 = load i32, i32* %57
%59 = add nsw i32 %58, -1
store i32 %59, i32* %57
%60 = load float, float* @q_gain_dec.prev_gain
%61 = load float*, float** %6
%62 = getelementptr inbounds float, float* %61, i64 1
%63 = load float, float* %62
%64 = fcmp olt float %60, %63
br i1 %64, label %65, label %70
65: ; preds = %55
%66 = load float, float* @q_gain_dec.prev_gain
store float %66, float* %11
%67 = load float*, float** %6
%68 = getelementptr inbounds float, float* %67, i64 1
%69 = load float, float* %68
store float %69, float* %12
br label %75
70: ; preds = %55
%71 = load float*, float** %6
%72 = getelementptr inbounds float, float* %71, i64 1
%73 = load float, float* %72
store float %73, float* %11
%74 = load float, float* @q_gain_dec.prev_gain
store float %74, float* %12
br label %75
75: ; preds = %70, %65
%76 = load float, float* %11
%77 = fpext float %76 to double
%78 = fsub double %77, 6.000000e+00
%79 = fptrunc double %78 to float
store float %79, float* %11
%80 = load float, float* %12
%81 = fpext float %80 to double
%82 = fadd double %81, 6.000000e+00
%83 = fptrunc double %82 to float
store float %83, float* %12
%84 = load float, float* %11
%85 = load float, float* %8
%86 = fcmp olt float %84, %85
br i1 %86, label %87, label %89
87: ; preds = %75
%88 = load float, float* %8
store float %88, float* %11
br label %89
89: ; preds = %87, %75
%90 = load float, float* %12
%91 = load float, float* %9
%92 = fcmp ogt float %90, %91
br i1 %92, label %93, label %95
93: ; preds = %89
%94 = load float, float* %9
store float %94, float* %12
br label %95
95: ; preds = %93, %89
%96 = load i32*, i32** %7
%97 = getelementptr inbounds i32, i32* %96, i64 0
%98 = load i32, i32* %97
%99 = load float*, float** %6
%100 = getelementptr inbounds float, float* %99, i64 0
%101 = load float, float* %11
%102 = load float, float* %12
%103 = call i32 @quant_u_dec(i32 %98, float* %100, float %101, float %102, i32 7)
br label %104
104: ; preds = %95, %44
%105 = load float*, float** %6
%106 = getelementptr inbounds float, float* %105, i64 1
%107 = load float, float* %106
store float %107, float* @q_gain_dec.prev_gain
ret void
}

LLVM IR (-O2):
@q_gain_dec.prev_gain = internal unnamed_addr global float 0.000000e+00
@q_gain_dec.prev_gain_err = internal unnamed_addr global i1 false
define void @q_gain_dec(float* %0, i32* nocapture %1, float %2, float %3, float %4) {
%6 = getelementptr inbounds i32, i32* %1, i64 1
%7 = load i32, i32* %6
%8 = getelementptr inbounds float, float* %0, i64 1
%9 = fptosi float %4 to i32
%10 = tail call i32 @quant_u_dec(i32 %7, float* %8, float %2, float %3, i32 %9)
%11 = load i32, i32* %1
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %5
%14 = load float, float* %8
%15 = load float, float* @q_gain_dec.prev_gain
%16 = fsub float %14, %15
%17 = tail call double @fabs(float %16)
%18 = fcmp ogt double %17, 5.000000e+00
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = load i1, i1* @q_gain_dec.prev_gain_err
br i1 %20, label %23, label %21
21: ; preds = %19
%22 = load float, float* @q_gain_dec.prev_gain
store float %22, float* %8
br label %23
23: ; preds = %13, %19, %21
store i1 %18, i1* @q_gain_dec.prev_gain_err
%24 = load float, float* %8
%25 = load float, float* @q_gain_dec.prev_gain
%26 = fadd float %24, %25
%27 = fmul float %26, 5.000000e-01
store float %27, float* %0
br label %43
28: ; preds = %5
store i1 false, i1* @q_gain_dec.prev_gain_err
%29 = add nsw i32 %11, -1
store i32 %29, i32* %1
%30 = load float, float* @q_gain_dec.prev_gain
%31 = load float, float* %8
%32 = fcmp olt float %30, %31
%33 = select i1 %32, float %30, float %31
%34 = select i1 %32, float %31, float %30
%35 = fadd float %33, -6.000000e+00
%36 = fadd float %34, 6.000000e+00
%37 = fcmp olt float %35, %2
%38 = select i1 %37, float %2, float %35
%39 = fcmp ogt float %36, %3
%40 = select i1 %39, float %3, float %36
%41 = tail call i32 @quant_u_dec(i32 %29, float* %0, float %38, float %40, i32 7)
%42 = load float, float* %8
br label %43
43: ; preds = %28, %23
%44 = phi float [ %42, %28 ], [ %24, %23 ]
store float %44, float* @q_gain_dec.prev_gain
ret void
}