// File: /workspace/github_cpp_makefile_star2_O1/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 0x3954
leaq -0x150(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x67a4(%rip), %rsi      # 0xe173
leaq 0x679e(%rip), %rdx      # 0xe174
leaq -0x160(%rbp), %rdi
callq 0xabe4
leaq -0x40(%rbp), %rdi
leaq -0x180(%rbp), %rsi
leaq -0x160(%rbp), %rdx
callq 0x34ec
movq -0x160(%rbp), %rdi
cmpq %r15, %rdi
je 0x7a0a
callq 0x31a0
movq -0x180(%rbp), %rdi
cmpq %r14, %rdi
je 0x7a1b
callq 0x31a0
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
subq %rsi, %rax
cmpq $0x40, %rax
jne 0x7c36
leaq -0x1a0(%rbp), %rdi
callq 0x35f2
leaq -0x130(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x67b5(%rip), %rsi      # 0xe203
leaq 0x67af(%rip), %rdx      # 0xe204
leaq -0x140(%rbp), %rdi
callq 0xabe4
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 0x3954
leaq -0xa0(%rbp), %rdi
callq 0x36b8
movq -0x140(%rbp), %rdi
cmpq %r14, %rdi
je 0x7abb
callq 0x31a0
leaq -0x190(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7ad0
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 0x7b0d
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 0x3954
leaq -0x120(%rbp), %rsi
movq %rbx, %rdi
callq 0xad2e
movq %rax, %r13
movq -0x120(%rbp), %rdi
cmpq %r14, %rdi
je 0x7b58
callq 0x31a0
leaq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x35f2
leaq 0x6605(%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 0x7b90
callq 0x31a0
testl %r14d, %r14d
jne 0x7ba0
movq %rbx, %rdi
callq 0xad1a
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 0x3954
leaq -0x100(%rbp), %rsi
movq %rbx, %r15
movq %rbx, %rdi
callq 0xad2e
movq %rax, %rbx
movq -0x100(%rbp), %rdi
cmpq %r12, %rdi
je 0x7bed
callq 0x31a0
movq %r13, %r14
movq -0x40(%rbp), %rsi
addq $0x20, %rsi
leaq -0x80(%rbp), %rdi
callq 0x35f2
leaq 0x656c(%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 0x7c29
callq 0x31a0
testl %r12d, %r12d
movq %r14, %r12
je 0x7c81
movq %rbx, %r14
jmp 0x7c8c
movq 0xb393(%rip), %rbx      # 0x12fd0
leaq 0x6622(%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 0xb361(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
jmp 0x7e66
movq %r15, %rdi
callq 0xad1a
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 0x3954
leaq -0xe0(%rbp), %rsi
movq %r12, %rdi
callq 0xbd50
testq %r14, %r14
setne %bl
andb %al, %bl
movq -0xe0(%rbp), %rdi
cmpq %r15, %rdi
je 0x7cd6
callq 0x31a0
testb %bl, %bl
je 0x7d41
leaq -0xb0(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %rdi
callq 0x3954
leaq -0xc0(%rbp), %rsi
movq %r12, %rdi
callq 0xc488
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
cmpq %r15, %rdi
je 0x7d1f
callq 0x31a0
testq %rbx, %rbx
je 0x7d8c
leaq 0xb045(%rip), %rsi      # 0x12d70
leaq 0xb04e(%rip), %rdx      # 0x12d80
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x31f0
movq %rax, %r15
jmp 0x7d8f
movq 0xb288(%rip), %rbx      # 0x12fd0
leaq 0x6542(%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 0xb256(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
jmp 0x7e3f
xorl %r15d, %r15d
testq %r15, %r15
je 0x7dbc
movl $0x48, %edi
callq 0x31c0
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
callq 0xb528
movq %r14, %rdi
movq %r12, %rsi
callq 0xbc84
jmp 0x7e3f
testq %rbx, %rbx
je 0x7dde
leaq 0xafa8(%rip), %rsi      # 0x12d70
leaq 0xafc9(%rip), %rdx      # 0x12d98
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x31f0
movq %rax, %rbx
jmp 0x7de0
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x7e3f
movl $0x30, %edi
callq 0x31c0
movq %rax, %r15
leaq 0xaeff(%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 0x3954
leaq 0xaefa(%rip), %rax      # 0x12d20
addq $0x10, %rax
movq %rax, (%r15)
movl 0x28(%rbx), %eax
movl %eax, 0x28(%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0xbc84
leaq -0x90(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7e54
callq 0x31a0
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x7e66
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
movq %rax, %rbx
movq %r15, %rdi
jmp 0x7ef1
jmp 0x7f78
movq %rax, %rbx
movq %r12, %rdi
jmp 0x7ef1
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
jmp 0x7eb6
jmp 0x7f78
jmp 0x7f78
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
cmpq %r15, %rdi
jne 0x7ef1
jmp 0x7f7b
jmp 0x7f78
movq %rax, %rbx
movq -0x100(%rbp), %rdi
cmpq %r12, %rdi
jne 0x7ef1
jmp 0x7f7b
jmp 0x7f78
movq %rax, %rbx
movq -0x120(%rbp), %rdi
cmpq %r14, %rdi
je 0x7f7b
callq 0x31a0
jmp 0x7f7b
movq %rax, %rbx
leaq -0x70(%rbp), %rax
jmp 0x7f82
movq %rax, %rbx
jmp 0x7f90
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x36b8
jmp 0x7f20
movq %rax, %rbx
movq -0x140(%rbp), %rdi
cmpq %r14, %rdi
je 0x7f36
callq 0x31a0
jmp 0x7f36
movq %rax, %rbx
leaq -0x190(%rbp), %rax
movq -0x10(%rax), %rdi
jmp 0x7f98
jmp 0x7f73
jmp 0x7f78
movq %rax, %rbx
movq -0x160(%rbp), %rdi
cmpq %r15, %rdi
je 0x7f60
callq 0x31a0
jmp 0x7f60
movq %rax, %rbx
movq -0x180(%rbp), %rdi
cmpq %r14, %rdi
je 0x7fab
callq 0x31a0
jmp 0x7fab
movq %rax, %rbx
jmp 0x7fa2
movq %rax, %rbx
leaq -0x90(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7f90
callq 0x31a0
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x7fa2
callq 0x31a0
leaq -0x40(%rbp), %rdi
callq 0x36b8
movq %rbx, %rdi
callq 0x32b0
nop