// File: /workspace/github_cpp_makefile_star2_O3/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 $0x1a8, %rsp            # imm = 0x1A8
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 0x392c
leaq -0x178(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x5f28(%rip), %rsi      # 0xe173
leaq 0x5f22(%rip), %rdx      # 0xe174
leaq -0x188(%rbp), %rdi
callq 0xab8a
leaq -0x68(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
leaq -0x188(%rbp), %rdx
callq 0x34ec
movq -0x188(%rbp), %rdi
cmpq %r15, %rdi
je 0x8286
callq 0x31a0
movq -0x1a8(%rbp), %rdi
cmpq %r14, %rdi
je 0x8297
callq 0x31a0
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rax
subq %rsi, %rax
cmpq $0x40, %rax
jne 0x8322
leaq -0x50(%rbp), %rdi
callq 0x35f2
leaq 0x5ebc(%rip), %rsi      # 0xe174
leaq -0x50(%rbp), %rdi
callq 0x3080
testl %eax, %eax
je 0x8308
movq -0x68(%rbp), %rsi
addq $0x20, %rsi
leaq -0x88(%rbp), %rdi
callq 0x35f2
leaq 0x5e94(%rip), %rsi      # 0xe174
leaq -0x88(%rbp), %r14
movq %r14, %rdi
callq 0x3080
testl %eax, %eax
sete %r15b
movq (%r14), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x830b
callq 0x31a0
jmp 0x830b
movb $0x1, %r15b
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x831d
callq 0x31a0
testb %r15b, %r15b
je 0x8383
movq 0xaca7(%rip), %rbx      # 0x12fd0
leaq 0x5f7b(%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 0xac75(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
leaq -0x68(%rbp), %rdi
callq 0x36b8
addq $0x1a8, %rsp            # imm = 0x1A8
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 0x5e5e(%rip), %rsi      # 0xe203
leaq 0x5e58(%rip), %rdx      # 0xe204
leaq -0x168(%rbp), %rdi
callq 0xab8a
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 0x392c
leaq -0x88(%rbp), %rdi
callq 0x36b8
movq -0x168(%rbp), %rdi
cmpq %r14, %rdi
je 0x840e
callq 0x31a0
leaq -0x1b8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8423
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 0x8469
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 0x392c
leaq -0x148(%rbp), %rsi
movq %rbx, %rdi
callq 0xacd6
movq %rax, -0x30(%rbp)
movq -0x148(%rbp), %rdi
cmpq %r15, %rdi
je 0x84b2
callq 0x31a0
leaq -0xa8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x35f2
leaq 0x5ca8(%rip), %rsi      # 0xe174
leaq -0xa8(%rbp), %r12
movq %r12, %rdi
callq 0x3080
movl %eax, %r15d
movq (%r12), %rdi
cmpq %r14, %rdi
je 0x84ec
callq 0x31a0
testl %r15d, %r15d
jne 0x84fd
movq %rbx, %rdi
callq 0xacc2
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 0x392c
leaq -0x128(%rbp), %rsi
movq %rbx, %rdi
callq 0xacd6
movq %rax, %r15
movq -0x128(%rbp), %rdi
cmpq %r12, %rdi
je 0x8547
callq 0x31a0
movq -0x68(%rbp), %rsi
addq $0x20, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x35f2
leaq 0x5c12(%rip), %rsi      # 0xe174
leaq -0xa8(%rbp), %r13
movq %r13, %rdi
callq 0x3080
movl %eax, %r12d
movq (%r13), %rdi
cmpq %r14, %rdi
je 0x8582
callq 0x31a0
testl %r12d, %r12d
jne 0x8592
movq %rbx, %rdi
callq 0xacc2
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 0x392c
leaq -0x108(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0xbcda
testq %r15, %r15
setne %r12b
andb %al, %r12b
movq -0x108(%rbp), %rdi
cmpq %r14, %rdi
je 0x85df
callq 0x31a0
testb %r12b, %r12b
je 0x868d
leaq -0xd8(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0xe8(%rbp), %rdi
callq 0x392c
leaq -0xe8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0xc41c
movq %rax, %r13
movq -0xe8(%rbp), %rdi
cmpq %r14, %rdi
je 0x862e
callq 0x31a0
testq %r13, %r13
je 0x8780
leaq 0xa732(%rip), %rsi      # 0x12d70
leaq 0xa73b(%rip), %rdx      # 0x12d80
movq %r13, %rdi
xorl %ecx, %ecx
callq 0x31f0
testq %rax, %rax
je 0x86d8
movq %rax, %r12
movq %rbx, %rdi
callq 0xacc2
movq %rax, %rbx
movq %rbx, %rdi
callq 0xbbf8
testq %rax, %rax
je 0x875d
cmpq %rbx, %r12
je 0x87c5
movq %rbx, %rdi
callq 0xbbf8
movq %rax, %rbx
jmp 0x8666
movq 0xa93c(%rip), %rbx      # 0x12fd0
leaq 0x5bf6(%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 0xa90a(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
jmp 0x880b
leaq 0xa691(%rip), %rsi      # 0x12d70
leaq 0xa6b2(%rip), %rdx      # 0x12d98
movq %r13, %rdi
xorl %ecx, %ecx
callq 0x31f0
testq %rax, %rax
je 0x8780
movq %rax, %rbx
movl $0x30, %edi
callq 0x31c0
movq %rax, %r12
leaq 0xa5e8(%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 0x392c
leaq 0xa5e0(%rip), %rax      # 0x12d20
addq $0x10, %rax
movq %rax, (%r12)
movl 0x28(%rbx), %eax
movl %eax, 0x28(%r12)
movq %r15, %rdi
movq %r12, %rsi
callq 0xbc0c
jmp 0x8780
movl $0x48, %edi
callq 0x31c0
movq %rax, %r13
movq %rax, %rdi
movq %r12, %rsi
callq 0xb49c
movq %r15, %rdi
movq %r13, %rsi
callq 0xbc0c
leaq -0xb8(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc8(%rbp), %rdi
callq 0x392c
leaq -0xc8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0xbd8c
movq -0xc8(%rbp), %rdi
cmpq %r14, %rdi
je 0x880b
callq 0x31a0
jmp 0x880b
movq 0xa804(%rip), %rbx      # 0x12fd0
leaq 0x5b0d(%rip), %rsi      # 0xe2e0
movl $0x14, %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 0xa7d2(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
leaq -0x78(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x881d
callq 0x31a0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x8368
callq 0x31a0
jmp 0x8368
movq %rax, %rbx
movq %r12, %rdi
jmp 0x88b9
movq %rax, %rbx
movq %r13, %rdi
jmp 0x88b9
jmp 0x894e
jmp 0x894e
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
jmp 0x887e
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
jmp 0x887e
jmp 0x894e
jmp 0x894e
movq %rax, %rbx
movq -0x108(%rbp), %rdi
cmpq %r14, %rdi
jne 0x88b9
jmp 0x8951
jmp 0x894e
movq %rax, %rbx
movq -0x128(%rbp), %rdi
cmpq %r12, %rdi
jne 0x88b9
jmp 0x8951
jmp 0x894e
movq %rax, %rbx
movq -0x148(%rbp), %rdi
cmpq %r15, %rdi
je 0x8951
callq 0x31a0
jmp 0x8951
movq %rax, %rbx
leaq -0x98(%rbp), %rax
jmp 0x8955
movq %rax, %rbx
jmp 0x8963
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x36b8
jmp 0x88ee
movq %rax, %rbx
movq -0x168(%rbp), %rdi
cmpq %r14, %rdi
je 0x8904
callq 0x31a0
jmp 0x8904
movq %rax, %rbx
leaq -0x1b8(%rbp), %rax
jmp 0x8916
jmp 0x8977
movq %rax, %rbx
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
jmp 0x896b
jmp 0x894e
jmp 0x8977
movq %rax, %rbx
movq -0x188(%rbp), %rdi
cmpq %r15, %rdi
je 0x8939
callq 0x31a0
jmp 0x8939
movq %rax, %rbx
movq -0x1a8(%rbp), %rdi
cmpq %r14, %rdi
je 0x8983
callq 0x31a0
jmp 0x8983
jmp 0x894e
movq %rax, %rbx
leaq -0x78(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8963
callq 0x31a0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x897a
callq 0x31a0
jmp 0x897a
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x36b8
movq %rbx, %rdi
callq 0x32b0
nop