// File: /workspace/github_cpp_makefile_star2_O2/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 $0x668, %rsp            # imm = 0x668
leaq 0x18e5(%rip), %rsi      # 0x5156
leaq -0x48(%rbp), %rbx
leaq -0x490(%rbp), %rdx
movq %rbx, %rdi
callq 0x20c0
movq (%rbx), %rsi
leaq -0x490(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x23a0
movq -0x490(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x470(%rbp,%rax)
je 0x3a3c
movq 0x4712(%rip), %rdi      # 0x7fc8
leaq 0x18c1(%rip), %rsi      # 0x517e
callq 0x21e0
movq -0x48(%rbp), %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x2100
movq 0x46f1(%rip), %rdi      # 0x7fc8
leaq 0x18ba(%rip), %rsi      # 0x5198
callq 0x21e0
leaq 0x1794(%rip), %rsi      # 0x507e
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %rdx
callq 0x20c0
leaq -0x288(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x45f5
leaq -0x690(%rbp), %rdi
leaq -0x288(%rbp), %rsi
pushq $0x10
popq %rdx
callq 0x23e0
leaq -0x288(%rbp), %rdi
callq 0x20f0
leaq -0x68(%rbp), %rdi
callq 0x20f0
leaq -0x690(%rbp), %rdi
callq 0x22d0
movq 0x467c(%rip), %rdi      # 0x7fc8
leaq 0x185d(%rip), %rsi      # 0x51b0
callq 0x21e0
leaq 0x16ba(%rip), %rsi      # 0x5019
leaq -0x48(%rbp), %rdi
callq 0x23c0
pushq $0x1
popq %rbx
leaq -0x88(%rbp), %r13
leaq -0x68(%rbp), %r14
leaq -0x288(%rbp), %r12
pushq $0x1
popq %r15
cmpl $0x21, %ebx
je 0x3a25
movq 0x4637(%rip), %rdi      # 0x7fc8
leaq 0x1839(%rip), %rsi      # 0x51d1
callq 0x21e0
movq %rax, %rdi
movl %ebx, %esi
callq 0x2370
movq %rax, %rdi
leaq 0x19ab(%rip), %rsi      # 0x535c
callq 0x21e0
movq %r13, %rdi
movl %ebx, %esi
callq 0x44ba
movq %r14, %rdi
leaq -0x48(%rbp), %rsi
movq %r13, %rdx
callq 0x45f5
movq %r12, %rdi
movq %r14, %rsi
pushq $0x14
popq %rdx
callq 0x23e0
movq %r14, %rdi
callq 0x20f0
movq %r13, %rdi
callq 0x20f0
movl $0xfffff, %esi          # imm = 0xFFFFF
movq %r12, %rdi
xorl %edx, %edx
callq 0x2250
movq %r12, %rdi
leaq 0x16af(%rip), %rsi      # 0x50b5
movq %r15, %rdx
callq 0x22b0
movq %r12, %rdi
callq 0x22d0
movq %r12, %rdi
callq 0x2300
incl %ebx
jmp 0x3981
andl $0x0, 0x172cec(%rip)    # 0x176718
leaq -0x690(%rbp), %rdi
callq 0x2300
xorl %ebx, %ebx
jmp 0x3a52
movq 0x4585(%rip), %rdi      # 0x7fc8
leaq 0x1712(%rip), %rsi      # 0x515c
callq 0x21e0
pushq $0x1
popq %rbx
leaq -0x490(%rbp), %rdi
callq 0x2080
leaq -0x48(%rbp), %rdi
callq 0x20f0
movl %ebx, %eax
addq $0x668, %rsp            # imm = 0x668
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x288(%rbp), %rdi
callq 0x20f0
jmp 0x3a8f
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x20f0
jmp 0x3ae9
jmp 0x3aa1
movq %rax, %rbx
jmp 0x3af5
movq %rax, %rbx
jmp 0x3ae9
jmp 0x3ada
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x20f0
jmp 0x3abb
jmp 0x3ada
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x20f0
jmp 0x3add
movq %rax, %rbx
leaq -0x288(%rbp), %rdi
callq 0x2300
jmp 0x3add
movq %rax, %rbx
leaq -0x690(%rbp), %rdi
callq 0x2300
leaq -0x490(%rbp), %rdi
callq 0x2080
leaq -0x48(%rbp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x2390