// File: /workspace/github_cpp_makefile_star2_O2/Distrotech[P]stund/stun.cxx
// Function: stunOpenSocket(StunAddress4&, StunAddress4*, int, StunAddress4*, bool)
int
stunOpenSocket( StunAddress4& dest, StunAddress4* mapAddr, 
                int port, StunAddress4* srcAddr, 
                bool verbose )
{
   assert( dest.addr != 0 );
   assert( dest.port != 0 );
   assert( mapAddr );
   
   if ( port == 0 )
   {
      port = stunRandomPort();
   }
   unsigned int interfaceIp = 0;
   if ( srcAddr )
   {
      interfaceIp = srcAddr->addr;
   }
   
   Socket myFd = openPort(port,interfaceIp,verbose);
   if (myFd == INVALID_SOCKET)
   {
      return myFd;
   }
   
   char msg[STUN_MAX_MESSAGE_SIZE];
   int msgLen = sizeof(msg);
	
   StunAtrString username;
   StunAtrString password;
	
   username.sizeValue = 0;
   password.sizeValue = 0;
	
#ifdef USE_TLS
   stunGetUserNameAndPassword( dest, username, password );
#endif
	
   stunSendTest(myFd, dest, username, password, 1, 0/*false*/ );
	
   StunAddress4 from;
	
   getMessage( myFd, msg, &msgLen, &from.addr, &from.port,verbose );
	
   StunMessage resp;
   memset(&resp, 0, sizeof(StunMessage));
	
   bool ok = stunParseMessage( msg, msgLen, resp,verbose );
   if (!ok)
   {
      return -1;
   }
	
   StunAddress4 mappedAddr = resp.mappedAddress.ipv4;
   StunAddress4 changedAddr = resp.changedAddress.ipv4;
	
   //clog << "--- stunOpenSocket --- " << endl;
   //clog << "\treq  id=" << req.id << endl;
   //clog << "\tresp id=" << id << endl;
   //clog << "\tmappedAddr=" << mappedAddr << endl;
	
   *mapAddr = mappedAddr;
	
   return myFd;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xee8, %rsp            # imm = 0xEE8
cmpl $0x0, 0x4(%rdi)
je 0x648f
movq %rdi, %r14
cmpw $0x0, (%rdi)
je 0x64ae
movq %rsi, %rbx
testq %rsi, %rsi
je 0x64cd
movl %r8d, %ebp
movq %rcx, %r15
testl %edx, %edx
jne 0x63ba
callq 0x40cb
movl %eax, %edx
testq %r15, %r15
je 0x63c5
movl 0x4(%r15), %esi
jmp 0x63c7
xorl %esi, %esi
movzbl %bpl, %r15d
movzwl %dx, %edi
movl %r15d, %edx
callq 0x67f4
cmpl $-0x1, %eax
je 0x6478
movl %eax, %ebp
leaq 0x10(%rsp), %r12
movl $0x800, (%r12)          # imm = 0x800
leaq 0x116(%rsp), %rdx
andw $0x0, 0x100(%rdx)
leaq 0x14(%rsp), %rcx
andw $0x0, 0x100(%rcx)
pushq $0x1
popq %r8
movl %eax, %edi
movq %r14, %rsi
xorl %r9d, %r9d
callq 0x5916
leaq 0xc(%rsp), %rcx
leaq 0x6e0(%rsp), %r14
leaq 0x8(%rsp), %r8
movl %ebp, %edi
movq %r14, %rsi
movq %r12, %rdx
movl %r15d, %r9d
callq 0x6a0e
leaq 0x218(%rsp), %r13
movl $0x4c8, %edx            # imm = 0x4C8
movq %r13, %rdi
xorl %esi, %esi
callq 0x2110
movl (%r12), %esi
movq %r14, %rdi
movq %r13, %rdx
movl %r15d, %ecx
callq 0x2d54
testb %al, %al
je 0x6478
movq 0x234(%rsp), %rax
movq %rax, (%rbx)
jmp 0x647b
pushq $-0x1
popq %rbp
movl %ebp, %eax
addq $0xee8, %rsp            # imm = 0xEE8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a30(%rip), %rdi      # 0x7ec6
leaq 0x12b0(%rip), %rsi      # 0x774d
leaq 0x1c2b(%rip), %rcx      # 0x80cf
movl $0x8ca, %edx            # imm = 0x8CA
callq 0x2120
leaq 0x1a20(%rip), %rdi      # 0x7ed5
leaq 0x1291(%rip), %rsi      # 0x774d
leaq 0x1c0c(%rip), %rcx      # 0x80cf
movl $0x8cb, %edx            # imm = 0x8CB
callq 0x2120
leaq 0x1c49(%rip), %rdi      # 0x811d
leaq 0x1272(%rip), %rsi      # 0x774d
leaq 0x1bed(%rip), %rcx      # 0x80cf
movl $0x8cc, %edx            # imm = 0x8CC
callq 0x2120