#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 *bits2ASCII(int);
void bin2hex(char *dst, char *src, int len) {
  while (len--) {
    *dst++ = bits2ASCII((*src >> 4) & 0xf);
    *dst++ = bits2ASCII(*src++ & 0xf);
  }
  *dst = '\0';
}


x86 assembly (clang, -O0):
<bin2hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     118e <bin2hex+0x7e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
sar    $0x4,%edi
and    $0xf,%edi
call   1030 <bits2ASCII@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
and    $0xf,%edi
call   1030 <bits2ASCII@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    1123 <bin2hex+0x13>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin2hex>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
test   %edx,%edx
je     1163 <bin2hex+0x53>
mov    %rsi,%r15
mov    %edx,%r12d
xor    %r13d,%r13d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%edi
shr    $0x4,%edi
call   1030 <bits2ASCII@plt>
mov    %al,(%r14,%rbx,2)
movzbl (%r15,%rbx,1),%edi
and    $0xf,%edi
call   1030 <bits2ASCII@plt>
mov    %al,0x1(%r14,%rbx,2)
add    $0x1,%rbx
add    $0xfffffffffffffffe,%r13
cmp    %ebx,%r12d
jne    1130 <bin2hex+0x20>
sub    %r13,%r14
movb   $0x0,(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @bin2hex(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %7
7: ; preds = %11, %3
%8 = load i32, i32* %6
%9 = add nsw i32 %8, -1
store i32 %9, i32* %6
%10 = icmp ne i32 %8, 0
br i1 %10, label %11, label %30
11: ; preds = %7
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = ashr i32 %14, 4
%16 = and i32 %15, 15
%17 = call i8* @bits2ASCII(i32 %16)
%18 = ptrtoint i8* %17 to i8
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %4
store i8 %18, i8* %19
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %5
%23 = load i8, i8* %21
%24 = sext i8 %23 to i32
%25 = and i32 %24, 15
%26 = call i8* @bits2ASCII(i32 %25)
%27 = ptrtoint i8* %26 to i8
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
store i8 %27, i8* %28
br label %7
30: ; preds = %7
%31 = load i8*, i8** %4
store i8 0, i8* %31
ret void
}

LLVM IR (-O2):
define void @bin2hex(i8* nocapture writeonly %0, i8* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %26, label %5
5: ; preds = %3, %5
%6 = phi i32 [ %9, %5 ], [ %2, %3 ]
%7 = phi i8* [ %17, %5 ], [ %1, %3 ]
%8 = phi i8* [ %24, %5 ], [ %0, %3 ]
%9 = add nsw i32 %6, -1
%10 = load i8, i8* %7
%11 = lshr i8 %10, 4
%12 = zext i8 %11 to i32
%13 = tail call i8* @bits2ASCII(i32 %12)
%14 = ptrtoint i8* %13 to i64
%15 = trunc i64 %14 to i8
%16 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %15, i8* %8
%17 = getelementptr inbounds i8, i8* %7, i64 1
%18 = load i8, i8* %7
%19 = and i8 %18, 15
%20 = zext i8 %19 to i32
%21 = tail call i8* @bits2ASCII(i32 %20)
%22 = ptrtoint i8* %21 to i64
%23 = trunc i64 %22 to i8
%24 = getelementptr inbounds i8, i8* %8, i64 2
store i8 %23, i8* %16
%25 = icmp eq i32 %9, 0
br i1 %25, label %26, label %5
26: ; preds = %5, %3
%27 = phi i8* [ %0, %3 ], [ %24, %5 ]
store i8 0, i8* %27
ret void
}