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

/* Variables and functions */
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ put_16bitLE(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ put_32bitLE(int /*<<< orphan*/ *, int);
void make_wav_header(uint8_t *buf, int32_t sample_count, int32_t sample_rate,
                     int channels) {
  size_t bytecount;
  bytecount = sample_count * channels * 2;
  memcpy(buf + 0, "RIFF", 4);
  put_32bitLE(buf + 4, (int32_t)(bytecount + 0x2c - 8));
  memcpy(buf + 8, "WAVE", 4);
  memcpy(buf + 0xc, "fmt ", 4);
  put_32bitLE(buf + 0x10, 0x10);
  put_16bitLE(buf + 0x14, 1);
  put_16bitLE(buf + 0x16, channels);
  put_32bitLE(buf + 0x18, sample_rate);
  put_32bitLE(buf + 0x1c, sample_rate * channels * 2);
  put_16bitLE(buf + 0x20, (int16_t)(channels * 2));
  put_16bitLE(buf + 0x22, 2 * 8);
  memcpy(buf + 0x24, "data", 4);
  put_32bitLE(buf + 0x28, (int32_t)bytecount);
}


x86 assembly (clang, -O0):
<make_wav_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x14(%rbp),%eax
shl    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea0(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
add    $0x10,%rdi
mov    -0x20(%rbp),%rax
add    $0x2c,%rax
sub    $0x8,%rax
mov    %eax,%esi
call   1050 <put_32bitLE@plt>
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
lea    0xe71(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
add    $0x30,%rdi
lea    0xe5d(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
add    $0x40,%rdi
mov    $0x10,%esi
call   1050 <put_32bitLE@plt>
mov    -0x8(%rbp),%rdi
add    $0x50,%rdi
mov    $0x1,%esi
call   1030 <put_16bitLE@plt>
mov    -0x8(%rbp),%rdi
add    $0x58,%rdi
mov    -0x14(%rbp),%esi
call   1030 <put_16bitLE@plt>
mov    -0x8(%rbp),%rdi
add    $0x60,%rdi
mov    -0x10(%rbp),%esi
call   1050 <put_32bitLE@plt>
mov    -0x8(%rbp),%rdi
add    $0x70,%rdi
mov    -0x10(%rbp),%esi
imul   -0x14(%rbp),%esi
shl    $0x1,%esi
call   1050 <put_32bitLE@plt>
mov    -0x8(%rbp),%rdi
add    $0x80,%rdi
mov    -0x14(%rbp),%esi
shl    $0x1,%esi
call   1030 <put_16bitLE@plt>
mov    -0x8(%rbp),%rdi
add    $0x88,%rdi
mov    $0x10,%esi
call   1030 <put_16bitLE@plt>
mov    -0x8(%rbp),%rdi
add    $0x90,%rdi
lea    0xdc0(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
add    $0xa0,%rdi
mov    -0x20(%rbp),%rax
mov    %eax,%esi
call   1050 <put_32bitLE@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_wav_header>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %esi,%ebp
mov    %rdi,%rbx
imul   %ecx,%ebp
lea    0x0(%rbp,%rbp,1),%r14d
lea    0xeae(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
lea    0x10(%rbx),%rdi
lea    0x24(%rbp,%rbp,1),%esi
call   1050 <put_32bitLE@plt>
lea    0x20(%rbx),%rdi
lea    0xe91(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
lea    0x30(%rbx),%rdi
lea    0xe81(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
lea    0x40(%rbx),%rdi
mov    $0x10,%esi
call   1050 <put_32bitLE@plt>
lea    0x50(%rbx),%rdi
mov    $0x1,%esi
call   1030 <put_16bitLE@plt>
lea    0x58(%rbx),%rdi
mov    %r15d,%esi
call   1030 <put_16bitLE@plt>
lea    0x60(%rbx),%rdi
mov    %r12d,%esi
call   1050 <put_32bitLE@plt>
lea    0x70(%rbx),%rdi
imul   %r15d,%r12d
add    %r12d,%r12d
mov    %r12d,%esi
call   1050 <put_32bitLE@plt>
lea    0x80(%rbx),%rdi
add    %r15d,%r15d
mov    %r15d,%esi
call   1030 <put_16bitLE@plt>
lea    0x88(%rbx),%rdi
mov    $0x10,%esi
call   1030 <put_16bitLE@plt>
lea    0x90(%rbx),%rdi
lea    0xe04(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
add    $0xa0,%rbx
mov    %rbx,%rdi
mov    %r14d,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <put_32bitLE@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"RIFF\00"
@.str.1 = [5 x i8] c"WAVE\00"
@.str.2 = [5 x i8] c"fmt \00"
@.str.3 = [5 x i8] c"data\00"
define void @make_wav_header(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %6
%11 = load i32, i32* %8
%12 = mul nsw i32 %10, %11
%13 = mul nsw i32 %12, 2
%14 = sext i32 %13 to i64
store i64 %14, i64* %9
%15 = load i32*, i32** %5
%16 = getelementptr inbounds i32, i32* %15, i64 0
%17 = call i32 @memcpy(i32* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%18 = load i32*, i32** %5
%19 = getelementptr inbounds i32, i32* %18, i64 4
%20 = load i64, i64* %9
%21 = add i64 %20, 44
%22 = sub i64 %21, 8
%23 = trunc i64 %22 to i32
%24 = call i32 @put_32bitLE(i32* %19, i32 %23)
%25 = load i32*, i32** %5
%26 = getelementptr inbounds i32, i32* %25, i64 8
%27 = call i32 @memcpy(i32* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%28 = load i32*, i32** %5
%29 = getelementptr inbounds i32, i32* %28, i64 12
%30 = call i32 @memcpy(i32* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%31 = load i32*, i32** %5
%32 = getelementptr inbounds i32, i32* %31, i64 16
%33 = call i32 @put_32bitLE(i32* %32, i32 16)
%34 = load i32*, i32** %5
%35 = getelementptr inbounds i32, i32* %34, i64 20
%36 = call i32 @put_16bitLE(i32* %35, i32 1)
%37 = load i32*, i32** %5
%38 = getelementptr inbounds i32, i32* %37, i64 22
%39 = load i32, i32* %8
%40 = call i32 @put_16bitLE(i32* %38, i32 %39)
%41 = load i32*, i32** %5
%42 = getelementptr inbounds i32, i32* %41, i64 24
%43 = load i32, i32* %7
%44 = call i32 @put_32bitLE(i32* %42, i32 %43)
%45 = load i32*, i32** %5
%46 = getelementptr inbounds i32, i32* %45, i64 28
%47 = load i32, i32* %7
%48 = load i32, i32* %8
%49 = mul nsw i32 %47, %48
%50 = mul nsw i32 %49, 2
%51 = call i32 @put_32bitLE(i32* %46, i32 %50)
%52 = load i32*, i32** %5
%53 = getelementptr inbounds i32, i32* %52, i64 32
%54 = load i32, i32* %8
%55 = mul nsw i32 %54, 2
%56 = call i32 @put_16bitLE(i32* %53, i32 %55)
%57 = load i32*, i32** %5
%58 = getelementptr inbounds i32, i32* %57, i64 34
%59 = call i32 @put_16bitLE(i32* %58, i32 16)
%60 = load i32*, i32** %5
%61 = getelementptr inbounds i32, i32* %60, i64 36
%62 = call i32 @memcpy(i32* %61, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%63 = load i32*, i32** %5
%64 = getelementptr inbounds i32, i32* %63, i64 40
%65 = load i64, i64* %9
%66 = trunc i64 %65 to i32
%67 = call i32 @put_32bitLE(i32* %64, i32 %66)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"RIFF\00"
@.str.1 = [5 x i8] c"WAVE\00"
@.str.2 = [5 x i8] c"fmt \00"
@.str.3 = [5 x i8] c"data\00"
define void @make_wav_header(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = shl i32 %1, 1
%6 = mul i32 %5, %3
%7 = tail call i32 @memcpy(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%8 = getelementptr inbounds i32, i32* %0, i64 4
%9 = add i32 %6, 36
%10 = tail call i32 @put_32bitLE(i32* %8, i32 %9)
%11 = getelementptr inbounds i32, i32* %0, i64 8
%12 = tail call i32 @memcpy(i32* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%13 = getelementptr inbounds i32, i32* %0, i64 12
%14 = tail call i32 @memcpy(i32* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%15 = getelementptr inbounds i32, i32* %0, i64 16
%16 = tail call i32 @put_32bitLE(i32* %15, i32 16)
%17 = getelementptr inbounds i32, i32* %0, i64 20
%18 = tail call i32 @put_16bitLE(i32* %17, i32 1)
%19 = getelementptr inbounds i32, i32* %0, i64 22
%20 = tail call i32 @put_16bitLE(i32* %19, i32 %3)
%21 = getelementptr inbounds i32, i32* %0, i64 24
%22 = tail call i32 @put_32bitLE(i32* %21, i32 %2)
%23 = getelementptr inbounds i32, i32* %0, i64 28
%24 = shl i32 %2, 1
%25 = mul i32 %24, %3
%26 = tail call i32 @put_32bitLE(i32* %23, i32 %25)
%27 = getelementptr inbounds i32, i32* %0, i64 32
%28 = shl nsw i32 %3, 1
%29 = tail call i32 @put_16bitLE(i32* %27, i32 %28)
%30 = getelementptr inbounds i32, i32* %0, i64 34
%31 = tail call i32 @put_16bitLE(i32* %30, i32 16)
%32 = getelementptr inbounds i32, i32* %0, i64 36
%33 = tail call i32 @memcpy(i32* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%34 = getelementptr inbounds i32, i32* %0, i64 40
%35 = tail call i32 @put_32bitLE(i32* %34, i32 %6)
ret void
}