// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %rbx
leaq -0xd0(%rbp), %r14
movq %r14, -0x10(%r14)
movq 0x28(%rdi), %rsi
movq 0x30(%rdi), %rdx
addq %rsi, %rdx
leaq -0xe0(%rbp), %rdi
callq 0x392c
leaq -0xb0(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x8286(%rip), %rsi      # 0xe173
leaq 0x8280(%rip), %rdx      # 0xe174
leaq -0xc0(%rbp), %rdi
callq 0xab8a
leaq -0x68(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq 0x34ec
movq -0xc0(%rbp), %rdi
cmpq %r15, %rdi
je 0x5f28
callq 0x31a0
movq -0xe0(%rbp), %rdi
cmpq %r14, %rdi
je 0x5f39
callq 0x31a0
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rax
movq %rax, %rcx
subq %rdi, %rcx
cmpq $0x40, %rcx
jne 0x5fac
leaq 0x825c(%rip), %rsi      # 0xe1b0
callq 0x3080
testl %eax, %eax
je 0x5fa8
movq 0xd06c(%rip), %rbx      # 0x12fd0
leaq 0x8248(%rip), %rsi      # 0xe1b3
movl $0x15, %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 0xd03a(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
jmp 0x6288
movq -0x60(%rbp), %rax
leaq -0x90(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x20(%rax), %rsi
movq -0x18(%rax), %rdx
addq %rsi, %rdx
leaq -0xa0(%rbp), %rdi
callq 0x392c
leaq -0xa0(%rbp), %rsi
movq %rbx, %rdi
callq 0xacd6
movq %rax, %r14
movq -0xa0(%rbp), %rdi
cmpq %r15, %rdi
je 0x5ff1
callq 0x31a0
movq -0x60(%rbp), %rdi
addq $-0x20, %rdi
leaq 0x8174(%rip), %rsi      # 0xe174
callq 0x3080
testl %eax, %eax
je 0x6071
movq -0x60(%rbp), %rdi
addq $-0x20, %rdi
leaq 0x8198(%rip), %rsi      # 0xe1b0
callq 0x3080
testl %eax, %eax
je 0x6071
testq %r14, %r14
jne 0x607c
movq 0xcfa3(%rip), %rbx      # 0x12fd0
leaq 0x8152(%rip), %rsi      # 0xe186
movl $0x29, %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 0xcf71(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
jmp 0x6288
movq %rbx, %rdi
callq 0xacc2
movq %rax, %r14
movq -0x68(%rbp), %rdi
leaq 0x8129(%rip), %rsi      # 0xe1b0
callq 0x3080
testl %eax, %eax
je 0x60a2
movq %r14, %rdi
callq 0xbf92
movq %r14, %rdi
callq 0xbf48
jmp 0x60b2
movq %r14, %rdi
callq 0xbf48
movq %r14, %rdi
callq 0xbf92
leaq -0x80(%rbp), %rdi
movq %r14, %rsi
callq 0xbfdc
movq -0x80(%rbp), %rbx
movq -0x78(%rbp), %r14
cmpq %r14, %rbx
je 0x627b
movq 0xcefa(%rip), %rcx      # 0x12fd0
leaq -0x50(%rbp), %r12
movq (%rbx), %r15
testq %r15, %r15
je 0x61b4
movq %r15, %rdi
leaq 0xcc80(%rip), %rsi      # 0x12d70
leaq 0xcc89(%rip), %rdx      # 0x12d80
xorl %ecx, %ecx
callq 0x31f0
movq 0xcecb(%rip), %rcx      # 0x12fd0
testq %rax, %rax
je 0x61b4
movq %rax, %r13
movl $0x3, %edx
movq %rcx, %r15
movq %rcx, %rdi
leaq 0x80a6(%rip), %rsi      # 0xe1c9
callq 0x3200
movb $0x9, -0x50(%rbp)
movl $0x1, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x3200
movq %rax, %r15
movq %r12, %rdi
movq %r13, %rsi
callq 0xb30a
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %r15, %rdi
callq 0x3200
movb $0x9, -0x29(%rbp)
movl $0x1, %edx
movq %rax, %rdi
leaq -0x29(%rbp), %rsi
callq 0x3200
movq %rax, %r15
movq (%r13), %rax
movq %r13, %rdi
callq *(%rax)
movq %r15, %rdi
movl %eax, %esi
callq 0x3290
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
jmp 0x6251
movl $0x4, %edx
movq %rcx, %r13
movq %rcx, %rdi
leaq 0x8007(%rip), %rsi      # 0xe1cd
callq 0x3200
movb $0x9, -0x50(%rbp)
movl $0x1, %edx
movq %r13, %rdi
movq %r12, %rsi
callq 0x3200
movq %rax, %r13
movq %r12, %rdi
movq %r15, %rsi
callq 0xb30a
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %r13, %rdi
callq 0x3200
movb $0x9, -0x29(%rbp)
movl $0x1, %edx
movq %rax, %rdi
leaq -0x29(%rbp), %rsi
callq 0x3200
movq %rax, %r13
movq (%r15), %rax
movq %r15, %rdi
callq *(%rax)
movq %r13, %rdi
movl %eax, %esi
callq 0x3290
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x6263
callq 0x31a0
addq $0x8, %rbx
cmpq %r14, %rbx
movq 0xcd5f(%rip), %rcx      # 0x12fd0
jne 0x60da
movq -0x80(%rbp), %rbx
testq %rbx, %rbx
je 0x6288
movq %rbx, %rdi
callq 0x31a0
leaq -0x68(%rbp), %rdi
callq 0x36b8
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x62e4
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
cmpq %r15, %rdi
jne 0x6312
jmp 0x6317
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
cmpq %r15, %rdi
je 0x62cf
callq 0x31a0
jmp 0x62cf
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
cmpq %r14, %rdi
je 0x6320
callq 0x31a0
jmp 0x6320
jmp 0x62e4
movq %rax, %rbx
jmp 0x6317
jmp 0x62ed
jmp 0x62ed
movq %rax, %rbx
jmp 0x6309
jmp 0x62f4
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x6309
callq 0x31a0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x6317
callq 0x31a0
leaq -0x68(%rbp), %rdi
callq 0x36b8
movq %rbx, %rdi
callq 0x32b0