#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 AFMT_S16_LE;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ SNDCTL_DSP_GETBLKSIZE;
int /*<<< orphan*/ SNDCTL_DSP_SETFMT;
int /*<<< orphan*/ SNDCTL_DSP_SETFRAGMENT;
int /*<<< orphan*/ SNDCTL_DSP_SPEED;
int /*<<< orphan*/ SNDCTL_DSP_STEREO;
int /*<<< orphan*/ SNDCTL_DSP_SYNC;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ makewave(short *);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
double oscil(float, short *, float *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int write(int, short *, int);
main() {
  int len, format, stereo, speed, cycle, frag_size;
  int audio_fd;
  int arg;
  short waveform[1000];
  short sampbuff[10][4096];
  int i, j, k, bufno;
  int active;
  float si[1000], phase[1000];
  if ((audio_fd = open("/dev/dsp", O_WRONLY, 0)) == -1) {
    perror("/dev/dsp");
    exit(1);
  }
  arg = 0x777f000a;
  if (ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &arg) == -1) {
    perror("incorrect fragment size");
    exit(1);
  }
  ioctl(audio_fd, SNDCTL_DSP_SYNC, 0);
  format = AFMT_S16_LE;
  if (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &format) == -1) {
    perror("SNDCTL_DSP_SETFMT");
    exit(1);
  }
  stereo = 0;
  if (ioctl(audio_fd, SNDCTL_DSP_STEREO, &stereo) == -1) {
    perror("SNDCTL_DSP_STEREO");
    exit(1);
  }
  speed = 44100;
  if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &speed) == -1) {
    perror("SNDCTL_DSP_SPEED");
    exit(1);
  }
  if (ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) {
    exit(1);
  }
  printf("Audio buffer:  %d\n", frag_size);
  makewave(waveform);
  for (i = 0; i < 1000; i++) {
    si[i] = (278.0 + (i * 5)) * 1000 / 44100;
    phase[i] = 0.0;
  }
  bufno = 0;
  active = 1;
  for (i = 0; i < 99999; i++) {
    for (k = 0; k < active; k++) {
      if (k == 0) {
        for (j = 0; j < 4096; j++) {
          sampbuff[bufno][j] = oscil(si[k], waveform, &phase[k]) * 1.0 / active;
        }
      } else {
        for (j = 0; j < 4096; j++) {
          sampbuff[bufno][j] +=
              oscil(si[k], waveform, &phase[k]) * 1.0 / active;
        }
      }
    }
    if ((len = write(audio_fd, sampbuff[bufno], 2 * 4096)) == -1) {
      perror("audio write");
      exit(1);
    }
    if (++bufno > 3) {
      if (++active > 1000)
        active -= 1;
      printf("%d oscillators, daddy-oh!\n", active);
      bufno = 0;
    }
  }
  close(audio_fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x16760,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
lea    0xe66(%rip),%rdi
xor    %edx,%edx
call   1090 <open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    11db <main+0x4b>
lea    0xe4c(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movl   $0x777f000a,-0x24(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
lea    -0x24(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1216 <main+0x86>
lea    0xe1a(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%edi
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <ioctl@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    126b <main+0xdb>
lea    0xddd(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2d6c(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    12a6 <main+0x116>
lea    0xdb4(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movl   $0xac44,-0x14(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2d19(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    12e1 <main+0x151>
lea    0xd8b(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%edi
mov    0x2ccd(%rip),%rax
mov    (%rax),%esi
lea    -0x1c(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1309 <main+0x179>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x1c(%rbp),%esi
lea    0xd5b(%rip),%rdi
call   1060 <printf@plt>
lea    -0x800(%rbp),%rdi
call   1050 <makewave@plt>
movl   $0x0,-0x14804(%rbp)
cmpl   $0x3e8,-0x14804(%rbp)
jge    13a8 <main+0x218>
imul   $0x5,-0x14804(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  0xcbf(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  0xcab(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xc97(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movslq -0x14804(%rbp),%rax
movss  %xmm0,-0x157c0(%rbp,%rax,4)
fe ff
movslq -0x14804(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,-0x16760(%rbp,%rax,4)
fe ff
mov    -0x14804(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14804(%rbp)
jmp    132e <main+0x19e>
movl   $0x0,-0x14810(%rbp)
movl   $0x1,-0x14814(%rbp)
movl   $0x0,-0x14804(%rbp)
cmpl   $0x1869f,-0x14804(%rbp)
jge    15f3 <main+0x463>
movl   $0x0,-0x1480c(%rbp)
mov    -0x1480c(%rbp),%eax
cmp    -0x14814(%rbp),%eax
jge    1539 <main+0x3a9>
cmpl   $0x0,-0x1480c(%rbp)
jne    1489 <main+0x2f9>
movl   $0x0,-0x14808(%rbp)
cmpl   $0x1000,-0x14808(%rbp)
jge    1484 <main+0x2f4>
movslq -0x1480c(%rbp),%rax
movss  -0x157c0(%rbp,%rax,4),%xmm0
fe ff
lea    -0x16760(%rbp,%rax,4),%rsi
ff
lea    -0x800(%rbp),%rdi
call   1030 <oscil@plt>
cvtsi2sdl -0x14814(%rbp),%xmm1
ff
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,%dx
movslq -0x14810(%rbp),%rcx
lea    -0x14800(%rbp),%rax
shl    $0xd,%rcx
add    %rcx,%rax
movslq -0x14808(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
mov    -0x14808(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14808(%rbp)
jmp    1409 <main+0x279>
jmp    1520 <main+0x390>
movl   $0x0,-0x14808(%rbp)
cmpl   $0x1000,-0x14808(%rbp)
jge    151b <main+0x38b>
movslq -0x1480c(%rbp),%rax
movss  -0x157c0(%rbp,%rax,4),%xmm0
fe ff
lea    -0x16760(%rbp,%rax,4),%rsi
ff
lea    -0x800(%rbp),%rdi
call   1030 <oscil@plt>
movaps %xmm0,%xmm1
cvtsi2sdl -0x14814(%rbp),%xmm0
ff
divsd  %xmm0,%xmm1
movslq -0x14810(%rbp),%rax
shl    $0xd,%rax
lea    -0x14800(%rbp,%rax,1),%rax
ff
movslq -0x14808(%rbp),%rdx
mov    %rdx,%rcx
movswl (%rax,%rdx,2),%edx
cvtsi2sd %edx,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
mov    %dx,(%rax,%rcx,2)
mov    -0x14808(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14808(%rbp)
jmp    1493 <main+0x303>
jmp    1520 <main+0x390>
jmp    1525 <main+0x395>
mov    -0x1480c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1480c(%rbp)
jmp    13e0 <main+0x250>
mov    -0x20(%rbp),%edi
movslq -0x14810(%rbp),%rax
lea    -0x14800(%rbp),%rsi
shl    $0xd,%rax
add    %rax,%rsi
mov    $0x2000,%edx
call   1040 <write@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    157d <main+0x3ed>
lea    0xb13(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x14810(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14810(%rbp)
cmp    $0x3,%eax
jle    15da <main+0x44a>
mov    -0x14814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14814(%rbp)
cmp    $0x3e8,%eax
jle    15be <main+0x42e>
mov    -0x14814(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14814(%rbp)
mov    -0x14814(%rbp),%esi
lea    0xac2(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x14810(%rbp)
jmp    15df <main+0x44f>
mov    -0x14804(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14804(%rbp)
jmp    13c6 <main+0x236>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x16760,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x16768,%rsp
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
xor    %edx,%edx
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     15a9 <main+0x409>
mov    %eax,%r14d
movl   $0x777f000a,0x1c(%rsp)
77
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
lea    0x1c(%rsp),%rdx
mov    %r14d,%edi
call   1080 <ioctl@plt>
cmp    $0xffffffff,%eax
je     15b2 <main+0x412>
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
xor    %edx,%edx
call   1080 <ioctl@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
lea    0x2c(%rsp),%rdx
mov    %r14d,%edi
call   1080 <ioctl@plt>
cmp    $0xffffffff,%eax
je     15bb <main+0x41b>
movl   $0x0,0x28(%rsp)
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
lea    0x28(%rsp),%rdx
mov    %r14d,%edi
call   1080 <ioctl@plt>
cmp    $0xffffffff,%eax
je     15c4 <main+0x424>
movl   $0xac44,0x24(%rsp)
mov    0x2d60(%rip),%rax
mov    (%rax),%esi
lea    0x24(%rsp),%rdx
mov    %r14d,%edi
call   1080 <ioctl@plt>
cmp    $0xffffffff,%eax
je     15cd <main+0x42d>
mov    0x2d29(%rip),%rax
mov    (%rax),%esi
lea    0x20(%rsp),%rdx
mov    %r14d,%edi
call   1080 <ioctl@plt>
cmp    $0xffffffff,%eax
je     15d6 <main+0x436>
mov    0x20(%rsp),%esi
lea    0xe04(%rip),%rdi
call   1060 <printf@plt>
lea    0xff0(%rsp),%rdi
call   1050 <makewave@plt>
lea    0x17c0(%rsp),%rdi
mov    $0xfa0,%edx
xor    %esi,%esi
call   1070 <memset@plt>
movdqa 0xd20(%rip),%xmm0
mov    $0x4,%eax
movapd 0xd23(%rip),%xmm1
movapd 0xd2b(%rip),%xmm2
movapd 0xd33(%rip),%xmm3
movdqa 0xd3a(%rip),%xmm8
movdqa 0xd41(%rip),%xmm9
nop
movdqa %xmm0,%xmm6
pslld  $0x2,%xmm6
paddd  %xmm0,%xmm6
cvtdq2pd %xmm6,%xmm7
pshufd $0xee,%xmm6,%xmm4
cvtdq2pd %xmm4,%xmm4
addpd  %xmm1,%xmm4
addpd  %xmm1,%xmm7
mulpd  %xmm2,%xmm7
paddd  %xmm8,%xmm6
mulpd  %xmm2,%xmm4
cvtdq2pd %xmm6,%xmm5
pshufd $0xee,%xmm6,%xmm6
divpd  %xmm3,%xmm7
cvtdq2pd %xmm6,%xmm6
addpd  %xmm1,%xmm6
divpd  %xmm3,%xmm4
addpd  %xmm1,%xmm5
mulpd  %xmm2,%xmm5
cvtpd2ps %xmm7,%xmm7
mulpd  %xmm2,%xmm6
divpd  %xmm3,%xmm6
cvtpd2ps %xmm4,%xmm4
divpd  %xmm3,%xmm5
cvtpd2ps %xmm5,%xmm5
unpcklpd %xmm4,%xmm7
cvtpd2ps %xmm6,%xmm4
unpcklpd %xmm4,%xmm5
movapd %xmm7,0x40(%rsp,%rax,4)
movapd %xmm5,0x50(%rsp,%rax,4)
paddd  %xmm9,%xmm0
add    $0x8,%rax
cmp    $0x3ec,%rax
jne    1310 <main+0x170>
xor    %r12d,%r12d
mov    $0x1,%r15d
movss  0x50(%rsp),%xmm0
movss  %xmm0,0x14(%rsp)
lea    0xff0(%rsp),%rbx
lea    0x17c0(%rsp),%r13
xor    %ebp,%ebp
mov    %r14d,0x8(%rsp)
jmp    1410 <main+0x270>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
cmp    $0x3e8,%r15d
setl   %al
add    %eax,%r15d
lea    0xcdf(%rip),%rdi
mov    %r15d,%esi
call   1060 <printf@plt>
xor    %r12d,%r12d
add    $0x1,%ebp
cmp    $0x1869f,%ebp
je     1577 <main+0x3d7>
test   %r15d,%r15d
jle    1540 <main+0x3a0>
mov    %ebp,0xc(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
movsd  %xmm0,0x30(%rsp)
mov    %r12,0x40(%rsp)
movslq %r12d,%rax
mov    %r15d,0x10(%rsp)
mov    %r15d,%ecx
mov    %rcx,0x48(%rsp)
mov    %rax,0x38(%rsp)
shl    $0xd,%rax
lea    (%rsp,%rax,1),%r12
add    $0x2760,%r12
xor    %r15d,%r15d
jmp    146f <main+0x2cf>
nopl   0x0(%rax)
add    $0x1,%r15
cmp    0x48(%rsp),%r15
je     1520 <main+0x380>
test   %r15,%r15
je     14d0 <main+0x330>
movss  0x50(%rsp,%r15,4),%xmm0
movss  %xmm0,0x18(%rsp)
lea    (%rsp,%r15,4),%rbp
add    $0x17c0,%rbp
xor    %r14d,%r14d
nop
movss  0x18(%rsp),%xmm0
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <oscil@plt>
movswl (%r12,%r14,2),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  0x30(%rsp),%xmm0
addsd  %xmm0,%xmm1
cvttsd2si %xmm1,%eax
mov    %ax,(%r12,%r14,2)
add    $0x1,%r14
cmp    $0x1000,%r14
jne    1490 <main+0x2f0>
jmp    1460 <main+0x2c0>
nop
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  0x14(%rsp),%xmm0
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <oscil@plt>
divsd  0x30(%rsp),%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,(%r12,%rbp,2)
add    $0x1,%rbp
cmp    $0x1000,%rbp
jne    14e0 <main+0x340>
jmp    1460 <main+0x2c0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x8(%rsp),%r14d
mov    0x10(%rsp),%r15d
mov    0xc(%rsp),%ebp
mov    0x40(%rsp),%r12
mov    0x38(%rsp),%rax
jmp    1543 <main+0x3a3>
nopw   0x0(%rax,%rax,1)
movslq %r12d,%rax
shl    $0xd,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x2760,%rsi
mov    %r14d,%edi
mov    $0x2000,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1593 <main+0x3f3>
cmp    $0x3,%r12d
jge    13e0 <main+0x240>
add    $0x1,%r12d
jmp    1401 <main+0x261>
mov    %r14d,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x16768,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb2f(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xab0(%rip),%rdi
jmp    159a <main+0x3fa>
lea    0xab0(%rip),%rdi
jmp    159a <main+0x3fa>
lea    0xabf(%rip),%rdi
jmp    159a <main+0x3fa>
lea    0xac8(%rip),%rdi
jmp    159a <main+0x3fa>
lea    0xad1(%rip),%rdi
jmp    159a <main+0x3fa>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/dsp\00"
@O_WRONLY = global i32 0
@SNDCTL_DSP_SETFRAGMENT = global i32 0
@.str.1 = [24 x i8] c"incorrect fragment size\00"
@SNDCTL_DSP_SYNC = global i32 0
@AFMT_S16_LE = global i32 0
@SNDCTL_DSP_SETFMT = global i32 0
@.str.2 = [18 x i8] c"SNDCTL_DSP_SETFMT\00"
@SNDCTL_DSP_STEREO = global i32 0
@.str.3 = [18 x i8] c"SNDCTL_DSP_STEREO\00"
@SNDCTL_DSP_SPEED = global i32 0
@.str.4 = [17 x i8] c"SNDCTL_DSP_SPEED\00"
@SNDCTL_DSP_GETBLKSIZE = global i32 0
@.str.5 = [19 x i8] c"Audio buffer: %d\0A\00"
@.str.6 = [12 x i8] c"audio write\00"
@.str.7 = [27 x i8] c"%d oscillators, daddy-oh!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [1000 x i16]
%11 = alloca [10 x [4096 x i16]]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca [1000 x float]
%18 = alloca [1000 x float]
store i32 0, i32* %1
%19 = load i32, i32* @O_WRONLY
%20 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %19, i32 0)
store i32 %20, i32* %8
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %0
%23 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %0
store i32 2004811786, i32* %9
%26 = load i32, i32* %8
%27 = load i32, i32* @SNDCTL_DSP_SETFRAGMENT
%28 = call i32 @ioctl(i32 %26, i32 %27, i32* %9)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %25
%34 = load i32, i32* %8
%35 = load i32, i32* @SNDCTL_DSP_SYNC
%36 = call i32 @ioctl(i32 %34, i32 %35, i32* null)
%37 = load i32, i32* @AFMT_S16_LE
store i32 %37, i32* %3
%38 = load i32, i32* %8
%39 = load i32, i32* @SNDCTL_DSP_SETFMT
%40 = call i32 @ioctl(i32 %38, i32 %39, i32* %3)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %45
42: ; preds = %33
%43 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %33
store i32 0, i32* %4
%46 = load i32, i32* %8
%47 = load i32, i32* @SNDCTL_DSP_STEREO
%48 = call i32 @ioctl(i32 %46, i32 %47, i32* %4)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %45
store i32 44100, i32* %5
%54 = load i32, i32* %8
%55 = load i32, i32* @SNDCTL_DSP_SPEED
%56 = call i32 @ioctl(i32 %54, i32 %55, i32* %5)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %61
58: ; preds = %53
%59 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %53
%62 = load i32, i32* %8
%63 = load i32, i32* @SNDCTL_DSP_GETBLKSIZE
%64 = call i32 @ioctl(i32 %62, i32 %63, i32* %7)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %68
66: ; preds = %61
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %61
%69 = load i32, i32* %7
%70 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %69)
%71 = getelementptr inbounds [1000 x i16], [1000 x i16]* %10, i64 0, i64 0
%72 = call i32 @makewave(i16* %71)
store i32 0, i32* %12
br label %73
73: ; preds = %90, %68
%74 = load i32, i32* %12
%75 = icmp slt i32 %74, 1000
br i1 %75, label %76, label %93
76: ; preds = %73
%77 = load i32, i32* %12
%78 = mul nsw i32 %77, 5
%79 = sitofp i32 %78 to double
%80 = fadd double 2.780000e+02, %79
%81 = fmul double %80, 1.000000e+03
%82 = fdiv double %81, 4.410000e+04
%83 = fptrunc double %82 to float
%84 = load i32, i32* %12
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [1000 x float], [1000 x float]* %17, i64 0, i64 %85
store float %83, float* %86
%87 = load i32, i32* %12
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [1000 x float], [1000 x float]* %18, i64 0, i64 %88
store float 0.000000e+00, float* %89
br label %90
90: ; preds = %76
%91 = load i32, i32* %12
%92 = add nsw i32 %91, 1
store i32 %92, i32* %12
br label %73
93: ; preds = %73
store i32 0, i32* %15
store i32 1, i32* %16
store i32 0, i32* %12
br label %94
94: ; preds = %196, %93
%95 = load i32, i32* %12
%96 = icmp slt i32 %95, 99999
br i1 %96, label %97, label %199
97: ; preds = %94
store i32 0, i32* %14
br label %98
98: ; preds = %167, %97
%99 = load i32, i32* %14
%100 = load i32, i32* %16
%101 = icmp slt i32 %99, %100
br i1 %101, label %102, label %170
102: ; preds = %98
%103 = load i32, i32* %14
%104 = icmp eq i32 %103, 0
br i1 %104, label %105, label %134
105: ; preds = %102
store i32 0, i32* %13
br label %106
106: ; preds = %130, %105
%107 = load i32, i32* %13
%108 = icmp slt i32 %107, 4096
br i1 %108, label %109, label %133
109: ; preds = %106
%110 = load i32, i32* %14
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds [1000 x float], [1000 x float]* %17, i64 0, i64 %111
%113 = load float, float* %112
%114 = getelementptr inbounds [1000 x i16], [1000 x i16]* %10, i64 0, i64 0
%115 = load i32, i32* %14
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds [1000 x float], [1000 x float]* %18, i64 0, i64 %116
%118 = call double @oscil(float %113, i16* %114, float* %117)
%119 = fmul double %118, 1.000000e+00
%120 = load i32, i32* %16
%121 = sitofp i32 %120 to double
%122 = fdiv double %119, %121
%123 = fptosi double %122 to i16
%124 = load i32, i32* %15
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds [10 x [4096 x i16]], [10 x [4096 x i16]]* %11, i64 0, i64 %125
%127 = load i32, i32* %13
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds [4096 x i16], [4096 x i16]* %126, i64 0, i64 %128
store i16 %123, i16* %129
br label %130
130: ; preds = %109
%131 = load i32, i32* %13
%132 = add nsw i32 %131, 1
store i32 %132, i32* %13
br label %106
133: ; preds = %106
br label %166
134: ; preds = %102
store i32 0, i32* %13
br label %135
135: ; preds = %162, %134
%136 = load i32, i32* %13
%137 = icmp slt i32 %136, 4096
br i1 %137, label %138, label %165
138: ; preds = %135
%139 = load i32, i32* %14
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds [1000 x float], [1000 x float]* %17, i64 0, i64 %140
%142 = load float, float* %141
%143 = getelementptr inbounds [1000 x i16], [1000 x i16]* %10, i64 0, i64 0
%144 = load i32, i32* %14
%145 = sext i32 %144 to i64
%146 = getelementptr inbounds [1000 x float], [1000 x float]* %18, i64 0, i64 %145
%147 = call double @oscil(float %142, i16* %143, float* %146)
%148 = fmul double %147, 1.000000e+00
%149 = load i32, i32* %16
%150 = sitofp i32 %149 to double
%151 = fdiv double %148, %150
%152 = load i32, i32* %15
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds [10 x [4096 x i16]], [10 x [4096 x i16]]* %11, i64 0, i64 %153
%155 = load i32, i32* %13
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds [4096 x i16], [4096 x i16]* %154, i64 0, i64 %156
%158 = load i16, i16* %157
%159 = sitofp i16 %158 to double
%160 = fadd double %159, %151
%161 = fptosi double %160 to i16
store i16 %161, i16* %157
br label %162
162: ; preds = %138
%163 = load i32, i32* %13
%164 = add nsw i32 %163, 1
store i32 %164, i32* %13
br label %135
165: ; preds = %135
br label %166
166: ; preds = %165, %133
br label %167
167: ; preds = %166
%168 = load i32, i32* %14
%169 = add nsw i32 %168, 1
store i32 %169, i32* %14
br label %98
170: ; preds = %98
%171 = load i32, i32* %8
%172 = load i32, i32* %15
%173 = sext i32 %172 to i64
%174 = getelementptr inbounds [10 x [4096 x i16]], [10 x [4096 x i16]]* %11, i64 0, i64 %173
%175 = getelementptr inbounds [4096 x i16], [4096 x i16]* %174, i64 0, i64 0
%176 = call i32 @write(i32 %171, i16* %175, i32 8192)
store i32 %176, i32* %2
%177 = icmp eq i32 %176, -1
br i1 %177, label %178, label %181
178: ; preds = %170
%179 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%180 = call i32 @exit(i32 1)
unreachable
181: ; preds = %170
%182 = load i32, i32* %15
%183 = add nsw i32 %182, 1
store i32 %183, i32* %15
%184 = icmp sgt i32 %183, 3
br i1 %184, label %185, label %195
185: ; preds = %181
%186 = load i32, i32* %16
%187 = add nsw i32 %186, 1
store i32 %187, i32* %16
%188 = icmp sgt i32 %187, 1000
br i1 %188, label %189, label %192
189: ; preds = %185
%190 = load i32, i32* %16
%191 = sub nsw i32 %190, 1
store i32 %191, i32* %16
br label %192
192: ; preds = %189, %185
%193 = load i32, i32* %16
%194 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %193)
store i32 0, i32* %15
br label %195
195: ; preds = %192, %181
br label %196
196: ; preds = %195
%197 = load i32, i32* %12
%198 = add nsw i32 %197, 1
store i32 %198, i32* %12
br label %94
199: ; preds = %94
%200 = load i32, i32* %8
%201 = call i32 @close(i32 %200)
%202 = load i32, i32* %1
ret i32 %202
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/dsp\00"
@O_WRONLY = global i32 0
@SNDCTL_DSP_SETFRAGMENT = global i32 0
@.str.1 = [24 x i8] c"incorrect fragment size\00"
@SNDCTL_DSP_SYNC = global i32 0
@AFMT_S16_LE = global i32 0
@SNDCTL_DSP_SETFMT = global i32 0
@.str.2 = [18 x i8] c"SNDCTL_DSP_SETFMT\00"
@SNDCTL_DSP_STEREO = global i32 0
@.str.3 = [18 x i8] c"SNDCTL_DSP_STEREO\00"
@SNDCTL_DSP_SPEED = global i32 0
@.str.4 = [17 x i8] c"SNDCTL_DSP_SPEED\00"
@SNDCTL_DSP_GETBLKSIZE = global i32 0
@.str.5 = [19 x i8] c"Audio buffer: %d\0A\00"
@.str.6 = [12 x i8] c"audio write\00"
@.str.7 = [27 x i8] c"%d oscillators, daddy-oh!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1000 x i16]
%7 = alloca [10 x [4096 x i16]]
%8 = alloca [1000 x float]
%9 = alloca [1000 x float]
%10 = bitcast [1000 x float]* %9 to i8*
%11 = bitcast i32* %1 to i8*
%12 = bitcast i32* %2 to i8*
%13 = bitcast i32* %3 to i8*
%14 = bitcast i32* %4 to i8*
%15 = bitcast i32* %5 to i8*
%16 = bitcast [1000 x i16]* %6 to i8*
%17 = bitcast [10 x [4096 x i16]]* %7 to i8*
%18 = bitcast [1000 x float]* %8 to i8*
%19 = load i32, i32* @O_WRONLY
%20 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %19, i32 0)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %0
%23 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %0
store i32 2004811786, i32* %5
%26 = load i32, i32* @SNDCTL_DSP_SETFRAGMENT
%27 = call i32 @ioctl(i32 %20, i32 %26, i32* %5)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %25
%33 = load i32, i32* @SNDCTL_DSP_SYNC
%34 = call i32 @ioctl(i32 %20, i32 %33, i32* null)
%35 = load i32, i32* @AFMT_S16_LE
store i32 %35, i32* %1
%36 = load i32, i32* @SNDCTL_DSP_SETFMT
%37 = call i32 @ioctl(i32 %20, i32 %36, i32* %1)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %42
39: ; preds = %32
%40 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %32
store i32 0, i32* %2
%43 = load i32, i32* @SNDCTL_DSP_STEREO
%44 = call i32 @ioctl(i32 %20, i32 %43, i32* %2)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %42
store i32 44100, i32* %3
%50 = load i32, i32* @SNDCTL_DSP_SPEED
%51 = call i32 @ioctl(i32 %20, i32 %50, i32* %3)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %49
%57 = load i32, i32* @SNDCTL_DSP_GETBLKSIZE
%58 = call i32 @ioctl(i32 %20, i32 %57, i32* %4)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %56
%63 = load i32, i32* %4
%64 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %63)
%65 = getelementptr inbounds [1000 x i16], [1000 x i16]* %6, i64 0, i64 0
%66 = call i32 @makewave(i16* %65)
br label %67
67: ; preds = %67, %62
%68 = phi i64 [ 0, %62 ], [ %88, %67 ]
%69 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %62 ], [ %89, %67 ]
%70 = mul <4 x i32> %69, <i32 5, i32 5, i32 5, i32 5>
%71 = sitofp <4 x i32> %70 to <4 x double>
%72 = fadd <4 x double> %71, <double 2.780000e+02, double 2.780000e+02, double 2.780000e+02, double 2.780000e+02>
%73 = fmul <4 x double> %72, <double 1.000000e+03, double 1.000000e+03, double 1.000000e+03, double 1.000000e+03>
%74 = fdiv <4 x double> %73, <double 4.410000e+04, double 4.410000e+04, double 4.410000e+04, double 4.410000e+04>
%75 = fptrunc <4 x double> %74 to <4 x float>
%76 = getelementptr inbounds [1000 x float], [1000 x float]* %8, i64 0, i64 %68
%77 = bitcast float* %76 to <4 x float>*
store <4 x float> %75, <4 x float>* %77
%78 = or i64 %68, 4
%79 = mul <4 x i32> %69, <i32 5, i32 5, i32 5, i32 5>
%80 = add <4 x i32> %79, <i32 20, i32 20, i32 20, i32 20>
%81 = sitofp <4 x i32> %80 to <4 x double>
%82 = fadd <4 x double> %81, <double 2.780000e+02, double 2.780000e+02, double 2.780000e+02, double 2.780000e+02>
%83 = fmul <4 x double> %82, <double 1.000000e+03, double 1.000000e+03, double 1.000000e+03, double 1.000000e+03>
%84 = fdiv <4 x double> %83, <double 4.410000e+04, double 4.410000e+04, double 4.410000e+04, double 4.410000e+04>
%85 = fptrunc <4 x double> %84 to <4 x float>
%86 = getelementptr inbounds [1000 x float], [1000 x float]* %8, i64 0, i64 %78
%87 = bitcast float* %86 to <4 x float>*
store <4 x float> %85, <4 x float>* %87
%88 = add nuw nsw i64 %68, 8
%89 = add <4 x i32> %69, <i32 8, i32 8, i32 8, i32 8>
%90 = icmp eq i64 %88, 1000
br i1 %90, label %91, label %67
91: ; preds = %67
%92 = getelementptr inbounds [1000 x float], [1000 x float]* %8, i64 0, i64 0
%93 = load float, float* %92
%94 = getelementptr inbounds [1000 x float], [1000 x float]* %9, i64 0, i64 0
br label %95
95: ; preds = %91, %151
%96 = phi i32 [ 1, %91 ], [ %153, %151 ]
%97 = phi i32 [ 0, %91 ], [ %152, %151 ]
%98 = phi i32 [ 0, %91 ], [ %154, %151 ]
%99 = icmp sgt i32 %96, 0
br i1 %99, label %102, label %100
100: ; preds = %95
%101 = sext i32 %97 to i64
br label %135
102: ; preds = %95
%103 = sitofp i32 %96 to double
%104 = sext i32 %97 to i64
%105 = zext i32 %96 to i64
br label %106
106: ; preds = %102, %132
%107 = phi i64 [ 0, %102 ], [ %133, %132 ]
%108 = icmp eq i64 %107, 0
br i1 %108, label %113, label %109
109: ; preds = %106
%110 = getelementptr inbounds [1000 x float], [1000 x float]* %8, i64 0, i64 %107
%111 = load float, float* %110
%112 = getelementptr inbounds [1000 x float], [1000 x float]* %9, i64 0, i64 %107
br label %121
113: ; preds = %106, %113
%114 = phi i64 [ %119, %113 ], [ 0, %106 ]
%115 = call double @oscil(float %93, i16* %65, float* %94)
%116 = fdiv double %115, %103
%117 = fptosi double %116 to i16
%118 = getelementptr inbounds [10 x [4096 x i16]], [10 x [4096 x i16]]* %7, i64 0, i64 %104, i64 %114
store i16 %117, i16* %118
%119 = add nuw nsw i64 %114, 1
%120 = icmp eq i64 %119, 4096
br i1 %120, label %132, label %113
121: ; preds = %109, %121
%122 = phi i64 [ 0, %109 ], [ %130, %121 ]
%123 = call double @oscil(float %111, i16* %65, float* %112)
%124 = fdiv double %123, %103
%125 = getelementptr inbounds [10 x [4096 x i16]], [10 x [4096 x i16]]* %7, i64 0, i64 %104, i64 %122
%126 = load i16, i16* %125
%127 = sitofp i16 %126 to double
%128 = fadd double %124, %127
%129 = fptosi double %128 to i16
store i16 %129, i16* %125
%130 = add nuw nsw i64 %122, 1
%131 = icmp eq i64 %130, 4096
br i1 %131, label %132, label %121
132: ; preds = %121, %113
%133 = add nuw nsw i64 %107, 1
%134 = icmp eq i64 %133, %105
br i1 %134, label %135, label %106
135: ; preds = %132, %100
%136 = phi i64 [ %101, %100 ], [ %104, %132 ]
%137 = getelementptr inbounds [10 x [4096 x i16]], [10 x [4096 x i16]]* %7, i64 0, i64 %136, i64 0
%138 = call i32 @write(i32 %20, i16* %137, i32 8192)
%139 = icmp eq i32 %138, -1
br i1 %139, label %140, label %143
140: ; preds = %135
%141 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%142 = call i32 @exit(i32 1)
unreachable
143: ; preds = %135
%144 = add nsw i32 %97, 1
%145 = icmp sgt i32 %97, 2
br i1 %145, label %146, label %151
146: ; preds = %143
%147 = icmp slt i32 %96, 1000
%148 = zext i1 %147 to i32
%149 = add nsw i32 %96, %148
%150 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %149)
br label %151
151: ; preds = %143, %146
%152 = phi i32 [ 0, %146 ], [ %144, %143 ]
%153 = phi i32 [ %149, %146 ], [ %96, %143 ]
%154 = add nuw nsw i32 %98, 1
%155 = icmp eq i32 %154, 99999
br i1 %155, label %156, label %95
156: ; preds = %151
%157 = call i32 @close(i32 %20)
ret i32 0
}