void MD5Hex(const unsigned char digest[16], char *buffer) {
  unsigned int i;
  static const char bin2hex[] = {'0', '1', '2', '3', '4', '5', '6', '7',
                                 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
  for (i = 0; i < 16; i++) {
    *buffer = bin2hex[digest[i] >> 4];
    buffer++;
    *buffer = bin2hex[digest[i] & 0xf];
    buffer++;
  }
  *buffer = '\0';
}


x86 assembly (clang, -O0):
<MD5Hex>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jae    1185 <MD5Hex+0x85>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
movslq %eax,%rcx
lea    0xecb(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xe9e(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1113 <MD5Hex+0x13>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<MD5Hex>:
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 <MD5Hex+0x10>
movb   $0x0,(%rsi,%rax,2)
ret

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

LLVM IR (-O2):
@MD5Hex.bin2hex = internal unnamed_addr constant [16 x i8] c"0123456789abcdef"
define void @MD5Hex(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 [16 x i8], [16 x i8]* @MD5Hex.bin2hex, i64 0, i64 %9
%11 = load i8, i8* %10
store i8 %11, i8* %5
%12 = getelementptr inbounds i8, i8* %5, i64 1
%13 = load i8, i8* %6
%14 = and i8 %13, 15
%15 = zext i8 %14 to i64
%16 = getelementptr inbounds [16 x i8], [16 x i8]* @MD5Hex.bin2hex, i64 0, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %12
%18 = getelementptr inbounds i8, i8* %5, i64 2
%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 [16 x i8], [16 x i8]* @MD5Hex.bin2hex, i64 0, i64 %23
%25 = load i8, i8* %24
store i8 %25, i8* %18
%26 = getelementptr inbounds i8, i8* %5, i64 3
%27 = load i8, i8* %20
%28 = and i8 %27, 15
%29 = zext i8 %28 to i64
%30 = getelementptr inbounds [16 x i8], [16 x i8]* @MD5Hex.bin2hex, i64 0, i64 %29
%31 = load i8, i8* %30
store i8 %31, i8* %26
%32 = getelementptr inbounds i8, i8* %5, i64 4
%33 = add nuw nsw i64 %4, 2
%34 = icmp eq i64 %33, 16
br i1 %34, label %35, label %3
35: ; preds = %3
store i8 0, i8* %32
ret void
}