// File: 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
subq $0x300, %rsp            # imm = 0x300
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x7c70
leaq -0x69(%rbp), %rdi
movq %rdi, -0x240(%rbp)
callq 0x3310
movq -0x240(%rbp), %rdx
leaq 0x9f2d(%rip), %rsi      # 0x1414b
leaq -0x68(%rbp), %rdi
callq 0x3260
jmp 0xa229
leaq -0x28(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x3550
jmp 0xa23c
leaq -0x68(%rbp), %rdi
callq 0x3130
leaq -0x69(%rbp), %rdi
callq 0x3200
leaq -0x48(%rbp), %rdi
callq 0x3130
leaq -0x28(%rbp), %rdi
callq 0x4020
cmpq $0x2, %rax
je 0xa2f2
movq 0x11d57(%rip), %rdi     # 0x1bfc8
leaq 0x9fc6(%rip), %rsi      # 0x1423e
callq 0x31b0
movq %rax, -0x248(%rbp)
jmp 0xa286
movq -0x248(%rbp), %rdi
movq 0x11d24(%rip), %rsi     # 0x1bfb8
callq 0x31e0
jmp 0xa29b
movl $0x1, -0x80(%rbp)
jmp 0xa9dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xa2ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3130
leaq -0x69(%rbp), %rdi
callq 0x3200
leaq -0x48(%rbp), %rdi
callq 0x3130
jmp 0xaa0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xaa06
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0xd9b0
movq %rax, %rsi
leaq -0xd8(%rbp), %rdi
callq 0x36c0
jmp 0xa310
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x3310
movq -0x250(%rbp), %rdx
leaq 0x9eaa(%rip), %rsi      # 0x141db
leaq -0xf8(%rbp), %rdi
callq 0x3260
jmp 0xa33f
leaq -0xb8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0xf8(%rbp), %rdx
callq 0x3550
jmp 0xa35b
leaq -0xb8(%rbp), %rdi
callq 0xda00
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x30e0
jmp 0xa378
leaq -0xb8(%rbp), %rdi
callq 0x37e0
leaq -0xf8(%rbp), %rdi
callq 0x3130
leaq -0xf9(%rbp), %rdi
callq 0x3200
leaq -0xd8(%rbp), %rdi
callq 0x3130
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0xd9b0
movq %rax, %rsi
leaq -0x140(%rbp), %rdi
callq 0x36c0
jmp 0xa3c6
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x258(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xd9b0
movq %rax, %rdi
callq 0x32a0
movq %rax, -0x260(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x32a0
movq -0x260(%rbp), %rcx
movq -0x258(%rbp), %rdx
subq %rax, %rcx
leaq -0x120(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x31d0
jmp 0xa41b
leaq -0x140(%rbp), %rdi
callq 0x3130
movq -0x10(%rbp), %rax
movq %rax, -0x268(%rbp)
leaq -0x168(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x30e0
jmp 0xa447
movq -0x268(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0xe1f0
movq %rax, -0x270(%rbp)
jmp 0xa463
leaq -0x168(%rbp), %rdi
callq 0x3130
movq -0x270(%rbp), %rax
movq %rax, -0x148(%rbp)
leaq -0x188(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x36c0
jmp 0xa492
leaq 0x9cb3(%rip), %rsi      # 0x1414c
leaq -0x188(%rbp), %rdi
callq 0xd980
movb %al, -0x271(%rbp)
jmp 0xa4ad
leaq -0x188(%rbp), %rdi
callq 0x3130
movb -0x271(%rbp), %al
testb $0x1, %al
jne 0xa4c8
jmp 0xa5c3
movq -0x10(%rbp), %rdi
callq 0xe1b0
movq %rax, -0x280(%rbp)
jmp 0xa4da
movq -0x280(%rbp), %rax
movq %rax, -0x148(%rbp)
jmp 0xa5c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xa52d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xa521
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x37e0
leaq -0xf8(%rbp), %rdi
callq 0x3130
leaq -0xf9(%rbp), %rdi
callq 0x3200
leaq -0xd8(%rbp), %rdi
callq 0x3130
jmp 0xaa06
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xa9fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x3130
jmp 0xa9fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xa9ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x3130
jmp 0xa9ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x3130
jmp 0xa9ee
movq -0x10(%rbp), %rax
movq %rax, -0x288(%rbp)
leaq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0xd9b0
movq %rax, %rsi
leaq -0x1b0(%rbp), %rdi
callq 0x30e0
jmp 0xa5ed
movq -0x288(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0xe1f0
movq %rax, -0x290(%rbp)
jmp 0xa609
leaq -0x1b0(%rbp), %rdi
callq 0x3130
movq -0x290(%rbp), %rax
movq %rax, -0x190(%rbp)
leaq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0xd9b0
movq %rax, %rsi
leaq -0x1d0(%rbp), %rdi
callq 0x36c0
jmp 0xa642
leaq 0x9b03(%rip), %rsi      # 0x1414c
leaq -0x1d0(%rbp), %rdi
callq 0xd980
movb %al, -0x291(%rbp)
jmp 0xa65d
leaq -0x1d0(%rbp), %rdi
callq 0x3130
movb -0x291(%rbp), %al
testb $0x1, %al
jne 0xa675
jmp 0xa6d1
movq -0x10(%rbp), %rdi
callq 0xe1b0
movq %rax, -0x2a0(%rbp)
jmp 0xa687
movq -0x2a0(%rbp), %rax
movq %rax, -0x190(%rbp)
jmp 0xa6d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x3130
jmp 0xa9ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x3130
jmp 0xa9ee
movq -0x148(%rbp), %rax
movq %rax, -0x2a8(%rbp)
leaq -0x1f0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x30e0
jmp 0xa6f4
movq -0x2a8(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
callq 0xf6a0
movb %al, -0x2a9(%rbp)
jmp 0xa70f
movb -0x2a9(%rbp), %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x2aa(%rbp)
jne 0xa724
jmp 0xa737
cmpq $0x0, -0x190(%rbp)
setne %al
xorb $-0x1, %al
movb %al, -0x2aa(%rbp)
movb -0x2aa(%rbp), %al
movb %al, -0x2ab(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x3130
movb -0x2ab(%rbp), %al
testb $0x1, %al
jne 0xa75b
jmp 0xa7b5
movq 0x11866(%rip), %rdi     # 0x1bfc8
leaq 0x9b00(%rip), %rsi      # 0x14269
callq 0x31b0
movq %rax, -0x2b8(%rbp)
jmp 0xa777
movq -0x2b8(%rbp), %rdi
movq 0x11833(%rip), %rsi     # 0x1bfb8
callq 0x31e0
jmp 0xa78c
movl $0x1, -0x80(%rbp)
jmp 0xa9c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x3130
jmp 0xa9ee
movq -0x148(%rbp), %rax
movq %rax, -0x2c0(%rbp)
leaq -0x218(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x30e0
jmp 0xa7d8
movq -0x2c0(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0xfde0
movq %rax, -0x2c8(%rbp)
jmp 0xa7f4
leaq -0x218(%rbp), %rdi
callq 0x3130
movq -0x2c8(%rbp), %rax
movq %rax, -0x1f8(%rbp)
movq -0x1f8(%rbp), %rax
movq %rax, -0x2d0(%rbp)
cmpq $0x0, %rax
je 0xa866
movq -0x2d0(%rbp), %rdi
leaq 0x11530(%rip), %rsi     # 0x1bd60
leaq 0x11539(%rip), %rdx     # 0x1bd70
xorl %eax, %eax
movl %eax, %ecx
callq 0x3210
movq %rax, -0x2d8(%rbp)
jmp 0xa871
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x3130
jmp 0xa9ee
xorl %eax, %eax
movq %rax, -0x2d8(%rbp)
jmp 0xa871
movq -0x2d8(%rbp), %rax
movq %rax, -0x220(%rbp)
cmpq $0x0, -0x220(%rbp)
je 0xa8f6
movl $0x48, %edi
callq 0x31c0
movq %rax, -0x2e0(%rbp)
jmp 0xa89c
movq -0x2e0(%rbp), %rdi
movq -0x220(%rbp), %rsi
callq 0xecd0
jmp 0xa8b1
movq -0x2e0(%rbp), %rax
movq %rax, -0x228(%rbp)
movq -0x190(%rbp), %rdi
movq -0x228(%rbp), %rsi
callq 0xf5b0
jmp 0xa8d4
jmp 0xa9bd
movq -0x2e0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
callq 0x31a0
jmp 0xa9ee
movq -0x1f8(%rbp), %rax
movq %rax, -0x2e8(%rbp)
cmpq $0x0, %rax
je 0xa931
movq -0x2e8(%rbp), %rdi
leaq 0x11448(%rip), %rsi     # 0x1bd60
leaq 0x11469(%rip), %rdx     # 0x1bd88
xorl %eax, %eax
movl %eax, %ecx
callq 0x3210
movq %rax, -0x2f0(%rbp)
jmp 0xa93c
xorl %eax, %eax
movq %rax, -0x2f0(%rbp)
jmp 0xa93c
movq -0x2f0(%rbp), %rax
movq %rax, -0x230(%rbp)
cmpq $0x0, -0x230(%rbp)
je 0xa9bb
movl $0x30, %edi
callq 0x31c0
movq %rax, -0x2f8(%rbp)
jmp 0xa967
movq -0x2f8(%rbp), %rdi
movq -0x230(%rbp), %rsi
callq 0xdc40
jmp 0xa97c
movq -0x2f8(%rbp), %rax
movq %rax, -0x238(%rbp)
movq -0x190(%rbp), %rdi
movq -0x238(%rbp), %rsi
callq 0xf5b0
jmp 0xa99f
jmp 0xa9bb
movq -0x2f8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
callq 0x31a0
jmp 0xa9ee
jmp 0xa9bd
movl $0x0, -0x80(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x3130
leaq -0xa0(%rbp), %rdi
callq 0x3130
leaq -0x28(%rbp), %rdi
callq 0x37e0
addq $0x300, %rsp            # imm = 0x300
popq %rbp
retq
leaq -0x120(%rbp), %rdi
callq 0x3130
leaq -0xa0(%rbp), %rdi
callq 0x3130
leaq -0x28(%rbp), %rdi
callq 0x37e0
movq -0x78(%rbp), %rdi
callq 0x3300
nopl (%rax,%rax)