// File: /workspace/github_cpp_makefile_star2_O2/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)
andq $0x0, 0x18(%rdi)
pushq $0x28
popq %rdi
callq 0x4380
movq %rax, %r15
leaq 0x39ef(%rip), %rsi      # 0x11595
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x41a0
leaq -0x68(%rbp), %rsi
movq %r15, %rdi
callq 0xe976
movq %r15, 0x20(%rbx)
leaq -0x68(%rbp), %rdi
callq 0x4638
pushq $0x2
popq %r14
pushq $0x1
popq %r15
movl %r14d, %edi
movl %r15d, %esi
xorl %edx, %edx
callq 0x40f0
movl %eax, (%rbx)
leaq -0x28(%rbp), %rcx
movl $0x1, (%rcx)
pushq $0x4
popq %r8
movl %eax, %edi
movl %r15d, %esi
movl %r14d, %edx
callq 0x4590
movl (%rbx), %edi
testl %edi, %edi
js 0xdc39
leaq -0x78(%rbp), %rsi
movw $0x2, (%rsi)
andl $0x0, 0x4(%rsi)
movzwl 0x4(%rbx), %eax
rolw $0x8, %ax
movw %ax, 0x2(%rsi)
pushq $0x10
popq %rdx
callq 0x4070
testl %eax, %eax
jne 0xdc9d
addq $0xa0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
pushq $0x28
popq %rdi
callq 0x4210
movq %rax, %r15
callq 0xdd75
leaq -0x48(%rbp), %rdi
leaq -0x78(%rbp), %rdx
movq %rax, %rsi
callq 0x41a0
leaq 0x3b2e(%rip), %rsi      # 0x1178e
leaq -0xb8(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x673e
movb $0x1, %r12b
leaq -0xb8(%rbp), %rsi
movq %r15, %rdi
callq 0xe304
xorl %r12d, %r12d
leaq 0x9e4c(%rip), %rsi      # 0x17ad8
leaq -0x757f(%rip), %rdx     # 0x6714
movq %r15, %rdi
callq 0x4560
jmp 0xdcff
pushq $0x28
popq %rdi
callq 0x4210
movq %rax, %r15
callq 0xdd75
leaq -0x48(%rbp), %rdi
leaq -0x21(%rbp), %rdx
movq %rax, %rsi
callq 0x41a0
leaq 0x3ae4(%rip), %rsi      # 0x117a8
leaq -0x98(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x673e
movb $0x1, %r12b
leaq -0x98(%rbp), %rsi
movq %r15, %rdi
callq 0xe304
xorl %r12d, %r12d
leaq 0x9de8(%rip), %rsi      # 0x17ad8
leaq -0x75e3(%rip), %rdx     # 0x6714
movq %r15, %rdi
callq 0x4560
movq %rax, %r14
leaq -0x98(%rbp), %rdi
jmp 0xdd17
jmp 0xdd1e
movq %rax, %r14
leaq -0xb8(%rbp), %rdi
callq 0x4638
jmp 0xdd24
movq %rax, %r14
movb $0x1, %r12b
leaq -0x48(%rbp), %rdi
callq 0x4638
testb %r12b, %r12b
jne 0xdd39
jmp 0xdd61
jmp 0xdd36
movq %rax, %r14
movq %r15, %rdi
callq 0x42a0
jmp 0xdd61
movq %rax, %r14
leaq -0x68(%rbp), %rdi
callq 0x4638
jmp 0xdd54
movq %rax, %r14
movq %r15, %rdi
callq 0x4330
jmp 0xdd61
movq %rax, %r14
addq $0x8, %rbx
movq %rbx, %rdi
callq 0xf120
movq %r14, %rdi
callq 0x4580