// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r14
pushq %rbx
subq $0x180, %rsp            # imm = 0x180
movq %rsi, %rbx
leaq 0x28(%rdi), %rsi
leaq -0x188(%rbp), %rdi
callq 0x3210
leaq 0x4167(%rip), %rsi      # 0xb14b
leaq -0x168(%rbp), %rdi
leaq -0x68(%rbp), %rdx
callq 0x30a0
leaq -0x28(%rbp), %rdi
leaq -0x188(%rbp), %rsi
leaq -0x168(%rbp), %rdx
callq 0x348c
leaq -0x168(%rbp), %rdi
callq 0x30c0
leaq -0x188(%rbp), %rdi
callq 0x30c0
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rax
subq %rsi, %rax
cmpq $0x40, %rax
jne 0x71aa
leaq -0x148(%rbp), %rdi
callq 0x3574
leaq 0x4190(%rip), %rsi      # 0xb1db
leaq -0x128(%rbp), %rdi
leaq -0x88(%rbp), %rdx
callq 0x30a0
leaq -0x48(%rbp), %rdi
leaq -0x148(%rbp), %rsi
leaq -0x128(%rbp), %rdx
callq 0x348c
movq -0x40(%rbp), %rsi
addq $-0x20, %rsi
leaq -0x68(%rbp), %rdi
callq 0x3210
leaq -0x48(%rbp), %rdi
callq 0x3614
leaq -0x128(%rbp), %rdi
callq 0x30c0
leaq -0x148(%rbp), %rdi
callq 0x30c0
movq -0x28(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x3574
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rcx
subq -0x60(%rbp), %rcx
leaq -0x48(%rbp), %rdi
leaq -0x88(%rbp), %rsi
xorl %edx, %edx
callq 0x31a0
leaq -0x88(%rbp), %rdi
callq 0x30c0
leaq -0x108(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x3210
leaq -0x108(%rbp), %rsi
movq %rbx, %rdi
callq 0x8590
movq %rax, %rbx
leaq -0x108(%rbp), %rdi
callq 0x30c0
testq %rbx, %rbx
je 0x71c7
leaq -0xe8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x3210
leaq -0xe8(%rbp), %rsi
movq %rbx, %rdi
callq 0x90c2
movl %eax, %r14d
leaq -0xe8(%rbp), %rdi
callq 0x30c0
testb %r14b, %r14b
je 0x71c7
leaq -0xc8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x3210
leaq -0xc8(%rbp), %rsi
movq %rbx, %rdi
callq 0x94a4
movq %rax, %rbx
movq -0x28(%rbp), %rsi
addq $0x20, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x3574
leaq -0xa8(%rbp), %rsi
movq %rbx, %rdi
callq 0x8a26
leaq -0xa8(%rbp), %rdi
callq 0x30c0
leaq -0xc8(%rbp), %rdi
callq 0x30c0
jmp 0x71e2
movq 0x9e17(%rip), %rdi      # 0x10fc8
leaq 0x4115(%rip), %rsi      # 0xb2cd
callq 0x3180
movq %rax, %rdi
callq 0x30d0
jmp 0x71f4
movq 0x9dfa(%rip), %rdi      # 0x10fc8
leaq 0x4094(%rip), %rsi      # 0xb269
callq 0x3180
movq %rax, %rdi
callq 0x30d0
leaq -0x48(%rbp), %rdi
callq 0x30c0
leaq -0x68(%rbp), %rdi
callq 0x30c0
leaq -0x28(%rbp), %rdi
callq 0x3614
addq $0x180, %rsp            # imm = 0x180
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x30c0
jmp 0x721d
movq %rax, %rbx
leaq -0xc8(%rbp), %rdi
jmp 0x723c
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
jmp 0x723c
movq %rax, %rbx
leaq -0x108(%rbp), %rdi
callq 0x30c0
jmp 0x72ab
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
jmp 0x72af
movq %rax, %rbx
jmp 0x72b4
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x3614
jmp 0x7265
movq %rax, %rbx
leaq -0x128(%rbp), %rdi
callq 0x30c0
jmp 0x7276
movq %rax, %rbx
leaq -0x148(%rbp), %rdi
jmp 0x72b8
jmp 0x7281
movq %rax, %rbx
jmp 0x72bd
movq %rax, %rbx
leaq -0x168(%rbp), %rdi
callq 0x30c0
jmp 0x729a
movq %rax, %rbx
leaq -0x188(%rbp), %rdi
callq 0x30c0
jmp 0x72c6
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x30c0
leaq -0x68(%rbp), %rdi
callq 0x30c0
leaq -0x28(%rbp), %rdi
callq 0x3614
movq %rbx, %rdi
callq 0x3290