// File: /workspace/github_cpp_makefile_star2_O1/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 %rbx
subq $0x4f8, %rsp            # imm = 0x4F8
cmpl $0x2, %edi
jne 0x4ea0
movq 0x8(%rsi), %rsi
leaq -0x510(%rbp), %rbx
movq %rbx, %rdi
callq 0x6920
leaq -0xf8(%rbp), %r15
movl $0x0, (%r15)
xorl %eax, %eax
movq %rax, 0x8(%r15)
movq %r15, 0x10(%r15)
movq %r15, 0x18(%r15)
movq %rax, 0x20(%r15)
movq %rbx, %rdi
callq 0x7018
leaq -0x100(%rbp), %rdi
movq %rax, %rsi
callq 0x5250
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
movq -0xe8(%rbp), %rbx
cmpq %r15, %rbx
je 0x4de2
leaq -0x40(%rbp), %r14
leaq 0x20(%rbx), %rdx
movq -0x38(%rbp), %rsi
cmpq -0x30(%rbp), %rsi
je 0x4dca
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x38(%rbp)
jmp 0x4dd2
movq %r14, %rdi
callq 0x582a
movq %rbx, %rdi
callq 0x42a0
movq %rax, %rbx
cmpq %r15, %rax
jne 0x4dae
leaq -0x238(%rbp), %rdi
callq 0xa44c
movq -0x40(%rbp), %rax
cmpq %rax, -0x38(%rbp)
je 0x4e44
xorl %r15d, %r15d
leaq -0x8c(%rbp), %rbx
leaq -0x238(%rbp), %r14
movl (%rax,%r15,4), %esi
movq %rbx, %rdi
movl $0x5, %edx
callq 0xbaf4
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa5fe
movq %rbx, %rdi
callq 0xbb1c
incq %r15
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rcx, %r15
jb 0x4e09
leaq -0x238(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0xa6e2
leaq -0x238(%rbp), %rdi
callq 0xa47c
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x4e78
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x43e0
leaq -0x100(%rbp), %rdi
callq 0x5778
leaq -0x510(%rbp), %rdi
callq 0x6f74
xorl %eax, %eax
addq $0x4f8, %rsp            # imm = 0x4F8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq -0x500(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x1016e(%rip), %rsi     # 0x15020
leaq 0x10188(%rip), %rdx     # 0x15041
leaq -0x510(%rbp), %rdi
callq 0x5790
leaq -0x228(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x1082a(%rip), %rdx     # 0x15701
leaq -0x238(%rbp), %rdi
movq %rdx, %rsi
callq 0x5790
leaq -0x510(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x13ed0
leaq -0x238(%rbp), %rdi
callq 0x47a8
leaq -0x510(%rbp), %rdi
jmp 0x50ae
movq %rax, %rbx
movq -0x238(%rbp), %rdi
cmpq %r15, %rdi
je 0x4f34
movq -0x228(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0x4f34
movq %rax, %rbx
movq -0x510(%rbp), %rdi
cmpq %r14, %rdi
je 0x517a
movq -0x500(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0x517a
movq %rax, %rbx
jmp 0x517a
jmp 0x4faa
jmp 0x4fa2
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x5162
movq %rbx, %rdi
callq 0x41d0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq 0x18040(%rip), %rdi     # 0x1cfc8
movq %rax, %rsi
callq 0x43c0
jmp 0x50b3
movq %rax, %rbx
callq 0x4660
jmp 0x5162
movq %rax, %rbx
jmp 0x514d
movq %rdx, %r14
movq %rax, %rbx
jmp 0x4fc4
movq %rdx, %r14
movq %rax, %rbx
leaq -0x8c(%rbp), %rdi
callq 0xbb1c
cmpl $0x1, %r14d
jne 0x5141
movq %rbx, %rdi
callq 0x41d0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
leaq -0xb0(%rbp), %rdi
leaq -0x19(%rbp), %rdx
movq %rax, %rsi
callq 0x518a
leaq 0x10049(%rip), %rsi     # 0x15042
leaq -0xd0(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
callq 0x51d5
leaq 0x103ac(%rip), %rsi     # 0x153bf
leaq -0xd0(%rbp), %rdi
callq 0x4760
leaq -0x50(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x503f
movups (%rcx), %xmm0
movups %xmm0, (%r14)
jmp 0x504a
movq %rdx, -0x60(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x50(%rbp)
movq 0x8(%rax), %rdx
movq %rdx, -0x58(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x70(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x10691(%rip), %rdx     # 0x15701
leaq -0x80(%rbp), %rdi
movq %rdx, %rsi
callq 0x5790
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x13ed0
leaq -0x80(%rbp), %rdi
callq 0x47a8
leaq -0x60(%rbp), %rdi
callq 0x47a8
leaq -0xd0(%rbp), %rdi
callq 0x47a8
leaq -0xb0(%rbp), %rdi
callq 0x47a8
movl $0x1, %edi
callq 0x44c0
movq %rax, %rbx
movq -0x80(%rbp), %rdi
cmpq %r15, %rdi
je 0x50da
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0x50da
movq %rax, %rbx
movq -0x60(%rbp), %rdi
cmpq %r14, %rdi
je 0x50f4
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0x50f4
movq %rax, %rbx
leaq -0xc0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5118
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0x5118
movq %rax, %rbx
leaq -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x513c
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0x513c
movq %rax, %rbx
callq 0x4660
leaq -0x238(%rbp), %rdi
callq 0xa47c
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x5162
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x43e0
leaq -0x100(%rbp), %rdi
callq 0x5778
leaq -0x510(%rbp), %rdi
callq 0x6f74
movq %rbx, %rdi
callq 0x46d0
movq %rax, %rdi
callq 0x51c7