#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 __bytes_to_hexstring(unsigned char const *bytes, size_t in_size, char *out,
                          size_t out_size, int reverse) {
  static char const *const B = "0123456789abcdef";
  size_t offset = 0;
  for (size_t i = 0; i < in_size && offset + 2 <= out_size; i++, offset += 2) {
    unsigned char v = bytes[(reverse != 0) ? (in_size - i - 1) : i];
    out[offset + 0] = B[((v & 0xf0) >> 4)];
    out[offset + 1] = B[v & 0x0f];
  }
}


x86 assembly (clang, -O0):
<__bytes_to_hexstring>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x3a(%rbp)
jae    114d <__bytes_to_hexstring+0x4d>
mov    -0x30(%rbp),%rax
add    $0x2,%rax
cmp    -0x20(%rbp),%rax
setbe  %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
test   $0x1,%al
jne    115d <__bytes_to_hexstring+0x5d>
jmp    11fb <__bytes_to_hexstring+0xfb>
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1184 <__bytes_to_hexstring+0x84>
mov    -0x10(%rbp),%rax
sub    -0x38(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    118c <__bytes_to_hexstring+0x8c>
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rax
mov    -0x50(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x39(%rbp)
movzbl -0x39(%rbp),%eax
and    $0xf0,%eax
sar    $0x4,%eax
movslq %eax,%rcx
lea    0xe50(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movzbl -0x39(%rbp),%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xe31(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %dl,0x1(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x30(%rbp)
jmp    1128 <__bytes_to_hexstring+0x28>
pop    %rbp
ret

x86 assembly (clang, -O2):
<__bytes_to_hexstring>:
push   %r14
push   %rbx
test   %rsi,%rsi
je     1176 <__bytes_to_hexstring+0x76>
cmp    $0x2,%rcx
jb     1176 <__bytes_to_hexstring+0x76>
lea    -0x1(%rsi),%r9
mov    $0x4,%r11d
mov    $0x1,%r14d
lea    0xedb(%rip),%r10
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x1(%r14),%rbx
test   %r8d,%r8d
cmovne %r9,%rbx
movzbl (%rdi,%rbx,1),%eax
mov    %rax,%rbx
shr    $0x4,%rbx
movzbl (%rbx,%r10,1),%ebx
mov    %bl,-0x4(%rdx,%r11,1)
and    $0xf,%eax
movzbl (%rax,%r10,1),%eax
mov    %al,-0x3(%rdx,%r11,1)
cmp    %rsi,%r14
jae    1176 <__bytes_to_hexstring+0x76>
lea    0x2(%r11),%rax
add    $0x1,%r14
add    $0xffffffffffffffff,%r9
cmp    %rcx,%r11
mov    %rax,%r11
jbe    1130 <__bytes_to_hexstring+0x30>
pop    %rbx
pop    %r14
ret

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

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