// File: 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
subq $0x330, %rsp            # imm = 0x330
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x7c70
leaq -0x69(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x3310
movq -0x250(%rbp), %rdx
leaq 0xb55d(%rip), %rsi      # 0x1414b
leaq -0x68(%rbp), %rdi
callq 0x3260
jmp 0x8bf9
leaq -0x28(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x3550
jmp 0x8c0c
leaq -0x68(%rbp), %rdi
callq 0x3130
leaq -0x69(%rbp), %rdi
callq 0x3200
leaq -0x48(%rbp), %rdi
callq 0x3130
leaq -0x28(%rbp), %rdi
callq 0x4020
cmpq $0x1, %rax
jne 0x8c69
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0xd9b0
movq %rax, %rdi
leaq 0xb4ff(%rip), %rsi      # 0x1414c
callq 0xd980
movb %al, -0x251(%rbp)
jmp 0x8c5a
movb -0x251(%rbp), %al
testb $0x1, %al
jne 0x8c69
jmp 0x8cf1
movq 0x13358(%rip), %rdi     # 0x1bfc8
leaq 0xb533(%rip), %rsi      # 0x141aa
callq 0x31b0
movq %rax, -0x260(%rbp)
jmp 0x8c85
movq -0x260(%rbp), %rdi
movq 0x13325(%rip), %rsi     # 0x1bfb8
callq 0x31e0
jmp 0x8c9a
movl $0x1, -0x80(%rbp)
jmp 0x94bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x8cc9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3130
leaq -0x69(%rbp), %rdi
callq 0x3200
leaq -0x48(%rbp), %rdi
callq 0x3130
jmp 0x94e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x94db
movq -0x10(%rbp), %rax
movq %rax, -0x268(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0xd9b0
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x30e0
jmp 0x8d1a
movq -0x268(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0xe1f0
movq %rax, -0x270(%rbp)
jmp 0x8d36
leaq -0xa0(%rbp), %rdi
callq 0x3130
movq -0x270(%rbp), %rax
cmpq $0x0, %rax
je 0x8da9
movq 0x13272(%rip), %rdi     # 0x1bfc8
leaq 0xb461(%rip), %rsi      # 0x141be
callq 0x31b0
movq %rax, -0x278(%rbp)
jmp 0x8d6b
movq -0x278(%rbp), %rdi
movq 0x1323f(%rip), %rsi     # 0x1bfb8
callq 0x31e0
jmp 0x8d80
movl $0x1, -0x80(%rbp)
jmp 0x94bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x3130
jmp 0x94db
movq -0x10(%rbp), %rdi
callq 0xe1b0
movq %rax, -0x280(%rbp)
jmp 0x8dbb
movq -0x280(%rbp), %rax
movq %rax, -0xa8(%rbp)
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x290(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xd9b0
movq -0x290(%rbp), %rsi
movq %rax, %rdi
callq 0x3330
movq %rax, -0x288(%rbp)
jmp 0x8df5
movq -0x288(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x8e34
movq -0x10(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0xe190
movq %rax, -0x298(%rbp)
jmp 0x8e1d
movq -0x298(%rbp), %rsi
movq -0x2a0(%rbp), %rdi
callq 0xe1d0
jmp 0x8e32
jmp 0x8e34
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0xd9b0
movq %rax, %rsi
leaq -0xe0(%rbp), %rdi
callq 0x30e0
jmp 0x8e52
leaq -0x101(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x3310
movq -0x2a8(%rbp), %rdx
leaq 0xb368(%rip), %rsi      # 0x141db
leaq -0x100(%rbp), %rdi
callq 0x3260
jmp 0x8e81
leaq -0xc0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
leaq -0x100(%rbp), %rdx
callq 0x3550
jmp 0x8e9d
leaq -0x100(%rbp), %rdi
callq 0x3130
leaq -0x101(%rbp), %rdi
callq 0x3200
leaq -0xe0(%rbp), %rdi
callq 0x3130
movw $0x0, -0x104(%rbp)
leaq -0xc0(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x110(%rbp), %rdi
callq 0x3ef0
movq %rax, -0x118(%rbp)
movq -0x110(%rbp), %rdi
callq 0x3d70
movq %rax, -0x120(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0xdb80
testb $0x1, %al
jne 0x8f1a
jmp 0x91c8
leaq -0x118(%rbp), %rdi
callq 0xdbc0
movq %rax, %rsi
leaq -0x140(%rbp), %rdi
callq 0x30e0
jmp 0x8f37
movq -0x10(%rbp), %rdi
callq 0xe1b0
movq %rax, -0x2b0(%rbp)
jmp 0x8f49
leaq -0x160(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x30e0
jmp 0x8f5e
movq -0x2b0(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0xfca0
movb %al, -0x2b1(%rbp)
jmp 0x8f79
leaq -0x160(%rbp), %rdi
callq 0x3130
movb -0x2b1(%rbp), %al
testb $0x1, %al
jne 0x8f94
jmp 0x90bb
leaq -0x1c8(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x30e0
jmp 0x8fa9
leaq -0x1a8(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0x7f00
jmp 0x8fbe
leaq -0x1c8(%rbp), %rdi
callq 0x3130
movq -0x10(%rbp), %rsi
leaq -0x1a8(%rbp), %rdi
callq 0x7f80
jmp 0x8fdc
movw -0x104(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x104(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x5de0
jmp 0x9172
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x9025
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x3130
leaq -0x101(%rbp), %rdi
callq 0x3200
leaq -0xe0(%rbp), %rdi
callq 0x3130
jmp 0x94db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x94cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x91b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x3130
jmp 0x91b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x3130
jmp 0x91b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x5de0
jmp 0x91b7
movq -0x10(%rbp), %rdi
callq 0xe1b0
movq %rax, -0x2c0(%rbp)
jmp 0x90cd
leaq -0x1e8(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x30e0
jmp 0x90e2
movq -0x2c0(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0xf6a0
movb %al, -0x2c1(%rbp)
jmp 0x90fd
leaq -0x1e8(%rbp), %rdi
callq 0x3130
movb -0x2c1(%rbp), %al
testb $0x1, %al
jne 0x9115
jmp 0x9169
movq 0x12eac(%rip), %rdi     # 0x1bfc8
leaq 0xb0ba(%rip), %rsi      # 0x141dd
callq 0x31b0
movq %rax, -0x2d0(%rbp)
jmp 0x9131
movq -0x2d0(%rbp), %rdi
movq 0x12e79(%rip), %rsi     # 0x1bfb8
callq 0x31e0
jmp 0x9146
movl $0x1, -0x80(%rbp)
jmp 0x9179
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0x3130
jmp 0x91b7
movl $0x2, -0x80(%rbp)
jmp 0x9179
movl $0x0, -0x80(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x3130
movl -0x80(%rbp), %eax
movl %eax, -0x2d4(%rbp)
testl %eax, %eax
je 0x91a4
jmp 0x9194
movl -0x2d4(%rbp), %eax
subl $0x2, %eax
je 0x91c8
jmp 0x94b1
jmp 0x91a6
leaq -0x118(%rbp), %rdi
callq 0xdbe0
jmp 0x8efe
leaq -0x140(%rbp), %rdi
callq 0x3130
jmp 0x94cf
movzwl -0x104(%rbp), %eax
movq %rax, -0x1f0(%rbp)
movq -0x1f0(%rbp), %rax
movq %rax, -0x2e0(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x4020
movq %rax, %rcx
movq -0x2e0(%rbp), %rax
cmpq %rcx, %rax
jae 0x9498
movq -0x1f0(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0xd9b0
movq %rax, %rdi
leaq 0xafcb(%rip), %rsi      # 0x141eb
callq 0xd980
movb %al, -0x2e1(%rbp)
jmp 0x922d
movb -0x2e1(%rbp), %al
testb $0x1, %al
jne 0x9239
jmp 0x923e
jmp 0x9481
movq -0x1f0(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0xd9b0
movq %rax, %rdi
leaq 0xaf8f(%rip), %rsi      # 0x141ea
callq 0xd980
movb %al, -0x2e2(%rbp)
jmp 0x9268
movb -0x2e2(%rbp), %al
testb $0x1, %al
jne 0x9277
jmp 0x933d
movq -0x10(%rbp), %rax
movq %rax, -0x300(%rbp)
movq %rax, -0x2f8(%rbp)
leaq -0x211(%rbp), %rdi
movq %rdi, -0x2f0(%rbp)
callq 0x3310
movq -0x2f0(%rbp), %rdx
leaq 0xaf40(%rip), %rsi      # 0x141ea
leaq -0x210(%rbp), %rdi
callq 0x3260
jmp 0x92b8
movq -0x300(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0xe1f0
movq %rax, -0x308(%rbp)
jmp 0x92d4
movq -0x308(%rbp), %rsi
movq -0x2f8(%rbp), %rdi
callq 0xe1d0
jmp 0x92e9
leaq -0x210(%rbp), %rdi
callq 0x3130
leaq -0x211(%rbp), %rdi
callq 0x3200
jmp 0x947f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x932c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x3130
leaq -0x211(%rbp), %rdi
callq 0x3200
jmp 0x94cf
movq -0x1f0(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0xd9b0
movq %rax, %rdi
leaq 0xadf2(%rip), %rsi      # 0x1414c
callq 0xd9d0
movb %al, -0x309(%rbp)
jmp 0x9367
movb -0x309(%rbp), %al
testb $0x1, %al
jne 0x9376
jmp 0x947d
movl $0x48, %edi
callq 0x31c0
movq %rax, -0x318(%rbp)
jmp 0x9389
movb $0x1, -0x241(%rbp)
movq -0x1f0(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0xd9b0
movq %rax, %rsi
leaq -0x240(%rbp), %rdi
callq 0x30e0
jmp 0x93b4
movq -0x10(%rbp), %rdi
callq 0xe1b0
movq %rax, -0x320(%rbp)
jmp 0x93c6
movq -0x320(%rbp), %rdx
movq -0x318(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0xec30
jmp 0x93e2
movb $0x0, -0x241(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x3130
movq -0x318(%rbp), %rax
movq %rax, -0x220(%rbp)
movq -0x10(%rbp), %rdi
callq 0xe1b0
movq %rax, -0x328(%rbp)
jmp 0x9415
movq -0x328(%rbp), %rdi
movq -0x220(%rbp), %rsi
callq 0xf5b0
jmp 0x942a
movq -0x10(%rbp), %rdi
movq -0x220(%rbp), %rsi
callq 0xe1d0
jmp 0x943c
jmp 0x947d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x9464
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x3130
testb $0x1, -0x241(%rbp)
jne 0x946f
jmp 0x947b
movq -0x318(%rbp), %rdi
callq 0x31a0
jmp 0x94cf
jmp 0x947f
jmp 0x9481
movq -0x1f0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1f0(%rbp)
jmp 0x91d6
movq -0x10(%rbp), %rdi
movq -0xa8(%rbp), %rsi
callq 0xe1d0
jmp 0x94aa
movl $0x0, -0x80(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x37e0
leaq -0x28(%rbp), %rdi
callq 0x37e0
addq $0x330, %rsp            # imm = 0x330
popq %rbp
retq
leaq -0xc0(%rbp), %rdi
callq 0x37e0
leaq -0x28(%rbp), %rdi
callq 0x37e0
movq -0x78(%rbp), %rdi
callq 0x3300
nopl (%rax)