#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 ctrls_value(int);
double pow(double, double);
double ctrls_sample_amp(int key, double vel, double rms) {
  if (rms == 0) {
    return 0;
  }
  double rmsLow = ctrls_value(5);
  double rmsHigh = ctrls_value(6);
  double gammaAmp = ctrls_value(2);
  double m = (rmsHigh - rmsLow) / 87;
  double amp = (rmsLow + m * ((double)key - 21)) / rms;
  return amp * pow(vel, gammaAmp);
}


x86 assembly (clang, -O0):
<ctrls_sample_amp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    115a <ctrls_sample_amp+0x3a>
jp     115a <ctrls_sample_amp+0x3a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f9 <ctrls_sample_amp+0xd9>
mov    $0x5,%edi
call   1030 <ctrls_value@plt>
movsd  %xmm0,-0x28(%rbp)
mov    $0x6,%edi
call   1030 <ctrls_value@plt>
movsd  %xmm0,-0x30(%rbp)
mov    $0x2,%edi
call   1030 <ctrls_value@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  0xe6f(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm2
movsd  0xe47(%rip),%xmm3
subsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ctrls_sample_amp>:
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1131 <ctrls_sample_amp+0x11>
jp     1131 <ctrls_sample_amp+0x11>
ret
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
mov    $0x5,%edi
movsd  %xmm2,0x18(%rsp)
movsd  %xmm1,(%rsp)
call   1030 <ctrls_value@plt>
movsd  %xmm0,0x10(%rsp)
mov    $0x6,%edi
call   1030 <ctrls_value@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0x2,%edi
call   1030 <ctrls_value@plt>
movsd  0x10(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
subsd  %xmm2,%xmm1
divsd  0xe7b(%rip),%xmm1
movapd %xmm1,%xmm4
cvtsi2sd %ebx,%xmm3
addsd  0xe73(%rip),%xmm3
movapd %xmm0,%xmm1
mulsd  %xmm4,%xmm3
addsd  %xmm2,%xmm3
divsd  (%rsp),%xmm3
movsd  %xmm3,(%rsp)
movsd  0x18(%rsp),%xmm0
call   1040 <pow@plt>
mulsd  (%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @ctrls_sample_amp(i32 %0, double %1, double %2) {
%4 = alloca double
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
store i32 %0, i32* %5
store double %1, double* %6
store double %2, double* %7
%13 = load double, double* %7
%14 = fcmp oeq double %13, 0.000000e+00
br i1 %14, label %15, label %16
15: ; preds = %3
store double 0.000000e+00, double* %4
br label %37
16: ; preds = %3
%17 = call double @ctrls_value(i32 5)
store double %17, double* %8
%18 = call double @ctrls_value(i32 6)
store double %18, double* %9
%19 = call double @ctrls_value(i32 2)
store double %19, double* %10
%20 = load double, double* %9
%21 = load double, double* %8
%22 = fsub double %20, %21
%23 = fdiv double %22, 8.700000e+01
store double %23, double* %11
%24 = load double, double* %8
%25 = load double, double* %11
%26 = load i32, i32* %5
%27 = sitofp i32 %26 to double
%28 = fsub double %27, 2.100000e+01
%29 = call double @llvm.fmuladd.f64(double %25, double %28, double %24)
%30 = load double, double* %7
%31 = fdiv double %29, %30
store double %31, double* %12
%32 = load double, double* %12
%33 = load double, double* %6
%34 = load double, double* %10
%35 = call double @pow(double %33, double %34)
%36 = fmul double %32, %35
store double %36, double* %4
br label %37
37: ; preds = %16, %15
%38 = load double, double* %4
ret double %38
}

LLVM IR (-O2):
define double @ctrls_sample_amp(i32 %0, double %1, double %2) {
%4 = fcmp oeq double %2, 0.000000e+00
br i1 %4, label %17, label %5
5: ; preds = %3
%6 = tail call double @ctrls_value(i32 5)
%7 = tail call double @ctrls_value(i32 6)
%8 = tail call double @ctrls_value(i32 2)
%9 = fsub double %7, %6
%10 = fdiv double %9, 8.700000e+01
%11 = sitofp i32 %0 to double
%12 = fadd double %11, -2.100000e+01
%13 = tail call double @llvm.fmuladd.f64(double %10, double %12, double %6)
%14 = fdiv double %13, %2
%15 = tail call double @pow(double %1, double %8)
%16 = fmul double %15, %14
br label %17
17: ; preds = %3, %5
%18 = phi double [ %16, %5 ], [ 0.000000e+00, %3 ]
ret double %18
}