#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 */
int /*<<< orphan*/ eembed_byte_to_hex_chars(char *, char *, unsigned char);
char *eembed_bytes_to_hex(char *buf, size_t buf_len, unsigned char *bytes,
                          size_t bytes_len) {
  size_t i = 0;
  size_t pos = 0;
  if (!buf) {
    return NULL;
  }
  if (buf_len < (2 + (2 * bytes_len) + 1)) {
    return NULL;
  }
  buf[pos++] = '0';
  buf[pos++] = 'x';
  for (i = 0; i < bytes_len; ++i) {
    char h = 0;
    char l = 0;
    eembed_byte_to_hex_chars(&h, &l, bytes[i]);
    buf[pos++] = h;
    buf[pos++] = l;
  }
  buf[pos] = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<eembed_bytes_to_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1150 <eembed_bytes_to_hex+0x40>
movq   $0x0,-0x8(%rbp)
jmp    1236 <eembed_bytes_to_hex+0x126>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
shl    $0x1,%rcx
add    $0x2,%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jae    117a <eembed_bytes_to_hex+0x6a>
movq   $0x0,-0x8(%rbp)
jmp    1236 <eembed_bytes_to_hex+0x126>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
movb   $0x30,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
movb   $0x78,(%rax,%rcx,1)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1222 <eembed_bytes_to_hex+0x112>
movb   $0x0,-0x39(%rbp)
movb   $0x0,-0x3a(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
lea    -0x39(%rbp),%rdi
lea    -0x3a(%rbp),%rsi
movzbl (%rax,%rcx,1),%edx
call   1030 <eembed_byte_to_hex_chars@plt>
mov    -0x39(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x38(%rbp)
mov    %dl,(%rax,%rcx,1)
mov    -0x3a(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x38(%rbp)
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11b0 <eembed_bytes_to_hex+0xa0>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eembed_bytes_to_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1130 <eembed_bytes_to_hex+0x20>
mov    %rcx,%r14
lea    (%rcx,%rcx,1),%rax
add    $0x3,%rax
cmp    %rsi,%rax
jbe    1134 <eembed_bytes_to_hex+0x24>
xor    %ebx,%ebx
jmp    11a8 <eembed_bytes_to_hex+0x98>
mov    %rdi,%rbx
movw   $0x7830,(%rdi)
test   %r14,%r14
je     119f <eembed_bytes_to_hex+0x8f>
mov    %rdx,%r15
mov    $0x2,%ebp
xor    %r12d,%r12d
lea    0x6(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x0,0x7(%rsp)
movb   $0x0,0x6(%rsp)
movzbl (%r15,%r12,1),%edx
lea    0x7(%rsp),%rdi
mov    %r13,%rsi
call   1030 <eembed_byte_to_hex_chars@plt>
movzbl 0x7(%rsp),%eax
mov    %al,0x2(%rbx,%r12,2)
movzbl 0x6(%rsp),%eax
add    $0x2,%rbp
mov    %al,0x3(%rbx,%r12,2)
add    $0x1,%r12
cmp    %r12,%r14
jne    1160 <eembed_bytes_to_hex+0x50>
jmp    11a4 <eembed_bytes_to_hex+0x94>
mov    $0x2,%ebp
movb   $0x0,(%rbx,%rbp,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @eembed_bytes_to_hex(i8* writeonly %0, i64 %1, i8* nocapture %2, i64 %3) {
%5 = alloca i8
%6 = alloca i8
%7 = icmp eq i8* %0, null
br i1 %7, label %32, label %8
8: ; preds = %4
%9 = shl i64 %3, 1
%10 = add i64 %9, 3
%11 = icmp ugt i64 %10, %1
br i1 %11, label %32, label %12
12: ; preds = %8
store i8 48, i8* %0
%13 = getelementptr inbounds i8, i8* %0, i64 1
store i8 120, i8* %13
%14 = icmp eq i64 %3, 0
br i1 %14, label %29, label %15
15: ; preds = %12, %15
%16 = phi i64 [ %25, %15 ], [ 2, %12 ]
%17 = phi i64 [ %27, %15 ], [ 0, %12 ]
store i8 0, i8* %5
store i8 0, i8* %6
%18 = getelementptr inbounds i8, i8* %2, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @eembed_byte_to_hex_chars(i8* %5, i8* %6, i8 zeroext %19)
%21 = load i8, i8* %5
%22 = or i64 %16, 1
%23 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 %21, i8* %23
%24 = load i8, i8* %6
%25 = add i64 %16, 2
%26 = getelementptr inbounds i8, i8* %0, i64 %22
store i8 %24, i8* %26
%27 = add nuw i64 %17, 1
%28 = icmp eq i64 %27, %3
br i1 %28, label %29, label %15
29: ; preds = %15, %12
%30 = phi i64 [ 2, %12 ], [ %25, %15 ]
%31 = getelementptr inbounds i8, i8* %0, i64 %30
store i8 0, i8* %31
br label %32
32: ; preds = %8, %4, %29
%33 = phi i8* [ %0, %29 ], [ null, %4 ], [ null, %8 ]
ret i8* %33
}