// File: /workspace/github_cpp_makefile_star2_O1/Distrotech[P]stund/stun.cxx
// Function: stunEncodeMessage(StunMessage const&, char*, unsigned int, StunAtrString const&, bool)
unsigned int
stunEncodeMessage( const StunMessage& msg, 
                   char* buf, 
                   unsigned int bufLen, 
                   const StunAtrString& password, 
                   bool verbose)
{
   assert(bufLen >= sizeof(StunMsgHdr));
   char* ptr = buf;
	
   ptr = encode16(ptr, msg.msgHdr.msgType);
   char* lengthp = ptr;
   ptr = encode16(ptr, 0);
   ptr = encode(ptr, reinterpret_cast<const char*>(msg.msgHdr.id.octet), sizeof(msg.msgHdr.id));
	
   if (verbose) clog << "Encoding stun message: " << endl;
   if (msg.hasMappedAddress)
   {
      if (verbose) clog << "Encoding MappedAddress: " << msg.mappedAddress.ipv4 << endl;
      ptr = encodeAtrAddress4 (ptr, MappedAddress, msg.mappedAddress);
   }
   if (msg.hasResponseAddress)
   {
      if (verbose) clog << "Encoding ResponseAddress: " << msg.responseAddress.ipv4 << endl;
      ptr = encodeAtrAddress4(ptr, ResponseAddress, msg.responseAddress);
   }
   if (msg.hasChangeRequest)
   {
      if (verbose) clog << "Encoding ChangeRequest: " << msg.changeRequest.value << endl;
      ptr = encodeAtrChangeRequest(ptr, msg.changeRequest);
   }
   if (msg.hasSourceAddress)
   {
      if (verbose) clog << "Encoding SourceAddress: " << msg.sourceAddress.ipv4 << endl;
      ptr = encodeAtrAddress4(ptr, SourceAddress, msg.sourceAddress);
   }
   if (msg.hasChangedAddress)
   {
      if (verbose) clog << "Encoding ChangedAddress: " << msg.changedAddress.ipv4 << endl;
      ptr = encodeAtrAddress4(ptr, ChangedAddress, msg.changedAddress);
   }
   if (msg.hasUsername)
   {
      if (verbose) clog << "Encoding Username: " << msg.username.value << endl;
      ptr = encodeAtrString(ptr, Username, msg.username);
   }
   if (msg.hasPassword)
   {
      if (verbose) clog << "Encoding Password: " << msg.password.value << endl;
      ptr = encodeAtrString(ptr, Password, msg.password);
   }
   if (msg.hasErrorCode)
   {
      if (verbose) clog << "Encoding ErrorCode: class=" 
			<< int(msg.errorCode.errorClass)  
			<< " number=" << int(msg.errorCode.number) 
			<< " reason=" 
			<< msg.errorCode.reason 
			<< endl;
		
      ptr = encodeAtrError(ptr, msg.errorCode);
   }
   if (msg.hasUnknownAttributes)
   {
      if (verbose) clog << "Encoding UnknownAttribute: ???" << endl;
      ptr = encodeAtrUnknown(ptr, msg.unknownAttributes);
   }
   if (msg.hasReflectedFrom)
   {
      if (verbose) clog << "Encoding ReflectedFrom: " << msg.reflectedFrom.ipv4 << endl;
      ptr = encodeAtrAddress4(ptr, ReflectedFrom, msg.reflectedFrom);
   }
   if (msg.hasXorMappedAddress)
   {
      if (verbose) clog << "Encoding XorMappedAddress: " << msg.xorMappedAddress.ipv4 << endl;
      ptr = encodeAtrAddress4 (ptr, XorMappedAddress, msg.xorMappedAddress);
   }
   if (msg.xorOnly)
   {
      if (verbose) clog << "Encoding xorOnly: " << endl;
      ptr = encodeXorOnly( ptr );
   }
   if (msg.hasServerName)
   {
      if (verbose) clog << "Encoding ServerName: " << msg.serverName.value << endl;
      ptr = encodeAtrString(ptr, ServerName, msg.serverName);
   }
   if (msg.hasSecondaryAddress)
   {
      if (verbose) clog << "Encoding SecondaryAddress: " << msg.secondaryAddress.ipv4 << endl;
      ptr = encodeAtrAddress4 (ptr, SecondaryAddress, msg.secondaryAddress);
   }

   if (password.sizeValue > 0)
   {
      if (verbose) clog << "HMAC with password: " << password.value << endl;
		
      StunAtrIntegrity integrity;
      computeHmac(integrity.hash, buf, int(ptr-buf) , password.value, password.sizeValue);
      ptr = encodeAtrIntegrity(ptr, integrity);
   }
   if (verbose) clog << endl;
	
   encode16(lengthp, UInt16(ptr - buf - sizeof(StunMsgHdr)));
   return int(ptr - buf);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, (%rsp)
cmpl $0x13, %edx
jbe 0x4a8c
movl %r8d, %ebp
movq %rsi, %rbx
movq %rdi, %r15
movzwl (%rdi), %eax
rolw $0x8, %ax
movw %ax, (%rsi)
movw $0x0, 0x2(%rsi)
movups 0x4(%rdi), %xmm0
movups %xmm0, 0x4(%rsi)
testb %bpl, %bpl
je 0x413c
movq 0x8eb8(%rip), %r12      # 0xcfb8
leaq 0x56be(%rip), %rsi      # 0x97c5
movl $0x17, %edx
movq %r12, %rdi
callq 0x21f0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
cmpb $0x1, 0x14(%r15)
jne 0x41c9
testb %bpl, %bpl
je 0x419b
movq 0x8e65(%rip), %r12      # 0xcfb8
leaq 0x5683(%rip), %rsi      # 0x97dd
movl $0x18, %edx
movq %r12, %rdi
callq 0x21f0
leaq 0x1c(%r15), %rsi
movq %r12, %rdi
callq 0x3f5b
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movl $0x8000100, 0x14(%rbx)  # imm = 0x8000100
movb 0x18(%r15), %al
movb %al, 0x18(%rbx)
movb $0x1, 0x19(%rbx)
movzwl 0x1c(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x1a(%rbx)
movl 0x20(%r15), %eax
bswapl %eax
movl %eax, 0x1c(%rbx)
leaq 0x20(%rbx), %r12
jmp 0x41cd
leaq 0x14(%rbx), %r12
cmpb $0x1, 0x24(%r15)
jne 0x4261
testb %bpl, %bpl
je 0x422c
movq 0x8dd4(%rip), %r13      # 0xcfb8
leaq 0x560b(%rip), %rsi      # 0x97f6
movl $0x1a, %edx
movq %r13, %rdi
callq 0x21f0
leaq 0x2c(%r15), %rsi
movq %r13, %rdi
callq 0x3f5b
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movl $0x8000200, (%r12)      # imm = 0x8000200
movb 0x28(%r15), %al
movb %al, 0x4(%r12)
movb $0x1, 0x5(%r12)
movzwl 0x2c(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x6(%r12)
movl 0x30(%r15), %eax
bswapl %eax
movl %eax, 0x8(%r12)
addq $0xc, %r12
cmpb $0x1, 0x34(%r15)
jne 0x42d5
testb %bpl, %bpl
je 0x42be
movq 0x8d44(%rip), %r13      # 0xcfb8
leaq 0x5596(%rip), %rsi      # 0x9811
movl $0x18, %edx
movq %r13, %rdi
callq 0x21f0
movl 0x38(%r15), %esi
movq %r13, %rdi
callq 0x2130
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movl $0x4000300, (%r12)      # imm = 0x4000300
movl 0x38(%r15), %eax
bswapl %eax
movl %eax, 0x4(%r12)
addq $0x8, %r12
cmpb $0x1, 0x3c(%r15)
jne 0x4369
testb %bpl, %bpl
je 0x4334
movq 0x8ccc(%rip), %r13      # 0xcfb8
leaq 0x5537(%rip), %rsi      # 0x982a
movl $0x18, %edx
movq %r13, %rdi
callq 0x21f0
leaq 0x44(%r15), %rsi
movq %r13, %rdi
callq 0x3f5b
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movl $0x8000400, (%r12)      # imm = 0x8000400
movb 0x40(%r15), %al
movb %al, 0x4(%r12)
movb $0x1, 0x5(%r12)
movzwl 0x44(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x6(%r12)
movl 0x48(%r15), %eax
bswapl %eax
movl %eax, 0x8(%r12)
addq $0xc, %r12
cmpb $0x1, 0x4c(%r15)
jne 0x43fd
testb %bpl, %bpl
je 0x43c8
movq 0x8c38(%rip), %r13      # 0xcfb8
leaq 0x54bc(%rip), %rsi      # 0x9843
movl $0x19, %edx
movq %r13, %rdi
callq 0x21f0
leaq 0x54(%r15), %rsi
movq %r13, %rdi
callq 0x3f5b
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movl $0x8000500, (%r12)      # imm = 0x8000500
movb 0x50(%r15), %al
movb %al, 0x4(%r12)
movb $0x1, 0x5(%r12)
movzwl 0x54(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x6(%r12)
movl 0x58(%r15), %eax
bswapl %eax
movl %eax, 0x8(%r12)
addq $0xc, %r12
cmpb $0x1, 0x5c(%r15)
jne 0x447a
testb %bpl, %bpl
je 0x4466
movq 0x8ba8(%rip), %r13      # 0xcfb8
leaq 0x5446(%rip), %rsi      # 0x985d
movl $0x13, %edx
movq %r13, %rdi
callq 0x21f0
leaq 0x5e(%r15), %r14
movq %r14, %rdi
callq 0x20c0
movq %r13, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x21f0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
leaq 0x5e(%r15), %rdx
movq %r12, %rdi
movl $0x6, %esi
callq 0x4aab
movq %rax, %r12
cmpb $0x1, 0x160(%r15)
jne 0x4500
testb %bpl, %bpl
je 0x44e9
movq 0x8b28(%rip), %r13      # 0xcfb8
leaq 0x53da(%rip), %rsi      # 0x9871
movl $0x13, %edx
movq %r13, %rdi
callq 0x21f0
leaq 0x162(%r15), %r14
movq %r14, %rdi
callq 0x20c0
movq %r13, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x21f0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
leaq 0x162(%r15), %rdx
movq %r12, %rdi
movl $0x7, %esi
callq 0x4aab
movq %rax, %r12
cmpb $0x1, 0x279(%r15)
jne 0x462e
testb %bpl, %bpl
je 0x45c5
movq 0x8a9a(%rip), %r14      # 0xcfb8
leaq 0x5360(%rip), %rsi      # 0x9885
movl $0x1a, %edx
movq %r14, %rdi
callq 0x21f0
movzbl 0x27c(%r15), %esi
movq %r14, %rdi
callq 0x22a0
movq %rax, %r14
leaq 0x5354(%rip), %rsi      # 0x98a0
movl $0x8, %edx
movq %rax, %rdi
callq 0x21f0
movzbl 0x27d(%r15), %esi
movq %r14, %rdi
callq 0x22a0
movq %rax, %r13
leaq 0x5336(%rip), %rsi      # 0x98a9
movl $0x8, %edx
movq %rax, %rdi
callq 0x21f0
leaq 0x27e(%r15), %r14
movq %r14, %rdi
callq 0x20c0
movq %r13, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x21f0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movw $0x900, (%r12)          # imm = 0x900
movzwl 0x37e(%r15), %eax
addl $0x6, %eax
rolw $0x8, %ax
movw %ax, 0x2(%r12)
movzwl 0x27a(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x4(%r12)
movb 0x27c(%r15), %al
movb %al, 0x6(%r12)
movb 0x27d(%r15), %al
leaq 0x8(%r12), %rdi
movb %al, 0x7(%r12)
leaq 0x27e(%r15), %rsi
movzwl 0x37e(%r15), %r14d
movq %r14, %rdx
callq 0x2170
addq %r14, %r12
addq $0x8, %r12
cmpb $0x1, 0x380(%r15)
jne 0x46da
testb %bpl, %bpl
je 0x4683
movq 0x8970(%rip), %r14      # 0xcfb8
leaq 0x5263(%rip), %rsi      # 0x98b2
movl $0x1e, %edx
movq %r14, %rdi
callq 0x21f0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movw $0xa00, (%r12)          # imm = 0xA00
movzwl 0x392(%r15), %eax
leal 0x2(,%rax,2), %eax
rolw $0x8, %ax
movw %ax, 0x2(%r12)
addq $0x4, %r12
cmpw $0x0, 0x392(%r15)
je 0x46da
xorl %eax, %eax
movzwl 0x382(%r15,%rax,2), %ecx
rolw $0x8, %cx
movw %cx, (%r12)
addq $0x2, %r12
incq %rax
movzwl 0x392(%r15), %ecx
cmpq %rcx, %rax
jb 0x46b4
cmpb $0x1, 0x394(%r15)
jne 0x477c
testb %bpl, %bpl
je 0x473e
movq 0x88c4(%rip), %r14      # 0xcfb8
leaq 0x51d6(%rip), %rsi      # 0x98d1
movl $0x18, %edx
movq %r14, %rdi
callq 0x21f0
leaq 0x39c(%r15), %rsi
movq %r14, %rdi
callq 0x3f5b
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movl $0x8000b00, (%r12)      # imm = 0x8000B00
movb 0x398(%r15), %al
movb %al, 0x4(%r12)
movb $0x1, 0x5(%r12)
movzwl 0x39c(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x6(%r12)
movl 0x3a0(%r15), %eax
bswapl %eax
movl %eax, 0x8(%r12)
addq $0xc, %r12
cmpb $0x1, 0x3a4(%r15)
jne 0x481e
testb %bpl, %bpl
je 0x47e0
movq 0x8822(%rip), %r14      # 0xcfb8
leaq 0x514d(%rip), %rsi      # 0x98ea
movl $0x1b, %edx
movq %r14, %rdi
callq 0x21f0
leaq 0x3ac(%r15), %rsi
movq %r14, %rdi
callq 0x3f5b
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movl $0x8002080, (%r12)      # imm = 0x8002080
movb 0x3a8(%r15), %al
movb %al, 0x4(%r12)
movb $0x1, 0x5(%r12)
movzwl 0x3ac(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x6(%r12)
movl 0x3b0(%r15), %eax
bswapl %eax
movl %eax, 0x8(%r12)
addq $0xc, %r12
cmpb $0x1, 0x3b4(%r15)
jne 0x487a
testb %bpl, %bpl
je 0x486f
movq 0x8784(%rip), %r14      # 0xcfb8
leaq 0x50cb(%rip), %rsi      # 0x9906
movl $0x12, %edx
movq %r14, %rdi
callq 0x21f0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movw $0x2100, (%r12)         # imm = 0x2100
addq $0x2, %r12
cmpb $0x1, 0x3b5(%r15)
jne 0x4900
testb %bpl, %bpl
je 0x48e9
movq 0x8728(%rip), %r13      # 0xcfb8
leaq 0x5082(%rip), %rsi      # 0x9919
movl $0x15, %edx
movq %r13, %rdi
callq 0x21f0
leaq 0x3b6(%r15), %r14
movq %r14, %rdi
callq 0x20c0
movq %r13, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x21f0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
leaq 0x3b6(%r15), %rdx
movq %r12, %rdi
movl $0x8022, %esi           # imm = 0x8022
callq 0x4aab
movq %rax, %r12
cmpb $0x1, 0x4b8(%r15)
jne 0x49a2
testb %bpl, %bpl
je 0x4964
movq 0x869e(%rip), %r14      # 0xcfb8
leaq 0x500e(%rip), %rsi      # 0x992f
movl $0x1b, %edx
movq %r14, %rdi
callq 0x21f0
leaq 0x4c0(%r15), %rsi
movq %r14, %rdi
callq 0x3f5b
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movl $0x8005080, (%r12)      # imm = 0x8005080
movb 0x4bc(%r15), %al
movb %al, 0x4(%r12)
movb $0x1, 0x5(%r12)
movzwl 0x4c0(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x6(%r12)
movl 0x4c4(%r15), %eax
bswapl %eax
movl %eax, 0x8(%r12)
addq $0xc, %r12
movq (%rsp), %rax
cmpw $0x0, 0x100(%rax)
je 0x4a37
testb %bpl, %bpl
je 0x4a15
movq 0x85f8(%rip), %r15      # 0xcfb8
leaq 0x4f84(%rip), %rsi      # 0x994b
movl $0x14, %edx
movq %r15, %rdi
callq 0x21f0
movq (%rsp), %r14
movq %r14, %rdi
callq 0x20c0
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x21f0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movl $0x14000800, (%r12)     # imm = 0x14000800
movaps 0x594c(%rip), %xmm0     # 0xa370
movups %xmm0, 0x4(%r12)
movl $0x6465746e, 0x14(%r12) # imm = 0x6465746E
addq $0x18, %r12
testb %bpl, %bpl
je 0x4a6a
movq 0x8575(%rip), %r14      # 0xcfb8
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
subl %ebx, %r12d
leal -0x14(%r12), %eax
rolw $0x8, %ax
movw %ax, 0x2(%rbx)
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4ca5(%rip), %rdi      # 0x9738
leaq 0x4cbb(%rip), %rsi      # 0x9755
leaq 0x4cbd(%rip), %rcx      # 0x975e
movl $0x225, %edx            # imm = 0x225
callq 0x2120