unsigned char *unparse_sha1(const void *shabuf) {
  const unsigned char *s = (const unsigned char *)shabuf;
  int i;
  static unsigned char buf[64];
  unsigned char *p;
  static const unsigned char hexd[] = "0123456789abcdef";
  for (i = 0, p = buf; i < 20; i++, s++) {
    *p++ = hexd[(*s >> 4) & 0xf];
    *p++ = hexd[*s & 0xf];
  }
  *p = 0;
  return buf;
}


x86 assembly (clang, -O0):
<unparse_sha1>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0x2f12(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x14,-0x14(%rbp)
jge    1199 <unparse_sha1+0x99>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
sar    $0x4,%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xebd(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xe95(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1122 <unparse_sha1+0x22>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e89(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<unparse_sha1>:
xor    %ecx,%ecx
lea    0x2f27(%rip),%rax
lea    0xef0(%rip),%r8
movzbl (%rdi),%esi
shr    $0x4,%rsi
movzbl (%rsi,%r8,1),%edx
mov    %dl,(%rcx,%rax,1)
movzbl (%rdi),%edx
and    $0xf,%edx
movzbl (%rdx,%r8,1),%edx
mov    %dl,0x1(%rcx,%rax,1)
movzbl 0x1(%rdi),%edx
shr    $0x4,%rdx
movzbl (%rdx,%r8,1),%edx
mov    %dl,0x2(%rcx,%rax,1)
movzbl 0x1(%rdi),%edx
and    $0xf,%edx
movzbl (%rdx,%r8,1),%edx
mov    %dl,0x3(%rcx,%rax,1)
add    $0x4,%rcx
add    $0x2,%rdi
cmp    $0x28,%ecx
jne    1110 <unparse_sha1+0x10>
movb   $0x0,(%rcx,%rax,1)
ret

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

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