#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*/ char2hex(char const, char *);
void binary2hex(const char *byte_str, int size, char *hex_str) {
  int i = 0;
  for (; i < size; ++i)
    char2hex(byte_str[i], hex_str + (i * 2));
  hex_str[i * 2] = '\0';
}


x86 assembly (clang, -O0):
<binary2hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1167 <binary2hex+0x57>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rsi
movsbl %al,%edi
call   1030 <char2hex@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <binary2hex+0x1a>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary2hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
test   %esi,%esi
jle    114f <binary2hex+0x3f>
mov    %esi,%r15d
mov    %rdi,%r12
mov    %esi,%r13d
xor    %ebp,%ebp
mov    %r14,%rbx
movsbl (%r12,%rbp,1),%edi
mov    %rbx,%rsi
call   1030 <char2hex@plt>
add    $0x1,%rbp
add    $0x2,%rbx
cmp    %rbp,%r13
jne    1130 <binary2hex+0x20>
add    %r15d,%r15d
jmp    1152 <binary2hex+0x42>
xor    %r15d,%r15d
movb   $0x0,(%r14,%r15,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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