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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
scalar_t__ strncmp(int /*<<< orphan*/ *, char *, int);
int32_t check_wav_file(FILE *fp, int32_t *sample_rate, int16_t *channels,
                       int16_t *bps) {
  fseek(fp, 0, SEEK_SET);
  int8_t header[44];
  fread(header, sizeof(int8_t), 44, fp);
  if (strncmp(header, "RIFF", 4) != 0)
    return -1;
  if (strncmp((header + 8), "WAVE", 4) != 0)
    return -2;
  *sample_rate = *((int32_t *)(header + 24));
  *channels = *((int16_t *)(header + 22));
  *bps = *((int16_t *)(header + 34));
  if (*bps != 16)
    return -3;
  return 1;
}


x86 assembly (clang, -O0):
<check_wav_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e8a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
lea    -0xe0(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x2c,%edx
call   1040 <fread@plt>
lea    -0xe0(%rbp),%rdi
lea    0xe79(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11a7 <check_wav_file+0x77>
movl   $0xffffffff,-0x4(%rbp)
jmp    1217 <check_wav_file+0xe7>
lea    -0xe0(%rbp),%rdi
add    $0x20,%rdi
lea    0xe4c(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11d9 <check_wav_file+0xa9>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1217 <check_wav_file+0xe7>
mov    -0x80(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x88(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x58(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
cmpl   $0x10,(%rax)
je     1210 <check_wav_file+0xe0>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1217 <check_wav_file+0xe7>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_wav_file>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb0,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    0x2e8d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
mov    %rsp,%r13
mov    %r13,%rdi
mov    $0x4,%esi
mov    $0x2c,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
lea    0xe85(%rip),%rsi
mov    %r13,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    11e0 <check_wav_file+0xb0>
lea    0x20(%rsp),%rdi
lea    0xe64(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
mov    $0xfffffffe,%eax
test   %rcx,%rcx
jne    11e0 <check_wav_file+0xb0>
mov    0x60(%rsp),%eax
mov    %eax,(%r12)
mov    0x58(%rsp),%eax
mov    %eax,(%r15)
mov    0x88(%rsp),%eax
mov    %eax,(%r14)
xor    %ecx,%ecx
cmp    $0x10,%eax
sete   %cl
lea    -0x3(,%rcx,4),%eax
add    $0xb0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [5 x i8] c"RIFF\00"
@.str.1 = [5 x i8] c"WAVE\00"
define i32 @check_wav_file(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca [44 x i32]
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%11 = load i32*, i32** %6
%12 = load i32, i32* @SEEK_SET
%13 = call i32 @fseek(i32* %11, i32 0, i32 %12)
%14 = getelementptr inbounds [44 x i32], [44 x i32]* %10, i64 0, i64 0
%15 = load i32*, i32** %6
%16 = call i32 @fread(i32* %14, i32 4, i32 44, i32* %15)
%17 = getelementptr inbounds [44 x i32], [44 x i32]* %10, i64 0, i64 0
%18 = call i64 @strncmp(i32* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %4
store i32 -1, i32* %5
br label %45
21: ; preds = %4
%22 = getelementptr inbounds [44 x i32], [44 x i32]* %10, i64 0, i64 0
%23 = getelementptr inbounds i32, i32* %22, i64 8
%24 = call i64 @strncmp(i32* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 -2, i32* %5
br label %45
27: ; preds = %21
%28 = getelementptr inbounds [44 x i32], [44 x i32]* %10, i64 0, i64 0
%29 = getelementptr inbounds i32, i32* %28, i64 24
%30 = load i32, i32* %29
%31 = load i32*, i32** %7
store i32 %30, i32* %31
%32 = getelementptr inbounds [44 x i32], [44 x i32]* %10, i64 0, i64 0
%33 = getelementptr inbounds i32, i32* %32, i64 22
%34 = load i32, i32* %33
%35 = load i32*, i32** %8
store i32 %34, i32* %35
%36 = getelementptr inbounds [44 x i32], [44 x i32]* %10, i64 0, i64 0
%37 = getelementptr inbounds i32, i32* %36, i64 34
%38 = load i32, i32* %37
%39 = load i32*, i32** %9
store i32 %38, i32* %39
%40 = load i32*, i32** %9
%41 = load i32, i32* %40
%42 = icmp ne i32 %41, 16
br i1 %42, label %43, label %44
43: ; preds = %27
store i32 -3, i32* %5
br label %45
44: ; preds = %27
store i32 1, i32* %5
br label %45
45: ; preds = %44, %43, %26, %20
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [5 x i8] c"RIFF\00"
@.str.1 = [5 x i8] c"WAVE\00"
define i32 @check_wav_file(i32* nocapture %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca [44 x i32]
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @fseek(i32* %0, i32 0, i32 %6)
%8 = bitcast [44 x i32]* %5 to i8*
%9 = getelementptr inbounds [44 x i32], [44 x i32]* %5, i64 0, i64 0
%10 = call i32 @fread(i32* %9, i32 4, i32 44, i32* %0)
%11 = call i64 @strncmp(i32* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %4
%14 = getelementptr inbounds [44 x i32], [44 x i32]* %5, i64 0, i64 8
%15 = call i64 @strncmp(i32* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = getelementptr inbounds [44 x i32], [44 x i32]* %5, i64 0, i64 24
%19 = load i32, i32* %18
store i32 %19, i32* %1
%20 = getelementptr inbounds [44 x i32], [44 x i32]* %5, i64 0, i64 22
%21 = load i32, i32* %20
store i32 %21, i32* %2
%22 = getelementptr inbounds [44 x i32], [44 x i32]* %5, i64 0, i64 34
%23 = load i32, i32* %22
store i32 %23, i32* %3
%24 = icmp eq i32 %23, 16
%25 = select i1 %24, i32 1, i32 -3
br label %26
26: ; preds = %17, %13, %4
%27 = phi i32 [ -1, %4 ], [ -2, %13 ], [ %25, %17 ]
ret i32 %27
}