// File: /workspace/github_cpp_makefile_star2_O3/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, -0x98(%rbp)
movq (%rdi), %r15
cmpq %rdi, %r15
je 0xb212
movq %rdi, %r14
cmpl $0x0, 0x130(%r14)
je 0xb212
leaq 0x10(%r15), %r13
movq %r13, %rdi
callq 0xbbae
leal 0x3f(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x6, %ecx
movslq %ecx, %rax
movq 0x30(%r14,%rax,8), %r12
movq %r13, %rdi
callq 0xbbae
btq %rax, %r12
jae 0xb206
movl $0x10, -0x2c(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xd0(%rbp)
movq %r13, %rdi
callq 0xbbae
movl %eax, %edi
leaq -0xd0(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x4160
testl %eax, %eax
js 0xb224
movl %eax, %r12d
movl %eax, %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x4260
movq %r13, %rdi
callq 0xbbb8
movq %r14, %rdi
movl %r12d, %esi
movl %eax, %edx
movq -0x98(%rbp), %rcx
callq 0xa6c2
movl %r12d, %esi
leaq -0xb8(%rbp), %r12
movq %r12, %rdi
callq 0x136be
movl $0xe, %r8d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0xa434(%rip), %rcx      # 0x15500
callq 0x4440
leaq -0x40(%rbp), %r12
movq %r12, -0x50(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
leaq -0x60(%rbp), %r13
je 0xb0f9
movq %rdx, -0x50(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x40(%rbp)
jmp 0xb101
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
movq %rdx, -0x48(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x50(%rbp), %rdi
leaq 0xa3ec(%rip), %rsi      # 0x1550f
callq 0x4760
movq %r13, -0x70(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
leaq -0x90(%rbp), %rbx
je 0xb14f
movq %rdx, -0x70(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x60(%rbp)
jmp 0xb157
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
movq %rdx, -0x68(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
movq %rbx, %rdi
leaq 0xa57e(%rip), %rdx      # 0x15701
movq %rdx, %rsi
callq 0x5796
leaq -0x70(%rbp), %rdi
movq %rbx, %rsi
callq 0x13da7
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0xb1b3
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0x70(%rbp), %rdi
cmpq %r13, %rdi
je 0xb1c8
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0xb1dd
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0xb1ff
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x43e0
decl 0x130(%r14)
movq (%r15), %r15
cmpq %r14, %r15
jne 0xb002
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x41f0
movq %rax, %r14
leaq 0xa2a3(%rip), %rsi      # 0x154db
movq %rax, %rdi
callq 0x41b0
movq 0x11da1(%rip), %rsi     # 0x1cfe8
movq 0x11d6a(%rip), %rdx     # 0x1cfb8
movq %r14, %rdi
callq 0x46a0
movq %rax, %rbx
movq %r14, %rdi
callq 0x42e0
jmp 0xb2e8
movq %rax, %rbx
jmp 0xb294
movq %rax, %rbx
jmp 0xb2ad
movq %rax, %rbx
jmp 0xb2c6
movq %rax, %rbx
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0xb294
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xb2ad
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0xb2c6
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0xb2e8
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x43e0
movq %rbx, %rdi
callq 0x46d0