// File: /workspace/github_cpp_makefile_star2_O2/llefranc[P]42_webserv/srcs/server/HttpServer.cpp
// Function: HttpServer::connectNewClients(std::map<int, std::vector<ServerInfo, std::allocator<ServerInfo>>, std::less<int>, std::allocator<std::pair<int const, std::vector<ServerInfo, std::allocator<ServerInfo>>>>>&)
void HttpServer::connectNewClients(std::map<int, std::vector<ServerInfo> >& mSrv)
{
	for (std::list<ServerSocket>::iterator it = _serverSocks.begin(); it != _serverSocks.end() && _nbReadyFds; ++it)
	{
		if (FD_ISSET(it->getFd(), &_readFds))
		{
			// Not use but need to be set for accept function
			struct sockaddr_in addrCli;
			int lenCli = sizeof(addrCli);
			bzero((char *) &addrCli, sizeof(addrCli));

			// Creates a new socket for a client connection
			int newClient;
			if ((newClient = accept(it->getFd(), (struct sockaddr *)&addrCli, (socklen_t *)&lenCli)) < 0)
				throw std::runtime_error("Fatal error: accept function failed\n");

			// Setting the fd in non-blocking mode, then saving it
			fcntl(newClient, F_SETFL, O_NONBLOCK);
			addClientSocket(newClient, it->getPort(), mSrv);
			printLog("\033[1;36m >> FD " + convertNbToString(newClient) + ": Client socket created\033[0m\n");

			// Exit for loop if no other sockets are ready
			--_nbReadyFds;
		}	
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, -0x38(%rbp)
movq %rdi, %r13
movq %rdi, %r14
movq (%r14), %r14
cmpq %r13, %r14
je 0x9f16
cmpl $0x0, 0x130(%r13)
je 0x9f16
leaq 0x10(%r14), %r15
movq %r15, %rdi
callq 0xa908
cltd
pushq $0x40
popq %rbx
idivl %ebx
cltq
movq %r13, %r12
movq 0x30(%r13,%rax,8), %r13
movq %r15, %rdi
callq 0xa908
cltd
idivl %ebx
btq %rdx, %r13
movq %r12, %r13
jae 0x9dd8
movl $0x10, -0x30(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq %r15, %rdi
callq 0xa908
movl %eax, %edi
leaq -0x50(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x4180
testl %eax, %eax
js 0x9f28
movl %eax, %r13d
movl %eax, %edi
pushq $0x4
popq %rsi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x4290
movq %r15, %rdi
callq 0xa912
movq %r12, %rdi
movl %r13d, %esi
movl %eax, %edx
movq -0x38(%rbp), %rcx
callq 0x98b0
movl %r13d, %esi
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
callq 0xfc62
leaq -0x90(%rbp), %r15
movq %r15, %rdi
leaq 0x765d(%rip), %rsi      # 0x114f9
movq %rbx, %rdx
callq 0x4f60
leaq -0xd0(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x7650(%rip), %rdx      # 0x11508
callq 0x4f37
leaq -0xb0(%rbp), %r15
movq %r15, %rdi
leaq 0x782c(%rip), %rsi      # 0x116fa
leaq -0x29(%rbp), %rdx
callq 0x4ec8
movq %r12, %r13
movq %rbx, %rdi
movq %r15, %rsi
callq 0x10271
movq %r15, %rdi
callq 0x47d8
movq %rbx, %rdi
callq 0x47d8
leaq -0x90(%rbp), %rdi
callq 0x47d8
leaq -0x70(%rbp), %rdi
callq 0x47d8
decl 0x130(%r13)
jmp 0x9dd8
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x4220
movq %rax, %r14
leaq 0x759a(%rip), %rsi      # 0x114d4
movq %rax, %rdi
callq 0x41c0
movq 0xf0a7(%rip), %rsi      # 0x18ff0
movq 0xf078(%rip), %rdx      # 0x18fc8
movq %r14, %rdi
callq 0x46b0
movq %rax, %rbx
movq %r14, %rdi
callq 0x4330
jmp 0x9fa4
movq %rax, %rbx
jmp 0x9f9b
movq %rax, %rbx
jmp 0x9f8f
movq %rax, %rbx
jmp 0x9f83
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x47d8
leaq -0xd0(%rbp), %rdi
callq 0x47d8
leaq -0x90(%rbp), %rdi
callq 0x47d8
leaq -0x70(%rbp), %rdi
callq 0x47d8
movq %rbx, %rdi
callq 0x46d0