// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rsi, -0x30(%rbp)
leaq 0x28(%rdi), %rsi
leaq -0x1a0(%rbp), %rdi
callq 0x3210
leaq 0x53b6(%rip), %rsi      # 0xb14b
leaq -0x180(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x30a0
leaq -0x68(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
leaq -0x180(%rbp), %rdx
callq 0x348c
leaq -0x180(%rbp), %rdi
callq 0x30c0
leaq -0x1a0(%rbp), %rdi
callq 0x30c0
movq -0x68(%rbp), %r14
movq -0x60(%rbp), %r13
movq %r13, %rax
subq %r14, %rax
cmpq $0x40, %rax
jne 0x5e3d
leaq -0x50(%rbp), %r15
leaq -0x88(%rbp), %r12
cmpq %r13, %r14
je 0x5e5d
movq %r15, %rdi
movq %r14, %rsi
callq 0x3210
movq %r12, %rdi
movq %r15, %rsi
callq 0x3574
movq %r12, %rdi
leaq 0x5334(%rip), %rsi      # 0xb14c
callq 0x8386
movl %eax, %ebx
movq %r12, %rdi
callq 0x30c0
testb %bl, %bl
jne 0x5f30
movq %r15, %rdi
callq 0x30c0
addq $0x20, %r14
jmp 0x5df3
movq 0xb184(%rip), %rdi      # 0x10fc8
leaq 0x53a2(%rip), %rsi      # 0xb1ed
callq 0x3180
movq %rax, %rdi
callq 0x30d0
jmp 0x60aa
movq -0x68(%rbp), %rax
movq 0x20(%rax), %rsi
leaq -0x50(%rbp), %rdi
leaq -0x88(%rbp), %rdx
callq 0x30a0
leaq -0x50(%rbp), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x83a3
movl %eax, %r14d
leaq -0x50(%rbp), %rdi
callq 0x30c0
movq -0x68(%rbp), %rsi
leaq -0x160(%rbp), %rdi
callq 0x3210
leaq 0x5335(%rip), %rsi      # 0xb1db
leaq -0x140(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x30a0
leaq -0xa0(%rbp), %rdi
leaq -0x160(%rbp), %rsi
leaq -0x140(%rbp), %rdx
callq 0x348c
leaq -0x140(%rbp), %rdi
callq 0x30c0
leaq -0x160(%rbp), %rdi
callq 0x30c0
movq -0x98(%rbp), %rsi
addq $-0x20, %rsi
leaq -0x50(%rbp), %rdi
callq 0x3210
leaq 0x5249(%rip), %rsi      # 0xb14c
leaq -0x50(%rbp), %rdi
callq 0x8386
testb %al, %al
je 0x5f59
movq 0xb0b1(%rip), %rdi      # 0x10fc8
leaq 0x52f4(%rip), %rsi      # 0xb212
callq 0x3180
movq %rax, %rdi
callq 0x30d0
jmp 0x6095
movq 0xb091(%rip), %rdi      # 0x10fc8
leaq 0x52af(%rip), %rsi      # 0xb1ed
callq 0x3180
movq %rax, %rdi
callq 0x30d0
leaq -0x50(%rbp), %rdi
callq 0x30c0
jmp 0x60aa
movq -0x68(%rbp), %rsi
movq 0x8(%rsi), %rcx
subq -0x48(%rbp), %rcx
leaq -0x88(%rbp), %rdi
xorl %edx, %edx
callq 0x31a0
leaq -0x120(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x3210
leaq -0x120(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x8590
testq %rax, %rax
je 0x5fcf
leaq -0x100(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x3210
leaq -0x100(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x8590
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
callq 0x30c0
jmp 0x5fdb
movq -0x30(%rbp), %rdi
callq 0x857c
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
callq 0x30c0
testq %rbx, %rbx
je 0x6028
leaq -0xe0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3210
leaq -0xe0(%rbp), %rsi
movq %rbx, %rdi
callq 0x90c2
movl %eax, %r15d
leaq -0xe0(%rbp), %rdi
callq 0x30c0
testb %r15b, %r15b
je 0x6045
leaq 0x5204(%rip), %rsi      # 0xb22a
jmp 0x602f
leaq 0x512f(%rip), %rsi      # 0xb15e
movq 0xaf92(%rip), %rdi      # 0x10fc8
callq 0x3180
movq %rax, %rdi
callq 0x30d0
jmp 0x6089
pushq $0x30
popq %rdi
callq 0x3190
movq %rax, %r15
leaq -0xc0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3210
leaq -0xc0(%rbp), %rsi
movq %r15, %rdi
movl %r14d, %edx
callq 0x8a34
leaq -0xc0(%rbp), %rdi
callq 0x30c0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9030
leaq -0x88(%rbp), %rdi
callq 0x30c0
leaq -0x50(%rbp), %rdi
callq 0x30c0
leaq -0xa0(%rbp), %rdi
callq 0x3614
leaq -0x68(%rbp), %rdi
callq 0x3614
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %rbx
movq %rax, %r14
leaq -0xc0(%rbp), %rdi
callq 0x30c0
jmp 0x60df
movq %rdx, %rbx
movq %rax, %r14
movq %r15, %rdi
callq 0x3170
jmp 0x6165
jmp 0x6112
jmp 0x615f
movq %rdx, %rbx
movq %rax, %r14
leaq -0xe0(%rbp), %rdi
jmp 0x611f
movq %rdx, %rbx
movq %rax, %r14
leaq -0x100(%rbp), %rdi
callq 0x30c0
jmp 0x6118
jmp 0x6126
movq %rdx, %rbx
movq %rax, %r14
leaq -0x120(%rbp), %rdi
callq 0x30c0
jmp 0x6165
movq %rdx, %rbx
movq %rax, %r14
jmp 0x6171
movq %rdx, %rbx
movq %rax, %r14
jmp 0x617a
movq %rdx, %rbx
movq %rax, %r14
leaq -0x140(%rbp), %rdi
callq 0x30c0
jmp 0x6150
movq %rdx, %rbx
movq %rax, %r14
leaq -0x160(%rbp), %rdi
jmp 0x61c6
jmp 0x61cd
jmp 0x61bc
jmp 0x61cd
movq %rdx, %rbx
movq %rax, %r14
leaq -0x88(%rbp), %rdi
callq 0x30c0
leaq -0x50(%rbp), %rdi
callq 0x30c0
leaq -0xa0(%rbp), %rdi
callq 0x3614
jmp 0x61d3
jmp 0x61bc
jmp 0x61cd
movq %rdx, %rbx
movq %rax, %r14
leaq -0x180(%rbp), %rdi
callq 0x30c0
jmp 0x61a6
movq %rdx, %rbx
movq %rax, %r14
leaq -0x1a0(%rbp), %rdi
callq 0x30c0
jmp 0x61dc
movq %rdx, %rbx
movq %rax, %r14
jmp 0x61dc
movq %rdx, %rbx
movq %rax, %r14
leaq -0x50(%rbp), %rdi
callq 0x30c0
jmp 0x61d3
movq %rdx, %rbx
movq %rax, %r14
leaq -0x68(%rbp), %rdi
callq 0x3614
cmpl $0x1, %ebx
jne 0x6216
movq %r14, %rdi
callq 0x30b0
movq 0xadd8(%rip), %rdi      # 0x10fc8
leaq 0x4ff6(%rip), %rsi      # 0xb1ed
callq 0x3180
movq %rax, %rdi
callq 0x30d0
callq 0x3270
jmp 0x60b3
movq %rax, %r14
callq 0x3270
movq %r14, %rdi
callq 0x3290