// File: RC2K7[P]SDisk-FileSystem/filesystem.cpp
// Function: FileSystem::delBlock(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
int FileSystem::delBlock(string fileName, int blockNum)
{
    int curBlock = this->getFirstBlock(fileName);

    // File Does Not Exist
    if (curBlock == -1)
        return 0;

    // Removing First Block Of File
    if (curBlock == blockNum) {
        for (int i = 0; i < this->rootFileName.size(); i++) {
            if (this->rootFileName[i] == fileName) {
                // Update Root [First Block]
                this->rootFirstBlock[i] = this->fat[blockNum];
                break;
            }
        }

        // Update + Sync, Fat And Root
        this->fat[blockNum] = this->fat[0];
        this->fat[0] = blockNum;
        return this->fsSynch();
    }

    // Block Is Not First Block
    for ( ; curBlock != 0; curBlock = this->fat[curBlock]) {
        if (this->fat[curBlock] == blockNum) {
            this->fat[curBlock] = this->fat[blockNum];

            // Sync Changes To Fat
            this->fat[blockNum] = this->fat[0];
            this->fat[0] = blockNum;
            return this->fsSynch();
        }
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rsi, -0x70(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x40(%rbp), %rdi
movq %rdi, -0x60(%rbp)
callq 0x3100
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x7a10
movl %eax, -0x54(%rbp)
jmp 0x80e1
leaq -0x40(%rbp), %rdi
callq 0x3170
movl -0x54(%rbp), %eax
movl %eax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
jne 0x811c
movl $0x0, -0x4(%rbp)
jmp 0x82ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3170
jmp 0x82f9
movl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x820d
movl $0x0, -0x50(%rbp)
movq -0x68(%rbp), %rdi
movslq -0x50(%rbp), %rax
movq %rax, -0x78(%rbp)
addq $0x38, %rdi
callq 0x5a60
movq %rax, %rcx
movq -0x78(%rbp), %rax
cmpq %rcx, %rax
jae 0x81ae
movq -0x68(%rbp), %rdi
addq $0x38, %rdi
movslq -0x50(%rbp), %rsi
callq 0x5a80
movq -0x70(%rbp), %rsi
movq %rax, %rdi
callq 0x87a0
testb $0x1, %al
jne 0x8173
jmp 0x81a1
movq -0x68(%rbp), %rdi
addq $0x68, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x8760
movq -0x68(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x7c(%rbp)
addq $0x50, %rdi
movslq -0x50(%rbp), %rsi
callq 0x8760
movl -0x7c(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x81ae
jmp 0x81a3
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x812f
movq -0x68(%rbp), %rdi
addq $0x68, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8760
movq -0x68(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x84(%rbp)
addq $0x68, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x8760
movl -0x84(%rbp), %ecx
movq -0x68(%rbp), %rdi
movl %ecx, (%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x80(%rbp)
addq $0x68, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8760
movl -0x80(%rbp), %ecx
movq -0x68(%rbp), %rdi
movl %ecx, (%rax)
callq 0x70c0
movl %eax, -0x4(%rbp)
jmp 0x82ed
jmp 0x820f
cmpl $0x0, -0x20(%rbp)
je 0x82e6
movq -0x68(%rbp), %rdi
addq $0x68, %rdi
movslq -0x20(%rbp), %rsi
callq 0x8760
movl (%rax), %eax
cmpl -0x1c(%rbp), %eax
jne 0x82c9
movq -0x68(%rbp), %rdi
addq $0x68, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x8760
movq -0x68(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x90(%rbp)
addq $0x68, %rdi
movslq -0x20(%rbp), %rsi
callq 0x8760
movl -0x90(%rbp), %ecx
movq -0x68(%rbp), %rdi
movl %ecx, (%rax)
addq $0x68, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8760
movq -0x68(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x8c(%rbp)
addq $0x68, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x8760
movl -0x8c(%rbp), %ecx
movq -0x68(%rbp), %rdi
movl %ecx, (%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x88(%rbp)
addq $0x68, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8760
movl -0x88(%rbp), %ecx
movq -0x68(%rbp), %rdi
movl %ecx, (%rax)
callq 0x70c0
movl %eax, -0x4(%rbp)
jmp 0x82ed
jmp 0x82cb
movq -0x68(%rbp), %rdi
addq $0x68, %rdi
movslq -0x20(%rbp), %rsi
callq 0x8760
movl (%rax), %eax
movl %eax, -0x20(%rbp)
jmp 0x820f
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x3470
nopw %cs:(%rax,%rax)