#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 raw2hex(char *dst, const unsigned char *src, size_t len) {
  size_t i, o;
  static const char hextab[] = "0123456789abcdef";
  for (i = 0, o = 0; i < len; i++, o += 2) {
    dst[o + 0] = hextab[0xf & (src[i] >> 4)];
    dst[o + 1] = hextab[0xf & src[i]];
  }
  dst[o] = 0;
}


x86 assembly (clang, -O0):
<raw2hex>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    119d <raw2hex+0x9d>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xeb6(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xe8f(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,0x1(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
jmp    1120 <raw2hex+0x20>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
pop    %rbp
ret

x86 assembly (clang, -O2):
<raw2hex>:
xor    %r9d,%r9d
test   %rdx,%rdx
je     114f <raw2hex+0x4f>
lea    0xef1(%rip),%r8
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rsi,%rcx,1),%eax
shr    $0x4,%rax
movzbl (%rax,%r8,1),%eax
mov    %al,(%rdi,%r9,1)
movzbl (%rsi,%rcx,1),%eax
and    $0xf,%eax
movzbl (%rax,%r8,1),%eax
mov    %al,0x1(%rdi,%r9,1)
add    $0x1,%rcx
add    $0x2,%r9
cmp    %rcx,%rdx
jne    1120 <raw2hex+0x20>
movb   $0x0,(%rdi,%r9,1)
ret

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

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