#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
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:\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)
        fprintf(stderr, "  %s\n", buff);
      fprintf(stderr, "  %04x ", i);
    }
    fprintf(stderr, " %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) {
    fprintf(stderr, "   ");
    i++;
  }
  fprintf(stderr, "  %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     1158 <hexDump+0x38>
mov    -0x8(%rbp),%rsi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1175 <hexDump+0x55>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12fa <hexDump+0x1da>
cmpl   $0x0,-0x14(%rbp)
jge    1195 <hexDump+0x75>
mov    -0x14(%rbp),%esi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12fa <hexDump+0x1da>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12a1 <hexDump+0x181>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11fb <hexDump+0xdb>
cmpl   $0x0,-0x18(%rbp)
je     11e1 <hexDump+0xc1>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     1248 <hexDump+0x128>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jle    1260 <hexDump+0x140>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movb   $0x2e,-0x30(%rbp,%rax,1)
jmp    127d <hexDump+0x15d>
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    119c <hexDump+0x7c>
jmp    12a6 <hexDump+0x186>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12df <hexDump+0x1bf>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
lea    0xd75(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12a6 <hexDump+0x186>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xd38(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@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     1159 <hexDump+0x29>
mov    %rdi,%rsi
lea    0xeae(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
je     124e <hexDump+0x11e>
js     1268 <hexDump+0x138>
mov    0x2e72(%rip),%r12
mov    (%r12),%edi
lea    0xea9(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r12),%edi
movzbl (%rbx),%edx
lea    0xe9a(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
movzbl (%rbx),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
mov    $0x2e,%ecx
cmovb  %ecx,%eax
mov    %al,0x10(%rsp)
movb   $0x0,0x11(%rsp)
mov    $0x1,%r13d
cmp    $0x1,%ebp
je     128d <hexDump+0x15d>
mov    %ebp,0xc(%rsp)
mov    %ebp,%r13d
mov    $0x1,%ebp
lea    0xe57(%rip),%r15
jmp    1218 <hexDump+0xe8>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12),%edi
movzbl (%rbx,%rbp,1),%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
movzbl (%rbx,%rbp,1),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
mov    $0x2e,%ecx
cmovb  %ecx,%eax
mov    %al,0x10(%rsp,%r14,1)
movb   $0x0,0x11(%rsp,%r14,1)
add    $0x1,%rbp
cmp    %rbp,%r13
je     1286 <hexDump+0x156>
mov    %rbp,%r14
and    $0xf,%r14
jne    11e0 <hexDump+0xb0>
mov    (%r12),%edi
lea    0xdf0(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r12),%edi
lea    0xddf(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11e0 <hexDump+0xb0>
lea    0xddf(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
lea    0xd96(%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     12ba <hexDump+0x18a>
add    $0x1,%r13d
lea    0xd98(%rip),%rbx
mov    %r13d,%ebp
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%ebp
test   $0xf,%r13b
mov    %ebp,%r13d
jne    12a0 <hexDump+0x170>
mov    (%r12),%edi
lea    0xd57(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1050 <fprintf@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"
@stderr = global i32 0
@.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 %109
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 %109
27: ; preds = %21
store i32 0, i32* %7
br label %28
28: ; preds = %92, %27
%29 = load i32, i32* %7
%30 = load i32, i32* %6
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %95
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 %47
36: ; preds = %32
%37 = load i32, i32* %7
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %39, %36
%44 = load i32, i32* @stderr
%45 = load i32, i32* %7
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %43, %32
%48 = load i32, i32* @stderr
%49 = load i8*, i8** %9
%50 = load i32, i32* %7
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %54)
%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 = icmp slt i32 %61, 32
br i1 %62, label %71, label %63
63: ; preds = %47
%64 = load i8*, i8** %9
%65 = load i32, i32* %7
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
%70 = icmp sgt i32 %69, 126
br i1 %70, label %71, label %76
71: ; preds = %63, %47
%72 = load i32, i32* %7
%73 = srem i32 %72, 16
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %74
store i8 46, i8* %75
br label %86
76: ; preds = %63
%77 = load i8*, i8** %9
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
%81 = load i8, i8* %80
%82 = load i32, i32* %7
%83 = srem i32 %82, 16
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %84
store i8 %81, i8* %85
br label %86
86: ; preds = %76, %71
%87 = load i32, i32* %7
%88 = srem i32 %87, 16
%89 = add nsw i32 %88, 1
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %90
store i8 0, i8* %91
br label %92
92: ; preds = %86
%93 = load i32, i32* %7
%94 = add nsw i32 %93, 1
store i32 %94, i32* %7
br label %28
95: ; preds = %28
br label %96
96: ; preds = %100, %95
%97 = load i32, i32* %7
%98 = srem i32 %97, 16
%99 = icmp ne i32 %98, 0
br i1 %99, label %100, label %105
100: ; preds = %96
%101 = load i32, i32* @stderr
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%103 = load i32, i32* %7
%104 = add nsw i32 %103, 1
store i32 %104, i32* %7
br label %96
105: ; preds = %96
%106 = load i32, i32* @stderr
%107 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %107)
br label %109
109: ; preds = %105, %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"
@stderr = global i32 0
@.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 %73
13: ; preds = %9
%14 = icmp slt i32 %2, 0
br i1 %14, label %29, label %15
15: ; preds = %13
%16 = zext i32 %2 to i64
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 0)
%19 = load i32, i32* @stderr
%20 = load i8, i8* %1
%21 = zext i8 %20 to i32
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* 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 = %13
%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 %73
31: ; preds = %46
%32 = and i32 %2, 15
%33 = icmp eq i32 %32, 0
br i1 %33, label %70, label %34
34: ; preds = %15, %31
%35 = phi i32 [ 1, %15 ], [ %2, %31 ]
br label %63
36: ; preds = %15, %46
%37 = phi i64 [ %61, %46 ], [ 1, %15 ]
%38 = trunc i64 %37 to i32
%39 = and i32 %38, 15
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %36
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %38)
br label %46
46: ; preds = %41, %36
%47 = load i32, i32* @stderr
%48 = getelementptr inbounds i8, i8* %1, i64 %37
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %50)
%52 = load i8, i8* %48
%53 = add i8 %52, -127
%54 = icmp ult i8 %53, -95
%55 = zext i32 %39 to i64
%56 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 %55
%57 = select i1 %54, i8 46, i8 %52
store i8 %57, i8* %56
%58 = add nuw nsw i32 %39, 1
%59 = zext i32 %58 to i64
%60 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 %59
store i8 0, i8* %60
%61 = add nuw nsw i64 %37, 1
%62 = icmp eq i64 %61, %16
br i1 %62, label %31, label %36
63: ; preds = %34, %63
%64 = phi i32 [ %67, %63 ], [ %35, %34 ]
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%67 = add nuw nsw i32 %64, 1
%68 = and i32 %67, 15
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %63
70: ; preds = %63, %31
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %5)
br label %73
73: ; preds = %70, %29, %11
ret void
}