// File: /workspace/github_cpp_makefile_star2_O3/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 0x7879
movq %rdi, %r14
cmpw $0x0, (%rdi)
je 0x7898
movq %rsi, %rbx
testq %rsi, %rsi
je 0x78b7
movl %r8d, %ebp
movq %rcx, %r15
testl %edx, %edx
jne 0x7799
callq 0x4b28
movl %eax, %edx
andl $0x3fff, %edx           # imm = 0x3FFF
orl $0x4000, %edx           # imm = 0x4000
testq %r15, %r15
je 0x77a4
movl 0x4(%r15), %esi
jmp 0x77a6
xorl %esi, %esi
movzbl %bpl, %r15d
movzwl %dx, %edi
movl %r15d, %edx
callq 0x7c14
cmpl $-0x1, %eax
je 0x7862
movl %eax, %ebp
leaq 0x10(%rsp), %r12
movl $0x800, (%r12)          # imm = 0x800
xorl %eax, %eax
leaq 0x116(%rsp), %rdx
movw %ax, 0x100(%rdx)
leaq 0x14(%rsp), %rcx
movw %ax, 0x100(%rcx)
movl %ebp, %edi
movq %r14, %rsi
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x6af5
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 0x7f81
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 0x31ac
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb %cl, %cl
je 0x7867
movq 0x234(%rsp), %rax
movq %rax, (%rbx)
movl %ebp, %eax
jmp 0x7867
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0xee8, %rsp            # imm = 0xEE8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2646(%rip), %rdi      # 0x9ec6
leaq 0x1ec6(%rip), %rsi      # 0x974d
leaq 0x2841(%rip), %rcx      # 0xa0cf
movl $0x8ca, %edx            # imm = 0x8CA
callq 0x2120
leaq 0x2636(%rip), %rdi      # 0x9ed5
leaq 0x1ea7(%rip), %rsi      # 0x974d
leaq 0x2822(%rip), %rcx      # 0xa0cf
movl $0x8cb, %edx            # imm = 0x8CB
callq 0x2120
leaq 0x285f(%rip), %rdi      # 0xa11d
leaq 0x1e88(%rip), %rsi      # 0x974d
leaq 0x2803(%rip), %rcx      # 0xa0cf
movl $0x8cc, %edx            # imm = 0x8CC
callq 0x2120