#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 int32_t;
typedef int int16_t;
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, int32_t *sample_rate, int16_t *channels,
                   int16_t *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    120a <check_wav_file+0xda>
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    120a <check_wav_file+0xda>
mov    -0x48(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movswl -0x4a(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movswl -0x3e(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
cmpl   $0x10,(%rax)
je     1203 <check_wav_file+0xd3>
movl   $0xfffffffd,-0x4(%rbp)
jmp    120a <check_wav_file+0xda>
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    11dc <check_wav_file+0xac>
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    11dc <check_wav_file+0xac>
mov    0x18(%rsp),%eax
mov    %eax,(%r12)
movswl 0x16(%rsp),%eax
mov    %eax,(%r15)
movswl 0x22(%rsp),%eax
xor    %ecx,%ecx
cmp    $0x10,%eax
sete   %cl
mov    %eax,(%r14)
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, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca [44 x i8]
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 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 %50
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 %50
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 = sext i16 %36 to i32
%38 = load i32*, i32** %8
store i32 %37, i32* %38
%39 = getelementptr inbounds [44 x i8], [44 x i8]* %10, i64 0, i64 0
%40 = getelementptr inbounds i8, i8* %39, i64 34
%41 = bitcast i8* %40 to i16*
%42 = load i16, i16* %41
%43 = sext i16 %42 to i32
%44 = load i32*, i32** %9
store i32 %43, i32* %44
%45 = load i32*, i32** %9
%46 = load i32, i32* %45
%47 = icmp ne i32 %46, 16
br i1 %47, label %48, label %49
48: ; preds = %27
store i32 -3, i32* %5
br label %50
49: ; preds = %27
store i32 1, i32* %5
br label %50
50: ; preds = %49, %48, %26, %20
%51 = load i32, i32* %5
ret i32 %51
}

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 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 %30
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 %30
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
%23 = sext i16 %22 to i32
store i32 %23, i32* %2
%24 = getelementptr inbounds [44 x i8], [44 x i8]* %5, i64 0, i64 34
%25 = bitcast i8* %24 to i16*
%26 = load i16, i16* %25
%27 = sext i16 %26 to i32
store i32 %27, i32* %3
%28 = icmp eq i16 %26, 16
%29 = select i1 %28, i32 1, i32 -3
br label %30
30: ; preds = %16, %12, %4
%31 = phi i32 [ -1, %4 ], [ -2, %12 ], [ %29, %16 ]
ret i32 %31
}