#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 pow(int, double);
double note_to_period(int n, int f, int type, double adj) {
  double d = (double)n + (double)f / 128;
  double per;
  per = type ? (240.0 - d) * 16 : 13694.0 / pow(2, d / 12);
  if (adj > 0.1)
    per *= adj;
  return per;
}


x86 assembly (clang, -O0):
<note_to_period>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xec8(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1172 <note_to_period+0x62>
movsd  0xec9(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  0xeb4(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11a1 <note_to_period+0x91>
movsd  -0x20(%rbp),%xmm0
movsd  0xe91(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xe70(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe70(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11d1 <note_to_period+0xc1>
movsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<note_to_period>:
sub    $0x18,%rsp
movapd %xmm0,%xmm3
cvtsi2sd %edi,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %esi,%xmm0
mulsd  0xed5(%rip),%xmm0
addsd  %xmm1,%xmm0
test   %edx,%edx
je     1149 <note_to_period+0x39>
movsd  0xecd(%rip),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xec9(%rip),%xmm1
jmp    1171 <note_to_period+0x61>
divsd  0xec7(%rip),%xmm0
mov    $0x2,%edi
movapd %xmm3,(%rsp)
call   1030 <pow@plt>
movapd (%rsp),%xmm3
movsd  0xeb3(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0xeaf(%rip),%xmm0
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm3
movsd  0xea6(%rip),%xmm2
andnpd %xmm2,%xmm0
orpd   %xmm3,%xmm0
mulsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @note_to_period(i32 %0, i32 %1, i32 %2, double %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store double %3, double* %8
%11 = load i32, i32* %5
%12 = sitofp i32 %11 to double
%13 = load i32, i32* %6
%14 = sitofp i32 %13 to double
%15 = fdiv double %14, 1.280000e+02
%16 = fadd double %12, %15
store double %16, double* %9
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %4
%20 = load double, double* %9
%21 = fsub double 2.400000e+02, %20
%22 = fmul double %21, 1.600000e+01
br label %28
23: ; preds = %4
%24 = load double, double* %9
%25 = fdiv double %24, 1.200000e+01
%26 = call double @pow(i32 2, double %25)
%27 = fdiv double 1.369400e+04, %26
br label %28
28: ; preds = %23, %19
%29 = phi double [ %22, %19 ], [ %27, %23 ]
store double %29, double* %10
%30 = load double, double* %8
%31 = fcmp ogt double %30, 1.000000e-01
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load double, double* %8
%34 = load double, double* %10
%35 = fmul double %34, %33
store double %35, double* %10
br label %36
36: ; preds = %32, %28
%37 = load double, double* %10
ret double %37
}

LLVM IR (-O2):
define double @note_to_period(i32 %0, i32 %1, i32 %2, double %3) {
%5 = sitofp i32 %0 to double
%6 = sitofp i32 %1 to double
%7 = fmul double %6, 7.812500e-03
%8 = fadd double %7, %5
%9 = icmp eq i32 %2, 0
br i1 %9, label %13, label %10
10: ; preds = %4
%11 = fsub double 2.400000e+02, %8
%12 = fmul double %11, 1.600000e+01
br label %17
13: ; preds = %4
%14 = fdiv double %8, 1.200000e+01
%15 = tail call double @pow(i32 2, double %14)
%16 = fdiv double 1.369400e+04, %15
br label %17
17: ; preds = %13, %10
%18 = phi double [ %12, %10 ], [ %16, %13 ]
%19 = fcmp ogt double %3, 1.000000e-01
%20 = select i1 %19, double %3, double 1.000000e+00
%21 = fmul double %20, %18
ret double %21
}