#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 */
typedef int int8_t;

/* Variables and functions */
float muGetFreqFromNote(int);
int8_t muGetNoteFromFreq(float fFreq) {
  int8_t iNote, iBestNote = 0;
  float f;
  float fDiff = 20000;
  for (iNote = 0; iNote < 127; ++iNote) {
    f = muGetFreqFromNote(iNote) - 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,-0x14(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x7f,-0x8(%rbp)
jge    11ae <muGetNoteFromFreq+0x9e>
mov    -0x8(%rbp),%edi
call   1030 <muGetFreqFromNote@plt>
subss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x10(%rbp),%xmm0
jbe    1178 <muGetNoteFromFreq+0x68>
movss  -0x10(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm1
movss  -0x14(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    119b <muGetNoteFromFreq+0x8b>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11a0 <muGetNoteFromFreq+0x90>
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* %6
store i32 0, i32* %3
br label %7
7: ; preds = %28, %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 127
br i1 %9, label %10, label %31
10: ; preds = %7
%11 = load i32, i32* %3
%12 = call float @muGetFreqFromNote(i32 %11)
%13 = load float, float* %2
%14 = fsub float %12, %13
store float %14, float* %5
%15 = load float, float* %5
%16 = fcmp olt float %15, 0.000000e+00
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = load float, float* %5
%19 = fneg float %18
store float %19, float* %5
br label %20
20: ; preds = %17, %10
%21 = load float, float* %5
%22 = load float, float* %6
%23 = fcmp olt float %21, %22
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load float, float* %5
store float %25, float* %6
%26 = load i32, i32* %3
store i32 %26, i32* %4
br label %27
27: ; preds = %24, %20
br label %28
28: ; preds = %27
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %7
31: ; preds = %7
%32 = load i32, i32* %4
ret i32 %32
}

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
}