#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, int);
int write(int, char *, int);
void WriteAiff(int f, long int bytes) {
  long size = bytes + 54;
  long frames = bytes / 4;
  int dummy __attribute__((unused));
  dummy = write(f, "FORM", 4);
  PutNum(size - 8, f, 1, 4);
  dummy = write(f, "AIFF", 4);
  dummy = write(f, "COMM", 4);
  PutNum(18, f, 1, 4);
  PutNum(2, f, 1, 2);
  PutNum(frames, f, 1, 4);
  PutNum(16, f, 1, 2);
  dummy = write(f, "@\016\254D\0\0\0\0\0\0", 10);
  dummy = write(f, "SSND", 4);
  PutNum(bytes + 8, f, 1, 4);
  PutNum(0, f, 1, 4);
  PutNum(0, f, 1, 4);
}


x86 assembly (clang, -O0):
<WriteAiff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x36,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x4,%ecx
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    0xea9(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
sub    $0x8,%rdi
mov    -0x4(%rbp),%esi
mov    $0x1,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
mov    -0x4(%rbp),%edi
lea    0xe7d(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
lea    0xe6b(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%esi
mov    $0x12,%edi
mov    $0x1,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
mov    -0x4(%rbp),%esi
mov    $0x2,%edi
mov    $0x1,%edx
mov    $0x2,%ecx
call   1040 <PutNum@plt>
mov    -0x20(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    $0x1,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
mov    -0x4(%rbp),%esi
mov    $0x10,%edi
mov    $0x1,%edx
mov    $0x2,%ecx
call   1040 <PutNum@plt>
mov    -0x4(%rbp),%edi
lea    0xe03(%rip),%rsi
mov    $0xa,%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
lea    0xde7(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
mov    -0x4(%rbp),%esi
mov    $0x1,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
mov    -0x4(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
mov    -0x4(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WriteAiff>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
lea    0x3(%rsi),%r15
test   %rsi,%rsi
cmovns %rsi,%r15
sar    $0x2,%r15
lea    0xec0(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
lea    0x2e(%r14),%rdi
mov    %ebx,%esi
mov    $0x1,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
lea    0xe9f(%rip),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
lea    0xe91(%rip),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
mov    $0x12,%edi
mov    %ebx,%esi
mov    $0x1,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
mov    $0x2,%edi
mov    %ebx,%esi
mov    $0x1,%edx
mov    $0x2,%ecx
call   1040 <PutNum@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
mov    $0x10,%edi
mov    %ebx,%esi
mov    $0x1,%edx
mov    $0x2,%ecx
call   1040 <PutNum@plt>
lea    0xe32(%rip),%rsi
mov    %ebx,%edi
mov    $0xa,%edx
call   1030 <write@plt>
lea    0xe1a(%rip),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
add    $0x8,%r14
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
xor    %edi,%edi
mov    %ebx,%esi
mov    $0x1,%edx
mov    $0x4,%ecx
call   1040 <PutNum@plt>
xor    %edi,%edi
mov    %ebx,%esi
mov    $0x1,%edx
mov    $0x4,%ecx
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <PutNum@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"FORM\00"
@.str.1 = [5 x i8] c"AIFF\00"
@.str.2 = [5 x i8] c"COMM\00"
@.str.3 = [11 x i8] c"@\0E\ACD\00\00\00\00\00\00\00"
@.str.4 = [5 x i8] c"SSND\00"
define void @WriteAiff(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %3
store i64 %1, i64* %4
%8 = load i64, i64* %4
%9 = add nsw i64 %8, 54
store i64 %9, i64* %5
%10 = load i64, i64* %4
%11 = sdiv i64 %10, 4
store i64 %11, i64* %6
%12 = load i32, i32* %3
%13 = call i32 @write(i32 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
store i32 %13, i32* %7
%14 = load i64, i64* %5
%15 = sub nsw i64 %14, 8
%16 = load i32, i32* %3
%17 = call i32 @PutNum(i64 %15, i32 %16, i32 1, i32 4)
%18 = load i32, i32* %3
%19 = call i32 @write(i32 %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
store i32 %19, i32* %7
%20 = load i32, i32* %3
%21 = call i32 @write(i32 %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
store i32 %21, i32* %7
%22 = load i32, i32* %3
%23 = call i32 @PutNum(i64 18, i32 %22, i32 1, i32 4)
%24 = load i32, i32* %3
%25 = call i32 @PutNum(i64 2, i32 %24, i32 1, i32 2)
%26 = load i64, i64* %6
%27 = load i32, i32* %3
%28 = call i32 @PutNum(i64 %26, i32 %27, i32 1, i32 4)
%29 = load i32, i32* %3
%30 = call i32 @PutNum(i64 16, i32 %29, i32 1, i32 2)
%31 = load i32, i32* %3
%32 = call i32 @write(i32 %31, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 10)
store i32 %32, i32* %7
%33 = load i32, i32* %3
%34 = call i32 @write(i32 %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
store i32 %34, i32* %7
%35 = load i64, i64* %4
%36 = add nsw i64 %35, 8
%37 = load i32, i32* %3
%38 = call i32 @PutNum(i64 %36, i32 %37, i32 1, i32 4)
%39 = load i32, i32* %3
%40 = call i32 @PutNum(i64 0, i32 %39, i32 1, i32 4)
%41 = load i32, i32* %3
%42 = call i32 @PutNum(i64 0, i32 %41, i32 1, i32 4)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"FORM\00"
@.str.1 = [5 x i8] c"AIFF\00"
@.str.2 = [5 x i8] c"COMM\00"
@.str.3 = [11 x i8] c"@\0E\ACD\00\00\00\00\00\00\00"
@.str.4 = [5 x i8] c"SSND\00"
define void @WriteAiff(i32 %0, i64 %1) {
%3 = sdiv i64 %1, 4
%4 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%5 = add nsw i64 %1, 46
%6 = tail call i32 @PutNum(i64 %5, i32 %0, i32 1, i32 4)
%7 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%8 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%9 = tail call i32 @PutNum(i64 18, i32 %0, i32 1, i32 4)
%10 = tail call i32 @PutNum(i64 2, i32 %0, i32 1, i32 2)
%11 = tail call i32 @PutNum(i64 %3, i32 %0, i32 1, i32 4)
%12 = tail call i32 @PutNum(i64 16, i32 %0, i32 1, i32 2)
%13 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 10)
%14 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%15 = add nsw i64 %1, 8
%16 = tail call i32 @PutNum(i64 %15, i32 %0, i32 1, i32 4)
%17 = tail call i32 @PutNum(i64 0, i32 %0, i32 1, i32 4)
%18 = tail call i32 @PutNum(i64 0, i32 %0, i32 1, i32 4)
ret void
}