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


x86 assembly (clang, -O0):
<interpolate_gain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  0xebc(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1040 <gain_to_position@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  0xea0(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1040 <gain_to_position@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
subsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <position_to_gain@plt>
mulsd  -0x20(%rbp),%xmm0
movsd  0xe5e(%rip),%xmm1
divsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interpolate_gain>:
sub    $0x28,%rsp
movsd  %xmm3,0x8(%rsp)
movsd  %xmm2,0x20(%rsp)
movsd  %xmm1,0x18(%rsp)
addsd  %xmm0,%xmm0
divsd  %xmm3,%xmm0
call   1040 <gain_to_position@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
addsd  %xmm0,%xmm0
divsd  0x8(%rsp),%xmm0
call   1040 <gain_to_position@plt>
movsd  0x10(%rsp),%xmm1
subsd  %xmm1,%xmm0
mulsd  0x20(%rsp),%xmm0
addsd  %xmm1,%xmm0
call   1030 <position_to_gain@plt>
mulsd  0x8(%rsp),%xmm0
mulsd  0xe7b(%rip),%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
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%11 = load double, double* %5
%12 = fmul double %11, 2.000000e+00
%13 = load double, double* %8
%14 = fdiv double %12, %13
%15 = call double @gain_to_position(double %14)
store double %15, double* %9
%16 = load double, double* %6
%17 = fmul double %16, 2.000000e+00
%18 = load double, double* %8
%19 = fdiv double %17, %18
%20 = call double @gain_to_position(double %19)
store double %20, double* %10
%21 = load double, double* %9
%22 = load double, double* %7
%23 = load double, double* %10
%24 = load double, double* %9
%25 = fsub double %23, %24
%26 = call double @llvm.fmuladd.f64(double %22, double %25, double %21)
%27 = call double @position_to_gain(double %26)
%28 = load double, double* %8
%29 = fmul double %27, %28
%30 = fdiv double %29, 2.000000e+00
ret double %30
}

LLVM IR (-O2):
define double @interpolate_gain(double %0, double %1, double %2, double %3) {
%5 = fmul double %0, 2.000000e+00
%6 = fdiv double %5, %3
%7 = tail call double @gain_to_position(double %6)
%8 = fmul double %1, 2.000000e+00
%9 = fdiv double %8, %3
%10 = tail call double @gain_to_position(double %9)
%11 = fsub double %10, %7
%12 = tail call double @llvm.fmuladd.f64(double %2, double %11, double %7)
%13 = tail call double @position_to_gain(double %12)
%14 = fmul double %13, %3
%15 = fmul double %14, 5.000000e-01
ret double %15
}