#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 abs(int);
int dsp(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputi(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int samplerate = 44100;
  int nsamples = samplerate * 240;
  int bytesize = nsamples * 2;
  fprintf(stdout, "RIFF");
  fputi(bytesize + 36, 4, stdout);
  fprintf(stdout, "WAVE");
  fprintf(stdout, "fmt ");
  fputi(16, 4, stdout);
  fputi(1, 2, stdout);
  fputi(1, 2, stdout);
  fputi(samplerate, 4, stdout);
  fputi(samplerate * 2, 4, stdout);
  fputi(2, 2, stdout);
  fputi(16, 2, stdout);
  fprintf(stdout, "data");
  fputi(bytesize, 4, stdout);
  int maxAmplitude = 0;
  for (int tn = 0; tn < nsamples; tn++) {
    int sample = (int)(32767 * dsp(tn));
    int asample = abs(sample);
    if (asample > maxAmplitude)
      maxAmplitude = asample;
    fputi(sample, 2, stdout);
  }
  fprintf(stderr, "%d", maxAmplitude);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xac44,-0x14(%rbp)
imul   $0xf0,-0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%edi
add    $0x24,%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1040 <fputi@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edx
mov    $0x10,%edi
mov    $0x4,%esi
call   1040 <fputi@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%edi
mov    $0x2,%esi
call   1040 <fputi@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%edi
mov    $0x2,%esi
call   1040 <fputi@plt>
mov    -0x14(%rbp),%edi
mov    0x2db8(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1040 <fputi@plt>
mov    -0x14(%rbp),%edi
shl    $0x1,%edi
mov    0x2d9f(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1040 <fputi@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
mov    %esi,%edi
call   1040 <fputi@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edx
mov    $0x10,%edi
mov    $0x2,%esi
call   1040 <fputi@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
lea    0xd8d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%edi
mov    0x2d45(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1040 <fputi@plt>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    130b <main+0x1cb>
mov    -0x24(%rbp),%edi
call   1050 <dsp@plt>
imul   $0x7fff,%eax,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    12e7 <main+0x1a7>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%edi
mov    0x2ce7(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   1040 <fputi@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12ad <main+0x16d>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xcf6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e9a(%rip),%r14
mov    (%r14),%edi
lea    0xeb8(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14),%edx
mov    $0x142ffa4,%edi
mov    $0x4,%esi
call   1030 <fputi@plt>
mov    (%r14),%edi
lea    0xe98(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14),%edi
lea    0xe8c(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14),%edx
mov    $0x10,%edi
mov    $0x4,%esi
call   1030 <fputi@plt>
mov    (%r14),%edx
mov    $0x1,%edi
mov    $0x2,%esi
call   1030 <fputi@plt>
mov    (%r14),%edx
mov    $0x1,%edi
mov    $0x2,%esi
call   1030 <fputi@plt>
mov    (%r14),%edx
mov    $0xac44,%edi
mov    $0x4,%esi
call   1030 <fputi@plt>
mov    (%r14),%edx
mov    $0x15888,%edi
mov    $0x4,%esi
call   1030 <fputi@plt>
mov    (%r14),%edx
mov    $0x2,%edi
mov    $0x2,%esi
call   1030 <fputi@plt>
mov    (%r14),%edx
mov    $0x10,%edi
mov    $0x2,%esi
call   1030 <fputi@plt>
mov    (%r14),%edi
lea    0xe02(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14),%edx
mov    $0x142ff80,%edi
mov    $0x4,%esi
call   1030 <fputi@plt>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%r15d
mov    %ebp,%edi
call   1040 <dsp@plt>
mov    %eax,%edi
shl    $0xf,%edi
sub    %eax,%edi
mov    %edi,%ebx
neg    %ebx
cmovs  %edi,%ebx
cmp    %r15d,%ebx
cmovle %r15d,%ebx
mov    (%r14),%edx
mov    $0x2,%esi
call   1030 <fputi@plt>
add    $0x1,%ebp
cmp    $0xa17fc0,%ebp
jne    1230 <main+0x100>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
lea    0xd9d(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [5 x i8] c"RIFF\00"
@.str.1 = [5 x i8] c"WAVE\00"
@.str.2 = [5 x i8] c"fmt \00"
@.str.3 = [5 x i8] c"data\00"
@stderr = global i32 0
@.str.4 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 44100, i32* %6
%13 = load i32, i32* %6
%14 = mul nsw i32 %13, 240
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = mul nsw i32 %15, 2
store i32 %16, i32* %8
%17 = load i32, i32* @stdout
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* %8
%20 = add nsw i32 %19, 36
%21 = load i32, i32* @stdout
%22 = call i32 @fputi(i32 %20, i32 4, i32 %21)
%23 = load i32, i32* @stdout
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @stdout
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @stdout
%28 = call i32 @fputi(i32 16, i32 4, i32 %27)
%29 = load i32, i32* @stdout
%30 = call i32 @fputi(i32 1, i32 2, i32 %29)
%31 = load i32, i32* @stdout
%32 = call i32 @fputi(i32 1, i32 2, i32 %31)
%33 = load i32, i32* %6
%34 = load i32, i32* @stdout
%35 = call i32 @fputi(i32 %33, i32 4, i32 %34)
%36 = load i32, i32* %6
%37 = mul nsw i32 %36, 2
%38 = load i32, i32* @stdout
%39 = call i32 @fputi(i32 %37, i32 4, i32 %38)
%40 = load i32, i32* @stdout
%41 = call i32 @fputi(i32 2, i32 2, i32 %40)
%42 = load i32, i32* @stdout
%43 = call i32 @fputi(i32 16, i32 2, i32 %42)
%44 = load i32, i32* @stdout
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32, i32* %8
%47 = load i32, i32* @stdout
%48 = call i32 @fputi(i32 %46, i32 4, i32 %47)
store i32 0, i32* %9
store i32 0, i32* %10
br label %49
49: ; preds = %68, %2
%50 = load i32, i32* %10
%51 = load i32, i32* %7
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %71
53: ; preds = %49
%54 = load i32, i32* %10
%55 = call i32 @dsp(i32 %54)
%56 = mul nsw i32 32767, %55
store i32 %56, i32* %11
%57 = load i32, i32* %11
%58 = call i32 @abs(i32 %57)
store i32 %58, i32* %12
%59 = load i32, i32* %12
%60 = load i32, i32* %9
%61 = icmp sgt i32 %59, %60
br i1 %61, label %62, label %64
62: ; preds = %53
%63 = load i32, i32* %12
store i32 %63, i32* %9
br label %64
64: ; preds = %62, %53
%65 = load i32, i32* %11
%66 = load i32, i32* @stdout
%67 = call i32 @fputi(i32 %65, i32 2, i32 %66)
br label %68
68: ; preds = %64
%69 = load i32, i32* %10
%70 = add nsw i32 %69, 1
store i32 %70, i32* %10
br label %49
71: ; preds = %49
%72 = load i32, i32* @stderr
%73 = load i32, i32* %9
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %73)
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [5 x i8] c"RIFF\00"
@.str.1 = [5 x i8] c"WAVE\00"
@.str.2 = [5 x i8] c"fmt \00"
@.str.3 = [5 x i8] c"data\00"
@stderr = global i32 0
@.str.4 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @stdout
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdout
%6 = tail call i32 @fputi(i32 21168036, i32 4, i32 %5)
%7 = load i32, i32* @stdout
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @stdout
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @stdout
%12 = tail call i32 @fputi(i32 16, i32 4, i32 %11)
%13 = load i32, i32* @stdout
%14 = tail call i32 @fputi(i32 1, i32 2, i32 %13)
%15 = load i32, i32* @stdout
%16 = tail call i32 @fputi(i32 1, i32 2, i32 %15)
%17 = load i32, i32* @stdout
%18 = tail call i32 @fputi(i32 44100, i32 4, i32 %17)
%19 = load i32, i32* @stdout
%20 = tail call i32 @fputi(i32 88200, i32 4, i32 %19)
%21 = load i32, i32* @stdout
%22 = tail call i32 @fputi(i32 2, i32 2, i32 %21)
%23 = load i32, i32* @stdout
%24 = tail call i32 @fputi(i32 16, i32 2, i32 %23)
%25 = load i32, i32* @stdout
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32, i32* @stdout
%28 = tail call i32 @fputi(i32 21168000, i32 4, i32 %27)
br label %32
29: ; preds = %32
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %39)
ret i32 0
32: ; preds = %2, %32
%33 = phi i32 [ 0, %2 ], [ %39, %32 ]
%34 = phi i32 [ 0, %2 ], [ %42, %32 ]
%35 = tail call i32 @dsp(i32 %34)
%36 = mul nsw i32 %35, 32767
%37 = tail call i32 @llvm.abs.i32(i32 %36, i1 true)
%38 = icmp sgt i32 %37, %33
%39 = select i1 %38, i32 %37, i32 %33
%40 = load i32, i32* @stdout
%41 = tail call i32 @fputi(i32 %36, i32 2, i32 %40)
%42 = add nuw nsw i32 %34, 1
%43 = icmp eq i32 %42, 10584000
br i1 %43, label %29, label %32
}