// File: /workspace/github_cpp_makefile_star2_O1/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 0x3954
leaq -0xb0(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x8272(%rip), %rsi      # 0xe173
leaq 0x826c(%rip), %rdx      # 0xe174
leaq -0xc0(%rbp), %rdi
callq 0xabe4
leaq -0x68(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq 0x34ec
movq -0xc0(%rbp), %rdi
cmpq %r15, %rdi
je 0x5f3c
callq 0x31a0
movq -0xe0(%rbp), %rdi
cmpq %r14, %rdi
je 0x5f4d
callq 0x31a0
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rax
subq %rdi, %rax
cmpq $0x40, %rax
jne 0x5fb9
leaq 0x824b(%rip), %rsi      # 0xe1b0
callq 0x3080
testl %eax, %eax
je 0x5fb9
movq 0xd05b(%rip), %rbx      # 0x12fd0
leaq 0x8237(%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 0xd029(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
jmp 0x6298
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 0x3954
leaq -0xa0(%rbp), %rsi
movq %rbx, %rdi
callq 0xad2e
movq %rax, %r14
movq -0xa0(%rbp), %rdi
cmpq %r15, %rdi
je 0x6002
callq 0x31a0
movq -0x60(%rbp), %rdi
addq $-0x20, %rdi
leaq 0x8163(%rip), %rsi      # 0xe174
callq 0x3080
testl %eax, %eax
je 0x6032
movq -0x60(%rbp), %rdi
addq $-0x20, %rdi
leaq 0x8187(%rip), %rsi      # 0xe1b0
callq 0x3080
testl %eax, %eax
jne 0x603d
movq %rbx, %rdi
callq 0xad1a
movq %rax, %r14
testq %r14, %r14
je 0x6068
movq -0x68(%rbp), %rdi
leaq 0x8163(%rip), %rsi      # 0xe1b0
callq 0x3080
testl %eax, %eax
je 0x60b3
movq %r14, %rdi
callq 0xbfdc
movq %r14, %rdi
callq 0xbf92
jmp 0x60c3
movq 0xcf61(%rip), %rbx      # 0x12fd0
leaq 0x8110(%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 0xcf2f(%rip), %rdi      # 0x12fd0
callq 0x3030
movq %rax, %rdi
callq 0x3130
jmp 0x6298
movq %r14, %rdi
callq 0xbf92
movq %r14, %rdi
callq 0xbfdc
leaq -0x80(%rbp), %rdi
movq %r14, %rsi
callq 0xc026
movq -0x80(%rbp), %r12
movq -0x78(%rbp), %rbx
cmpq %rbx, %r12
je 0x628a
movq 0xcee9(%rip), %rcx      # 0x12fd0
leaq -0x50(%rbp), %r15
movq (%r12), %r14
testq %r14, %r14
je 0x6118
movq %r14, %rdi
leaq 0xcc72(%rip), %rsi      # 0x12d70
leaq 0xcc7b(%rip), %rdx      # 0x12d80
xorl %ecx, %ecx
callq 0x31f0
movq 0xcebd(%rip), %rcx      # 0x12fd0
movq %rax, %r13
jmp 0x611b
xorl %r13d, %r13d
testq %r13, %r13
je 0x61c7
movl $0x3, %edx
movq %rcx, %r14
movq %rcx, %rdi
leaq 0x8093(%rip), %rsi      # 0xe1c9
callq 0x3200
movb $0x9, -0x50(%rbp)
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x3200
movq %rax, %r14
movq %r15, %rdi
movq %r13, %rsi
callq 0xb396
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %r14, %rdi
callq 0x3200
movb $0x9, -0x29(%rbp)
movl $0x1, %edx
movq %rax, %rdi
leaq -0x29(%rbp), %rsi
callq 0x3200
movq %rax, %r14
movq (%r13), %rax
movq %r13, %rdi
callq *(%rax)
movq %r14, %rdi
movl %eax, %esi
callq 0x3290
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
jmp 0x6264
movl $0x4, %edx
movq %rcx, %r13
movq %rcx, %rdi
leaq 0x7ff4(%rip), %rsi      # 0xe1cd
callq 0x3200
movb $0x9, -0x50(%rbp)
movl $0x1, %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0x3200
movq %rax, %r13
movq %r15, %rdi
movq %r14, %rsi
callq 0xb396
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 (%r14), %rax
movq %r14, %rdi
callq *(%rax)
movq %r13, %rdi
movl %eax, %esi
callq 0x3290
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x6276
callq 0x31a0
addq $0x8, %r12
cmpq %rbx, %r12
movq 0xcd4c(%rip), %rcx      # 0x12fd0
jne 0x60eb
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x6298
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 0x62f4
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
cmpq %r15, %rdi
jne 0x6322
jmp 0x6327
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
cmpq %r15, %rdi
je 0x62df
callq 0x31a0
jmp 0x62df
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
cmpq %r14, %rdi
je 0x6330
callq 0x31a0
jmp 0x6330
jmp 0x62f4
movq %rax, %rbx
jmp 0x6327
jmp 0x62fd
jmp 0x62fd
movq %rax, %rbx
jmp 0x6319
jmp 0x6304
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x6319
callq 0x31a0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x6327
callq 0x31a0
leaq -0x68(%rbp), %rdi
callq 0x36b8
movq %rbx, %rdi
callq 0x32b0