// File: /workspace/github_cpp_makefile_star2_O1/wrighteagle2d[P]wrighteaglebase/Debug/../src/UDPSocket.cpp
// Function: UDPSocket::Initial(char const*, int)
void UDPSocket::Initial(const char *host, int port) {
  struct hostent *host_ent;
  struct in_addr *addr_ptr;

#ifdef WIN32
  WORD wVersionRequested;
  WSADATA wsaData;
  wVersionRequested = MAKEWORD(2, 2);
  if (WSAStartup(wVersionRequested, &wsaData) != 0) {
    PRINT_ERROR("WSAStartup failed");
  }
  if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
    WSACleanup();
    PRINT_ERROR("WSASTartup version mismatch");
  }
#endif

  if ((host_ent = (struct hostent *)gethostbyname(host)) == 0) {
    if (inet_addr(host) == INADDR_NONE)
      PRINT_ERROR("Invalid host name");
  } else {
    addr_ptr = (struct in_addr *)*host_ent->h_addr_list;
    host = inet_ntoa(*addr_ptr);
  }

  if ((mSockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    PRINT_ERROR("Can't create socket");
  }

  memset(&mAddress, 0, sizeof(mAddress));
  mAddress.sin_family = AF_INET;
  mAddress.sin_addr.s_addr = htonl(INADDR_ANY);
  mAddress.sin_port = htons(0);

  if (bind(mSockfd, (sockaddr *)&mAddress, sizeof(mAddress)) < 0) {
#ifdef WIN32
    closesocket(mSockfd);
#else
    close(mSockfd);
#endif
    PRINT_ERROR("Can't bind client to any port");
  }

  memset(&mAddress, 0, sizeof(mAddress));
  mAddress.sin_family = AF_INET;
  mAddress.sin_addr.s_addr = inet_addr(host);
  mAddress.sin_port = htons(port);
  mIsInitialOK = true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebx
movq %rsi, %r15
movq %rdi, %r14
movq %rsi, %rdi
callq 0x9550
testq %rax, %rax
je 0x55887
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax), %edi
callq 0x9210
movq %rax, %r15
jmp 0x55927
movq %r15, %rdi
callq 0x94d0
cmpl $-0x1, %eax
jne 0x55927
movq 0x31751(%rip), %r12     # 0x86ff0
leaq 0x199bd(%rip), %rsi     # 0x6f263
movl $0x14, %edx
movq %r12, %rdi
callq 0x9560
leaq 0x19908(%rip), %rsi     # 0x6f1c2
movl $0x1, %edx
movq %r12, %rdi
callq 0x9560
movq %r12, %rdi
movl $0x42, %esi
callq 0x9880
movq %rax, %r12
leaq 0x17ba1(%rip), %rsi     # 0x6d47f
movl $0x3, %edx
movq %rax, %rdi
callq 0x9560
leaq 0x19986(%rip), %rsi     # 0x6f278
movl $0x11, %edx
movq %r12, %rdi
callq 0x9560
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x9480
movsbl %al, %esi
movq %r12, %rdi
callq 0x9070
movq %rax, %rdi
callq 0x9330
movl $0x2, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x9160
movl %eax, 0x14(%r14)
testl %eax, %eax
jns 0x559d3
movq 0x316a5(%rip), %r12     # 0x86ff0
leaq 0x19911(%rip), %rsi     # 0x6f263
movl $0x14, %edx
movq %r12, %rdi
callq 0x9560
leaq 0x1985c(%rip), %rsi     # 0x6f1c2
movl $0x1, %edx
movq %r12, %rdi
callq 0x9560
movq %r12, %rdi
movl $0x49, %esi
callq 0x9880
movq %rax, %r12
leaq 0x17af5(%rip), %rsi     # 0x6d47f
movl $0x3, %edx
movq %rax, %rdi
callq 0x9560
leaq 0x198ec(%rip), %rsi     # 0x6f28a
movl $0x13, %edx
movq %r12, %rdi
callq 0x9560
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x9480
movsbl %al, %esi
movq %r12, %rdi
callq 0x9070
movq %rax, %rdi
callq 0x9330
leaq 0x4(%r14), %r12
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%r14)
movq $0x2, 0x4(%r14)
movl 0x14(%r14), %edi
movq %r12, %rsi
movl $0x10, %edx
callq 0x90e0
testl %eax, %eax
jns 0x55a98
movl 0x14(%r14), %edi
callq 0x99c0
movq 0x315e0(%rip), %r13     # 0x86ff0
leaq 0x1984c(%rip), %rsi     # 0x6f263
movl $0x14, %edx
movq %r13, %rdi
callq 0x9560
leaq 0x19797(%rip), %rsi     # 0x6f1c2
movl $0x1, %edx
movq %r13, %rdi
callq 0x9560
movq %r13, %rdi
movl $0x57, %esi
callq 0x9880
movq %rax, %r13
leaq 0x17a30(%rip), %rsi     # 0x6d47f
movl $0x3, %edx
movq %rax, %rdi
callq 0x9560
leaq 0x1983b(%rip), %rsi     # 0x6f29e
movl $0x1d, %edx
movq %r13, %rdi
callq 0x9560
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x9480
movsbl %al, %esi
movq %r13, %rdi
callq 0x9070
movq %rax, %rdi
callq 0x9330
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movw $0x2, 0x4(%r14)
movq %r15, %rdi
callq 0x94d0
movl %eax, 0x8(%r14)
rolw $0x8, %bx
movw %bx, 0x6(%r14)
movb $0x1, (%r14)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop