// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
movl %edx, %ebx
movq %rsi, %r15
movq %rdi, %r14
movq %rsi, %rdi
callq 0x9550
testq %rax, %rax
je 0x4721b
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax), %edi
callq 0x9220
movq %rax, %r15
jmp 0x4727b
movq %r15, %rdi
callq 0x94e0
cmpl $-0x1, %eax
jne 0x4727b
movq 0x2fdc1(%rip), %rdi     # 0x76ff0
leaq 0x13fdd(%rip), %rsi     # 0x5b213
callq 0x94b0
leaq 0x13f30(%rip), %rsi     # 0x5b172
movq %rax, %rdi
callq 0x94b0
pushq $0x42
popq %rsi
movq %rax, %rdi
callq 0x9890
leaq 0x121c3(%rip), %rsi     # 0x5941f
movq %rax, %rdi
callq 0x94b0
leaq 0x13fbd(%rip), %rsi     # 0x5b228
movq %rax, %rdi
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
pushq $0x2
popq %rdi
movl %edi, %esi
xorl %edx, %edx
callq 0x9170
movl %eax, 0x14(%r14)
testl %eax, %eax
jns 0x472e6
movq 0x2fd5a(%rip), %rdi     # 0x76ff0
leaq 0x13f76(%rip), %rsi     # 0x5b213
callq 0x94b0
leaq 0x13ec9(%rip), %rsi     # 0x5b172
movq %rax, %rdi
callq 0x94b0
pushq $0x49
popq %rsi
movq %rax, %rdi
callq 0x9890
leaq 0x1215c(%rip), %rsi     # 0x5941f
movq %rax, %rdi
callq 0x94b0
leaq 0x13f68(%rip), %rsi     # 0x5b23a
movq %rax, %rdi
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
movl 0x14(%r14), %eax
leaq 0x4(%r14), %r12
andq $0x0, 0xc(%r14)
movq $0x2, 0x4(%r14)
pushq $0x10
popq %rdx
movl %eax, %edi
movq %r12, %rsi
callq 0x90d0
testl %eax, %eax
jns 0x47364
movl 0x14(%r14), %edi
callq 0x99b0
movq 0x2fcd8(%rip), %rdi     # 0x76ff0
leaq 0x13ef4(%rip), %rsi     # 0x5b213
callq 0x94b0
leaq 0x13e47(%rip), %rsi     # 0x5b172
movq %rax, %rdi
callq 0x94b0
pushq $0x57
popq %rsi
movq %rax, %rdi
callq 0x9890
leaq 0x120da(%rip), %rsi     # 0x5941f
movq %rax, %rdi
callq 0x94b0
leaq 0x13efa(%rip), %rsi     # 0x5b24e
movq %rax, %rdi
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movw $0x2, 0x4(%r14)
movq %r15, %rdi
callq 0x94e0
movl %eax, 0x8(%r14)
rolw $0x8, %bx
movw %bx, 0x6(%r14)
movb $0x1, (%r14)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop