// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x180, %rsp            # imm = 0x180
movq %rsi, %rbx
leaq -0x128(%rbp), %r14
movq %r14, -0x10(%r14)
movq 0x28(%rdi), %rsi
movq 0x30(%rdi), %rdx
addq %rsi, %rdx
leaq -0x138(%rbp), %rdi
callq 0x3954
leaq -0x108(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x54f8(%rip), %rsi      # 0xe173
leaq 0x54f2(%rip), %rdx      # 0xe174
leaq -0x118(%rbp), %rdi
callq 0xabe4
leaq -0x38(%rbp), %rdi
leaq -0x138(%rbp), %rsi
leaq -0x118(%rbp), %rdx
callq 0x34ec
movq -0x118(%rbp), %rdi
cmpq %r15, %rdi
je 0x8cb6
callq 0x31a0
movq -0x138(%rbp), %rdi
cmpq %r14, %rdi
je 0x8cc7
callq 0x31a0
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rax
subq %rsi, %rax
cmpq $0x40, %rax
jne 0x8e3f
leaq -0x198(%rbp), %rdi
callq 0x35f2
leaq -0xe8(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x5509(%rip), %rsi      # 0xe203
leaq 0x5503(%rip), %rdx      # 0xe204
leaq -0xf8(%rbp), %rdi
callq 0xabe4
leaq -0x58(%rbp), %rdi
leaq -0x198(%rbp), %rsi
leaq -0xf8(%rbp), %rdx
callq 0x34ec
movq -0x50(%rbp), %rax
leaq -0x68(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x20(%rax), %rsi
movq -0x18(%rax), %rdx
addq %rsi, %rdx
leaq -0x78(%rbp), %rdi
callq 0x3954
leaq -0x58(%rbp), %rdi
callq 0x36b8
movq -0xf8(%rbp), %rdi
cmpq %r14, %rdi
je 0x8d5e
callq 0x31a0
leaq -0x188(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8d73
callq 0x31a0
movq -0x38(%rbp), %rsi
leaq -0x178(%rbp), %rdi
callq 0x35f2
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rcx
subq -0x70(%rbp), %rcx
leaq -0x58(%rbp), %rdi
leaq -0x178(%rbp), %rsi
xorl %edx, %edx
callq 0x31d0
leaq -0x168(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8db6
callq 0x31a0
leaq -0xc8(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0xd8(%rbp), %rdi
callq 0x3954
leaq -0xd8(%rbp), %rsi
movq %rbx, %rdi
callq 0xad2e
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
cmpq %r14, %rdi
je 0x8dfb
callq 0x31a0
testq %rbx, %rbx
je 0x8e8a
leaq -0xa8(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
addq %rsi, %rdx
leaq -0xb8(%rbp), %rdi
callq 0x3954
leaq -0xb8(%rbp), %rsi
movq %rbx, %rdi
callq 0xbd50
movl %eax, %r14d
xorb $0x1, %r14b
jmp 0x8e8d
movq 0xa18a(%rip), %rbx      # 0x12fd0
leaq 0x54a8(%rip), %rsi      # 0xe2f5
movl $0x28, %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 0xa158(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
jmp 0x8f91
movb $0x1, %r14b
testq %rbx, %rbx
je 0x8ea7
leaq -0xa8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8ea7
callq 0x31a0
testb %r14b, %r14b
je 0x8ef4
movq 0xa11d(%rip), %rbx      # 0x12fd0
leaq 0x53d7(%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 0xa0eb(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
jmp 0x8f71
leaq -0x88(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
addq %rsi, %rdx
leaq -0x98(%rbp), %rdi
callq 0x3954
leaq -0x98(%rbp), %rsi
movq %rbx, %rdi
callq 0xc488
movq %rax, %rbx
movq -0x38(%rbp), %rsi
addq $0x20, %rsi
leaq -0x158(%rbp), %rdi
callq 0x35f2
leaq -0x158(%rbp), %rsi
movq %rbx, %rdi
callq 0xb3c4
leaq -0x148(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8f60
callq 0x31a0
movq -0x98(%rbp), %rdi
cmpq %r14, %rdi
je 0x8f71
callq 0x31a0
leaq -0x48(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8f83
callq 0x31a0
movq -0x78(%rbp), %rdi
cmpq %r15, %rdi
je 0x8f91
callq 0x31a0
leaq -0x38(%rbp), %rdi
callq 0x36b8
addq $0x180, %rsp            # imm = 0x180
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x148(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8fdb
callq 0x31a0
jmp 0x8fdb
movq %rax, %rbx
movq -0xb8(%rbp), %rdi
cmpq %r12, %rdi
jne 0x8ff7
jmp 0x9084
movq %rax, %rbx
movq -0x98(%rbp), %rdi
jmp 0x8fee
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
cmpq %r14, %rdi
je 0x9084
callq 0x31a0
jmp 0x9084
movq %rax, %rbx
leaq -0x168(%rbp), %rax
jmp 0x9088
movq %rax, %rbx
jmp 0x9096
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x36b8
jmp 0x9026
movq %rax, %rbx
movq -0xf8(%rbp), %rdi
cmpq %r14, %rdi
je 0x903c
callq 0x31a0
jmp 0x903c
movq %rax, %rbx
leaq -0x188(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x909f
jmp 0x90a4
jmp 0x907c
movq %rax, %rbx
movq -0x118(%rbp), %rdi
cmpq %r15, %rdi
je 0x9069
callq 0x31a0
jmp 0x9069
movq %rax, %rbx
movq -0x138(%rbp), %rdi
cmpq %r14, %rdi
je 0x90ad
callq 0x31a0
jmp 0x90ad
movq %rax, %rbx
jmp 0x90a4
movq %rax, %rbx
leaq -0x48(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9096
callq 0x31a0
movq -0x78(%rbp), %rdi
cmpq %r15, %rdi
je 0x90a4
callq 0x31a0
leaq -0x38(%rbp), %rdi
callq 0x36b8
movq %rbx, %rdi
callq 0x32b0
nop