#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 hexdump(void *addr, int len) {
  int i;
  int count;
  unsigned char buff[17];
  unsigned char *pc;
  if (len <= 0) {
    return;
  }
  printf("       Address                     Hexadecimal values                "
         "      Printable     \n");
  printf(
      "   ----------------  ------------------------------------------------  "
      "------------------\n");
  if (len % 16 != 0) {
    count = ((len / 16) + 1) * 16;
  } else {
    count = len;
  }
  pc = (unsigned char *)addr;
  for (i = 0; i < count; i++) {
    if ((i % 8) == 0) {
      if (i != 0) {
        printf(" ");
      }
    }
    if (i < len) {
      if ((i % 16) == 0) {
        if (i != 0) {
          printf(" |%s|\n", buff);
        }
        printf("   (%5d) %08x ", i, i);
      }
      printf(" %02x", pc[i]);
      if ((pc[i] < 0x20) || (pc[i] > 0x7e)) {
        buff[i % 16] = '.';
      } else {
        buff[i % 16] = pc[i];
      }
      buff[(i % 16) + 1] = '\0';
    } else {
      printf("   ");
      buff[i % 16] = '.';
      buff[(i % 16) + 1] = '\0';
    }
  }
  printf("  |%s|\n", buff);
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     112e <hexdump+0x1e>
jmp    1309 <hexdump+0x1f9>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1177 <hexdump+0x67>
mov    -0xc(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
shl    $0x4,%eax
mov    %eax,-0x14(%rbp)
jmp    117d <hexdump+0x6d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12f7 <hexdump+0x1e7>
mov    -0x10(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11c9 <hexdump+0xb9>
cmpl   $0x0,-0x10(%rbp)
je     11c4 <hexdump+0xb4>
lea    0xf10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c9 <hexdump+0xb9>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12ad <hexdump+0x19d>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1219 <hexdump+0x109>
cmpl   $0x0,-0x10(%rbp)
je     1205 <hexdump+0xf5>
lea    -0x30(%rbp),%rsi
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     125d <hexdump+0x14d>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jle    1275 <hexdump+0x165>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movb   $0x2e,-0x30(%rbp,%rax,1)
jmp    1292 <hexdump+0x182>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%eax
mov    $0x10,%esi
cltd
idiv   %esi
movslq %edx,%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
movslq %edx,%rax
movb   $0x0,-0x30(%rbp,%rax,1)
jmp    12e4 <hexdump+0x1d4>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movb   $0x2e,-0x30(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
movslq %edx,%rax
movb   $0x0,-0x30(%rbp,%rax,1)
jmp    12e9 <hexdump+0x1d9>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118c <hexdump+0x7c>
lea    -0x30(%rbp),%rsi
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
test   %esi,%esi
jle    11d5 <hexdump+0xa5>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xecb(%rip),%rdi
call   1040 <puts@plt>
lea    0xf19(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rbx),%ebp
and    $0xfffffff0,%ebp
test   $0xf,%bl
cmove  %ebx,%ebp
test   %ebp,%ebp
jle    11b6 <hexdump+0x86>
lea    0xe86(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
movzbl (%r14),%esi
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl (%r14),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
mov    $0x2e,%ecx
cmovb  %ecx,%eax
mov    %al,(%rsp)
movb   $0x0,0x1(%rsp)
cmp    $0x1,%ebp
jne    11d6 <hexdump+0xa6>
lea    0xe58(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%r13d
mov    %ebp,%ebp
mov    $0x1,%ebx
mov    %rsp,%r12
jmp    121c <hexdump+0xec>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%r15d
and    $0xf,%r15d
movb   $0x2e,(%rsp,%r15,1)
mov    %r15d,%eax
movb   $0x0,0x1(%rax,%r12,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11b6 <hexdump+0x86>
test   $0x7,%bl
je     1230 <hexdump+0x100>
cmp    %r13,%rbx
jae    11f0 <hexdump+0xc0>
jmp    123f <hexdump+0x10f>
nopl   0x0(%rax,%rax,1)
mov    $0x20,%edi
call   1030 <putchar@plt>
cmp    %r13,%rbx
jae    11f0 <hexdump+0xc0>
mov    %ebx,%r15d
and    $0xf,%r15d
test   %r15,%r15
jne    126e <hexdump+0x13e>
lea    0xdc4(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd9d(%rip),%rdi
mov    %ebx,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
movzbl (%r14,%rbx,1),%esi
lea    0xd95(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl (%r14,%rbx,1),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
mov    $0x2e,%ecx
cmovb  %ecx,%eax
mov    %al,(%rsp,%r15,1)
jmp    120a <hexdump+0xda>

LLVM IR (-O0):
@.str = [91 x i8] c" Address Hexadecimal values Printable \0A\00"
@.str.1 = [91 x i8] c" ---------------- ------------------------------------------------ ------------------\0A\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [7 x i8] c" |%s|\0A\00"
@.str.4 = [15 x i8] c" (%5d) %08x \00"
@.str.5 = [6 x i8] c" %02x\00"
@.str.6 = [4 x i8] c" \00"
@.str.7 = [8 x i8] c" |%s|\0A\00"
define void @hexdump(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [17 x i8]
%8 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = icmp sle i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
br label %121
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* %4
%16 = srem i32 %15, 16
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = load i32, i32* %4
%20 = sdiv i32 %19, 16
%21 = add nsw i32 %20, 1
%22 = mul nsw i32 %21, 16
store i32 %22, i32* %6
br label %25
23: ; preds = %12
%24 = load i32, i32* %4
store i32 %24, i32* %6
br label %25
25: ; preds = %23, %18
%26 = load i8*, i8** %3
store i8* %26, i8** %8
store i32 0, i32* %5
br label %27
27: ; preds = %115, %25
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %118
31: ; preds = %27
%32 = load i32, i32* %5
%33 = srem i32 %32, 8
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %31
%36 = load i32, i32* %5
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %35
br label %41
41: ; preds = %40, %31
%42 = load i32, i32* %5
%43 = load i32, i32* %4
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %103
45: ; preds = %41
%46 = load i32, i32* %5
%47 = srem i32 %46, 16
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %59
49: ; preds = %45
%50 = load i32, i32* %5
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %52, %49
%56 = load i32, i32* %5
%57 = load i32, i32* %5
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %56, i32 %57)
br label %59
59: ; preds = %55, %45
%60 = load i8*, i8** %8
%61 = load i32, i32* %5
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %65)
%67 = load i8*, i8** %8
%68 = load i32, i32* %5
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = icmp slt i32 %72, 32
br i1 %73, label %82, label %74
74: ; preds = %59
%75 = load i8*, i8** %8
%76 = load i32, i32* %5
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %75, i64 %77
%79 = load i8, i8* %78
%80 = zext i8 %79 to i32
%81 = icmp sgt i32 %80, 126
br i1 %81, label %82, label %87
82: ; preds = %74, %59
%83 = load i32, i32* %5
%84 = srem i32 %83, 16
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 %85
store i8 46, i8* %86
br label %97
87: ; preds = %74
%88 = load i8*, i8** %8
%89 = load i32, i32* %5
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i8, i8* %88, i64 %90
%92 = load i8, i8* %91
%93 = load i32, i32* %5
%94 = srem i32 %93, 16
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 %95
store i8 %92, i8* %96
br label %97
97: ; preds = %87, %82
%98 = load i32, i32* %5
%99 = srem i32 %98, 16
%100 = add nsw i32 %99, 1
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 %101
store i8 0, i8* %102
br label %114
103: ; preds = %41
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%105 = load i32, i32* %5
%106 = srem i32 %105, 16
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 %107
store i8 46, i8* %108
%109 = load i32, i32* %5
%110 = srem i32 %109, 16
%111 = add nsw i32 %110, 1
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 %112
store i8 0, i8* %113
br label %114
114: ; preds = %103, %97
br label %115
115: ; preds = %114
%116 = load i32, i32* %5
%117 = add nsw i32 %116, 1
store i32 %117, i32* %5
br label %27
118: ; preds = %27
%119 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %119)
br label %121
121: ; preds = %118, %11
ret void
}

LLVM IR (-O2):
@.str.3 = [7 x i8] c" |%s|\0A\00"
@.str.4 = [15 x i8] c" (%5d) %08x \00"
@.str.5 = [6 x i8] c" %02x\00"
@.str.6 = [4 x i8] c" \00"
@.str.7 = [8 x i8] c" |%s|\0A\00"
@str = [90 x i8] c" Address Hexadecimal values Printable \00"
@str.8 = [90 x i8] c" ---------------- ------------------------------------------------ ------------------\00"
define void @hexdump(i8* nocapture %0, i32 %1) {
%3 = alloca [17 x i8]
%4 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %1, 1
br i1 %5, label %68, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([90 x i8], [90 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([90 x i8], [90 x i8]* @str.8, i64 0, i64 0))
%9 = and i32 %1, 15
%10 = icmp eq i32 %9, 0
%11 = add nuw i32 %1, 16
%12 = and i32 %11, -16
%13 = select i1 %10, i32 %1, i32 %12
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %66
15: ; preds = %6
%16 = zext i32 %1 to i64
%17 = zext i32 %13 to i64
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 0)
%19 = load i8, i8* %0
%20 = zext i8 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %20)
%22 = load i8, i8* %0
%23 = add i8 %22, -127
%24 = icmp ult i8 %23, -95
%25 = select i1 %24, i8 46, i8 %22
store i8 %25, i8* %4
%26 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 1
store i8 0, i8* %26
%27 = icmp eq i32 %13, 1
br i1 %27, label %66, label %28
28: ; preds = %15, %59
%29 = phi i64 [ %64, %59 ], [ 1, %15 ]
%30 = trunc i64 %29 to i32
%31 = and i32 %30, 7
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 @putchar(i32 32)
br label %35
35: ; preds = %33, %28
%36 = icmp ult i64 %29, %16
br i1 %36, label %37, label %54
37: ; preds = %35
%38 = and i32 %30, 15
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %30, i32 %30)
br label %43
43: ; preds = %40, %37
%44 = getelementptr inbounds i8, i8* %0, i64 %29
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %46)
%48 = load i8, i8* %44
%49 = add i8 %48, -127
%50 = icmp ult i8 %49, -95
%51 = zext i32 %38 to i64
%52 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %51
%53 = select i1 %50, i8 46, i8 %48
store i8 %53, i8* %52
br label %59
54: ; preds = %35
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%56 = and i32 %30, 15
%57 = zext i32 %56 to i64
%58 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %57
store i8 46, i8* %58
br label %59
59: ; preds = %43, %54
%60 = phi i32 [ %38, %43 ], [ %56, %54 ]
%61 = add nuw nsw i32 %60, 1
%62 = zext i32 %61 to i64
%63 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %62
store i8 0, i8* %63
%64 = add nuw nsw i64 %29, 1
%65 = icmp eq i64 %64, %17
br i1 %65, label %66, label %28
66: ; preds = %59, %15, %6
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %4)
br label %68
68: ; preds = %2, %66
ret void
}