#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*/ memcpy(char *, ...);
int /*<<< orphan*/ write(int, char *, int);
void wav_head(int fd, int len, int nch) {
  char buf[44];
  memcpy(buf,
         "RIFF----WAVEfmt "
         "\020\0\0\0\01\0\01\0\x44\xac\0\0\x88\x58\01\0\02\0\020\0data",
         40);
  buf[22] = nch;
  int l = 2 * len * nch, rate = 88200 * nch;
  memcpy(buf + 28, &rate, 4);
  buf[32] = 2 * nch;
  memcpy(buf + 40, &l, 4);
  l += 36;
  memcpy(buf + 4, &l, 4);
  write(fd, buf, 44);
}


x86 assembly (clang, -O0):
<wav_head>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xec4(%rip),%rsi
xor    %eax,%eax
mov    $0x28,%edx
call   1040 <memcpy@plt>
mov    -0xc(%rbp),%eax
mov    %al,-0x2a(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x44(%rbp)
imul   $0x15888,-0xc(%rbp),%eax
mov    %eax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
add    $0x1c,%rdi
xor    %eax,%eax
lea    -0x48(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
add    $0x28,%rdi
xor    %eax,%eax
lea    -0x44(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x44(%rbp),%eax
add    $0x24,%eax
mov    %eax,-0x44(%rbp)
lea    -0x40(%rbp),%rdi
add    $0x4,%rdi
xor    %eax,%eax
lea    -0x44(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x4(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x2c,%edx
call   1030 <write@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wav_head>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %edx,%ebx
mov    %esi,%ebp
mov    %edi,%r15d
lea    0xec8(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x28,%edx
xor    %eax,%eax
call   1040 <memcpy@plt>
mov    %bl,0x26(%rsp)
imul   %ebx,%ebp
add    %ebp,%ebp
mov    %ebp,0x8(%rsp)
imul   $0x15888,%ebx,%eax
mov    %eax,0xc(%rsp)
lea    0x2c(%rsp),%rdi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <memcpy@plt>
lea    (%rbx,%rbx,1),%eax
mov    %al,0x30(%rsp)
lea    0x38(%rsp),%rdi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <memcpy@plt>
addl   $0x24,0x8(%rsp)
lea    0x14(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <memcpy@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x2c,%edx
call   1030 <write@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"RIFF----WAVEfmt \10\00\00\00\01\00\01\00D\AC\00\00\88X\01\00\02\00\10\00data\00"
define void @wav_head(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [44 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = getelementptr inbounds [44 x i8], [44 x i8]* %7, i64 0, i64 0
%11 = call i32 (i8*, ...) @memcpy(i8* %10, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 40)
%12 = load i32, i32* %6
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds [44 x i8], [44 x i8]* %7, i64 0, i64 22
store i8 %13, i8* %14
%15 = load i32, i32* %5
%16 = mul nsw i32 2, %15
%17 = load i32, i32* %6
%18 = mul nsw i32 %16, %17
store i32 %18, i32* %8
%19 = load i32, i32* %6
%20 = mul nsw i32 88200, %19
store i32 %20, i32* %9
%21 = getelementptr inbounds [44 x i8], [44 x i8]* %7, i64 0, i64 0
%22 = getelementptr inbounds i8, i8* %21, i64 28
%23 = call i32 (i8*, ...) @memcpy(i8* %22, i32* %9, i32 4)
%24 = load i32, i32* %6
%25 = mul nsw i32 2, %24
%26 = trunc i32 %25 to i8
%27 = getelementptr inbounds [44 x i8], [44 x i8]* %7, i64 0, i64 32
store i8 %26, i8* %27
%28 = getelementptr inbounds [44 x i8], [44 x i8]* %7, i64 0, i64 0
%29 = getelementptr inbounds i8, i8* %28, i64 40
%30 = call i32 (i8*, ...) @memcpy(i8* %29, i32* %8, i32 4)
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 36
store i32 %32, i32* %8
%33 = getelementptr inbounds [44 x i8], [44 x i8]* %7, i64 0, i64 0
%34 = getelementptr inbounds i8, i8* %33, i64 4
%35 = call i32 (i8*, ...) @memcpy(i8* %34, i32* %8, i32 4)
%36 = load i32, i32* %4
%37 = getelementptr inbounds [44 x i8], [44 x i8]* %7, i64 0, i64 0
%38 = call i32 @write(i32 %36, i8* %37, i32 44)
ret void
}

LLVM IR (-O2):
@.str = [41 x i8] c"RIFF----WAVEfmt \10\00\00\00\01\00\01\00D\AC\00\00\88X\01\00\02\00\10\00data\00"
define void @wav_head(i32 %0, i32 %1, i32 %2) {
%4 = alloca [44 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = getelementptr inbounds [44 x i8], [44 x i8]* %4, i64 0, i64 0
%8 = call i32 (i8*, ...) @memcpy(i8* %7, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 40)
%9 = trunc i32 %2 to i8
%10 = getelementptr inbounds [44 x i8], [44 x i8]* %4, i64 0, i64 22
store i8 %9, i8* %10
%11 = bitcast i32* %5 to i8*
%12 = shl nsw i32 %1, 1
%13 = mul nsw i32 %12, %2
store i32 %13, i32* %5
%14 = bitcast i32* %6 to i8*
%15 = mul nsw i32 %2, 88200
store i32 %15, i32* %6
%16 = getelementptr inbounds [44 x i8], [44 x i8]* %4, i64 0, i64 28
%17 = call i32 (i8*, ...) @memcpy(i8* %16, i32* %6, i32 4)
%18 = shl i8 %9, 1
%19 = getelementptr inbounds [44 x i8], [44 x i8]* %4, i64 0, i64 32
store i8 %18, i8* %19
%20 = getelementptr inbounds [44 x i8], [44 x i8]* %4, i64 0, i64 40
%21 = call i32 (i8*, ...) @memcpy(i8* %20, i32* %5, i32 4)
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 36
store i32 %23, i32* %5
%24 = getelementptr inbounds [44 x i8], [44 x i8]* %4, i64 0, i64 4
%25 = call i32 (i8*, ...) @memcpy(i8* %24, i32* %5, i32 4)
%26 = call i32 @write(i32 %0, i8* %7, i32 44)
ret void
}