#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 */
void aeron_format_to_hex(char *str, size_t str_length, uint8_t *data,
                         size_t data_len) {
  static char table[] = {'0', '1', '2', '3', '4', '5', '6', '7',
                         '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
  size_t j = 0;
  for (size_t i = 0; i < data_len && j < str_length; i++) {
    char c_high = table[(data[i] >> 4) & 0x0F];
    char c_low = table[data[i] & 0x0F];
    str[j++] = c_high;
    str[j++] = c_low;
  }
  str[j] = '\0';
}


x86 assembly (clang, -O0):
<aeron_format_to_hex>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x33(%rbp)
jae    1145 <aeron_format_to_hex+0x45>
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
setb   %al
mov    %al,-0x33(%rbp)
mov    -0x33(%rbp),%al
test   $0x1,%al
jne    1155 <aeron_format_to_hex+0x55>
jmp    11d7 <aeron_format_to_hex+0xd7>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
sar    $0x4,%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0x2ec0(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x31(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0x2ea2(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x32(%rbp)
mov    -0x31(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x28(%rbp)
mov    %dl,(%rax,%rcx,1)
mov    -0x32(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x28(%rbp)
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1124 <aeron_format_to_hex+0x24>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
pop    %rbp
ret

x86 assembly (clang, -O2):
<aeron_format_to_hex>:
push   %rbx
xor    %r10d,%r10d
test   %rcx,%rcx
je     1156 <aeron_format_to_hex+0x56>
test   %rsi,%rsi
je     1156 <aeron_format_to_hex+0x56>
mov    $0x1,%r8d
xor    %r10d,%r10d
lea    0xee2(%rip),%r9
xchg   %ax,%ax
mov    (%rdx,%r10,2),%r11d
mov    %r11d,%eax
shr    $0x4,%eax
and    $0xf,%eax
movzbl (%rax,%r9,1),%ebx
and    $0xf,%r11d
movzbl (%r11,%r9,1),%eax
mov    %bl,(%rdi,%r10,1)
mov    %al,0x1(%rdi,%r10,1)
add    $0x2,%r10
cmp    %rcx,%r8
jae    1156 <aeron_format_to_hex+0x56>
add    $0x1,%r8
cmp    %rsi,%r10
jb     1120 <aeron_format_to_hex+0x20>
movb   $0x0,(%rdi,%r10,1)
pop    %rbx
ret

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

LLVM IR (-O2):
@aeron_format_to_hex.table = internal unnamed_addr constant [16 x i8] c"0123456789abcdef"
define void @aeron_format_to_hex(i8* nocapture writeonly %0, i64 %1, i32* nocapture %2, i64 %3) {
%5 = icmp ne i64 %3, 0
%6 = icmp ne i64 %1, 0
%7 = and i1 %5, %6
br i1 %7, label %11, label %8
8: ; preds = %11, %4
%9 = phi i64 [ 0, %4 ], [ %27, %11 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 0, i8* %10
ret void
11: ; preds = %4, %11
%12 = phi i64 [ %27, %11 ], [ 0, %4 ]
%13 = phi i64 [ %29, %11 ], [ 0, %4 ]
%14 = getelementptr inbounds i32, i32* %2, i64 %13
%15 = load i32, i32* %14
%16 = lshr i32 %15, 4
%17 = and i32 %16, 15
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds [16 x i8], [16 x i8]* @aeron_format_to_hex.table, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = and i32 %15, 15
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [16 x i8], [16 x i8]* @aeron_format_to_hex.table, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = or i64 %12, 1
%26 = getelementptr inbounds i8, i8* %0, i64 %12
store i8 %20, i8* %26
%27 = add i64 %12, 2
%28 = getelementptr inbounds i8, i8* %0, i64 %25
store i8 %24, i8* %28
%29 = add nuw i64 %13, 1
%30 = icmp ult i64 %29, %3
%31 = icmp ult i64 %27, %1
%32 = select i1 %30, i1 %31, i1 false
br i1 %32, label %11, label %8
}