#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 */
typedef char uint8_t;
typedef int /*<<< orphan*/ Dump;
typedef int /*<<< orphan*/ Ascii;

/* Variables and functions */
scalar_t__ isprint(char const);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, char const *, char *, char *);
extern void utilHexDump(const void *pBuffer, const size_t TotalBytes) {
  const uint8_t *pByte = pBuffer;
  const char *pCurrent = pBuffer;
  uint8_t Dump[16 * 3 + 1];
  uint8_t Ascii[16 + 1];
  uint8_t *pDump = Dump;
  uint8_t *pAscii = Ascii;
  size_t Bytes;
  for (Bytes = 0; Bytes <= TotalBytes; pByte++, Bytes++) {
    if ((Bytes % 16) == 0 || Bytes == TotalBytes) {
      if (Bytes != 0) {
        printf("%p: %s|%.16s|\n", pCurrent, Dump, Ascii);
        pCurrent += 16;
      }
      if (Bytes == TotalBytes)
        return;
      pDump = Dump;
      pAscii = Ascii;
      memset(Dump, ' ', sizeof(Dump) - 1);
      Dump[sizeof(Dump) - 1] = 0;
      memset(Ascii, ' ', sizeof(Ascii) - 1);
      Ascii[sizeof(Ascii) - 1] = 0;
    }
    const uint8_t Byte = *pByte;
    *pDump++ = "0123456789ABCDEF"[(Byte >> 4) & 0xF];
    *pDump++ = "0123456789ABCDEF"[(Byte >> 0) & 0xF];
    *pDump++ = ' ';
    *pAscii++ = isprint(Byte) ? Byte : '.';
  }
}


