#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 char uint8_t;

/* Variables and functions */
int /*<<< orphan*/ uint8t2hex_lower(char, char *);
void do_full_hexify(uint8_t *buf, int len, uint8_t *out) {
  int max_len = (len >= 64) ? 64 : len;
  out[0] = '$';
  out[1] = 'H';
  out[2] = 'E';
  out[3] = 'X';
  out[4] = '[';
  out += 5;
  for (int i = max_len - 1, j = i * 2; i >= 0; i -= 1, j -= 2) {
    uint8t2hex_lower(buf[i], out + j);
  }
  out[max_len * 2] = ']';
  out[max_len * 2 + 1] = 0;
  return;
}


x86 assembly (clang, -O0):
<do_full_hexify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x40,-0xc(%rbp)
jl     113a <do_full_hexify+0x2a>
mov    $0x40,%eax
mov    %eax,-0x28(%rbp)
jmp    1140 <do_full_hexify+0x30>
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x24,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x48,0x1(%rax)
mov    -0x18(%rbp),%rax
movb   $0x45,0x2(%rax)
mov    -0x18(%rbp),%rax
movb   $0x58,0x3(%rax)
mov    -0x18(%rbp),%rax
movb   $0x5b,0x4(%rax)
mov    -0x18(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     11ca <do_full_hexify+0xba>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x18(%rbp),%rsi
movslq -0x24(%rbp),%rcx
add    %rcx,%rsi
movsbl %al,%edi
call   1030 <uint8t2hex_lower@plt>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x24(%rbp)
jmp    118b <do_full_hexify+0x7b>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x5d,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_full_hexify>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x40,%esi
mov    $0x40,%r12d
cmovl  %esi,%r12d
mov    %rdx,%r14
movl   $0x58454824,(%rdx)
movb   $0x5b,0x4(%rdx)
test   %esi,%esi
jle    117b <do_full_hexify+0x6b>
mov    %rdi,%r15
lea    -0x1(%r12),%eax
lea    (%rax,%rax,1),%ecx
movslq %ecx,%rcx
mov    %eax,%eax
add    %rax,%r15
lea    (%rcx,%r14,1),%rbx
add    $0x5,%rbx
mov    %r12d,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%r15),%edi
mov    %rbx,%rsi
call   1030 <uint8t2hex_lower@plt>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%r15
add    $0xfffffffffffffffe,%rbx
test   %ebp,%ebp
jg     1160 <do_full_hexify+0x50>
movslq %r12d,%rax
add    %r12d,%r12d
movb   $0x5d,0x5(%r14,%rax,2)
movslq %r12d,%rax
movb   $0x0,0x6(%r14,%rax,1)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @do_full_hexify(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = load i32, i32* %5
%11 = icmp sge i32 %10, 64
br i1 %11, label %12, label %13
12: ; preds = %3
br label %15
13: ; preds = %3
%14 = load i32, i32* %5
br label %15
15: ; preds = %13, %12
%16 = phi i32 [ 64, %12 ], [ %14, %13 ]
store i32 %16, i32* %7
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i64 0
store i8 36, i8* %18
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8 72, i8* %20
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 2
store i8 69, i8* %22
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i64 3
store i8 88, i8* %24
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 4
store i8 91, i8* %26
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i64 5
store i8* %28, i8** %6
%29 = load i32, i32* %7
%30 = sub nsw i32 %29, 1
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = mul nsw i32 %31, 2
store i32 %32, i32* %9
br label %33
33: ; preds = %47, %15
%34 = load i32, i32* %8
%35 = icmp sge i32 %34, 0
br i1 %35, label %36, label %52
36: ; preds = %33
%37 = load i8*, i8** %4
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
%42 = load i8*, i8** %6
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = call i32 @uint8t2hex_lower(i8 signext %41, i8* %45)
br label %47
47: ; preds = %36
%48 = load i32, i32* %8
%49 = sub nsw i32 %48, 1
store i32 %49, i32* %8
%50 = load i32, i32* %9
%51 = sub nsw i32 %50, 2
store i32 %51, i32* %9
br label %33
52: ; preds = %33
%53 = load i8*, i8** %6
%54 = load i32, i32* %7
%55 = mul nsw i32 %54, 2
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
store i8 93, i8* %57
%58 = load i8*, i8** %6
%59 = load i32, i32* %7
%60 = mul nsw i32 %59, 2
%61 = add nsw i32 %60, 1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %58, i64 %62
store i8 0, i8* %63
ret void
}

LLVM IR (-O2):
define void @do_full_hexify(i8* nocapture %0, i32 %1, i8* %2) {
%4 = icmp slt i32 %1, 64
%5 = select i1 %4, i32 %1, i32 64
store i8 36, i8* %2
%6 = getelementptr inbounds i8, i8* %2, i64 1
store i8 72, i8* %6
%7 = getelementptr inbounds i8, i8* %2, i64 2
store i8 69, i8* %7
%8 = getelementptr inbounds i8, i8* %2, i64 3
store i8 88, i8* %8
%9 = getelementptr inbounds i8, i8* %2, i64 4
store i8 91, i8* %9
%10 = getelementptr inbounds i8, i8* %2, i64 5
%11 = add i32 %5, -1
%12 = icmp sgt i32 %1, 0
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = shl i32 %11, 1
%15 = sext i32 %14 to i64
%16 = zext i32 %11 to i64
br label %24
17: ; preds = %24, %3
%18 = shl nsw i32 %5, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %10, i64 %19
store i8 93, i8* %20
%21 = or i32 %18, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %10, i64 %22
store i8 0, i8* %23
ret void
24: ; preds = %13, %24
%25 = phi i64 [ %16, %13 ], [ %31, %24 ]
%26 = phi i64 [ %15, %13 ], [ %32, %24 ]
%27 = getelementptr inbounds i8, i8* %0, i64 %25
%28 = load i8, i8* %27
%29 = getelementptr inbounds i8, i8* %10, i64 %26
%30 = tail call i32 @uint8t2hex_lower(i8 signext %28, i8* %29)
%31 = add nsw i64 %25, -1
%32 = add nsw i64 %26, -2
%33 = trunc i64 %25 to i32
%34 = icmp sgt i32 %33, 0
br i1 %34, label %24, label %17
}