#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 const log(double);
int get_note(double freq) {
  extern double adj_pitch;
  extern double pitch_shift;
  extern int n_pitch;
  const double factor = 1.731234049066756242e+01;
  double dnote;
  int inote;
  dnote = 69.5 + factor * log(freq / 440.0) + adj_pitch;
  inote = (int)dnote;
  pitch_shift += (dnote - (double)inote);
  n_pitch++;
  return inote;
}


x86 assembly (clang, -O0):
<get_note>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xedb(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xed9(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <log@plt>
movsd  0xeb8(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xeb4(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    0x2e91(%rip),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
cvttsd2si -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
subsd  %xmm1,%xmm0
mov    0x2e73(%rip),%rax
addsd  (%rax),%xmm0
mov    0x2e68(%rip),%rax
movsd  %xmm0,(%rax)
mov    0x2e45(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    0x2e39(%rip),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_note>:
push   %rax
divsd  0xee7(%rip),%xmm0
call   1030 <log@plt>
mulsd  0xee2(%rip),%xmm0
addsd  0xee2(%rip),%xmm0
mov    0x2ebb(%rip),%rax
addsd  (%rax),%xmm0
cvttsd2si %xmm0,%eax
cvttpd2dq %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
subsd  %xmm1,%xmm0
mov    0x2ea8(%rip),%rcx
addsd  (%rcx),%xmm0
movsd  %xmm0,(%rcx)
mov    0x2e81(%rip),%rcx
addl   $0x1,(%rcx)
pop    %rcx
ret

LLVM IR (-O0):
@adj_pitch = external global double
@pitch_shift = external global double
@n_pitch = external global i32
define i32 @get_note(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store double %0, double* %2
store double 0x40314FF58BE0A23F, double* %3
%6 = load double, double* %2
%7 = fdiv double %6, 4.400000e+02
%8 = call double @log(double %7)
%9 = call double @llvm.fmuladd.f64(double 0x40314FF58BE0A23F, double %8, double 6.950000e+01)
%10 = load double, double* @adj_pitch
%11 = fadd double %9, %10
store double %11, double* %4
%12 = load double, double* %4
%13 = fptosi double %12 to i32
store i32 %13, i32* %5
%14 = load double, double* %4
%15 = load i32, i32* %5
%16 = sitofp i32 %15 to double
%17 = fsub double %14, %16
%18 = load double, double* @pitch_shift
%19 = fadd double %18, %17
store double %19, double* @pitch_shift
%20 = load i32, i32* @n_pitch
%21 = add nsw i32 %20, 1
store i32 %21, i32* @n_pitch
%22 = load i32, i32* %5
ret i32 %22
}

LLVM IR (-O2):
@adj_pitch = external global double
@pitch_shift = external global double
@n_pitch = external global i32
define i32 @get_note(double %0) {
%2 = fdiv double %0, 4.400000e+02
%3 = tail call double @log(double %2)
%4 = tail call double @llvm.fmuladd.f64(double %3, double 0x40314FF58BE0A23F, double 6.950000e+01)
%5 = load double, double* @adj_pitch
%6 = fadd double %4, %5
%7 = fptosi double %6 to i32
%8 = sitofp i32 %7 to double
%9 = fsub double %6, %8
%10 = load double, double* @pitch_shift
%11 = fadd double %10, %9
store double %11, double* @pitch_shift
%12 = load i32, i32* @n_pitch
%13 = add nsw i32 %12, 1
store i32 %13, i32* @n_pitch
ret i32 %7
}