#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 */
typedef int int32_t;
typedef int int16_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int _le_16(int);
int _le_32(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
void twtw_write_wav_header(FILE *file, int rate, int channels, int format,
                           int size) {
  char ch[5];
  int32_t itmp;
  int16_t stmp;
  ch[4] = 0;
  fprintf(file, "RIFF");
  itmp = 0x7fffffff;
  fwrite(&itmp, 4, 1, file);
  fprintf(file, "WAVEfmt ");
  itmp = _le_32(16);
  fwrite(&itmp, 4, 1, file);
  stmp = _le_16(1);
  fwrite(&stmp, 2, 1, file);
  stmp = _le_16(channels);
  fwrite(&stmp, 2, 1, file);
  itmp = _le_32(rate);
  fwrite(&itmp, 4, 1, file);
  itmp = _le_32(rate * channels * 2);
  fwrite(&itmp, 4, 1, file);
  stmp = _le_16(2 * channels);
  fwrite(&stmp, 2, 1, file);
  stmp = _le_16(16);
  fwrite(&stmp, 2, 1, file);
  fprintf(file, "data");
  itmp = _le_32(0x7fffffff);
  fwrite(&itmp, 4, 1, file);
}


x86 assembly (clang, -O0):
<twtw_write_wav_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe98(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x7fffffff,-0x24(%rbp)
mov    -0x8(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0x8(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x10,%edi
call   1030 <_le_32@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    $0x1,%edi
call   1050 <_le_16@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rcx
lea    -0x28(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0x10(%rbp),%edi
call   1050 <_le_16@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rcx
lea    -0x28(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0xc(%rbp),%edi
call   1030 <_le_32@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0xc(%rbp),%edi
imul   -0x10(%rbp),%edi
shl    $0x1,%edi
call   1030 <_le_32@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0x10(%rbp),%edi
shl    $0x1,%edi
call   1050 <_le_16@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rcx
lea    -0x28(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    $0x10,%edi
call   1050 <_le_16@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rcx
lea    -0x28(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0x8(%rbp),%rdi
lea    0xd6a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x7fffffff,%edi
call   1030 <_le_32@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<twtw_write_wav_header>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xeb5(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
movl   $0x7fffffff,0x8(%rsp)
7f
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
lea    0xe7f(%rip),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
mov    $0x10,%edi
call   1030 <_le_32@plt>
mov    %eax,0x8(%rsp)
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
mov    $0x1,%edi
call   1040 <_le_16@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%r12
mov    %r12,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
mov    %r15d,%edi
call   1040 <_le_16@plt>
mov    %eax,0xc(%rsp)
mov    %r12,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
mov    %ebp,%edi
call   1030 <_le_32@plt>
mov    %eax,0x8(%rsp)
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
imul   %r15d,%ebp
add    %ebp,%ebp
mov    %ebp,%edi
call   1030 <_le_32@plt>
mov    %eax,0x8(%rsp)
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
add    %r15d,%r15d
mov    %r15d,%edi
call   1040 <_le_16@plt>
mov    %eax,0xc(%rsp)
mov    %r12,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
mov    $0x10,%edi
call   1040 <_le_16@plt>
mov    %eax,0xc(%rsp)
mov    %r12,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
lea    0xd76(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
mov    $0x7fffffff,%edi
call   1030 <_le_32@plt>
mov    %eax,0x8(%rsp)
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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 @twtw_write_wav_header(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [5 x i8]
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%14 = getelementptr inbounds [5 x i8], [5 x i8]* %11, i64 0, i64 4
store i8 0, i8* %14
%15 = load i32*, i32** %6
%16 = call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 2147483647, i32* %12
%17 = load i32*, i32** %6
%18 = call i32 @fwrite(i32* %12, i32 4, i32 1, i32* %17)
%19 = load i32*, i32** %6
%20 = call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @_le_32(i32 16)
store i32 %21, i32* %12
%22 = load i32*, i32** %6
%23 = call i32 @fwrite(i32* %12, i32 4, i32 1, i32* %22)
%24 = call i32 @_le_16(i32 1)
store i32 %24, i32* %13
%25 = load i32*, i32** %6
%26 = call i32 @fwrite(i32* %13, i32 2, i32 1, i32* %25)
%27 = load i32, i32* %8
%28 = call i32 @_le_16(i32 %27)
store i32 %28, i32* %13
%29 = load i32*, i32** %6
%30 = call i32 @fwrite(i32* %13, i32 2, i32 1, i32* %29)
%31 = load i32, i32* %7
%32 = call i32 @_le_32(i32 %31)
store i32 %32, i32* %12
%33 = load i32*, i32** %6
%34 = call i32 @fwrite(i32* %12, i32 4, i32 1, i32* %33)
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = mul nsw i32 %35, %36
%38 = mul nsw i32 %37, 2
%39 = call i32 @_le_32(i32 %38)
store i32 %39, i32* %12
%40 = load i32*, i32** %6
%41 = call i32 @fwrite(i32* %12, i32 4, i32 1, i32* %40)
%42 = load i32, i32* %8
%43 = mul nsw i32 2, %42
%44 = call i32 @_le_16(i32 %43)
store i32 %44, i32* %13
%45 = load i32*, i32** %6
%46 = call i32 @fwrite(i32* %13, i32 2, i32 1, i32* %45)
%47 = call i32 @_le_16(i32 16)
store i32 %47, i32* %13
%48 = load i32*, i32** %6
%49 = call i32 @fwrite(i32* %13, i32 2, i32 1, i32* %48)
%50 = load i32*, i32** %6
%51 = call i32 @fprintf(i32* %50, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%52 = call i32 @_le_32(i32 2147483647)
store i32 %52, i32* %12
%53 = load i32*, i32** %6
%54 = call i32 @fwrite(i32* %12, i32 4, i32 1, i32* %53)
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 @twtw_write_wav_header(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %6 to i8*
%9 = bitcast i32* %7 to i8*
%10 = tail call i64 bitcast (i32 (i32*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 4, i64 1, i32* %0)
store i32 2147483647, i32* %6
%11 = call i32 @fwrite(i32* %6, i32 4, i32 1, i32* %0)
%12 = tail call i64 bitcast (i32 (i32*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 8, i64 1, i32* %0)
%13 = tail call i32 @_le_32(i32 16)
store i32 %13, i32* %6
%14 = call i32 @fwrite(i32* %6, i32 4, i32 1, i32* %0)
%15 = tail call i32 @_le_16(i32 1)
store i32 %15, i32* %7
%16 = call i32 @fwrite(i32* %7, i32 2, i32 1, i32* %0)
%17 = tail call i32 @_le_16(i32 %2)
store i32 %17, i32* %7
%18 = call i32 @fwrite(i32* %7, i32 2, i32 1, i32* %0)
%19 = tail call i32 @_le_32(i32 %1)
store i32 %19, i32* %6
%20 = call i32 @fwrite(i32* %6, i32 4, i32 1, i32* %0)
%21 = shl i32 %1, 1
%22 = mul i32 %21, %2
%23 = tail call i32 @_le_32(i32 %22)
store i32 %23, i32* %6
%24 = call i32 @fwrite(i32* %6, i32 4, i32 1, i32* %0)
%25 = shl nsw i32 %2, 1
%26 = tail call i32 @_le_16(i32 %25)
store i32 %26, i32* %7
%27 = call i32 @fwrite(i32* %7, i32 2, i32 1, i32* %0)
%28 = tail call i32 @_le_16(i32 16)
store i32 %28, i32* %7
%29 = call i32 @fwrite(i32* %7, i32 2, i32 1, i32* %0)
%30 = tail call i64 bitcast (i32 (i32*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 4, i64 1, i32* %0)
%31 = tail call i32 @_le_32(i32 2147483647)
store i32 %31, i32* %6
%32 = call i32 @fwrite(i32* %6, i32 4, i32 1, i32* %0)
ret void
}