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

	if (arguments.size() != 1 || arguments[0] == "")
	{
		std::cout << "Usage: mkdir <path>" << std::endl;
		return;
	}

	if (fs.getDirectoryFromPath(arguments[0]))
	{
		std::cout << "The directory already exists" << std::endl;
		return;
	}

	Directory* cwd = &fs.getWorkingDirectory(); // push working directory

	if (arguments[0][0] == '/')
		fs.setWorkingDirectory(&fs.getRootDirectory());

	std::vector<std::string> names = StringTools::split(arguments[0], "/");
	uint16_t processed_names = 0;

	for (std::string name : names)
	{
		if (fs.getWorkingDirectory().childDirectoryExists(name))
		{
			CdCommand cd_command(name);
			cd_command.execute(fs);
			processed_names++;
		}
		else if (fs.getWorkingDirectory().childExists(name))
		{
			std::cout << "Invalid path" << std::endl;
			return;
		}
		else break;
	}

	for (size_t i = processed_names; i < names.size(); i++)
	{
		if (names[i] == ".")
			continue;
		if (names[i] == "..")
		{
			fs.setWorkingDirectory(fs.getDirectoryFromPath(".."));
		}
		else if (names[i] != "")
		{
			Directory* dir = new Directory(names[i], &fs.getWorkingDirectory());
			fs.getWorkingDirectory().addFile(dir);
			fs.setWorkingDirectory(dir);
		}
	}

	fs.setWorkingDirectory(cwd); // pop working directory
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rsi, %rbx
leaq -0x1c0(%rbp), %r14
movq %r14, -0x10(%r14)
movq 0x28(%rdi), %rsi
movq 0x30(%rdi), %rdx
addq %rsi, %rdx
leaq -0x1d0(%rbp), %rdi
callq 0x392c
leaq -0x1a0(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x7b90(%rip), %rsi      # 0xe173
leaq 0x7b8a(%rip), %rdx      # 0xe174
leaq -0x1b0(%rbp), %rdi
callq 0xab8a
leaq -0x80(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
leaq -0x1b0(%rbp), %rdx
callq 0x34ec
movq -0x1b0(%rbp), %rdi
cmpq %r15, %rdi
je 0x661e
callq 0x31a0
movq -0x1d0(%rbp), %rdi
cmpq %r14, %rdi
je 0x662f
callq 0x31a0
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rax
subq %rdi, %rax
movl $0x13, %r14d
leaq 0x7b8b(%rip), %r15      # 0xe1d2
cmpq $0x20, %rax
jne 0x66b7
leaq 0x7b20(%rip), %rsi      # 0xe174
callq 0x3080
testl %eax, %eax
je 0x66b7
movq -0x80(%rbp), %rax
leaq -0x180(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0x190(%rbp), %rdi
callq 0x392c
leaq -0x190(%rbp), %rsi
movq %rbx, %rdi
callq 0xacd6
movq %rax, %r14
movq -0x190(%rbp), %rdi
cmpq %r15, %rdi
je 0x66a5
callq 0x31a0
testq %r14, %r14
je 0x6712
movl $0x1c, %r14d
leaq 0x7b2f(%rip), %r15      # 0xe1e6
movq 0xc912(%rip), %rbx      # 0x12fd0
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x3200
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq 0xc8e6(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
leaq -0x80(%rbp), %rdi
callq 0x36b8
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0xacc2
movq %rax, %r12
movq -0x80(%rbp), %rax
movq (%rax), %rcx
cmpb $0x2f, (%rcx)
jne 0x6740
movq %rbx, %rdi
callq 0xacb8
movq %rbx, %rdi
movq %rax, %rsi
callq 0xaccc
movq -0x80(%rbp), %rax
leaq -0x160(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0x170(%rbp), %rdi
callq 0x392c
leaq -0x140(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x7a90(%rip), %rsi      # 0xe203
leaq 0x7a8a(%rip), %rdx      # 0xe204
leaq -0x150(%rbp), %rdi
callq 0xab8a
leaq -0x48(%rbp), %rdi
leaq -0x170(%rbp), %rsi
leaq -0x150(%rbp), %rdx
callq 0x34ec
movq -0x150(%rbp), %rdi
cmpq %r15, %rdi
je 0x67ae
callq 0x31a0
movq -0x170(%rbp), %rdi
cmpq %r14, %rdi
je 0x67bf
callq 0x31a0
movq %r12, -0x88(%rbp)
movq -0x48(%rbp), %r13
movq -0x40(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq %rax, %r13
je 0x69e8
movl $0x0, -0x2c(%rbp)
leaq -0xf0(%rbp), %r15
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rdi
callq 0x392c
movq %rbx, %rdi
callq 0xacc2
movq %rax, %r14
leaq -0x100(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
leaq -0x110(%rbp), %rdi
callq 0x392c
movq %r14, %rdi
leaq -0x110(%rbp), %rsi
callq 0xc362
movl %eax, %r14d
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x6862
callq 0x31a0
testb %r14b, %r14b
je 0x6908
leaq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x392c
leaq -0x218(%rbp), %rdi
movq %r15, %rsi
callq 0x59d6
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x68b3
callq 0x31a0
leaq -0x218(%rbp), %rdi
movq %rbx, %rsi
callq 0x5a4e
leaq 0xc137(%rip), %rax      # 0x12a00
movq %rax, -0x218(%rbp)
movq -0x1f0(%rbp), %rdi
leaq -0x1e0(%rbp), %rax
cmpq %rax, %rdi
je 0x68e8
callq 0x31a0
movq -0x210(%rbp), %rdi
leaq -0x200(%rbp), %rax
cmpq %rax, %rdi
je 0x6900
callq 0x31a0
incl -0x2c(%rbp)
jmp 0x69b4
movq %rbx, %rdi
callq 0xacc2
movq %rax, %r15
leaq -0xc0(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
leaq -0xd0(%rbp), %rdi
callq 0x392c
movq %r15, %rdi
leaq -0xd0(%rbp), %rsi
callq 0xbcda
movl %eax, %r15d
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x6962
callq 0x31a0
movb $0x1, %r12b
testb %r15b, %r15b
je 0x69b7
movl $0xc, %edx
movq 0xc65a(%rip), %rdi      # 0x12fd0
leaq 0x7888(%rip), %rsi      # 0xe205
callq 0x3200
movq 0xc647(%rip), %rcx      # 0x12fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq 0xc629(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
xorl %r12d, %r12d
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x69c9
callq 0x31a0
testb %r14b, %r14b
je 0x69f1
addq $0x20, %r13
cmpq -0x90(%rbp), %r13
leaq -0xf0(%rbp), %r15
jne 0x67ec
jmp 0x69fa
movl $0x0, -0x2c(%rbp)
jmp 0x69fa
testb %r12b, %r12b
je 0x6b7a
movzwl -0x2c(%rbp), %r15d
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rax
subq %rdi, %rax
sarq $0x5, %rax
cmpq %r15, %rax
jbe 0x6b6b
movl %r15d, %r12d
shll $0x5, %r12d
addq %r12, %rdi
leaq 0x77eb(%rip), %rsi      # 0xe213
callq 0x3080
testl %eax, %eax
je 0x6b4c
movq -0x48(%rbp), %rdi
addq %r12, %rdi
leaq 0x77cf(%rip), %r13      # 0xe212
movq %r13, %rsi
callq 0x3080
testl %eax, %eax
je 0x6af7
movq -0x48(%rbp), %rdi
addq %r12, %rdi
leaq 0x7713(%rip), %rsi      # 0xe174
callq 0x3080
testl %eax, %eax
je 0x6b4c
movl $0x48, %edi
callq 0x31c0
movq %rax, %r13
movq -0x48(%rbp), %rax
leaq -0xa0(%rbp), %rcx
movq %rcx, -0xb0(%rbp)
movq (%rax,%r12), %rsi
movq 0x8(%rax,%r12), %rdx
addq %rsi, %rdx
leaq -0xb0(%rbp), %rdi
callq 0x392c
movq %rbx, %rdi
callq 0xacc2
movq %r13, %rdi
leaq -0xb0(%rbp), %rsi
movq %rax, %rdx
callq 0xb3ee
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x6ad7
callq 0x31a0
movq %rbx, %rdi
callq 0xacc2
movq %rax, %rdi
movq %r13, %rsi
callq 0xbc0c
movq %rbx, %rdi
movq %r13, %rsi
callq 0xaccc
jmp 0x6b4c
leaq -0x120(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0x130(%rbp), %r14
movq %r14, %rdi
movq %r13, %rsi
leaq 0x76fb(%rip), %rdx      # 0xe214
callq 0xab8a
movq %rbx, %rdi
movq %r14, %rsi
callq 0xacd6
movq %rbx, %rdi
movq %rax, %rsi
callq 0xaccc
movq -0x130(%rbp), %rdi
leaq -0x120(%rbp), %rax
cmpq %rax, %rdi
je 0x6b4c
callq 0x31a0
incq %r15
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rax
subq %rdi, %rax
sarq $0x5, %rax
addq $0x20, %r12
cmpq %rax, %r15
jb 0x6a1e
movq %rbx, %rdi
movq -0x88(%rbp), %rsi
callq 0xaccc
leaq -0x48(%rbp), %rdi
callq 0x36b8
jmp 0x66f7
jmp 0x6cab
movq %rax, %rbx
movq -0x150(%rbp), %rdi
cmpq %r15, %rdi
je 0x6ba6
callq 0x31a0
jmp 0x6ba6
movq %rax, %rbx
movq -0x170(%rbp), %rdi
cmpq %r14, %rdi
jne 0x6bd4
jmp 0x6cd3
jmp 0x6cb0
jmp 0x6cb0
movq %rax, %rbx
movq -0x190(%rbp), %rdi
cmpq %r15, %rdi
je 0x6cd3
callq 0x31a0
jmp 0x6cd3
jmp 0x6cab
movq %rax, %rbx
jmp 0x6c5b
movq %rax, %rbx
leaq -0x218(%rbp), %rdi
callq 0x52ea
jmp 0x6cb8
movq %rax, %rbx
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
jmp 0x6c9f
jmp 0x6cb5
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
jmp 0x6c9f
movq %rax, %rbx
movq -0x130(%rbp), %rdi
leaq -0x120(%rbp), %rax
jmp 0x6cc0
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x6c5b
callq 0x31a0
movq %r13, %rdi
jmp 0x6cc5
movq %rax, %rbx
movq -0x1b0(%rbp), %rdi
cmpq %r15, %rdi
je 0x6c79
callq 0x31a0
jmp 0x6c79
movq %rax, %rbx
movq -0x1d0(%rbp), %rdi
cmpq %r14, %rdi
je 0x6cdc
callq 0x31a0
jmp 0x6cdc
jmp 0x6cab
movq %rax, %rbx
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x6cb8
callq 0x31a0
jmp 0x6cb8
movq %rax, %rbx
jmp 0x6cca
movq %rax, %rbx
jmp 0x6cd3
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x6cca
callq 0x31a0
leaq -0x48(%rbp), %rdi
callq 0x36b8
leaq -0x80(%rbp), %rdi
callq 0x36b8
movq %rbx, %rdi
callq 0x32b0