// File: Distrotech[P]stund/stun.cxx
// Function: stunBuildReqSimple(StunMessage*, StunAtrString const&, bool, bool, unsigned int)
void
stunBuildReqSimple( StunMessage* msg,
                    const StunAtrString& username,
                    bool changePort, bool changeIp, unsigned int id )
{
   assert( msg );
   memset( msg , 0 , sizeof(*msg) );
	
   msg->msgHdr.msgType = BindRequestMsg;
	
   for ( int i=0; i<16; i=i+4 )
   {
      assert(i+3<16);
      int r = stunRand();
      msg->msgHdr.id.octet[i+0]= r>>0;
      msg->msgHdr.id.octet[i+1]= r>>8;
      msg->msgHdr.id.octet[i+2]= r>>16;
      msg->msgHdr.id.octet[i+3]= r>>24;
   }
	
   if ( id != 0 )
   {
      msg->msgHdr.id.octet[0] = id; 
   }
	
   msg->hasChangeRequest = true;
   msg->changeRequest.value =(changeIp?ChangeIpFlag:0) | 
      (changePort?ChangePortFlag:0);
	
   if ( username.sizeValue > 0 )
   {
      msg->hasUsername = true;
      msg->username = username;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movb %cl, %al
movb %dl, %cl
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %cl
movb %cl, -0x11(%rbp)
andb $0x1, %al
movb %al, -0x12(%rbp)
movl %r8d, -0x18(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x76ec
jmp 0x770b
leaq 0x3835(%rip), %rdi      # 0xaf28
leaq 0x305b(%rip), %rsi      # 0xa755
movl $0x6a4, %edx            # imm = 0x6A4
leaq 0x3826(%rip), %rcx      # 0xaf2c
callq 0x2140
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x4c8, %edx            # imm = 0x4C8
callq 0x2130
movq -0x8(%rbp), %rax
movw $0x1, (%rax)
movl $0x0, -0x1c(%rbp)
cmpl $0x10, -0x1c(%rbp)
jge 0x77db
movl -0x1c(%rbp), %eax
addl $0x3, %eax
cmpl $0x10, %eax
jge 0x7742
jmp 0x7761
leaq 0x383b(%rip), %rdi      # 0xaf84
leaq 0x3005(%rip), %rsi      # 0xa755
movl $0x6ab, %edx            # imm = 0x6AB
leaq 0x37d0(%rip), %rcx      # 0xaf2c
callq 0x2140
callq 0x4ff0
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
sarl $0x0, %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movb %dl, 0x4(%rax,%rcx)
movl -0x20(%rbp), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, 0x4(%rax,%rcx)
movl -0x20(%rbp), %eax
sarl $0x10, %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, 0x4(%rax,%rcx)
movl -0x20(%rbp), %eax
sarl $0x18, %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb %dl, 0x4(%rax,%rcx)
movl -0x1c(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x1c(%rbp)
jmp 0x772b
cmpl $0x0, -0x18(%rbp)
je 0x77ed
movl -0x18(%rbp), %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x4(%rax)
movq -0x8(%rbp), %rax
movb $0x1, 0x34(%rax)
movb -0x12(%rbp), %dl
xorl %ecx, %ecx
movl $0x4, %eax
testb $0x1, %dl
cmovnel %eax, %ecx
movb -0x11(%rbp), %sil
xorl %eax, %eax
movl $0x2, %edx
testb $0x1, %sil
cmovnel %edx, %eax
orl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x10(%rbp), %rax
movzwl 0x100(%rax), %eax
cmpl $0x0, %eax
jle 0x784e
movq -0x8(%rbp), %rax
movb $0x1, 0x5c(%rax)
movq -0x10(%rbp), %rsi
movq -0x8(%rbp), %rdi
addq $0x5e, %rdi
movl $0x102, %edx            # imm = 0x102
callq 0x2190
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)