#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 acos(double);
double ascender(double);
double fader(double);
double sin(double);
double dsp(int tn) {
  double tx0 = tn / 44100.0;
  double amp = 0.0;
  double pi2 = 2.0 * acos(-1.0);
  int tones = 1 + ((int)tx0) / 16;
  for (int i = 0; i < tones; i++) {
    double tx = tx0 - 16.0 * i;
    double freq = ascender(tx);
    double ax = fader(tx);
    amp += 1.8 * ax * sin(pi2 * (0.1 * i + 20.0 * freq * tx));
  }
  if (amp > 1.0)
    amp = 1.0;
  if (amp < -1.0)
    amp = -1.0;
  return amp;
}


x86 assembly (clang, -O0):
<dsp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xeb8(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe97(%rip),%xmm0
call   1040 <acos@plt>
movaps %xmm0,%xmm1
movsd  0xe7f(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
cvttsd2si -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    125c <dsp+0x11c>
movsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0x28(%rbp),%xmm0
movsd  0xe76(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <ascender@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1060 <fader@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  0xe3b(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x28(%rbp),%xmm1
movsd  0xe17(%rip),%xmm2
mulsd  -0x38(%rbp),%xmm2
mulsd  -0x30(%rbp),%xmm2
movsd  0xdfd(%rip),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11a4 <dsp+0x64>
movsd  -0x18(%rbp),%xmm0
movsd  0xdaf(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1280 <dsp+0x140>
movsd  0xd9d(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xd80(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    12a0 <dsp+0x160>
movsd  0xd6d(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dsp>:
push   %rbx
sub    $0x30,%rsp
cvtsi2sd %edi,%xmm0
divsd  0xebf(%rip),%xmm0
cvttsd2si %xmm0,%eax
xorpd  %xmm2,%xmm2
cmp    $0xfffffff1,%eax
jl     1217 <dsp+0xe7>
lea    0xf(%rax),%ebx
test   %eax,%eax
cmovns %eax,%ebx
sar    $0x4,%ebx
add    $0x1,%ebx
xorpd  %xmm2,%xmm2
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x10(%rsp)
xchg   %ax,%ax
movsd  %xmm1,0x8(%rsp)
movsd  %xmm2,0x28(%rsp)
mulsd  0xe84(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movapd %xmm1,%xmm0
call   1030 <ascender@plt>
movsd  %xmm0,0x18(%rsp)
movsd  (%rsp),%xmm0
call   1050 <fader@plt>
mulsd  0xe62(%rip),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x18(%rsp),%xmm0
mulsd  0xe56(%rip),%xmm0
mulsd  (%rsp),%xmm0
movapd %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
mulsd  0xe47(%rip),%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe43(%rip),%xmm0
call   1040 <sin@plt>
movsd  0x8(%rsp),%xmm1
movsd  0x28(%rsp),%xmm2
mulsd  0x20(%rsp),%xmm0
addsd  %xmm0,%xmm2
movsd  0x10(%rsp),%xmm0
addsd  0xe22(%rip),%xmm1
add    $0xffffffff,%ebx
jne    1170 <dsp+0x40>
movsd  0xe11(%rip),%xmm1
minsd  %xmm2,%xmm1
movsd  0xe0d(%rip),%xmm0
maxsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @dsp(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
store i32 %0, i32* %2
%11 = load i32, i32* %2
%12 = sitofp i32 %11 to double
%13 = fdiv double %12, 4.410000e+04
store double %13, double* %3
store double 0.000000e+00, double* %4
%14 = call double @acos(double -1.000000e+00)
%15 = fmul double 2.000000e+00, %14
store double %15, double* %5
%16 = load double, double* %3
%17 = fptosi double %16 to i32
%18 = sdiv i32 %17, 16
%19 = add nsw i32 1, %18
store i32 %19, i32* %6
store i32 0, i32* %7
br label %20
20: ; preds = %47, %1
%21 = load i32, i32* %7
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %50
24: ; preds = %20
%25 = load double, double* %3
%26 = load i32, i32* %7
%27 = sitofp i32 %26 to double
%28 = call double @llvm.fmuladd.f64(double -1.600000e+01, double %27, double %25)
store double %28, double* %8
%29 = load double, double* %8
%30 = call double @ascender(double %29)
store double %30, double* %9
%31 = load double, double* %8
%32 = call double @fader(double %31)
store double %32, double* %10
%33 = load double, double* %10
%34 = fmul double 1.800000e+00, %33
%35 = load double, double* %5
%36 = load i32, i32* %7
%37 = sitofp i32 %36 to double
%38 = load double, double* %9
%39 = fmul double 2.000000e+01, %38
%40 = load double, double* %8
%41 = fmul double %39, %40
%42 = call double @llvm.fmuladd.f64(double 1.000000e-01, double %37, double %41)
%43 = fmul double %35, %42
%44 = call double @sin(double %43)
%45 = load double, double* %4
%46 = call double @llvm.fmuladd.f64(double %34, double %44, double %45)
store double %46, double* %4
br label %47
47: ; preds = %24
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %20
50: ; preds = %20
%51 = load double, double* %4
%52 = fcmp ogt double %51, 1.000000e+00
br i1 %52, label %53, label %54
53: ; preds = %50
store double 1.000000e+00, double* %4
br label %54
54: ; preds = %53, %50
%55 = load double, double* %4
%56 = fcmp olt double %55, -1.000000e+00
br i1 %56, label %57, label %58
57: ; preds = %54
store double -1.000000e+00, double* %4
br label %58
58: ; preds = %57, %54
%59 = load double, double* %4
ret double %59
}

LLVM IR (-O2):
define double @dsp(i32 %0) {
%2 = sitofp i32 %0 to double
%3 = fdiv double %2, 4.410000e+04
%4 = fptosi double %3 to i32
%5 = icmp slt i32 %4, -15
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = sdiv i32 %4, 16
br label %14
8: ; preds = %14, %1
%9 = phi double [ 0.000000e+00, %1 ], [ %27, %14 ]
%10 = fcmp ogt double %9, 1.000000e+00
%11 = select i1 %10, double 1.000000e+00, double %9
%12 = fcmp olt double %11, -1.000000e+00
%13 = select i1 %12, double -1.000000e+00, double %11
ret double %13
14: ; preds = %6, %14
%15 = phi double [ %27, %14 ], [ 0.000000e+00, %6 ]
%16 = phi i32 [ %28, %14 ], [ 0, %6 ]
%17 = sitofp i32 %16 to double
%18 = tail call double @llvm.fmuladd.f64(double %17, double -1.600000e+01, double %3)
%19 = tail call double @ascender(double %18)
%20 = tail call double @fader(double %18)
%21 = fmul double %20, 1.800000e+00
%22 = fmul double %19, 2.000000e+01
%23 = fmul double %18, %22
%24 = tail call double @llvm.fmuladd.f64(double %17, double 1.000000e-01, double %23)
%25 = fmul double %24, 0x401921FB54442D18
%26 = tail call double @sin(double %25)
%27 = tail call double @llvm.fmuladd.f64(double %21, double %26, double %15)
%28 = add nuw nsw i32 %16, 1
%29 = icmp eq i32 %16, %7
br i1 %29, label %8, label %14
}