// File: /workspace/github_cpp_makefile_star2_O2/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 0x28(%rdi), %rsi
leaq -0x1a0(%rbp), %rdi
callq 0x3210
leaq 0x4dad(%rip), %rsi      # 0xb14b
leaq -0x180(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x30a0
leaq -0x40(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
leaq -0x180(%rbp), %rdx
callq 0x348c
leaq -0x180(%rbp), %rdi
callq 0x30c0
leaq -0x1a0(%rbp), %rdi
callq 0x30c0
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
subq %rsi, %rax
cmpq $0x40, %rax
jne 0x662f
leaq -0x160(%rbp), %rdi
callq 0x3574
leaq 0x4dd3(%rip), %rsi      # 0xb1db
leaq -0x140(%rbp), %rdi
leaq -0x60(%rbp), %rdx
callq 0x30a0
leaq -0x80(%rbp), %rdi
leaq -0x160(%rbp), %rsi
leaq -0x140(%rbp), %rdx
callq 0x348c
movq -0x78(%rbp), %rsi
addq $-0x20, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x3210
leaq -0x80(%rbp), %rdi
callq 0x3614
leaq -0x140(%rbp), %rdi
callq 0x30c0
leaq -0x160(%rbp), %rdi
callq 0x30c0
movq -0x40(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x3574
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
subq -0x98(%rbp), %rcx
leaq -0x80(%rbp), %rdi
leaq -0x60(%rbp), %rsi
xorl %edx, %edx
callq 0x31a0
leaq -0x60(%rbp), %rdi
callq 0x30c0
leaq -0x120(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x3210
leaq -0x120(%rbp), %rsi
movq %rbx, %rdi
callq 0x8590
movq %rax, %r15
leaq -0x120(%rbp), %rdi
callq 0x30c0
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x3574
leaq 0x4c72(%rip), %rsi      # 0xb14c
leaq -0x60(%rbp), %r14
movq %r14, %rdi
callq 0x8386
movl %eax, %r12d
movq %r14, %rdi
callq 0x30c0
testb %r12b, %r12b
je 0x6501
movq %rbx, %rdi
callq 0x857c
movq %rax, %r15
movq -0x40(%rbp), %rsi
addq $0x20, %rsi
leaq -0x100(%rbp), %rdi
callq 0x3210
leaq -0x100(%rbp), %rsi
movq %rbx, %rdi
callq 0x8590
movq %rax, %r14
leaq -0x100(%rbp), %rdi
callq 0x30c0
movq -0x40(%rbp), %rsi
addq $0x20, %rsi
leaq -0x60(%rbp), %rdi
callq 0x3574
leaq 0x4c01(%rip), %rsi      # 0xb14c
leaq -0x60(%rbp), %r12
movq %r12, %rdi
callq 0x8386
movl %eax, %r13d
movq %r12, %rdi
callq 0x30c0
testb %r13b, %r13b
je 0x6572
movq %rbx, %rdi
callq 0x857c
movq %rax, %r14
leaq -0xe0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x3210
leaq -0xe0(%rbp), %rsi
movq %r15, %rdi
callq 0x90c2
movl %eax, %ebx
testq %r14, %r14
setne %r12b
leaq -0xe0(%rbp), %rdi
callq 0x30c0
testb %bl, %r12b
je 0x664c
leaq -0xc0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x3210
leaq -0xc0(%rbp), %rsi
movq %r15, %rdi
callq 0x94a4
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x30c0
testq %rbx, %rbx
je 0x6667
leaq 0xa779(%rip), %rsi      # 0x10d68
leaq 0xa782(%rip), %rdx      # 0x10d78
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x31c0
testq %rax, %rax
je 0x6697
movq %rax, %r12
pushq $0x48
popq %rdi
callq 0x3190
movq %rax, %r15
movq %rax, %rdi
movq %r12, %rsi
callq 0x8b0c
movq %r14, %rdi
movq %r15, %rsi
callq 0x9030
jmp 0x6667
movq 0xa992(%rip), %rdi      # 0x10fc8
leaq 0x4c01(%rip), %rsi      # 0xb23e
callq 0x3180
movq %rax, %rdi
callq 0x30d0
jmp 0x667c
movq 0xa975(%rip), %rdi      # 0x10fc8
leaq 0x4c0f(%rip), %rsi      # 0xb269
callq 0x3180
movq %rax, %rdi
callq 0x30d0
leaq -0x80(%rbp), %rdi
callq 0x30c0
leaq -0xa0(%rbp), %rdi
callq 0x30c0
leaq -0x40(%rbp), %rdi
callq 0x3614
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa6ca(%rip), %rsi      # 0x10d68
leaq 0xa6eb(%rip), %rdx      # 0x10d90
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x31c0
testq %rax, %rax
je 0x6667
movq %rax, %rbx
pushq $0x30
popq %rdi
callq 0x3190
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
callq 0x83c4
movq %r14, %rdi
movq %r15, %rsi
callq 0x9030
jmp 0x6667
jmp 0x66e1
jmp 0x679b
movq %rax, %rbx
movq %r15, %rdi
callq 0x3170
jmp 0x679e
jmp 0x679b
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
jmp 0x6730
jmp 0x679b
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
jmp 0x6730
jmp 0x679b
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
jmp 0x6730
jmp 0x679b
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
callq 0x30c0
jmp 0x679e
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
jmp 0x67a2
movq %rax, %rbx
jmp 0x67a7
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x3614
jmp 0x6756
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
callq 0x30c0
jmp 0x6767
movq %rax, %rbx
leaq -0x160(%rbp), %rdi
jmp 0x67ae
jmp 0x6774
jmp 0x679b
movq %rax, %rbx
jmp 0x67b3
movq %rax, %rbx
leaq -0x180(%rbp), %rdi
callq 0x30c0
jmp 0x678d
movq %rax, %rbx
leaq -0x1a0(%rbp), %rdi
callq 0x30c0
jmp 0x67bc
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x30c0
leaq -0xa0(%rbp), %rdi
callq 0x30c0
leaq -0x40(%rbp), %rdi
callq 0x3614
movq %rbx, %rdi
callq 0x3290