#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(float *, int *, float, float, int);
void q_gain(float *gain, int *gain_index, float GN_QLO, float GN_QUP,
            float GN_QLEV) {
  static float prev_gain = 0.0;
  float temp, temp2;
  quant_u(&gain[1], &gain_index[1], GN_QLO, GN_QUP, GN_QLEV);
  if (gain[0] < GN_QLO)
    gain[0] = GN_QLO;
  if (gain[0] > GN_QUP)
    gain[0] = GN_QUP;
  if (fabs(gain[1] - prev_gain) < 5.0 &&
      fabs(gain[0] - 0.5 * (gain[1] + prev_gain)) < 3.0) {
    gain[0] = 0.5 * (gain[1] + prev_gain);
    gain_index[0] = 0;
  } else {
    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(&gain[0], &gain_index[0], temp, temp2, 7);
    gain_index[0]++;
  }
  prev_gain = gain[1];
}


x86 assembly (clang, -O0):
<q_gain>:
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    -0x8(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
movss  -0x14(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
cvttss2si -0x1c(%rbp),%edx
call   1040 <quant_u@plt>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm1
movss  -0x14(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    1186 <q_gain+0x66>
movss  -0x14(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
ucomiss -0x18(%rbp),%xmm0
jbe    11a5 <q_gain+0x85>
movss  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
subss  0x2e7e(%rip),%xmm0
call   1030 <fabs@plt>
movaps %xmm0,%xmm1
movsd  0xe3a(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    125b <q_gain+0x13b>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
addss  0x2e47(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe17(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1030 <fabs@plt>
movaps %xmm0,%xmm1
movsd  0xdf3(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    125b <q_gain+0x13b>
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
addss  0x2e04(%rip),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xde4(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
jmp    1349 <q_gain+0x229>
movss  0x2dd1(%rip),%xmm1
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
ucomiss %xmm1,%xmm0
jbe    1295 <q_gain+0x175>
movss  0x2db7(%rip),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
movss  %xmm0,-0x24(%rbp)
jmp    12b0 <q_gain+0x190>
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  0x2d89(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd57(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd39(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x20(%rbp),%xmm1
movss  -0x14(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    1309 <q_gain+0x1e9>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x24(%rbp),%xmm0
ucomiss -0x18(%rbp),%xmm0
jbe    1322 <q_gain+0x202>
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movss  -0x20(%rbp),%xmm0
movss  -0x24(%rbp),%xmm1
mov    $0x7,%edx
call   1040 <quant_u@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
movss  %xmm0,0x2cda(%rip)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<q_gain>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movss  %xmm1,0xc(%rsp)
movss  %xmm0,0x8(%rsp)
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x4(%rdi),%r15
add    $0x4,%rsi
cvttss2si %xmm2,%edx
mov    %r15,%rdi
call   1040 <quant_u@plt>
movss  0xc(%rsp),%xmm2
movss  (%rbx),%xmm1
movss  0x8(%rsp),%xmm0
ucomiss %xmm1,%xmm0
maxss  %xmm1,%xmm0
ja     116d <q_gain+0x4d>
ucomiss %xmm2,%xmm0
jbe    1178 <q_gain+0x58>
movaps %xmm2,%xmm1
minss  %xmm0,%xmm1
movss  %xmm1,(%rbx)
movss  (%r15),%xmm0
subss  0x2eaf(%rip),%xmm0
call   1030 <fabs@plt>
movsd  0xe6e(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11f5 <q_gain+0xd5>
movss  0x4(%rbx),%xmm0
addss  0x2e8f(%rip),%xmm0
movss  (%rbx),%xmm1
cvtss2sd %xmm0,%xmm0
mulsd  0xe53(%rip),%xmm0
cvtss2sd %xmm1,%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1030 <fabs@plt>
movsd  0xe42(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11f5 <q_gain+0xd5>
movss  0x4(%rbx),%xmm0
movss  0x2e53(%rip),%xmm1
addss  %xmm0,%xmm1
mulss  0xe33(%rip),%xmm1
movss  %xmm1,(%rbx)
xor    %eax,%eax
jmp    124c <q_gain+0x12c>
movss  0x2e37(%rip),%xmm0
movss  0x4(%rbx),%xmm3
movaps %xmm0,%xmm2
minss  %xmm3,%xmm2
maxss  %xmm0,%xmm3
addss  0xe03(%rip),%xmm2
addss  0xdff(%rip),%xmm3
movss  0x8(%rsp),%xmm0
maxss  %xmm2,%xmm0
movss  0xc(%rsp),%xmm1
minss  %xmm3,%xmm1
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x7,%edx
call   1040 <quant_u@plt>
mov    (%r14),%eax
add    $0x1,%eax
movss  0x4(%rbx),%xmm0
mov    %eax,(%r14)
movss  %xmm0,0x2ddd(%rip)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@q_gain.prev_gain = internal global float 0.000000e+00
define void @q_gain(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 float*, float** %6
%14 = getelementptr inbounds float, float* %13, i64 1
%15 = load i32*, i32** %7
%16 = getelementptr inbounds i32, i32* %15, i64 1
%17 = load float, float* %8
%18 = load float, float* %9
%19 = load float, float* %10
%20 = fptosi float %19 to i32
%21 = call i32 @quant_u(float* %14, i32* %16, float %17, float %18, i32 %20)
%22 = load float*, float** %6
%23 = getelementptr inbounds float, float* %22, i64 0
%24 = load float, float* %23
%25 = load float, float* %8
%26 = fcmp olt float %24, %25
br i1 %26, label %27, label %31
27: ; preds = %5
%28 = load float, float* %8
%29 = load float*, float** %6
%30 = getelementptr inbounds float, float* %29, i64 0
store float %28, float* %30
br label %31
31: ; preds = %27, %5
%32 = load float*, float** %6
%33 = getelementptr inbounds float, float* %32, i64 0
%34 = load float, float* %33
%35 = load float, float* %9
%36 = fcmp ogt float %34, %35
br i1 %36, label %37, label %41
37: ; preds = %31
%38 = load float, float* %9
%39 = load float*, float** %6
%40 = getelementptr inbounds float, float* %39, i64 0
store float %38, float* %40
br label %41
41: ; preds = %37, %31
%42 = load float*, float** %6
%43 = getelementptr inbounds float, float* %42, i64 1
%44 = load float, float* %43
%45 = load float, float* @q_gain.prev_gain
%46 = fsub float %44, %45
%47 = call double @fabs(float %46)
%48 = fcmp olt double %47, 5.000000e+00
br i1 %48, label %49, label %77
49: ; preds = %41
%50 = load float*, float** %6
%51 = getelementptr inbounds float, float* %50, i64 0
%52 = load float, float* %51
%53 = fpext float %52 to double
%54 = load float*, float** %6
%55 = getelementptr inbounds float, float* %54, i64 1
%56 = load float, float* %55
%57 = load float, float* @q_gain.prev_gain
%58 = fadd float %56, %57
%59 = fpext float %58 to double
%60 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %59, double %53)
%61 = fptrunc double %60 to float
%62 = call double @fabs(float %61)
%63 = fcmp olt double %62, 3.000000e+00
br i1 %63, label %64, label %77
64: ; preds = %49
%65 = load float*, float** %6
%66 = getelementptr inbounds float, float* %65, i64 1
%67 = load float, float* %66
%68 = load float, float* @q_gain.prev_gain
%69 = fadd float %67, %68
%70 = fpext float %69 to double
%71 = fmul double 5.000000e-01, %70
%72 = fptrunc double %71 to float
%73 = load float*, float** %6
%74 = getelementptr inbounds float, float* %73, i64 0
store float %72, float* %74
%75 = load i32*, i32** %7
%76 = getelementptr inbounds i32, i32* %75, i64 0
store i32 0, i32* %76
br label %125
77: ; preds = %49, %41
%78 = load float, float* @q_gain.prev_gain
%79 = load float*, float** %6
%80 = getelementptr inbounds float, float* %79, i64 1
%81 = load float, float* %80
%82 = fcmp olt float %78, %81
br i1 %82, label %83, label %88
83: ; preds = %77
%84 = load float, float* @q_gain.prev_gain
store float %84, float* %11
%85 = load float*, float** %6
%86 = getelementptr inbounds float, float* %85, i64 1
%87 = load float, float* %86
store float %87, float* %12
br label %93
88: ; preds = %77
%89 = load float*, float** %6
%90 = getelementptr inbounds float, float* %89, i64 1
%91 = load float, float* %90
store float %91, float* %11
%92 = load float, float* @q_gain.prev_gain
store float %92, float* %12
br label %93
93: ; preds = %88, %83
%94 = load float, float* %11
%95 = fpext float %94 to double
%96 = fsub double %95, 6.000000e+00
%97 = fptrunc double %96 to float
store float %97, float* %11
%98 = load float, float* %12
%99 = fpext float %98 to double
%100 = fadd double %99, 6.000000e+00
%101 = fptrunc double %100 to float
store float %101, float* %12
%102 = load float, float* %11
%103 = load float, float* %8
%104 = fcmp olt float %102, %103
br i1 %104, label %105, label %107
105: ; preds = %93
%106 = load float, float* %8
store float %106, float* %11
br label %107
107: ; preds = %105, %93
%108 = load float, float* %12
%109 = load float, float* %9
%110 = fcmp ogt float %108, %109
br i1 %110, label %111, label %113
111: ; preds = %107
%112 = load float, float* %9
store float %112, float* %12
br label %113
113: ; preds = %111, %107
%114 = load float*, float** %6
%115 = getelementptr inbounds float, float* %114, i64 0
%116 = load i32*, i32** %7
%117 = getelementptr inbounds i32, i32* %116, i64 0
%118 = load float, float* %11
%119 = load float, float* %12
%120 = call i32 @quant_u(float* %115, i32* %117, float %118, float %119, i32 7)
%121 = load i32*, i32** %7
%122 = getelementptr inbounds i32, i32* %121, i64 0
%123 = load i32, i32* %122
%124 = add nsw i32 %123, 1
store i32 %124, i32* %122
br label %125
125: ; preds = %113, %64
%126 = load float*, float** %6
%127 = getelementptr inbounds float, float* %126, i64 1
%128 = load float, float* %127
store float %128, float* @q_gain.prev_gain
ret void
}

LLVM IR (-O2):
@q_gain.prev_gain = internal unnamed_addr global float 0.000000e+00
define void @q_gain(float* %0, i32* %1, float %2, float %3, float %4) {
%6 = getelementptr inbounds float, float* %0, i64 1
%7 = getelementptr inbounds i32, i32* %1, i64 1
%8 = fptosi float %4 to i32
%9 = tail call i32 @quant_u(float* %6, i32* %7, float %2, float %3, i32 %8)
%10 = load float, float* %0
%11 = fcmp olt float %10, %2
%12 = select i1 %11, float %2, float %10
%13 = fcmp ogt float %12, %3
%14 = or i1 %11, %13
br i1 %14, label %15, label %17
15: ; preds = %5
%16 = select i1 %13, float %3, float %12
store float %16, float* %0
br label %17
17: ; preds = %5, %15
%18 = load float, float* %6
%19 = load float, float* @q_gain.prev_gain
%20 = fsub float %18, %19
%21 = tail call double @fabs(float %20)
%22 = fcmp olt double %21, 5.000000e+00
br i1 %22, label %23, label %39
23: ; preds = %17
%24 = load float, float* %0
%25 = fpext float %24 to double
%26 = load float, float* %6
%27 = load float, float* @q_gain.prev_gain
%28 = fadd float %26, %27
%29 = fpext float %28 to double
%30 = tail call double @llvm.fmuladd.f64(double %29, double -5.000000e-01, double %25)
%31 = fptrunc double %30 to float
%32 = tail call double @fabs(float %31)
%33 = fcmp olt double %32, 3.000000e+00
br i1 %33, label %34, label %39
34: ; preds = %23
%35 = load float, float* %6
%36 = load float, float* @q_gain.prev_gain
%37 = fadd float %35, %36
%38 = fmul float %37, 5.000000e-01
store float %38, float* %0
br label %55
39: ; preds = %23, %17
%40 = load float, float* @q_gain.prev_gain
%41 = load float, float* %6
%42 = fcmp olt float %40, %41
%43 = select i1 %42, float %40, float %41
%44 = select i1 %42, float %41, float %40
%45 = fadd float %43, -6.000000e+00
%46 = fadd float %44, 6.000000e+00
%47 = fcmp olt float %45, %2
%48 = select i1 %47, float %2, float %45
%49 = fcmp ogt float %46, %3
%50 = select i1 %49, float %3, float %46
%51 = tail call i32 @quant_u(float* %0, i32* %1, float %48, float %50, i32 7)
%52 = load i32, i32* %1
%53 = add nsw i32 %52, 1
%54 = load float, float* %6
br label %55
55: ; preds = %39, %34
%56 = phi float [ %54, %39 ], [ %35, %34 ]
%57 = phi i32 [ %53, %39 ], [ 0, %34 ]
store i32 %57, i32* %1
store float %56, float* @q_gain.prev_gain
ret void
}