#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);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
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.3, 0.3, 0.3, 0.4};
  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;
    fprintf(stderr, "%.2f ", gains[i]);
  }
  fprintf(stderr, "    ");
}


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    0xee5(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xee2(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xedf(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xedc(%rip),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x4,-0x44(%rbp)
jge    1334 <gain_adjust_bins+0x204>
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   1050 <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  0xddb(%rip),%xmm0
movss  %xmm0,-0x4c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  0xdc1(%rip),%xmm1
ucomiss %xmm1,%xmm0
ja     125d <gain_adjust_bins+0x12d>
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
xorps  %xmm0,%xmm0
ucomiss (%rax,%rcx,4),%xmm0
jb     126a <gain_adjust_bins+0x13a>
movss  0xd9f(%rip),%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x48(%rbp),%xmm0
call   1030 <fabs@plt>
movsd  0xd94(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12c6 <gain_adjust_bins+0x196>
movss  -0x48(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd81(%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  0xd41(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12fe <gain_adjust_bins+0x1ce>
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
movss  0xd0f(%rip),%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd31(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1177 <gain_adjust_bins+0x47>
mov    0x2ca5(%rip),%rax
mov    (%rax),%edi
lea    0xd12(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
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,%r13
xor    %ebx,%ebx
mov    0x2e90(%rip),%rbp
lea    0xf09(%rip),%r12
jmp    117f <gain_adjust_bins+0x4f>
nopl   0x0(%rax)
mov    0x0(%rbp),%edi
cvtss2sd %xmm0,%xmm0
mov    %r12,%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
add    $0x4,%rbx
cmp    $0x10,%rbx
je     12a8 <gain_adjust_bins+0x178>
movss  (%r15,%rbx,1),%xmm0
mulss  0x0(%r13,%rbx,1),%xmm0
movss  %xmm0,0x0(%r13,%rbx,1)
movss  (%r14,%rbx,1),%xmm1
lea    0xea0(%rip),%rax
movss  (%rbx,%rax,1),%xmm2
call   1050 <filter_bin@plt>
movss  %xmm0,(%r14,%rbx,1)
lea    0xe99(%rip),%rax
movss  (%rbx,%rax,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  0x0(%r13,%rbx,1),%xmm0
movss  %xmm0,0x8(%rsp)
movss  %xmm1,0x14(%rsp)
movaps %xmm1,%xmm0
call   1030 <fabs@plt>
ucomisd 0xe00(%rip),%xmm0
jbe    1230 <gain_adjust_bins+0x100>
movss  0x14(%rsp),%xmm1
xor    %eax,%eax
xorps  %xmm0,%xmm0
movss  0x8(%rsp),%xmm2
ucomiss %xmm2,%xmm0
setb   %cl
ucomiss 0xdf8(%rip),%xmm2
jbe    1250 <gain_adjust_bins+0x120>
movsd  0xdde(%rip),%xmm0
jmp    125e <gain_adjust_bins+0x12e>
nopl   0x0(%rax)
movss  (%r15,%rbx,1),%xmm0
ucomiss 0xddf(%rip),%xmm0
jbe    1160 <gain_adjust_bins+0x30>
jmp    1293 <gain_adjust_bins+0x163>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %cl,%al
lea    0xdd7(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
cvtss2sd %xmm1,%xmm1
mulsd  0xda6(%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 0xd8f(%rip),%xmm0
jbe    1160 <gain_adjust_bins+0x30>
movl   $0x41b00000,(%r15,%rbx,1)
41
movss  0xd79(%rip),%xmm0
jmp    1160 <gain_adjust_bins+0x30>
mov    0x0(%rbp),%edi
lea    0xdb4(%rip),%rsi
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fprintf@plt>

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 0x3FD3333340000000, float 0x3FD3333340000000, float 0x3FD3333340000000, float 0x3FD99999A0000000]
@stderr = global i32 0
@.str = [6 x i8] c"%.2f \00"
@.str.1 = [5 x i8] c" \00"
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 = %121, %3
%15 = load i32, i32* %9
%16 = icmp slt i32 %15, 4
br i1 %16, label %17, label %124
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
%113 = load i32, i32* @stderr
%114 = load float*, float** %6
%115 = load i32, i32* %9
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds float, float* %114, i64 %116
%118 = load float, float* %117
%119 = fpext float %118 to double
%120 = call i32 (i32, i8*, ...) @fprintf(i32 %113, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %119)
br label %121
121: ; preds = %112
%122 = load i32, i32* %9
%123 = add nsw i32 %122, 1
store i32 %123, i32* %9
br label %14
124: ; preds = %14
%125 = load i32, i32* @stderr
%126 = call i32 (i32, i8*, ...) @fprintf(i32 %125, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
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 0x3FD3333340000000, float 0x3FD3333340000000, float 0x3FD3333340000000, float 0x3FD99999A0000000]
@stderr = global i32 0
@.str = [6 x i8] c"%.2f \00"
@.str.1 = [5 x i8] c" \00"
define void @gain_adjust_bins(float* nocapture %0, float* nocapture %1, float* nocapture %2) {
br label %7
4: ; preds = %46
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
ret void
7: ; preds = %3, %46
%8 = phi i64 [ 0, %3 ], [ %51, %46 ]
%9 = getelementptr inbounds float, float* %2, i64 %8
%10 = load float, float* %9
%11 = getelementptr inbounds float, float* %0, i64 %8
%12 = load float, float* %11
%13 = fmul float %10, %12
store float %13, float* %11
%14 = getelementptr inbounds float, float* %1, i64 %8
%15 = load float, float* %14
%16 = getelementptr inbounds [4 x float], [4 x float]* @__const.gain_adjust_bins.cutoffs, i64 0, i64 %8
%17 = load float, float* %16
%18 = tail call float @filter_bin(float %13, float %15, float %17)
store float %18, float* %14
%19 = getelementptr inbounds [4 x float], [4 x float]* @__const.gain_adjust_bins.act_goal, i64 0, i64 %8
%20 = load float, float* %19
%21 = fsub float %20, %18
%22 = fpext float %21 to double
%23 = tail call double @fabs(float %18)
%24 = fdiv double %22, %23
%25 = fptrunc double %24 to float
%26 = load float, float* %11
%27 = tail call double @fabs(float %25)
%28 = fcmp ogt double %27, 5.000000e-02
br i1 %28, label %29, label %40
29: ; preds = %7
%30 = fcmp ule float %26, 1.000000e+00
%31 = fcmp ugt float %26, 0.000000e+00
%32 = and i1 %30, %31
%33 = select i1 %32, double 1.000000e+00, double 5.000000e+01
%34 = fpext float %25 to double
%35 = fmul double %34, 1.000000e-03
%36 = load float, float* %9
%37 = fpext float %36 to double
%38 = tail call double @llvm.fmuladd.f64(double %35, double %33, double %37)
%39 = fptrunc double %38 to float
store float %39, float* %9
br label %42
40: ; preds = %7
%41 = load float, float* %9
br label %42
42: ; preds = %40, %29
%43 = phi float [ %41, %40 ], [ %39, %29 ]
%44 = fcmp ogt float %43, 2.200000e+01
br i1 %44, label %45, label %46
45: ; preds = %42
store float 2.200000e+01, float* %9
br label %46
46: ; preds = %45, %42
%47 = phi float [ 2.200000e+01, %45 ], [ %43, %42 ]
%48 = load i32, i32* @stderr
%49 = fpext float %47 to double
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %49)
%51 = add nuw nsw i64 %8, 1
%52 = icmp eq i64 %51, 4
br i1 %52, label %4, label %7
}