#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 */
scalar_t__ isprint(unsigned char const);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
void HexDump(const unsigned char *p, int len) {
  int o = 0;
  int f;
  char buff[17] = {0};
  while (o < len) {
    strcpy(buff, "                ");
    printf("%4.4X:  ", o);
    for (f = 0; f < 16; f++) {
      if (o < len) {
        printf(" %2.2X", p[o]);
      } else {
        printf(" **");
      }
      if (isprint(p[o])) {
        buff[f] = p[o];
      } else {
        buff[f] = '.';
      }
      o++;
    }
    printf("   %s\n", buff);
  }
}


x86 assembly (clang, -O0):
<HexDump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1247 <HexDump+0x107>
lea    -0x30(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%esi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    1230 <HexDump+0xf0>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11cf <HexDump+0x8f>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11dd <HexDump+0x9d>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
je     1210 <HexDump+0xd0>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
jmp    1219 <HexDump+0xd9>
movslq -0x14(%rbp),%rax
movb   $0x2e,-0x30(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119a <HexDump+0x5a>
lea    -0x30(%rbp),%rsi
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1166 <HexDump+0x26>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HexDump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x20(%rsp)
mov    %esi,0xc(%rsp)
test   %esi,%esi
jle    120c <HexDump+0xdc>
mov    %rdi,%rbx
mov    0xc(%rsp),%r15d
lea    0x10(%rsp),%rbp
lea    0xeb6(%rip),%r12
xor    %r14d,%r14d
jmp    1190 <HexDump+0x60>
add    %r13d,%r14d
lea    0xeab(%rip),%rdi
lea    0x10(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    0xc(%rsp),%r14d
jge    120c <HexDump+0xdc>
mov    %rbp,%rdi
lea    0xe66(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xe6b(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movslq %r14d,%rbp
xor    %r13d,%r13d
jmp    11d7 <HexDump+0xa7>
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%rbp,1),%eax
mov    %al,0x10(%rsp,%r13,1)
add    $0x1,%rbp
add    $0x1,%r13
cmp    $0x10,%r13
je     1170 <HexDump+0x40>
cmp    %r15,%rbp
jge    11f0 <HexDump+0xc0>
movzbl (%rbx,%rbp,1),%esi
lea    0xe33(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11fa <HexDump+0xca>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%rbx,%rbp,1),%edi
call   1050 <isprint@plt>
test   %rax,%rax
jne    11c0 <HexDump+0x90>
mov    $0x2e,%al
jmp    11c4 <HexDump+0x94>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c" \00"
@.str.1 = [9 x i8] c"%4.4X: \00"
@.str.2 = [7 x i8] c" %2.2X\00"
@.str.3 = [4 x i8] c" **\00"
@.str.4 = [7 x i8] c" %s\0A\00"
define void @HexDump(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [17 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%8 = bitcast [17 x i8]* %7 to i8*
br label %9
9: ; preds = %62, %2
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %65
13: ; preds = %9
%14 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %5
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %16)
store i32 0, i32* %6
br label %18
18: ; preds = %59, %13
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 16
br i1 %20, label %21, label %62
21: ; preds = %18
%22 = load i32, i32* %5
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %21
%26 = load i8*, i8** %3
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %35
33: ; preds = %21
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %33, %25
%36 = load i8*, i8** %3
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = call i64 @isprint(i8 zeroext %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %52
43: ; preds = %35
%44 = load i8*, i8** %3
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 %50
store i8 %48, i8* %51
br label %56
52: ; preds = %35
%53 = load i32, i32* %6
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 %54
store i8 46, i8* %55
br label %56
56: ; preds = %52, %43
%57 = load i32, i32* %5
%58 = add nsw i32 %57, 1
store i32 %58, i32* %5
br label %59
59: ; preds = %56
%60 = load i32, i32* %6
%61 = add nsw i32 %60, 1
store i32 %61, i32* %6
br label %18
62: ; preds = %18
%63 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %63)
br label %9
65: ; preds = %9
ret void
}

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