#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 */
float muGetFreqFromNote(int);
int muGetNoteFromFreq(float fFreq) {
  int iNote, iBestNote = 0;
  float fDiff = 20000, f;
  for (iNote = 0; iNote < 127; ++iNote) {
    f = muGetFreqFromNote(iNote);
    f -= fFreq;
    if (f < 0)
      f = -f;
    if (f < fDiff) {
      fDiff = f;
      iBestNote = iNote;
    }
  }
  return iBestNote;
}


x86 assembly (clang, -O0):
<muGetNoteFromFreq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movss  0xed4(%rip),%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x7f,-0x8(%rbp)
jge    11bc <muGetNoteFromFreq+0xac>
mov    -0x8(%rbp),%edi
call   1030 <muGetFreqFromNote@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x4(%rbp),%xmm1
movss  -0x14(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x14(%rbp),%xmm0
jbe    1186 <muGetNoteFromFreq+0x76>
movss  -0x14(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm1
movss  -0x10(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    11a9 <muGetNoteFromFreq+0x99>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11ae <muGetNoteFromFreq+0x9e>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1138 <muGetNoteFromFreq+0x28>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<muGetNoteFromFreq>:
push   %rbp
push   %rbx
push   %rax
movss  %xmm0,(%rsp)
xor    %ebx,%ebx
movss  0xede(%rip),%xmm2
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movss  %xmm2,0x4(%rsp)
mov    %ebp,%edi
call   1030 <muGetFreqFromNote@plt>
subss  (%rsp),%xmm0
movaps %xmm0,%xmm1
xorps  0xec4(%rip),%xmm1
movaps %xmm0,%xmm2
cmpltss 0xeac(%rip),%xmm2
andps  %xmm2,%xmm1
andnps %xmm0,%xmm2
orps   %xmm1,%xmm2
movss  0x4(%rsp),%xmm0
ucomiss %xmm2,%xmm0
cmova  %ebp,%ebx
minss  %xmm0,%xmm2
add    $0x1,%ebp
cmp    $0x7f,%ebp
jne    1130 <muGetNoteFromFreq+0x20>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @muGetNoteFromFreq(float %0) {
%2 = alloca float
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = alloca float
store float %0, float* %2
store i32 0, i32* %4
store float 2.000000e+04, float* %5
store i32 0, i32* %3
br label %7
7: ; preds = %29, %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 127
br i1 %9, label %10, label %32
10: ; preds = %7
%11 = load i32, i32* %3
%12 = call float @muGetFreqFromNote(i32 %11)
store float %12, float* %6
%13 = load float, float* %2
%14 = load float, float* %6
%15 = fsub float %14, %13
store float %15, float* %6
%16 = load float, float* %6
%17 = fcmp olt float %16, 0.000000e+00
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = load float, float* %6
%20 = fneg float %19
store float %20, float* %6
br label %21
21: ; preds = %18, %10
%22 = load float, float* %6
%23 = load float, float* %5
%24 = fcmp olt float %22, %23
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load float, float* %6
store float %26, float* %5
%27 = load i32, i32* %3
store i32 %27, i32* %4
br label %28
28: ; preds = %25, %21
br label %29
29: ; preds = %28
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %7
32: ; preds = %7
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
define i32 @muGetNoteFromFreq(float %0) {
br label %2
2: ; preds = %1, %2
%3 = phi float [ 2.000000e+04, %1 ], [ %13, %2 ]
%4 = phi i32 [ 0, %1 ], [ %12, %2 ]
%5 = phi i32 [ 0, %1 ], [ %14, %2 ]
%6 = tail call float @muGetFreqFromNote(i32 %5)
%7 = fsub float %6, %0
%8 = fcmp olt float %7, 0.000000e+00
%9 = fneg float %7
%10 = select i1 %8, float %9, float %7
%11 = fcmp olt float %10, %3
%12 = select i1 %11, i32 %5, i32 %4
%13 = select i1 %11, float %10, float %3
%14 = add nuw nsw i32 %5, 1
%15 = icmp eq i32 %14, 127
br i1 %15, label %16, label %2
16: ; preds = %2
ret i32 %12
}