// File: /workspace/github_cpp_makefile_star2_O1/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 0x3954
leaq -0x130(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x4e02(%rip), %rsi      # 0xe173
leaq 0x4dfc(%rip), %rdx      # 0xe174
leaq -0x140(%rbp), %rdi
callq 0xabe4
leaq -0x40(%rbp), %rdi
leaq -0x160(%rbp), %rsi
leaq -0x140(%rbp), %rdx
callq 0x34ec
movq -0x140(%rbp), %rdi
cmpq %r15, %rdi
je 0x93ac
callq 0x31a0
movq -0x160(%rbp), %rdi
cmpq %r14, %rdi
je 0x93bd
callq 0x31a0
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
subq %rdi, %rax
movl $0x10, %r14d
leaq 0x4f49(%rip), %r15      # 0xe31e
cmpq $0x20, %rax
jne 0x957f
leaq 0x4d8e(%rip), %rsi      # 0xe174
callq 0x3080
testl %eax, %eax
je 0x957f
movq -0x40(%rbp), %rdi
leaq 0x4e05(%rip), %rsi      # 0xe203
callq 0x3080
testl %eax, %eax
je 0x9572
movq -0x40(%rbp), %rsi
leaq -0x1a0(%rbp), %rdi
callq 0x35f2
leaq -0x110(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x4dd6(%rip), %rsi      # 0xe203
leaq 0x4dd0(%rip), %rdx      # 0xe204
leaq -0x120(%rbp), %rdi
callq 0xabe4
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 0x3954
leaq -0x80(%rbp), %rdi
callq 0x36b8
movq -0x120(%rbp), %rdi
cmpq %r14, %rdi
je 0x9492
callq 0x31a0
leaq -0x190(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x94a7
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 0x94ea
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 0x3954
leaq -0x100(%rbp), %rsi
movq %rbx, %rdi
callq 0xad2e
movq %rax, %r14
movq -0x100(%rbp), %rdi
cmpq %r15, %rdi
je 0x952f
callq 0x31a0
testq %r14, %r14
je 0x95da
leaq -0xd0(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0xe0(%rbp), %rdi
callq 0x3954
leaq -0xe0(%rbp), %rsi
movq %r14, %rdi
callq 0xbd50
movl %eax, %r15d
xorb $0x1, %r15b
jmp 0x95dd
movl $0x16, %r14d
leaq 0x4db0(%rip), %r15      # 0xe32f
movq 0x9a4a(%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 0x9a1e(%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
movb $0x1, %r15b
testq %r14, %r14
je 0x95f7
leaq -0xd0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x95f7
callq 0x31a0
testb %r15b, %r15b
je 0x9647
movq 0x99cd(%rip), %rbx      # 0x12fd0
leaq 0x4c87(%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 0x999b(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
jmp 0x9730
leaq -0xb0(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %rdi
callq 0x3954
leaq -0xc0(%rbp), %rsi
movq %r14, %rdi
callq 0xc488
movq %rax, %r15
movq -0xc0(%rbp), %rdi
cmpq %r13, %rdi
je 0x968c
callq 0x31a0
movq %rbx, %rdi
callq 0xad10
cmpq %rax, %r15
je 0x96ea
movq %rbx, %rdi
callq 0xad1a
cmpq %rax, %r15
je 0x96ea
leaq -0x90(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0xa0(%rbp), %rdi
callq 0x3954
leaq -0xa0(%rbp), %rsi
movq %r14, %rdi
callq 0xbdf8
movq -0xa0(%rbp), %rdi
cmpq %r15, %rdi
je 0x9730
callq 0x31a0
jmp 0x9730
movq 0x98df(%rip), %rbx      # 0x12fd0
leaq 0x4c37(%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 0x98ad(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
leaq -0x70(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9742
callq 0x31a0
movq -0x60(%rbp), %rdi
cmpq %r12, %rdi
je 0x95bf
callq 0x31a0
jmp 0x95bf
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
jmp 0x978c
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
jmp 0x977b
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
cmpq %r13, %rdi
jne 0x9791
jmp 0x97e9
movq %rax, %rbx
movq -0x100(%rbp), %rdi
cmpq %r15, %rdi
je 0x97e9
callq 0x31a0
jmp 0x97e9
movq %rax, %rbx
leaq -0x170(%rbp), %rax
jmp 0x97ed
movq %rax, %rbx
jmp 0x97fb
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x36b8
jmp 0x97ba
movq %rax, %rbx
movq -0x120(%rbp), %rdi
cmpq %r14, %rdi
je 0x97d0
callq 0x31a0
jmp 0x97d0
movq %rax, %rbx
leaq -0x190(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x9804
jmp 0x983a
jmp 0x9837
jmp 0x97e6
movq %rax, %rbx
leaq -0x70(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x97fb
callq 0x31a0
movq -0x60(%rbp), %rdi
cmpq %r12, %rdi
je 0x983a
callq 0x31a0
jmp 0x983a
movq %rax, %rbx
movq -0x140(%rbp), %rdi
cmpq %r15, %rdi
je 0x9824
callq 0x31a0
jmp 0x9824
movq %rax, %rbx
movq -0x160(%rbp), %rdi
cmpq %r14, %rdi
je 0x9843
callq 0x31a0
jmp 0x9843
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x36b8
movq %rbx, %rdi
callq 0x32b0
nop