// File: /workspace/github_cpp_makefile_star2_O2/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
cmpl $0x13, %edx
jbe 0x3fbc
movl %r8d, %ebp
movq %rcx, %r14
movq %rsi, %rbx
movq %rdi, %r12
movzwl (%rdi), %eax
rolw $0x8, %ax
movw %ax, (%rsi)
andw $0x0, 0x2(%rsi)
movups 0x4(%rdi), %xmm0
movups %xmm0, 0x4(%rsi)
leaq 0x14(%rsi), %r15
testb %bpl, %bpl
je 0x38d9
movq 0x7728(%rip), %rdi      # 0xafb8
leaq 0x3f26(%rip), %rsi      # 0x77bd
callq 0x21d0
movq %rax, %rdi
callq 0x20c0
cmpb $0x0, 0x14(%r12)
je 0x3903
movq 0x7705(%rip), %rdi      # 0xafb8
leaq 0x3f1b(%rip), %rsi      # 0x77d5
callq 0x21d0
movq %rax, %r13
leaq 0x1c(%r12), %rsi
movq %rax, %rdi
callq 0x3732
movq %r13, %rdi
callq 0x20c0
jmp 0x38e1
cmpb $0x0, 0x14(%r12)
je 0x3938
leaq 0x18(%r12), %rdx
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0x3fdb
movq %rax, %r15
cmpb $0x0, 0x24(%r12)
je 0x3957
testb %bpl, %bpl
jne 0x390b
jmp 0x3944
cmpb $0x0, 0x24(%r12)
je 0x3966
movq 0x76a6(%rip), %rdi      # 0xafb8
leaq 0x3ed5(%rip), %rsi      # 0x77ee
callq 0x21d0
movq %rax, %r13
leaq 0x2c(%r12), %rsi
movq %rax, %rdi
callq 0x3732
movq %r13, %rdi
callq 0x20c0
jmp 0x3944
cmpb $0x0, 0x24(%r12)
je 0x3e50
leaq 0x28(%r12), %rdx
pushq $0x2
popq %rsi
movq %r15, %rdi
callq 0x3fdb
movq %rax, %r15
cmpb $0x0, 0x34(%r12)
je 0x39b0
testb %bpl, %bpl
jne 0x3972
jmp 0x399a
cmpb $0x0, 0x34(%r12)
je 0x3f0c
movq 0x763f(%rip), %rdi      # 0xafb8
leaq 0x3e89(%rip), %rsi      # 0x7809
callq 0x21d0
movl 0x38(%r12), %esi
movq %rax, %rdi
callq 0x2130
movq %rax, %rdi
callq 0x20c0
movl $0x4000300, (%r15)      # imm = 0x4000300
movl 0x38(%r12), %eax
bswapl %eax
movl %eax, 0x4(%r15)
addq $0x8, %r15
cmpb $0x0, 0x3c(%r12)
je 0x39fb
testb %bpl, %bpl
je 0x39e8
movq 0x75f4(%rip), %rdi      # 0xafb8
leaq 0x3e57(%rip), %rsi      # 0x7822
callq 0x21d0
movq %rax, %r13
leaq 0x44(%r12), %rsi
movq %rax, %rdi
callq 0x3732
movq %r13, %rdi
callq 0x20c0
leaq 0x40(%r12), %rdx
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0x3fdb
movq %rax, %r15
cmpb $0x0, 0x4c(%r12)
je 0x3a46
testb %bpl, %bpl
je 0x3a33
movq 0x75a9(%rip), %rdi      # 0xafb8
leaq 0x3e25(%rip), %rsi      # 0x783b
callq 0x21d0
movq %rax, %r13
leaq 0x54(%r12), %rsi
movq %rax, %rdi
callq 0x3732
movq %r13, %rdi
callq 0x20c0
leaq 0x50(%r12), %rdx
pushq $0x5
popq %rsi
movq %r15, %rdi
callq 0x3fdb
movq %rax, %r15
cmpb $0x0, 0x5c(%r12)
je 0x3a8e
testb %bpl, %bpl
je 0x3a7b
movq 0x755e(%rip), %rdi      # 0xafb8
leaq 0x3df4(%rip), %rsi      # 0x7855
callq 0x21d0
leaq 0x5e(%r12), %rsi
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20c0
leaq 0x5e(%r12), %rdx
pushq $0x6
popq %rsi
movq %r15, %rdi
callq 0x400a
movq %rax, %r15
cmpb $0x0, 0x160(%r12)
je 0x3adf
testb %bpl, %bpl
je 0x3ac9
movq 0x7513(%rip), %rdi      # 0xafb8
leaq 0x3dbd(%rip), %rsi      # 0x7869
callq 0x21d0
leaq 0x162(%r12), %rsi
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20c0
leaq 0x162(%r12), %rdx
pushq $0x7
popq %rsi
movq %r15, %rdi
callq 0x400a
movq %rax, %r15
cmpb $0x0, 0x279(%r12)
je 0x3bc7
testb %bpl, %bpl
je 0x3b5e
movq 0x74be(%rip), %rdi      # 0xafb8
leaq 0x3d7c(%rip), %rsi      # 0x787d
callq 0x21d0
movzbl 0x27c(%r12), %esi
movq %rax, %rdi
callq 0x22a0
leaq 0x3d7a(%rip), %rsi      # 0x7898
movq %rax, %rdi
callq 0x21d0
movzbl 0x27d(%r12), %esi
movq %rax, %rdi
callq 0x22a0
leaq 0x3d63(%rip), %rsi      # 0x78a1
movq %rax, %rdi
callq 0x21d0
leaq 0x27e(%r12), %rsi
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20c0
movw $0x900, (%r15)          # imm = 0x900
movzwl 0x37e(%r12), %eax
addl $0x6, %eax
rolw $0x8, %ax
movw %ax, 0x2(%r15)
movzwl 0x27a(%r12), %eax
rolw $0x8, %ax
movw %ax, 0x4(%r15)
movb 0x27c(%r12), %al
movb %al, 0x6(%r15)
movb 0x27d(%r12), %al
leaq 0x8(%r15), %rdi
movb %al, 0x7(%r15)
leaq 0x27e(%r12), %rsi
movzwl 0x37e(%r12), %r13d
movq %r13, %rdx
callq 0x2170
addq %r13, %r15
addq $0x8, %r15
cmpb $0x0, 0x380(%r12)
je 0x3c3f
testb %bpl, %bpl
je 0x3bf2
movq 0x73da(%rip), %rdi      # 0xafb8
leaq 0x3cc5(%rip), %rsi      # 0x78aa
callq 0x21d0
movq %rax, %rdi
callq 0x20c0
movw $0xa00, (%r15)          # imm = 0xA00
movzwl 0x392(%r12), %eax
leal 0x2(,%rax,2), %eax
rolw $0x8, %ax
movw %ax, 0x2(%r15)
addq $0x4, %r15
xorl %eax, %eax
movzwl 0x392(%r12), %ecx
cmpq %rcx, %rax
jae 0x3c3f
movzwl 0x382(%r12,%rax,2), %ecx
rolw $0x8, %cx
movw %cx, (%r15)
addq $0x2, %r15
incq %rax
jmp 0x3c17
cmpb $0x0, 0x394(%r12)
je 0x3c93
testb %bpl, %bpl
je 0x3c7d
movq 0x7362(%rip), %rdi      # 0xafb8
leaq 0x3c6c(%rip), %rsi      # 0x78c9
callq 0x21d0
movq %rax, %r13
leaq 0x39c(%r12), %rsi
movq %rax, %rdi
callq 0x3732
movq %r13, %rdi
callq 0x20c0
leaq 0x398(%r12), %rdx
pushq $0xb
popq %rsi
movq %r15, %rdi
callq 0x3fdb
movq %rax, %r15
cmpb $0x0, 0x3a4(%r12)
je 0x3ce9
testb %bpl, %bpl
je 0x3cd1
movq 0x730e(%rip), %rdi      # 0xafb8
leaq 0x3c31(%rip), %rsi      # 0x78e2
callq 0x21d0
movq %rax, %r13
leaq 0x3ac(%r12), %rsi
movq %rax, %rdi
callq 0x3732
movq %r13, %rdi
callq 0x20c0
leaq 0x3a8(%r12), %rdx
movq %r15, %rdi
movl $0x8020, %esi           # imm = 0x8020
callq 0x3fdb
movq %rax, %r15
cmpb $0x0, 0x3b4(%r12)
je 0x3d1e
testb %bpl, %bpl
je 0x3d14
movq 0x72b8(%rip), %rdi      # 0xafb8
leaq 0x3bf7(%rip), %rsi      # 0x78fe
callq 0x21d0
movq %rax, %rdi
callq 0x20c0
movw $0x2100, (%r15)         # imm = 0x2100
addq $0x2, %r15
cmpb $0x0, 0x3b5(%r12)
je 0x3d71
testb %bpl, %bpl
je 0x3d59
movq 0x7283(%rip), %rdi      # 0xafb8
leaq 0x3bd5(%rip), %rsi      # 0x7911
callq 0x21d0
leaq 0x3b6(%r12), %rsi
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20c0
leaq 0x3b6(%r12), %rdx
movq %r15, %rdi
movl $0x8022, %esi           # imm = 0x8022
callq 0x400a
movq %rax, %r15
cmpb $0x0, 0x4b8(%r12)
je 0x3dc9
testb %bpl, %bpl
je 0x3daf
movq 0x7230(%rip), %rdi      # 0xafb8
leaq 0x3b98(%rip), %rsi      # 0x7927
callq 0x21d0
movq %rax, %r13
leaq 0x4c0(%r12), %rsi
movq %rax, %rdi
callq 0x3732
movq %r13, %rdi
callq 0x20c0
addq $0x4bc, %r12            # imm = 0x4BC
movq %r15, %rdi
movl $0x8050, %esi           # imm = 0x8050
movq %r12, %rdx
callq 0x3fdb
movq %rax, %r15
cmpw $0x0, 0x100(%r14)
je 0x3e1e
testb %bpl, %bpl
je 0x3dff
movq 0x71d8(%rip), %rdi      # 0xafb8
leaq 0x3b5c(%rip), %rsi      # 0x7943
callq 0x21d0
movq %rax, %rdi
movq %r14, %rsi
callq 0x21d0
movq %rax, %rdi
callq 0x20c0
movl $0x14000800, (%r15)     # imm = 0x14000800
movaps 0x4563(%rip), %xmm0     # 0x8370
movups %xmm0, 0x4(%r15)
movl $0x6465746e, 0x14(%r15) # imm = 0x6465746E
addq $0x18, %r15
testb %bpl, %bpl
je 0x3e2f
movq 0x718e(%rip), %rdi      # 0xafb8
callq 0x20c0
subl %ebx, %r15d
leal -0x14(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x2(%rbx)
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x34(%r12)
jne 0x399a
cmpb $0x0, 0x3c(%r12)
jne 0x39e8
cmpb $0x0, 0x4c(%r12)
jne 0x3a33
cmpb $0x0, 0x5c(%r12)
jne 0x3a7b
cmpb $0x0, 0x160(%r12)
jne 0x3ac9
cmpb $0x0, 0x279(%r12)
jne 0x3b5e
cmpb $0x0, 0x380(%r12)
jne 0x3bf2
cmpb $0x0, 0x394(%r12)
jne 0x3c7d
cmpb $0x0, 0x3a4(%r12)
jne 0x3cd1
cmpb $0x0, 0x3b4(%r12)
jne 0x3d14
cmpb $0x0, 0x3b5(%r12)
jne 0x3d59
cmpb $0x0, 0x4b8(%r12)
jne 0x3daf
cmpw $0x0, 0x100(%r14)
jne 0x3dff
jmp 0x3e2f
cmpb $0x0, 0x3c(%r12)
jne 0x39bd
cmpb $0x0, 0x4c(%r12)
jne 0x3a08
cmpb $0x0, 0x5c(%r12)
jne 0x3a53
cmpb $0x0, 0x160(%r12)
jne 0x3a9e
cmpb $0x0, 0x279(%r12)
jne 0x3af3
cmpb $0x0, 0x380(%r12)
jne 0x3bd7
cmpb $0x0, 0x394(%r12)
jne 0x3c4f
cmpb $0x0, 0x3a4(%r12)
jne 0x3ca3
cmpb $0x0, 0x3b4(%r12)
jne 0x3cf9
cmpb $0x0, 0x3b5(%r12)
jne 0x3d2e
cmpb $0x0, 0x4b8(%r12)
jne 0x3d81
cmpw $0x0, 0x100(%r14)
jne 0x3dd9
jmp 0x3e23
leaq 0x376d(%rip), %rdi      # 0x7730
leaq 0x3783(%rip), %rsi      # 0x774d
leaq 0x3785(%rip), %rcx      # 0x7756
movl $0x225, %edx            # imm = 0x225
callq 0x2120