#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(const void *data, int length) {
  int i, j;
  for (i = 0; i < length; i += 16) {
    printf("%8x | ", i);
    for (j = 0; j < 16; ++j) {
      if (i + j < length) {
        printf("%2.2x ", ((unsigned char *)data)[i + j]);
      } else {
        printf("   ");
      }
    }
    printf("| ");
    for (j = 0; j < 16; ++j) {
      if (i + j < length) {
        unsigned char c = ((unsigned char *)data)[i + j];
        printf("%c", (c >= 32 && c < 127) ? c : '.');
      } else {
        printf(" ");
      }
    }
    printf(" |\n");
  }
}


x86 assembly (clang, -O0):
<HexDump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    126f <HexDump+0x15f>
mov    -0x10(%rbp),%esi
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    11a8 <HexDump+0x98>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1187 <HexDump+0x77>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1195 <HexDump+0x85>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119a <HexDump+0x8a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114a <HexDump+0x3a>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    1253 <HexDump+0x143>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1232 <HexDump+0x122>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
movzbl -0x15(%rbp),%eax
cmp    $0x20,%eax
jl     120f <HexDump+0xff>
movzbl -0x15(%rbp),%eax
cmp    $0x7f,%eax
jge    120f <HexDump+0xff>
movzbl -0x15(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    121c <HexDump+0x10c>
mov    $0x2e,%eax
mov    %eax,-0x1c(%rbp)
jmp    121c <HexDump+0x10c>
mov    -0x1c(%rbp),%esi
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1240 <HexDump+0x130>
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1245 <HexDump+0x135>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11bd <HexDump+0xad>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <HexDump+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HexDump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,0x4(%rsp)
test   %esi,%esi
jle    1244 <HexDump+0x114>
mov    %rdi,%rbx
mov    0x4(%rsp),%r13d
mov    $0x2e,%r15d
lea    0xeb2(%rip),%r14
xor    %r12d,%r12d
jmp    118f <HexDump+0x5f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe9b(%rip),%rdi
call   1040 <puts@plt>
add    $0x10,%r12
add    $0x10,%rbx
cmp    0x4(%rsp),%r12d
jge    1244 <HexDump+0x114>
lea    0xe6a(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebp,%ebp
jmp    11c4 <HexDump+0x94>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    $0x10,%rbp
je     11f0 <HexDump+0xc0>
lea    (%r12,%rbp,1),%rax
cmp    %r13,%rax
jge    11b0 <HexDump+0x80>
movzbl (%rbx,%rbp,1),%esi
lea    0xe2f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11ba <HexDump+0x8a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe0d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebp,%ebp
jmp    1223 <HexDump+0xf3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1030 <putchar@plt>
add    $0x1,%rbp
cmp    $0x10,%rbp
je     1170 <HexDump+0x40>
lea    (%r12,%rbp,1),%rax
mov    $0x20,%edi
cmp    %r13,%rax
jge    1210 <HexDump+0xe0>
movzbl (%rbx,%rbp,1),%eax
lea    -0x20(%rax),%ecx
cmp    $0x5f,%cl
cmovae %r15d,%eax
movzbl %al,%edi
jmp    1210 <HexDump+0xe0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%8x | \00"
@.str.1 = [7 x i8] c"%2.2x \00"
@.str.2 = [4 x i8] c" \00"
@.str.3 = [3 x i8] c"| \00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [2 x i8] c" \00"
@.str.6 = [4 x i8] c" |\0A\00"
define void @HexDump(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %8
8: ; preds = %81, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %84
12: ; preds = %8
%13 = load i32, i32* %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 0, i32* %6
br label %15
15: ; preds = %37, %12
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 16
br i1 %17, label %18, label %40
18: ; preds = %15
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = add nsw i32 %19, %20
%22 = load i32, i32* %4
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %34
24: ; preds = %18
%25 = load i8*, i8** %3
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = add nsw i32 %26, %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %25, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %32)
br label %36
34: ; preds = %18
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %24
br label %37
37: ; preds = %36
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %15
40: ; preds = %15
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %42
42: ; preds = %76, %40
%43 = load i32, i32* %6
%44 = icmp slt i32 %43, 16
br i1 %44, label %45, label %79
45: ; preds = %42
%46 = load i32, i32* %5
%47 = load i32, i32* %6
%48 = add nsw i32 %46, %47
%49 = load i32, i32* %4
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %73
51: ; preds = %45
%52 = load i8*, i8** %3
%53 = load i32, i32* %5
%54 = load i32, i32* %6
%55 = add nsw i32 %53, %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %52, i64 %56
%58 = load i8, i8* %57
store i8 %58, i8* %7
%59 = load i8, i8* %7
%60 = zext i8 %59 to i32
%61 = icmp sge i32 %60, 32
br i1 %61, label %62, label %69
62: ; preds = %51
%63 = load i8, i8* %7
%64 = zext i8 %63 to i32
%65 = icmp slt i32 %64, 127
br i1 %65, label %66, label %69
66: ; preds = %62
%67 = load i8, i8* %7
%68 = zext i8 %67 to i32
br label %70
69: ; preds = %62, %51
br label %70
70: ; preds = %69, %66
%71 = phi i32 [ %68, %66 ], [ 46, %69 ]
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %71)
br label %75
73: ; preds = %45
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %75
75: ; preds = %73, %70
br label %76
76: ; preds = %75
%77 = load i32, i32* %6
%78 = add nsw i32 %77, 1
store i32 %78, i32* %6
br label %42
79: ; preds = %42
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %81
81: ; preds = %79
%82 = load i32, i32* %5
%83 = add nsw i32 %82, 16
store i32 %83, i32* %5
br label %8
84: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%8x | \00"
@.str.1 = [7 x i8] c"%2.2x \00"
@.str.2 = [4 x i8] c" \00"
@.str.3 = [3 x i8] c"| \00"
@str = [3 x i8] c" |\00"
define void @HexDump(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %47
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %42
%7 = phi i64 [ 0, %4 ], [ %44, %42 ]
%8 = trunc i64 %7 to i32
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %6, %21
%11 = phi i64 [ 0, %6 ], [ %22, %21 ]
%12 = add nuw nsw i64 %11, %7
%13 = icmp slt i64 %12, %5
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = getelementptr inbounds i8, i8* %0, i64 %12
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %21
19: ; preds = %10
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %14, %19
%22 = add nuw nsw i64 %11, 1
%23 = icmp eq i64 %22, 16
br i1 %23, label %24, label %10
24: ; preds = %21
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %24, %37
%27 = phi i64 [ 0, %24 ], [ %40, %37 ]
%28 = add nuw nsw i64 %27, %7
%29 = icmp slt i64 %28, %5
br i1 %29, label %30, label %37
30: ; preds = %26
%31 = getelementptr inbounds i8, i8* %0, i64 %28
%32 = load i8, i8* %31
%33 = add i8 %32, -32
%34 = icmp ult i8 %33, 95
%35 = select i1 %34, i8 %32, i8 46
%36 = zext i8 %35 to i32
br label %37
37: ; preds = %26, %30
%38 = phi i32 [ %36, %30 ], [ 32, %26 ]
%39 = tail call i32 @putchar(i32 %38)
%40 = add nuw nsw i64 %27, 1
%41 = icmp eq i64 %40, 16
br i1 %41, label %42, label %26
42: ; preds = %37
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%44 = add nuw i64 %7, 16
%45 = trunc i64 %44 to i32
%46 = icmp slt i32 %45, %1
br i1 %46, label %6, label %47
47: ; preds = %42, %2
ret void
}