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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
scalar_t__ lseek(int, int, int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ strncmp(char *, char *, int);
int fileIsIso(const char *file) {
  int blkNum;
  char magic[5];
  int fd;
  fd = open(file, O_RDONLY);
  if (fd < 0)
    return 0;
  for (blkNum = 16; blkNum < 100; blkNum++) {
    if (lseek(fd, blkNum * 2048 + 1, SEEK_SET) < 0) {
      close(fd);
      return 0;
    }
    if (read(fd, magic, sizeof(magic)) != sizeof(magic)) {
      close(fd);
      return 0;
    }
    if (!strncmp(magic, "CD001", 5)) {
      close(fd);
      return 1;
    }
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<fileIsIso>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1187 <fileIsIso+0x37>
movl   $0x0,-0x4(%rbp)
jmp    1255 <fileIsIso+0x105>
movl   $0x10,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    1246 <fileIsIso+0xf6>
mov    -0x20(%rbp),%edi
mov    -0x14(%rbp),%esi
shl    $0xb,%esi
add    $0x1,%esi
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
cmp    $0x0,%rax
jge    11d0 <fileIsIso+0x80>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1255 <fileIsIso+0x105>
mov    -0x20(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x5,%edx
call   1060 <read@plt>
cltq
cmp    $0x5,%rax
je     1201 <fileIsIso+0xb1>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1255 <fileIsIso+0x105>
lea    -0x19(%rbp),%rdi
lea    0xdf4(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1233 <fileIsIso+0xe3>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1255 <fileIsIso+0x105>
jmp    1238 <fileIsIso+0xe8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118e <fileIsIso+0x3e>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileIsIso>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     11dc <fileIsIso+0x8c>
mov    %eax,%r14d
mov    $0x8001,%ebx
mov    0x2e5c(%rip),%r13
lea    0x3(%rsp),%r15
lea    0xe78(%rip),%r12
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%edx
mov    %r14d,%edi
mov    %ebx,%esi
call   1040 <lseek@plt>
test   %rax,%rax
js     11e5 <fileIsIso+0x95>
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x5,%edx
call   1060 <read@plt>
cmp    $0x5,%eax
jne    11e5 <fileIsIso+0x95>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11e0 <fileIsIso+0x90>
add    $0x800,%ebx
cmp    $0x32001,%ebx
jne    1190 <fileIsIso+0x40>
jmp    11e5 <fileIsIso+0x95>
xor    %ebp,%ebp
jmp    11ed <fileIsIso+0x9d>
mov    $0x1,%ebp
mov    %r14d,%edi
call   1050 <close@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
@.str = [6 x i8] c"CD001\00"
define i32 @fileIsIso(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [5 x i8]
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 0, i32* %2
br label %51
13: ; preds = %1
store i32 16, i32* %4
br label %14
14: ; preds = %45, %13
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 100
br i1 %16, label %17, label %48
17: ; preds = %14
%18 = load i32, i32* %6
%19 = load i32, i32* %4
%20 = mul nsw i32 %19, 2048
%21 = add nsw i32 %20, 1
%22 = load i32, i32* @SEEK_SET
%23 = call i64 @lseek(i32 %18, i32 %21, i32 %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load i32, i32* %6
%27 = call i32 @close(i32 %26)
store i32 0, i32* %2
br label %51
28: ; preds = %17
%29 = load i32, i32* %6
%30 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%31 = call i32 @read(i32 %29, i8* %30, i32 5)
%32 = sext i32 %31 to i64
%33 = icmp ne i64 %32, 5
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = load i32, i32* %6
%36 = call i32 @close(i32 %35)
store i32 0, i32* %2
br label %51
37: ; preds = %28
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%39 = call i32 @strncmp(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%40 = icmp ne i32 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %37
%42 = load i32, i32* %6
%43 = call i32 @close(i32 %42)
store i32 1, i32* %2
br label %51
44: ; preds = %37
br label %45
45: ; preds = %44
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %14
48: ; preds = %14
%49 = load i32, i32* %6
%50 = call i32 @close(i32 %49)
store i32 0, i32* %2
br label %51
51: ; preds = %48, %41, %34, %25, %12
%52 = load i32, i32* %2
ret i32 %52
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
@.str = [6 x i8] c"CD001\00"
define i32 @fileIsIso(i8* nocapture %0) {
%2 = alloca [5 x i8]
%3 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %26, label %10
7: ; preds = %20
%8 = add nuw nsw i32 %11, 1
%9 = icmp eq i32 %8, 100
br i1 %9, label %23, label %10
10: ; preds = %1, %7
%11 = phi i32 [ %8, %7 ], [ 16, %1 ]
%12 = shl nuw nsw i32 %11, 11
%13 = or i32 %12, 1
%14 = load i32, i32* @SEEK_SET
%15 = call i64 @lseek(i32 %5, i32 %13, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %10
%18 = call i32 @read(i32 %5, i8* %3, i32 5)
%19 = icmp eq i32 %18, 5
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i32 @strncmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %7
23: ; preds = %7, %20, %17, %10
%24 = phi i32 [ 0, %10 ], [ 0, %17 ], [ 1, %20 ], [ 0, %7 ]
%25 = call i32 @close(i32 %5)
br label %26
26: ; preds = %23, %1
%27 = phi i32 [ 0, %1 ], [ %24, %23 ]
ret i32 %27
}