#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*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ strdump(int /*<<< orphan*/ const *, size_t);
void hexdump8(const void *buf, size_t len) {
  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 |", (void *)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),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1158 <hexdump8+0x28>
jmp    12d0 <hexdump8+0x1a0>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1213 <hexdump8+0xe3>
mov    -0x20(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    11c7 <hexdump8+0x97>
cmpq   $0x0,-0x20(%rbp)
je     11b5 <hexdump8+0x85>
lea    0xe6e(%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    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
and    $0x3,%rax
cmp    $0x0,%rax
jne    11e3 <hexdump8+0xb3>
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    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1160 <hexdump8+0x30>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
and    $0xf,%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1248 <hexdump8+0x118>
mov    $0x10,%eax
sub    -0x30(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1250 <hexdump8+0x120>
movq   $0x10,-0x30(%rbp)
jmp    1255 <hexdump8+0x125>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    129e <hexdump8+0x16e>
mov    -0x20(%rbp),%rax
and    $0x3,%rax
cmp    $0x0,%rax
jne    127f <hexdump8+0x14f>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1255 <hexdump8+0x125>
lea    0xd5b(%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>:
test   %rsi,%rsi
je     1224 <hexdump8+0xf4>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xeb3(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
lea    0x4(%rbp),%r14
mov    0x0(%rbp),%esi
lea    0xe96(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%rbx
je     1228 <hexdump8+0xf8>
add    $0xffffffffffffffc4,%rbp
mov    %rbp,(%rsp)
mov    $0x1,%r13d
lea    0xe70(%rip),%rbp
xor    %r15d,%r15d
jmp    11bc <hexdump8+0x8c>
xchg   %ax,%ax
mov    -0x4(%r14,%r13,4),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r13
add    $0x4,%r15
cmp    %r13,%rbx
je     1225 <hexdump8+0xf5>
test   $0xf,%r13b
je     11d0 <hexdump8+0xa0>
test   $0x3,%r13b
jne    11a0 <hexdump8+0x70>
jmp    1215 <hexdump8+0xe5>
nopw   0x0(%rax,%rax,1)
lea    (%r14,%r15,1),%r12
lea    0xe25(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%rax
lea    (%rax,%r15,1),%rdi
mov    $0x10,%esi
call   1050 <strdump@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xdff(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x3,%r13b
jne    11a0 <hexdump8+0x70>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    11a0 <hexdump8+0x70>
ret
add    %r15,%r14
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    1285 <hexdump8+0x155>
lea    0xdb7(%rip),%r12
jmp    1274 <hexdump8+0x144>
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbp
je     1285 <hexdump8+0x155>
test   $0x3,%bl
jne    1260 <hexdump8+0x130>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1260 <hexdump8+0x130>
lea    0xd74(%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>

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