// File: talyerushalmy[P]SimpleFileSystem/src/Commands.cpp
// Function: MkfileCommand::execute(FileSystem&)
void MkfileCommand::execute(FileSystem& fs)
{
	try
	{
		std::vector<std::string> arguments = StringTools::split(this->getArgs(), " ");

		if (arguments.size() != 2)
		{
			std::cout << "Usage: mkfile <path/filename> <size>" << std::endl;
			return;
		}
		for (std::string i : arguments)
		{
			if (StringTools::trim(i) == "")
			{
				std::cout << "Usage: mkfile <path/filename> <size>" << std::endl;
				return;
			}
		}

		unsigned int file_size = std::stoi(arguments[1].c_str());
		std::vector<std::string> path_parts = StringTools::split(arguments[0], "/");
		std::string file_name = path_parts.back();
		if (file_name == "")
		{
			std::cout << "File name not specified" << std::endl;
			return;
		}
		std::string path = arguments[0].substr(0, arguments[0].length() - file_name.length());
		Directory* dir = fs.getDirectoryFromPath(path) ? fs.getDirectoryFromPath(path) : &fs.getWorkingDirectory();
		if (!dir)
		{
			std::cout << "The system cannot find the path specified" << std::endl;
			return;
		}
		if (dir->childExists(file_name))
		{
			std::cout << "File already exists" << std::endl;
			return;
		}

		File* new_file = new File(file_name, file_size);
		dir->addFile(new_file);
	}
	catch (int e)
	{
		std::cout << "Usage: mkfile <path/filename> <size>" << std::endl;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x320, %rsp            # imm = 0x320
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x7c70
jmp 0x96f2
leaq -0x79(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x3310
movq -0x250(%rbp), %rdx
leaq 0xaa3b(%rip), %rsi      # 0x1414b
leaq -0x78(%rbp), %rdi
callq 0x3260
jmp 0x971b
leaq -0x28(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x3550
jmp 0x972e
leaq -0x78(%rbp), %rdi
callq 0x3130
leaq -0x79(%rbp), %rdi
callq 0x3200
leaq -0x48(%rbp), %rdi
callq 0x3130
leaq -0x28(%rbp), %rdi
callq 0x4020
cmpq $0x2, %rax
je 0x97f5
movq 0x12865(%rip), %rdi     # 0x1bfc8
leaq 0xaa83(%rip), %rsi      # 0x141ed
callq 0x31b0
movq %rax, -0x258(%rbp)
jmp 0x9778
movq -0x258(%rbp), %rdi
movq 0x12832(%rip), %rsi     # 0x1bfb8
callq 0x31e0
jmp 0x978d
movl $0x1, -0x80(%rbp)
jmp 0x9efc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x9f84
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x97cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x3130
leaq -0x79(%rbp), %rdi
callq 0x3200
leaq -0x48(%rbp), %rdi
callq 0x3130
jmp 0x9f84
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x9f7b
leaq -0x28(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
callq 0x3ef0
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rdi
callq 0x3d70
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xdb80
testb $0x1, %al
jne 0x9842
jmp 0x994d
leaq -0x90(%rbp), %rdi
callq 0xdbc0
movq %rax, %rsi
leaq -0xb8(%rbp), %rdi
callq 0x30e0
jmp 0x985f
leaq -0xd8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x36c0
jmp 0x9874
leaq 0xa8d1(%rip), %rsi      # 0x1414c
leaq -0xd8(%rbp), %rdi
callq 0xd980
movb %al, -0x259(%rbp)
jmp 0x988f
leaq -0xd8(%rbp), %rdi
callq 0x3130
movb -0x259(%rbp), %al
testb $0x1, %al
jne 0x98a7
jmp 0x9909
movq 0x1271a(%rip), %rdi     # 0x1bfc8
leaq 0xa938(%rip), %rsi      # 0x141ed
callq 0x31b0
movq %rax, -0x268(%rbp)
jmp 0x98c3
movq -0x268(%rbp), %rdi
movq 0x126e7(%rip), %rsi     # 0x1bfb8
callq 0x31e0
jmp 0x98d8
movl $0x1, -0x80(%rbp)
jmp 0x9910
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x993c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x3130
jmp 0x993c
movl $0x0, -0x80(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x3130
movl -0x80(%rbp), %eax
testl %eax, %eax
jne 0x9efc
jmp 0x9929
jmp 0x992b
leaq -0x90(%rbp), %rdi
callq 0xdbe0
jmp 0x9826
leaq -0xb8(%rbp), %rdi
callq 0x3130
jmp 0x9f7b
leaq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0xd9b0
movq %rax, %rdi
callq 0x30d0
movq %rax, -0x278(%rbp)
leaq -0x101(%rbp), %rdi
movq %rdi, -0x270(%rbp)
callq 0x3310
movq -0x278(%rbp), %rsi
movq -0x270(%rbp), %rdx
leaq -0x100(%rbp), %rdi
callq 0x3260
jmp 0x9999
xorl %eax, %eax
movl %eax, %esi
leaq -0x100(%rbp), %rdi
movl $0xa, %edx
callq 0xdc00
movl %eax, -0x27c(%rbp)
jmp 0x99b6
leaq -0x100(%rbp), %rdi
callq 0x3130
leaq -0x101(%rbp), %rdi
callq 0x3200
movl -0x27c(%rbp), %eax
movl %eax, -0xdc(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0xd9b0
movq %rax, %rsi
leaq -0x140(%rbp), %rdi
callq 0x30e0
jmp 0x99f8
leaq -0x161(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x3310
movq -0x288(%rbp), %rdx
leaq 0xa7c2(%rip), %rsi      # 0x141db
leaq -0x160(%rbp), %rdi
callq 0x3260
jmp 0x9a27
leaq -0x120(%rbp), %rdi
leaq -0x140(%rbp), %rsi
leaq -0x160(%rbp), %rdx
callq 0x3550
jmp 0x9a43
leaq -0x160(%rbp), %rdi
callq 0x3130
leaq -0x161(%rbp), %rdi
callq 0x3200
leaq -0x140(%rbp), %rdi
callq 0x3130
leaq -0x120(%rbp), %rdi
callq 0xda00
movq %rax, %rsi
leaq -0x188(%rbp), %rdi
callq 0x30e0
jmp 0x9a84
leaq 0xa6c1(%rip), %rsi      # 0x1414c
leaq -0x188(%rbp), %rdi
callq 0xd980
movb %al, -0x289(%rbp)
jmp 0x9a9f
movb -0x289(%rbp), %al
testb $0x1, %al
jne 0x9aae
jmp 0x9b87
movq 0x12513(%rip), %rdi     # 0x1bfc8
leaq 0xa756(%rip), %rsi      # 0x14212
callq 0x31b0
movq %rax, -0x298(%rbp)
jmp 0x9aca
movq -0x298(%rbp), %rdi
movq 0x124e0(%rip), %rsi     # 0x1bfb8
callq 0x31e0
jmp 0x9adf
movl $0x1, -0x80(%rbp)
jmp 0x9ee4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x9b11
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x3130
leaq -0x101(%rbp), %rdi
callq 0x3200
jmp 0x9f7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x9b48
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x3130
leaq -0x161(%rbp), %rdi
callq 0x3200
leaq -0x140(%rbp), %rdi
callq 0x3130
jmp 0x9f7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x9f6f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x9f63
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x2a0(%rbp)
leaq -0x28(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0xd9b0
movq -0x2b8(%rbp), %rdi
movq -0x2a0(%rbp), %rsi
movq %rax, -0x2a8(%rbp)
callq 0xd9b0
movq %rax, %rdi
callq 0x32a0
movq %rax, -0x2b0(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x32a0
movq -0x2b0(%rbp), %rcx
movq -0x2a8(%rbp), %rsi
movq -0x2a0(%rbp), %rdx
subq %rax, %rcx
leaq -0x1a8(%rbp), %rdi
callq 0x31d0
jmp 0x9bfd
movq -0x10(%rbp), %rax
movq %rax, -0x2c0(%rbp)
movb $0x0, -0x1f1(%rbp)
leaq -0x1d0(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x30e0
jmp 0x9c24
movq -0x2c0(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0xe1f0
movq %rax, -0x2c8(%rbp)
jmp 0x9c40
movq -0x2c8(%rbp), %rax
cmpq $0x0, %rax
je 0x9ca0
movq -0x10(%rbp), %rax
movq %rax, -0x2d0(%rbp)
leaq -0x1f0(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x30e0
jmp 0x9c6d
movq -0x2d0(%rbp), %rdi
movb $0x1, -0x1f1(%rbp)
leaq -0x1f0(%rbp), %rsi
callq 0xe1f0
movq %rax, -0x2d8(%rbp)
jmp 0x9c90
movq -0x2d8(%rbp), %rax
movq %rax, -0x2e0(%rbp)
jmp 0x9cc2
movq -0x10(%rbp), %rdi
callq 0xe1b0
movq %rax, -0x2e8(%rbp)
jmp 0x9cb2
movq -0x2e8(%rbp), %rax
movq %rax, -0x2e0(%rbp)
jmp 0x9cc2
movq -0x2e0(%rbp), %rax
movq %rax, -0x2f0(%rbp)
testb $0x1, -0x1f1(%rbp)
jne 0x9cdb
jmp 0x9ce7
leaq -0x1f0(%rbp), %rdi
callq 0x3130
leaq -0x1d0(%rbp), %rdi
callq 0x3130
movq -0x2f0(%rbp), %rax
movq %rax, -0x1b0(%rbp)
cmpq $0x0, -0x1b0(%rbp)
jne 0x9da1
movq 0x122b2(%rip), %rdi     # 0x1bfc8
leaq 0xa441(%rip), %rsi      # 0x1415e
callq 0x31b0
movq %rax, -0x2f8(%rbp)
jmp 0x9d2b
movq -0x2f8(%rbp), %rdi
movq 0x1227f(%rip), %rsi     # 0x1bfb8
callq 0x31e0
jmp 0x9d40
movl $0x1, -0x80(%rbp)
jmp 0x9ed8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x9f57
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x9d90
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
testb $0x1, -0x1f1(%rbp)
jne 0x9d82
jmp 0x9d8e
leaq -0x1f0(%rbp), %rdi
callq 0x3130
jmp 0x9d90
leaq -0x1d0(%rbp), %rdi
callq 0x3130
jmp 0x9f57
movq -0x1b0(%rbp), %rax
movq %rax, -0x300(%rbp)
leaq -0x218(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x30e0
jmp 0x9dc4
movq -0x300(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0xf6a0
movb %al, -0x301(%rbp)
jmp 0x9ddf
leaq -0x218(%rbp), %rdi
callq 0x3130
movb -0x301(%rbp), %al
testb $0x1, %al
jne 0x9df7
jmp 0x9e51
movq 0x121ca(%rip), %rdi     # 0x1bfc8
leaq 0xa425(%rip), %rsi      # 0x1422a
callq 0x31b0
movq %rax, -0x310(%rbp)
jmp 0x9e13
movq -0x310(%rbp), %rdi
movq 0x12197(%rip), %rsi     # 0x1bfb8
callq 0x31e0
jmp 0x9e28
movl $0x1, -0x80(%rbp)
jmp 0x9ed8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x3130
jmp 0x9f57
movl $0x30, %edi
callq 0x31c0
movq %rax, -0x318(%rbp)
jmp 0x9e64
movb $0x1, -0x241(%rbp)
leaq -0x240(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x30e0
jmp 0x9e80
movq -0x318(%rbp), %rdi
movl -0xdc(%rbp), %edx
leaq -0x240(%rbp), %rsi
callq 0xeb90
jmp 0x9e9b
movb $0x0, -0x241(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x3130
movq -0x318(%rbp), %rax
movq %rax, -0x220(%rbp)
movq -0x1b0(%rbp), %rdi
movq -0x220(%rbp), %rsi
callq 0xf5b0
jmp 0x9ed1
movl $0x0, -0x80(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x3130
leaq -0x188(%rbp), %rdi
callq 0x3130
leaq -0x120(%rbp), %rdi
callq 0x37e0
leaq -0x28(%rbp), %rdi
callq 0x37e0
movl -0x80(%rbp), %eax
testl %eax, %eax
je 0x9f13
jmp 0x9f0e
jmp 0x9fd7
jmp 0x9fd7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x9f3e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x3130
testb $0x1, -0x241(%rbp)
jne 0x9f49
jmp 0x9f55
movq -0x318(%rbp), %rdi
callq 0x31a0
jmp 0x9f57
leaq -0x1a8(%rbp), %rdi
callq 0x3130
leaq -0x188(%rbp), %rdi
callq 0x3130
leaq -0x120(%rbp), %rdi
callq 0x37e0
leaq -0x28(%rbp), %rdi
callq 0x37e0
movl -0x54(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x9ff1
movq -0x50(%rbp), %rdi
callq 0x30c0
movl (%rax), %eax
movl %eax, -0x248(%rbp)
movq 0x12020(%rip), %rdi     # 0x1bfc8
leaq 0xa23e(%rip), %rsi      # 0x141ed
callq 0x31b0
movq %rax, -0x320(%rbp)
jmp 0x9fbd
movq -0x320(%rbp), %rdi
movq 0x11fed(%rip), %rsi     # 0x1bfb8
callq 0x31e0
jmp 0x9fd2
callq 0x32e0
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
callq 0x32e0
movq -0x50(%rbp), %rdi
callq 0x3300
nopw (%rax,%rax)