#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, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int strncmp(char *, char const *, int);
int header(FILE *fp) {
  int ret = 1;
  char c[4] = {0};
  const char riff[] = "RIFF";
  const char wave[] = "WAVE";
  const char chan = 1;
  const char bits = 8;
  fseek(fp, 0, SEEK_SET);
  fread(&c, 1, 4, fp);
  ret = strncmp(c, riff, 4);
  if (ret) {
    printf("\nThis is not a wave file.\n");
    return -1;
  }
  fseek(fp, 8, SEEK_SET);
  fread(&c, 1, 4, fp);
  ret = strncmp(c, wave, 4);
  if (ret) {
    printf("\nThis is not a wave file.\n");
    return -1;
  }
  fseek(fp, 22, SEEK_SET);
  fread(&c, 1, 1, fp);
  if (c[0] != chan) {
    printf("\nThis is not a mono wave.\n");
    return -1;
  }
  fseek(fp, 34, SEEK_SET);
  fread(&c, 1, 1, fp);
  if (c[0] != bits) {
    printf("\nThis is not an 8-bit wave.\n");
    return -1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    0xe87(%rip),%eax
mov    %eax,-0x1d(%rbp)
mov    0xe82(%rip),%al
mov    %al,-0x19(%rbp)
mov    0xe7a(%rip),%eax
mov    %eax,-0x22(%rbp)
mov    0xe75(%rip),%al
mov    %al,-0x1e(%rbp)
movb   $0x1,-0x23(%rbp)
movb   $0x8,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1040 <fread@plt>
lea    -0x18(%rbp),%rdi
lea    -0x1d(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1201 <header+0xb1>
lea    0xe1a(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130d <header+0x1bd>
mov    -0x10(%rbp),%rdi
mov    0x2dd4(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%esi
call   1070 <fseek@plt>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1040 <fread@plt>
lea    -0x18(%rbp),%rdi
lea    -0x22(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1266 <header+0x116>
lea    0xdb5(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130d <header+0x1bd>
mov    -0x10(%rbp),%rdi
mov    0x2d6f(%rip),%rax
mov    (%rax),%edx
mov    $0x16,%esi
call   1070 <fseek@plt>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
movsbl -0x18(%rbp),%eax
cmp    $0x1,%eax
je     12b6 <header+0x166>
lea    0xd80(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130d <header+0x1bd>
mov    -0x10(%rbp),%rdi
mov    0x2d1f(%rip),%rax
mov    (%rax),%edx
mov    $0x22,%esi
call   1070 <fseek@plt>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
movsbl -0x18(%rbp),%eax
cmp    $0x8,%eax
je     1306 <header+0x1b6>
lea    0xd4b(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130d <header+0x1bd>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<header>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movl   $0x0,0x4(%rsp)
movb   $0x0,0x14(%rsp)
movl   $0x46464952,0x10(%rsp)
46
movb   $0x0,0xc(%rsp)
movl   $0x45564157,0x8(%rsp)
45
mov    0x2e6a(%rip),%r15
mov    (%r15),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
lea    0x4(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
lea    0x10(%rsp),%rsi
mov    %rbp,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
lea    0xe8d(%rip),%r14
test   %eax,%eax
jne    126c <header+0x12c>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x8,%esi
call   1060 <fseek@plt>
lea    0x4(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    126c <header+0x12c>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x16,%esi
call   1060 <fseek@plt>
lea    0x4(%rsp),%rdi
mov    $0x1,%ebp
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmpb   $0x1,0x4(%rsp)
jne    1265 <header+0x125>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x22,%esi
call   1060 <fseek@plt>
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmpb   $0x8,0x4(%rsp)
je     1279 <header+0x139>
lea    0xda7(%rip),%r14
jmp    126c <header+0x12c>
lea    0xdba(%rip),%r14
mov    %r14,%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.header.riff = [5 x i8] c"RIFF\00"
@__const.header.wave = [5 x i8] c"WAVE\00"
@SEEK_SET = global i32 0
@.str = [27 x i8] c"\0AThis is not a wave file.\0A\00"
@.str.1 = [27 x i8] c"\0AThis is not a mono wave.\0A\00"
@.str.2 = [29 x i8] c"\0AThis is not an 8-bit wave.\0A\00"
define i32 @header(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [4 x i8]
%6 = alloca [5 x i8]
%7 = alloca [5 x i8]
%8 = alloca i8
%9 = alloca i8
store i32* %0, i32** %3
store i32 1, i32* %4
%10 = bitcast [4 x i8]* %5 to i8*
%11 = bitcast [5 x i8]* %6 to i8*
%12 = bitcast [5 x i8]* %7 to i8*
store i8 1, i8* %8
store i8 8, i8* %9
%13 = load i32*, i32** %3
%14 = load i32, i32* @SEEK_SET
%15 = call i32 @fseek(i32* %13, i32 0, i32 %14)
%16 = bitcast [4 x i8]* %5 to i8**
%17 = load i32*, i32** %3
%18 = call i32 @fread(i8** %16, i32 1, i32 4, i32* %17)
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%20 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%21 = call i32 @strncmp(i8* %19, i8* %20, i32 4)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %1
%25 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %67
26: ; preds = %1
%27 = load i32*, i32** %3
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @fseek(i32* %27, i32 8, i32 %28)
%30 = bitcast [4 x i8]* %5 to i8**
%31 = load i32*, i32** %3
%32 = call i32 @fread(i8** %30, i32 1, i32 4, i32* %31)
%33 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%34 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%35 = call i32 @strncmp(i8* %33, i8* %34, i32 4)
store i32 %35, i32* %4
%36 = load i32, i32* %4
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %26
%39 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %67
40: ; preds = %26
%41 = load i32*, i32** %3
%42 = load i32, i32* @SEEK_SET
%43 = call i32 @fseek(i32* %41, i32 22, i32 %42)
%44 = bitcast [4 x i8]* %5 to i8**
%45 = load i32*, i32** %3
%46 = call i32 @fread(i8** %44, i32 1, i32 1, i32* %45)
%47 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 1
br i1 %50, label %51, label %53
51: ; preds = %40
%52 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %67
53: ; preds = %40
%54 = load i32*, i32** %3
%55 = load i32, i32* @SEEK_SET
%56 = call i32 @fseek(i32* %54, i32 34, i32 %55)
%57 = bitcast [4 x i8]* %5 to i8**
%58 = load i32*, i32** %3
%59 = call i32 @fread(i8** %57, i32 1, i32 1, i32* %58)
%60 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 8
br i1 %63, label %64, label %66
64: ; preds = %53
%65 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %67
66: ; preds = %53
store i32 1, i32* %2
br label %67
67: ; preds = %66, %64, %51, %38, %24
%68 = load i32, i32* %2
ret i32 %68
}

LLVM IR (-O2):
@__const.header.riff = [5 x i8] c"RIFF\00"
@__const.header.wave = [5 x i8] c"WAVE\00"
@SEEK_SET = global i32 0
@str = [28 x i8] c"\0AThis is not an 8-bit wave.\00"
@str.3 = [26 x i8] c"\0AThis is not a mono wave.\00"
@str.5 = [26 x i8] c"\0AThis is not a wave file.\00"
define i32 @header(i32* nocapture %0) {
%2 = alloca i32
%3 = alloca [5 x i8]
%4 = alloca [5 x i8]
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @fseek(i32* %0, i32 0, i32 %8)
%10 = bitcast i32* %2 to i8**
%11 = call i32 @fread(i8** %10, i32 1, i32 4, i32* %0)
%12 = call i32 @strncmp(i8* %5, i8* %6, i32 4)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %32
14: ; preds = %1
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @fseek(i32* %0, i32 8, i32 %15)
%17 = call i32 @fread(i8** %10, i32 1, i32 4, i32* %0)
%18 = call i32 @strncmp(i8* %5, i8* %7, i32 4)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %14
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @fseek(i32* %0, i32 22, i32 %21)
%23 = call i32 @fread(i8** %10, i32 1, i32 1, i32* %0)
%24 = load i8, i8* %5
%25 = icmp eq i8 %24, 1
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = load i32, i32* @SEEK_SET
%28 = call i32 @fseek(i32* %0, i32 34, i32 %27)
%29 = call i32 @fread(i8** %10, i32 1, i32 1, i32* %0)
%30 = load i8, i8* %5
%31 = icmp eq i8 %30, 8
br i1 %31, label %35, label %32
32: ; preds = %26, %20, %14, %1
%33 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @str.5, i64 0, i64 0), %1 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @str.5, i64 0, i64 0), %14 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @str.3, i64 0, i64 0), %20 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0), %26 ]
%34 = call i32 @puts(i8* dereferenceable(1) %33)
br label %35
35: ; preds = %32, %26
%36 = phi i32 [ 1, %26 ], [ -1, %32 ]
ret i32 %36
}