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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int lseek(int, int, int /*<<< orphan*/);
int read(int, char *, int);
scalar_t__ strcmp(char *, char *);
int IsWav(int hFilename) {
  int i;
  char cBuffer[5];
  lseek(hFilename, 0, SEEK_SET);
  i = read(hFilename, cBuffer, 4);
  if (i == 4) {
    cBuffer[4] = 0;
    if (strcmp("RIFF", cBuffer) != 0) {
      return 0;
    }
  } else {
    return 0;
  }
  if (lseek(hFilename, 8, SEEK_SET) != 8) {
    return 0;
  }
  i = read(hFilename, cBuffer, 4);
  if (i == 4) {
    cBuffer[4] = 0;
    if (strcmp("WAVE", cBuffer) != 0) {
      return 0;
    }
  } else {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<IsWav>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    -0x8(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jne    119b <IsWav+0x6b>
movb   $0x0,-0xd(%rbp)
lea    -0x11(%rbp),%rsi
lea    0xe85(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1196 <IsWav+0x66>
movl   $0x0,-0x4(%rbp)
jmp    1232 <IsWav+0x102>
jmp    11a7 <IsWav+0x77>
movl   $0x0,-0x4(%rbp)
jmp    1232 <IsWav+0x102>
mov    -0x8(%rbp),%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%esi
call   1030 <lseek@plt>
cmp    $0x8,%eax
je     11d2 <IsWav+0xa2>
movl   $0x0,-0x4(%rbp)
jmp    1232 <IsWav+0x102>
mov    -0x8(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jne    121f <IsWav+0xef>
movb   $0x0,-0xd(%rbp)
lea    -0x11(%rbp),%rsi
lea    0xe06(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     121a <IsWav+0xea>
movl   $0x0,-0x4(%rbp)
jmp    1232 <IsWav+0x102>
jmp    122b <IsWav+0xfb>
movl   $0x0,-0x4(%rbp)
jmp    1232 <IsWav+0x102>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IsWav>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
mov    0x2e9f(%rip),%r14
mov    (%r14),%edx
xor    %ebx,%ebx
xor    %esi,%esi
call   1030 <lseek@plt>
lea    0xb(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x4,%eax
jne    11c6 <IsWav+0x96>
movb   $0x0,0xf(%rsp)
lea    0xe91(%rip),%rdi
lea    0xb(%rsp),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11c6 <IsWav+0x96>
mov    (%r14),%edx
mov    %ebp,%edi
mov    $0x8,%esi
call   1030 <lseek@plt>
cmp    $0x8,%eax
jne    11c6 <IsWav+0x96>
lea    0xb(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x4,%eax
jne    11c6 <IsWav+0x96>
movb   $0x0,0xf(%rsp)
lea    0xe51(%rip),%rdi
lea    0xb(%rsp),%rsi
call   1050 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
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 @IsWav(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [5 x i8]
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = load i32, i32* @SEEK_SET
%8 = call i32 @lseek(i32 %6, i32 0, i32 %7)
%9 = load i32, i32* %3
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%11 = call i32 @read(i32 %9, i8* %10, i32 4)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 4
br i1 %13, label %14, label %21
14: ; preds = %1
%15 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 4
store i8 0, i8* %15
%16 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%17 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
store i32 0, i32* %2
br label %43
20: ; preds = %14
br label %22
21: ; preds = %1
store i32 0, i32* %2
br label %43
22: ; preds = %20
%23 = load i32, i32* %3
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @lseek(i32 %23, i32 8, i32 %24)
%26 = icmp ne i32 %25, 8
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 0, i32* %2
br label %43
28: ; preds = %22
%29 = load i32, i32* %3
%30 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%31 = call i32 @read(i32 %29, i8* %30, i32 4)
store i32 %31, i32* %4
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 4
br i1 %33, label %34, label %41
34: ; preds = %28
%35 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 4
store i8 0, i8* %35
%36 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%37 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %34
store i32 0, i32* %2
br label %43
40: ; preds = %34
br label %42
41: ; preds = %28
store i32 0, i32* %2
br label %43
42: ; preds = %40
store i32 1, i32* %2
br label %43
43: ; preds = %42, %41, %39, %27, %21, %19
%44 = load i32, i32* %2
ret i32 %44
}

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 @IsWav(i32 %0) {
%2 = alloca [5 x i8]
%3 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @SEEK_SET
%5 = tail call i32 @lseek(i32 %0, i32 0, i32 %4)
%6 = call i32 @read(i32 %0, i8* %3, i32 4)
%7 = icmp eq i32 %6, 4
br i1 %7, label %8, label %23
8: ; preds = %1
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 4
store i8 0, i8* %9
%10 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %8
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @lseek(i32 %0, i32 8, i32 %13)
%15 = icmp eq i32 %14, 8
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = call i32 @read(i32 %0, i8* %3, i32 4)
%18 = icmp eq i32 %17, 4
br i1 %18, label %19, label %23
19: ; preds = %16
store i8 0, i8* %9
%20 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%21 = icmp eq i64 %20, 0
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %16, %19, %12, %1, %8
%24 = phi i32 [ 0, %8 ], [ 0, %1 ], [ 0, %12 ], [ %22, %19 ], [ 0, %16 ]
ret i32 %24
}