void _digest_to_hex(const char *digest, char *hex) {
  int i;
  const char hexdigit[] = "0123456789abcdef";
  for (i = 0; i < 16; i++) {
    *hex++ = hexdigit[(digest[i] >> 4) & 0x0F];
    *hex++ = hexdigit[digest[i] & 0x0F];
  }
}


x86 assembly (clang, -O0):
<_digest_to_hex>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeed(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeea(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xee8(%rip),%al
mov    %al,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    1199 <_digest_to_hex+0x99>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
and    $0xf,%eax
cltq
mov    -0x30(%rbp,%rax,1),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xf,%eax
cltq
mov    -0x30(%rbp,%rax,1),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1132 <_digest_to_hex+0x32>
pop    %rbp
ret

x86 assembly (clang, -O2):
<_digest_to_hex>:
xor    %eax,%eax
lea    0xef7(%rip),%rcx
nopl   0x0(%rax)
movzbl (%rdi,%rax,1),%edx
shr    $0x4,%rdx
movzbl (%rdx,%rcx,1),%edx
mov    %dl,(%rsi,%rax,2)
movzbl (%rdi,%rax,1),%edx
and    $0xf,%edx
movzbl (%rdx,%rcx,1),%edx
mov    %dl,0x1(%rsi,%rax,2)
movzbl 0x1(%rdi,%rax,1),%edx
shr    $0x4,%rdx
movzbl (%rdx,%rcx,1),%edx
mov    %dl,0x2(%rsi,%rax,2)
movzbl 0x1(%rdi,%rax,1),%edx
and    $0xf,%edx
movzbl (%rdx,%rcx,1),%edx
mov    %dl,0x3(%rsi,%rax,2)
add    $0x2,%rax
cmp    $0x10,%rax
jne    1110 <_digest_to_hex+0x10>
ret

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

LLVM IR (-O2):
@__const._digest_to_hex.hexdigit = [17 x i8] c"0123456789abcdef\00"
define void @_digest_to_hex(i8* nocapture %0, i8* nocapture writeonly %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i64 [ 0, %2 ], [ %33, %3 ]
%5 = phi i8* [ %1, %2 ], [ %32, %3 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %4
%7 = load i8, i8* %6
%8 = lshr i8 %7, 4
%9 = zext i8 %8 to i64
%10 = getelementptr inbounds [17 x i8], [17 x i8]* @__const._digest_to_hex.hexdigit, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = getelementptr inbounds i8, i8* %5, i64 1
store i8 %11, i8* %5
%13 = load i8, i8* %6
%14 = and i8 %13, 15
%15 = zext i8 %14 to i64
%16 = getelementptr inbounds [17 x i8], [17 x i8]* @__const._digest_to_hex.hexdigit, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %5, i64 2
store i8 %17, i8* %12
%19 = or i64 %4, 1
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
%22 = lshr i8 %21, 4
%23 = zext i8 %22 to i64
%24 = getelementptr inbounds [17 x i8], [17 x i8]* @__const._digest_to_hex.hexdigit, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = getelementptr inbounds i8, i8* %5, i64 3
store i8 %25, i8* %18
%27 = load i8, i8* %20
%28 = and i8 %27, 15
%29 = zext i8 %28 to i64
%30 = getelementptr inbounds [17 x i8], [17 x i8]* @__const._digest_to_hex.hexdigit, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = getelementptr inbounds i8, i8* %5, i64 4
store i8 %31, i8* %26
%33 = add nuw nsw i64 %4, 2
%34 = icmp eq i64 %33, 16
br i1 %34, label %35, label %3
35: ; preds = %3
ret void
}