#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*/ loadFileSectors(char *, char *);
int matchNames(char *, char *, int);
int /*<<< orphan*/ readSector(char *, int);
int readFile(char *name, char *buffer) {
  char directory[512];
  int entry, matched;
  readSector(directory, 2);
  for (entry = 0; entry < 16; entry++) {
    matched = matchNames(name, directory + entry * 32, 6);
    if (matched == 1) {
      break;
    }
  }
  buffer[0] = '\0';
  if (matched == 0) {
    return 0;
  }
  loadFileSectors(buffer, directory + entry * 32);
  return 1;
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
mov    $0x2,%esi
call   1030 <readSector@plt>
movl   $0x0,-0x224(%rbp)
cmpl   $0x10,-0x224(%rbp)
jge    11bf <readFile+0x8f>
mov    -0x10(%rbp),%rdi
lea    -0x220(%rbp),%rsi
mov    -0x224(%rbp),%eax
shl    $0x5,%eax
cltq
add    %rax,%rsi
mov    $0x6,%edx
call   1050 <matchNames@plt>
mov    %eax,-0x228(%rbp)
cmpl   $0x1,-0x228(%rbp)
jne    11a6 <readFile+0x76>
jmp    11bf <readFile+0x8f>
jmp    11ab <readFile+0x7b>
mov    -0x224(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x224(%rbp)
jmp    115e <readFile+0x2e>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x228(%rbp)
jne    11df <readFile+0xaf>
movl   $0x0,-0x4(%rbp)
jmp    1204 <readFile+0xd4>
mov    -0x18(%rbp),%rdi
lea    -0x220(%rbp),%rsi
mov    -0x224(%rbp),%eax
shl    $0x5,%eax
cltq
add    %rax,%rsi
call   1040 <loadFileSectors@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <readSector@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1050 <matchNames@plt>
cmp    $0x1,%eax
jne    116e <readFile+0x3e>
xor    %ecx,%ecx
jmp    135e <readFile+0x22e>
lea    0x20(%rsp),%rsi
mov    %r15,%rdi
mov    $0x6,%edx
call   1050 <matchNames@plt>
mov    $0x20,%ecx
cmp    $0x1,%eax
je     135e <readFile+0x22e>
lea    0x40(%rsp),%rsi
mov    %r15,%rdi
mov    $0x6,%edx
call   1050 <matchNames@plt>
mov    $0x40,%ecx
cmp    $0x1,%eax
je     135e <readFile+0x22e>
lea    0x60(%rsp),%rsi
mov    %r15,%rdi
mov    $0x6,%edx
call   1050 <matchNames@plt>
mov    $0x60,%ecx
cmp    $0x1,%eax
je     135e <readFile+0x22e>
lea    0x80(%rsp),%rsi
mov    %r15,%rdi
mov    $0x6,%edx
call   1050 <matchNames@plt>
mov    $0x80,%ecx
cmp    $0x1,%eax
je     135e <readFile+0x22e>
lea    0xa0(%rsp),%rsi
mov    %r15,%rdi
mov    $0x6,%edx
call   1050 <matchNames@plt>
mov    $0xa0,%ecx
cmp    $0x1,%eax
je     135e <readFile+0x22e>
lea    0xc0(%rsp),%rsi
mov    %r15,%rdi
mov    $0x6,%edx
call   1050 <matchNames@plt>
mov    $0xc0,%ecx
cmp    $0x1,%eax
je     135e <readFile+0x22e>
lea    0xe0(%rsp),%rsi
mov    %r15,%rdi
mov    $0x6,%edx
call   1050 <matchNames@plt>
mov    $0xe0,%ecx
cmp    $0x1,%eax
je     135e <readFile+0x22e>
lea    0x100(%rsp),%rsi
mov    %r15,%rdi
mov    $0x6,%edx
call   1050 <matchNames@plt>
mov    $0x100,%ecx
cmp    $0x1,%eax
je     135e <readFile+0x22e>
lea    0x120(%rsp),%rsi
mov    %r15,%rdi
mov    $0x6,%edx
call   1050 <matchNames@plt>
mov    $0x120,%ecx
cmp    $0x1,%eax
je     135e <readFile+0x22e>
lea    0x140(%rsp),%rsi
mov    %r15,%rdi
mov    $0x6,%edx
call   1050 <matchNames@plt>
mov    $0x140,%ecx
cmp    $0x1,%eax
je     135e <readFile+0x22e>
lea    0x160(%rsp),%rsi
mov    %r15,%rdi
mov    $0x6,%edx
call   1050 <matchNames@plt>
mov    $0x160,%ecx
cmp    $0x1,%eax
je     135e <readFile+0x22e>
lea    0x180(%rsp),%rsi
mov    %r15,%rdi
mov    $0x6,%edx
call   1050 <matchNames@plt>
mov    $0x180,%ecx
cmp    $0x1,%eax
je     135e <readFile+0x22e>
lea    0x1a0(%rsp),%rsi
mov    %r15,%rdi
mov    $0x6,%edx
call   1050 <matchNames@plt>
mov    $0x1a0,%ecx
cmp    $0x1,%eax
je     135e <readFile+0x22e>
lea    0x1c0(%rsp),%rsi
mov    %r15,%rdi
mov    $0x6,%edx
call   1050 <matchNames@plt>
mov    $0x1c0,%ecx
cmp    $0x1,%eax
je     135e <readFile+0x22e>
lea    0x1e0(%rsp),%rsi
mov    %r15,%rdi
mov    $0x6,%edx
call   1050 <matchNames@plt>
mov    $0x1e0,%ecx
cmp    $0x1,%eax
jne    1380 <readFile+0x250>
movb   $0x0,(%r14)
lea    (%rsp,%rcx,1),%rsi
mov    %r14,%rdi
call   1040 <loadFileSectors@plt>
mov    $0x1,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
movb   $0x0,(%r14)
mov    $0x200,%ecx
test   %eax,%eax
jne    1362 <readFile+0x232>
xor    %eax,%eax
jmp    1373 <readFile+0x243>

LLVM IR (-O0):
define i32 @readFile(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [512 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%10 = call i32 @readSector(i8* %9, i32 2)
store i32 0, i32* %7
br label %11
11: ; preds = %26, %2
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 16
br i1 %13, label %14, label %29
14: ; preds = %11
%15 = load i8*, i8** %4
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%17 = load i32, i32* %7
%18 = mul nsw i32 %17, 32
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
%21 = call i32 @matchNames(i8* %15, i8* %20, i32 6)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %25
24: ; preds = %14
br label %29
25: ; preds = %14
br label %26
26: ; preds = %25
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %11
29: ; preds = %24, %11
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 0
store i8 0, i8* %31
%32 = load i32, i32* %8
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %29
store i32 0, i32* %3
br label %43
35: ; preds = %29
%36 = load i8*, i8** %5
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%38 = load i32, i32* %7
%39 = mul nsw i32 %38, 32
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
%42 = call i32 @loadFileSectors(i8* %36, i8* %41)
store i32 1, i32* %3
br label %43
43: ; preds = %35, %34
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
define i32 @readFile(i8* %0, i8* %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = call i32 @readSector(i8* %4, i32 2)
%6 = call i32 @matchNames(i8* %0, i8* %4, i32 6)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %10
8: ; preds = %66, %62, %58, %54, %50, %46, %42, %38, %34, %30, %26, %22, %18, %14, %10, %2
%9 = phi i64 [ 0, %2 ], [ 32, %10 ], [ 64, %14 ], [ 96, %18 ], [ 128, %22 ], [ 160, %26 ], [ 192, %30 ], [ 224, %34 ], [ 256, %38 ], [ 288, %42 ], [ 320, %46 ], [ 352, %50 ], [ 384, %54 ], [ 416, %58 ], [ 448, %62 ], [ 480, %66 ]
store i8 0, i8* %1
br label %72
10: ; preds = %2
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 32
%12 = call i32 @matchNames(i8* %0, i8* %11, i32 6)
%13 = icmp eq i32 %12, 1
br i1 %13, label %8, label %14
14: ; preds = %10
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 64
%16 = call i32 @matchNames(i8* %0, i8* %15, i32 6)
%17 = icmp eq i32 %16, 1
br i1 %17, label %8, label %18
18: ; preds = %14
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 96
%20 = call i32 @matchNames(i8* %0, i8* %19, i32 6)
%21 = icmp eq i32 %20, 1
br i1 %21, label %8, label %22
22: ; preds = %18
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 128
%24 = call i32 @matchNames(i8* %0, i8* %23, i32 6)
%25 = icmp eq i32 %24, 1
br i1 %25, label %8, label %26
26: ; preds = %22
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 160
%28 = call i32 @matchNames(i8* %0, i8* %27, i32 6)
%29 = icmp eq i32 %28, 1
br i1 %29, label %8, label %30
30: ; preds = %26
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 192
%32 = call i32 @matchNames(i8* %0, i8* %31, i32 6)
%33 = icmp eq i32 %32, 1
br i1 %33, label %8, label %34
34: ; preds = %30
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 224
%36 = call i32 @matchNames(i8* %0, i8* %35, i32 6)
%37 = icmp eq i32 %36, 1
br i1 %37, label %8, label %38
38: ; preds = %34
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 256
%40 = call i32 @matchNames(i8* %0, i8* %39, i32 6)
%41 = icmp eq i32 %40, 1
br i1 %41, label %8, label %42
42: ; preds = %38
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 288
%44 = call i32 @matchNames(i8* %0, i8* %43, i32 6)
%45 = icmp eq i32 %44, 1
br i1 %45, label %8, label %46
46: ; preds = %42
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 320
%48 = call i32 @matchNames(i8* %0, i8* %47, i32 6)
%49 = icmp eq i32 %48, 1
br i1 %49, label %8, label %50
50: ; preds = %46
%51 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 352
%52 = call i32 @matchNames(i8* %0, i8* %51, i32 6)
%53 = icmp eq i32 %52, 1
br i1 %53, label %8, label %54
54: ; preds = %50
%55 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 384
%56 = call i32 @matchNames(i8* %0, i8* %55, i32 6)
%57 = icmp eq i32 %56, 1
br i1 %57, label %8, label %58
58: ; preds = %54
%59 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 416
%60 = call i32 @matchNames(i8* %0, i8* %59, i32 6)
%61 = icmp eq i32 %60, 1
br i1 %61, label %8, label %62
62: ; preds = %58
%63 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 448
%64 = call i32 @matchNames(i8* %0, i8* %63, i32 6)
%65 = icmp eq i32 %64, 1
br i1 %65, label %8, label %66
66: ; preds = %62
%67 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 480
%68 = call i32 @matchNames(i8* %0, i8* %67, i32 6)
%69 = icmp eq i32 %68, 1
br i1 %69, label %8, label %70
70: ; preds = %66
store i8 0, i8* %1
%71 = icmp eq i32 %68, 0
br i1 %71, label %76, label %72
72: ; preds = %8, %70
%73 = phi i64 [ %9, %8 ], [ 512, %70 ]
%74 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %73
%75 = call i32 @loadFileSectors(i8* %1, i8* %74)
br label %76
76: ; preds = %70, %72
%77 = phi i32 [ 1, %72 ], [ 0, %70 ]
ret i32 %77
}