#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*/ assert(void const *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ strdump(int /*<<< orphan*/ const *, size_t);
void hexdump8(const void *buf, size_t len) {
  assert(buf);
  const uint8_t *data = buf;
  size_t i, spaces, tail;
  if (!len) {
    return;
  }
  for (i = 0; i < len; ++i) {
    if (i % 16 == 0) {
      if (i) {
        printf(" | ");
        strdump(data - 16, 16);
        putchar('\n');
      }
      printf("%p |", data);
    }
    if (i % 4 == 0) {
      putchar(' ');
    }
    printf("%02x", *data++);
  }
  spaces = len;
  tail = len % 16;
  if (tail) {
    spaces += 16 - tail;
  } else {
    tail = 16;
  }
  while (i < spaces) {
    if (i % 4 == 0) {
      putchar(' ');
    }
    ++i;
    printf("  ");
  }
  printf(" | ");
  strdump(data - tail, tail);
  putchar('\n');
}


x86 assembly (clang, -O0):
<hexdump8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1171 <hexdump8+0x31>
jmp    12e9 <hexdump8+0x1a9>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    122c <hexdump8+0xec>
mov    -0x20(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    11e0 <hexdump8+0xa0>
cmpq   $0x0,-0x20(%rbp)
je     11ce <hexdump8+0x8e>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
add    $0xffffffffffffffc0,%rdi
mov    $0x10,%esi
call   1050 <strdump@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%rsi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
and    $0x3,%rax
cmp    $0x0,%rax
jne    11fc <hexdump8+0xbc>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%esi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1179 <hexdump8+0x39>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
and    $0xf,%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1261 <hexdump8+0x121>
mov    $0x10,%eax
sub    -0x30(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1269 <hexdump8+0x129>
movq   $0x10,-0x30(%rbp)
jmp    126e <hexdump8+0x12e>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    12b7 <hexdump8+0x177>
mov    -0x20(%rbp),%rax
and    $0x3,%rax
cmp    $0x0,%rax
jne    1298 <hexdump8+0x158>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126e <hexdump8+0x12e>
lea    0xd42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
sub    -0x30(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
call   1050 <strdump@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump8>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1060 <assert@plt>
test   %rbx,%rbx
je     1231 <hexdump8+0xf1>
lea    0xe9e(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    (%r14),%esi
add    $0x4,%r14
lea    0xe81(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%rbx
jne    1240 <hexdump8+0x100>
mov    %ebx,%r15d
and    $0xf,%r15d
mov    $0x10,%eax
mov    $0x10,%ebp
sub    %r15,%rbp
test   %r15,%r15
cmove  %r15,%rbp
cmove  %rax,%r15
lea    (%rbx,%rbp,1),%rax
cmp    %rbx,%rax
jbe    11f5 <hexdump8+0xb5>
lea    0xe46(%rip),%r12
jmp    11e4 <hexdump8+0xa4>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbp
je     11f5 <hexdump8+0xb5>
test   $0x3,%bl
jne    11d0 <hexdump8+0x90>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    11d0 <hexdump8+0x90>
lea    0xe04(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x0(,%r15,4),%rax
sub    %rax,%r14
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strdump@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebp
lea    0xdb4(%rip),%r15
lea    0xdb1(%rip),%r12
lea    0xdaf(%rip),%r13
jmp    127e <hexdump8+0x13e>
nopl   0x0(%rax)
mov    (%r14),%esi
add    $0x4,%r14
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
je     1199 <hexdump8+0x59>
test   $0xf,%bpl
je     1290 <hexdump8+0x150>
test   $0x3,%bpl
jne    1260 <hexdump8+0x120>
jmp    12c5 <hexdump8+0x185>
nopl   0x0(%rax)
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    -0x40(%r14),%rdi
mov    $0x10,%esi
call   1050 <strdump@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x3,%bpl
jne    1260 <hexdump8+0x120>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1260 <hexdump8+0x120>

LLVM IR (-O0):
@.str = [4 x i8] c" | \00"
@.str.1 = [5 x i8] c"%p |\00"
@.str.2 = [5 x i8] c"%02x\00"
@.str.3 = [3 x i8] c" \00"
define void @hexdump8(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%9 = load i8*, i8** %3
%10 = call i32 @assert(i8* %9)
%11 = load i8*, i8** %3
%12 = bitcast i8* %11 to i32*
store i32* %12, i32** %5
%13 = load i64, i64* %4
%14 = icmp ne i64 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %2
br label %87
16: ; preds = %2
store i64 0, i64* %6
br label %17
17: ; preds = %48, %16
%18 = load i64, i64* %6
%19 = load i64, i64* %4
%20 = icmp ult i64 %18, %19
br i1 %20, label %21, label %51
21: ; preds = %17
%22 = load i64, i64* %6
%23 = urem i64 %22, 16
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %37
25: ; preds = %21
%26 = load i64, i64* %6
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%30 = load i32*, i32** %5
%31 = getelementptr inbounds i32, i32* %30, i64 -16
%32 = call i32 @strdump(i32* %31, i64 16)
%33 = call i32 @putchar(i8 signext 10)
br label %34
34: ; preds = %28, %25
%35 = load i32*, i32** %5
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %35)
br label %37
37: ; preds = %34, %21
%38 = load i64, i64* %6
%39 = urem i64 %38, 4
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @putchar(i8 signext 32)
br label %43
43: ; preds = %41, %37
%44 = load i32*, i32** %5
%45 = getelementptr inbounds i32, i32* %44, i32 1
store i32* %45, i32** %5
%46 = load i32, i32* %44
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %43
%49 = load i64, i64* %6
%50 = add i64 %49, 1
store i64 %50, i64* %6
br label %17
51: ; preds = %17
%52 = load i64, i64* %4
store i64 %52, i64* %7
%53 = load i64, i64* %4
%54 = urem i64 %53, 16
store i64 %54, i64* %8
%55 = load i64, i64* %8
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %51
%58 = load i64, i64* %8
%59 = sub i64 16, %58
%60 = load i64, i64* %7
%61 = add i64 %60, %59
store i64 %61, i64* %7
br label %63
62: ; preds = %51
store i64 16, i64* %8
br label %63
63: ; preds = %62, %57
br label %64
64: ; preds = %74, %63
%65 = load i64, i64* %6
%66 = load i64, i64* %7
%67 = icmp ult i64 %65, %66
br i1 %67, label %68, label %78
68: ; preds = %64
%69 = load i64, i64* %6
%70 = urem i64 %69, 4
%71 = icmp eq i64 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %68
%73 = call i32 @putchar(i8 signext 32)
br label %74
74: ; preds = %72, %68
%75 = load i64, i64* %6
%76 = add i64 %75, 1
store i64 %76, i64* %6
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %64
78: ; preds = %64
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%80 = load i32*, i32** %5
%81 = load i64, i64* %8
%82 = sub i64 0, %81
%83 = getelementptr inbounds i32, i32* %80, i64 %82
%84 = load i64, i64* %8
%85 = call i32 @strdump(i32* %83, i64 %84)
%86 = call i32 @putchar(i8 signext 10)
br label %87
87: ; preds = %78, %15
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c" | \00"
@.str.1 = [5 x i8] c"%p |\00"
@.str.2 = [5 x i8] c"%02x\00"
@.str.3 = [3 x i8] c" \00"
define void @hexdump8(i8* %0, i64 %1) {
%3 = tail call i32 @assert(i8* %0)
%4 = icmp eq i64 %1, 0
br i1 %4, label %61, label %5
5: ; preds = %2
%6 = bitcast i8* %0 to i32*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = tail call i32 @putchar(i8 signext 32)
%9 = getelementptr inbounds i8, i8* %0, i64 4
%10 = bitcast i8* %9 to i32*
%11 = load i32, i32* %6
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = icmp eq i64 %1, 1
br i1 %13, label %36, label %14
14: ; preds = %5, %30
%15 = phi i64 [ %34, %30 ], [ 1, %5 ]
%16 = phi i32* [ %31, %30 ], [ %10, %5 ]
%17 = and i64 %15, 15
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%21 = getelementptr inbounds i32, i32* %16, i64 -16
%22 = tail call i32 @strdump(i32* %21, i64 16)
%23 = tail call i32 @putchar(i8 signext 10)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %16)
br label %25
25: ; preds = %19, %14
%26 = and i64 %15, 3
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = tail call i32 @putchar(i8 signext 32)
br label %30
30: ; preds = %28, %25
%31 = getelementptr inbounds i32, i32* %16, i64 1
%32 = load i32, i32* %16
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = add nuw i64 %15, 1
%35 = icmp eq i64 %34, %1
br i1 %35, label %36, label %14
36: ; preds = %30, %5
%37 = phi i32* [ %10, %5 ], [ %31, %30 ]
%38 = and i64 %1, 15
%39 = icmp eq i64 %38, 0
%40 = sub nuw nsw i64 16, %38
%41 = select i1 %39, i64 0, i64 %40
%42 = add i64 %41, %1
%43 = select i1 %39, i64 16, i64 %38
%44 = icmp ugt i64 %42, %1
br i1 %44, label %45, label %55
45: ; preds = %36, %51
%46 = phi i64 [ %52, %51 ], [ %1, %36 ]
%47 = and i64 %46, 3
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = tail call i32 @putchar(i8 signext 32)
br label %51
51: ; preds = %49, %45
%52 = add i64 %46, 1
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%54 = icmp eq i64 %52, %42
br i1 %54, label %55, label %45
55: ; preds = %51, %36
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%57 = sub nsw i64 0, %43
%58 = getelementptr inbounds i32, i32* %37, i64 %57
%59 = tail call i32 @strdump(i32* %58, i64 %43)
%60 = tail call i32 @putchar(i8 signext 10)
br label %61
61: ; preds = %2, %55
ret void
}