// File: /workspace/github_cpp_makefile_star2_O1/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 0x786d
movq %rdi, %r14
cmpw $0x0, (%rdi)
je 0x788c
movq %rsi, %rbx
testq %rsi, %rsi
je 0x78ab
movl %r8d, %ebp
movq %rcx, %r15
testl %edx, %edx
jne 0x778d
callq 0x4b17
movl %eax, %edx
andl $0x3fff, %edx           # imm = 0x3FFF
orl $0x4000, %edx           # imm = 0x4000
testq %r15, %r15
je 0x7798
movl 0x4(%r15), %esi
jmp 0x779a
xorl %esi, %esi
movzbl %bpl, %r15d
movzwl %dx, %edi
movl %r15d, %edx
callq 0x7c10
cmpl $-0x1, %eax
je 0x7856
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 0x6a54
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 0x7f4a
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 0x3248
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb %cl, %cl
je 0x785b
movq 0x234(%rsp), %rax
movq %rax, (%rbx)
movl %ebp, %eax
jmp 0x785b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0xee8, %rsp            # imm = 0xEE8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x265a(%rip), %rdi      # 0x9ece
leaq 0x1eda(%rip), %rsi      # 0x9755
leaq 0x2855(%rip), %rcx      # 0xa0d7
movl $0x8ca, %edx            # imm = 0x8CA
callq 0x2120
leaq 0x264a(%rip), %rdi      # 0x9edd
leaq 0x1ebb(%rip), %rsi      # 0x9755
leaq 0x2836(%rip), %rcx      # 0xa0d7
movl $0x8cb, %edx            # imm = 0x8CB
callq 0x2120
leaq 0x2873(%rip), %rdi      # 0xa125
leaq 0x1e9c(%rip), %rsi      # 0x9755
leaq 0x2817(%rip), %rcx      # 0xa0d7
movl $0x8cc, %edx            # imm = 0x8CC
callq 0x2120