#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);
float filter_bin(float, float, float const);
void gain_adjust_bins(float bins[4], float filter_state[4], float gains[4]) {
  const float cutoffs[4] = {0.02, 0.02, 0.02, 0.02};
  const float act_goal[4] = {0.4, 0.5, 0.4, 0.6};
  for (int i = 0; i < 4; i++) {
    bins[i] *= gains[i];
    filter_state[i] = filter_bin(bins[i], filter_state[i], cutoffs[i]);
    float update = (act_goal[i] - filter_state[i]) / fabs(filter_state[i]);
    float edgegain = 1;
    if (bins[i] > 1 || bins[i] <= 0)
      edgegain = 50;
    if (fabs(update) > 0.05)
      gains[i] += 0.001 * update * edgegain;
    if (gains[i] > 22.0)
      gains[i] = 22.0;
  }
}


x86 assembly (clang, -O0):
<gain_adjust_bins>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0xef5(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xef2(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeef(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xeec(%rip),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x4,-0x44(%rbp)
jge    1301 <gain_adjust_bins+0x1e1>
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
mulss  (%rax,%rcx,4),%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
movslq -0x44(%rbp),%rax
movss  -0x30(%rbp,%rax,4),%xmm2
call   1040 <filter_bin@plt>
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
movslq -0x44(%rbp),%rax
movss  -0x40(%rbp,%rax,4),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
subss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1030 <fabs@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x48(%rbp)
movss  0xdeb(%rip),%xmm0
movss  %xmm0,-0x4c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  0xdd1(%rip),%xmm1
ucomiss %xmm1,%xmm0
ja     124d <gain_adjust_bins+0x12d>
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
xorps  %xmm0,%xmm0
ucomiss (%rax,%rcx,4),%xmm0
jb     125a <gain_adjust_bins+0x13a>
movss  0xdaf(%rip),%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x48(%rbp),%xmm0
call   1030 <fabs@plt>
movsd  0xda4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12b6 <gain_adjust_bins+0x196>
movss  -0x48(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd91(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x4c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm2
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd51(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12ee <gain_adjust_bins+0x1ce>
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
movss  0xd1f(%rip),%xmm0
movss  %xmm0,(%rax,%rcx,4)
jmp    12f3 <gain_adjust_bins+0x1d3>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1167 <gain_adjust_bins+0x47>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gain_adjust_bins>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
xor    %ebx,%ebx
lea    0xf00(%rip),%r13
lea    0xf09(%rip),%rbp
jmp    115e <gain_adjust_bins+0x3e>
nopl   0x0(%rax)
add    $0x4,%rbx
cmp    $0x10,%rbx
je     1270 <gain_adjust_bins+0x150>
movss  (%r15,%rbx,1),%xmm0
mulss  (%r12,%rbx,1),%xmm0
movss  %xmm0,(%r12,%rbx,1)
movss  (%r14,%rbx,1),%xmm1
movss  (%rbx,%r13,1),%xmm2
call   1040 <filter_bin@plt>
movss  %xmm0,(%r14,%rbx,1)
movss  (%rbx,%rbp,1),%xmm1
subss  %xmm0,%xmm1
cvtss2sd %xmm1,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1030 <fabs@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  (%r12,%rbx,1),%xmm0
movss  %xmm0,0x8(%rsp)
movss  %xmm1,0x14(%rsp)
movaps %xmm1,%xmm0
call   1030 <fabs@plt>
ucomisd 0xe31(%rip),%xmm0
jbe    1200 <gain_adjust_bins+0xe0>
movss  0x14(%rsp),%xmm1
xor    %eax,%eax
xorps  %xmm0,%xmm0
movss  0x8(%rsp),%xmm2
ucomiss %xmm2,%xmm0
setb   %cl
ucomiss 0xe29(%rip),%xmm2
jbe    1220 <gain_adjust_bins+0x100>
movsd  0xe0f(%rip),%xmm0
jmp    122e <gain_adjust_bins+0x10e>
nopl   0x0(%rax,%rax,1)
movss  (%r15,%rbx,1),%xmm0
ucomiss 0xe0f(%rip),%xmm0
jbe    1150 <gain_adjust_bins+0x30>
jmp    1263 <gain_adjust_bins+0x143>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %cl,%al
lea    0xe07(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
cvtss2sd %xmm1,%xmm1
mulsd  0xdd6(%rip),%xmm1
mulsd  %xmm0,%xmm1
movss  (%r15,%rbx,1),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%r15,%rbx,1)
ucomiss 0xdbf(%rip),%xmm0
jbe    1150 <gain_adjust_bins+0x30>
movl   $0x41b00000,(%r15,%rbx,1)
41
jmp    1150 <gain_adjust_bins+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.gain_adjust_bins.cutoffs = [4 x float] [float 0x3F947AE140000000, float 0x3F947AE140000000, float 0x3F947AE140000000, float 0x3F947AE140000000]
@__const.gain_adjust_bins.act_goal = [4 x float] [float 0x3FD99999A0000000, float 5.000000e-01, float 0x3FD99999A0000000, float 0x3FE3333340000000]
define void @gain_adjust_bins(float* %0, float* %1, float* %2) {
%4 = alloca float*
%5 = alloca float*
%6 = alloca float*
%7 = alloca [4 x float]
%8 = alloca [4 x float]
%9 = alloca i32
%10 = alloca float
%11 = alloca float
store float* %0, float** %4
store float* %1, float** %5
store float* %2, float** %6
%12 = bitcast [4 x float]* %7 to i8*
%13 = bitcast [4 x float]* %8 to i8*
store i32 0, i32* %9
br label %14
14: ; preds = %113, %3
%15 = load i32, i32* %9
%16 = icmp slt i32 %15, 4
br i1 %16, label %17, label %116
17: ; preds = %14
%18 = load float*, float** %6
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds float, float* %18, i64 %20
%22 = load float, float* %21
%23 = load float*, float** %4
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds float, float* %23, i64 %25
%27 = load float, float* %26
%28 = fmul float %27, %22
store float %28, float* %26
%29 = load float*, float** %4
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds float, float* %29, i64 %31
%33 = load float, float* %32
%34 = load float*, float** %5
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds float, float* %34, i64 %36
%38 = load float, float* %37
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [4 x float], [4 x float]* %7, i64 0, i64 %40
%42 = load float, float* %41
%43 = call float @filter_bin(float %33, float %38, float %42)
%44 = load float*, float** %5
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds float, float* %44, i64 %46
store float %43, float* %47
%48 = load i32, i32* %9
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [4 x float], [4 x float]* %8, i64 0, i64 %49
%51 = load float, float* %50
%52 = load float*, float** %5
%53 = load i32, i32* %9
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds float, float* %52, i64 %54
%56 = load float, float* %55
%57 = fsub float %51, %56
%58 = fpext float %57 to double
%59 = load float*, float** %5
%60 = load i32, i32* %9
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds float, float* %59, i64 %61
%63 = load float, float* %62
%64 = call double @fabs(float %63)
%65 = fdiv double %58, %64
%66 = fptrunc double %65 to float
store float %66, float* %10
store float 1.000000e+00, float* %11
%67 = load float*, float** %4
%68 = load i32, i32* %9
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds float, float* %67, i64 %69
%71 = load float, float* %70
%72 = fcmp ogt float %71, 1.000000e+00
br i1 %72, label %80, label %73
73: ; preds = %17
%74 = load float*, float** %4
%75 = load i32, i32* %9
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds float, float* %74, i64 %76
%78 = load float, float* %77
%79 = fcmp ole float %78, 0.000000e+00
br i1 %79, label %80, label %81
80: ; preds = %73, %17
store float 5.000000e+01, float* %11
br label %81
81: ; preds = %80, %73
%82 = load float, float* %10
%83 = call double @fabs(float %82)
%84 = fcmp ogt double %83, 5.000000e-02
br i1 %84, label %85, label %99
85: ; preds = %81
%86 = load float, float* %10
%87 = fpext float %86 to double
%88 = fmul double 1.000000e-03, %87
%89 = load float, float* %11
%90 = fpext float %89 to double
%91 = load float*, float** %6
%92 = load i32, i32* %9
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds float, float* %91, i64 %93
%95 = load float, float* %94
%96 = fpext float %95 to double
%97 = call double @llvm.fmuladd.f64(double %88, double %90, double %96)
%98 = fptrunc double %97 to float
store float %98, float* %94
br label %99
99: ; preds = %85, %81
%100 = load float*, float** %6
%101 = load i32, i32* %9
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds float, float* %100, i64 %102
%104 = load float, float* %103
%105 = fpext float %104 to double
%106 = fcmp ogt double %105, 2.200000e+01
br i1 %106, label %107, label %112
107: ; preds = %99
%108 = load float*, float** %6
%109 = load i32, i32* %9
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds float, float* %108, i64 %110
store float 2.200000e+01, float* %111
br label %112
112: ; preds = %107, %99
br label %113
113: ; preds = %112
%114 = load i32, i32* %9
%115 = add nsw i32 %114, 1
store i32 %115, i32* %9
br label %14
116: ; preds = %14
ret void
}

LLVM IR (-O2):
@__const.gain_adjust_bins.cutoffs = [4 x float] [float 0x3F947AE140000000, float 0x3F947AE140000000, float 0x3F947AE140000000, float 0x3F947AE140000000]
@__const.gain_adjust_bins.act_goal = [4 x float] [float 0x3FD99999A0000000, float 5.000000e-01, float 0x3FD99999A0000000, float 0x3FE3333340000000]
define void @gain_adjust_bins(float* nocapture %0, float* nocapture %1, float* nocapture %2) {
br label %5
4: ; preds = %44
ret void
5: ; preds = %3, %44
%6 = phi i64 [ 0, %3 ], [ %45, %44 ]
%7 = getelementptr inbounds float, float* %2, i64 %6
%8 = load float, float* %7
%9 = getelementptr inbounds float, float* %0, i64 %6
%10 = load float, float* %9
%11 = fmul float %8, %10
store float %11, float* %9
%12 = getelementptr inbounds float, float* %1, i64 %6
%13 = load float, float* %12
%14 = getelementptr inbounds [4 x float], [4 x float]* @__const.gain_adjust_bins.cutoffs, i64 0, i64 %6
%15 = load float, float* %14
%16 = tail call float @filter_bin(float %11, float %13, float %15)
store float %16, float* %12
%17 = getelementptr inbounds [4 x float], [4 x float]* @__const.gain_adjust_bins.act_goal, i64 0, i64 %6
%18 = load float, float* %17
%19 = fsub float %18, %16
%20 = fpext float %19 to double
%21 = tail call double @fabs(float %16)
%22 = fdiv double %20, %21
%23 = fptrunc double %22 to float
%24 = load float, float* %9
%25 = tail call double @fabs(float %23)
%26 = fcmp ogt double %25, 5.000000e-02
br i1 %26, label %27, label %38
27: ; preds = %5
%28 = fcmp ule float %24, 1.000000e+00
%29 = fcmp ugt float %24, 0.000000e+00
%30 = and i1 %28, %29
%31 = select i1 %30, double 1.000000e+00, double 5.000000e+01
%32 = fpext float %23 to double
%33 = fmul double %32, 1.000000e-03
%34 = load float, float* %7
%35 = fpext float %34 to double
%36 = tail call double @llvm.fmuladd.f64(double %33, double %31, double %35)
%37 = fptrunc double %36 to float
store float %37, float* %7
br label %40
38: ; preds = %5
%39 = load float, float* %7
br label %40
40: ; preds = %38, %27
%41 = phi float [ %39, %38 ], [ %37, %27 ]
%42 = fcmp ogt float %41, 2.200000e+01
br i1 %42, label %43, label %44
43: ; preds = %40
store float 2.200000e+01, float* %7
br label %44
44: ; preds = %43, %40
%45 = add nuw nsw i64 %6, 1
%46 = icmp eq i64 %45, 4
br i1 %46, label %4, label %5
}