// File: /workspace/github_cpp_makefile_star2_O3/sidvishnoi[P]filesystem-assignment/day1/FileSystem.cpp
// Function: FileSystem::FileSystem(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
FileSystem::FileSystem(string title)
        : diskTitle_k(title) {

    // check if disk doesn't exists or is empty
    //  and if exists, get it's size in bytes

    /* %%
    >> write a code to check whether the disk already exists or not by checking it's size (store size in diskSize_k)
    and update the boolean variable
        alreadyExists = true, if file with same name exists
        else false
    */
    // %% logic here
    bool alreadyExists; // %%;

    // get size if not exists
    if (!alreadyExists) {
        int diskSizeMB;
        cout << "Enter disk size in MiB : ";
        cin >> diskSizeMB;
        cin.ignore(32767, '\n');
        diskSize_k = 1024*1024*diskSizeMB;
    }

    /* %%
    how many sectors of each size sectorSize_k exist, if total disk size = diskSize_k
    >> update right hand value for numberOfSectors_k
    */
    numberOfSectors_k = -1;

    /* %%
    how many sectors need to be reserved, if each sector needs 4 bytes (sizeof int) to store a status?
    >> update right hand value for reservedSectors_k
    */
    reservedSectors_k = -1;

    // reserve space, if disk doesn't already exist
    if (!alreadyExists) createDisk();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdi, %rbx
leaq 0x10(%rdi), %r13
movq %r13, (%rdi)
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
addq %rax, %rdx
movq %rax, %rsi
callq 0x2ae4
movl $0x200, 0x20(%rbx)      # imm = 0x200
movl $0x2, 0x30(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%rbx)
movups %xmm0, 0x48(%rbx)
movups %xmm0, 0x58(%rbx)
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x1188(%rip), %rsi      # 0x5292
leaq 0x1185(%rip), %rdx      # 0x5296
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x3e0e
leaq 0x28(%rsp), %r15
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x1164(%rip), %rsi      # 0x5297
leaq 0x1161(%rip), %rdx      # 0x529b
movq %r15, %rdi
callq 0x3e0e
leaq 0x48(%rsp), %r15
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x1145(%rip), %rsi      # 0x529c
leaq 0x1146(%rip), %rdx      # 0x52a4
movq %r15, %rdi
callq 0x3e0e
leaq 0x68(%rsp), %r15
leaq 0x78(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x112a(%rip), %rsi      # 0x52a5
leaq 0x112c(%rip), %rdx      # 0x52ae
movq %r15, %rdi
callq 0x3e0e
leaq 0x88(%rsp), %r15
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x110a(%rip), %rsi      # 0x52af
leaq 0x110c(%rip), %rdx      # 0x52b8
movq %r15, %rdi
callq 0x3e0e
leaq 0xa8(%rsp), %r15
leaq 0xb8(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x10ea(%rip), %rsi      # 0x52b9
leaq 0x10ea(%rip), %rdx      # 0x52c0
movq %r15, %rdi
callq 0x3e0e
leaq 0xc8(%rsp), %r15
leaq 0xd8(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x10c8(%rip), %rsi      # 0x52c1
leaq 0x10c4(%rip), %rdx      # 0x52c4
movq %r15, %rdi
callq 0x3e0e
leaq 0x68(%rbx), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x7(%rsp), %rcx
movl $0x7, %edx
callq 0x42f0
movl $0xd0, %ebx
leaq (%rsp,%rbx), %rax
addq $0x8, %rax
movq -0x10(%rax), %rdi
cmpq %rdi, %rax
je 0x4241
movq (%rax), %rsi
incq %rsi
callq 0x21e0
addq $-0x20, %rbx
jmp 0x4225
movq %rax, %r12
xorl %r14d, %r14d
movq 0xc8(%rsp,%r14), %rdi
leaq (%r14,%rbp), %rax
cmpq %rdi, %rax
je 0x4269
movq (%rax), %rsi
incq %rsi
callq 0x21e0
addq $-0x20, %r14
cmpq $-0xe0, %r14
jne 0x424d
jmp 0x42ad
jmp 0x4282
jmp 0x4282
jmp 0x4282
jmp 0x4282
jmp 0x4282
movq %rax, %r12
addq $-0x10, %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x429d
movq (%r15), %rsi
incq %rsi
callq 0x21e0
leaq -0x20(%r15), %rax
addq $-0x10, %r15
cmpq %r14, %r15
movq %rax, %r15
jne 0x4289
leaq 0x38(%rbx), %r14
leaq 0x50(%rbx), %rdi
callq 0x2a86
movq (%r14), %rdi
testq %rdi, %rdi
je 0x42ce
movq 0x48(%rbx), %rsi
subq %rdi, %rsi
callq 0x21e0
movq (%rbx), %rdi
cmpq %r13, %rdi
je 0x42e2
movq (%r13), %rsi
incq %rsi
callq 0x21e0
movq %r12, %rdi
callq 0x2350
movq %rax, %r12
jmp 0x42ad
nop