// File: 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
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x150(%rbp)
movq %rdi, %rax
movq %rax, -0x168(%rbp)
callq 0x30c0
movq -0x150(%rbp), %rdi
movl $0x200, 0x20(%rdi)      # imm = 0x200
movl $0x2, 0x30(%rdi)
addq $0x38, %rdi
movq %rdi, -0x160(%rbp)
callq 0x7aa0
movq -0x150(%rbp), %rdi
addq $0x50, %rdi
movq %rdi, -0x158(%rbp)
callq 0x62c0
movq -0x150(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x148(%rbp)
movb $0x1, -0x123(%rbp)
leaq -0x100(%rbp), %rax
movq %rax, -0x140(%rbp)
movq %rax, -0x108(%rbp)
leaq -0x109(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x3460
movq -0x140(%rbp), %rdi
movq -0x138(%rbp), %rdx
leaq 0x4d1d(%rip), %rsi      # 0xc27c
callq 0x63a0
jmp 0x7566
leaq -0xe0(%rbp), %rax
movq %rax, -0x178(%rbp)
movq %rax, -0x108(%rbp)
leaq -0x11d(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x3460
movq -0x178(%rbp), %rdi
movq -0x170(%rbp), %rdx
leaq 0x4cde(%rip), %rsi      # 0xc281
callq 0x63a0
jmp 0x75aa
leaq -0xc0(%rbp), %rax
movq %rax, -0x188(%rbp)
movq %rax, -0x108(%rbp)
leaq -0x11e(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x3460
movq -0x188(%rbp), %rdi
movq -0x180(%rbp), %rdx
leaq 0x4c9f(%rip), %rsi      # 0xc286
callq 0x63a0
jmp 0x75ee
leaq -0xa0(%rbp), %rax
movq %rax, -0x198(%rbp)
movq %rax, -0x108(%rbp)
leaq -0x11f(%rbp), %rdi
movq %rdi, -0x190(%rbp)
callq 0x3460
movq -0x198(%rbp), %rdi
movq -0x190(%rbp), %rdx
leaq 0x4c64(%rip), %rsi      # 0xc28f
callq 0x63a0
jmp 0x7632
leaq -0x80(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movq %rax, -0x108(%rbp)
leaq -0x120(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x3460
movq -0x1a8(%rbp), %rdi
movq -0x1a0(%rbp), %rdx
leaq 0x4c2d(%rip), %rsi      # 0xc299
callq 0x63a0
jmp 0x7673
leaq -0x60(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movq %rax, -0x108(%rbp)
leaq -0x121(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x3460
movq -0x1b8(%rbp), %rdi
movq -0x1b0(%rbp), %rdx
leaq 0x4bf6(%rip), %rsi      # 0xc2a3
callq 0x63a0
jmp 0x76b4
leaq -0x40(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movq %rax, -0x108(%rbp)
leaq -0x122(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x3460
movq -0x1c8(%rbp), %rdi
movq -0x1c0(%rbp), %rdx
leaq 0x4bbd(%rip), %rsi      # 0xc2ab
callq 0x63a0
jmp 0x76f5
movb $0x0, -0x123(%rbp)
leaq -0x100(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x7, -0x18(%rbp)
leaq -0x124(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x6600
movq -0x148(%rbp), %rdi
movq -0x1d0(%rbp), %rcx
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x7ac0
jmp 0x773f
leaq -0x124(%rbp), %rdi
callq 0x3ff0
leaq -0x100(%rbp), %rax
movq %rax, -0x1e0(%rbp)
addq $0xe0, %rax
movq %rax, -0x1d8(%rbp)
movq -0x1d8(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x3150
movq -0x1e0(%rbp), %rcx
movq -0x1e8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x1d8(%rbp)
jne 0x7766
leaq -0x122(%rbp), %rdi
callq 0x3280
leaq -0x121(%rbp), %rdi
callq 0x3280
leaq -0x120(%rbp), %rdi
callq 0x3280
leaq -0x11f(%rbp), %rdi
callq 0x3280
leaq -0x11e(%rbp), %rdi
callq 0x3280
leaq -0x11d(%rbp), %rdi
callq 0x3280
leaq -0x109(%rbp), %rdi
callq 0x3280
testb $0x1, -0x125(%rbp)
jne 0x7a2a
movq 0x97d1(%rip), %rdi      # 0x10fd0
leaq 0x4aa9(%rip), %rsi      # 0xc2af
callq 0x3230
jmp 0x780d
movq 0x97cc(%rip), %rdi      # 0x10fe0
leaq -0x12c(%rbp), %rsi
callq 0x3140
jmp 0x7822
movq 0x97b7(%rip), %rdi      # 0x10fe0
movl $0x7fff, %esi           # imm = 0x7FFF
movl $0xa, %edx
callq 0x3170
jmp 0x783a
movq -0x168(%rbp), %rax
movl -0x12c(%rbp), %ecx
shll $0x14, %ecx
movl %ecx, 0x24(%rax)
jmp 0x7a2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
jmp 0x79a4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
jmp 0x7998
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
jmp 0x798c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
jmp 0x7980
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
jmp 0x7974
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
jmp 0x7968
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
jmp 0x795c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
leaq -0x124(%rbp), %rdi
callq 0x3ff0
leaq -0x100(%rbp), %rax
movq %rax, -0x1f8(%rbp)
addq $0xe0, %rax
movq %rax, -0x1f0(%rbp)
movq -0x1f0(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x200(%rbp)
callq 0x3150
movq -0x1f8(%rbp), %rcx
movq -0x200(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x1f0(%rbp)
jne 0x7929
jmp 0x795c
leaq -0x122(%rbp), %rdi
callq 0x3280
leaq -0x121(%rbp), %rdi
callq 0x3280
leaq -0x120(%rbp), %rdi
callq 0x3280
leaq -0x11f(%rbp), %rdi
callq 0x3280
leaq -0x11e(%rbp), %rdi
callq 0x3280
leaq -0x11d(%rbp), %rdi
callq 0x3280
leaq -0x109(%rbp), %rdi
callq 0x3280
testb $0x1, -0x123(%rbp)
jne 0x79bb
jmp 0x7a08
movq -0x108(%rbp), %rax
leaq -0x100(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x208(%rbp)
je 0x7a06
movq -0x208(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x210(%rbp)
callq 0x3150
movq -0x210(%rbp), %rax
leaq -0x100(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x208(%rbp)
jne 0x79d5
jmp 0x7a08
jmp 0x7a61
movq -0x148(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
callq 0x3d50
jmp 0x7a61
movq -0x168(%rbp), %rax
movl $0xffffffff, 0x2c(%rax) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x28(%rax) # imm = 0xFFFFFFFF
testb $0x1, -0x125(%rbp)
jne 0x7a58
movq -0x168(%rbp), %rdi
callq 0x7f30
jmp 0x7a56
jmp 0x7a58
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
movq -0x158(%rbp), %rdi
callq 0x3d50
movq -0x160(%rbp), %rdi
callq 0x3db0
movq -0x150(%rbp), %rdi
callq 0x3150
movq -0x118(%rbp), %rdi
callq 0x3450
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)