#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 */
unsigned char int2char(unsigned char const);
int bin2Hex(unsigned char *target, const unsigned char *src, int srcLen) {
  for (int i = 0; i < srcLen; i++) {
    *(target) = int2char(*src >> 4);
    target++;
    *(target) = int2char(*src & 0x0f);
    target++;
    src++;
  }
  return srcLen * 2;
}


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)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    119c <bin2Hex+0x8c>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
sar    $0x4,%eax
movzbl %al,%edi
call   1030 <int2char@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
and    $0xf,%eax
movzbl %al,%edi
call   1030 <int2char@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <bin2Hex+0x1a>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin2Hex>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
test   %edx,%edx
jle    115e <bin2Hex+0x4e>
mov    %rsi,%r12
mov    %rdi,%rbp
mov    %r14d,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%r12,%rbx,1),%eax
shr    $0x4,%al
movzbl %al,%edi
call   1030 <int2char@plt>
mov    %al,0x0(%rbp,%rbx,2)
movzbl (%r12,%rbx,1),%edi
and    $0xf,%edi
call   1030 <int2char@plt>
mov    %al,0x1(%rbp,%rbx,2)
add    $0x1,%rbx
cmp    %ebx,%r15d
jne    1130 <bin2Hex+0x20>
add    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bin2Hex(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %33, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %36
12: ; preds = %8
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = ashr i32 %15, 4
%17 = trunc i32 %16 to i8
%18 = call zeroext i8 @int2char(i8 zeroext %17)
%19 = load i8*, i8** %4
store i8 %18, i8* %19
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
%22 = load i8*, i8** %5
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = and i32 %24, 15
%26 = trunc i32 %25 to i8
%27 = call zeroext i8 @int2char(i8 zeroext %26)
%28 = load i8*, i8** %4
store i8 %27, i8* %28
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %4
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %5
br label %33
33: ; preds = %12
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %8
36: ; preds = %8
%37 = load i32, i32* %6
%38 = mul nsw i32 %37, 2
ret i32 %38
}

LLVM IR (-O2):
define i32 @bin2Hex(i8* nocapture writeonly %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %7, label %5
5: ; preds = %7, %3
%6 = shl nsw i32 %2, 1
ret i32 %6
7: ; preds = %3, %7
%8 = phi i32 [ %20, %7 ], [ 0, %3 ]
%9 = phi i8* [ %18, %7 ], [ %0, %3 ]
%10 = phi i8* [ %19, %7 ], [ %1, %3 ]
%11 = load i8, i8* %10
%12 = lshr i8 %11, 4
%13 = tail call zeroext i8 @int2char(i8 zeroext %12)
store i8 %13, i8* %9
%14 = getelementptr inbounds i8, i8* %9, i64 1
%15 = load i8, i8* %10
%16 = and i8 %15, 15
%17 = tail call zeroext i8 @int2char(i8 zeroext %16)
store i8 %17, i8* %14
%18 = getelementptr inbounds i8, i8* %9, i64 2
%19 = getelementptr inbounds i8, i8* %10, i64 1
%20 = add nuw nsw i32 %8, 1
%21 = icmp eq i32 %20, %2
br i1 %21, label %5, label %7
}