// File: /workspace/github_cpp_makefile_star2_O1/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 0x3954
leaq -0x1a0(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x7b80(%rip), %rsi      # 0xe173
leaq 0x7b7a(%rip), %rdx      # 0xe174
leaq -0x1b0(%rbp), %rdi
callq 0xabe4
leaq -0x80(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
leaq -0x1b0(%rbp), %rdx
callq 0x34ec
movq -0x1b0(%rbp), %rdi
cmpq %r15, %rdi
je 0x662e
callq 0x31a0
movq -0x1d0(%rbp), %rdi
cmpq %r14, %rdi
je 0x663f
callq 0x31a0
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rax
subq %rdi, %rax
movl $0x13, %r14d
leaq 0x7b7b(%rip), %r15      # 0xe1d2
cmpq $0x20, %rax
jne 0x66c7
leaq 0x7b10(%rip), %rsi      # 0xe174
callq 0x3080
testl %eax, %eax
je 0x66c7
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 0x3954
leaq -0x190(%rbp), %rsi
movq %rbx, %rdi
callq 0xad2e
movq %rax, %r14
movq -0x190(%rbp), %rdi
cmpq %r15, %rdi
je 0x66b5
callq 0x31a0
testq %r14, %r14
je 0x6722
movl $0x1c, %r14d
leaq 0x7b1f(%rip), %r15      # 0xe1e6
movq 0xc902(%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 0xc8d6(%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 0xad1a
movq %rax, %r12
movq -0x80(%rbp), %rax
movq (%rax), %rax
cmpb $0x2f, (%rax)
jne 0x674c
movq %rbx, %rdi
callq 0xad10
movq %rbx, %rdi
movq %rax, %rsi
callq 0xad24
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 0x3954
leaq -0x140(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x7a80(%rip), %rsi      # 0xe203
leaq 0x7a7a(%rip), %rdx      # 0xe204
leaq -0x150(%rbp), %rdi
callq 0xabe4
leaq -0x48(%rbp), %rdi
leaq -0x170(%rbp), %rsi
leaq -0x150(%rbp), %rdx
callq 0x34ec
movq -0x150(%rbp), %rdi
cmpq %r15, %rdi
je 0x67be
callq 0x31a0
movq -0x170(%rbp), %rdi
cmpq %r14, %rdi
je 0x67cf
callq 0x31a0
movq %r12, -0x88(%rbp)
movq -0x48(%rbp), %r13
movq -0x40(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq %rax, %r13
je 0x6a0c
movl $0x0, -0x2c(%rbp)
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rdi
callq 0x3954
movq %rbx, %rdi
callq 0xad1a
movq %rax, %r14
leaq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
leaq -0xf0(%rbp), %rdi
callq 0x3954
movq %r14, %rdi
leaq -0xf0(%rbp), %rsi
callq 0xc3b2
movl %eax, %r14d
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
leaq -0x130(%rbp), %r15
je 0x6872
callq 0x31a0
testb %r14b, %r14b
je 0x691b
leaq -0x120(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x3954
leaq -0x218(%rbp), %rdi
movq %r15, %rsi
callq 0x59ea
movq -0x130(%rbp), %rdi
leaq -0x120(%rbp), %rax
cmpq %rax, %rdi
je 0x68c3
callq 0x31a0
leaq -0x218(%rbp), %rdi
movq %rbx, %rsi
callq 0x5a62
leaq 0xc127(%rip), %rax      # 0x12a00
movq %rax, -0x218(%rbp)
movq -0x1f0(%rbp), %rdi
leaq -0x1e0(%rbp), %rax
cmpq %rax, %rdi
je 0x68f8
callq 0x31a0
movq -0x210(%rbp), %rdi
leaq -0x200(%rbp), %rax
cmpq %rax, %rdi
je 0x6910
callq 0x31a0
incl -0x2c(%rbp)
xorl %r12d, %r12d
jmp 0x69d0
movq %rbx, %rdi
callq 0xad1a
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 0x3954
movq %r15, %rdi
leaq -0xd0(%rbp), %rsi
callq 0xbd50
movl %eax, %r15d
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x6975
callq 0x31a0
movl $0x2, %r12d
testb %r15b, %r15b
je 0x69d0
movl $0xc, %edx
movq 0xc644(%rip), %rdi      # 0x12fd0
leaq 0x7872(%rip), %rsi      # 0xe205
callq 0x3200
movq 0xc631(%rip), %rcx      # 0x12fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq 0xc613(%rip), %rdi      # 0x12fd0
callq 0x3030
movl $0x1, %r12d
movq %rax, %rdi
callq 0x3130
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x69e2
callq 0x31a0
testb %r14b, %r14b
je 0x69fe
addq $0x20, %r13
cmpq -0x90(%rbp), %r13
jne 0x67f5
movl $0x2, %r12d
cmpl $0x2, %r12d
sete %al
movzwl -0x2c(%rbp), %r15d
jmp 0x6a11
movb $0x1, %al
xorl %r15d, %r15d
testb %al, %al
je 0x6b94
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rax
subq %rdi, %rax
sarq $0x5, %rax
cmpq %r15, %rax
jbe 0x6b85
movl %r15d, %r12d
shll $0x5, %r12d
addq %r12, %rdi
leaq 0x77d1(%rip), %rsi      # 0xe213
callq 0x3080
testl %eax, %eax
je 0x6b66
movq -0x48(%rbp), %rdi
addq %r12, %rdi
leaq 0x77b5(%rip), %r13      # 0xe212
movq %r13, %rsi
callq 0x3080
testl %eax, %eax
je 0x6b11
movq -0x48(%rbp), %rdi
addq %r12, %rdi
leaq 0x76f9(%rip), %rsi      # 0xe174
callq 0x3080
testl %eax, %eax
je 0x6b66
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 0x3954
movq %rbx, %rdi
callq 0xad1a
movq %r13, %rdi
leaq -0xb0(%rbp), %rsi
movq %rax, %rdx
callq 0xb47a
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x6af1
callq 0x31a0
movq %rbx, %rdi
callq 0xad1a
movq %rax, %rdi
movq %r13, %rsi
callq 0xbc84
movq %rbx, %rdi
movq %r13, %rsi
callq 0xad24
jmp 0x6b66
leaq -0x100(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq -0x110(%rbp), %r14
movq %r14, %rdi
movq %r13, %rsi
leaq 0x76e1(%rip), %rdx      # 0xe214
callq 0xabe4
movq %rbx, %rdi
movq %r14, %rsi
callq 0xad2e
movq %rbx, %rdi
movq %rax, %rsi
callq 0xad24
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x6b66
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 0x6a38
movq %rbx, %rdi
movq -0x88(%rbp), %rsi
callq 0xad24
leaq -0x48(%rbp), %rdi
callq 0x36b8
jmp 0x6707
jmp 0x6ca5
movq %rax, %rbx
movq -0x150(%rbp), %rdi
cmpq %r15, %rdi
je 0x6bc0
callq 0x31a0
jmp 0x6bc0
movq %rax, %rbx
movq -0x170(%rbp), %rdi
cmpq %r14, %rdi
jne 0x6bf8
jmp 0x6cea
jmp 0x6cc7
jmp 0x6ca5
movq %rax, %rbx
jmp 0x6c33
jmp 0x6cc7
movq %rax, %rbx
movq -0x190(%rbp), %rdi
cmpq %r15, %rdi
je 0x6cea
callq 0x31a0
jmp 0x6cea
movq %rax, %rbx
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
jmp 0x6cd7
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x6c33
callq 0x31a0
movq %r13, %rdi
jmp 0x6cdc
movq %rax, %rbx
leaq -0x218(%rbp), %rdi
callq 0x530e
jmp 0x6ccf
movq %rax, %rbx
movq -0x130(%rbp), %rdi
leaq -0x120(%rbp), %rax
jmp 0x6cbb
jmp 0x6ccc
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
jmp 0x6cbb
jmp 0x6ca5
movq %rax, %rbx
movq -0x1b0(%rbp), %rdi
cmpq %r15, %rdi
je 0x6c92
callq 0x31a0
jmp 0x6c92
movq %rax, %rbx
movq -0x1d0(%rbp), %rdi
cmpq %r14, %rdi
je 0x6cf3
callq 0x31a0
jmp 0x6cf3
movq %rax, %rbx
jmp 0x6ce1
movq %rax, %rbx
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x6ccf
callq 0x31a0
jmp 0x6ccf
movq %rax, %rbx
jmp 0x6cea
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x6ce1
callq 0x31a0
leaq -0x48(%rbp), %rdi
callq 0x36b8
leaq -0x80(%rbp), %rdi
callq 0x36b8
movq %rbx, %rdi
callq 0x32b0
nop