// File: /workspace/github_cpp_makefile_star2_O1/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 $0xf8, %rsp
movq %rdi, %rbx
leaq 0x10(%rdi), %rbp
movq %rbp, (%rdi)
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
addq %rax, %rdx
movq %rax, %rsi
callq 0x2af2
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 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x112c(%rip), %rsi      # 0x5292
leaq 0x1129(%rip), %rdx      # 0x5296
leaq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x3e38
leaq 0x38(%rsp), %r14
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x1108(%rip), %rsi      # 0x5297
leaq 0x1105(%rip), %rdx      # 0x529b
movq %r14, %rdi
callq 0x3e38
leaq 0x58(%rsp), %r14
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x10e9(%rip), %rsi      # 0x529c
leaq 0x10ea(%rip), %rdx      # 0x52a4
movq %r14, %rdi
callq 0x3e38
leaq 0x78(%rsp), %r14
leaq 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x10cb(%rip), %rsi      # 0x52a5
leaq 0x10cd(%rip), %rdx      # 0x52ae
movq %r14, %rdi
callq 0x3e38
leaq 0x98(%rsp), %r14
leaq 0xa8(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x10ab(%rip), %rsi      # 0x52af
leaq 0x10ad(%rip), %rdx      # 0x52b8
movq %r14, %rdi
callq 0x3e38
leaq 0xb8(%rsp), %r14
leaq 0xc8(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x108b(%rip), %rsi      # 0x52b9
leaq 0x108b(%rip), %rdx      # 0x52c0
movq %r14, %rdi
callq 0x3e38
leaq 0xd8(%rsp), %r14
leaq 0xe8(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x1069(%rip), %rsi      # 0x52c1
leaq 0x1065(%rip), %rdx      # 0x52c4
movq %r14, %rdi
callq 0x3e38
leaq 0x68(%rbx), %rdi
leaq 0x18(%rsp), %rsi
leaq 0x17(%rsp), %rcx
movl $0x7, %edx
callq 0x4376
movl $0xd0, %ebx
leaq (%rsp,%rbx), %rax
addq $0x18, %rax
movq -0x10(%rax), %rdi
cmpq %rdi, %rax
je 0x42a0
movq (%rax), %rsi
incq %rsi
callq 0x21e0
addq $-0x20, %rbx
jmp 0x4284
movq %rax, 0x8(%rsp)
xorl %r12d, %r12d
movq 0xd8(%rsp,%r12), %rdi
leaq (%r12,%r13), %rax
cmpq %rdi, %rax
je 0x42ca
movq (%rax), %rsi
incq %rsi
callq 0x21e0
addq $-0x20, %r12
cmpq $-0xe0, %r12
jne 0x42ae
movb $0x1, %al
jmp 0x42ec
jmp 0x42e5
jmp 0x42e5
jmp 0x42e5
jmp 0x42e5
jmp 0x42e5
movq %rax, 0x8(%rsp)
xorl %eax, %eax
leaq 0x38(%rbx), %r12
leaq 0x50(%rbx), %r13
cmpq %r14, %r15
sete %cl
orb %al, %cl
jne 0x432b
addq $-0x10, %r14
leaq 0x18(%rsp), %r15
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x431b
movq (%r14), %rsi
incq %rsi
callq 0x21e0
leaq -0x20(%r14), %rax
addq $-0x10, %r14
cmpq %r15, %r14
movq %rax, %r14
jne 0x4307
movq %r13, %rdi
callq 0x2a96
movq (%r12), %rdi
testq %rdi, %rdi
je 0x4348
movq 0x48(%rbx), %rsi
subq %rdi, %rsi
callq 0x21e0
movq (%rbx), %rdi
cmpq %rbp, %rdi
je 0x435c
movq (%rbp), %rsi
incq %rsi
callq 0x21e0
movq 0x8(%rsp), %rdi
callq 0x2360
movq %rax, 0x8(%rsp)
xorl %eax, %eax
movq %r15, %r14
jmp 0x42ec
nop