// File: Distrotech[P]stund/stun.cxx
// Function: stunCreateUserName(StunAddress4 const&, StunAtrString*)
void
stunCreateUserName(const StunAddress4& source, StunAtrString* username)
{
   UInt64 time = stunGetSystemTimeSecs();
   time -= (time % 20*60);
   //UInt64 hitime = time >> 32;
   UInt64 lotime = time & 0xFFFFFFFF;
	
   char buffer[1024];
   sprintf(buffer,
           "%08x:%08x:%08x:", 
           UInt32(source.addr),
           UInt32(stunRand()),
           UInt32(lotime));
   assert( strlen(buffer) < 1024 );
	
   assert(strlen(buffer) + 41 < STUN_MAX_STRING);
	
   char hmac[20];
   char key[] = "Jason";
   computeHmac(hmac, buffer, strlen(buffer), key, strlen(key) );
   char hmacHex[41];
   toHex(hmac, 20, hmacHex );
   hmacHex[40] =0;
	
   strcat(buffer,hmacHex);
	
   int l = strlen(buffer);
   assert( l+1 < STUN_MAX_STRING );
   assert( l%4 == 0 );
   
   username->sizeValue = l;
   memcpy(username->value,buffer,l);
   username->value[l]=0;
	
   //if (verbose) clog << "computed username=" << username.value << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4a0, %rsp            # imm = 0x4A0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x5300
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl $0x14, %ecx
xorl %edx, %edx
divq %rcx
imulq $0x3c, %rdx, %rcx
movq -0x18(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x18(%rbp)
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq -0x420(%rbp), %rax
movq %rax, -0x480(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x478(%rbp)
callq 0x4ff0
movq -0x480(%rbp), %rdi
movl -0x478(%rbp), %edx
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %eax, %r8d
leaq 0x5854(%rip), %rsi      # 0xa96c
movb $0x0, %al
callq 0x2070
leaq -0x420(%rbp), %rdi
callq 0x20e0
cmpq $0x400, %rax            # imm = 0x400
jae 0x5135
jmp 0x5154
leaq 0x5840(%rip), %rdi      # 0xa97c
leaq 0x5612(%rip), %rsi      # 0xa755
movl $0x308, %edx            # imm = 0x308
leaq 0x5843(%rip), %rcx      # 0xa992
callq 0x2140
leaq -0x420(%rbp), %rdi
callq 0x20e0
addq $0x29, %rax
cmpq $0x100, %rax            # imm = 0x100
jae 0x516e
jmp 0x518d
leaq 0x585c(%rip), %rdi      # 0xa9d1
leaq 0x55d9(%rip), %rsi      # 0xa755
movl $0x30a, %edx            # imm = 0x30A
leaq 0x580a(%rip), %rcx      # 0xa992
callq 0x2140
movl 0x5864(%rip), %eax      # 0xa9f7
movl %eax, -0x446(%rbp)
movw 0x585b(%rip), %ax       # 0xa9fb
movw %ax, -0x442(%rbp)
leaq -0x440(%rbp), %rax
movq %rax, -0x4a0(%rbp)
leaq -0x420(%rbp), %rax
movq %rax, -0x498(%rbp)
leaq -0x420(%rbp), %rdi
callq 0x20e0
movl %eax, -0x48c(%rbp)
leaq -0x446(%rbp), %rax
movq %rax, -0x488(%rbp)
leaq -0x446(%rbp), %rdi
callq 0x20e0
movq -0x4a0(%rbp), %rdi
movq -0x498(%rbp), %rsi
movl -0x48c(%rbp), %edx
movq -0x488(%rbp), %rcx
movl %eax, %r8d
callq 0x4f50
leaq -0x440(%rbp), %rdi
leaq -0x470(%rbp), %rdx
movl $0x14, %esi
callq 0x5330
movb $0x0, -0x448(%rbp)
leaq -0x420(%rbp), %rdi
leaq -0x470(%rbp), %rsi
callq 0x2310
leaq -0x420(%rbp), %rdi
callq 0x20e0
movl %eax, -0x474(%rbp)
movl -0x474(%rbp), %eax
addl $0x1, %eax
cmpl $0x100, %eax            # imm = 0x100
jge 0x5268
jmp 0x5287
leaq 0x578e(%rip), %rdi      # 0xa9fd
leaq 0x54df(%rip), %rsi      # 0xa755
movl $0x316, %edx            # imm = 0x316
leaq 0x5710(%rip), %rcx      # 0xa992
callq 0x2140
movl -0x474(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x529c
jmp 0x52bb
leaq 0x5770(%rip), %rdi      # 0xaa13
leaq 0x54ab(%rip), %rsi      # 0xa755
movl $0x317, %edx            # imm = 0x317
leaq 0x56dc(%rip), %rcx      # 0xa992
callq 0x2140
movl -0x474(%rbp), %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x100(%rax)
movq -0x10(%rbp), %rdi
leaq -0x420(%rbp), %rsi
movslq -0x474(%rbp), %rdx
callq 0x2190
movq -0x10(%rbp), %rax
movslq -0x474(%rbp), %rcx
movb $0x0, (%rax,%rcx)
addq $0x4a0, %rsp            # imm = 0x4A0
popq %rbp
retq
nop