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

	if (arguments.size() != 1 || (arguments.size() > 0 && arguments[0] == ""))
	{
		std::cout << "Usage: rm <path>" << std::endl;
		return;
	}
	
	if (arguments[0] == "/")
	{
		std::cout << "Can't remove directory" << 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;
	}

	BaseFile* bf = src->getChildByName(src_name);

	if (bf == &fs.getRootDirectory() || bf == &fs.getWorkingDirectory())
	{
		std::cout << "Can't remove directory" << std::endl;
		return;
	}

	src->removeFile(src_name);
}

// 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 -0x150(%rbp), %r14
movq %r14, -0x10(%r14)
movq 0x28(%rdi), %rsi
movq 0x30(%rdi), %rdx
addq %rsi, %rdx
leaq -0x160(%rbp), %rdi
callq 0x392c
leaq -0x130(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x4e42(%rip), %rsi      # 0xe173
leaq 0x4e3c(%rip), %rdx      # 0xe174
leaq -0x140(%rbp), %rdi
callq 0xab8a
leaq -0x40(%rbp), %rdi
leaq -0x160(%rbp), %rsi
leaq -0x140(%rbp), %rdx
callq 0x34ec
movq -0x140(%rbp), %rdi
cmpq %r15, %rdi
je 0x936c
callq 0x31a0
movq -0x160(%rbp), %rdi
cmpq %r14, %rdi
je 0x937d
callq 0x31a0
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
subq %rdi, %rax
movl $0x10, %r14d
leaq 0x4f89(%rip), %r15      # 0xe31e
cmpq $0x20, %rax
jne 0x9650
leaq 0x4dce(%rip), %rsi      # 0xe174
callq 0x3080
testl %eax, %eax
je 0x9650
movq -0x40(%rbp), %rdi
leaq 0x4e45(%rip), %rsi      # 0xe203
callq 0x3080
testl %eax, %eax
je 0x9643
movq -0x40(%rbp), %rsi
leaq -0x1a0(%rbp), %rdi
callq 0x35f2
leaq -0x110(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x4e16(%rip), %rsi      # 0xe203
leaq 0x4e10(%rip), %rdx      # 0xe204
leaq -0x120(%rbp), %rdi
callq 0xab8a
leaq -0x80(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
leaq -0x120(%rbp), %rdx
callq 0x34ec
movq -0x78(%rbp), %rax
leaq -0x50(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x20(%rax), %rsi
movq -0x18(%rax), %rdx
addq %rsi, %rdx
leaq -0x60(%rbp), %rdi
callq 0x392c
leaq -0x80(%rbp), %rdi
callq 0x36b8
movq -0x120(%rbp), %rdi
cmpq %r14, %rdi
je 0x9452
callq 0x31a0
leaq -0x190(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9467
callq 0x31a0
movq -0x40(%rbp), %rsi
leaq -0x180(%rbp), %rdi
callq 0x35f2
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
subq -0x58(%rbp), %rcx
leaq -0x80(%rbp), %rdi
leaq -0x180(%rbp), %rsi
xorl %edx, %edx
callq 0x31d0
leaq -0x170(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x94aa
callq 0x31a0
leaq -0xf0(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
addq %rsi, %rdx
leaq -0x100(%rbp), %rdi
callq 0x392c
leaq -0x100(%rbp), %rsi
movq %rbx, %rdi
callq 0xacd6
movq %rax, %r14
movq -0x100(%rbp), %rdi
cmpq %r15, %rdi
je 0x94ef
callq 0x31a0
testq %r14, %r14
je 0x95f8
leaq -0xd0(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0xe0(%rbp), %rdi
callq 0x392c
leaq -0xe0(%rbp), %rsi
movq %r14, %rdi
callq 0xbcda
movl %eax, %r15d
movq -0xe0(%rbp), %rdi
cmpq %r13, %rdi
je 0x953d
callq 0x31a0
testb %r15b, %r15b
je 0x95f8
leaq -0xb0(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %rdi
callq 0x392c
leaq -0xc0(%rbp), %rsi
movq %r14, %rdi
callq 0xc41c
movq %rax, %r15
movq -0xc0(%rbp), %rdi
cmpq %r13, %rdi
je 0x958b
callq 0x31a0
movq %rbx, %rdi
callq 0xacb8
cmpq %rax, %r15
je 0x96ab
movq %rbx, %rdi
callq 0xacc2
cmpq %rax, %r15
je 0x96ab
leaq -0x90(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0xa0(%rbp), %rdi
callq 0x392c
leaq -0xa0(%rbp), %rsi
movq %r14, %rdi
callq 0xbd8c
movq -0xa0(%rbp), %rdi
cmpq %r15, %rdi
je 0x96f1
callq 0x31a0
jmp 0x96f1
movq 0x99d1(%rip), %rbx      # 0x12fd0
leaq 0x4c8b(%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 0x999f(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
jmp 0x96f1
movl $0x16, %r14d
leaq 0x4cdf(%rip), %r15      # 0xe32f
movq 0x9979(%rip), %rbx      # 0x12fd0
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x3200
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq 0x994d(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
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 0x991e(%rip), %rbx      # 0x12fd0
leaq 0x4c76(%rip), %rsi      # 0xe32f
movl $0x16, %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 0x98ec(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
leaq -0x70(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9703
callq 0x31a0
movq -0x60(%rbp), %rdi
cmpq %r12, %rdi
je 0x9690
callq 0x31a0
jmp 0x9690
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
jmp 0x9749
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
jmp 0x9738
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
cmpq %r13, %rdi
jne 0x974e
jmp 0x97a6
movq %rax, %rbx
movq -0x100(%rbp), %rdi
cmpq %r15, %rdi
je 0x97a6
callq 0x31a0
jmp 0x97a6
movq %rax, %rbx
leaq -0x170(%rbp), %rax
jmp 0x97aa
movq %rax, %rbx
jmp 0x97b8
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x36b8
jmp 0x9777
movq %rax, %rbx
movq -0x120(%rbp), %rdi
cmpq %r14, %rdi
je 0x978d
callq 0x31a0
jmp 0x978d
movq %rax, %rbx
leaq -0x190(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x97c1
jmp 0x97f7
jmp 0x97f4
jmp 0x97a3
movq %rax, %rbx
leaq -0x70(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x97b8
callq 0x31a0
movq -0x60(%rbp), %rdi
cmpq %r12, %rdi
je 0x97f7
callq 0x31a0
jmp 0x97f7
movq %rax, %rbx
movq -0x140(%rbp), %rdi
cmpq %r15, %rdi
je 0x97e1
callq 0x31a0
jmp 0x97e1
movq %rax, %rbx
movq -0x160(%rbp), %rdi
cmpq %r14, %rdi
je 0x9800
callq 0x31a0
jmp 0x9800
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x36b8
movq %rbx, %rdi
callq 0x32b0