#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*/ printf(char *, ...);
void u_hexout(void *_data, int _len) {
  if (!_data || _len <= 0) {
    return;
  }
  unsigned char *data = (unsigned char *)_data;
  int i = 0;
  do {
    if (i % 16 == 0) {
      printf("\t0x%04X: ", i);
    }
    if (i % 2 == 0) {
      printf("%02x", data[i]);
    } else {
      printf("%02x ", data[i]);
    }
    if ((i + 1) % 16 == 0) {
      printf("\n");
    }
    i++;
  } while (i < _len);
  printf("\n");
}


x86 assembly (clang, -O0):
<u_hexout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1134 <u_hexout+0x24>
cmpl   $0x0,-0xc(%rbp)
jg     1139 <u_hexout+0x29>
jmp    1202 <u_hexout+0xf2>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    116d <u_hexout+0x5d>
mov    -0x1c(%rbp),%esi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11a0 <u_hexout+0x90>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ba <u_hexout+0xaa>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11df <u_hexout+0xcf>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     1148 <u_hexout+0x38>
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<u_hexout>:
test   %rdi,%rdi
je     11a1 <u_hexout+0x81>
test   %esi,%esi
jle    11a1 <u_hexout+0x81>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    %esi,%r12d
lea    0xebf(%rip),%r14
lea    0xec2(%rip),%r13
lea    0xec0(%rip),%rbp
xor    %ebx,%ebx
jmp    1165 <u_hexout+0x45>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %rbx,%r12
je     11a2 <u_hexout+0x82>
test   $0xf,%bl
jne    1176 <u_hexout+0x56>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x1,%bl
movzbl (%r15,%rbx,1),%esi
mov    %rbp,%rdi
cmove  %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
test   $0xf,%bl
jne    1160 <u_hexout+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1160 <u_hexout+0x40>
ret
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"\090x%04X: \00"
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [6 x i8] c"%02x \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @u_hexout(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* %4
%11 = icmp sle i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9, %2
br label %58
13: ; preds = %9
%14 = load i8*, i8** %3
store i8* %14, i8** %5
store i32 0, i32* %6
br label %15
15: ; preds = %52, %13
%16 = load i32, i32* %6
%17 = srem i32 %16, 16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %19, %15
%23 = load i32, i32* %6
%24 = srem i32 %23, 2
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %22
%27 = load i8*, i8** %5
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %32)
br label %42
34: ; preds = %22
%35 = load i8*, i8** %5
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %34, %26
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
%45 = srem i32 %44, 16
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47, %42
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
br label %52
52: ; preds = %49
%53 = load i32, i32* %6
%54 = load i32, i32* %4
%55 = icmp slt i32 %53, %54
br i1 %55, label %15, label %56
56: ; preds = %52
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %58
58: ; preds = %56, %12
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"\090x%04X: \00"
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [6 x i8] c"%02x \00"
define void @u_hexout(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
%4 = icmp slt i32 %1, 1
%5 = or i1 %3, %4
br i1 %5, label %32, label %6
6: ; preds = %2
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %28
%9 = phi i64 [ 0, %6 ], [ %23, %28 ]
%10 = trunc i64 %9 to i32
%11 = and i32 %10, 15
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %15
15: ; preds = %13, %8
%16 = and i32 %10, 1
%17 = icmp eq i32 %16, 0
%18 = getelementptr inbounds i8, i8* %0, i64 %9
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = select i1 %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %21, i32 %20)
%23 = add nuw nsw i64 %9, 1
%24 = and i64 %23, 15
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %15
%27 = tail call i32 @putchar(i32 10)
br label %28
28: ; preds = %26, %15
%29 = icmp eq i64 %23, %7
br i1 %29, label %30, label %8
30: ; preds = %28
%31 = tail call i32 @putchar(i32 10)
br label %32
32: ; preds = %2, %30
ret void
}