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

	if (arguments.size() != 2)
	{
		std::cout << "Usage: mv <source-path/file-name> <destination-path>" << std::endl;
		return;
	}
	if (StringTools::trim(arguments[0]) == "" || StringTools::trim(arguments[1]) == "")
	{
		std::cout << "Usage: mv <source-path/file-name> <destination-path>" << std::endl;
		return;
	}

	std::string src_name = StringTools::split(StringTools::trim(arguments[0]), "/").back();
	std::string src_dir = StringTools::trim(arguments[0]).substr(0, arguments[0].length() - src_name.length());

	Directory* src = fs.getDirectoryFromPath(src_dir);
	if (StringTools::trim(src_dir) == "")
		src = &fs.getWorkingDirectory();
	Directory* dest = fs.getDirectoryFromPath(arguments[1]);
	if (StringTools::trim(arguments[1]) == "")
		dest = &fs.getWorkingDirectory();

	if (!src->childExists(src_name) || !dest)
	{
		std::cout << "No such file or directory" << std::endl;
		return;
	}

	BaseFile* bf = src->getChildByName(src_name);
	if (Directory* d = dynamic_cast<Directory*>(bf))
	{
		Directory* check_cwd_or_parents = &fs.getWorkingDirectory();
		while (check_cwd_or_parents->getParent() != NULL)
		{
			if (d == check_cwd_or_parents)
			{
				std::cout << "Can't move directory" << std::endl;
				return;
			}
			check_cwd_or_parents = check_cwd_or_parents->getParent();
		}
		Directory* new_d = new Directory(*d);
		dest->addFile(new_d);
	}
	else if (File* f = dynamic_cast<File*>(bf))
	{
		File* new_f = new File(*f);
		dest->addFile(new_f);
	}
	src->removeFile(src_name);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rsi, %rbx
