#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 bin_to_hex(char bin2hex_table[256][2], const unsigned char *bin_buffer,
                size_t bin_buffer_size, char *hex_buffer,
                size_t hex_buffer_size) {
  unsigned i;
  for (i = 0; i < bin_buffer_size; ++i) {
    hex_buffer[i * 2] = bin2hex_table[bin_buffer[i]][0];
    hex_buffer[i * 2 + 1] = bin2hex_table[bin_buffer[i]][1];
  }
  hex_buffer[bin_buffer_size * 2] = 0x00;
  return;
}


x86 assembly (clang, -O0):
<bin_to_hex>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%rax
jae    1180 <bin_to_hex+0x80>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x2c(%rbp),%edx
movzbl (%rcx,%rdx,1),%ecx
mov    (%rax,%rcx,2),%dl
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
shl    $0x1,%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x2c(%rbp),%edx
movzbl (%rcx,%rdx,1),%ecx
mov    0x1(%rax,%rcx,2),%dl
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    111f <bin_to_hex+0x1f>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
shl    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin_to_hex>:
test   %rdx,%rdx
je     113a <bin_to_hex+0x3a>
xor    %r8d,%r8d
nopl   0x0(%rax,%rax,1)
movzbl (%rsi,%r8,1),%eax
movzbl (%rdi,%rax,2),%r9d
lea    (%r8,%r8,1),%r10d
mov    %r9b,(%rcx,%r10,1)
movzbl (%rsi,%r8,1),%eax
movzbl 0x1(%rdi,%rax,2),%eax
mov    %al,0x1(%rcx,%r10,1)
add    $0x1,%r8d
cmp    %rdx,%r8
jb     1110 <bin_to_hex+0x10>
movb   $0x0,(%rcx,%rdx,2)
ret

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

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