#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(double);
double gain_to_position(double);
double position_to_gain(double);
double interpolate_gain(double f, double t, double fraction, double upper) {
  double from = f + (0.0000001);
  double to = t + (0.0000001);
  if (fabs(to - from) < (0.0000001)) {
    return to;
  }
  double g0 = gain_to_position(from * 2. / upper);
  double g1 = gain_to_position(to * 2. / upper);
  double diff = g1 - g0;
  return position_to_gain(g0 + fraction * (diff)) * upper / 2.;
}


x86 assembly (clang, -O0):
<interpolate_gain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  0xebc(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xeaa(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
subsd  -0x30(%rbp),%xmm1
movaps 0xe9f(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe83(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1196 <interpolate_gain+0x76>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120f <interpolate_gain+0xef>
movsd  0xe6a(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
call   1040 <gain_to_position@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  0xe4e(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
call   1040 <gain_to_position@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <position_to_gain@plt>
mulsd  -0x28(%rbp),%xmm0
movsd  0xe02(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interpolate_gain>:
sub    $0x28,%rsp
movapd %xmm1,%xmm4
movsd  0xed0(%rip),%xmm1
addsd  %xmm1,%xmm0
addsd  %xmm1,%xmm4
movapd %xmm4,%xmm5
subsd  %xmm0,%xmm5
andpd  0xec8(%rip),%xmm5
ucomisd %xmm5,%xmm1
ja     11b3 <interpolate_gain+0x93>
addsd  %xmm0,%xmm0
divsd  %xmm3,%xmm0
movsd  %xmm3,0x8(%rsp)
movsd  %xmm4,0x10(%rsp)
movsd  %xmm2,0x20(%rsp)
call   1040 <gain_to_position@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm0
addsd  %xmm0,%xmm0
divsd  0x8(%rsp),%xmm0
call   1040 <gain_to_position@plt>
movsd  0x18(%rsp),%xmm1
subsd  %xmm1,%xmm0
mulsd  0x20(%rsp),%xmm0
addsd  %xmm1,%xmm0
call   1030 <position_to_gain@plt>
movapd %xmm0,%xmm4
mulsd  0x8(%rsp),%xmm4
mulsd  0xe55(%rip),%xmm4
movapd %xmm4,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @interpolate_gain(double %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
%15 = load double, double* %6
%16 = fadd double %15, 0x3E7AD7F29ABCAF48
store double %16, double* %10
%17 = load double, double* %7
%18 = fadd double %17, 0x3E7AD7F29ABCAF48
store double %18, double* %11
%19 = load double, double* %11
%20 = load double, double* %10
%21 = fsub double %19, %20
%22 = call double @llvm.fabs.f64(double %21)
%23 = fcmp olt double %22, 0x3E7AD7F29ABCAF48
br i1 %23, label %24, label %26
24: ; preds = %4
%25 = load double, double* %11
store double %25, double* %5
br label %48
26: ; preds = %4
%27 = load double, double* %10
%28 = fmul double %27, 2.000000e+00
%29 = load double, double* %9
%30 = fdiv double %28, %29
%31 = call double @gain_to_position(double %30)
store double %31, double* %12
%32 = load double, double* %11
%33 = fmul double %32, 2.000000e+00
%34 = load double, double* %9
%35 = fdiv double %33, %34
%36 = call double @gain_to_position(double %35)
store double %36, double* %13
%37 = load double, double* %13
%38 = load double, double* %12
%39 = fsub double %37, %38
store double %39, double* %14
%40 = load double, double* %12
%41 = load double, double* %8
%42 = load double, double* %14
%43 = call double @llvm.fmuladd.f64(double %41, double %42, double %40)
%44 = call double @position_to_gain(double %43)
%45 = load double, double* %9
%46 = fmul double %44, %45
%47 = fdiv double %46, 2.000000e+00
store double %47, double* %5
br label %48
48: ; preds = %26, %24
%49 = load double, double* %5
ret double %49
}

LLVM IR (-O2):
define double @interpolate_gain(double %0, double %1, double %2, double %3) {
%5 = fadd double %0, 0x3E7AD7F29ABCAF48
%6 = fadd double %1, 0x3E7AD7F29ABCAF48
%7 = fsub double %6, %5
%8 = tail call double @llvm.fabs.f64(double %7)
%9 = fcmp olt double %8, 0x3E7AD7F29ABCAF48
br i1 %9, label %22, label %10
10: ; preds = %4
%11 = fmul double %5, 2.000000e+00
%12 = fdiv double %11, %3
%13 = tail call double @gain_to_position(double %12)
%14 = fmul double %6, 2.000000e+00
%15 = fdiv double %14, %3
%16 = tail call double @gain_to_position(double %15)
%17 = fsub double %16, %13
%18 = tail call double @llvm.fmuladd.f64(double %2, double %17, double %13)
%19 = tail call double @position_to_gain(double %18)
%20 = fmul double %19, %3
%21 = fmul double %20, 5.000000e-01
br label %22
22: ; preds = %4, %10
%23 = phi double [ %21, %10 ], [ %6, %4 ]
ret double %23
}