// File: mbourand[P]webserv/srcs/tcp-server.cpp
// Function: handle_new_connection(ServerSocket&, std::__cxx11::list<Client, std::allocator<Client>>&)
int		handle_new_connection(ServerSocket &server, std::list<Client> &clients)
{
	if (clients.size() <= g_webserv.max_connections)
	{
		Client	new_client;
		new_client.sckt = new ServerSocket;
		new_client.req = new Request(server.getServerPort());
		new_client.sckt->setServerPort(server.getServerPort());
		server.Accept(*new_client.sckt);
		clients.push_back(new_client);
		return (Logger::print("New Client Connected ("+new_client.sckt->getIPAddress()+")", new_client.sckt->GetSocket(), SUCCESS, NORMAL));
	}
	else
	{
		return (Logger::print("Connections limit reached, client pending connection.", 0, ERROR, NORMAL));
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x5bcd0
movl 0x38af2(%rip), %ecx     # 0x8f7e4
cmpq %rcx, %rax
ja 0x56ed1
movl $0x60, %edi
callq 0x9680
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xc8(%rbp)
callq 0x5bd00
jmp 0x56d19
movq -0xc8(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x1a0, %edi            # imm = 0x1A0
callq 0x9680
movq %rax, -0xd8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1c160
movl %eax, -0xcc(%rbp)
jmp 0x56d46
movl -0xcc(%rbp), %esi
movq -0xd8(%rbp), %rdi
callq 0x5da30
jmp 0x56d5a
movq -0xd8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1c160
movq -0xe8(%rbp), %rdi
movl %eax, %esi
callq 0x1c090
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x1bf70
movq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x5bd40
movq -0x28(%rbp), %rsi
leaq -0x98(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x1c1b0
movq -0xe0(%rbp), %rdx
leaq 0x1672b(%rip), %rsi     # 0x6d4f1
leaq -0x78(%rbp), %rdi
callq 0x14790
jmp 0x56dd1
leaq 0x14059(%rip), %rdx     # 0x6ae31
leaq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x13970
jmp 0x56de7
movq -0x28(%rbp), %rdi
callq 0x1cdb0
movl %eax, -0xec(%rbp)
jmp 0x56df8
movl -0xec(%rbp), %esi
leaq -0x58(%rbp), %rdi
movl $0x1, %ecx
movl %ecx, %edx
callq 0x1cdd0
movl %eax, -0xf0(%rbp)
jmp 0x56e16
movl -0xf0(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x9c98
leaq -0x78(%rbp), %rdi
callq 0x9c98
leaq -0x98(%rbp), %rdi
callq 0x9c98
jmp 0x56f77
movq -0xc8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x60, %esi
callq 0x9690
jmp 0x56f83
movq -0xd8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x1a0, %esi            # imm = 0x1A0
callq 0x9690
jmp 0x56f83
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x56ec0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x56eb7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x9c98
leaq -0x78(%rbp), %rdi
callq 0x9c98
leaq -0x98(%rbp), %rdi
callq 0x9c98
jmp 0x56f83
leaq -0xb9(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x9b10
movq -0xf8(%rbp), %rdx
leaq 0x16616(%rip), %rsi     # 0x6d508
leaq -0xb8(%rbp), %rdi
callq 0xa780
jmp 0x56f00
leaq -0xb8(%rbp), %rdi
xorl %esi, %esi
movl $0x3, %edx
movl $0x1, %ecx
callq 0x1cdd0
movl %eax, -0xfc(%rbp)
jmp 0x56f20
movl -0xfc(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x9c98
leaq -0xb9(%rbp), %rdi
callq 0x9700
jmp 0x56f77
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x56f69
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x9c98
leaq -0xb9(%rbp), %rdi
callq 0x9700
jmp 0x56f83
movl -0x4(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x9af0
nopl (%rax)