#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 */
typedef int uint8_t;

/* Variables and functions */
int bin_to_hex(int);
int binary_to_hexascii(uint8_t hex_buf[], uint8_t bin_buf[], int n_bin) {
  int i, j;
  for (i = 0, j = 0; j < n_bin; i += 2, j++) {
    hex_buf[i] = bin_to_hex(bin_buf[j] >> 4);
    hex_buf[i + 1] = bin_to_hex(bin_buf[j] & 0x0F);
  }
  hex_buf[i] = '\0';
  return i;
}


x86 assembly (clang, -O0):
<binary_to_hexascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1199 <binary_to_hexascii+0x89>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
sar    $0x4,%edi
call   1030 <bin_to_hex@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
and    $0xf,%edi
call   1030 <bin_to_hex@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1131 <binary_to_hexascii+0x21>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary_to_hexascii>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
test   %edx,%edx
jle    115c <binary_to_hexascii+0x4c>
mov    %rsi,%r15
mov    %edx,%r12d
add    %r12,%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbx,2),%edi
sar    $0x4,%edi
call   1030 <bin_to_hex@plt>
mov    %eax,(%r14,%rbx,4)
mov    (%r15,%rbx,2),%edi
and    $0xf,%edi
call   1030 <bin_to_hex@plt>
mov    %eax,0x4(%r14,%rbx,4)
add    $0x2,%rbx
cmp    %rbx,%r12
jne    1130 <binary_to_hexascii+0x20>
jmp    115e <binary_to_hexascii+0x4e>
xor    %ebx,%ebx
mov    %ebx,%eax
movl   $0x0,(%r14,%rax,4)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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