#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_SET;
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
scalar_t__ strncmp(char *, char *, int);
int check_wav_file(FILE *fp, int *sample_rate, short *channels, short *bps) {
  fseek(fp, 0, SEEK_SET);
  char header[44];
  fread(header, sizeof(char), 44, fp);
  if (strncmp(header, "RIFF", 4) != 0)
    return -1;
  if (strncmp((header + 8), "WAVE", 4) != 0)
    return -2;
  *sample_rate = *((int *)(header + 24));
  *channels = *((short *)(header + 22));
  *bps = *((short *)(header + 34));
  if (*bps != 16)
    return -3;
  return 1;
}


x86 assembly (clang, -O0):
<check_wav_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e8d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2c,%edx
call   1040 <fread@plt>
lea    -0x60(%rbp),%rdi
lea    0xe82(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     119e <check_wav_file+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    120f <check_wav_file+0xdf>
lea    -0x60(%rbp),%rdi
add    $0x8,%rdi
lea    0xe58(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11cd <check_wav_file+0x9d>
movl   $0xfffffffe,-0x4(%rbp)
jmp    120f <check_wav_file+0xdf>
mov    -0x48(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4a(%rbp),%cx
mov    -0x20(%rbp),%rax
mov    %cx,(%rax)
mov    -0x3e(%rbp),%cx
mov    -0x28(%rbp),%rax
mov    %cx,(%rax)
mov    -0x28(%rbp),%rax
movswl (%rax),%eax
cmp    $0x10,%eax
je     1208 <check_wav_file+0xd8>
movl   $0xfffffffd,-0x4(%rbp)
jmp    120f <check_wav_file+0xdf>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_wav_file>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
mov    %rsp,%r13
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x2c,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
lea    0xe88(%rip),%rsi
mov    %r13,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    11df <check_wav_file+0xaf>
lea    0x8(%rsp),%rdi
lea    0xe67(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
mov    $0xfffffffe,%eax
test   %rcx,%rcx
jne    11df <check_wav_file+0xaf>
mov    0x18(%rsp),%eax
mov    %eax,(%r12)
movzwl 0x16(%rsp),%eax
mov    %ax,(%r15)
movzwl 0x22(%rsp),%eax
mov    %ax,(%r14)
xor    %ecx,%ecx
cmp    $0x10,%ax
sete   %cl
lea    -0x3(,%rcx,4),%eax
add    $0x30,%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, i16* %2, i16* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i16*
%9 = alloca i16*
%10 = alloca [44 x i8]
store i32* %0, i32** %6
store i32* %1, i32** %7
store i16* %2, i16** %8
store i16* %3, i16** %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 i8], [44 x i8]* %10, i64 0, i64 0
%15 = load i32*, i32** %6
%16 = call i32 @fread(i8* %14, i32 1, i32 44, i32* %15)
%17 = getelementptr inbounds [44 x i8], [44 x i8]* %10, i64 0, i64 0
%18 = call i64 @strncmp(i8* %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 %49
21: ; preds = %4
%22 = getelementptr inbounds [44 x i8], [44 x i8]* %10, i64 0, i64 0
%23 = getelementptr inbounds i8, i8* %22, i64 8
%24 = call i64 @strncmp(i8* %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 %49
27: ; preds = %21
%28 = getelementptr inbounds [44 x i8], [44 x i8]* %10, i64 0, i64 0
%29 = getelementptr inbounds i8, i8* %28, i64 24
%30 = bitcast i8* %29 to i32*
%31 = load i32, i32* %30
%32 = load i32*, i32** %7
store i32 %31, i32* %32
%33 = getelementptr inbounds [44 x i8], [44 x i8]* %10, i64 0, i64 0
%34 = getelementptr inbounds i8, i8* %33, i64 22
%35 = bitcast i8* %34 to i16*
%36 = load i16, i16* %35
%37 = load i16*, i16** %8
store i16 %36, i16* %37
%38 = getelementptr inbounds [44 x i8], [44 x i8]* %10, i64 0, i64 0
%39 = getelementptr inbounds i8, i8* %38, i64 34
%40 = bitcast i8* %39 to i16*
%41 = load i16, i16* %40
%42 = load i16*, i16** %9
store i16 %41, i16* %42
%43 = load i16*, i16** %9
%44 = load i16, i16* %43
%45 = sext i16 %44 to i32
%46 = icmp ne i32 %45, 16
br i1 %46, label %47, label %48
47: ; preds = %27
store i32 -3, i32* %5
br label %49
48: ; preds = %27
store i32 1, i32* %5
br label %49
49: ; preds = %48, %47, %26, %20
%50 = load i32, i32* %5
ret i32 %50
}

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, i16* nocapture writeonly %2, i16* nocapture writeonly %3) {
%5 = alloca [44 x i8]
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @fseek(i32* %0, i32 0, i32 %6)
%8 = getelementptr inbounds [44 x i8], [44 x i8]* %5, i64 0, i64 0
%9 = call i32 @fread(i8* %8, i32 1, i32 44, i32* %0)
%10 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %4
%13 = getelementptr inbounds [44 x i8], [44 x i8]* %5, i64 0, i64 8
%14 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %12
%17 = getelementptr inbounds [44 x i8], [44 x i8]* %5, i64 0, i64 24
%18 = bitcast i8* %17 to i32*
%19 = load i32, i32* %18
store i32 %19, i32* %1
%20 = getelementptr inbounds [44 x i8], [44 x i8]* %5, i64 0, i64 22
%21 = bitcast i8* %20 to i16*
%22 = load i16, i16* %21
store i16 %22, i16* %2
%23 = getelementptr inbounds [44 x i8], [44 x i8]* %5, i64 0, i64 34
%24 = bitcast i8* %23 to i16*
%25 = load i16, i16* %24
store i16 %25, i16* %3
%26 = icmp eq i16 %25, 16
%27 = select i1 %26, i32 1, i32 -3
br label %28
28: ; preds = %16, %12, %4
%29 = phi i32 [ -1, %4 ], [ -2, %12 ], [ %27, %16 ]
ret i32 %29
}