// File: solaldunckel[P]webserv/srcs/HTTP/Server.cpp
// Function: Server::newConnection(int)
void Server::newConnection(int fd) {
  struct sockaddr_storage their_addr;
  socklen_t addr_size = sizeof(their_addr);

  FD_CLR(fd, &read_fds_);

  int clientFd = accept(fd, (struct sockaddr *)&their_addr, &addr_size);

  if (clientFd == -1)
    return ;

  Log.print(INFO, head_ + "new connection on " + ft::to_string(running_server_[fd].ip_) + ":" + ft::to_string(running_server_[fd].port_), GREEN);

  fcntl(clientFd, F_SETFL, O_NONBLOCK);

  std::string client_addr = ft::inet_ntop(ft::get_in_addr((struct sockaddr *)&their_addr));
  clients_[clientFd] = new Client(clientFd, client_addr, running_server_[fd], worker_id_, clients_.size() >= MAX_CLIENT);

  add_to_fd_set(clientFd);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movl $0x80, -0x94(%rbp)
movl -0xc(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
xorq $-0x1, %rax
movq %rax, -0x1e0(%rbp)
movl -0xc(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x1e0(%rbp), %rdx
movl %eax, %ecx
movq -0x1d8(%rbp), %rax
movslq %ecx, %rcx
andq 0xf8(%rax,%rcx,8), %rdx
movq %rdx, 0xf8(%rax,%rcx,8)
movl -0xc(%rbp), %edi
leaq -0x90(%rbp), %rsi
leaq -0x94(%rbp), %rdx
callq 0x5150
movl %eax, -0x98(%rbp)
cmpl $-0x1, -0x98(%rbp)
jne 0x2cb31
jmp 0x2cdee
movq -0x1d8(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
leaq 0x16eab(%rip), %rdx     # 0x439f1
leaq -0x118(%rbp), %rdi
callq 0x8f70
movq -0x1d8(%rbp), %rdi
addq $0x18, %rdi
leaq -0xc(%rbp), %rsi
callq 0x2e700
movq %rax, -0x1e8(%rbp)
jmp 0x2cb6f
movq -0x1e8(%rbp), %rsi
leaq -0x158(%rbp), %rdi
callq 0x5200
jmp 0x2cb84
leaq -0x138(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x2e820
jmp 0x2cb99
leaq -0xf8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
leaq -0x138(%rbp), %rdx
callq 0x9550
jmp 0x2cbb5
leaq 0x16875(%rip), %rdx     # 0x43431
leaq -0xd8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x6a80
jmp 0x2cbd1
movq -0x1d8(%rbp), %rdi
addq $0x18, %rdi
leaq -0xc(%rbp), %rsi
callq 0x2e700
movq %rax, -0x1f0(%rbp)
jmp 0x2cbee
movq -0x1f0(%rbp), %rax
movl 0x20(%rax), %esi
leaq -0x188(%rbp), %rdi
callq 0x20fb0
jmp 0x2cc06
leaq -0xb8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0x188(%rbp), %rdx
callq 0x9550
jmp 0x2cc22
leaq -0x1a9(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x5960
movq -0x1f8(%rbp), %rdx
leaq 0x16da8(%rip), %rsi     # 0x439eb
leaq -0x1a8(%rbp), %rdi
callq 0x6be0
jmp 0x2cc51
leaq 0x2f9a0(%rip), %rdi     # 0x5c5f8
movl $0x1, %esi
leaq -0xb8(%rbp), %rdx
leaq -0x1a8(%rbp), %rcx
xorl %r8d, %r8d
callq 0x3b240
jmp 0x2cc75
leaq -0x1a8(%rbp), %rdi
callq 0x5aa8
leaq -0x1a9(%rbp), %rdi
callq 0x55e0
leaq -0xb8(%rbp), %rdi
callq 0x5aa8
leaq -0x188(%rbp), %rdi
callq 0x5aa8
leaq -0xd8(%rbp), %rdi
callq 0x5aa8
leaq -0xf8(%rbp), %rdi
callq 0x5aa8
leaq -0x138(%rbp), %rdi
callq 0x5aa8
leaq -0x158(%rbp), %rdi
callq 0x5aa8
leaq -0x118(%rbp), %rdi
callq 0x5aa8
movl -0x98(%rbp), %edi
xorl %eax, %eax
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
callq 0x52e0
leaq -0x90(%rbp), %rdi
callq 0x42290
movq %rax, %rsi
leaq -0x1d0(%rbp), %rdi
callq 0x42030
movl $0x50, %edi
callq 0x5550
movq %rax, -0x200(%rbp)
jmp 0x2cd26
movq -0x1d8(%rbp), %rdi
movl -0x98(%rbp), %eax
movl %eax, -0x20c(%rbp)
addq $0x18, %rdi
leaq -0xc(%rbp), %rsi
callq 0x2e700
movq %rax, -0x208(%rbp)
jmp 0x2cd4f
movq -0x1d8(%rbp), %rdi
movl (%rdi), %eax
movl %eax, -0x210(%rbp)
addq $0x48, %rdi
callq 0x2e940
movq -0x200(%rbp), %rdi
movl -0x20c(%rbp), %esi
movq -0x208(%rbp), %rcx
movl -0x210(%rbp), %r8d
subq $0x3e8, %rax            # imm = 0x3E8
setae %al
movzbl %al, %r9d
leaq -0x1d0(%rbp), %rdx
callq 0x21610
jmp 0x2cd9d
movq -0x1d8(%rbp), %rdi
addq $0x48, %rdi
leaq -0x98(%rbp), %rsi
callq 0x2e960
movq %rax, -0x218(%rbp)
jmp 0x2cdbd
movq -0x1d8(%rbp), %rdi
movq -0x218(%rbp), %rax
movq -0x200(%rbp), %rcx
movq %rcx, (%rax)
movl -0x98(%rbp), %esi
callq 0x2ca00
jmp 0x2cde2
leaq -0x1d0(%rbp), %rdi
callq 0x5aa8
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0x2cf01
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0x2cef5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0x2cee9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0x2cedd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0x2ced1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0x2cec5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0x2cead
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x5aa8
leaq -0x1a9(%rbp), %rdi
callq 0x55e0
leaq -0xb8(%rbp), %rdi
callq 0x5aa8
leaq -0x188(%rbp), %rdi
callq 0x5aa8
leaq -0xd8(%rbp), %rdi
callq 0x5aa8
leaq -0xf8(%rbp), %rdi
callq 0x5aa8
leaq -0x138(%rbp), %rdi
callq 0x5aa8
leaq -0x158(%rbp), %rdi
callq 0x5aa8
leaq -0x118(%rbp), %rdi
callq 0x5aa8
jmp 0x2cf52
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0x2cf46
movq -0x200(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
movl $0x50, %esi
callq 0x5580
leaq -0x1d0(%rbp), %rdi
callq 0x5aa8
movq -0x160(%rbp), %rdi
callq 0x5950
nop