x86 assembly (clang, -O0):
<utilHexDump>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
movq   $0x0,-0x98(%rbp)
mov    -0x98(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     1337 <utilHexDump+0x207>
mov    -0x98(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
je     11ab <utilHexDump+0x7b>
mov    -0x98(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1237 <utilHexDump+0x107>
cmpq   $0x0,-0x98(%rbp)
je     11dd <utilHexDump+0xad>
mov    -0x20(%rbp),%rsi
lea    -0x60(%rbp),%rdx
lea    -0x80(%rbp),%rcx
lea    0xe34(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x20(%rbp)
mov    -0x98(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11f3 <utilHexDump+0xc3>
jmp    1337 <utilHexDump+0x207>
lea    -0x60(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x20,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
movb   $0x0,-0x30(%rbp)
lea    -0x80(%rbp),%rdi
mov    $0x20,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
movb   $0x0,-0x70(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x99(%rbp)
movsbl -0x99(%rbp),%eax
sar    $0x4,%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xdb5(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x88(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x88(%rbp)
mov    %cl,(%rax)
movsbl -0x99(%rbp),%eax
sar    $0x0,%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xd84(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x88(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x88(%rbp)
mov    %cl,(%rax)
mov    -0x88(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x88(%rbp)
movb   $0x20,(%rax)
movsbl -0x99(%rbp),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     12e5 <utilHexDump+0x1b5>
movsbl -0x99(%rbp),%eax
mov    %eax,-0xa0(%rbp)
jmp    12f5 <utilHexDump+0x1c5>
mov    $0x2e,%eax
mov    %eax,-0xa0(%rbp)
jmp    12f5 <utilHexDump+0x1c5>
mov    -0xa0(%rbp),%eax
mov    %al,%cl
mov    -0x90(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x90(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x98(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x98(%rbp)
jmp    1174 <utilHexDump+0x44>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utilHexDump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0x30(%rsp),%r12
lea    0x10(%rsp),%r14
xor    %r15d,%r15d
mov    %rdi,0x8(%rsp)
jmp    11be <utilHexDump+0x8e>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
movsbl (%rax,%r15,1),%r13d
movzbl %r13b,%eax
shr    $0x4,%rax
lea    0xe96(%rip),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %al,(%r12)
mov    %r13d,%eax
and    $0xf,%eax
movzbl (%rax,%rcx,1),%eax
mov    %al,0x1(%r12)
movb   $0x20,0x2(%r12)
add    $0x3,%r12
mov    %r13d,%edi
call   1050 <isprint@plt>
test   %rax,%rax
mov    $0x2e,%eax
cmove  %eax,%r13d
mov    %r13b,(%r14)
add    $0x1,%r14
add    $0x1,%r15
cmp    %rbx,%r15
ja     1232 <utilHexDump+0x102>
cmp    %r15,%rbx
je     11ce <utilHexDump+0x9e>
mov    %r15d,%eax
and    $0xf,%eax
test   %rax,%rax
jne    1160 <utilHexDump+0x30>
test   %r15,%r15
je     11f0 <utilHexDump+0xc0>
lea    0xe26(%rip),%rdi
mov    %rbp,%rsi
lea    0x30(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1030 <printf@plt>
add    $0x10,%rbp
cmp    %r15,%rbx
je     1232 <utilHexDump+0x102>
lea    0x30(%rsp),%r12
mov    %r12,%rdi
mov    $0x20,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
movb   $0x0,0x60(%rsp)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x20,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
movb   $0x0,0x20(%rsp)
jmp    1160 <utilHexDump+0x30>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [15 x i8] c"%p: %s|%.16s|\0A\00"
@.str.1 = [17 x i8] c"0123456789ABCDEF\00"
define void @utilHexDump(i8* %0, i64 %1) {
%3 = alloca [49 x i8]
%4 = alloca [17 x i8]
%5 = getelementptr inbounds [49 x i8], [49 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [49 x i8], [49 x i8]* %3, i64 0, i64 48
%8 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 16
br label %9
9: ; preds = %2, %29
%10 = phi i8* [ %0, %2 ], [ %50, %29 ]
%11 = phi i64 [ 0, %2 ], [ %51, %29 ]
%12 = phi i8* [ %6, %2 ], [ %49, %29 ]
%13 = phi i8* [ %5, %2 ], [ %45, %29 ]
%14 = phi i8* [ %0, %2 ], [ %30, %29 ]
%15 = and i64 %11, 15
%16 = icmp eq i64 %15, 0
%17 = icmp eq i64 %11, %1
%18 = or i1 %17, %16
br i1 %18, label %19, label %29
19: ; preds = %9
%20 = icmp eq i64 %11, 0
br i1 %20, label %24, label %21
21: ; preds = %19
%22 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %5, i8* %6)
%23 = getelementptr inbounds i8, i8* %14, i64 16
br label %24
24: ; preds = %21, %19
%25 = phi i8* [ %23, %21 ], [ %14, %19 ]
br i1 %17, label %53, label %26
26: ; preds = %24
%27 = call i32 @memset(i8* %5, i8 signext 32, i32 48)
store i8 0, i8* %7
%28 = call i32 @memset(i8* %6, i8 signext 32, i32 16)
store i8 0, i8* %8
br label %29
29: ; preds = %9, %26
%30 = phi i8* [ %25, %26 ], [ %14, %9 ]
%31 = phi i8* [ %5, %26 ], [ %13, %9 ]
%32 = phi i8* [ %6, %26 ], [ %12, %9 ]
%33 = load i8, i8* %10
%34 = zext i8 %33 to i32
%35 = lshr i32 %34, 4
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds [17 x i8], [17 x i8]* @.str.1, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = getelementptr inbounds i8, i8* %31, i64 1
store i8 %38, i8* %31
%40 = and i32 %34, 15
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds [17 x i8], [17 x i8]* @.str.1, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = getelementptr inbounds i8, i8* %31, i64 2
store i8 %43, i8* %39
%45 = getelementptr inbounds i8, i8* %31, i64 3
store i8 32, i8* %44
%46 = call i64 @isprint(i8 signext %33)
%47 = icmp eq i64 %46, 0
%48 = select i1 %47, i8 46, i8 %33
%49 = getelementptr inbounds i8, i8* %32, i64 1
store i8 %48, i8* %32
%50 = getelementptr inbounds i8, i8* %10, i64 1
%51 = add i64 %11, 1
%52 = icmp ugt i64 %51, %1
br i1 %52, label %53, label %9
53: ; preds = %29, %24
ret void
}