// File: mbourand[P]webserv/srcs/Methods/GetMethod.cpp
// Function: GetMethod::list_directory(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
std::list<std::string> GetMethod::list_directory(const std::string& realPath)
{
	std::list<std::string> list;
	std::list<std::string> files;
	DIR* dir;
	struct dirent *ent;

	if ((dir = opendir(realPath.c_str())) == NULL)
	{
		Logger::print("Error while trying to open directory", NULL, INFO, VERBOSE);
		throw std::invalid_argument("Error while trying to open directory");
	}
	while ((ent = readdir(dir)) != NULL)
	{
		if (ent->d_type == DT_DIR)
			list.push_back(std::string(ent->d_name) + "/");
		else
			files.push_back(std::string(ent->d_name));
	}
	closedir(dir);
	files.sort(compare_nocase);
	list.sort(compare_nocase);
	std::list<std::string>::iterator it = files.begin();
	files.insert(it, list.begin(), list.end());
	return files;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x128(%rbp)
movq %rdi, %rax
movq %rax, -0x130(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x13880
movq -0x128(%rbp), %rdi
movb $0x0, -0x31(%rbp)
callq 0x13880
movq -0x18(%rbp), %rdi
callq 0x92b0
movq %rax, %rdi
callq 0x9970
movq %rax, -0x120(%rbp)
jmp 0xf6db
movq -0x120(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0xf7df
leaq -0x79(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x9b10
movq -0x138(%rbp), %rdx
leaq 0x5ac36(%rip), %rsi     # 0x6a344
leaq -0x78(%rbp), %rdi
callq 0xa780
jmp 0xf719
xorl %ecx, %ecx
movl %ecx, %esi
leaq -0x78(%rbp), %rdi
movl %ecx, %edx
callq 0x138a0
jmp 0xf72a
leaq -0x78(%rbp), %rdi
callq 0x9c98
leaq -0x79(%rbp), %rdi
callq 0x9700
movl $0x10, %edi
callq 0x9340
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x140(%rbp)
leaq 0x5abea(%rip), %rsi     # 0x6a344
callq 0x9be0
jmp 0xf761
movq -0x140(%rbp), %rdi
movq 0x7f859(%rip), %rsi     # 0x8efc8
movq 0x7f842(%rip), %rdx     # 0x8efb8
callq 0x9aa0
jmp 0xfaaf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xfa91
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xf7b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x9c98
leaq -0x79(%rbp), %rdi
callq 0x9700
jmp 0xfa91
movq -0x140(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
callq 0x94c0
jmp 0xfa91
jmp 0xf7e1
movq -0x40(%rbp), %rdi
callq 0x9980
movq %rax, -0x148(%rbp)
jmp 0xf7f3
movq -0x148(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0xf9a8
movq -0x48(%rbp), %rax
movzbl 0x12(%rax), %eax
cmpl $0x4, %eax
jne 0xf8ff
movq -0x48(%rbp), %rax
addq $0x13, %rax
movq %rax, -0x158(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x9b10
movq -0x158(%rbp), %rsi
movq -0x150(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0xa780
jmp 0xf857
leaq 0x5b1fa(%rip), %rdx     # 0x6aa58
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x13970
jmp 0xf873
leaq -0x30(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x13930
jmp 0xf885
leaq -0xa0(%rbp), %rdi
callq 0x9c98
leaq -0xc0(%rbp), %rdi
callq 0x9c98
leaq -0xc1(%rbp), %rdi
callq 0x9700
jmp 0xf9a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xf8ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xf8e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x9c98
leaq -0xc0(%rbp), %rdi
callq 0x9c98
leaq -0xc1(%rbp), %rdi
callq 0x9700
jmp 0xfa91
movq -0x48(%rbp), %rax
addq $0x13, %rax
movq %rax, -0x168(%rbp)
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x9b10
movq -0x168(%rbp), %rsi
movq -0x160(%rbp), %rdx
leaq -0xe8(%rbp), %rdi
callq 0xa780
jmp 0xf93d
movq -0x128(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x13930
jmp 0xf952
leaq -0xe8(%rbp), %rdi
callq 0x9c98
leaq -0xe9(%rbp), %rdi
callq 0x9700
jmp 0xf9a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xf992
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x9c98
leaq -0xe9(%rbp), %rdi
callq 0x9700
jmp 0xfa91
jmp 0xf7e1
movq -0x40(%rbp), %rdi
callq 0x9a00
jmp 0xf9b3
movq -0x128(%rbp), %rdi
leaq -0x4a1(%rip), %rsi      # 0xf520
callq 0x139c0
jmp 0xf9c8
leaq -0x4af(%rip), %rsi      # 0xf520
leaq -0x30(%rbp), %rdi
callq 0x139c0
jmp 0xf9da
movq -0x128(%rbp), %rdi
callq 0xcc30
movq %rax, -0xf8(%rbp)
leaq -0x100(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0xcc60
leaq -0x30(%rbp), %rdi
movq %rdi, -0x178(%rbp)
callq 0xcc30
movq -0x178(%rbp), %rdi
movq %rax, -0x108(%rbp)
callq 0xccb0
movq -0x128(%rbp), %rdi
movq %rax, -0x110(%rbp)
movq -0x100(%rbp), %rsi
movq -0x108(%rbp), %rdx
movq -0x110(%rbp), %rcx
callq 0x13dd0
movq %rax, -0x170(%rbp)
jmp 0xfa54
movq -0x170(%rbp), %rax
movq %rax, -0x118(%rbp)
movb $0x1, -0x31(%rbp)
testb $0x1, -0x31(%rbp)
jne 0xfa78
movq -0x128(%rbp), %rdi
callq 0xceb0
leaq -0x30(%rbp), %rdi
callq 0xceb0
movq -0x130(%rbp), %rax
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
movq -0x128(%rbp), %rdi
callq 0xceb0
leaq -0x30(%rbp), %rdi
callq 0xceb0
movq -0x50(%rbp), %rdi
callq 0x9af0
nop