#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 */
void _blkmk_bin2hex(char *out, const void *data, size_t datasz) {
  const unsigned char *datac = data;
  static char hex[] = "0123456789abcdef";
  out[datasz * 2] = '\0';
  for (size_t i = 0; i < datasz; ++i) {
    out[i * 2] = hex[datac[i] >> 4];
    out[(i * 2) + 1] = hex[datac[i] & 15];
  }
}


x86 assembly (clang, -O0):
<_blkmk_bin2hex>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
shl    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a6 <_blkmk_bin2hex+0xa6>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
movslq %eax,%rcx
lea    0x2ed9(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
shl    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0x2eae(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
shl    $0x1,%rcx
mov    %dl,0x1(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1130 <_blkmk_bin2hex+0x30>
pop    %rbp
ret

x86 assembly (clang, -O2):
<_blkmk_bin2hex>:
movb   $0x0,(%rdi,%rdx,2)
test   %rdx,%rdx
je     1149 <_blkmk_bin2hex+0x49>
xor    %eax,%eax
lea    0xeee(%rip),%r8
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rsi,%rax,1),%ecx
shr    $0x4,%rcx
movzbl (%rcx,%r8,1),%ecx
mov    %cl,(%rdi,%rax,2)
movzbl (%rsi,%rax,1),%ecx
and    $0xf,%ecx
movzbl (%rcx,%r8,1),%ecx
mov    %cl,0x1(%rdi,%rax,2)
add    $0x1,%rax
cmp    %rax,%rdx
jne    1120 <_blkmk_bin2hex+0x20>
ret

LLVM IR (-O0):
@_blkmk_bin2hex.hex = internal global [17 x i8] c"0123456789abcdef\00"
define void @_blkmk_bin2hex(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i8*, i8** %5
store i8* %9, i8** %7
%10 = load i8*, i8** %4
%11 = load i64, i64* %6
%12 = mul i64 %11, 2
%13 = getelementptr inbounds i8, i8* %10, i64 %12
store i8 0, i8* %13
store i64 0, i64* %8
br label %14
14: ; preds = %46, %3
%15 = load i64, i64* %8
%16 = load i64, i64* %6
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %49
18: ; preds = %14
%19 = load i8*, i8** %7
%20 = load i64, i64* %8
%21 = getelementptr inbounds i8, i8* %19, i64 %20
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = ashr i32 %23, 4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [17 x i8], [17 x i8]* @_blkmk_bin2hex.hex, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = load i8*, i8** %4
%29 = load i64, i64* %8
%30 = mul i64 %29, 2
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 %27, i8* %31
%32 = load i8*, i8** %7
%33 = load i64, i64* %8
%34 = getelementptr inbounds i8, i8* %32, i64 %33
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = and i32 %36, 15
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [17 x i8], [17 x i8]* @_blkmk_bin2hex.hex, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = load i8*, i8** %4
%42 = load i64, i64* %8
%43 = mul i64 %42, 2
%44 = add i64 %43, 1
%45 = getelementptr inbounds i8, i8* %41, i64 %44
store i8 %40, i8* %45
br label %46
46: ; preds = %18
%47 = load i64, i64* %8
%48 = add i64 %47, 1
store i64 %48, i64* %8
br label %14
49: ; preds = %14
ret void
}

LLVM IR (-O2):
@_blkmk_bin2hex.hex = internal unnamed_addr constant [17 x i8] c"0123456789abcdef\00"
define void @_blkmk_bin2hex(i8* nocapture writeonly %0, i8* nocapture %1, i64 %2) {
%4 = shl i64 %2, 1
%5 = getelementptr inbounds i8, i8* %0, i64 %4
store i8 0, i8* %5
%6 = icmp eq i64 %2, 0
br i1 %6, label %7, label %8
7: ; preds = %8, %3
ret void
8: ; preds = %3, %8
%9 = phi i64 [ %25, %8 ], [ 0, %3 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = load i8, i8* %10
%12 = lshr i8 %11, 4
%13 = zext i8 %12 to i64
%14 = getelementptr inbounds [17 x i8], [17 x i8]* @_blkmk_bin2hex.hex, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = shl i64 %9, 1
%17 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 %15, i8* %17
%18 = load i8, i8* %10
%19 = and i8 %18, 15
%20 = zext i8 %19 to i64
%21 = getelementptr inbounds [17 x i8], [17 x i8]* @_blkmk_bin2hex.hex, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = or i64 %16, 1
%24 = getelementptr inbounds i8, i8* %0, i64 %23
store i8 %22, i8* %24
%25 = add nuw i64 %9, 1
%26 = icmp eq i64 %25, %2
br i1 %26, label %7, label %8
}