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

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned char);
char *bin2hex(unsigned char *d) {
  static char ret[20 * 2 + 1];
  int i;
  for (i = 0; i < 20 * 2; i += 2, d++)
    snprintf(ret + i, 20 * 2 + 1 - i, "%02X", *d);
  return ret;
}


x86 assembly (clang, -O0):
<bin2hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x28,-0xc(%rbp)
jge    1170 <bin2hex+0x60>
movslq -0xc(%rbp),%rax
lea    0x2f08(%rip),%rdi
add    %rax,%rdi
mov    $0x29,%esi
sub    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rax
lea    0xeb2(%rip),%rdx
movzbl (%rax),%ecx
call   1030 <snprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1123 <bin2hex+0x13>
lea    0x2ec9(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin2hex>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
mov    $0x29,%ebp
mov    $0xfffffffffffffffe,%rbx
lea    0x2f12(%rip),%r12
lea    0xecb(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rbx,%r12,1),%rdi
add    $0x2,%rdi
movzbl (%r15),%ecx
mov    %ebp,%esi
mov    %r14,%rdx
call   1030 <snprintf@plt>
add    $0x1,%r15
add    $0xfffffffe,%ebp
add    $0x2,%rbx
cmp    $0x26,%rbx
jb     1140 <bin2hex+0x30>
lea    0x2ed2(%rip),%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@bin2hex.ret = internal global [41 x i8] zeroinitializer
@.str = [5 x i8] c"%02X\00"
define i8* @bin2hex(i8* nocapture %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i64 [ 0, %1 ], [ %10, %2 ]
%4 = phi i8* [ %0, %1 ], [ %11, %2 ]
%5 = getelementptr inbounds [41 x i8], [41 x i8]* @bin2hex.ret, i64 0, i64 %3
%6 = load i8, i8* %4
%7 = trunc i64 %3 to i32
%8 = sub nuw nsw i32 41, %7
%9 = tail call i32 @snprintf(i8* %5, i32 %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %6)
%10 = add nuw nsw i64 %3, 2
%11 = getelementptr inbounds i8, i8* %4, i64 1
%12 = icmp ult i64 %3, 38
br i1 %12, label %2, label %13
13: ; preds = %2
ret i8* getelementptr inbounds ([41 x i8], [41 x i8]* @bin2hex.ret, i64 0, i64 0)
}