#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;
  printf("%p %02x\n", pc, ((char *)pc)[0]);
  printf("%p\n", pc);
  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)
mov    -0x38(%rbp),%rsi
mov    -0x38(%rbp),%rax
movsbl (%rax),%edx
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rsi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x8(%rbp)
je     1179 <hexdump+0x69>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1196 <hexdump+0x86>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ee <hexdump+0x1de>
cmpl   $0x0,-0x14(%rbp)
jge    11b6 <hexdump+0xa6>
mov    -0x14(%rbp),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ee <hexdump+0x1de>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12a7 <hexdump+0x197>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    120a <hexdump+0xfa>
cmpl   $0x0,-0x18(%rbp)
je     11f9 <hexdump+0xe9>
lea    -0x30(%rbp),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe32(%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     124e <hexdump+0x13e>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jle    1266 <hexdump+0x156>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movb   $0x2e,-0x30(%rbp,%rax,1)
jmp    1283 <hexdump+0x173>
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    11bd <hexdump+0xad>
jmp    12ac <hexdump+0x19c>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12dc <hexdump+0x1cc>
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12ac <hexdump+0x19c>
lea    -0x30(%rbp),%rsi
lea    0xd5a(%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,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
movsbl (%rsi),%edx
lea    0xebf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeba(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
test   %rbp,%rbp
je     1171 <hexdump+0x51>
lea    0xea8(%rip),%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14d,%r14d
je     124e <hexdump+0x12e>
js     1268 <hexdump+0x148>
lea    0xeb1(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%rbx),%esi
lea    0xea6(%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,%r14d
je     128e <hexdump+0x16e>
mov    %r14d,0xc(%rsp)
mov    %r14d,%r12d
mov    $0x1,%ebp
lea    0xe5f(%rip),%r15
jmp    1220 <hexdump+0x100>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
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     1287 <hexdump+0x167>
mov    %rbp,%r14
and    $0xf,%r14
jne    11f0 <hexdump+0xd0>
lea    0xe02(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdf5(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f0 <hexdump+0xd0>
lea    0xdf5(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
lea    0xdac(%rip),%rdi
mov    %r14d,%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     12b6 <hexdump+0x196>
add    $0x1,%r12d
lea    0xdad(%rip),%rbx
mov    %r12d,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
test   $0xf,%r12b
mov    %ebp,%r12d
jne    12a0 <hexdump+0x180>
lea    0xd75(%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 = [9 x i8] c"%p %02x\0A\00"
@.str.1 = [4 x i8] c"%p\0A\00"
@.str.2 = [14 x i8] c"%s (0x%08x):\0A\00"
@.str.3 = [15 x i8] c" ZERO LENGTH\0A\00"
@.str.4 = [23 x i8] c" NEGATIVE LENGTH: %i\0A\00"
@.str.5 = [6 x i8] c" %s\0A\00"
@.str.6 = [8 x i8] c" %04x \00"
@.str.7 = [6 x i8] c" %02x\00"
@.str.8 = [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** %9
%12 = load i8*, i8** %9
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %15)
%17 = load i8*, i8** %9
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %4
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %26
21: ; preds = %3
%22 = load i8*, i8** %4
%23 = load i8*, i8** %5
%24 = ptrtoint i8* %23 to i32
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %22, i32 %24)
br label %26
26: ; preds = %21, %3
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %114
31: ; preds = %26
%32 = load i32, i32* %6
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* %6
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %35)
br label %114
37: ; preds = %31
store i32 0, i32* %7
br label %38
38: ; preds = %99, %37
%39 = load i32, i32* %7
%40 = load i32, i32* %6
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %102
42: ; preds = %38
%43 = load i32, i32* %7
%44 = srem i32 %43, 16
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %55
46: ; preds = %42
%47 = load i32, i32* %7
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %49, %46
%53 = load i32, i32* %7
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %52, %42
%56 = load i8*, i8** %9
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %61)
%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 slt i32 %68, 32
br i1 %69, label %78, label %70
70: ; preds = %55
%71 = load i8*, i8** %9
%72 = load i32, i32* %7
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %71, i64 %73
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = icmp sgt i32 %76, 126
br i1 %77, label %78, label %83
78: ; preds = %70, %55
%79 = load i32, i32* %7
%80 = srem i32 %79, 16
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %81
store i8 46, i8* %82
br label %93
83: ; preds = %70
%84 = load i8*, i8** %9
%85 = load i32, i32* %7
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %84, i64 %86
%88 = load i8, i8* %87
%89 = load i32, i32* %7
%90 = srem i32 %89, 16
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %91
store i8 %88, i8* %92
br label %93
93: ; preds = %83, %78
%94 = load i32, i32* %7
%95 = srem i32 %94, 16
%96 = add nsw i32 %95, 1
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %97
store i8 0, i8* %98
br label %99
99: ; preds = %93
%100 = load i32, i32* %7
%101 = add nsw i32 %100, 1
store i32 %101, i32* %7
br label %38
102: ; preds = %38
br label %103
103: ; preds = %107, %102
%104 = load i32, i32* %7
%105 = srem i32 %104, 16
%106 = icmp ne i32 %105, 0
br i1 %106, label %107, label %111
107: ; preds = %103
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%109 = load i32, i32* %7
%110 = add nsw i32 %109, 1
store i32 %110, i32* %7
br label %103
111: ; preds = %103
%112 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %112)
br label %114
114: ; preds = %111, %34, %29
ret void
}

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