#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 */
char *getSector(int);
int /*<<< orphan*/ printf(char *, int, int, int);
int addToDirectory(int index, int fileInd) {
  char *sector = getSector(index);
  int i = 8;
  while (sector[i] || sector[i + 1])
    i += 2;
  printf("Adding index %d at offset %d in sector %d ...\n", fileInd, i, index);
  sector[i + 1] = fileInd >> 8;
  sector[i] = fileInd & 0xFF;
}


x86 assembly (clang, -O0):
<addToDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <getSector@plt>
mov    %rax,-0x18(%rbp)
movl   $0x8,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
jne    1175 <addToDirectory+0x55>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1185 <addToDirectory+0x65>
jmp    1193 <addToDirectory+0x73>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    1141 <addToDirectory+0x21>
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addToDirectory>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r14d
call   1040 <getSector@plt>
mov    %rax,%rbx
mov    $0x8,%edx
jmp    1144 <addToDirectory+0x24>
nopl   (%rax)
add    $0x2,%rdx
cmpb   $0x0,(%rbx,%rdx,1)
jne    1140 <addToDirectory+0x20>
cmpb   $0x0,0x1(%rbx,%rdx,1)
jne    1140 <addToDirectory+0x20>
mov    %edx,%ebp
and    $0xfffffffe,%ebp
lea    0x1(%rdx),%r12d
lea    0xe9f(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%ecx
call   1030 <printf@plt>
mov    %r12,%rax
mov    %r15d,%ecx
mov    %ch,(%rbx,%rax,1)
mov    %cl,(%rbx,%rbp,1)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"Adding index %d at offset %d in sector %d ...\0A\00"
define i32 @addToDirectory(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = call i8* @getSector(i32 %8)
store i8* %9, i8** %6
store i32 8, i32* %7
br label %10
10: ; preds = %29, %2
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %27, label %18
18: ; preds = %10
%19 = load i8*, i8** %6
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br label %27
27: ; preds = %18, %10
%28 = phi i1 [ true, %10 ], [ %26, %18 ]
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 2
store i32 %31, i32* %7
br label %10
32: ; preds = %27
%33 = load i32, i32* %5
%34 = load i32, i32* %7
%35 = load i32, i32* %4
%36 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %33, i32 %34, i32 %35)
%37 = load i32, i32* %5
%38 = ashr i32 %37, 8
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %6
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %40, i64 %43
store i8 %39, i8* %44
%45 = load i32, i32* %5
%46 = and i32 %45, 255
%47 = trunc i32 %46 to i8
%48 = load i8*, i8** %6
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 %47, i8* %51
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [47 x i8] c"Adding index %d at offset %d in sector %d ...\0A\00"
define i32 @addToDirectory(i32 %0, i32 %1) {
%3 = tail call i8* @getSector(i32 %0)
br label %4
4: ; preds = %14, %2
%5 = phi i64 [ %15, %14 ], [ 8, %2 ]
%6 = getelementptr inbounds i8, i8* %3, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = or i64 %5, 1
%11 = getelementptr inbounds i8, i8* %3, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %4, %9
%15 = add nuw i64 %5, 2
br label %4
16: ; preds = %9
%17 = trunc i64 %5 to i32
%18 = and i64 %5, 4294967294
%19 = getelementptr inbounds i8, i8* %3, i64 %18
%20 = and i64 %10, 4294967295
%21 = getelementptr inbounds i8, i8* %3, i64 %20
%22 = tail call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %17, i32 %0)
%23 = lshr i32 %1, 8
%24 = trunc i32 %23 to i8
store i8 %24, i8* %21
%25 = trunc i32 %1 to i8
store i8 %25, i8* %19
ret i32 undef
}