// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
leaq 0x20(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x10(%rax)
movq %rdi, 0x8(%rdi)
movq %rdi, (%rdi)
movq %rcx, 0x10(%rdi)
movq (%rdx), %rdi
callq 0x76a0
testq %rax, %rax
je 0xa568
movq %rax, %r14
leaq 0x10(%rsp), %rbp
leaq 0x38(%rsp), %r15
movq %r14, %rdi
callq 0x76d0
movq %rax, %r12
testq %rax, %rax
je 0xa511
cmpb $0x4, 0x12(%r12)
jne 0xa3c0
leaq 0x13(%r12), %r13
leaq 0x48(%rsp), %rax
movq %rax, 0x38(%rsp)
movq %r13, %rdi
callq 0x7220
leaq (%r12,%rax), %rdx
addq $0x13, %rdx
movq %r15, %rdi
movq %r13, %rsi
callq 0x80f4
movq %r15, %rdi
leaq 0x306fa(%rip), %rsi     # 0x3aa94
callq 0x78d0
movq %rbp, (%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xa411
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0xa418
leaq 0x13(%r12), %r13
movq %rbp, (%rsp)
movq %r13, %rdi
callq 0x7220
leaq (%r12,%rax), %rdx
addq $0x13, %rdx
movq %rsp, %rdi
movq %r13, %rsi
callq 0x80f4
movl $0x30, %edi
callq 0x74a0
movq %rax, %rcx
addq $0x20, %rcx
movq %rcx, 0x10(%rax)
movq (%rsp), %rdx
cmpq %rbp, %rdx
je 0xa45d
movq %rdx, 0x10(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, 0x20(%rax)
jmp 0xa464
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
movq %rdx, 0x8(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl $0x30, %edi
callq 0x74a0
movq %rax, %rcx
addq $0x20, %rcx
movq %rcx, 0x10(%rax)
movq (%rsp), %rdx
cmpq %rbp, %rdx
je 0xa4a2
movq %rdx, 0x10(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, 0x20(%rax)
jmp 0xa4a9
movups (%rbp), %xmm0
movups %xmm0, (%rcx)
movq 0x8(%rsp), %rcx
movq %rcx, 0x18(%rax)
movq %rbp, (%rsp)
movq $0x0, 0x8(%rsp)
movb $0x0, 0x10(%rsp)
movq %rax, %rdi
movq %rbx, %rsi
callq 0x7090
incq 0x10(%rbx)
movq (%rsp), %rdi
cmpq %rbp, %rdi
je 0xa34a
movq 0x10(%rsp), %rsi
jmp 0xa504
movups (%rbp), %xmm0
movups %xmm0, (%rcx)
movq 0x8(%rsp), %rcx
movq %rcx, 0x18(%rax)
movq %rbp, (%rsp)
movq $0x0, 0x8(%rsp)
movb $0x0, 0x10(%rsp)
movq %rax, %rdi
leaq 0x20(%rsp), %rsi
callq 0x7090
incq 0x30(%rsp)
movq (%rsp), %rdi
cmpq %rbp, %rdi
je 0xa4ec
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xa34a
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0xa34a
movq %r14, %rdi
callq 0x7730
leaq -0x2d5(%rip), %rsi      # 0xa24b
movq %rbx, %rdi
callq 0xdf38
leaq -0x2e4(%rip), %rsi      # 0xa24b
leaq 0x20(%rsp), %rdi
callq 0xdf38
movq (%rbx), %rsi
leaq 0x20(%rsp), %rcx
movq (%rcx), %rdx
movq %rbx, %rdi
callq 0xe18c
leaq 0x20(%rsp), %rdi
callq 0x96b6
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x2fe08(%rip), %rsi     # 0x3a380
leaq 0x2fe25(%rip), %rdx     # 0x3a3a4
leaq 0x58(%rsp), %rdi
callq 0x80f4
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xdea4
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0xa5b0
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x74b0
movl $0x10, %edi
callq 0x7260
movq %rax, %r15
leaq 0x2fdbc(%rip), %rsi     # 0x3a380
movq %rax, %rdi
callq 0x78c0
movq 0x439f5(%rip), %rsi     # 0x4dfc8
movq 0x439d6(%rip), %rdx     # 0x4dfb0
movq %r15, %rdi
callq 0x77d0
movq %rax, %r14
movq %r15, %rdi
callq 0x7390
jmp 0xa65f
movq %rax, %r14
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0xa65f
movq 0x68(%rsp), %rsi
jmp 0xa652
jmp 0xa65c
jmp 0xa65c
jmp 0xa65c
movq %rax, %r14
movq (%rsp), %rdi
cmpq %rbp, %rdi
je 0xa65f
movq 0x10(%rsp), %rsi
jmp 0xa652
movq %rax, %r14
jmp 0xa63e
jmp 0xa65c
jmp 0xa65c
movq %rax, %r14
movq (%rsp), %rdi
cmpq %rbp, %rdi
je 0xa63e
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xa65f
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0xa65f
movq %rax, %r14
movq %rbx, %rdi
callq 0x96b6
leaq 0x20(%rsp), %rdi
callq 0x96b6
movq %r14, %rdi
callq 0x7810
nop