#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void hexdump(const char *desc, const void *addr, unsigned int len) {
  unsigned int i;
  char buff[17] = "";
  uint8_t *pc = (uint8_t *)addr;
  if (desc != NULL)
    printf("%s:\n", desc);
  if (len == 0) {
    printf("  ZERO LENGTH\n");
    return;
  }
  for (i = 0; i < len; i++) {
    if ((i % 16) == 0) {
      if (i != 0)
        printf("  %s\n", buff);
      printf("  %04x ", i);
    }
    printf(" %02x", (unsigned int)pc[i]);
    if ((pc[i] < 0x20) || (pc[i] > 0x7e))
      buff[i % 16] = '.';
    else
      buff[i % 16] = (char)pc[i];
    buff[(i % 16) + 1] = '\0';
  }
  while ((i % 16) != 0) {
    printf("   ");
    i++;
  }
  printf("  %s\n", buff);
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1168 <hexdump+0x48>
mov    -0x8(%rbp),%rsi
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1185 <hexdump+0x65>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1298 <hexdump+0x178>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1256 <hexdump+0x136>
mov    -0x18(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    11d4 <hexdump+0xb4>
cmpl   $0x0,-0x18(%rbp)
je     11c3 <hexdump+0xa3>
lea    -0x30(%rbp),%rsi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    (%rax,%rcx,4),%esi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
mov    -0x18(%rbp),%ecx
cmpl   $0x20,(%rax,%rcx,4)
jl     120e <hexdump+0xee>
mov    -0x38(%rbp),%rax
mov    -0x18(%rbp),%ecx
cmpl   $0x7e,(%rax,%rcx,4)
jle    1220 <hexdump+0x100>
mov    -0x18(%rbp),%eax
and    $0xf,%eax
mov    %eax,%eax
movb   $0x2e,-0x30(%rbp,%rax,1)
jmp    1238 <hexdump+0x118>
mov    -0x38(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
mov    %al,%cl
mov    -0x18(%rbp),%eax
and    $0xf,%eax
mov    %eax,%eax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
and    $0xf,%eax
add    $0x1,%eax
mov    %eax,%eax
movb   $0x0,-0x30(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118c <hexdump+0x6c>
jmp    125b <hexdump+0x13b>
mov    -0x18(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
je     1286 <hexdump+0x166>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    125b <hexdump+0x13b>
lea    -0x30(%rbp),%rsi
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x20(%rsp)
test   %rdi,%rdi
je     1156 <hexdump+0x36>
mov    %rdi,%rsi
lea    0xeb1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
je     121c <hexdump+0xfc>
lea    0xea6(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%esi
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xffffffa1,%ecx
mov    $0x2e,%r12d
cmovb  %r12d,%eax
mov    %al,0x10(%rsp)
movb   $0x0,0x11(%rsp)
mov    $0x1,%r15d
cmp    $0x1,%ebp
je     123d <hexdump+0x11d>
mov    %ebp,0xc(%rsp)
mov    %ebp,%r15d
mov    $0x1,%ebp
lea    0xe58(%rip),%r14
jmp    11ee <hexdump+0xce>
nopl   (%rax)
mov    (%rbx,%rbp,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx,%rbp,4),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xffffffa1,%ecx
cmovb  %r12d,%eax
mov    %al,0x10(%rsp,%r13,1)
movb   $0x0,0x11(%rsp,%r13,1)
add    $0x1,%rbp
cmp    %rbp,%r15
je     1236 <hexdump+0x116>
mov    %rbp,%r13
and    $0xf,%r13
jne    11c0 <hexdump+0xa0>
lea    0xe07(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdfa(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c0 <hexdump+0xa0>
lea    0xdfa(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
testb  $0xf,0xc(%rsp)
je     1266 <hexdump+0x146>
add    $0x1,%r15d
lea    0xdd1(%rip),%rbx
mov    %r15d,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
test   $0xf,%r15b
mov    %ebp,%r15d
jne    1250 <hexdump+0x130>
lea    0xd98(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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