// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, (%rdi)
movl %edx, %r14d
movq %rsi, %r12
movq %rdi, %rbx
movb $0x1, 0x8(%rdi)
xorl %edi, %edi
callq 0x22090
movl %eax, %edi
callq 0x22170
movl $0x1, %esi
movl $0xd, %edi
callq 0x22570
movq 0x10c1a(%rip), %rax     # 0x4cfa0
movb (%rax), %al
testb %al, %al
je 0x3c4e6
vxorps %xmm0, %xmm0, %xmm0
leaq 0x10(%rbx), %rax
movl %r14d, %ebp
negl %ebp
movl $0x1, %r13d
vmovups %ymm0, 0x10(%rbx)
vmovups %ymm0, 0x20(%rbx)
movl $0x1, 0x18(%rbx)
movq %rax, 0x10(%rsp)
cmovsl %r14d, %ebp
movq (%r12), %rax
movq %rax, 0x8(%rsp)
cmpl $0xa, %ebp
jb 0x3c414
movl $0x4, %r13d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebp, %ecx
cmpl $0x63, %ecx
jbe 0x3c40b
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x3c411
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x3c414
movl %ecx, %edx
imulq %rax, %rdx
addl $0x4, %r13d
shrq $0x2d, %rdx
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x3c3d8
addl $-0x3, %r13d
jmp 0x3c414
addl $-0x2, %r13d
jmp 0x3c414
decl %r13d
shrl $0x1f, %r14d
leaq 0x28(%rsp), %r12
leaq 0x18(%rsp), %r15
movl $0x2d, %edx
leal (%r13,%r14), %esi
movq %r15, %rdi
movq %r12, -0x10(%r12)
vzeroupper
callq 0x22520
addq (%r15), %r14
movl %r13d, %esi
movl %ebp, %edx
movq %r14, %rdi
callq 0x22a70
movq (%r15), %rsi
leaq 0x40(%rbx), %rcx
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rdx
callq 0x226b0
movq 0x18(%rsp), %rdi
movl %eax, %ebp
cmpq %r12, %rdi
je 0x3c473
callq 0x22130
testl %ebp, %ebp
jne 0x3c531
movq 0x40(%rbx), %rax
movl 0x4(%rax), %edi
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
callq 0x21350
movl %eax, 0x48(%rbx)
cmpl $-0x1, %eax
je 0x3c54b
leaq 0x18(%rsp), %rcx
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
movl %eax, %edi
movl $0x1, (%rcx)
callq 0x23170
movq 0x40(%rbx), %rax
movl 0x48(%rbx), %edi
movq 0x18(%rax), %rsi
movl 0x10(%rax), %edx
callq 0x211b0
cmpl $-0x1, %eax
je 0x3c565
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10ab3(%rip), %rdi     # 0x4cfa0
callq 0x231d0
testl %eax, %eax
je 0x3c390
movq 0x10ac7(%rip), %rdi     # 0x4cfc8
callq 0x231b0
movq 0x1074b(%rip), %rdi     # 0x4cc58
movq 0x10ab4(%rip), %rsi     # 0x4cfc8
leaq 0x11d75(%rip), %rdx     # 0x4e290
callq 0x21fa0
movq 0x10a79(%rip), %rdi     # 0x4cfa0
callq 0x21b30
jmp 0x3c390
movl $0x8, %edi
callq 0x217b0
movq 0x1082e(%rip), %rcx     # 0x4cd70
movq 0x107bf(%rip), %rsi     # 0x4cd08
jmp 0x3c57d
movl $0x8, %edi
callq 0x217b0
movq 0x10754(%rip), %rcx     # 0x4ccb0
movq 0x109ed(%rip), %rsi     # 0x4cf50
jmp 0x3c57d
movl $0x8, %edi
callq 0x217b0
movq 0x106aa(%rip), %rcx     # 0x4cc20
movq 0x10753(%rip), %rsi     # 0x4ccd0
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x10a2d(%rip), %rdx     # 0x4cfb8
movq %rax, %rdi
callq 0x23090
movq 0x10a06(%rip), %rdi     # 0x4cfa0
movq %rax, %rbx
callq 0x21ac0
jmp 0x3c5b6
movq 0x18(%rsp), %rdi
movq %rax, %rbx
cmpq %r12, %rdi
je 0x3c5b6
callq 0x22130
movq %rbx, %rdi
callq 0x23160