#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(char *desc, void *addr, int len) {
  int i;
  unsigned char buff[17];
  unsigned char *pc = (unsigned char *)addr;
  if (desc != 0)
    printf("%s:\n", desc);
  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     1148 <hexDump+0x38>
mov    -0x8(%rbp),%rsi
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1165 <hexDump+0x55>
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12bd <hexDump+0x1ad>
cmpl   $0x0,-0x14(%rbp)
jge    1185 <hexDump+0x75>
mov    -0x14(%rbp),%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12bd <hexDump+0x1ad>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1276 <hexDump+0x166>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11d9 <hexDump+0xc9>
cmpl   $0x0,-0x18(%rbp)
je     11c8 <hexDump+0xb8>
lea    -0x30(%rbp),%rsi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe4d(%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     121d <hexDump+0x10d>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jle    1235 <hexDump+0x125>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movb   $0x2e,-0x30(%rbp,%rax,1)
jmp    1252 <hexDump+0x142>
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    118c <hexDump+0x7c>
jmp    127b <hexDump+0x16b>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12ab <hexDump+0x19b>
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    127b <hexDump+0x16b>
lea    -0x30(%rbp),%rsi
lea    0xd75(%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     1149 <hexDump+0x29>
mov    %rdi,%rsi
lea    0xebe(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
je     121e <hexDump+0xfe>
js     1238 <hexDump+0x118>
lea    0xec4(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%rbx),%esi
lea    0xeb9(%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    0xe74(%rip),%r15
jmp    11f0 <hexDump+0xd0>
nopl   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    0xe1c(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe0f(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c0 <hexDump+0xa0>
lea    0xe0f(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
lea    0xdc6(%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    0xdc8(%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    0xd8f(%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 = [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 %16
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %3
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %104
21: ; preds = %16
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %6
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %104
27: ; preds = %21
store i32 0, i32* %7
br label %28
28: ; preds = %89, %27
%29 = load i32, i32* %7
%30 = load i32, i32* %6
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %92
32: ; preds = %28
%33 = load i32, i32* %7
%34 = srem i32 %33, 16
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %45
36: ; preds = %32
%37 = load i32, i32* %7
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %39, %36
%43 = load i32, i32* %7
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %42, %32
%46 = load i8*, i8** %9
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %51)
%53 = load i8*, i8** %9
%54 = load i32, i32* %7
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = icmp slt i32 %58, 32
br i1 %59, label %68, label %60
60: ; preds = %45
%61 = load i8*, i8** %9
%62 = load i32, i32* %7
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = icmp sgt i32 %66, 126
br i1 %67, label %68, label %73
68: ; preds = %60, %45
%69 = load i32, i32* %7
%70 = srem i32 %69, 16
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %71
store i8 46, i8* %72
br label %83
73: ; preds = %60
%74 = load i8*, i8** %9
%75 = load i32, i32* %7
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %74, i64 %76
%78 = load i8, i8* %77
%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 %78, i8* %82
br label %83
83: ; preds = %73, %68
%84 = load i32, i32* %7
%85 = srem i32 %84, 16
%86 = add nsw i32 %85, 1
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %87
store i8 0, i8* %88
br label %89
89: ; preds = %83
%90 = load i32, i32* %7
%91 = add nsw i32 %90, 1
store i32 %91, i32* %7
br label %28
92: ; preds = %28
br label %93
93: ; preds = %97, %92
%94 = load i32, i32* %7
%95 = srem i32 %94, 16
%96 = icmp ne i32 %95, 0
br i1 %96, label %97, label %101
97: ; preds = %93
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%99 = load i32, i32* %7
%100 = add nsw i32 %99, 1
store i32 %100, i32* %7
br label %93
101: ; preds = %93
%102 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %102)
br label %104
104: ; preds = %101, %24, %19
ret void
}

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