#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*/ PutNum(long, int, int /*<<< orphan*/, int);
int /*<<< orphan*/ write(int, char *, int);
void WriteWav(int f, long int bytes) {
  write(f, "RIFF", 4);
  PutNum(bytes + 44 - 8, f, 0, 4);
  write(f, "WAVEfmt ", 8);
  PutNum(16, f, 0, 4);
  PutNum(1, f, 0, 2);
  PutNum(2, f, 0, 2);
  PutNum(44100, f, 0, 4);
  PutNum(44100 * 2 * 2, f, 0, 4);
  PutNum(4, f, 0, 2);
  PutNum(16, f, 0, 2);
  write(f, "data", 4);
  PutNum(bytes, f, 0, 4);
}


x86 assembly (clang, -O0):
<WriteWav>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    0xec7(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%rdi
add    $0x2c,%rdi
sub    $0x8,%rdi
mov    -0x4(%rbp),%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
mov    -0x4(%rbp),%edi
lea    0xe9d(%rip),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%esi
mov    $0x10,%edi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
mov    -0x4(%rbp),%esi
mov    $0x1,%edi
xor    %edx,%edx
mov    $0x2,%ecx
call   1040 <PutNum@plt>
mov    -0x4(%rbp),%esi
mov    $0x2,%edi
xor    %edx,%edx
mov    $0x2,%ecx
call   1040 <PutNum@plt>
mov    -0x4(%rbp),%esi
mov    $0xac44,%edi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
mov    -0x4(%rbp),%esi
mov    $0x2b110,%edi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
mov    -0x4(%rbp),%esi
mov    $0x4,%edi
xor    %edx,%edx
mov    $0x2,%ecx
call   1040 <PutNum@plt>
mov    -0x4(%rbp),%esi
mov    $0x10,%edi
xor    %edx,%edx
mov    $0x2,%ecx
call   1040 <PutNum@plt>
mov    -0x4(%rbp),%edi
lea    0xe06(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WriteWav>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xed0(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
lea    0x24(%r14),%rdi
mov    %ebx,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
lea    0xeb2(%rip),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1030 <write@plt>
mov    $0x10,%edi
mov    %ebx,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
mov    $0x1,%edi
mov    %ebx,%esi
xor    %edx,%edx
mov    $0x2,%ecx
call   1040 <PutNum@plt>
mov    $0x2,%edi
mov    %ebx,%esi
xor    %edx,%edx
mov    $0x2,%ecx
call   1040 <PutNum@plt>
mov    $0xac44,%edi
mov    %ebx,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
mov    $0x2b110,%edi
mov    %ebx,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
mov    $0x4,%edi
mov    %ebx,%esi
xor    %edx,%edx
mov    $0x2,%ecx
call   1040 <PutNum@plt>
mov    $0x10,%edi
mov    %ebx,%esi
xor    %edx,%edx
mov    $0x2,%ecx
call   1040 <PutNum@plt>
lea    0xe23(%rip),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %edx,%edx
mov    $0x4,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <PutNum@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"RIFF\00"
@.str.1 = [9 x i8] c"WAVEfmt \00"
@.str.2 = [5 x i8] c"data\00"
define void @WriteWav(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
store i32 %0, i32* %3
store i64 %1, i64* %4
%5 = load i32, i32* %3
%6 = call i32 @write(i32 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%7 = load i64, i64* %4
%8 = add nsw i64 %7, 44
%9 = sub nsw i64 %8, 8
%10 = load i32, i32* %3
%11 = call i32 @PutNum(i64 %9, i32 %10, i32 0, i32 4)
%12 = load i32, i32* %3
%13 = call i32 @write(i32 %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%14 = load i32, i32* %3
%15 = call i32 @PutNum(i64 16, i32 %14, i32 0, i32 4)
%16 = load i32, i32* %3
%17 = call i32 @PutNum(i64 1, i32 %16, i32 0, i32 2)
%18 = load i32, i32* %3
%19 = call i32 @PutNum(i64 2, i32 %18, i32 0, i32 2)
%20 = load i32, i32* %3
%21 = call i32 @PutNum(i64 44100, i32 %20, i32 0, i32 4)
%22 = load i32, i32* %3
%23 = call i32 @PutNum(i64 176400, i32 %22, i32 0, i32 4)
%24 = load i32, i32* %3
%25 = call i32 @PutNum(i64 4, i32 %24, i32 0, i32 2)
%26 = load i32, i32* %3
%27 = call i32 @PutNum(i64 16, i32 %26, i32 0, i32 2)
%28 = load i32, i32* %3
%29 = call i32 @write(i32 %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%30 = load i64, i64* %4
%31 = load i32, i32* %3
%32 = call i32 @PutNum(i64 %30, i32 %31, i32 0, i32 4)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"RIFF\00"
@.str.1 = [9 x i8] c"WAVEfmt \00"
@.str.2 = [5 x i8] c"data\00"
define void @WriteWav(i32 %0, i64 %1) {
%3 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%4 = add nsw i64 %1, 36
%5 = tail call i32 @PutNum(i64 %4, i32 %0, i32 0, i32 4)
%6 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%7 = tail call i32 @PutNum(i64 16, i32 %0, i32 0, i32 4)
%8 = tail call i32 @PutNum(i64 1, i32 %0, i32 0, i32 2)
%9 = tail call i32 @PutNum(i64 2, i32 %0, i32 0, i32 2)
%10 = tail call i32 @PutNum(i64 44100, i32 %0, i32 0, i32 4)
%11 = tail call i32 @PutNum(i64 176400, i32 %0, i32 0, i32 4)
%12 = tail call i32 @PutNum(i64 4, i32 %0, i32 0, i32 2)
%13 = tail call i32 @PutNum(i64 16, i32 %0, i32 0, i32 2)
%14 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%15 = tail call i32 @PutNum(i64 %1, i32 %0, i32 0, i32 4)
ret void
}