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

	if (arguments.size() != 2)
	{
		std::cout << "Usage: rename <path/old-name> <new-name>" << 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 (!src || !src->childExists(src_name))
	{
		std::cout << "No such file or directory" << std::endl;
		return;
	}

	src->getChildByName(src_name)->setName(StringTools::trim(arguments[1]));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x7c70
leaq -0x69(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x3310
movq -0x1d8(%rbp), %rdx
leaq 0x886d(%rip), %rsi      # 0x1414b
leaq -0x68(%rbp), %rdi
callq 0x3260
jmp 0xb8e9
leaq -0x28(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x3550
jmp 0xb8fc
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 0xb9b2
movq 0x10697(%rip), %rdi     # 0x1bfc8
leaq 0x8995(%rip), %rsi      # 0x142cd
callq 0x31b0
movq %rax, -0x1e0(%rbp)
jmp 0xb946
movq -0x1e0(%rbp), %rdi
movq 0x10664(%rip), %rsi     # 0x1bfb8
callq 0x31e0
jmp 0xb95b
movl $0x1, -0x80(%rbp)
jmp 0xbda6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xb98a
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 0xbe0b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xbe02
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0xd9b0
movq %rax, %rsi
leaq -0xd8(%rbp), %rdi
callq 0x36c0
jmp 0xb9d0
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x3310
movq -0x1e8(%rbp), %rdx
leaq 0x87ea(%rip), %rsi      # 0x141db
leaq -0xf8(%rbp), %rdi
callq 0x3260
jmp 0xb9ff
leaq -0xb8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0xf8(%rbp), %rdx
callq 0x3550
jmp 0xba1b
leaq -0xb8(%rbp), %rdi
callq 0xda00
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x30e0
jmp 0xba38
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 0xba86
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x1f0(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xd9b0
movq %rax, %rdi
callq 0x32a0
movq %rax, -0x1f8(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x32a0
movq -0x1f8(%rbp), %rcx
movq -0x1f0(%rbp), %rdx
subq %rax, %rcx
leaq -0x120(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x31d0
jmp 0xbadb
leaq -0x140(%rbp), %rdi
callq 0x3130
movq -0x10(%rbp), %rax
movq %rax, -0x200(%rbp)
leaq -0x168(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x30e0
jmp 0xbb07
movq -0x200(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0xe1f0
movq %rax, -0x208(%rbp)
jmp 0xbb23
leaq -0x168(%rbp), %rdi
callq 0x3130
movq -0x208(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rcx
movb $0x0, -0x189(%rbp)
movb $0x1, %al
cmpq $0x0, %rcx
movb %al, -0x209(%rbp)
je 0xbbac
movq -0x148(%rbp), %rax
movq %rax, -0x218(%rbp)
leaq -0x188(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x30e0
jmp 0xbb7c
movq -0x218(%rbp), %rdi
movb $0x1, -0x189(%rbp)
leaq -0x188(%rbp), %rsi
callq 0xf6a0
movb %al, -0x219(%rbp)
jmp 0xbb9e
movb -0x219(%rbp), %al
xorb $-0x1, %al
movb %al, -0x209(%rbp)
movb -0x209(%rbp), %al
movb %al, -0x21a(%rbp)
testb $0x1, -0x189(%rbp)
jne 0xbbc3
jmp 0xbbcf
leaq -0x188(%rbp), %rdi
callq 0x3130
movb -0x21a(%rbp), %al
testb $0x1, %al
jne 0xbbde
jmp 0xbcfc
movq 0x103e3(%rip), %rdi     # 0x1bfc8
leaq 0x867d(%rip), %rsi      # 0x14269
callq 0x31b0
movq %rax, -0x228(%rbp)
jmp 0xbbfa
movq -0x228(%rbp), %rdi
movq 0x103b0(%rip), %rsi     # 0x1bfb8
callq 0x31e0
jmp 0xbc0f
movl $0x1, -0x80(%rbp)
jmp 0xbd8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xbc5b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xbc4f
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 0xbe02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xbdf6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x3130
jmp 0xbdf6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xbdea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x3130
jmp 0xbdea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
testb $0x1, -0x189(%rbp)
jne 0xbceb
jmp 0xbcf7
leaq -0x188(%rbp), %rdi
callq 0x3130
jmp 0xbdea
movq -0x148(%rbp), %rax
movq %rax, -0x230(%rbp)
leaq -0x1b0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x30e0
jmp 0xbd1f
movq -0x230(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0xfde0
movq %rax, -0x238(%rbp)
jmp 0xbd3b
leaq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0xd9b0
movq %rax, %rsi
leaq -0x1d0(%rbp), %rdi
callq 0x36c0
jmp 0xbd5a
movq -0x238(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0xeb60
jmp 0xbd6f
leaq -0x1d0(%rbp), %rdi
callq 0x3130
leaq -0x1b0(%rbp), %rdi
callq 0x3130
movl $0x0, -0x80(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x3130
leaq -0xa0(%rbp), %rdi
callq 0x3130
leaq -0x28(%rbp), %rdi
callq 0x37e0
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xbdde
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x3130
leaq -0x1b0(%rbp), %rdi
callq 0x3130
leaq -0x120(%rbp), %rdi
callq 0x3130
leaq -0xa0(%rbp), %rdi
callq 0x3130
leaq -0x28(%rbp), %rdi
callq 0x37e0
movq -0x78(%rbp), %rdi
callq 0x3300
nopw %cs:(%rax,%rax)