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

	if (arguments.size() != 2)
	{
		std::cout << "Usage: cp <source-path> <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* 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);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rsi, %rbx
leaq -0x170(%rbp), %r14
movq %r14, -0x10(%r14)
movq 0x28(%rdi), %rsi
movq 0x30(%rdi), %rdx
addq %rsi, %rdx
leaq -0x180(%rbp), %rdi
callq 0x392c
leaq -0x150(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x67bc(%rip), %rsi      # 0xe173
leaq 0x67b6(%rip), %rdx      # 0xe174
leaq -0x160(%rbp), %rdi
callq 0xab8a
leaq -0x40(%rbp), %rdi
leaq -0x180(%rbp), %rsi
leaq -0x160(%rbp), %rdx
callq 0x34ec
movq -0x160(%rbp), %rdi
cmpq %r15, %rdi
je 0x79f2
callq 0x31a0
movq -0x180(%rbp), %rdi
cmpq %r14, %rdi
je 0x7a03
callq 0x31a0
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
subq %rsi, %rax
cmpq $0x40, %rax
jne 0x7c1e
leaq -0x1a0(%rbp), %rdi
callq 0x35f2
leaq -0x130(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x67cd(%rip), %rsi      # 0xe203
leaq 0x67c7(%rip), %rdx      # 0xe204
leaq -0x140(%rbp), %rdi
callq 0xab8a
leaq -0xa0(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
leaq -0x140(%rbp), %rdx
callq 0x34ec
movq -0x98(%rbp), %rax
leaq -0x50(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq -0x20(%rax), %rsi
movq -0x18(%rax), %rdx
addq %rsi, %rdx
leaq -0x60(%rbp), %rdi
callq 0x392c
leaq -0xa0(%rbp), %rdi
callq 0x36b8
movq -0x140(%rbp), %rdi
cmpq %r14, %rdi
je 0x7aa3
callq 0x31a0
leaq -0x190(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7ab8
callq 0x31a0
movq -0x40(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x35f2
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
subq -0x58(%rbp), %rcx
leaq -0xa0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
xorl %edx, %edx
callq 0x31d0
leaq -0x70(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7af5
callq 0x31a0
leaq -0x110(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
addq %rsi, %rdx
leaq -0x120(%rbp), %rdi
callq 0x392c
leaq -0x120(%rbp), %rsi
movq %rbx, %rdi
callq 0xacd6
movq %rax, %r13
movq -0x120(%rbp), %rdi
cmpq %r14, %rdi
je 0x7b40
callq 0x31a0
leaq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x35f2
leaq 0x661d(%rip), %rsi      # 0xe174
leaq -0x80(%rbp), %r12
movq %r12, %rdi
callq 0x3080
movl %eax, %r14d
movq (%r12), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x7b78
callq 0x31a0
testl %r14d, %r14d
jne 0x7b88
movq %rbx, %rdi
callq 0xacc2
movq %rax, %r13
movq -0x40(%rbp), %rax
leaq -0xf0(%rbp), %r12
movq %r12, -0x10(%r12)
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
addq %rsi, %rdx
leaq -0x100(%rbp), %rdi
callq 0x392c
leaq -0x100(%rbp), %rsi
movq %rbx, %r15
movq %rbx, %rdi
callq 0xacd6
movq %rax, %rbx
movq -0x100(%rbp), %rdi
cmpq %r12, %rdi
je 0x7bd5
callq 0x31a0
movq %r13, %r14
movq -0x40(%rbp), %rsi
addq $0x20, %rsi
leaq -0x80(%rbp), %rdi
callq 0x35f2
leaq 0x6584(%rip), %rsi      # 0xe174
leaq -0x80(%rbp), %r13
movq %r13, %rdi
callq 0x3080
movl %eax, %r12d
movq (%r13), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x7c11
callq 0x31a0
testl %r12d, %r12d
movq %r14, %r12
je 0x7c69
movq %rbx, %r14
jmp 0x7c74
movq 0xb3ab(%rip), %rbx      # 0x12fd0
leaq 0x663a(%rip), %rsi      # 0xe266
movl $0x2a, %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 0xb379(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
jmp 0x7dca
movq %r15, %rdi
callq 0xacc2
movq %rax, %r14
leaq -0xd0(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0xe0(%rbp), %rdi
callq 0x392c
leaq -0xe0(%rbp), %rsi
movq %r12, %rdi
callq 0xbcda
testq %r14, %r14
setne %bl
andb %al, %bl
movq -0xe0(%rbp), %rdi
cmpq %r15, %rdi
je 0x7cbe
callq 0x31a0
testb %bl, %bl
je 0x7d5d
leaq -0xb0(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %rdi
callq 0x392c
leaq -0xc0(%rbp), %rsi
movq %r12, %rdi
callq 0xc41c
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
cmpq %r15, %rdi
je 0x7d0b
callq 0x31a0
testq %rbx, %rbx
je 0x7da3
leaq 0xb055(%rip), %rsi      # 0x12d70
leaq 0xb05e(%rip), %rdx      # 0x12d80
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x31f0
testq %rax, %rax
je 0x7de5
movq %rax, %r12
movl $0x48, %edi
callq 0x31c0
movq %rax, %r15
movq %rax, %rdi
movq %r12, %rsi
callq 0xb49c
movq %r14, %rdi
movq %r15, %rsi
callq 0xbc0c
jmp 0x7da3
movq 0xb26c(%rip), %rbx      # 0x12fd0
leaq 0x6526(%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 0xb23a(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
leaq -0x90(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7db8
callq 0x31a0
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x7dca
callq 0x31a0
leaq -0x40(%rbp), %rdi
callq 0x36b8
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xaf84(%rip), %rsi      # 0x12d70
leaq 0xafa5(%rip), %rdx      # 0x12d98
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x31f0
testq %rax, %rax
je 0x7da3
movq %rax, %rbx
movl $0x30, %edi
callq 0x31c0
movq %rax, %r15
leaq 0xaedf(%rip), %rax      # 0x12cf8
addq $0x10, %rax
movq %rax, (%r15)
leaq 0x8(%r15), %rdi
movq %r15, %rax
addq $0x18, %rax
movq %rax, 0x8(%r15)
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
addq %rsi, %rdx
callq 0x392c
leaq 0xaeda(%rip), %rax      # 0x12d20
addq $0x10, %rax
movq %rax, (%r15)
movl 0x28(%rbx), %eax
movl %eax, 0x28(%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0xbc0c
jmp 0x7da3
jmp 0x7e6b
jmp 0x7f55
movq %rax, %rbx
movq %r15, %rdi
jmp 0x7ece
jmp 0x7f55
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
jmp 0x7e93
jmp 0x7f55
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
cmpq %r15, %rdi
jne 0x7ece
jmp 0x7f58
jmp 0x7f55
movq %rax, %rbx
movq -0x100(%rbp), %rdi
cmpq %r12, %rdi
jne 0x7ece
jmp 0x7f58
jmp 0x7f55
movq %rax, %rbx
movq -0x120(%rbp), %rdi
cmpq %r14, %rdi
je 0x7f58
callq 0x31a0
jmp 0x7f58
movq %rax, %rbx
leaq -0x70(%rbp), %rax
jmp 0x7f5f
movq %rax, %rbx
jmp 0x7f6d
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x36b8
jmp 0x7efd
movq %rax, %rbx
movq -0x140(%rbp), %rdi
cmpq %r14, %rdi
je 0x7f13
callq 0x31a0
jmp 0x7f13
movq %rax, %rbx
leaq -0x190(%rbp), %rax
movq -0x10(%rax), %rdi
jmp 0x7f75
jmp 0x7f50
jmp 0x7f55
movq %rax, %rbx
movq -0x160(%rbp), %rdi
cmpq %r15, %rdi
je 0x7f3d
callq 0x31a0
jmp 0x7f3d
movq %rax, %rbx
movq -0x180(%rbp), %rdi
cmpq %r14, %rdi
je 0x7f88
callq 0x31a0
jmp 0x7f88
movq %rax, %rbx
jmp 0x7f7f
movq %rax, %rbx
leaq -0x90(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7f6d
callq 0x31a0
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x7f7f
callq 0x31a0
leaq -0x40(%rbp), %rdi
callq 0x36b8
movq %rbx, %rdi
callq 0x32b0