#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 /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ tprintf(char *, ...);
void _hex(uint8_t *ptr, size_t len) {
  if (!len)
    return;
  tprintf(" [ Hex ");
  for (; ptr && len-- > 0; ptr++)
    tprintf(" %.2x", *ptr);
  tprintf(" ]\n");
}


x86 assembly (clang, -O0):
<_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1130 <_hex+0x20>
jmp    11aa <_hex+0x9a>
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1030 <tprintf@plt>
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x11(%rbp)
je     1167 <_hex+0x57>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
seta   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1177 <_hex+0x67>
jmp    119c <_hex+0x8c>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <tprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
jmp    113e <_hex+0x2e>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <tprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_hex>:
test   %rsi,%rsi
je     1170 <_hex+0x60>
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
lea    0xed6(%rip),%rdi
xor    %eax,%eax
call   1030 <tprintf@plt>
test   %r14,%r14
je     1157 <_hex+0x47>
lea    0xecb(%rip),%r15
xor    %ebx,%ebx
nop
mov    (%r14,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <tprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <_hex+0x30>
lea    0xeb0(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <tprintf@plt>
ret

LLVM IR (-O0):
@.str = [8 x i8] c" [ Hex \00"
@.str.1 = [6 x i8] c" %.2x\00"
@.str.2 = [4 x i8] c" ]\0A\00"
define void @_hex(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
store i32* %0, i32** %3
store i64 %1, i64* %4
%5 = load i64, i64* %4
%6 = icmp ne i64 %5, 0
br i1 %6, label %8, label %7
7: ; preds = %2
br label %28
8: ; preds = %2
%9 = call i32 (i8*, ...) @tprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %23, %8
%11 = load i32*, i32** %3
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i64, i64* %4
%15 = add i64 %14, -1
store i64 %15, i64* %4
%16 = icmp ugt i64 %14, 0
br label %17
17: ; preds = %13, %10
%18 = phi i1 [ false, %10 ], [ %16, %13 ]
br i1 %18, label %19, label %26
19: ; preds = %17
%20 = load i32*, i32** %3
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @tprintf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %19
%24 = load i32*, i32** %3
%25 = getelementptr inbounds i32, i32* %24, i32 1
store i32* %25, i32** %3
br label %10
26: ; preds = %17
%27 = call i32 (i8*, ...) @tprintf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %7
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c" [ Hex \00"
@.str.1 = [6 x i8] c" %.2x\00"
@.str.2 = [4 x i8] c" ]\0A\00"
define void @_hex(i32* %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @tprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %0, null
br i1 %6, label %15, label %7
7: ; preds = %4, %7
%8 = phi i64 [ %10, %7 ], [ %1, %4 ]
%9 = phi i32* [ %13, %7 ], [ %0, %4 ]
%10 = add i64 %8, -1
%11 = load i32, i32* %9
%12 = tail call i32 (i8*, ...) @tprintf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds i32, i32* %9, i64 1
%14 = icmp eq i64 %10, 0
br i1 %14, label %15, label %7
15: ; preds = %7, %4
%16 = tail call i32 (i8*, ...) @tprintf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %2, %15
ret void
}