#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 */
scalar_t__ readFile(int, char *, int);
int /*<<< orphan*/ readSector(char *, int);
scalar_t__ strncmp(int, char *, int);
void countFileSectors(int filename, int *countPtr) {
  char directory[512];
  unsigned int i, j, k;
  char tempBuffer[13312];
  if (readFile(filename, tempBuffer, 1) < 0) {
    *countPtr = -1;
    return;
  }
  *countPtr = 0;
  readSector(directory, 2);
  for (i = 0; i < 512; i += 32) {
    if (directory[i] == 0) {
      continue;
    } else if (strncmp(filename, directory + i, 6)) {
      for (j = 6, k = 0; j < 32; j++, k += 512) {
        if (directory[i + j] == 0) {
          return;
        } else {
          (*countPtr)++;
        }
      }
    }
  }
  return;
}


x86 assembly (clang, -O0):
<countFileSectors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3620,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x3620(%rbp),%rsi
mov    $0x1,%edx
call   1050 <readFile@plt>
cmp    $0x0,%rax
jge    116f <countFileSectors+0x3f>
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
jmp    1289 <countFileSectors+0x159>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x210(%rbp),%rdi
mov    $0x2,%esi
call   1040 <readSector@plt>
movl   $0x0,-0x214(%rbp)
cmpl   $0x200,-0x214(%rbp)
jae    1284 <countFileSectors+0x154>
mov    -0x214(%rbp),%eax
movsbl -0x210(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
jne    11c0 <countFileSectors+0x90>
jmp    1270 <countFileSectors+0x140>
mov    -0x4(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    -0x214(%rbp),%eax
add    %rax,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1266 <countFileSectors+0x136>
movl   $0x6,-0x218(%rbp)
movl   $0x0,-0x21c(%rbp)
cmpl   $0x20,-0x218(%rbp)
jae    1261 <countFileSectors+0x131>
mov    -0x214(%rbp),%eax
add    -0x218(%rbp),%eax
mov    %eax,%eax
movsbl -0x210(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
jne    122c <countFileSectors+0xfc>
jmp    1289 <countFileSectors+0x159>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    123c <countFileSectors+0x10c>
mov    -0x218(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x218(%rbp)
mov    -0x21c(%rbp),%eax
add    $0x200,%eax
mov    %eax,-0x21c(%rbp)
jmp    11fb <countFileSectors+0xcb>
jmp    1266 <countFileSectors+0x136>
jmp    126b <countFileSectors+0x13b>
jmp    1270 <countFileSectors+0x140>
mov    -0x214(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x214(%rbp)
jmp    1194 <countFileSectors+0x64>
jmp    1289 <countFileSectors+0x159>
add    $0x3620,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countFileSectors>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3608,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0x200(%rsp),%rsi
mov    $0x1,%edx
call   1050 <readFile@plt>
test   %rax,%rax
js     11e0 <countFileSectors+0xb0>
movl   $0x0,(%rbx)
mov    %rsp,%rdi
mov    $0x2,%esi
call   1040 <readSector@plt>
lea    0x7(%rsp),%rbp
xor    %r15d,%r15d
jmp    1194 <countFileSectors+0x64>
nopl   0x0(%rax,%rax,1)
lea    0x20(%r15),%rax
add    $0x20,%rbp
cmp    $0x1e0,%r15
mov    %rax,%r15
jae    11e6 <countFileSectors+0xb6>
cmpb   $0x0,(%rsp,%r15,1)
je     1180 <countFileSectors+0x50>
lea    (%rsp,%r15,1),%rsi
mov    %r14d,%edi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1180 <countFileSectors+0x50>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0x0,-0x1(%rbp,%rax,1)
je     11e6 <countFileSectors+0xb6>
addl   $0x1,(%rbx)
cmpb   $0x0,0x0(%rbp,%rax,1)
je     11e6 <countFileSectors+0xb6>
addl   $0x1,(%rbx)
add    $0x2,%rax
cmp    $0x1a,%rax
jne    11c0 <countFileSectors+0x90>
jmp    1180 <countFileSectors+0x50>
movl   $0xffffffff,(%rbx)
add    $0x3608,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @countFileSectors(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [512 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [13312 x i8]
store i32 %0, i32* %3
store i32* %1, i32** %4
%10 = load i32, i32* %3
%11 = getelementptr inbounds [13312 x i8], [13312 x i8]* %9, i64 0, i64 0
%12 = call i64 @readFile(i32 %10, i8* %11, i32 1)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32*, i32** %4
store i32 -1, i32* %15
br label %70
16: ; preds = %2
%17 = load i32*, i32** %4
store i32 0, i32* %17
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%19 = call i32 @readSector(i8* %18, i32 2)
store i32 0, i32* %6
br label %20
20: ; preds = %66, %16
%21 = load i32, i32* %6
%22 = icmp ult i32 %21, 512
br i1 %22, label %23, label %69
23: ; preds = %20
%24 = load i32, i32* %6
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %23
br label %66
31: ; preds = %23
%32 = load i32, i32* %3
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%34 = load i32, i32* %6
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = call i64 @strncmp(i32 %32, i8* %36, i32 6)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %64
39: ; preds = %31
store i32 6, i32* %7
store i32 0, i32* %8
br label %40
40: ; preds = %58, %39
%41 = load i32, i32* %7
%42 = icmp ult i32 %41, 32
br i1 %42, label %43, label %63
43: ; preds = %40
%44 = load i32, i32* %6
%45 = load i32, i32* %7
%46 = add i32 %44, %45
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %43
br label %70
53: ; preds = %43
%54 = load i32*, i32** %4
%55 = load i32, i32* %54
%56 = add nsw i32 %55, 1
store i32 %56, i32* %54
br label %57
57: ; preds = %53
br label %58
58: ; preds = %57
%59 = load i32, i32* %7
%60 = add i32 %59, 1
store i32 %60, i32* %7
%61 = load i32, i32* %8
%62 = add i32 %61, 512
store i32 %62, i32* %8
br label %40
63: ; preds = %40
br label %64
64: ; preds = %63, %31
br label %65
65: ; preds = %64
br label %66
66: ; preds = %65, %30
%67 = load i32, i32* %6
%68 = add i32 %67, 32
store i32 %68, i32* %6
br label %20
69: ; preds = %20
br label %70
70: ; preds = %69, %52, %14
ret void
}

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