unsigned long hmac_hex(const unsigned char *key, const unsigned int keylen,
                       const unsigned char *salt, const unsigned int saltlen,
                       unsigned char *ascii) {
  unsigned char hash[32] = {0x00};
  int i = 0;
  unsigned long ret = hmac(key, keylen, salt, saltlen, hash);
  for (i = 0; i < 32; i++) {
    sprintf(((char *)ascii) + i * 2, "%02x", (unsigned char *)(hash[i]));
  }
  return ret;
}


x86 assembly (clang, -O0):
<hmac_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    -0x50(%rbp),%r8
mov    $0x0,%al
call   1040 <hmac@plt>
cltq
mov    %rax,-0x60(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x20,-0x54(%rbp)
jge    11c7 <hmac_hex+0x97>
mov    -0x28(%rbp),%rdi
mov    -0x54(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
movslq -0x54(%rbp),%rax
movzbl -0x50(%rbp,%rax,1),%eax
mov    %eax,%edx
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1187 <hmac_hex+0x57>
mov    -0x60(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hmac_hex>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %r8,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%r8
xor    %eax,%eax
call   1030 <hmac@plt>
mov    %eax,%r14d
lea    0xeb3(%rip),%r15
xor    %ebp,%ebp
nop
movzbl (%rsp,%rbp,1),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <sprintf@plt>
add    $0x1,%rbp
add    $0x2,%rbx
cmp    $0x20,%rbp
jne    1150 <hmac_hex+0x30>
movslq %r14d,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
define i64 @hmac_hex(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [32 x i8]
%12 = alloca i32
%13 = alloca i64
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%14 = bitcast [32 x i8]* %11 to i8*
store i32 0, i32* %12
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = load i8*, i8** %8
%18 = load i32, i32* %9
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%20 = call i32 (i8*, i32, i8*, i32, i8*, ...) bitcast (i32 (...)* @hmac to i32 (i8*, i32, i8*, i32, i8*, ...)*)(i8* %15, i32 %16, i8* %17, i32 %18, i8* %19)
%21 = sext i32 %20 to i64
store i64 %21, i64* %13
store i32 0, i32* %12
br label %22
22: ; preds = %38, %5
%23 = load i32, i32* %12
%24 = icmp slt i32 %23, 32
br i1 %24, label %25, label %41
25: ; preds = %22
%26 = load i8*, i8** %10
%27 = load i32, i32* %12
%28 = mul nsw i32 %27, 2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
%31 = load i32, i32* %12
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = zext i8 %34 to i64
%36 = inttoptr i64 %35 to i8*
%37 = call i32 (i8*, i8*, ...) @sprintf(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %25
%39 = load i32, i32* %12
%40 = add nsw i32 %39, 1
store i32 %40, i32* %12
br label %22
41: ; preds = %22
%42 = load i64, i64* %13
ret i64 %42
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
define i64 @hmac_hex(i8* %0, i32 %1, i8* %2, i32 %3, i8* nocapture writeonly %4) {
%6 = alloca [32 x i8]
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%8 = call i32 (i8*, i32, i8*, i32, i8*, ...) bitcast (i32 (...)* @hmac to i32 (i8*, i32, i8*, i32, i8*, ...)*)(i8* %0, i32 %1, i8* %2, i32 %3, i8* %7)
br label %9
9: ; preds = %5, %9
%10 = phi i64 [ 0, %5 ], [ %18, %9 ]
%11 = shl nuw nsw i64 %10, 1
%12 = getelementptr inbounds i8, i8* %4, i64 %11
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 %10
%14 = load i8, i8* %13
%15 = zext i8 %14 to i64
%16 = inttoptr i64 %15 to i8*
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = add nuw nsw i64 %10, 1
%19 = icmp eq i64 %18, 32
br i1 %19, label %20, label %9
20: ; preds = %9
%21 = sext i32 %8 to i64
ret i64 %21
}