// File: /workspace/github_cpp_makefile_star2_O3/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 0x204d(%rip), %rsi      # 0x6156
leaq 0x204b(%rip), %rdx      # 0x615b
leaq -0x68(%rbp), %rbx
movq %rbx, %rdi
callq 0x5678
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 0x41e8
movq 0x4e80(%rip), %rdi      # 0x8fd0
leaq 0x2027(%rip), %rsi      # 0x617e
movl $0x19, %edx
callq 0x2240
movq -0x68(%rbp), %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x20d0
movq 0x4e5a(%rip), %rdi      # 0x8fd0
leaq 0x201b(%rip), %rsi      # 0x6198
movl $0x17, %edx
callq 0x2240
leaq -0x38(%rbp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x1ee8(%rip), %rsi      # 0x607e
leaq 0x1eea(%rip), %rdx      # 0x6087
leaq -0x48(%rbp), %rdi
callq 0x5678
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 0x420a
movq %rdx, -0x298(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x288(%rbp)
jmp 0x4211
movl $0x1, %ebx
movq 0x4ddc(%rip), %rdi      # 0x8fd0
leaq 0x1f61(%rip), %rsi      # 0x615c
movl $0x21, %edx
callq 0x2240
jmp 0x44b2
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 0x4251
callq 0x21b0
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x425f
callq 0x21b0
leaq -0x498(%rbp), %rdi
callq 0x22e0
movq 0x4d5e(%rip), %rdi      # 0x8fd0
leaq 0x1f37(%rip), %rsi      # 0x61b0
movl $0x20, %edx
callq 0x2240
leaq 0x1d8f(%rip), %rsi      # 0x6019
leaq -0x68(%rbp), %rdi
callq 0x23e0
movq 0x4d2e(%rip), %rax      # 0x8fc8
movq (%rax), %rcx
movq %rcx, -0x70(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x78(%rbp)
xorl %ebx, %ebx
movq 0x4d1e(%rip), %r15      # 0x8fd0
leaq -0x298(%rbp), %r14
movl $0x16, %edx
movq %r15, %rdi
leaq 0x1f09(%rip), %rsi      # 0x61d1
callq 0x2240
leal 0x1(%rbx), %r12d
movq %r15, %rdi
movl %r12d, %esi
callq 0x2380
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2071(%rip), %rsi      # 0x635c
callq 0x2240
movl $0x1, %r13d
cmpl $0x9, %ebx
leaq -0x98(%rbp), %rbx
jb 0x4349
movl $0x4, %r13d
movl %r12d, %eax
cmpl $0x63, %eax
jbe 0x4340
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x4346
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x4349
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 0x430b
addl $-0x3, %r13d
jmp 0x4349
addl $-0x2, %r13d
jmp 0x4349
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 0x555a
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 0x43b1
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x43b9
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 0x43ef
callq 0x21b0
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x4407
callq 0x21b0
movl $0xfffff, %esi          # imm = 0xFFFFF
movq %r14, %rdi
xorl %edx, %edx
callq 0x2270
movl $0x1, %edx
movq %r14, %rdi
leaq 0x1c90(%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 0x42b9
movl $0x0, 0x17329c(%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 0x44cc
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 0x44f9
callq 0x21b0
jmp 0x44f9
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x4571
callq 0x21b0
jmp 0x4571
jmp 0x4514
movq %rax, %rbx
jmp 0x457d
movq %rax, %rbx
jmp 0x4571
jmp 0x455e
jmp 0x455e
movq %rax, %rbx
jmp 0x4533
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x4533
callq 0x21b0
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x4561
callq 0x21b0
jmp 0x4561
movq %rax, %rbx
leaq -0x298(%rbp), %rdi
callq 0x2310
jmp 0x4561
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 0x458b
callq 0x21b0
movq %rbx, %rdi
callq 0x23a0
nop