// File: 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
subq $0x290, %rsp            # imm = 0x290
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x7c70
leaq -0x69(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x3310
movq -0x1e0(%rbp), %rdx
leaq 0x810d(%rip), %rsi      # 0x1414b
leaq -0x68(%rbp), %rdi
callq 0x3260
jmp 0xc049
leaq -0x28(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x3550
jmp 0xc05c
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 $0x1, %rax
jne 0xc0cc
leaq -0x28(%rbp), %rdi
callq 0x4020
cmpq $0x0, %rax
jbe 0xc154
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0xd9b0
movq %rax, %rdi
leaq 0x809c(%rip), %rsi      # 0x1414c
callq 0xd980
movb %al, -0x1e1(%rbp)
jmp 0xc0bd
movb -0x1e1(%rbp), %al
testb $0x1, %al
jne 0xc0cc
jmp 0xc154
movq 0xfef5(%rip), %rdi      # 0x1bfc8
leaq 0x821c(%rip), %rsi      # 0x142f6
callq 0x31b0
movq %rax, -0x1f0(%rbp)
jmp 0xc0e8
movq -0x1f0(%rbp), %rdi
movq 0xfec2(%rip), %rsi      # 0x1bfb8
callq 0x31e0
jmp 0xc0fd
movl $0x1, -0x80(%rbp)
jmp 0xc684
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xc12c
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 0xc6cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xc6c6
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0xd9b0
movq %rax, %rdi
leaq 0x8070(%rip), %rsi      # 0x141db
callq 0xd980
movb %al, -0x1f1(%rbp)
jmp 0xc178
movb -0x1f1(%rbp), %al
testb $0x1, %al
jne 0xc184
jmp 0xc1c1
movq 0xfe3d(%rip), %rdi      # 0x1bfc8
leaq 0x8175(%rip), %rsi      # 0x14307
callq 0x31b0
movq %rax, -0x200(%rbp)
jmp 0xc1a0
movq -0x200(%rbp), %rdi
movq 0xfe0a(%rip), %rsi      # 0x1bfb8
callq 0x31e0
jmp 0xc1b5
movl $0x1, -0x80(%rbp)
jmp 0xc684
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0xd9b0
movq %rax, %rsi
leaq -0xd8(%rbp), %rdi
callq 0x36c0
jmp 0xc1df
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x3310
movq -0x208(%rbp), %rdx
leaq 0x7fdb(%rip), %rsi      # 0x141db
leaq -0xf8(%rbp), %rdi
callq 0x3260
jmp 0xc20e
leaq -0xb8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0xf8(%rbp), %rdx
callq 0x3550
jmp 0xc22a
leaq -0xb8(%rbp), %rdi
callq 0xda00
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x30e0
jmp 0xc247
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 0xc295
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x210(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xd9b0
movq %rax, %rdi
callq 0x32a0
movq %rax, -0x218(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x32a0
movq -0x218(%rbp), %rcx
movq -0x210(%rbp), %rdx
subq %rax, %rcx
leaq -0x120(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x31d0
jmp 0xc2ea
leaq -0x140(%rbp), %rdi
callq 0x3130
movq -0x10(%rbp), %rax
movq %rax, -0x220(%rbp)
leaq -0x168(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x30e0
jmp 0xc316
movq -0x220(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0xe1f0
movq %rax, -0x228(%rbp)
jmp 0xc332
leaq -0x168(%rbp), %rdi
callq 0x3130
movq -0x228(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rcx
movb $0x0, -0x189(%rbp)
movb $0x1, %al
cmpq $0x0, %rcx
movb %al, -0x229(%rbp)
je 0xc3bb
movq -0x148(%rbp), %rax
movq %rax, -0x238(%rbp)
leaq -0x188(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x30e0
jmp 0xc38b
movq -0x238(%rbp), %rdi
movb $0x1, -0x189(%rbp)
leaq -0x188(%rbp), %rsi
callq 0xf6a0
movb %al, -0x239(%rbp)
jmp 0xc3ad
movb -0x239(%rbp), %al
xorb $-0x1, %al
movb %al, -0x229(%rbp)
movb -0x229(%rbp), %al
movb %al, -0x23a(%rbp)
testb $0x1, -0x189(%rbp)
jne 0xc3d2
jmp 0xc3de
leaq -0x188(%rbp), %rdi
callq 0x3130
movb -0x23a(%rbp), %al
testb $0x1, %al
jne 0xc3ed
jmp 0xc50b
movq 0xfbd4(%rip), %rdi      # 0x1bfc8
leaq 0x7e6e(%rip), %rsi      # 0x14269
callq 0x31b0
movq %rax, -0x248(%rbp)
jmp 0xc409
movq -0x248(%rbp), %rdi
movq 0xfba1(%rip), %rsi      # 0x1bfb8
callq 0x31e0
jmp 0xc41e
movl $0x1, -0x80(%rbp)
jmp 0xc66c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xc46a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xc45e
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 0xc6c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xc6ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x3130
jmp 0xc6ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xc6ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x3130
jmp 0xc6ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
testb $0x1, -0x189(%rbp)
jne 0xc4fa
jmp 0xc506
leaq -0x188(%rbp), %rdi
callq 0x3130
jmp 0xc6ae
movq -0x148(%rbp), %rax
movq %rax, -0x250(%rbp)
leaq -0x1b8(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x30e0
jmp 0xc52e
movq -0x250(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0xfde0
movq %rax, -0x258(%rbp)
jmp 0xc54a
leaq -0x1b8(%rbp), %rdi
callq 0x3130
movq -0x258(%rbp), %rax
movq %rax, -0x198(%rbp)
movq -0x198(%rbp), %rax
movq %rax, -0x268(%rbp)
movq -0x10(%rbp), %rdi
callq 0xe190
movq %rax, -0x260(%rbp)
jmp 0xc584
movq -0x268(%rbp), %rax
movq -0x260(%rbp), %rcx
cmpq %rcx, %rax
je 0xc5ca
movq -0x198(%rbp), %rax
movq %rax, -0x278(%rbp)
movq -0x10(%rbp), %rdi
callq 0xe1b0
movq %rax, -0x270(%rbp)
jmp 0xc5b7
movq -0x278(%rbp), %rax
movq -0x270(%rbp), %rcx
cmpq %rcx, %rax
jne 0xc621
movq 0xf9f7(%rip), %rdi      # 0x1bfc8
leaq 0x7d2f(%rip), %rsi      # 0x14307
callq 0x31b0
movq %rax, -0x280(%rbp)
jmp 0xc5e6
movq -0x280(%rbp), %rdi
movq 0xf9c4(%rip), %rsi      # 0x1bfb8
callq 0x31e0
jmp 0xc5fb
movl $0x1, -0x80(%rbp)
jmp 0xc66c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x3130
jmp 0xc6ae
movq -0x148(%rbp), %rax
movq %rax, -0x288(%rbp)
leaq -0x1d8(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x30e0
jmp 0xc644
movq -0x288(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0xf780
jmp 0xc659
leaq -0x1d8(%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 $0x290, %rsp            # imm = 0x290
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x1d8(%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
nopl (%rax,%rax)