leaq -0x198(%rbp), %r14
movq %r14, -0x10(%r14)
movq 0x28(%rdi), %rsi
movq 0x30(%rdi), %rdx
addq %rsi, %rdx
leaq -0x1a8(%rbp), %rdi
callq 0x3954
leaq -0x178(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x5f04(%rip), %rsi      # 0xe173
leaq 0x5efe(%rip), %rdx      # 0xe174
leaq -0x188(%rbp), %rdi
callq 0xabe4
leaq -0x68(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
leaq -0x188(%rbp), %rdx
callq 0x34ec
movq -0x188(%rbp), %rdi
cmpq %r15, %rdi
je 0x82aa
callq 0x31a0
movq -0x1a8(%rbp), %rdi
cmpq %r14, %rdi
je 0x82bb
callq 0x31a0
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rax
subq %rsi, %rax
cmpq $0x40, %rax
jne 0x8353
leaq -0x50(%rbp), %rdi
callq 0x35f2
leaq 0x5e94(%rip), %rsi      # 0xe174
leaq -0x50(%rbp), %rdi
callq 0x3080
movl %eax, %r14d
testl %eax, %eax
je 0x831f
movq -0x68(%rbp), %rsi
addq $0x20, %rsi
leaq -0x1e8(%rbp), %rdi
callq 0x35f2
leaq 0x5e69(%rip), %rsi      # 0xe174
leaq -0x1e8(%rbp), %rdi
callq 0x3080
testl %eax, %eax
sete %r15b
jmp 0x8322
movb $0x1, %r15b
testl %r14d, %r14d
je 0x833c
leaq -0x1d8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x833c
callq 0x31a0
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x834e
callq 0x31a0
testb %r15b, %r15b
je 0x83b4
movq 0xac76(%rip), %rbx      # 0x12fd0
leaq 0x5f4a(%rip), %rsi      # 0xe2ab
movl $0x34, %edx
movq %rbx, %rdi
callq 0x3200
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq 0xac44(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
leaq -0x68(%rbp), %rdi
callq 0x36b8
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x68(%rbp), %rsi
leaq -0x1c8(%rbp), %rdi
callq 0x35f2
leaq -0x158(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x5e2d(%rip), %rsi      # 0xe203
leaq 0x5e27(%rip), %rdx      # 0xe204
leaq -0x168(%rbp), %rdi
callq 0xabe4
leaq -0x88(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
leaq -0x168(%rbp), %rdx
callq 0x34ec
movq -0x80(%rbp), %rax
leaq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rcx
movq %rcx, (%rdi)
movq -0x20(%rax), %rsi
movq -0x18(%rax), %rdx
addq %rsi, %rdx
callq 0x3954
leaq -0x88(%rbp), %rdi
callq 0x36b8
movq -0x168(%rbp), %rdi
cmpq %r14, %rdi
je 0x843f
callq 0x31a0
leaq -0x1b8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8454
callq 0x31a0
movq -0x68(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x35f2
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rcx
subq -0x48(%rbp), %rcx
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
xorl %edx, %edx
callq 0x31d0
leaq -0x98(%rbp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x849a
callq 0x31a0
leaq -0x138(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
addq %rsi, %rdx
leaq -0x148(%rbp), %rdi
callq 0x3954
leaq -0x148(%rbp), %rsi
movq %rbx, %rdi
callq 0xad2e
movq %rax, -0x30(%rbp)
movq -0x148(%rbp), %rdi
cmpq %r15, %rdi
je 0x84e3
callq 0x31a0
leaq -0xa8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x35f2
leaq 0x5c77(%rip), %rsi      # 0xe174
leaq -0xa8(%rbp), %r12
movq %r12, %rdi
callq 0x3080
movl %eax, %r15d
movq (%r12), %rdi
cmpq %r14, %rdi
je 0x851d
callq 0x31a0
testl %r15d, %r15d
jne 0x852e
movq %rbx, %rdi
callq 0xad1a
movq %rax, -0x30(%rbp)
movq -0x68(%rbp), %rax
leaq -0x118(%rbp), %r12
movq %r12, -0x10(%r12)
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
addq %rsi, %rdx
leaq -0x128(%rbp), %rdi
callq 0x3954
leaq -0x128(%rbp), %rsi
movq %rbx, %rdi
callq 0xad2e
movq %rax, %r15
movq -0x128(%rbp), %rdi
cmpq %r12, %rdi
je 0x8578
callq 0x31a0
movq -0x68(%rbp), %rsi
addq $0x20, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x35f2
leaq 0x5be1(%rip), %rsi      # 0xe174
leaq -0xa8(%rbp), %r13
movq %r13, %rdi
callq 0x3080
movl %eax, %r12d
movq (%r13), %rdi
cmpq %r14, %rdi
je 0x85b3
callq 0x31a0
testl %r12d, %r12d
jne 0x85c3
movq %rbx, %rdi
callq 0xad1a
movq %rax, %r15
leaq -0xf8(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0x108(%rbp), %rdi
callq 0x3954
leaq -0x108(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0xbd50
testq %r15, %r15
setne %r12b
andb %al, %r12b
movq -0x108(%rbp), %rdi
cmpq %r14, %rdi
je 0x8610
callq 0x31a0
testb %r12b, %r12b
je 0x867d
leaq -0xd8(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0xe8(%rbp), %rdi
callq 0x3954
leaq -0xe8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0xc488
movq %rax, %r13
movq -0xe8(%rbp), %rdi
cmpq %r14, %rdi
je 0x865b
callq 0x31a0
testq %r13, %r13
je 0x86c8
leaq 0xa709(%rip), %rsi      # 0x12d70
leaq 0xa712(%rip), %rdx      # 0x12d80
movq %r13, %rdi
xorl %ecx, %ecx
callq 0x31f0
movq %rax, %r12
jmp 0x86cb
movq 0xa94c(%rip), %rbx      # 0x12fd0
leaq 0x5c06(%rip), %rsi      # 0xe291
movl $0x19, %edx
movq %rbx, %rdi
callq 0x3200
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq 0xa91a(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
jmp 0x8842
xorl %r12d, %r12d
testq %r12, %r12
je 0x86fd
movq %rbx, %rdi
callq 0xad1a
movq %rax, %r13
movq %r13, %rdi
callq 0xbc70
movq %rax, %rbx
testq %rax, %rax
je 0x8723
cmpq %r13, %r12
je 0x8748
movq %r13, %rdi
callq 0xbc70
movq %rax, %r13
jmp 0x86db
testq %r13, %r13
je 0x8799
leaq 0xa663(%rip), %rsi      # 0x12d70
leaq 0xa684(%rip), %rdx      # 0x12d98
movq %r13, %rdi
xorl %ecx, %ecx
callq 0x31f0
movq %rax, %rbx
jmp 0x879b
movl $0x48, %edi
callq 0x31c0
movq %rax, %r13
movq %rax, %rdi
movq %r12, %rsi
callq 0xb528
movq %r15, %rdi
movq %r13, %rsi
callq 0xbc84
jmp 0x878e
movq 0xa881(%rip), %r15      # 0x12fd0
leaq 0x5b8a(%rip), %rsi      # 0xe2e0
movl $0x14, %edx
movq %r15, %rdi
callq 0x3200
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq 0xa84f(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
testq %rbx, %rbx
jne 0x8842
jmp 0x87ff
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x87ff
movl $0x30, %edi
callq 0x31c0
movq %rax, %r12
leaq 0xa544(%rip), %rax      # 0x12cf8
addq $0x10, %rax
movq %rax, (%r12)
leaq 0x8(%r12), %rdi
movq %r12, %rax
addq $0x18, %rax
movq %rax, 0x8(%r12)
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
addq %rsi, %rdx
callq 0x3954
leaq 0xa53c(%rip), %rax      # 0x12d20
addq $0x10, %rax
movq %rax, (%r12)
movl 0x28(%rbx), %eax
movl %eax, 0x28(%r12)
movq %r15, %rdi
movq %r12, %rsi
callq 0xbc84
leaq -0xb8(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc8(%rbp), %rdi
callq 0x3954
leaq -0xc8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0xbdf8
movq -0xc8(%rbp), %rdi
cmpq %r14, %rdi
je 0x8842
callq 0x31a0
leaq -0x78(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8854
callq 0x31a0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x8399
callq 0x31a0
jmp 0x8399
movq %rax, %rbx
movq %r12, %rdi
jmp 0x88f0
movq %rax, %rbx
movq %r13, %rdi
jmp 0x88f0
jmp 0x8985
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
jmp 0x88b5
jmp 0x8985
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
jmp 0x88b5
jmp 0x8985
jmp 0x8985
movq %rax, %rbx
movq -0x108(%rbp), %rdi
cmpq %r14, %rdi
jne 0x88f0
jmp 0x8988
jmp 0x8985
movq %rax, %rbx
movq -0x128(%rbp), %rdi
cmpq %r12, %rdi
jne 0x88f0
jmp 0x8988
jmp 0x8985
movq %rax, %rbx
movq -0x148(%rbp), %rdi
cmpq %r15, %rdi
je 0x8988
callq 0x31a0
jmp 0x8988
movq %rax, %rbx
leaq -0x98(%rbp), %rax
jmp 0x898c
movq %rax, %rbx
jmp 0x899a
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x36b8
jmp 0x8925
movq %rax, %rbx
movq -0x168(%rbp), %rdi
cmpq %r14, %rdi
je 0x893b
callq 0x31a0
jmp 0x893b
movq %rax, %rbx
leaq -0x1b8(%rbp), %rax
jmp 0x894d
jmp 0x89ae
movq %rax, %rbx
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
jmp 0x89a2
jmp 0x8985
jmp 0x89ae
movq %rax, %rbx
movq -0x188(%rbp), %rdi
cmpq %r15, %rdi
je 0x8970
callq 0x31a0
jmp 0x8970
movq %rax, %rbx
movq -0x1a8(%rbp), %rdi
cmpq %r14, %rdi
je 0x89ba
callq 0x31a0
jmp 0x89ba
jmp 0x8985
movq %rax, %rbx
leaq -0x78(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x899a
callq 0x31a0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x89b1
callq 0x31a0
jmp 0x89b1
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x36b8
movq %rbx, %rdi
callq 0x32b0