#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 write(int, char *, int);
void WriteWav(int f, long int bytes) {
  int dummy __attribute__((unused));
  dummy = write(f, "RIFF", 4);
  PutNum(bytes + 44 - 8, f, 0, 4);
  dummy = 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);
  dummy = write(f, "data", 4);
  PutNum(bytes, f, 0, 4);
}


x86 assembly (clang, -O0):
<WriteWav>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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    %eax,-0x14(%rbp)
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    0xe9a(%rip),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
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    0xe00(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
add    $0x20,%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
%5 = alloca i32
store i32 %0, i32* %3
store i64 %1, i64* %4
%6 = load i32, i32* %3
%7 = call i32 @write(i32 %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
store i32 %7, i32* %5
%8 = load i64, i64* %4
%9 = add nsw i64 %8, 44
%10 = sub nsw i64 %9, 8
%11 = load i32, i32* %3
%12 = call i32 @PutNum(i64 %10, i32 %11, i32 0, i32 4)
%13 = load i32, i32* %3
%14 = call i32 @write(i32 %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
store i32 %14, i32* %5
%15 = load i32, i32* %3
%16 = call i32 @PutNum(i64 16, i32 %15, i32 0, i32 4)
%17 = load i32, i32* %3
%18 = call i32 @PutNum(i64 1, i32 %17, i32 0, i32 2)
%19 = load i32, i32* %3
%20 = call i32 @PutNum(i64 2, i32 %19, i32 0, i32 2)
%21 = load i32, i32* %3
%22 = call i32 @PutNum(i64 44100, i32 %21, i32 0, i32 4)
%23 = load i32, i32* %3
%24 = call i32 @PutNum(i64 176400, i32 %23, i32 0, i32 4)
%25 = load i32, i32* %3
%26 = call i32 @PutNum(i64 4, i32 %25, i32 0, i32 2)
%27 = load i32, i32* %3
%28 = call i32 @PutNum(i64 16, i32 %27, i32 0, i32 2)
%29 = load i32, i32* %3
%30 = call i32 @write(i32 %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
store i32 %30, i32* %5
%31 = load i64, i64* %4
%32 = load i32, i32* %3
%33 = call i32 @PutNum(i64 %31, i32 %32, 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
}