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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void hexdump(char *desc, void *addr, int len) {
  int i;
  unsigned char buff[17];
  unsigned char *pc = (unsigned char *)addr;
  if (desc != NULL)
    printf("%s (0x%08x):\n", desc, (uint32_t)addr);
  if (len == 0) {
    printf("  ZERO LENGTH\n");
    return;
  }
  if (len < 0) {
    printf("  NEGATIVE LENGTH: %i\n", len);
    return;
  }
  for (i = 0; i < len; i++) {
    if ((i % 16) == 0) {
      if (i != 0)
        printf("  %s\n", buff);
      printf("  %04x ", 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';
  }
  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)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     114e <hexdump+0x3e>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    116b <hexdump+0x5b>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12c3 <hexdump+0x1b3>
cmpl   $0x0,-0x14(%rbp)
jge    118b <hexdump+0x7b>
mov    -0x14(%rbp),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12c3 <hexdump+0x1b3>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    127c <hexdump+0x16c>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11df <hexdump+0xcf>
cmpl   $0x0,-0x18(%rbp)
je     11ce <hexdump+0xbe>
lea    -0x30(%rbp),%rsi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     1223 <hexdump+0x113>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jle    123b <hexdump+0x12b>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movb   $0x2e,-0x30(%rbp,%rax,1)
jmp    1258 <hexdump+0x148>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%eax
mov    $0x10,%esi
cltd
idiv   %esi
movslq %edx,%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
movslq %edx,%rax
movb   $0x0,-0x30(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1192 <hexdump+0x82>
jmp    1281 <hexdump+0x171>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12b1 <hexdump+0x1a1>
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1281 <hexdump+0x171>
lea    -0x30(%rbp),%rsi
lea    0xd78(%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
test   %rdi,%rdi
je     114b <hexdump+0x2b>
mov    %rdi,%rsi
lea    0xebe(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
je     121e <hexdump+0xfe>
js     1238 <hexdump+0x118>
lea    0xecb(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%rbx),%esi
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%rbx),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
mov    $0x2e,%r13d
cmovb  %r13d,%eax
mov    %al,0x10(%rsp)
movb   $0x0,0x11(%rsp)
mov    $0x1,%r12d
cmp    $0x1,%ebp
je     125d <hexdump+0x13d>
mov    %ebp,0xc(%rsp)
mov    %ebp,%r12d
mov    $0x1,%ebp
lea    0xe7b(%rip),%r15
jmp    11f0 <hexdump+0xd0>
nopw   0x0(%rax,%rax,1)
movzbl (%rbx,%rbp,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%rbx,%rbp,1),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
cmovb  %r13d,%eax
mov    %al,0x10(%rsp,%r14,1)
movb   $0x0,0x11(%rsp,%r14,1)
add    $0x1,%rbp
cmp    %rbp,%r12
je     1256 <hexdump+0x136>
mov    %rbp,%r14
and    $0xf,%r14
jne    11c0 <hexdump+0xa0>
lea    0xe25(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe18(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c0 <hexdump+0xa0>
lea    0xe18(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
lea    0xdcf(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
testb  $0xf,0xc(%rsp)
je     1286 <hexdump+0x166>
add    $0x1,%r12d
lea    0xdd1(%rip),%rbx
mov    %r12d,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
test   $0xf,%r12b
mov    %ebp,%r12d
jne    1270 <hexdump+0x150>
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 = [14 x i8] c"%s (0x%08x):\0A\00"
@.str.1 = [15 x i8] c" ZERO LENGTH\0A\00"
@.str.2 = [23 x i8] c" NEGATIVE LENGTH: %i\0A\00"
@.str.3 = [6 x i8] c" %s\0A\00"
@.str.4 = [8 x i8] c" %04x \00"
@.str.5 = [6 x i8] c" %02x\00"
@.str.6 = [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 i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %5
store i8* %10, i8** %9
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = ptrtoint i8* %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %16)
br label %18
18: ; preds = %13, %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 %106
23: ; preds = %18
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %6
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %106
29: ; preds = %23
store i32 0, i32* %7
br label %30
30: ; preds = %91, %29
%31 = load i32, i32* %7
%32 = load i32, i32* %6
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %94
34: ; preds = %30
%35 = load i32, i32* %7
%36 = srem i32 %35, 16
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %47
38: ; preds = %34
%39 = load i32, i32* %7
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %41, %38
%45 = load i32, i32* %7
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %44, %34
%48 = load i8*, i8** %9
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %53)
%55 = load i8*, i8** %9
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = icmp slt i32 %60, 32
br i1 %61, label %70, label %62
62: ; preds = %47
%63 = load i8*, i8** %9
%64 = load i32, i32* %7
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
%69 = icmp sgt i32 %68, 126
br i1 %69, label %70, label %75
70: ; preds = %62, %47
%71 = load i32, i32* %7
%72 = srem i32 %71, 16
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %73
store i8 46, i8* %74
br label %85
75: ; preds = %62
%76 = load i8*, i8** %9
%77 = load i32, i32* %7
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %76, i64 %78
%80 = load i8, i8* %79
%81 = load i32, i32* %7
%82 = srem i32 %81, 16
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %83
store i8 %80, i8* %84
br label %85
85: ; preds = %75, %70
%86 = load i32, i32* %7
%87 = srem i32 %86, 16
%88 = add nsw i32 %87, 1
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %89
store i8 0, i8* %90
br label %91
91: ; preds = %85
%92 = load i32, i32* %7
%93 = add nsw i32 %92, 1
store i32 %93, i32* %7
br label %30
94: ; preds = %30
br label %95
95: ; preds = %99, %94
%96 = load i32, i32* %7
%97 = srem i32 %96, 16
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %103
99: ; preds = %95
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%101 = load i32, i32* %7
%102 = add nsw i32 %101, 1
store i32 %102, i32* %7
br label %95
103: ; preds = %95
%104 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %104)
br label %106
106: ; preds = %103, %26, %21
ret void
}

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