// File: /workspace/github_cpp_makefile_star2_O3/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 0x4a9d
movl %r8d, %ebp
movq %rsi, %rbx
movq %rdi, %r12
movzwl (%rdi), %eax
rolw $0x8, %ax
movw %ax, (%rsi)
movw $0x0, 0x2(%rsi)
movups 0x4(%rdi), %xmm0
movups %xmm0, 0x4(%rsi)
leaq 0x14(%rsi), %r14
testb %bpl, %bpl
je 0x3ffb
movq 0x9050(%rip), %r13      # 0xcfb8
leaq 0x584e(%rip), %rsi      # 0x97bd
movl $0x17, %edx
movq %r13, %rdi
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
cmpb $0x0, 0x14(%r12)
je 0x4049
leaq 0x581e(%rip), %rsi      # 0x97d5
movl $0x18, %edx
movq %r13, %rdi
callq 0x21f0
leaq 0x1c(%r12), %rsi
movq %r13, %rdi
callq 0x3dbb
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
jmp 0x4007
cmpb $0x0, 0x14(%r12)
je 0x40a7
movl $0x8000100, 0x14(%rbx)  # imm = 0x8000100
movb 0x18(%r12), %al
movb %al, 0x18(%rbx)
movb $0x1, 0x19(%rbx)
movzwl 0x1c(%r12), %eax
rolw $0x8, %ax
movw %ax, 0x1a(%rbx)
movl 0x20(%r12), %eax
bswapl %eax
movl %eax, 0x1c(%rbx)
leaq 0x20(%rbx), %r14
cmpb $0x0, 0x24(%r12)
je 0x40e6
testb %bpl, %bpl
jne 0x4055
jmp 0x40b3
cmpb $0x0, 0x24(%r12)
je 0x40f5
movq 0x8f5c(%rip), %r13      # 0xcfb8
leaq 0x578b(%rip), %rsi      # 0x97ee
movl $0x1a, %edx
movq %r13, %rdi
callq 0x21f0
leaq 0x2c(%r12), %rsi
movq %r13, %rdi
callq 0x3dbb
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
jmp 0x40b3
cmpb $0x0, 0x24(%r12)
je 0x492b
movl $0x8000200, (%r14)      # imm = 0x8000200
movb 0x28(%r12), %al
movb %al, 0x4(%r14)
movb $0x1, 0x5(%r14)
movzwl 0x2c(%r12), %eax
rolw $0x8, %ax
movw %ax, 0x6(%r14)
movl 0x30(%r12), %eax
bswapl %eax
movl %eax, 0x8(%r14)
addq $0xc, %r14
cmpb $0x0, 0x34(%r12)
je 0x4169
testb %bpl, %bpl
jne 0x4101
jmp 0x4153
cmpb $0x0, 0x34(%r12)
je 0x49ea
movq 0x8eb0(%rip), %r13      # 0xcfb8
leaq 0x56fa(%rip), %rsi      # 0x9809
movl $0x18, %edx
movq %r13, %rdi
callq 0x21f0
movl 0x38(%r12), %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, (%r14)      # imm = 0x4000300
movl 0x38(%r12), %eax
bswapl %eax
movl %eax, 0x4(%r14)
addq $0x8, %r14
cmpb $0x0, 0x3c(%r12)
je 0x41fd
testb %bpl, %bpl
je 0x41ca
movq 0x8e37(%rip), %r13      # 0xcfb8
leaq 0x569a(%rip), %rsi      # 0x9822
movl $0x18, %edx
movq %r13, %rdi
callq 0x21f0
leaq 0x44(%r12), %rsi
movq %r13, %rdi
callq 0x3dbb
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, (%r14)      # imm = 0x8000400
movb 0x40(%r12), %al
movb %al, 0x4(%r14)
movb $0x1, 0x5(%r14)
movzwl 0x44(%r12), %eax
rolw $0x8, %ax
movw %ax, 0x6(%r14)
movl 0x48(%r12), %eax
bswapl %eax
movl %eax, 0x8(%r14)
addq $0xc, %r14
cmpb $0x0, 0x4c(%r12)
je 0x4291
testb %bpl, %bpl
je 0x425e
movq 0x8da3(%rip), %r13      # 0xcfb8
leaq 0x561f(%rip), %rsi      # 0x983b
movl $0x19, %edx
movq %r13, %rdi
callq 0x21f0
leaq 0x54(%r12), %rsi
movq %r13, %rdi
callq 0x3dbb
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, (%r14)      # imm = 0x8000500
movb 0x50(%r12), %al
movb %al, 0x4(%r14)
movb $0x1, 0x5(%r14)
movzwl 0x54(%r12), %eax
rolw $0x8, %ax
movw %ax, 0x6(%r14)
movl 0x58(%r12), %eax
bswapl %eax
movl %eax, 0x8(%r14)
addq $0xc, %r14
cmpb $0x0, 0x5c(%r12)
je 0x4311
testb %bpl, %bpl
je 0x42fc
movq 0x8d13(%rip), %r13      # 0xcfb8
leaq 0x55a9(%rip), %rsi      # 0x9855
movl $0x13, %edx
movq %r13, %rdi
callq 0x21f0
leaq 0x5e(%r12), %r15
movq %r15, %rdi
callq 0x20c0
movq %r13, %rdi
movq %r15, %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(%r12), %rdx
movq %r14, %rdi
movl $0x6, %esi
callq 0x4abc
movq %rax, %r14
cmpb $0x0, 0x160(%r12)
je 0x439a
testb %bpl, %bpl
je 0x4382
movq 0x8c90(%rip), %r13      # 0xcfb8
leaq 0x553a(%rip), %rsi      # 0x9869
movl $0x13, %edx
movq %r13, %rdi
callq 0x21f0
leaq 0x162(%r12), %r15
movq %r15, %rdi
callq 0x20c0
movq %r13, %rdi
movq %r15, %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(%r12), %rdx
movq %r14, %rdi
movl $0x7, %esi
callq 0x4abc
movq %rax, %r14
cmpb $0x0, 0x279(%r12)
je 0x44cc
testb %bpl, %bpl
je 0x4463
movq 0x8bff(%rip), %r15      # 0xcfb8
leaq 0x54bd(%rip), %rsi      # 0x987d
movl $0x1a, %edx
movq %r15, %rdi
callq 0x21f0
movzbl 0x27c(%r12), %esi
movq %r15, %rdi
callq 0x2290
movq %rax, %r15
leaq 0x54b0(%rip), %rsi      # 0x9898
movl $0x8, %edx
movq %rax, %rdi
callq 0x21f0
movzbl 0x27d(%r12), %esi
movq %r15, %rdi
callq 0x2290
movq %rax, %r13
leaq 0x5491(%rip), %rsi      # 0x98a1
movl $0x8, %edx
movq %rax, %rdi
callq 0x21f0
leaq 0x27e(%r12), %r15
movq %r15, %rdi
callq 0x20c0
movq %r13, %rdi
movq %r15, %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, (%r14)          # imm = 0x900
movzwl 0x37e(%r12), %eax
addl $0x6, %eax
rolw $0x8, %ax
movw %ax, 0x2(%r14)
movzwl 0x27a(%r12), %eax
rolw $0x8, %ax
movw %ax, 0x4(%r14)
movb 0x27c(%r12), %al
movb %al, 0x6(%r14)
movb 0x27d(%r12), %al
leaq 0x8(%r14), %rdi
movb %al, 0x7(%r14)
leaq 0x27e(%r12), %rsi
movzwl 0x37e(%r12), %r15d
movq %r15, %rdx
callq 0x2170
addq %r15, %r14
addq $0x8, %r14
cmpb $0x0, 0x380(%r12)
je 0x4579
testb %bpl, %bpl
je 0x4522
movq 0x8ad1(%rip), %r15      # 0xcfb8
leaq 0x53bc(%rip), %rsi      # 0x98aa
movl $0x1e, %edx
movq %r15, %rdi
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
movw $0xa00, (%r14)          # imm = 0xA00
movzwl 0x392(%r12), %eax
leal 0x2(,%rax,2), %eax
rolw $0x8, %ax
movw %ax, 0x2(%r14)
addq $0x4, %r14
cmpw $0x0, 0x392(%r12)
je 0x4579
xorl %eax, %eax
movzwl 0x382(%r12,%rax,2), %ecx
rolw $0x8, %cx
movw %cx, (%r14)
addq $0x2, %r14
incq %rax
movzwl 0x392(%r12), %ecx
cmpq %rcx, %rax
jb 0x4553
cmpb $0x0, 0x394(%r12)
je 0x461b
testb %bpl, %bpl
je 0x45df
movq 0x8a24(%rip), %r15      # 0xcfb8
leaq 0x532e(%rip), %rsi      # 0x98c9
movl $0x18, %edx
movq %r15, %rdi
callq 0x21f0
leaq 0x39c(%r12), %rsi
movq %r15, %rdi
callq 0x3dbb
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 $0x8000b00, (%r14)      # imm = 0x8000B00
movb 0x398(%r12), %al
movb %al, 0x4(%r14)
movb $0x1, 0x5(%r14)
movzwl 0x39c(%r12), %eax
rolw $0x8, %ax
movw %ax, 0x6(%r14)
movl 0x3a0(%r12), %eax
bswapl %eax
movl %eax, 0x8(%r14)
addq $0xc, %r14
cmpb $0x0, 0x3a4(%r12)
je 0x46bd
testb %bpl, %bpl
je 0x4681
movq 0x8982(%rip), %r15      # 0xcfb8
leaq 0x52a5(%rip), %rsi      # 0x98e2
movl $0x1b, %edx
movq %r15, %rdi
callq 0x21f0
leaq 0x3ac(%r12), %rsi
movq %r15, %rdi
callq 0x3dbb
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 $0x8002080, (%r14)      # imm = 0x8002080
movb 0x3a8(%r12), %al
movb %al, 0x4(%r14)
movb $0x1, 0x5(%r14)
movzwl 0x3ac(%r12), %eax
rolw $0x8, %ax
movw %ax, 0x6(%r14)
movl 0x3b0(%r12), %eax
bswapl %eax
movl %eax, 0x8(%r14)
addq $0xc, %r14
cmpb $0x0, 0x3b4(%r12)
je 0x4719
testb %bpl, %bpl
je 0x470f
movq 0x88e4(%rip), %r15      # 0xcfb8
leaq 0x5223(%rip), %rsi      # 0x98fe
movl $0x12, %edx
movq %r15, %rdi
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
movw $0x2100, (%r14)         # imm = 0x2100
addq $0x2, %r14
cmpb $0x0, 0x3b5(%r12)
je 0x47a2
testb %bpl, %bpl
je 0x478a
movq 0x8888(%rip), %r13      # 0xcfb8
leaq 0x51da(%rip), %rsi      # 0x9911
movl $0x15, %edx
movq %r13, %rdi
callq 0x21f0
leaq 0x3b6(%r12), %r15
movq %r15, %rdi
callq 0x20c0
movq %r13, %rdi
movq %r15, %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(%r12), %rdx
movq %r14, %rdi
movl $0x8022, %esi           # imm = 0x8022
callq 0x4abc
movq %rax, %r14
cmpb $0x0, 0x4b8(%r12)
je 0x4844
testb %bpl, %bpl
je 0x4808
movq 0x87fb(%rip), %r15      # 0xcfb8
leaq 0x5163(%rip), %rsi      # 0x9927
movl $0x1b, %edx
movq %r15, %rdi
callq 0x21f0
leaq 0x4c0(%r12), %rsi
movq %r15, %rdi
callq 0x3dbb
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 $0x8005080, (%r14)      # imm = 0x8005080
movb 0x4bc(%r12), %al
movb %al, 0x4(%r14)
movb $0x1, 0x5(%r14)
movzwl 0x4c0(%r12), %eax
rolw $0x8, %ax
movw %ax, 0x6(%r14)
movl 0x4c4(%r12), %eax
bswapl %eax
movl %eax, 0x8(%r14)
addq $0xc, %r14
movq (%rsp), %rax
cmpw $0x0, 0x100(%rax)
je 0x48d7
testb %bpl, %bpl
je 0x48b8
movq 0x8756(%rip), %r12      # 0xcfb8
leaq 0x50da(%rip), %rsi      # 0x9943
movl $0x14, %edx
movq %r12, %rdi
callq 0x21f0
movq (%rsp), %r15
movq %r15, %rdi
callq 0x20c0
movq %r12, %rdi
movq %r15, %rsi
movq %rax, %rdx
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
movl $0x14000800, (%r14)     # imm = 0x14000800
movaps 0x5aaa(%rip), %xmm0     # 0xa370
movups %xmm0, 0x4(%r14)
movl $0x6465746e, 0x14(%r14) # imm = 0x6465746E
addq $0x18, %r14
testb %bpl, %bpl
je 0x490a
movq 0x86d5(%rip), %r15      # 0xcfb8
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
subl %ebx, %r14d
leal -0x14(%r14), %eax
rolw $0x8, %ax
movw %ax, 0x2(%rbx)
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x34(%r12)
jne 0x4153
cmpb $0x0, 0x3c(%r12)
jne 0x41ca
cmpb $0x0, 0x4c(%r12)
jne 0x425e
cmpb $0x0, 0x5c(%r12)
jne 0x42fc
cmpb $0x0, 0x160(%r12)
jne 0x4382
cmpb $0x0, 0x279(%r12)
jne 0x4463
cmpb $0x0, 0x380(%r12)
jne 0x4522
cmpb $0x0, 0x394(%r12)
jne 0x45df
cmpb $0x0, 0x3a4(%r12)
jne 0x4681
cmpb $0x0, 0x3b4(%r12)
jne 0x470f
cmpb $0x0, 0x3b5(%r12)
jne 0x478a
cmpb $0x0, 0x4b8(%r12)
jne 0x4808
movq (%rsp), %rax
cmpw $0x0, 0x100(%rax)
jne 0x48b8
jmp 0x490a
cmpb $0x0, 0x3c(%r12)
jne 0x417a
cmpb $0x0, 0x4c(%r12)
jne 0x420e
cmpb $0x0, 0x5c(%r12)
jne 0x429e
cmpb $0x0, 0x160(%r12)
jne 0x4321
cmpb $0x0, 0x279(%r12)
jne 0x43b2
cmpb $0x0, 0x380(%r12)
jne 0x44e0
cmpb $0x0, 0x394(%r12)
jne 0x458d
cmpb $0x0, 0x3a4(%r12)
jne 0x462f
cmpb $0x0, 0x3b4(%r12)
jne 0x46cd
cmpb $0x0, 0x3b5(%r12)
jne 0x4729
cmpb $0x0, 0x4b8(%r12)
jne 0x47b6
movq (%rsp), %rax
cmpw $0x0, 0x100(%rax)
jne 0x485b
jmp 0x48dc
leaq 0x4c8c(%rip), %rdi      # 0x9730
leaq 0x4ca2(%rip), %rsi      # 0x974d
leaq 0x4ca4(%rip), %rcx      # 0x9756
movl $0x225, %edx            # imm = 0x225
callq 0x2120