#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(void *, long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
void *malloc(long);
int load_wav_file(const char *file, void **data, size_t *size, size_t *freq) {
  if (NULL == file || NULL == data || NULL == size || NULL == freq) {
    return -1;
  }
  FILE *fp = fopen(file, "rb");
  if (NULL == fp) {
    return -1;
  }
  fseek(fp, 0, SEEK_END);
  long fs = ftell(fp);
  *data = malloc(fs - 44);
  if (NULL == *data) {
    fclose(fp);
    return -1;
  }
  fseek(fp, 44, SEEK_SET);
  fread(*data, fs - 44, 1, fp);
  fclose(fp);
  *size = fs - 44;
  *freq = 11025;
  return 0;
}


x86 assembly (clang, -O0):
<load_wav_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     11a8 <load_wav_file+0x48>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     11a8 <load_wav_file+0x48>
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
je     11a8 <load_wav_file+0x48>
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    11b4 <load_wav_file+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    129a <load_wav_file+0x13a>
mov    -0x10(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    11e0 <load_wav_file+0x80>
movl   $0xffffffff,-0x4(%rbp)
jmp    129a <load_wav_file+0x13a>
mov    -0x30(%rbp),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x30(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
sub    $0x2c,%rdi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%rax
jne    123c <load_wav_file+0xdc>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129a <load_wav_file+0x13a>
mov    -0x30(%rbp),%rdi
mov    0x2d91(%rip),%rax
mov    (%rax),%edx
mov    $0x2c,%esi
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x38(%rbp),%rsi
sub    $0x2c,%rsi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rcx
sub    $0x2c,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movq   $0x2b11,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_wav_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%r12d
test   %rdi,%rdi
je     122c <load_wav_file+0xcc>
mov    %rsi,%rbx
test   %rsi,%rsi
je     122c <load_wav_file+0xcc>
mov    %rdx,%r15
test   %rdx,%rdx
je     122c <load_wav_file+0xcc>
mov    %rcx,%r14
test   %rcx,%rcx
je     122c <load_wav_file+0xcc>
lea    0xe5b(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     122c <load_wav_file+0xcc>
mov    %rax,%rbp
mov    0x2e2f(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %rbp,%rdi
call   1050 <ftell@plt>
mov    %rax,%r13
add    $0xffffffffffffffd4,%r13
mov    %r13,%rdi
call   1060 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     1224 <load_wav_file+0xc4>
mov    0x2ded(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    $0x2c,%esi
call   1070 <fseek@plt>
mov    (%rbx),%rdi
mov    %r13,%rsi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %r13,(%r15)
movq   $0x2b11,(%r14)
xor    %r12d,%r12d
jmp    122c <load_wav_file+0xcc>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @load_wav_file(i8* %0, i8** %1, i64* %2, i64* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i64*
%9 = alloca i64*
%10 = alloca i32*
%11 = alloca i64
store i8* %0, i8** %6
store i8** %1, i8*** %7
store i64* %2, i64** %8
store i64* %3, i64** %9
%12 = load i8*, i8** %6
%13 = icmp eq i8* null, %12
br i1 %13, label %23, label %14
14: ; preds = %4
%15 = load i8**, i8*** %7
%16 = icmp eq i8** null, %15
br i1 %16, label %23, label %17
17: ; preds = %14
%18 = load i64*, i64** %8
%19 = icmp eq i64* null, %18
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = load i64*, i64** %9
%22 = icmp eq i64* null, %21
br i1 %22, label %23, label %24
23: ; preds = %20, %17, %14, %4
store i32 -1, i32* %5
br label %62
24: ; preds = %20
%25 = load i8*, i8** %6
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %26, i32** %10
%27 = load i32*, i32** %10
%28 = icmp eq i32* null, %27
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 -1, i32* %5
br label %62
30: ; preds = %24
%31 = load i32*, i32** %10
%32 = load i32, i32* @SEEK_END
%33 = call i32 @fseek(i32* %31, i32 0, i32 %32)
%34 = load i32*, i32** %10
%35 = call i64 @ftell(i32* %34)
store i64 %35, i64* %11
%36 = load i64, i64* %11
%37 = sub nsw i64 %36, 44
%38 = call i8* @malloc(i64 %37)
%39 = load i8**, i8*** %7
store i8* %38, i8** %39
%40 = load i8**, i8*** %7
%41 = load i8*, i8** %40
%42 = icmp eq i8* null, %41
br i1 %42, label %43, label %46
43: ; preds = %30
%44 = load i32*, i32** %10
%45 = call i32 @fclose(i32* %44)
store i32 -1, i32* %5
br label %62
46: ; preds = %30
%47 = load i32*, i32** %10
%48 = load i32, i32* @SEEK_SET
%49 = call i32 @fseek(i32* %47, i32 44, i32 %48)
%50 = load i8**, i8*** %7
%51 = load i8*, i8** %50
%52 = load i64, i64* %11
%53 = sub nsw i64 %52, 44
%54 = load i32*, i32** %10
%55 = call i32 @fread(i8* %51, i64 %53, i32 1, i32* %54)
%56 = load i32*, i32** %10
%57 = call i32 @fclose(i32* %56)
%58 = load i64, i64* %11
%59 = sub nsw i64 %58, 44
%60 = load i64*, i64** %8
store i64 %59, i64* %60
%61 = load i64*, i64** %9
store i64 11025, i64* %61
store i32 0, i32* %5
br label %62
62: ; preds = %46, %43, %29, %23
%63 = load i32, i32* %5
ret i32 %63
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @load_wav_file(i8* %0, i8** %1, i64* writeonly %2, i64* writeonly %3) {
%5 = icmp eq i8* %0, null
%6 = icmp eq i8** %1, null
%7 = or i1 %5, %6
%8 = icmp eq i64* %2, null
%9 = or i1 %7, %8
%10 = icmp eq i64* %3, null
%11 = or i1 %9, %10
br i1 %11, label %30, label %12
12: ; preds = %4
%13 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %30, label %15
15: ; preds = %12
%16 = load i32, i32* @SEEK_END
%17 = tail call i32 @fseek(i32* %13, i32 0, i32 %16)
%18 = tail call i64 @ftell(i32* %13)
%19 = add nsw i64 %18, -44
%20 = tail call i8* @malloc(i64 %19)
store i8* %20, i8** %1
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = tail call i32 @fclose(i32* %13)
br label %30
24: ; preds = %15
%25 = load i32, i32* @SEEK_SET
%26 = tail call i32 @fseek(i32* %13, i32 44, i32 %25)
%27 = load i8*, i8** %1
%28 = tail call i32 @fread(i8* %27, i64 %19, i32 1, i32* %13)
%29 = tail call i32 @fclose(i32* %13)
store i64 %19, i64* %2
store i64 11025, i64* %3
br label %30
30: ; preds = %12, %24, %22, %4
%31 = phi i32 [ -1, %4 ], [ -1, %12 ], [ -1, %22 ], [ 0, %24 ]
ret i32 %31
}