// File: alfanick[P]rest-cpp/src/rest/server.cpp
// Function: REST::Server::Server(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, REST::Dispatcher*)
Server::Server(std::string address, int port, Dispatcher* d) : dispatcher(d) {
  srand(time(0));
  signal(SIGPIPE, SIG_IGN);
  Router::instance();
  int status;

  memset(&host_info, 0, sizeof(host_info));

  host_info.ai_family = AF_UNSPEC;
  host_info.ai_socktype = SOCK_STREAM;

  status = getaddrinfo(address.c_str(), std::to_string(port).c_str(), &host_info, &host_info_list);
  if (status != 0)
    throw AddressResolvingError();

  handle = socket(host_info_list->ai_family, host_info_list->ai_socktype, host_info_list->ai_protocol);
  if (handle == -1)
    throw SocketCreationError();

  int yes = 1;
  status = setsockopt(handle, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
  status = bind(handle, host_info_list->ai_addr, host_info_list->ai_addrlen);
  if (status == -1)
    throw PortInUseError();
}

// Assembly:
subq $0xa8, %rsp
movq %rsi, 0x20(%rsp)
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movl %edx, 0x94(%rsp)
movq %rcx, 0x88(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x88(%rsp), %rcx
movq %rcx, (%rax)
movb $0x1, 0x8(%rax)
addq $0x10, %rax
movq %rax, 0x40(%rsp)
xorl %eax, %eax
movl %eax, %edi
callq 0x92a80
movl %eax, %edi
callq 0x92d90
movl $0xd, %edi
movl $0x1, %esi
callq 0x94520
callq 0x8ee40
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %rax
vpxor %xmm0, %xmm0, %xmm0
vmovdqu %ymm0, 0x20(%rax)
vmovdqu %ymm0, 0x10(%rax)
movl $0x0, 0x14(%rax)
movl $0x1, 0x18(%rax)
vzeroupper
callq 0x8f110
movq %rax, 0x38(%rsp)
movl 0x94(%rsp), %esi
leaq 0x60(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x950d0
movq 0x28(%rsp), %rdi
callq 0x8f110
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rdx
movq %rax, %rsi
addq $0x40, %rcx
callq 0x94b70
movl %eax, 0x4c(%rsp)
jmp 0xe1fa8
movl 0x4c(%rsp), %eax
movl %eax, 0x84(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x99830
cmpl $0x0, 0x84(%rsp)
je 0xe2024
movl $0x8, %edi
callq 0x8f970
movq %rax, %rdi
movq %rdi, 0x18(%rsp)
xorl %esi, %esi
movl $0x8, %edx
callq 0x8ffc0
movq 0x18(%rsp), %rdi
callq 0x940b0
movq 0x18(%rsp), %rdi
movq 0x23c85(%rip), %rsi     # 0x105c80
movq 0x23c06(%rip), %rdx     # 0x105c08
callq 0x97c60
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x99830
jmp 0xe213b
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rcx
movl 0x4(%rcx), %edi
movq 0x40(%rax), %rcx
movl 0x8(%rcx), %esi
movq 0x40(%rax), %rax
movl 0xc(%rax), %edx
callq 0x8e250
movl %eax, %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x48(%rax)
cmpl $-0x1, 0x48(%rax)
jne 0xe2093
movl $0x8, %edi
callq 0x8f970
movq %rax, %rdi
movq %rdi, 0x10(%rsp)
xorl %esi, %esi
movl $0x8, %edx
callq 0x8ffc0
movq 0x10(%rsp), %rdi
callq 0x95db0
movq 0x10(%rsp), %rdi
movq 0x23e91(%rip), %rsi     # 0x105f18
movq 0x23f52(%rip), %rdx     # 0x105fe0
callq 0x97c60
movq 0x30(%rsp), %rax
movl $0x1, 0x50(%rsp)
movl 0x48(%rax), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq 0x50(%rsp), %rcx
movl $0x4, %r8d
callq 0x982f0
movl %eax, %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x84(%rsp)
movl 0x48(%rax), %edi
movq 0x40(%rax), %rcx
movq 0x18(%rcx), %rsi
movq 0x40(%rax), %rax
movl 0x10(%rax), %edx
callq 0x8d9a0
movl %eax, 0x84(%rsp)
cmpl $-0x1, 0x84(%rsp)
jne 0xe2133
movl $0x8, %edi
callq 0x8f970
movq %rax, %rdi
movq %rdi, 0x8(%rsp)
xorl %esi, %esi
movl $0x8, %edx
callq 0x8ffc0
movq 0x8(%rsp), %rdi
callq 0x90800
movq 0x8(%rsp), %rdi
movq 0x23b09(%rip), %rsi     # 0x105c30
movq 0x23c72(%rip), %rdx     # 0x105da0
callq 0x97c60
addq $0xa8, %rsp
retq
movq 0x58(%rsp), %rdi
callq 0x981c0
nopw %cs:(%rax,%rax)