// File: /workspace/github_cpp_makefile_star2_O2/llefranc[P]42_webserv/srcs/main.cpp
// Function: main
int main(int ac, char **av)
{
	if (ac != 2)
	{
		printLog(" >> Fatal error: wrong arguments\n");
		exit(EXIT_FAILURE);
	}
	
	// ** CONFIRURATION FILE PARSER PART **
	FileParser conf(av[1]);
	std::map<int, std::vector<ServerInfo> > m_srv;

	try{
		m_srv = conf.getConfigFile();
	}
	catch (std::exception &errmsg){
		std::cout << errmsg.what();
		exit(EXIT_FAILURE);
	}

	// ** SERVER PART **
	// boucle pour add tous les sockets >> ou les mettre dans la boucle en dessous ?
	std::vector<int> sockArray;
	for (std::map<int, std::vector<ServerInfo> >::iterator it = m_srv.begin(); it != m_srv.end(); it++)
		sockArray.push_back(it->first);

	HttpServer server;

	// Creating sockets and binding them to a port
	try
	{
		for (size_t i = 0; i < sockArray.size(); ++i)
			server.addServerSocket(ServerSocket(sockArray[i], 5));
			
		server.etablishConnection(m_srv);
	}
	catch (std::exception& e)
	{
		printLog(" >> Exception occured " + std::string(e.what()) + "\n");
		exit(EXIT_FAILURE);
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x4f0, %rsp            # imm = 0x4F0
cmpl $0x2, %edi
jne 0x4c9d
movq 0x8(%rsi), %rsi
leaq -0x510(%rbp), %rbx
movq %rbx, %rdi
callq 0x64b0
leaq -0x98(%rbp), %r15
andl $0x0, (%r15)
andq $0x0, 0x8(%r15)
movq %r15, 0x10(%r15)
movq %r15, 0x18(%r15)
andq $0x0, 0x20(%r15)
movq %rbx, %rdi
callq 0x69ca
leaq -0xa0(%rbp), %rdi
movq %rax, %rsi
callq 0x4f8e
xorps %xmm0, %xmm0
leaq -0x40(%rbp), %rbx
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
movq -0x88(%rbp), %r14
cmpq %r15, %r14
je 0x4bf2
leaq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0x4f12
movq %r14, %rdi
callq 0x42f0
movq %rax, %r14
jmp 0x4bd4
leaq -0x238(%rbp), %rdi
callq 0x9704
xorl %r12d, %r12d
leaq -0x4c(%rbp), %rbx
pushq $0x5
popq %r14
leaq -0x238(%rbp), %r15
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rcx, %r12
jae 0x4c4b
movl (%rax,%r12,4), %esi
movq %rbx, %rdi
movl %r14d, %edx
callq 0xa898
movq %r15, %rdi
movq %rbx, %rsi
callq 0x988c
movq %rbx, %rdi
callq 0xa8be
incq %r12
jmp 0x4c10
leaq -0x238(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x9928
leaq -0x238(%rbp), %rdi
callq 0x9732
leaq -0x40(%rbp), %rdi
callq 0x5656
leaq -0xa0(%rbp), %rdi
callq 0x55a0
leaq -0x510(%rbp), %rdi
callq 0x695c
xorl %eax, %eax
addq $0x4f0, %rsp            # imm = 0x4F0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc360(%rip), %rsi      # 0x11004
leaq -0x510(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x4ec8
leaq 0xca3c(%rip), %rsi      # 0x116fa
leaq -0x238(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x4ec8
leaq -0x510(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x10271
leaq -0x238(%rbp), %rdi
callq 0x47d8
leaq -0x510(%rbp), %rdi
jmp 0x4e30
movq %rax, %rbx
leaq -0x238(%rbp), %rdi
callq 0x47d8
jmp 0x4d0d
movq %rax, %rbx
leaq -0x510(%rbp), %rdi
callq 0x47d8
jmp 0x4ec0
movq %rax, %rbx
jmp 0x4ec0
jmp 0x4d7c
jmp 0x4e9c
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x4ea8
movq %rbx, %rdi
callq 0x41e0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq 0x1427f(%rip), %rdi     # 0x18fd0
movq %rax, %rsi
callq 0x4420
jmp 0x4e35
movq %rax, %rbx
callq 0x4680
jmp 0x4ea8
movq %rdx, %r14
movq %rax, %rbx
leaq -0x4c(%rbp), %rdi
callq 0xa8be
jmp 0x4d82
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x1, %r14d
jne 0x4e86
movq %rbx, %rdi
callq 0x41e0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
leaq -0xe0(%rbp), %rdi
leaq -0x22(%rbp), %rdx
movq %rax, %rsi
callq 0x4ec8
leaq 0xc26f(%rip), %rsi      # 0x11026
leaq -0x100(%rbp), %rdi
leaq -0xe0(%rbp), %rdx
callq 0x4f60
leaq 0xc5d2(%rip), %rdx      # 0x113a3
leaq -0x70(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x4f37
leaq 0xc912(%rip), %rsi      # 0x116fa
leaq -0xc0(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x4ec8
leaq -0x70(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x10271
leaq -0xc0(%rbp), %rdi
callq 0x47d8
leaq -0x70(%rbp), %rdi
callq 0x47d8
leaq -0x100(%rbp), %rdi
callq 0x47d8
leaq -0xe0(%rbp), %rdi
callq 0x47d8
pushq $0x1
popq %rdi
callq 0x44e0
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x47d8
jmp 0x4e51
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x47d8
jmp 0x4e5f
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
callq 0x47d8
jmp 0x4e70
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x47d8
jmp 0x4e81
movq %rax, %rbx
callq 0x4680
leaq -0x238(%rbp), %rdi
callq 0x9732
jmp 0x4e9f
movq %rax, %rdi
callq 0x4f03
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x5656
leaq -0xa0(%rbp), %rdi
callq 0x55a0
leaq -0x510(%rbp), %rdi
callq 0x695c
movq %rbx, %rdi
callq 0x46d0