#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fread(char *, int, int, int /*<<< orphan*/ *);
bool cdrdao_check_file(FILE *f) {
  char buf[3];
  if (fread(buf, 1, sizeof(buf), f) != sizeof(buf))
    return false;
  return (buf[0] == 'C' && buf[1] == 'D' && buf[2] == '_') ||
         (buf[0] == 'C' && buf[1] == 'A' && buf[3] == 'T');
}


x86 assembly (clang, -O0):
<cdrdao_check_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x13(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3,%edx
call   1030 <fread@plt>
cltq
cmp    $0x3,%rax
je     114b <cdrdao_check_file+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    11b9 <cdrdao_check_file+0xa9>
movsbl -0x13(%rbp),%eax
cmp    $0x43,%eax
jne    1177 <cdrdao_check_file+0x67>
movsbl -0x12(%rbp),%eax
cmp    $0x44,%eax
jne    1177 <cdrdao_check_file+0x67>
movsbl -0x11(%rbp),%ecx
mov    $0x1,%al
cmp    $0x5f,%ecx
mov    %al,-0x14(%rbp)
je     11ae <cdrdao_check_file+0x9e>
movsbl -0x13(%rbp),%ecx
xor    %eax,%eax
cmp    $0x43,%ecx
mov    %al,-0x15(%rbp)
jne    11a8 <cdrdao_check_file+0x98>
movsbl -0x12(%rbp),%ecx
xor    %eax,%eax
cmp    $0x41,%ecx
mov    %al,-0x15(%rbp)
jne    11a8 <cdrdao_check_file+0x98>
movsbl -0x10(%rbp),%eax
cmp    $0x54,%eax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
mov    %al,-0x14(%rbp)
mov    -0x14(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cdrdao_check_file>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rcx
lea    0xd(%rsp),%rdi
mov    $0x1,%ebx
mov    $0x1,%esi
mov    $0x3,%edx
call   1030 <fread@plt>
cmp    $0x3,%eax
jne    1168 <cdrdao_check_file+0x58>
mov    0xd(%rsp),%cl
mov    0xe(%rsp),%al
cmp    $0x43,%cl
jne    114e <cdrdao_check_file+0x3e>
cmp    $0x44,%al
jne    114e <cdrdao_check_file+0x3e>
cmpb   $0x5f,0xf(%rsp)
je     116a <cdrdao_check_file+0x5a>
cmp    $0x43,%cl
jne    1168 <cdrdao_check_file+0x58>
mov    $0x0,%ebx
cmp    $0x41,%al
jne    116a <cdrdao_check_file+0x5a>
xor    %ebx,%ebx
cmpb   $0x54,0x10(%rsp)
sete   %bl
jmp    116a <cdrdao_check_file+0x5a>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @cdrdao_check_file(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [3 x i8]
store i32* %0, i32** %3
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%6 = load i32*, i32** %3
%7 = call i32 @fread(i8* %5, i32 1, i32 3, i32* %6)
%8 = sext i32 %7 to i64
%9 = icmp ne i64 %8, 3
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %46
11: ; preds = %1
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 67
br i1 %15, label %16, label %26
16: ; preds = %11
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 68
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 95
br i1 %25, label %43, label %26
26: ; preds = %21, %16, %11
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 67
br i1 %30, label %31, label %41
31: ; preds = %26
%32 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 65
br i1 %35, label %36, label %41
36: ; preds = %31
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 3
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 84
br label %41
41: ; preds = %36, %31, %26
%42 = phi i1 [ false, %31 ], [ false, %26 ], [ %40, %36 ]
br label %43
43: ; preds = %41, %21
%44 = phi i1 [ true, %21 ], [ %42, %41 ]
%45 = zext i1 %44 to i32
store i32 %45, i32* %2
br label %46
46: ; preds = %43, %10
%47 = load i32, i32* %2
ret i32 %47
}

LLVM IR (-O2):
define i32 @cdrdao_check_file(i32* nocapture %0) {
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%4 = call i32 @fread(i8* %3, i32 1, i32 3, i32* %0)
%5 = icmp eq i32 %4, 3
br i1 %5, label %6, label %25
6: ; preds = %1
%7 = load i8, i8* %3
%8 = icmp eq i8 %7, 67
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 68
%12 = select i1 %8, i1 %11, i1 false
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 2
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 95
%16 = select i1 %12, i1 %15, i1 false
br i1 %16, label %25, label %17
17: ; preds = %6
%18 = icmp eq i8 %10, 65
%19 = select i1 %8, i1 %18, i1 false
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 3
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 84
%24 = zext i1 %23 to i32
br label %25
25: ; preds = %6, %20, %17, %1
%26 = phi i32 [ 0, %1 ], [ 1, %6 ], [ 0, %17 ], [ %24, %20 ]
ret i32 %26
}