#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 */
const char *in_data_to_hex(char *buff, const uint8_t *src, int s,
                           int lowercase) {
  int i;
  static const char hex_table_uc[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
                                        '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
  static const char hex_table_lc[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
                                        '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
  const char *hex_table = lowercase ? hex_table_lc : hex_table_uc;
  for (i = 0; i < s; i++) {
    buff[i * 2] = hex_table[src[i] >> 4];
    buff[i * 2 + 1] = hex_table[src[i] & 0xF];
  }
  return buff;
}


x86 assembly (clang, -O0):
<in_data_to_hex>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x18(%rbp),%edx
lea    0xee4(%rip),%rax
lea    0xeed(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a2 <in_data_to_hex+0xa2>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
mov    (%rcx,%rdx,4),%ecx
sar    $0x4,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
mov    (%rcx,%rdx,4),%ecx
and    $0xf,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1135 <in_data_to_hex+0x35>
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<in_data_to_hex>:
mov    %rdi,%rax
test   %ecx,%ecx
lea    0xef4(%rip),%rdi
lea    0xefd(%rip),%rcx
cmove  %rdi,%rcx
test   %edx,%edx
jle    1147 <in_data_to_hex+0x47>
mov    %edx,%r8d
xor    %edi,%edi
mov    (%rsi,%rdi,4),%edx
sar    $0x4,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%edx
mov    %dl,(%rax,%rdi,2)
mov    (%rsi,%rdi,4),%edx
and    $0xf,%edx
movzbl (%rcx,%rdx,1),%edx
mov    %dl,0x1(%rax,%rdi,2)
add    $0x1,%rdi
cmp    %rdi,%r8
jne    1120 <in_data_to_hex+0x20>
ret

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

LLVM IR (-O2):
@in_data_to_hex.hex_table_uc = internal unnamed_addr constant [16 x i8] c"0123456789ABCDEF"
@in_data_to_hex.hex_table_lc = internal unnamed_addr constant [16 x i8] c"0123456789abcdef"
define i8* @in_data_to_hex(i8* returned writeonly %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %3, 0
%6 = select i1 %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @in_data_to_hex.hex_table_uc, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @in_data_to_hex.hex_table_lc, i64 0, i64 0)
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %29
8: ; preds = %4
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %27, %10 ]
%12 = getelementptr inbounds i32, i32* %1, i64 %11
%13 = load i32, i32* %12
%14 = ashr i32 %13, 4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %6, i64 %15
%17 = load i8, i8* %16
%18 = shl nuw nsw i64 %11, 1
%19 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 %17, i8* %19
%20 = load i32, i32* %12
%21 = and i32 %20, 15
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %6, i64 %22
%24 = load i8, i8* %23
%25 = or i64 %18, 1
%26 = getelementptr inbounds i8, i8* %0, i64 %25
store i8 %24, i8* %26
%27 = add nuw nsw i64 %11, 1
%28 = icmp eq i64 %27, %9
br i1 %28, label %29, label %10
29: ; preds = %10, %4
ret i8* %0
}