#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*/ log_debug(char *, ...);
void hexDump(void *addr, int len) {
  int i;
  unsigned char buff[17];
  unsigned char *pc = (unsigned char *)addr;
  (void)buff;
  log_debug("hexDump %p:\n", addr);
  if (len == 0) {
    log_debug("  ZERO LENGTH\n");
    return;
  }
  if (len < 0) {
    log_debug("  NEGATIVE LENGTH: %i\n", len);
    return;
  }
  for (i = 0; i < len; i++) {
    if ((i % 16) == 0) {
      if (i != 0) {
        log_debug("  %s\n", buff);
      }
      log_debug("  %04x ", i);
    }
    log_debug(" %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) {
    log_debug("   ");
    i++;
  }
  log_debug("  %s\n", buff);
}


x86 assembly (clang, -O0):
<hexDump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <log_debug@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1156 <hexDump+0x46>
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <log_debug@plt>
jmp    12ae <hexDump+0x19e>
cmpl   $0x0,-0xc(%rbp)
jge    1176 <hexDump+0x66>
mov    -0xc(%rbp),%esi
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <log_debug@plt>
jmp    12ae <hexDump+0x19e>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1267 <hexDump+0x157>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ca <hexDump+0xba>
cmpl   $0x0,-0x10(%rbp)
je     11b9 <hexDump+0xa9>
lea    -0x30(%rbp),%rsi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <log_debug@plt>
mov    -0x10(%rbp),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <log_debug@plt>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <log_debug@plt>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     120e <hexDump+0xfe>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jle    1226 <hexDump+0x116>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movb   $0x2e,-0x30(%rbp,%rax,1)
jmp    1243 <hexDump+0x133>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%eax
mov    $0x10,%esi
cltd
idiv   %esi
movslq %edx,%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
movslq %edx,%rax
movb   $0x0,-0x30(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117d <hexDump+0x6d>
jmp    126c <hexDump+0x15c>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     129c <hexDump+0x18c>
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1030 <log_debug@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    126c <hexDump+0x15c>
lea    -0x30(%rbp),%rsi
lea    0xd8c(%rip),%rdi
mov    $0x0,%al
call   1030 <log_debug@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    %esi,%ebp
mov    %rdi,%rbx
lea    0xed6(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <log_debug@plt>
test   %ebp,%ebp
je     120e <hexDump+0xfe>
js     122a <hexDump+0x11a>
lea    0xef0(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <log_debug@plt>
movzbl (%rbx),%esi
lea    0xee5(%rip),%rdi
xor    %eax,%eax
call   1030 <log_debug@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     124f <hexDump+0x13f>
mov    %ebp,0xc(%rsp)
mov    %ebp,%r12d
mov    $0x1,%ebp
lea    0xea0(%rip),%r15
jmp    11e0 <hexDump+0xd0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rbx,%rbp,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <log_debug@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     1248 <hexDump+0x138>
mov    %rbp,%r14
and    $0xf,%r14
jne    11b0 <hexDump+0xa0>
lea    0xe43(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1030 <log_debug@plt>
lea    0xe36(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <log_debug@plt>
jmp    11b0 <hexDump+0xa0>
lea    0xdf8(%rip),%rdi
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <log_debug@plt>
lea    0xdeb(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <log_debug@plt>
testb  $0xf,0xc(%rsp)
je     1276 <hexDump+0x166>
add    $0x1,%r12d
lea    0xded(%rip),%rbx
mov    %r12d,%ebp
nopl   (%rax)
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <log_debug@plt>
add    $0x1,%ebp
test   $0xf,%r12b
mov    %ebp,%r12d
jne    1260 <hexDump+0x150>
lea    0xdb6(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1030 <log_debug@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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