#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*/ memcmp(unsigned char const *, char *, int);
int audio_wav_check(const void *data, size_t length) {
  const unsigned char *p = data;
  if (length < 12)
    return 0;
  if (!memcmp(p, "RIFF", 4) && !memcmp(p + 8, "WAVE", 4))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<audio_wav_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0xc,-0x18(%rbp)
jae    113f <audio_wav_check+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    1192 <audio_wav_check+0x82>
mov    -0x20(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
jne    118b <audio_wav_check+0x7b>
mov    -0x20(%rbp),%rdi
add    $0x8,%rdi
lea    0xe99(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
jne    118b <audio_wav_check+0x7b>
movl   $0x1,-0x4(%rbp)
jmp    1192 <audio_wav_check+0x82>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<audio_wav_check>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
cmp    $0xc,%rsi
jb     1154 <audio_wav_check+0x44>
mov    %rdi,%rbx
lea    0xedb(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
test   %eax,%eax
jne    1154 <audio_wav_check+0x44>
add    $0x8,%rbx
lea    0xec7(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <memcmp@plt>
test   %eax,%eax
jne    1154 <audio_wav_check+0x44>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"RIFF\00"
@.str.1 = [5 x i8] c"WAVE\00"
define i32 @audio_wav_check(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = load i8*, i8** %4
store i8* %7, i8** %6
%8 = load i64, i64* %5
%9 = icmp ult i64 %8, 12
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %3
br label %22
11: ; preds = %2
%12 = load i8*, i8** %6
%13 = call i32 @memcmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%14 = icmp ne i32 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %11
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i64 8
%18 = call i32 @memcmp(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %15
store i32 1, i32* %3
br label %22
21: ; preds = %15, %11
store i32 0, i32* %3
br label %22
22: ; preds = %21, %20, %10
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [5 x i8] c"RIFF\00"
@.str.1 = [5 x i8] c"WAVE\00"
define i32 @audio_wav_check(i8* %0, i64 %1) {
%3 = icmp ult i64 %1, 12
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = tail call i32 @memcmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %0, i64 8
%9 = tail call i32 @memcmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%10 = icmp eq i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %7, %4
br label %12
12: ; preds = %7, %2, %11
%13 = phi i32 [ 0, %11 ], [ 0, %2 ], [ 1, %7 ]
ret i32 %13
}