#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 hexprint(const void *_str, size_t len) {
  size_t i;
  const char *str = _str;
  printf("\t;; ");
  for (i = 0; i < len; i++) {
    printf("%02x ", (str[i] & 0xFF));
    if ((i + 1) % 8 == 0)
      printf(" ");
    if ((i + 1) % 16 == 0 && i + 1 < len)
      printf("\n\t;; ");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<hexprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xed8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11dc <hexprint+0xcc>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
and    $0xff,%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
and    $0x7,%rax
cmp    $0x0,%rax
jne    1190 <hexprint+0x80>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    11c6 <hexprint+0xb6>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
cmp    -0x10(%rbp),%rax
jae    11c6 <hexprint+0xb6>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11cb <hexprint+0xbb>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113e <hexprint+0x2e>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexprint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %rdi,%r14
lea    0xecf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r13,%r13
je     11ad <hexprint+0x8d>
mov    %r13,%rbx
neg    %rbx
mov    $0x1,%ebp
lea    0xeaa(%rip),%r15
lea    0xea9(%rip),%r12
jmp    1172 <hexprint+0x52>
nop
lea    (%rbx,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbp
cmp    $0x1,%rax
je     11ad <hexprint+0x8d>
movzbl -0x1(%r14,%rbp,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x7,%bpl
jne    1192 <hexprint+0x72>
mov    $0x20,%edi
call   1030 <putchar@plt>
cmp    %r13,%rbp
jae    1160 <hexprint+0x40>
mov    %ebp,%eax
and    $0xf,%eax
test   %rax,%rax
jne    1160 <hexprint+0x40>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1160 <hexprint+0x40>
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 = [5 x i8] c"\09;; \00"
@.str.1 = [6 x i8] c"%02x \00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [6 x i8] c"\0A\09;; \00"
@.str.4 = [2 x i8] c"\0A\00"
define void @hexprint(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i8*, i8** %3
store i8* %7, i8** %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %5
br label %9
9: ; preds = %40, %2
%10 = load i64, i64* %5
%11 = load i64, i64* %4
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %43
13: ; preds = %9
%14 = load i8*, i8** %6
%15 = load i64, i64* %5
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = and i32 %18, 255
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = load i64, i64* %5
%22 = add i64 %21, 1
%23 = urem i64 %22, 8
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %13
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %13
%28 = load i64, i64* %5
%29 = add i64 %28, 1
%30 = urem i64 %29, 16
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %27
%33 = load i64, i64* %5
%34 = add i64 %33, 1
%35 = load i64, i64* %4
%36 = icmp ult i64 %34, %35
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %32, %27
br label %40
40: ; preds = %39
%41 = load i64, i64* %5
%42 = add i64 %41, 1
store i64 %42, i64* %5
br label %9
43: ; preds = %9
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"\09;; \00"
@.str.1 = [6 x i8] c"%02x \00"
@.str.3 = [6 x i8] c"\0A\09;; \00"
define void @hexprint(i8* nocapture %0, i64 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %1, 0
br i1 %4, label %25, label %5
5: ; preds = %2, %23
%6 = phi i64 [ %11, %23 ], [ 0, %2 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = zext i8 %8 to i32
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = add nuw i64 %6, 1
%12 = and i64 %11, 7
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %5
%15 = tail call i32 @putchar(i32 32)
br label %16
16: ; preds = %14, %5
%17 = and i64 %11, 15
%18 = icmp eq i64 %17, 0
%19 = icmp ult i64 %11, %1
%20 = and i1 %19, %18
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %16, %21
%24 = icmp eq i64 %11, %1
br i1 %24, label %25, label %5
25: ; preds = %23, %2
%26 = tail call i32 @putchar(i32 10)
ret void
}