#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 */
int /*<<< orphan*/ KIOCSOUND;
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int);
int powf(float, int);
void libpcspeak_sustain(int device, int note, int octave) {
  int steps = note - 9;
  steps = ((octave - 4) * 12) + steps;
  float etr = 1.05946;
  float fq = 440 * powf(etr, steps);
  int rounded_freq = (fq >= 0) ? (int)(fq + 0.5) : (int)(fq - 0.5);
  ioctl(device, KIOCSOUND, 1193180 / rounded_freq);
}


x86 assembly (clang, -O0):
<libpcspeak_sustain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x9,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x4,%eax
imul   $0xc,%eax,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
movss  0xeaf(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
mov    -0x10(%rbp),%edi
call   1030 <powf@plt>
imul   $0x1b8,%eax,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     11a4 <libpcspeak_sustain+0x84>
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe74(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x20(%rbp)
jmp    11c0 <libpcspeak_sustain+0xa0>
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe53(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
mov    $0x1234dc,%eax
cltd
idivl  -0x1c(%rbp)
mov    %eax,%edx
call   1040 <ioctl@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libpcspeak_sustain>:
push   %rbx
mov    %edi,%ebx
lea    (%rdx,%rdx,2),%eax
lea    (%rsi,%rax,4),%edi
add    $0xffffffc7,%edi
movss  0xecc(%rip),%xmm0
call   1030 <powf@plt>
xor    %ecx,%ecx
test   %eax,%eax
setns  %cl
imul   $0x1b8,%eax,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xeb0(%rip),%rax
addsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%ecx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
mov    $0x1234dc,%eax
xor    %edx,%edx
idiv   %ecx
mov    %ebx,%edi
mov    %eax,%edx
pop    %rbx
jmp    1040 <ioctl@plt>

LLVM IR (-O0):
@KIOCSOUND = global i32 0
define void @libpcspeak_sustain(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca float
%9 = alloca float
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, 9
store i32 %12, i32* %7
%13 = load i32, i32* %6
%14 = sub nsw i32 %13, 4
%15 = mul nsw i32 %14, 12
%16 = load i32, i32* %7
%17 = add nsw i32 %15, %16
store i32 %17, i32* %7
store float 0x3FF0F38C60000000, float* %8
%18 = load float, float* %8
%19 = load i32, i32* %7
%20 = call i32 @powf(float %18, i32 %19)
%21 = mul nsw i32 440, %20
%22 = sitofp i32 %21 to float
store float %22, float* %9
%23 = load float, float* %9
%24 = fcmp oge float %23, 0.000000e+00
br i1 %24, label %25, label %30
25: ; preds = %3
%26 = load float, float* %9
%27 = fpext float %26 to double
%28 = fadd double %27, 5.000000e-01
%29 = fptosi double %28 to i32
br label %35
30: ; preds = %3
%31 = load float, float* %9
%32 = fpext float %31 to double
%33 = fsub double %32, 5.000000e-01
%34 = fptosi double %33 to i32
br label %35
35: ; preds = %30, %25
%36 = phi i32 [ %29, %25 ], [ %34, %30 ]
store i32 %36, i32* %10
%37 = load i32, i32* %4
%38 = load i32, i32* @KIOCSOUND
%39 = load i32, i32* %10
%40 = sdiv i32 1193180, %39
%41 = call i32 @ioctl(i32 %37, i32 %38, i32 %40)
ret void
}

LLVM IR (-O2):
@KIOCSOUND = global i32 0
define void @libpcspeak_sustain(i32 %0, i32 %1, i32 %2) {
%4 = mul i32 %2, 12
%5 = add i32 %1, -57
%6 = add i32 %5, %4
%7 = tail call i32 @powf(float 0x3FF0F38C60000000, i32 %6)
%8 = mul nsw i32 %7, 440
%9 = sitofp i32 %8 to float
%10 = icmp sgt i32 %7, -1
%11 = fpext float %9 to double
%12 = select i1 %10, double 5.000000e-01, double -5.000000e-01
%13 = fadd double %12, %11
%14 = fptosi double %13 to i32
%15 = load i32, i32* @KIOCSOUND
%16 = sdiv i32 1193180, %14
%17 = tail call i32 @ioctl(i32 %0, i32 %15, i32 %16)
ret void
}