#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 uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, int);
void digest_to_str(char strdigest[33], uint8_t digest[16]) {
  uint32_t i;
  for (i = 0; i < 16; i++) {
    snprintf(strdigest + 2 * i, 3, "%02X", digest[i]);
  }
  strdigest[32] = '\0';
}


x86 assembly (clang, -O0):
<digest_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    116a <digest_to_str+0x5a>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    $0x3,%esi
lea    0xea9(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1127 <digest_to_str+0x17>
mov    -0x8(%rbp),%rax
movb   $0x0,0x20(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<digest_to_str>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rsi),%ecx
lea    0xedc(%rip),%r15
mov    $0x3,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
lea    0x2(%rbx),%rdi
mov    0x4(%r14),%ecx
mov    $0x3,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
lea    0x4(%rbx),%rdi
mov    0x8(%r14),%ecx
mov    $0x3,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
lea    0x6(%rbx),%rdi
mov    0xc(%r14),%ecx
mov    $0x3,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
lea    0x8(%rbx),%rdi
mov    0x10(%r14),%ecx
mov    $0x3,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
lea    0xa(%rbx),%rdi
mov    0x14(%r14),%ecx
mov    $0x3,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
lea    0xc(%rbx),%rdi
mov    0x18(%r14),%ecx
mov    $0x3,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
lea    0xe(%rbx),%rdi
mov    0x1c(%r14),%ecx
mov    $0x3,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
lea    0x10(%rbx),%rdi
mov    0x20(%r14),%ecx
mov    $0x3,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
lea    0x12(%rbx),%rdi
mov    0x24(%r14),%ecx
mov    $0x3,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
lea    0x14(%rbx),%rdi
mov    0x28(%r14),%ecx
mov    $0x3,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
lea    0x16(%rbx),%rdi
mov    0x2c(%r14),%ecx
mov    $0x3,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
lea    0x18(%rbx),%rdi
mov    0x30(%r14),%ecx
mov    $0x3,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
lea    0x1a(%rbx),%rdi
mov    0x34(%r14),%ecx
mov    $0x3,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
lea    0x1c(%rbx),%rdi
mov    0x38(%r14),%ecx
mov    $0x3,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
lea    0x1e(%rbx),%rdi
mov    0x3c(%r14),%ecx
mov    $0x3,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
movb   $0x0,0x20(%rbx)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02X\00"
define void @digest_to_str(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 = %21, %2
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 16
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = load i8*, i8** %3
%11 = load i32, i32* %5
%12 = mul nsw i32 2, %11
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = load i32*, i32** %4
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = call i32 @snprintf(i8* %14, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %9
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %6
24: ; preds = %6
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 32
store i8 0, i8* %26
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02X\00"
define void @digest_to_str(i8* %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = tail call i32 @snprintf(i8* %0, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = getelementptr inbounds i8, i8* %0, i64 2
%6 = getelementptr inbounds i32, i32* %1, i64 1
%7 = load i32, i32* %6
%8 = tail call i32 @snprintf(i8* %5, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds i8, i8* %0, i64 4
%10 = getelementptr inbounds i32, i32* %1, i64 2
%11 = load i32, i32* %10
%12 = tail call i32 @snprintf(i8* %9, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds i8, i8* %0, i64 6
%14 = getelementptr inbounds i32, i32* %1, i64 3
%15 = load i32, i32* %14
%16 = tail call i32 @snprintf(i8* %13, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds i8, i8* %0, i64 8
%18 = getelementptr inbounds i32, i32* %1, i64 4
%19 = load i32, i32* %18
%20 = tail call i32 @snprintf(i8* %17, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds i8, i8* %0, i64 10
%22 = getelementptr inbounds i32, i32* %1, i64 5
%23 = load i32, i32* %22
%24 = tail call i32 @snprintf(i8* %21, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds i8, i8* %0, i64 12
%26 = getelementptr inbounds i32, i32* %1, i64 6
%27 = load i32, i32* %26
%28 = tail call i32 @snprintf(i8* %25, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds i8, i8* %0, i64 14
%30 = getelementptr inbounds i32, i32* %1, i64 7
%31 = load i32, i32* %30
%32 = tail call i32 @snprintf(i8* %29, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds i8, i8* %0, i64 16
%34 = getelementptr inbounds i32, i32* %1, i64 8
%35 = load i32, i32* %34
%36 = tail call i32 @snprintf(i8* %33, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds i8, i8* %0, i64 18
%38 = getelementptr inbounds i32, i32* %1, i64 9
%39 = load i32, i32* %38
%40 = tail call i32 @snprintf(i8* %37, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %39)
%41 = getelementptr inbounds i8, i8* %0, i64 20
%42 = getelementptr inbounds i32, i32* %1, i64 10
%43 = load i32, i32* %42
%44 = tail call i32 @snprintf(i8* %41, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = getelementptr inbounds i8, i8* %0, i64 22
%46 = getelementptr inbounds i32, i32* %1, i64 11
%47 = load i32, i32* %46
%48 = tail call i32 @snprintf(i8* %45, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %47)
%49 = getelementptr inbounds i8, i8* %0, i64 24
%50 = getelementptr inbounds i32, i32* %1, i64 12
%51 = load i32, i32* %50
%52 = tail call i32 @snprintf(i8* %49, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %51)
%53 = getelementptr inbounds i8, i8* %0, i64 26
%54 = getelementptr inbounds i32, i32* %1, i64 13
%55 = load i32, i32* %54
%56 = tail call i32 @snprintf(i8* %53, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %55)
%57 = getelementptr inbounds i8, i8* %0, i64 28
%58 = getelementptr inbounds i32, i32* %1, i64 14
%59 = load i32, i32* %58
%60 = tail call i32 @snprintf(i8* %57, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %59)
%61 = getelementptr inbounds i8, i8* %0, i64 30
%62 = getelementptr inbounds i32, i32* %1, i64 15
%63 = load i32, i32* %62
%64 = tail call i32 @snprintf(i8* %61, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %63)
%65 = getelementptr inbounds i8, i8* %0, i64 32
store i8 0, i8* %65
ret void
}