// File: talyerushalmy[P]SimpleFileSystem/src/Commands.cpp
// Function: LsCommand::execute(FileSystem&)
void LsCommand::execute(FileSystem& fs)
{
	std::vector<std::string> words = StringTools::split(this->getArgs(), " ");
	
	if (words.size() != 1 && (words.size() == 2 && words[0] != "-s"))
	{
		std::cout << "Usage: ls [-s] <path>" << std::endl;
		return;
	}

	Directory* dir = fs.getDirectoryFromPath(words.back());
	if (words.back() == "" || words.back() == "-s")
		dir = &fs.getWorkingDirectory();

	if (!dir)
	{
		std::cout << "The system cannot find the path specified" << std::endl;
		return;
	}

	if (words[0] == "-s")
	{
		dir->sortByName();
		dir->sortBySize();
	}
	else
	{
		dir->sortBySize();
		dir->sortByName();
	}

	for (BaseFile* bf : dir->getChildren())
	{
		if (Directory* d = dynamic_cast<Directory*>(bf))
			std::cout << "DIR" << '\t' << d->getName() << '\t' << d->getSize() << std::endl;
		else
			std::cout << "FILE" << '\t' << bf->getName() << '\t' << bf->getSize() << std::endl;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x7c70
leaq -0x69(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x3310
movq -0x130(%rbp), %rdx
leaq 0xbd6d(%rip), %rsi      # 0x1414b
leaq -0x68(%rbp), %rdi
callq 0x3260
jmp 0x83e9
leaq -0x28(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x3550
jmp 0x83fc
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
je 0x84f8
leaq -0x28(%rbp), %rdi
callq 0x4020
cmpq $0x2, %rax
jne 0x84f8
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0xd9b0
movq %rax, %rdi
leaq 0xbd34(%rip), %rsi      # 0x14188
callq 0xd9d0
movb %al, -0x131(%rbp)
jmp 0x8461
movb -0x131(%rbp), %al
testb $0x1, %al
jne 0x8470
jmp 0x84f8
movq 0x13b51(%rip), %rdi     # 0x1bfc8
leaq 0xbd0d(%rip), %rsi      # 0x1418b
callq 0x31b0
movq %rax, -0x140(%rbp)
jmp 0x848c
movq -0x140(%rbp), %rdi
movq 0x13b1e(%rip), %rsi     # 0x1bfb8
callq 0x31e0
jmp 0x84a1
movl $0x1, -0x80(%rbp)
jmp 0x89ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x84d0
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 0x89c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x89be
movq -0x10(%rbp), %rax
movq %rax, -0x148(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xda00
movq %rax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x30e0
jmp 0x851d
movq -0x148(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0xe1f0
movq %rax, -0x150(%rbp)
jmp 0x8539
leaq -0xa8(%rbp), %rdi
callq 0x3130
movq -0x150(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xda00
movq %rax, %rdi
leaq 0xbbe6(%rip), %rsi      # 0x1414c
callq 0xd980
movb %al, -0x151(%rbp)
jmp 0x8573
movb -0x151(%rbp), %al
testb $0x1, %al
jne 0x85ab
jmp 0x857f
leaq -0x28(%rbp), %rdi
callq 0xda00
movq %rax, %rdi
leaq 0xbbf6(%rip), %rsi      # 0x14188
callq 0xd980
movb %al, -0x152(%rbp)
jmp 0x859f
movb -0x152(%rbp), %al
testb $0x1, %al
jne 0x85ab
jmp 0x85ea
movq -0x10(%rbp), %rdi
callq 0xe1b0
movq %rax, -0x160(%rbp)
jmp 0x85bd
movq -0x160(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x85ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x3130
jmp 0x89be
cmpq $0x0, -0x88(%rbp)
jne 0x8631
movq 0x139cd(%rip), %rdi     # 0x1bfc8
leaq 0xbb5c(%rip), %rsi      # 0x1415e
callq 0x31b0
movq %rax, -0x168(%rbp)
jmp 0x8610
movq -0x168(%rbp), %rdi
movq 0x1399a(%rip), %rsi     # 0x1bfb8
callq 0x31e0
jmp 0x8625
movl $0x1, -0x80(%rbp)
jmp 0x89ac
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0xd9b0
movq %rax, %rdi
leaq 0xbb40(%rip), %rsi      # 0x14188
callq 0xd980
movb %al, -0x169(%rbp)
jmp 0x8655
movb -0x169(%rbp), %al
testb $0x1, %al
jne 0x8661
jmp 0x867f
movq -0x88(%rbp), %rdi
callq 0xf940
jmp 0x866f
movq -0x88(%rbp), %rdi
callq 0xf990
jmp 0x867d
jmp 0x869d
movq -0x88(%rbp), %rdi
callq 0xf990
jmp 0x868d
movq -0x88(%rbp), %rdi
callq 0xf940
jmp 0x869b
jmp 0x869d
movq -0x88(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
callq 0xf9e0
jmp 0x86b2
leaq -0xc8(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
callq 0xda40
movq %rax, -0xd0(%rbp)
movq -0xb0(%rbp), %rdi
callq 0xda70
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0xdaa0
testb $0x1, %al
jne 0x8715
movl $0x2, -0x80(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0xdb20
jmp 0x89a5
leaq -0xd0(%rbp), %rdi
callq 0xdae0
movq (%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0x178(%rbp)
cmpq $0x0, %rax
je 0x8766
movq -0x178(%rbp), %rdi
leaq 0x13613(%rip), %rsi     # 0x1bd60
leaq 0x1361c(%rip), %rdx     # 0x1bd70
xorl %eax, %eax
movl %eax, %ecx
callq 0x3210
movq %rax, -0x180(%rbp)
jmp 0x8771
xorl %eax, %eax
movq %rax, -0x180(%rbp)
jmp 0x8771
movq -0x180(%rbp), %rax
movq %rax, -0xe8(%rbp)
cmpq $0x0, -0xe8(%rbp)
je 0x8894
movq 0x13834(%rip), %rdi     # 0x1bfc8
leaq 0xba06(%rip), %rsi      # 0x141a1
callq 0x31b0
movq %rax, -0x188(%rbp)
jmp 0x87a9
movq -0x188(%rbp), %rdi
movl $0x9, %esi
callq 0x3220
movq %rax, -0x190(%rbp)
jmp 0x87c3
movq -0xe8(%rbp), %rsi
leaq -0x108(%rbp), %rdi
callq 0xeb30
jmp 0x87d8
movq -0x190(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x3180
movq %rax, -0x198(%rbp)
jmp 0x87f4
movq -0x198(%rbp), %rdi
movl $0x9, %esi
callq 0x3220
movq %rax, -0x1a0(%rbp)
jmp 0x880e
movq -0xe8(%rbp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movl %eax, -0x1a4(%rbp)
jmp 0x8825
movl -0x1a4(%rbp), %esi
movq -0x1a0(%rbp), %rdi
callq 0x32f0
movq %rax, -0x1b0(%rbp)
jmp 0x8840
movq -0x1b0(%rbp), %rdi
movq 0x1376a(%rip), %rsi     # 0x1bfb8
callq 0x31e0
jmp 0x8855
leaq -0x108(%rbp), %rdi
callq 0x3130
jmp 0x8984
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x8997
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x3130
jmp 0x8997
movq 0x1372d(%rip), %rdi     # 0x1bfc8
leaq 0xb903(%rip), %rsi      # 0x141a5
callq 0x31b0
movq %rax, -0x1b8(%rbp)
jmp 0x88b0
movq -0x1b8(%rbp), %rdi
movl $0x9, %esi
callq 0x3220
movq %rax, -0x1c0(%rbp)
jmp 0x88ca
movq -0xe0(%rbp), %rsi
leaq -0x128(%rbp), %rdi
callq 0xeb30
jmp 0x88df
movq -0x1c0(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x3180
movq %rax, -0x1c8(%rbp)
jmp 0x88fb
movq -0x1c8(%rbp), %rdi
movl $0x9, %esi
callq 0x3220
movq %rax, -0x1d0(%rbp)
jmp 0x8915
movq -0xe0(%rbp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movl %eax, -0x1d4(%rbp)
jmp 0x892c
movl -0x1d4(%rbp), %esi
movq -0x1d0(%rbp), %rdi
callq 0x32f0
movq %rax, -0x1e0(%rbp)
jmp 0x8947
movq -0x1e0(%rbp), %rdi
movq 0x13663(%rip), %rsi     # 0x1bfb8
callq 0x31e0
jmp 0x895c
leaq -0x128(%rbp), %rdi
callq 0x3130
jmp 0x8984
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x3130
jmp 0x8997
jmp 0x8986
leaq -0xd0(%rbp), %rdi
callq 0xdb00
jmp 0x86e6
leaq -0xc8(%rbp), %rdi
callq 0xdb20
jmp 0x89be
movl $0x0, -0x80(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x37e0
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
leaq -0x28(%rbp), %rdi
callq 0x37e0
movq -0x78(%rbp), %rdi
callq 0x3300