#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 uint16_t;

/* Variables and functions */
double pow(double, int);
scalar_t__ round(double);
int createtable(int fs, uint16_t table[]) {
  for (int i = 0; i < 128; i++) {
    double f = 440.0 * pow(2.0, (i - 69.0) / 12.0) / fs;
    table[i] = (int)round(f * 65536);
  }
  return 128;
}


x86 assembly (clang, -O0):
<createtable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x80,-0x14(%rbp)
jge    11bb <createtable+0x9b>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xed0(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xebc(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
movsd  0xea4(%rip),%xmm0
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xe8c(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe6a(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
call   1040 <round@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1136 <createtable+0x16>
mov    $0x80,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createtable>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cvtsi2sd %edi,%xmm0
movsd  %xmm0,(%rsp)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    -0x45(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xeae(%rip),%xmm0
cvttsd2si %xmm0,%edi
movsd  0xeaa(%rip),%xmm0
call   1030 <pow@plt>
mulsd  0xea5(%rip),%xmm0
divsd  (%rsp),%xmm0
mulsd  0xea0(%rip),%xmm0
call   1040 <round@plt>
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    $0x80,%rbx
jne    1140 <createtable+0x20>
mov    $0x80,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @createtable(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca double
store i32 %0, i32* %3
store i32* %1, i32** %4
store i32 0, i32* %5
br label %7
7: ; preds = %29, %2
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 128
br i1 %9, label %10, label %32
10: ; preds = %7
%11 = load i32, i32* %5
%12 = sitofp i32 %11 to double
%13 = fsub double %12, 6.900000e+01
%14 = fdiv double %13, 1.200000e+01
%15 = fptosi double %14 to i32
%16 = call double @pow(double 2.000000e+00, i32 %15)
%17 = fmul double 4.400000e+02, %16
%18 = load i32, i32* %3
%19 = sitofp i32 %18 to double
%20 = fdiv double %17, %19
store double %20, double* %6
%21 = load double, double* %6
%22 = fmul double %21, 6.553600e+04
%23 = call i64 @round(double %22)
%24 = trunc i64 %23 to i32
%25 = load i32*, i32** %4
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
store i32 %24, i32* %28
br label %29
29: ; preds = %10
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %7
32: ; preds = %7
ret i32 128
}

LLVM IR (-O2):
define i32 @createtable(i32 %0, i32* nocapture writeonly %1) {
%3 = sitofp i32 %0 to double
br label %5
4: ; preds = %5
ret i32 128
5: ; preds = %2, %5
%6 = phi i64 [ 0, %2 ], [ %19, %5 ]
%7 = trunc i64 %6 to i32
%8 = add i32 %7, -69
%9 = sitofp i32 %8 to double
%10 = fdiv double %9, 1.200000e+01
%11 = fptosi double %10 to i32
%12 = tail call double @pow(double 2.000000e+00, i32 %11)
%13 = fmul double %12, 4.400000e+02
%14 = fdiv double %13, %3
%15 = fmul double %14, 6.553600e+04
%16 = tail call i64 @round(double %15)
%17 = trunc i64 %16 to i32
%18 = getelementptr inbounds i32, i32* %1, i64 %6
store i32 %17, i32* %18
%19 = add nuw nsw i64 %6, 1
%20 = icmp eq i64 %19, 128
br i1 %20, label %4, label %5
}