// File: /workspace/github_cpp_makefile_star2_O3/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 -0x60(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x671c(%rip), %rdx      # 0x195d4
leaq -0x70(%rbp), %rdi
movq %rdx, %rsi
callq 0x6f56
leaq 0xbe9d(%rip), %rax      # 0x1ed68
movq %rax, (%r15)
leaq 0x8(%r15), %rdi
movq %r15, %rax
addq $0x18, %rax
movq %rax, 0x8(%r15)
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
addq %rsi, %rdx
callq 0x7dfa
movq %r15, 0x20(%rbx)
movq -0x70(%rbp), %rdi
cmpq %r12, %rdi
je 0x12eff
callq 0x4310
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x40e0
movl %eax, (%rbx)
leaq -0x4c(%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 0x12f73
leaq -0x80(%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 0x12fe0
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 -0x80(%rbp), %rdx
movq %rax, %rsi
callq 0x4190
leaq 0x67ff(%rip), %rsi      # 0x197a2
leaq -0xc0(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x141b2
movb $0x1, %r12b
leaq -0xc0(%rbp), %rsi
movq %r15, %rdi
callq 0x138e0
xorl %r12d, %r12d
leaq 0xbb01(%rip), %rsi      # 0x1ead0
leaq -0xb4a4(%rip), %rdx     # 0x7b32
movq %r15, %rdi
callq 0x4570
jmp 0x1304b
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 0x67ac(%rip), %rsi      # 0x197bc
leaq -0xa0(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x141b2
movb $0x1, %r12b
leaq -0xa0(%rbp), %rsi
movq %r15, %rdi
callq 0x138e0
xorl %r12d, %r12d
leaq 0xba94(%rip), %rsi      # 0x1ead0
leaq -0xb511(%rip), %rdx     # 0x7b32
movq %r15, %rdi
callq 0x4570
movq %rax, %r14
leaq -0x90(%rbp), %rax
jmp 0x13063
jmp 0x1308a
movq %rax, %r14
leaq -0xb0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x13071
callq 0x4310
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x13083
callq 0x4310
testb %r12b, %r12b
jne 0x130a6
jmp 0x130ce
movq %rax, %r14
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x130a6
callq 0x4310
jmp 0x130a6
jmp 0x130a3
movq %rax, %r14
movq %r15, %rdi
callq 0x4290
jmp 0x130ce
movq %rax, %r14
movq -0x70(%rbp), %rdi
cmpq %r12, %rdi
je 0x130c6
callq 0x4310
jmp 0x130c6
movq %rax, %r14
movq %r15, %rdi
callq 0x4310
addq $0x8, %rbx
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x130df
callq 0x4310
movq %r14, %rdi
callq 0x45a0
nop