#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*/ res;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char const);
int /*<<< orphan*/ stderr;
void crypto_digest_print(const unsigned char *buf, size_t len) {
  unsigned int i = 0;
  char res[128];
  if (len > sizeof(res) - 1) {
    return;
  }
  for (i = 0; i < len; i++) {
    sprintf(&res[i * 2], "%02x", buf[i]);
  }
  res[i * 2] = 0x00;
  fprintf(stderr, "%s\n", res);
}


x86 assembly (clang, -O0):
<crypto_digest_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x7f,-0x10(%rbp)
jbe    114a <crypto_digest_print+0x2a>
jmp    11c1 <crypto_digest_print+0xa1>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%rax
jae    1195 <crypto_digest_print+0x75>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,%eax
lea    -0xa0(%rbp),%rdi
add    %rax,%rdi
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
lea    0xe82(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1040 <sprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1151 <crypto_digest_print+0x31>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,%eax
movb   $0x0,-0xa0(%rbp,%rax,1)
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    -0xa0(%rbp),%rdx
lea    0xe49(%rip),%rsi
call   1030 <fprintf@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_digest_print>:
cmp    $0x7f,%rsi
ja     119c <crypto_digest_print+0x7c>
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%r12
test   %rsi,%rsi
je     1170 <crypto_digest_print+0x50>
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0xeb8(%rip),%r15
nopl   0x0(%rax,%rax,1)
lea    (%rbx,%rbx,1),%eax
lea    (%rsp,%rax,1),%rdi
movzbl (%r14,%rbx,1),%edx
mov    %r15,%rsi
call   1040 <sprintf@plt>
add    $0x1,%ebx
cmp    %r12,%rbx
jb     1150 <crypto_digest_print+0x30>
add    %ebx,%ebx
jmp    1172 <crypto_digest_print+0x52>
xor    %ebx,%ebx
movb   $0x0,(%rsp,%rbx,1)
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
mov    %rsp,%rdx
call   1030 <fprintf@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define void @crypto_digest_print(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca [128 x i8]
store i8* %0, i8** %3
store i64 %1, i64* %4
store i32 0, i32* %5
%7 = load i64, i64* %4
%8 = icmp ugt i64 %7, 127
br i1 %8, label %9, label %10
9: ; preds = %2
br label %38
10: ; preds = %2
store i32 0, i32* %5
br label %11
11: ; preds = %27, %10
%12 = load i32, i32* %5
%13 = zext i32 %12 to i64
%14 = load i64, i64* %4
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %30
16: ; preds = %11
%17 = load i32, i32* %5
%18 = mul i32 %17, 2
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 %19
%21 = load i8*, i8** %3
%22 = load i32, i32* %5
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %25)
br label %27
27: ; preds = %16
%28 = load i32, i32* %5
%29 = add i32 %28, 1
store i32 %29, i32* %5
br label %11
30: ; preds = %11
%31 = load i32, i32* %5
%32 = mul i32 %31, 2
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 %33
store i8 0, i8* %34
%35 = load i32, i32* @stderr
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %30, %9
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define void @crypto_digest_print(i8* nocapture %0, i64 %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = icmp ugt i64 %1, 127
br i1 %5, label %28, label %6
6: ; preds = %2
%7 = icmp eq i64 %1, 0
br i1 %7, label %23, label %8
8: ; preds = %6, %8
%9 = phi i64 [ %18, %8 ], [ 0, %6 ]
%10 = trunc i64 %9 to i32
%11 = shl nuw nsw i64 %9, 1
%12 = and i64 %11, 4294967294
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %12
%14 = getelementptr inbounds i8, i8* %0, i64 %9
%15 = load i8, i8* %14
%16 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %15)
%17 = add i32 %10, 1
%18 = zext i32 %17 to i64
%19 = icmp ult i64 %18, %1
br i1 %19, label %8, label %20
20: ; preds = %8
%21 = shl i32 %17, 1
%22 = zext i32 %21 to i64
br label %23
23: ; preds = %20, %6
%24 = phi i64 [ 0, %6 ], [ %22, %20 ]
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %24
store i8 0, i8* %25
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %28
28: ; preds = %2, %23
ret void
}