// File: Distrotech[P]stund/stun.cxx
// Function: stunTest(StunAddress4&, int, bool, StunAddress4*)
void 
stunTest( StunAddress4& dest, int testNum, bool verbose, StunAddress4* sAddr )
{ 
   assert( dest.addr != 0 );
   assert( dest.port != 0 );
	
   int port = stunRandomPort();
   UInt32 interfaceIp=0;
   if (sAddr)
   {
      interfaceIp = sAddr->addr;
      if ( sAddr->port != 0 )
      {
        port = sAddr->port;
      }
   }
   Socket myFd = openPort(port,interfaceIp,verbose);
	
   StunAtrString username;
   StunAtrString password;
	
   username.sizeValue = 0;
   password.sizeValue = 0;
	
#ifdef USE_TLS
   stunGetUserNameAndPassword( dest, username, password );
#endif
	
   stunSendTest( myFd, dest, username, password, testNum, verbose );
    
   char msg[STUN_MAX_MESSAGE_SIZE];
   int msgLen = STUN_MAX_MESSAGE_SIZE;
	
   StunAddress4 from;
   getMessage( myFd,
               msg,
               &msgLen,
               &from.addr,
               &from.port,verbose );
	
   StunMessage resp;
   memset(&resp, 0, sizeof(StunMessage));
	
   if ( verbose ) clog << "Got a response" << endl;
   bool ok = stunParseMessage( msg,msgLen, resp,verbose );
	
   if ( verbose )
   {
      clog << "\t ok=" << ok << endl;
      clog << "\t id=" << resp.msgHdr.id << endl;
      clog << "\t mappedAddr=" << resp.mappedAddress.ipv4 << endl;
      clog << "\t changedAddr=" << resp.changedAddress.ipv4 << endl;
      clog << endl;
   }
	
   if (sAddr)
   {
      sAddr->port = resp.mappedAddress.ipv4.port;
      sAddr->addr = resp.mappedAddress.ipv4.addr;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf10, %rsp            # imm = 0xF10
movb %dl, %al
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
andb $0x1, %al
movb %al, -0xd(%rbp)
movq %rcx, -0x18(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x78c9
jmp 0x78e8
leaq 0x360b(%rip), %rdi      # 0xaedb
leaq 0x2e7e(%rip), %rsi      # 0xa755
movl $0x716, %edx            # imm = 0x716
leaq 0x36a8(%rip), %rcx      # 0xaf8b
callq 0x2140
movq -0x8(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x0, %eax
je 0x78f6
jmp 0x7915
leaq 0x361c(%rip), %rdi      # 0xaf19
leaq 0x2e51(%rip), %rsi      # 0xa755
movl $0x717, %edx            # imm = 0x717
leaq 0x367b(%rip), %rcx      # 0xaf8b
callq 0x2140
callq 0x5050
movl %eax, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x794d
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x0, %eax
je 0x794b
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
movl %eax, -0x1c(%rbp)
jmp 0x794d
movl -0x1c(%rbp), %eax
movw %ax, %cx
movl -0x20(%rbp), %esi
movb -0xd(%rbp), %al
andb $0x1, %al
movzwl %cx, %edi
movzbl %al, %edx
callq 0x8e90
movl %eax, -0x24(%rbp)
movw $0x0, -0x26(%rbp)
movw $0x0, -0x128(%rbp)
movl -0x24(%rbp), %edi
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %r8d
movb -0xd(%rbp), %al
leaq -0x126(%rbp), %rdx
leaq -0x228(%rbp), %rcx
andb $0x1, %al
movzbl %al, %r9d
callq 0x7b70
movl $0x800, -0xa34(%rbp)    # imm = 0x800
movl -0x24(%rbp), %edi
leaq -0xa30(%rbp), %rsi
leaq -0xa3c(%rbp), %rcx
addq $0x4, %rcx
leaq -0xa3c(%rbp), %r8
movb -0xd(%rbp), %al
leaq -0xa34(%rbp), %rdx
andb $0x1, %al
movzbl %al, %r9d
callq 0x91a0
leaq -0xf04(%rbp), %rdi
xorl %esi, %esi
movl $0x4c8, %edx            # imm = 0x4C8
callq 0x2130
testb $0x1, -0xd(%rbp)
je 0x7a15
movq 0x65b6(%rip), %rdi      # 0xdfb0
leaq 0x35c3(%rip), %rsi      # 0xafc4
callq 0x21f0
movq %rax, %rdi
movq 0x65b0(%rip), %rsi      # 0xdfc0
callq 0x2200
leaq -0xa30(%rbp), %rdi
movl -0xa34(%rbp), %esi
movb -0xd(%rbp), %al
leaq -0xf04(%rbp), %rdx
andb $0x1, %al
movzbl %al, %ecx
callq 0x3380
andb $0x1, %al
movb %al, -0xf05(%rbp)
testb $0x1, -0xd(%rbp)
je 0x7b37
movq 0x6561(%rip), %rdi      # 0xdfb0
leaq 0x357d(%rip), %rsi      # 0xafd3
callq 0x21f0
movq %rax, %rdi
movb -0xf05(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x2320
movq %rax, %rdi
movq 0x6548(%rip), %rsi      # 0xdfc0
callq 0x2200
movq 0x652c(%rip), %rdi      # 0xdfb0
leaq 0x354e(%rip), %rsi      # 0xafd9
callq 0x21f0
movq %rax, %rdi
leaq -0xf04(%rbp), %rsi
addq $0x4, %rsi
callq 0x5480
movq %rax, %rdi
movq 0x6513(%rip), %rsi      # 0xdfc0
callq 0x2200
movq 0x64f7(%rip), %rdi      # 0xdfb0
leaq 0x351f(%rip), %rsi      # 0xafdf
callq 0x21f0
movq %rax, %rdi
leaq -0xf04(%rbp), %rsi
addq $0x18, %rsi
addq $0x4, %rsi
callq 0x4040
movq %rax, %rdi
movq 0x64da(%rip), %rsi      # 0xdfc0
callq 0x2200
movq 0x64be(%rip), %rdi      # 0xdfb0
leaq 0x34f4(%rip), %rsi      # 0xafed
callq 0x21f0
movq %rax, %rdi
leaq -0xf04(%rbp), %rsi
addq $0x50, %rsi
addq $0x4, %rsi
callq 0x4040
movq %rax, %rdi
movq 0x64a1(%rip), %rsi      # 0xdfc0
callq 0x2200
movq 0x6485(%rip), %rdi      # 0xdfb0
movq 0x648e(%rip), %rsi      # 0xdfc0
callq 0x2200
cmpq $0x0, -0x18(%rbp)
je 0x7b59
movw -0xee8(%rbp), %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movl -0xee4(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
addq $0xf10, %rsp            # imm = 0xF10
popq %rbp
retq
nopw %cs:(%rax,%rax)