// File: RC2K7[P]SDisk-FileSystem/filesystem.cpp
// Function: FileSystem::initFat()
int FileSystem::initFat()
{
	stringstream ssBuffer;
	int dataStart = 1 + this->fatSize;

    // FileSystem Was Just Created
	if (this->getStatusCode() == 1) {
        // Setup Fat With Default Variables
		ssBuffer << setw(5) << setfill('0') << dataStart << this->delimiter;
		for (int i = 1; i < dataStart; i++)
			ssBuffer << "00000" << this->delimiter;
		for (int i = dataStart; i < (this->getNumberOfBlocks() - 1); i++)
			ssBuffer << setw(5) << setfill('0') << (i + 1) << this->delimiter;
		ssBuffer << "00000" << this->delimiter;
	} else {  // FileSystem Previously Existed
		string temp;
		for (int i = 1; i < dataStart; i++) {
			this->getBlock(i, temp);
			ssBuffer << temp;
		}
	}

	vector<string> vecFAT = block(ssBuffer.str(), this->getBlockSize());
	ssBuffer.str("");
	for (int i = 0; i < vecFAT.size(); i++)
		ssBuffer << vecFAT[i];

	{ // Local Scope
		int i;
		string entry;
		for (i = 0; i < this->getNumberOfBlocks() && getline(ssBuffer, entry,
			this->delimiter); i++)
		{
			this->fat.push_back(std::stoi(entry, nullptr, 10));
		}
	}

	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x280(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x31c0
movq -0x280(%rbp), %rdi
movl 0x30(%rdi), %eax
incl %eax
movl %eax, -0x194(%rbp)
callq 0x9c10
movl %eax, -0x278(%rbp)
jmp 0x6a85
movl -0x278(%rbp), %eax
cmpl $0x1, %eax
jne 0x6cf2
leaq -0x180(%rbp), %rax
movq %rax, -0x290(%rbp)
movl $0x5, %edi
callq 0x8720
movl %eax, -0x284(%rbp)
jmp 0x6ab4
movq -0x290(%rbp), %rdi
movl -0x284(%rbp), %eax
movl %eax, -0x1a8(%rbp)
movl -0x1a8(%rbp), %esi
callq 0x3320
movq %rax, -0x298(%rbp)
jmp 0x6adb
movl $0x30, %edi
callq 0x8740
movb %al, -0x299(%rbp)
jmp 0x6aed
movq -0x298(%rbp), %rdi
movb -0x299(%rbp), %al
movb %al, -0x1a9(%rbp)
movzbl -0x1a9(%rbp), %esi
callq 0x3430
movq %rax, -0x2a8(%rbp)
jmp 0x6b15
movq -0x2a8(%rbp), %rdi
movl -0x194(%rbp), %esi
callq 0x3460
movq %rax, -0x2b0(%rbp)
jmp 0x6b30
movq -0x2b0(%rbp), %rdi
movl $0x20, %esi
callq 0x3330
jmp 0x6b43
movl $0x1, -0x1b0(%rbp)
movl -0x1b0(%rbp), %eax
cmpl -0x194(%rbp), %eax
jge 0x6bb4
leaq -0x180(%rbp), %rdi
leaq 0x3686(%rip), %rsi      # 0xa1ef
callq 0x3280
movq %rax, -0x2b8(%rbp)
jmp 0x6b77
movq -0x2b8(%rbp), %rdi
movl $0x20, %esi
callq 0x3330
jmp 0x6b8a
jmp 0x6b8c
movl -0x1b0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b0(%rbp)
jmp 0x6b4d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a0(%rbp)
movl %eax, -0x1a4(%rbp)
jmp 0x709b
movl -0x194(%rbp), %eax
movl %eax, -0x1b4(%rbp)
movq -0x280(%rbp), %rdi
movl -0x1b4(%rbp), %eax
movl %eax, -0x2c0(%rbp)
callq 0x9bd0
movl %eax, -0x2bc(%rbp)
jmp 0x6be0
movl -0x2c0(%rbp), %eax
movl -0x2bc(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x6cbe
leaq -0x180(%rbp), %rax
movq %rax, -0x2d0(%rbp)
movl $0x5, %edi
callq 0x8720
movl %eax, -0x2c4(%rbp)
jmp 0x6c17
movq -0x2d0(%rbp), %rdi
movl -0x2c4(%rbp), %eax
movl %eax, -0x1b8(%rbp)
movl -0x1b8(%rbp), %esi
callq 0x3320
movq %rax, -0x2d8(%rbp)
jmp 0x6c3e
movl $0x30, %edi
callq 0x8740
movb %al, -0x2d9(%rbp)
jmp 0x6c50
movq -0x2d8(%rbp), %rdi
movb -0x2d9(%rbp), %al
movb %al, -0x1b9(%rbp)
movzbl -0x1b9(%rbp), %esi
callq 0x3430
movq %rax, -0x2e8(%rbp)
jmp 0x6c78
movq -0x2e8(%rbp), %rdi
movl -0x1b4(%rbp), %esi
incl %esi
callq 0x3460
movq %rax, -0x2f0(%rbp)
jmp 0x6c95
movq -0x2f0(%rbp), %rdi
movl $0x20, %esi
callq 0x3330
jmp 0x6ca8
jmp 0x6caa
movl -0x1b4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b4(%rbp)
jmp 0x6bc0
leaq -0x180(%rbp), %rdi
leaq 0x3523(%rip), %rsi      # 0xa1ef
callq 0x3280
movq %rax, -0x2f8(%rbp)
jmp 0x6cda
movq -0x2f8(%rbp), %rdi
movl $0x20, %esi
callq 0x3330
jmp 0x6ced
jmp 0x6d88
leaq -0x1e0(%rbp), %rdi
callq 0x33e0
movl $0x1, -0x1e4(%rbp)
movl -0x1e4(%rbp), %eax
cmpl -0x194(%rbp), %eax
jge 0x6d7c
movq -0x280(%rbp), %rdi
movl -0x1e4(%rbp), %esi
leaq -0x1e0(%rbp), %rdx
callq 0x9840
jmp 0x6d31
leaq -0x180(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x3230
jmp 0x6d46
jmp 0x6d48
movl -0x1e4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e4(%rbp)
jmp 0x6d08
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a0(%rbp)
movl %eax, -0x1a4(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x3170
jmp 0x709b
leaq -0x1e0(%rbp), %rdi
callq 0x3170
leaq -0x220(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x3270
jmp 0x6d9d
movq -0x280(%rbp), %rdi
callq 0x9bf0
movl %eax, -0x2fc(%rbp)
jmp 0x6db1
movl -0x2fc(%rbp), %edx
leaq -0x200(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0x76a0
jmp 0x6dcc
leaq -0x220(%rbp), %rdi
callq 0x3170
leaq -0x241(%rbp), %rdi
movq %rdi, -0x308(%rbp)
callq 0x3480
movq -0x308(%rbp), %rdx
leaq 0x32c3(%rip), %rsi      # 0xa0bc
leaq -0x240(%rbp), %rdi
callq 0x3750
jmp 0x6e07
leaq -0x190(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x3310
jmp 0x6e1c
leaq -0x240(%rbp), %rdi
callq 0x3170
leaq -0x241(%rbp), %rdi
callq 0x32e0
movl $0x0, -0x248(%rbp)
movslq -0x248(%rbp), %rax
movq %rax, -0x310(%rbp)
leaq -0x200(%rbp), %rdi
callq 0x5a60
movq %rax, %rcx
movq -0x310(%rbp), %rax
cmpq %rcx, %rax
jae 0x6f2d
leaq -0x180(%rbp), %rax
movq %rax, -0x318(%rbp)
movslq -0x248(%rbp), %rsi
leaq -0x200(%rbp), %rdi
callq 0x5a80
movq -0x318(%rbp), %rdi
movq %rax, %rsi
callq 0x3230
jmp 0x6e9d
jmp 0x6e9f
movl -0x248(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x248(%rbp)
jmp 0x6e3e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a0(%rbp)
movl %eax, -0x1a4(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x3170
jmp 0x709b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a0(%rbp)
movl %eax, -0x1a4(%rbp)
jmp 0x6f05
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a0(%rbp)
movl %eax, -0x1a4(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x3170
leaq -0x241(%rbp), %rdi
callq 0x32e0
jmp 0x708f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a0(%rbp)
movl %eax, -0x1a4(%rbp)
jmp 0x708f
leaq -0x270(%rbp), %rdi
callq 0x33e0
movl $0x0, -0x24c(%rbp)
movq -0x280(%rbp), %rdi
movl -0x24c(%rbp), %eax
movl %eax, -0x320(%rbp)
callq 0x9bd0
movl %eax, -0x31c(%rbp)
jmp 0x6f63
movl -0x320(%rbp), %ecx
movl -0x31c(%rbp), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x321(%rbp)
jge 0x6fc8
leaq -0x190(%rbp), %rdi
leaq -0x270(%rbp), %rsi
movl $0x20, %edx
callq 0x34a0
movq %rax, -0x330(%rbp)
jmp 0x6f9c
movq -0x330(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3380
movb %al, -0x331(%rbp)
jmp 0x6fba
movb -0x331(%rbp), %al
movb %al, -0x321(%rbp)
jmp 0x6fc8
movb -0x321(%rbp), %al
testb $0x1, %al
jne 0x6fd7
jmp 0x705d
movq -0x280(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x340(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x270(%rbp), %rdi
movl $0xa, %edx
callq 0x88d0
movl %eax, -0x338(%rbp)
jmp 0x7006
movq -0x340(%rbp), %rdi
movl -0x338(%rbp), %eax
movl %eax, -0x274(%rbp)
leaq -0x274(%rbp), %rsi
callq 0x88a0
jmp 0x7027
jmp 0x7029
movl -0x24c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24c(%rbp)
jmp 0x6f43
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a0(%rbp)
movl %eax, -0x1a4(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x3170
jmp 0x708f
leaq -0x270(%rbp), %rdi
callq 0x3170
leaq -0x200(%rbp), %rdi
callq 0x38d0
leaq -0x190(%rbp), %rdi
callq 0x31e0
movl $0x1, %eax
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq
leaq -0x200(%rbp), %rdi
callq 0x38d0
leaq -0x190(%rbp), %rdi
callq 0x31e0
movq -0x1a0(%rbp), %rdi
callq 0x3470
nopw %cs:(%rax,%rax)