#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int be32toh(int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
const char *digest2hex(const char *digest) {
  int i;
  static char hexstr[41];
  uint32_t *t = (uint32_t *)digest;
  for (i = 0; i < 5; i++)
    snprintf(hexstr + 8 * i, 9, "%08x", be32toh(t[i]));
  return hexstr;
}


x86 assembly (clang, -O0):
<digest2hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jge    1191 <digest2hex+0x71>
mov    -0xc(%rbp),%eax
shl    $0x3,%eax
movslq %eax,%rcx
lea    0x2eeb(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <be32toh@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%ecx
mov    $0x9,%esi
lea    0xe82(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113b <digest2hex+0x1b>
lea    0x2ea8(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<digest2hex>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%edi
call   1040 <be32toh@plt>
lea    0x2f0a(%rip),%r14
lea    0xec3(%rip),%r15
mov    %r14,%rdi
mov    $0x9,%esi
mov    %r15,%rdx
mov    %eax,%ecx
call   1030 <snprintf@plt>
mov    0x4(%rbx),%edi
call   1040 <be32toh@plt>
lea    0x2eea(%rip),%rdi
mov    $0x9,%esi
mov    %r15,%rdx
mov    %eax,%ecx
call   1030 <snprintf@plt>
mov    0x8(%rbx),%edi
call   1040 <be32toh@plt>
lea    0x2ed4(%rip),%rdi
mov    $0x9,%esi
mov    %r15,%rdx
mov    %eax,%ecx
call   1030 <snprintf@plt>
mov    0xc(%rbx),%edi
call   1040 <be32toh@plt>
lea    0x2ebe(%rip),%rdi
mov    $0x9,%esi
mov    %r15,%rdx
mov    %eax,%ecx
call   1030 <snprintf@plt>
mov    0x10(%rbx),%edi
call   1040 <be32toh@plt>
lea    0x2ea8(%rip),%rdi
mov    $0x9,%esi
mov    %r15,%rdx
mov    %eax,%ecx
call   1030 <snprintf@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@digest2hex.hexstr = internal global [41 x i8] zeroinitializer
@.str = [5 x i8] c"%08x\00"
define i8* @digest2hex(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = bitcast i8* %5 to i32*
store i32* %6, i32** %4
store i32 0, i32* %3
br label %7
7: ; preds = %22, %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 5
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = load i32, i32* %3
%12 = mul nsw i32 8, %11
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @digest2hex.hexstr, i64 0, i64 0), i64 %13
%15 = load i32*, i32** %4
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = call i32 @be32toh(i32 %19)
%21 = call i32 @snprintf(i8* %14, i32 9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %10
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %7
25: ; preds = %7
ret i8* getelementptr inbounds ([41 x i8], [41 x i8]* @digest2hex.hexstr, i64 0, i64 0)
}

LLVM IR (-O2):
@digest2hex.hexstr = internal global [41 x i8] zeroinitializer
@.str = [5 x i8] c"%08x\00"
define i8* @digest2hex(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i32, i32* %2
%4 = tail call i32 @be32toh(i32 %3)
%5 = tail call i32 @snprintf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @digest2hex.hexstr, i64 0, i64 0), i32 9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = getelementptr inbounds i8, i8* %0, i64 4
%7 = bitcast i8* %6 to i32*
%8 = load i32, i32* %7
%9 = tail call i32 @be32toh(i32 %8)
%10 = tail call i32 @snprintf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @digest2hex.hexstr, i64 0, i64 8), i32 9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds i8, i8* %0, i64 8
%12 = bitcast i8* %11 to i32*
%13 = load i32, i32* %12
%14 = tail call i32 @be32toh(i32 %13)
%15 = tail call i32 @snprintf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @digest2hex.hexstr, i64 0, i64 16), i32 9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds i8, i8* %0, i64 12
%17 = bitcast i8* %16 to i32*
%18 = load i32, i32* %17
%19 = tail call i32 @be32toh(i32 %18)
%20 = tail call i32 @snprintf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @digest2hex.hexstr, i64 0, i64 24), i32 9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds i8, i8* %0, i64 16
%22 = bitcast i8* %21 to i32*
%23 = load i32, i32* %22
%24 = tail call i32 @be32toh(i32 %23)
%25 = tail call i32 @snprintf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @digest2hex.hexstr, i64 0, i64 32), i32 9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %24)
ret i8* getelementptr inbounds ([41 x i8], [41 x i8]* @digest2hex.hexstr, i64 0, i64 0)
}