// File: /workspace/github_cpp_makefile_star2_O1/solaldunckel[P]webserv/srcs/HTTP/Server.cpp
// Function: Server::setup()
void Server::setup() {
  int yes = 1;
  int server_fd = 0;

  std::vector<Listen> is_bind;

  for (std::vector<ServerConfig>::iterator it = servers_.begin(); it != servers_.end(); it++) {
    if (it->getListens().empty())
      it->getListens().push_back(Listen("0.0.0.0", 80));
    for (std::vector<Listen>::iterator list = it->getListens().begin(); list != it->getListens().end(); list++) {
      if (std::find(is_bind.begin(), is_bind.end(), *list) == is_bind.end()) {
        if ((server_fd = socket(PF_INET, SOCK_STREAM, 0)) < 0)
          throw webserv_exception("socket() failed", errno);

        fcntl(server_fd, F_SETFL, O_NONBLOCK);

        struct sockaddr_in address;
        memset(&address, 0, sizeof(address));
        address.sin_family = AF_INET;
        address.sin_addr.s_addr = inet_addr(list->ip_.c_str());
        address.sin_port = htons(list->port_);

        setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));

        if (bind(server_fd, (struct sockaddr *)&address, sizeof(address)) < 0)
          throw webserv_exception("bind() to % failed", errno, list->ip_ + ":" + ft::to_string(list->port_));

        if (listen(server_fd, MAX_CONNECTION) < 0)
          throw webserv_exception("listen() failed", errno);

        running_server_[server_fd] = Listen(list->ip_, list->port_);

        Log.print(INFO, "listening on " + ft::to_string(list->ip_) + ":" + ft::to_string(list->port_), GREEN);

        add_to_fd_set(server_fd);
        is_bind.push_back(*list);
      }
    }
  }

  if (is_bind.empty())
    throw webserv_exception("listen() failed", errno);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movl $0x1, 0x5c(%rsp)
