#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*/ memset(char *, int /*<<< orphan*/, int);
char nibbleToHexChar(int);
void multosBinToHex(unsigned char *binIn, char *hexOut, int len) {
  int x;
  int hi, lo;
  char hichar, lochar;
  memset(hexOut, 0, len * 2 + 1);
  for (x = 0; x < len; x++) {
    hi = binIn[x] >> 4;
    lo = binIn[x] & 0x0F;
    hichar = nibbleToHexChar(hi);
    lochar = nibbleToHexChar(lo);
    hexOut[x * 2] = hichar;
    hexOut[(x * 2) + 1] = lochar;
  }
}


x86 assembly (clang, -O0):
<multosBinToHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
shl    $0x1,%edx
add    $0x1,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11cb <multosBinToHex+0xab>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <nibbleToHexChar@plt>
mov    %al,-0x21(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <nibbleToHexChar@plt>
mov    %al,-0x22(%rbp)
mov    -0x21(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x22(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114e <multosBinToHex+0x2e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multosBinToHex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%r14
lea    (%r15,%r15,1),%edx
add    $0x1,%edx
mov    %rsi,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
test   %r15d,%r15d
jle    117e <multosBinToHex+0x5e>
mov    %r15d,%r15d
xor    %ebx,%ebx
nop
movzbl (%r14,%rbx,1),%ebp
mov    %ebp,%edi
shr    $0x4,%edi
and    $0xf,%ebp
call   1030 <nibbleToHexChar@plt>
mov    %eax,%r13d
mov    %ebp,%edi
call   1030 <nibbleToHexChar@plt>
mov    %r13b,(%r12,%rbx,2)
mov    %al,0x1(%r12,%rbx,2)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <multosBinToHex+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @multosBinToHex(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%12 = load i8*, i8** %5
%13 = load i32, i32* %6
%14 = mul nsw i32 %13, 2
%15 = add nsw i32 %14, 1
%16 = call i32 @memset(i8* %12, i32 0, i32 %15)
store i32 0, i32* %7
br label %17
17: ; preds = %53, %3
%18 = load i32, i32* %7
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %56
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = ashr i32 %27, 4
store i32 %28, i32* %8
%29 = load i8*, i8** %4
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = and i32 %34, 15
store i32 %35, i32* %9
%36 = load i32, i32* %8
%37 = call signext i8 @nibbleToHexChar(i32 %36)
store i8 %37, i8* %10
%38 = load i32, i32* %9
%39 = call signext i8 @nibbleToHexChar(i32 %38)
store i8 %39, i8* %11
%40 = load i8, i8* %10
%41 = load i8*, i8** %5
%42 = load i32, i32* %7
%43 = mul nsw i32 %42, 2
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
store i8 %40, i8* %45
%46 = load i8, i8* %11
%47 = load i8*, i8** %5
%48 = load i32, i32* %7
%49 = mul nsw i32 %48, 2
%50 = add nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %47, i64 %51
store i8 %46, i8* %52
br label %53
53: ; preds = %21
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
br label %17
56: ; preds = %17
ret void
}

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