// File: emr4378[P]FAT-File-System/Shell.cpp
// Function: Shell::Shell(char*)
Shell::Shell(char *name) {
	char *dir = (char*)malloc(sizeof(char)*FILENAME_MAX);
	int fileSysUse = -1;
	string tempName;

	getcwd(dir, sizeof(char)*FILENAME_MAX);
	filePath = new string(dir);
	oldFilePath = new string(dir);
	fakeFilePath = new string();
	free(dir);

	fileSystem = new FileSys();

	if (name != NULL) {
		tempName = name;
		getAbsoluteFromRelativePath(tempName, &tempName);
		if (checkIfExists(tempName)) {
			fileSysUse = fileSystem->openFileSys(name);
		} else {
			fileSysUse = createFileSystem(name);
		}
	}
	
	if (fileSysUse == 0) {
		chdir("/");
		*fakeFilePath = "/";
		*fakeFilePath += name;
		*filePath = *fakeFilePath;
	}

	cout << "Shell Created" << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movl $0x1000, %edi           # imm = 0x1000
movq %rdi, -0xf0(%rbp)
callq 0x3400
movq %rax, -0x18(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
leaq -0x40(%rbp), %rdi
callq 0x3430
movq -0xf0(%rbp), %rsi
movq -0x18(%rbp), %rdi
callq 0x3150
movl $0x20, %edi
callq 0x32b0
movq %rax, -0xe8(%rbp)
jmp 0x8846
movb $0x1, -0x4e(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x4d(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x3540
movq -0xe8(%rbp), %rdi
movq -0x108(%rbp), %rsi
movq -0x100(%rbp), %rdx
callq 0x6e60
jmp 0x8881
movq -0xf8(%rbp), %rax
movq -0xe8(%rbp), %rcx
movb $0x0, -0x4e(%rbp)
movq %rcx, 0x8(%rax)
leaq -0x4d(%rbp), %rdi
callq 0x3300
movl $0x20, %edi
callq 0x32b0
movq %rax, -0x110(%rbp)
jmp 0x88b3
movb $0x1, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x120(%rbp)
leaq -0x4f(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x3540
movq -0x110(%rbp), %rdi
movq -0x120(%rbp), %rsi
movq -0x118(%rbp), %rdx
callq 0x6e60
jmp 0x88ee
movq -0xf8(%rbp), %rax
movq -0x110(%rbp), %rcx
movb $0x0, -0x50(%rbp)
movq %rcx, 0x10(%rax)
leaq -0x4f(%rbp), %rdi
callq 0x3300
movl $0x20, %edi
callq 0x32b0
movq %rax, -0x128(%rbp)
jmp 0x8920
movq -0x128(%rbp), %rdi
callq 0x3430
movq -0x128(%rbp), %rcx
movq -0xf8(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rdi
callq 0x3370
movl $0x60, %edi
callq 0x32b0
movq %rax, -0x130(%rbp)
jmp 0x8959
movq -0x130(%rbp), %rdi
xorl %esi, %esi
movl $0x60, %edx
callq 0x3170
movq -0x130(%rbp), %rdi
callq 0xb5e0
movq -0x130(%rbp), %rcx
movq -0xf8(%rbp), %rax
movq %rcx, 0x18(%rax)
cmpq $0x0, -0x10(%rbp)
je 0x8c3d
movq -0x10(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x3420
jmp 0x89a4
leaq -0x70(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3120
jmp 0x89b3
movq -0xf8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0x8cf0
jmp 0x89c9
leaq -0x70(%rbp), %rdi
callq 0x3180
leaq -0x90(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3120
jmp 0x89e4
movq -0xf8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x9210
movb %al, -0x131(%rbp)
jmp 0x89ff
leaq -0x90(%rbp), %rdi
callq 0x3180
movb -0x131(%rbp), %al
testb $0x1, %al
jne 0x8a1a
jmp 0x8b8c
movq -0xf8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x150(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x148(%rbp)
leaq -0xb1(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x3540
movq -0x148(%rbp), %rsi
movq -0x140(%rbp), %rdx
leaq -0xb0(%rbp), %rdi
callq 0x6e60
jmp 0x8a66
movq -0x150(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x38c0
movl %eax, -0x154(%rbp)
jmp 0x8a81
movl -0x154(%rbp), %eax
movl %eax, -0x1c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x3180
leaq -0xb1(%rbp), %rdi
callq 0x3300
jmp 0x8c3b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x8cdd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x4d(%rbp), %rdi
callq 0x3300
testb $0x1, -0x4e(%rbp)
jne 0x8ad5
jmp 0x8ae6
movq -0xe8(%rbp), %rdi
movl $0x20, %esi
callq 0x32c0
jmp 0x8cdd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x4f(%rbp), %rdi
callq 0x3300
testb $0x1, -0x50(%rbp)
jne 0x8b08
jmp 0x8b19
movq -0x110(%rbp), %rdi
movl $0x20, %esi
callq 0x32c0
jmp 0x8cdd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x3180
jmp 0x8cdd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x3180
jmp 0x8cdd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x8b7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x3180
leaq -0xb1(%rbp), %rdi
callq 0x3300
jmp 0x8cdd
movq -0x10(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0xd9(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x3540
movq -0x168(%rbp), %rsi
movq -0x160(%rbp), %rdx
leaq -0xd8(%rbp), %rdi
callq 0x6e60
jmp 0x8bc6
movq -0xf8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x9270
movl %eax, -0x16c(%rbp)
jmp 0x8be1
movl -0x16c(%rbp), %eax
movl %eax, -0x1c(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x3180
leaq -0xd9(%rbp), %rdi
callq 0x3300
jmp 0x8c3b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x8c2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x3180
leaq -0xd9(%rbp), %rdi
callq 0x3300
jmp 0x8cdd
jmp 0x8c3d
cmpl $0x0, -0x1c(%rbp)
jne 0x8c9a
leaq 0x34c2(%rip), %rdi      # 0xc10c
movq %rdi, -0x178(%rbp)
callq 0x3450
movq -0x178(%rbp), %rsi
movq -0xf8(%rbp), %rax
movq (%rax), %rdi
callq 0x3420
jmp 0x8c6e
movq -0xf8(%rbp), %rax
movq -0x10(%rbp), %rsi
movq (%rax), %rdi
callq 0x3280
jmp 0x8c83
movq -0xf8(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdi
callq 0x3050
jmp 0x8c98
jmp 0x8c9a
movq 0x732f(%rip), %rdi      # 0xffd0
leaq 0x3466(%rip), %rsi      # 0xc10e
callq 0x3290
movq %rax, -0x180(%rbp)
jmp 0x8cb6
movq -0x180(%rbp), %rdi
movq 0x72fc(%rip), %rsi      # 0xffc0
callq 0x32e0
jmp 0x8ccb
leaq -0x40(%rbp), %rdi
callq 0x3180
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x3180
movq -0x48(%rbp), %rdi
callq 0x3530
nop