char *ndz_hash_dump(unsigned char *h, int hlen) {
  static char hbuf[20 * 2 + 1];
  static const char hex[] = "0123456789abcdef";
  int i;
  for (i = 0; i < hlen; i++) {
    hbuf[i * 2] = hex[h[i] >> 4];
    hbuf[i * 2 + 1] = hex[h[i] & 0xf];
  }
  hbuf[i * 2] = '\0';
  return hbuf;
}


x86 assembly (clang, -O0):
<ndz_hash_dump>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118d <ndz_hash_dump+0x8d>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
movslq %eax,%rcx
lea    0xec9(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
movslq %eax,%rcx
lea    0x2ee6(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xe9a(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
movslq %eax,%rcx
lea    0x2eb4(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1112 <ndz_hash_dump+0x12>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
movslq %eax,%rcx
lea    0x2e93(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e88(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ndz_hash_dump>:
test   %esi,%esi
jle    114d <ndz_hash_dump+0x4d>
mov    %esi,%r8d
xor    %ecx,%ecx
lea    0xef0(%rip),%r9
lea    0x2f19(%rip),%rax
nopw   0x0(%rax,%rax,1)
movzbl (%rdi,%rcx,1),%edx
shr    $0x4,%rdx
movzbl (%rdx,%r9,1),%edx
mov    %dl,(%rax,%rcx,2)
movzbl (%rdi,%rcx,1),%edx
and    $0xf,%edx
movzbl (%rdx,%r9,1),%edx
mov    %dl,0x1(%rax,%rcx,2)
add    $0x1,%rcx
cmp    %rcx,%r8
jne    1120 <ndz_hash_dump+0x20>
add    %esi,%esi
jmp    114f <ndz_hash_dump+0x4f>
xor    %esi,%esi
lea    0x2eda(%rip),%rax
movb   $0x0,(%rsi,%rax,1)
ret

LLVM IR (-O0):
@ndz_hash_dump.hbuf = internal global [41 x i8] zeroinitializer
@ndz_hash_dump.hex = internal constant [17 x i8] c"0123456789abcdef\00"
define i8* @ndz_hash_dump(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %40, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %43
10: ; preds = %6
%11 = load i8*, i8** %3
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = ashr i32 %16, 4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [17 x i8], [17 x i8]* @ndz_hash_dump.hex, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = load i32, i32* %5
%22 = mul nsw i32 %21, 2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [41 x i8], [41 x i8]* @ndz_hash_dump.hbuf, i64 0, i64 %23
store i8 %20, i8* %24
%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 = zext i8 %29 to i32
%31 = and i32 %30, 15
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [17 x i8], [17 x i8]* @ndz_hash_dump.hex, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = load i32, i32* %5
%36 = mul nsw i32 %35, 2
%37 = add nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [41 x i8], [41 x i8]* @ndz_hash_dump.hbuf, i64 0, i64 %38
store i8 %34, i8* %39
br label %40
40: ; preds = %10
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %6
43: ; preds = %6
%44 = load i32, i32* %5
%45 = mul nsw i32 %44, 2
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [41 x i8], [41 x i8]* @ndz_hash_dump.hbuf, i64 0, i64 %46
store i8 0, i8* %47
ret i8* getelementptr inbounds ([41 x i8], [41 x i8]* @ndz_hash_dump.hbuf, i64 0, i64 0)
}

LLVM IR (-O2):
@ndz_hash_dump.hbuf = internal global [41 x i8] zeroinitializer
@ndz_hash_dump.hex = internal unnamed_addr constant [17 x i8] c"0123456789abcdef\00"
define i8* @ndz_hash_dump(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %28
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %23, %6 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = lshr i8 %9, 4
%11 = zext i8 %10 to i64
%12 = getelementptr inbounds [17 x i8], [17 x i8]* @ndz_hash_dump.hex, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = shl nuw nsw i64 %7, 1
%15 = getelementptr inbounds [41 x i8], [41 x i8]* @ndz_hash_dump.hbuf, i64 0, i64 %14
store i8 %13, i8* %15
%16 = load i8, i8* %8
%17 = and i8 %16, 15
%18 = zext i8 %17 to i64
%19 = getelementptr inbounds [17 x i8], [17 x i8]* @ndz_hash_dump.hex, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = or i64 %14, 1
%22 = getelementptr inbounds [41 x i8], [41 x i8]* @ndz_hash_dump.hbuf, i64 0, i64 %21
store i8 %20, i8* %22
%23 = add nuw nsw i64 %7, 1
%24 = icmp eq i64 %23, %5
br i1 %24, label %25, label %6
25: ; preds = %6
%26 = shl i32 %1, 1
%27 = zext i32 %26 to i64
br label %28
28: ; preds = %25, %2
%29 = phi i64 [ 0, %2 ], [ %27, %25 ]
%30 = getelementptr inbounds [41 x i8], [41 x i8]* @ndz_hash_dump.hbuf, i64 0, i64 %29
store i8 0, i8* %30
ret i8* getelementptr inbounds ([41 x i8], [41 x i8]* @ndz_hash_dump.hbuf, i64 0, i64 0)
}