// File: /workspace/github_cpp_makefile_star2_O1/jasperandrew[P]cs350-project2/./lab7.h
// Function: initDrive()
int initDrive()
{
    string path = "DRIVE";
    ifstream f(path.c_str());
    if(f.good()){
        if(DBG) cout << "Loading data from existing DRIVE\n";
        return 1;
    }

    if(DBG) cout << "Creating DRIVE directory\n";

    // Create drive directory
    mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);

    // Create file map
    if(DBG) cout << "Creating FILE_MAP file\n";
    ofstream filemap(path + string("/FILE_MAP"), ios::out);
    filemap.close();

    // Create checkpoint region file
    if(DBG) cout << "Creating CHECKPOINT_REGION file\n";
    /*ofstream checkpoint(path + string("/CHECKPOINT_REGION"), ios::out );
      checkpoint.seekp(192-1);
      checkpoint.write("", 1);
      checkpoint.close();*/

    // Create segment files
    path += "/SEGMENT";
    for(int i = 0; i < 32; i++){
        if(DBG) cout << "Creating segment file " << i + 1 << "\n";
        ofstream segment(path + to_string(i+1), ios::out | ios::binary);
        segment.seekp(SEG_SZ-1);
        segment.write("", 1);
        segment.close();
    }

    g_imap.idx = 0;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x678, %rsp            # imm = 0x678
leaq -0x58(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x20dc(%rip), %rsi      # 0x6156
leaq 0x20da(%rip), %rdx      # 0x615b
leaq -0x68(%rbp), %rbx
movq %rbx, %rdi
callq 0x55be
movq (%rbx), %rsi
leaq -0x6a0(%rbp), %rdi
movl $0x8, %edx
callq 0x23c0
movq -0x6a0(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x680(%rbp,%rax)
je 0x4159
movq 0x4f0f(%rip), %rdi      # 0x8fd0
leaq 0x20b6(%rip), %rsi      # 0x617e
movl $0x19, %edx
callq 0x2240
movq -0x68(%rbp), %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x20d0
movq 0x4ee9(%rip), %rdi      # 0x8fd0
leaq 0x20aa(%rip), %rsi      # 0x6198
movl $0x17, %edx
callq 0x2240
leaq -0x38(%rbp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x1f77(%rip), %rsi      # 0x607e
leaq 0x1f79(%rip), %rdx      # 0x6087
leaq -0x48(%rbp), %rdi
callq 0x55be
movq -0x68(%rbp), %rcx
movq -0x60(%rbp), %r8
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2230
leaq -0x288(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x417b
movq %rdx, -0x298(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x288(%rbp)
jmp 0x4182
movl $0x1, %ebx
movq 0x4e6b(%rip), %rdi      # 0x8fd0
leaq 0x1ff0(%rip), %rsi      # 0x615c
movl $0x21, %edx
callq 0x2240
jmp 0x4423
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq -0x298(%rbp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x498(%rbp), %rdi
movl $0x10, %edx
callq 0x23f0
movq -0x298(%rbp), %rdi
cmpq %r14, %rdi
je 0x41c2
callq 0x21b0
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x41d0
callq 0x21b0
leaq -0x498(%rbp), %rdi
callq 0x22e0
movq 0x4ded(%rip), %rdi      # 0x8fd0
leaq 0x1fc6(%rip), %rsi      # 0x61b0
movl $0x20, %edx
callq 0x2240
leaq 0x1e1e(%rip), %rsi      # 0x6019
leaq -0x68(%rbp), %rdi
callq 0x23e0
movq 0x4dbd(%rip), %rax      # 0x8fc8
movq (%rax), %rcx
movq %rcx, -0x70(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x78(%rbp)
xorl %ebx, %ebx
movq 0x4dad(%rip), %r15      # 0x8fd0
leaq -0x298(%rbp), %r14
movl $0x16, %edx
movq %r15, %rdi
leaq 0x1f98(%rip), %rsi      # 0x61d1
callq 0x2240
leal 0x1(%rbx), %r12d
movq %r15, %rdi
movl %r12d, %esi
callq 0x2380
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2100(%rip), %rsi      # 0x635c
callq 0x2240
movl $0x1, %r13d
cmpl $0x9, %ebx
leaq -0x98(%rbp), %rbx
jb 0x42ba
movl $0x4, %r13d
movl %r12d, %eax
cmpl $0x63, %eax
jbe 0x42b1
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x42b7
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x42ba
movl %eax, %ecx
movl $0xd1b71759, %edx       # imm = 0xD1B71759
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %r13d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x427c
addl $-0x3, %r13d
jmp 0x42ba
addl $-0x2, %r13d
jmp 0x42ba
decl %r13d
movl %r13d, %esi
leaq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
movq %rbx, %rdi
movl $0x2d, %edx
callq 0x2250
movq -0x98(%rbp), %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x54a4
movq -0x68(%rbp), %rcx
movq -0x60(%rbp), %r8
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2230
leaq -0x38(%rbp), %r13
movq %r13, -0x48(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4322
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x432a
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
movq %rdx, -0x40(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r14, %rdi
leaq -0x48(%rbp), %rsi
movl $0x14, %edx
callq 0x23f0
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x4360
callq 0x21b0
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x4378
callq 0x21b0
movl $0xfffff, %esi          # imm = 0xFFFFF
movq %r14, %rdi
xorl %edx, %edx
callq 0x2270
movl $0x1, %edx
movq %r14, %rdi
leaq 0x1d1f(%rip), %rsi      # 0x60b5
callq 0x22c0
movq %r14, %rdi
callq 0x22e0
movq -0x70(%rbp), %rax
movq %rax, -0x298(%rbp)
movq -0x18(%rax), %rax
movq -0x78(%rbp), %rcx
movq %rcx, -0x298(%rbp,%rax)
leaq -0x290(%rbp), %rdi
callq 0x2190
leaq -0x1a0(%rbp), %rdi
callq 0x20a0
movl %r12d, %ebx
cmpl $0x20, %r12d
jne 0x422a
movl $0x0, 0x17332b(%rip)    # 0x177718
leaq -0x490(%rbp), %rdi
movq -0x70(%rbp), %rax
movq %rax, -0x8(%rdi)
movq -0x18(%rax), %rax
movq -0x78(%rbp), %rcx
movq %rcx, -0x498(%rbp,%rax)
callq 0x2190
leaq -0x3a0(%rbp), %rdi
callq 0x20a0
xorl %ebx, %ebx
leaq -0x58(%rbp), %r15
leaq -0x6a0(%rbp), %rdi
callq 0x2070
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x443d
callq 0x21b0
movl %ebx, %eax
addq $0x678, %rsp            # imm = 0x678
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x298(%rbp), %rdi
cmpq %r14, %rdi
je 0x446a
callq 0x21b0
jmp 0x446a
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x44e2
callq 0x21b0
jmp 0x44e2
jmp 0x4485
movq %rax, %rbx
jmp 0x44ee
movq %rax, %rbx
jmp 0x44e2
jmp 0x44cf
jmp 0x44cf
movq %rax, %rbx
jmp 0x44a4
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x44a4
callq 0x21b0
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x44d2
callq 0x21b0
jmp 0x44d2
movq %rax, %rbx
leaq -0x298(%rbp), %rdi
callq 0x2310
jmp 0x44d2
movq %rax, %rbx
leaq -0x58(%rbp), %r15
leaq -0x498(%rbp), %rdi
callq 0x2310
leaq -0x6a0(%rbp), %rdi
callq 0x2070
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x44fc
callq 0x21b0
movq %rbx, %rdi
callq 0x23a0