// File: /workspace/github_cpp_makefile_star2_O1/UTAP[P]APHTTP/server/server.cpp
// Function: Server::Server(int)
Server::Server(int _port) : port(_port) {
#ifdef _WIN32
  WSADATA wsa_data;
  int initializeResult = WSAStartup(MAKEWORD(2, 2), &wsa_data);
  if (initializeResult != 0) {
    throw Exception("Error: WinSock WSAStartup failed: " + string(getSocketError()));
  }
#endif

  notFoundHandler = new NotFoundHandler();

  sc = socket(AF_INET, SOCK_STREAM, 0);
  int sc_option = 1;

#ifdef _WIN32
  setsockopt(sc, SOL_SOCKET, SO_REUSEADDR, (char*)&sc_option, sizeof(sc_option));
#else
  setsockopt(sc, SOL_SOCKET, SO_REUSEADDR, &sc_option, sizeof(sc_option));
#endif
  if (!ISVALIDSOCKET(sc))
    throw Exception("Error on opening socket: " + string(getSocketError()));

  struct sockaddr_in serv_addr;
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = INADDR_ANY;
  serv_addr.sin_port = htons(port);

  if (::bind(sc, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) != 0) {
    throw Exception("Error on binding: " + string(getSocketError()));
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xa0, %rsp
movq %rdi, %rbx
movl %esi, 0x4(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rdi)
movq $0x0, 0x18(%rdi)
movl $0x28, %edi
callq 0x4350
movq %rax, %r15
leaq -0x58(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x6628(%rip), %rdx      # 0x195d4
leaq -0x68(%rbp), %rdi
movq %rdx, %rsi
callq 0x6f6c
leaq 0xbda9(%rip), %rax      # 0x1ed68
movq %rax, (%r15)
leaq 0x8(%r15), %rdi
movq %r15, %rax
addq $0x18, %rax
movq %rax, 0x8(%r15)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
callq 0x7e12
movq %r15, 0x20(%rbx)
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
je 0x12ff3
callq 0x4310
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x40e0
movl %eax, (%rbx)
leaq -0x28(%rbp), %rcx
movl $0x1, (%rcx)
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
callq 0x45b0
movl (%rbx), %edi
testl %edi, %edi
js 0x13067
leaq -0x78(%rbp), %rsi
movw $0x2, (%rsi)
movl $0x0, 0x4(%rsi)
movzwl 0x4(%rbx), %eax
rolw $0x8, %ax
movw %ax, 0x2(%rsi)
movl $0x10, %edx
callq 0x4080
testl %eax, %eax
jne 0x130d4
addq $0xa0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0x28, %edi
callq 0x41f0
movq %rax, %r15
callq 0x4060
movl (%rax), %edi
callq 0x4170
leaq -0x48(%rbp), %rdi
leaq -0x78(%rbp), %rdx
movq %rax, %rsi
callq 0x4190
leaq 0x670b(%rip), %rsi      # 0x197a2
leaq -0xb8(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x142b2
movb $0x1, %r12b
leaq -0xb8(%rbp), %rsi
movq %r15, %rdi
callq 0x139e0
xorl %r12d, %r12d
leaq 0xba0d(%rip), %rsi      # 0x1ead0
leaq -0xb580(%rip), %rdx     # 0x7b4a
movq %r15, %rdi
callq 0x4570
jmp 0x1313f
movl $0x28, %edi
callq 0x41f0
movq %rax, %r15
callq 0x4060
movl (%rax), %edi
callq 0x4170
leaq -0x48(%rbp), %rdi
leaq -0x21(%rbp), %rdx
movq %rax, %rsi
callq 0x4190
leaq 0x66b8(%rip), %rsi      # 0x197bc
leaq -0x98(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x142b2
movb $0x1, %r12b
leaq -0x98(%rbp), %rsi
movq %r15, %rdi
callq 0x139e0
xorl %r12d, %r12d
leaq 0xb9a0(%rip), %rsi      # 0x1ead0
leaq -0xb5ed(%rip), %rdx     # 0x7b4a
movq %r15, %rdi
callq 0x4570
movq %rax, %r14
leaq -0x88(%rbp), %rax
jmp 0x13157
jmp 0x13167
movq %rax, %r14
leaq -0xa8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1316d
callq 0x4310
jmp 0x1316d
movq %rax, %r14
movb $0x1, %r12b
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x13189
callq 0x4310
jmp 0x13189
jmp 0x13183
movq %rax, %r14
movb $0x1, %r12b
testb %r12b, %r12b
je 0x131bb
movq %r15, %rdi
callq 0x4290
jmp 0x131bb
movq %rax, %r14
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
je 0x131ae
callq 0x4310
jmp 0x131ae
movq %rax, %r14
movq %r15, %rdi
callq 0x4310
jmp 0x131bb
movq %rax, %r14
addq $0x8, %rbx
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x131cc
callq 0x4310
movq %r14, %rdi
callq 0x45a0