movl $0x0, 0x4(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movq $0x0, 0x90(%rsp)
movq %rdi, 0x50(%rsp)
movq 0x8(%rdi), %rax
movq (%rax), %rbp
cmpq 0x8(%rax), %rbp
je 0x18c2e
leaq 0x18(%rsp), %rbx
movq 0x50(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x158(%rsp)
leaq 0x70(%rsp), %r15
leaq 0x8(%rsp), %r14
leaq 0x138(%rsp), %r12
movq %rbp, %rdi
callq 0xcb9a
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
jne 0x1873e
movq %rbp, %rdi
callq 0xcb9a
movq %rax, %r13
leaq 0xf0(%rsp), %rax
movq %rax, 0xe0(%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0xcc7d(%rip), %rsi      # 0x25340
leaq 0xcc7d(%rip), %rdx      # 0x25347
callq 0x578e
movq %rbx, 0x8(%rsp)
movq 0xe0(%rsp), %rsi
movq 0xe8(%rsp), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x6bac
movl $0x50, 0x28(%rsp)
movq %r13, %rdi
movq %r14, %rsi
callq 0xdba2
movq 0x8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x18719
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x1873e
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x4460
movq %rbp, %rdi
callq 0xcb9a
movq (%rax), %r13
movq %rbp, 0x160(%rsp)
movq %rbp, %rdi
callq 0xcb9a
cmpq 0x8(%rax), %r13
je 0x18c14
movq 0x80(%rsp), %rdi
movq 0x88(%rsp), %rsi
movq %r13, %rdx
callq 0xda4b
cmpq 0x88(%rsp), %rax
jne 0x18c0b
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x40c0
movl %eax, 0x4(%rsp)
testl %eax, %eax
js 0x18c63
movl %eax, %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x4260
xorps %xmm0, %xmm0
movaps %xmm0, 0x100(%rsp)
movw $0x2, 0x100(%rsp)
movq (%r13), %rdi
callq 0x4450
movl %eax, 0x104(%rsp)
movzwl 0x20(%r13), %eax
rolw $0x8, %ax
movw %ax, 0x102(%rsp)
movl 0x4(%rsp), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq 0x5c(%rsp), %rcx
movl $0x4, %r8d
callq 0x47a0
movl 0x4(%rsp), %edi
leaq 0x100(%rsp), %rsi
movl $0x10, %edx
callq 0x4080
testl %eax, %eax
js 0x18d93
movl 0x4(%rsp), %edi
movl $0x80, %esi
callq 0x44b0
testl %eax, %eax
js 0x18cfb
leaq 0xd0(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0xc0(%rsp), %rdi
callq 0x6bac
movq %r14, %rdi
movl 0x20(%r13), %ebp
movq %rbx, 0x8(%rsp)
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
addq %rsi, %rdx
callq 0x6bac
movl %ebp, 0x28(%rsp)
movq 0x158(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x1ab00
movq %rax, %rbp
movq %rax, %rdi
movq %r14, %rsi
callq 0x4560
movl 0x28(%rsp), %eax
movl %eax, 0x20(%rbp)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x188d4
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x188f9
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x4460
leaq 0x148(%rsp), %rax
movq %rax, 0x138(%rsp)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
movq %r12, %rbx
movq %r12, %rdi
callq 0x6bac
leaq 0x168(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x1ab64
movl $0xd, %r8d
movq %rbp, %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0xd0bb(%rip), %rcx      # 0x25a01
callq 0x44c0
leaq 0x40(%rsp), %rsi
movq %rsi, 0x30(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x18973
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x18979
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x38(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x30(%rsp), %rdi
leaq 0xca85(%rip), %rsi      # 0x25422
callq 0x4830
leaq 0x18(%rsp), %rsi
movq %rsi, 0x8(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x189ca
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x189d0
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl 0x20(%r13), %esi
leaq 0xa0(%rsp), %rdi
callq 0x105d9
movq 0x8(%rsp), %rcx
movl $0xf, %esi
leaq 0x18(%rsp), %rax
cmpq %rax, %rcx
je 0x18a12
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %r8
movq 0xa8(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0x18a4c
movl $0xf, %esi
leaq 0xb0(%rsp), %rdi
cmpq %rdi, 0xa0(%rsp)
je 0x18a47
movq 0xb0(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x18a5e
movq 0xa0(%rsp), %rsi
movq %r14, %rdi
callq 0x4100
jmp 0x18a6f
leaq 0xa0(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x44c0
movq %r15, 0x60(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x18a8f
movq %rdx, 0x60(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x70(%rsp)
jmp 0x18a96
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x68(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x128(%rsp), %rax
movq %rax, 0x118(%rsp)
leaq 0x118(%rsp), %rbx
movq %rbx, %rdi
leaq 0xcf3a(%rip), %rsi      # 0x25a0f
leaq 0xcf38(%rip), %rdx      # 0x25a14
callq 0x578e
leaq 0x199f0(%rip), %rdi     # 0x324d8
movl $0x1, %esi
leaq 0x60(%rsp), %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x20fae
movq 0x118(%rsp), %rdi
leaq 0x128(%rsp), %rax
cmpq %rax, %rdi
je 0x18b22
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x60(%rsp), %rdi
cmpq %r15, %rdi
je 0x18b39
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x18b5e
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x18b7a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x18b96
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x168(%rsp), %rdi
leaq 0x178(%rsp), %rax
cmpq %rax, %rdi
leaq 0x18(%rsp), %rbx
movq 0x160(%rsp), %rbp
je 0x18bc8
movq 0x178(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x138(%rsp), %rdi
leaq 0x148(%rsp), %rax
cmpq %rax, %rdi
je 0x18bed
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x4460
movl 0x4(%rsp), %esi
movq 0x50(%rsp), %rdi
callq 0x1923e
leaq 0x80(%rsp), %rdi
movq %r13, %rsi
callq 0x1abec
addq $0x28, %r13
jmp 0x18751
addq $0x198, %rbp            # imm = 0x198
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rax
cmpq 0x8(%rax), %rbp
jne 0x18684
movq 0x80(%rsp), %rax
cmpq 0x88(%rsp), %rax
je 0x18e42
leaq 0x80(%rsp), %rdi
callq 0x7ac2
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x30, %edi
callq 0x41d0
movq %rax, %r14
leaq 0x258(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xcd4b(%rip), %rsi      # 0x259ce
leaq 0xcd53(%rip), %rdx      # 0x259dd
leaq 0x248(%rsp), %rdi
callq 0x578e
callq 0x4050
movl (%rax), %ebx
leaq 0x238(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0xcdc7(%rip), %rdx      # 0x25a78
leaq 0x228(%rsp), %rdi
movq %rdx, %rsi
callq 0x578e
movb $0x1, %bpl
leaq 0x248(%rsp), %rsi
leaq 0x228(%rsp), %rcx
movq %r14, %rdi
movl %ebx, %edx
callq 0x6542
xorl %ebp, %ebp
leaq 0x19019(%rip), %rsi     # 0x31d00
leaq -0x12392(%rip), %rdx    # 0x695c
movq %r14, %rdi
callq 0x4750
jmp 0x18ed5
movl $0x30, %edi
callq 0x41d0
movq %rax, %r14
leaq 0x1f8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xccd6(%rip), %rsi      # 0x259f1
leaq 0xccde(%rip), %rdx      # 0x25a00
leaq 0x1e8(%rsp), %rdi
callq 0x578e
callq 0x4050
movl (%rax), %ebx
leaq 0x1d8(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0xcd2f(%rip), %rdx      # 0x25a78
leaq 0x1c8(%rsp), %rdi
movq %rdx, %rsi
callq 0x578e
movb $0x1, %bpl
leaq 0x1e8(%rsp), %rsi
leaq 0x1c8(%rsp), %rcx
movq %r14, %rdi
movl %ebx, %edx
callq 0x6542
xorl %ebp, %ebp
leaq 0x18f81(%rip), %rsi     # 0x31d00
leaq -0x1242a(%rip), %rdx    # 0x695c
movq %r14, %rdi
callq 0x4750
jmp 0x18ed5
movl $0x30, %edi
callq 0x41d0
movq %rax, %r14
leaq 0x218(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0xcc2b(%rip), %rsi      # 0x259de
leaq 0xcc36(%rip), %rdx      # 0x259f0
leaq 0x208(%rsp), %rdi
callq 0x578e
callq 0x4050
movl (%rax), %ebx
leaq 0xc64d(%rip), %rdx      # 0x25422
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x91e6
movl 0x20(%r13), %esi
leaq 0x30(%rsp), %rdi
callq 0x105d9
leaq 0x268(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x1aa57
movb $0x1, %r13b
leaq 0x208(%rsp), %rsi
leaq 0x268(%rsp), %rcx
movq %r14, %rdi
movl %ebx, %edx
callq 0x6542
xorl %r13d, %r13d
leaq 0x18ed2(%rip), %rsi     # 0x31d00
leaq -0x124d9(%rip), %rdx    # 0x695c
movq %r14, %rdi
callq 0x4750
jmp 0x18ed5
movl $0x30, %edi
callq 0x41d0
movq %rax, %r14
leaq 0x1b8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xcb8f(%rip), %rsi      # 0x259f1
leaq 0xcb97(%rip), %rdx      # 0x25a00
leaq 0x1a8(%rsp), %rdi
callq 0x578e
callq 0x4050
movl (%rax), %ebx
leaq 0x198(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0xcbe8(%rip), %rdx      # 0x25a78
leaq 0x188(%rsp), %rdi
movq %rdx, %rsi
callq 0x578e
movb $0x1, %bpl
leaq 0x1a8(%rsp), %rsi
leaq 0x188(%rsp), %rcx
movq %r14, %rdi
movl %ebx, %edx
callq 0x6542
xorl %ebp, %ebp
leaq 0x18e3a(%rip), %rsi     # 0x31d00
leaq -0x12571(%rip), %rdx    # 0x695c
movq %r14, %rdi
callq 0x4750
movq %rax, %r12
movq 0x188(%rsp), %rdi
cmpq %r13, %rdi
je 0x18efd
movq 0x198(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x18efd
movq %rax, %r12
movb $0x1, %bpl
movq 0x1a8(%rsp), %rdi
cmpq %r15, %rdi
je 0x190ac
movq 0x1b8(%rsp), %rsi
jmp 0x1908a
jmp 0x190a6
movq %rax, %r12
movq 0x8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x18f3f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x18f3f
movq %rax, %r12
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x19228
movq 0xf0(%rsp), %rsi
jmp 0x19213
jmp 0x19225
movq %rax, %r12
leaq 0x278(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x18f96
movq 0x278(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x18f96
movq %rax, %r12
movb $0x1, %r13b
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x18fc4
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x18fc4
jmp 0x19225
jmp 0x19225
movq %rax, %r12
movb $0x1, %r13b
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x18fe8
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x18fe8
movq %rax, %r12
movb $0x1, %r13b
movq 0x208(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1909a
movq 0x218(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x1909a
movq %rax, %r12
movq 0x1c8(%rsp), %rdi
cmpq %r13, %rdi
je 0x19036
movq 0x1d8(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x19036
movq %rax, %r12
movb $0x1, %bpl
movq 0x1e8(%rsp), %rdi
cmpq %r15, %rdi
je 0x190ac
movq 0x1f8(%rsp), %rsi
jmp 0x1908a
movq %rax, %r12
movq 0x228(%rsp), %rdi
cmpq %r13, %rdi
je 0x19075
movq 0x238(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x19075
movq %rax, %r12
movb $0x1, %bpl
movq 0x248(%rsp), %rdi
cmpq %r15, %rdi
je 0x190ac
movq 0x258(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x190ac
movq %rax, %r12
movb $0x1, %r13b
testb %r13b, %r13b
jne 0x190b5
jmp 0x19228
jmp 0x190a6
movq %rax, %r12
movb $0x1, %bpl
testb %bpl, %bpl
je 0x19228
movq %r14, %rdi
callq 0x4300
jmp 0x19228
movq %rax, %r12
movq 0x118(%rsp), %rdi
leaq 0x128(%rsp), %rax
cmpq %rax, %rdi
je 0x19118
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x19118
movq %rax, %r12
jmp 0x191b5
movq %rax, %r12
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x1913c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x1913c
movq %rax, %r12
movq 0x60(%rsp), %rdi
cmpq %r15, %rdi
je 0x19165
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x19165
movq %rax, %r12
jmp 0x191d1
movq %rax, %r12
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x19228
movq 0xd0(%rsp), %rsi
jmp 0x19213
movq %rax, %r12
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x19199
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x19199
movq %rax, %r12
jmp 0x191f6
jmp 0x19225
movq %rax, %r12
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x191b5
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x191d1
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x168(%rsp), %rdi
leaq 0x178(%rsp), %rax
cmpq %rax, %rdi
je 0x191f6
movq 0x178(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x138(%rsp), %rdi
leaq 0x148(%rsp), %rax
cmpq %rax, %rdi
je 0x19228
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x19228
jmp 0x19225
jmp 0x19225
jmp 0x19225
jmp 0x19225
movq %rax, %r12
leaq 0x80(%rsp), %rdi
callq 0x7ac2
movq %r12, %rdi
callq 0x4780
nop