// File: /workspace/github_cpp_makefile_star2_O1/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 0xa592
movq %rax, %r14
leaq 0x10(%rsp), %rbp
leaq 0x38(%rsp), %r15
movq %r14, %rdi
callq 0x76d0
movq %rax, %r12
testq %rax, %rax
je 0xa53b
cmpb $0x4, 0x12(%r12)
jne 0xa3ea
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 0x306d0(%rip), %rsi     # 0x3aa94
callq 0x78d0
movq %rbp, (%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xa43b
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0xa442
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 0xa487
movq %rdx, 0x10(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, 0x20(%rax)
jmp 0xa48e
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 0xa4cc
movq %rdx, 0x10(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, 0x20(%rax)
jmp 0xa4d3
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 0xa374
movq 0x10(%rsp), %rsi
jmp 0xa52e
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 0xa516
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xa374
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0xa374
movq %r14, %rdi
callq 0x7730
leaq -0x2df(%rip), %rsi      # 0xa26b
movq %rbx, %rdi
callq 0xdf6c
leaq -0x2ee(%rip), %rsi      # 0xa26b
leaq 0x20(%rsp), %rdi
callq 0xdf6c
movq (%rbx), %rsi
leaq 0x20(%rsp), %rcx
movq (%rcx), %rdx
movq %rbx, %rdi
callq 0xe1de
leaq 0x20(%rsp), %rdi
callq 0x96d8
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 0x2fdde(%rip), %rsi     # 0x3a380
leaq 0x2fdfb(%rip), %rdx     # 0x3a3a4
leaq 0x58(%rsp), %rdi
callq 0x80f4
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xded8
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0xa5da
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x74b0
movl $0x10, %edi
callq 0x7260
movq %rax, %r15
leaq 0x2fd92(%rip), %rsi     # 0x3a380
movq %rax, %rdi
callq 0x78c0
movq 0x439cb(%rip), %rsi     # 0x4dfc8
movq 0x439ac(%rip), %rdx     # 0x4dfb0
movq %r15, %rdi
callq 0x77d0
movq %rax, %r14
movq %r15, %rdi
callq 0x7390
jmp 0xa689
movq %rax, %r14
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0xa689
movq 0x68(%rsp), %rsi
jmp 0xa67c
jmp 0xa686
jmp 0xa686
jmp 0xa686
movq %rax, %r14
movq (%rsp), %rdi
cmpq %rbp, %rdi
je 0xa689
movq 0x10(%rsp), %rsi
jmp 0xa67c
movq %rax, %r14
jmp 0xa668
jmp 0xa686
jmp 0xa686
movq %rax, %r14
movq (%rsp), %rdi
cmpq %rbp, %rdi
je 0xa668
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xa689
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0xa689
movq %rax, %r14
movq %rbx, %rdi
callq 0x96d8
leaq 0x20(%rsp), %rdi
callq 0x96d8
movq %r14, %rdi
callq 0x7810
nop