#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 *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strlen(char *);
void HEX_DUMP(void *addr, int len) {
  int i;
  char buff[17] = {0};
  unsigned char *pc = (unsigned char *)addr;
  unsigned char desc[1024] = {0};
  printf("VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
  sprintf(buff, "SIZE %d\n", (int)len);
  printf(buff, strlen(buff));
  if (desc != NULL)
    printf("%s:\n", desc);
  for (i = 0; i < len; i++) {
    if ((i % 16) == 0) {
      if (i != 0)
        printf("\t%s\n", buff);
      printf("  %04x ", i);
    }
    printf(" %02x", pc[i]);
    if ((pc[i] < 0x20) || (pc[i] > 0x7e))
      buff[i % 16] = '.';
    else
      buff[i % 16] = pc[i];
    buff[(i % 16) + 1] = '\0';
  }
  printf("\n");
  printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}


x86 assembly (clang, -O0):
<HEX_DUMP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x440(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe87(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x448(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x448(%rbp),%rdi
mov    %eax,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x440(%rbp),%rsi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12c8 <HEX_DUMP+0x188>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    122b <HEX_DUMP+0xeb>
cmpl   $0x0,-0x10(%rbp)
je     121a <HEX_DUMP+0xda>
lea    -0x30(%rbp),%rsi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     126f <HEX_DUMP+0x12f>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jle    1287 <HEX_DUMP+0x147>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movb   $0x2e,-0x30(%rbp,%rax,1)
jmp    12a4 <HEX_DUMP+0x164>
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    11de <HEX_DUMP+0x9e>
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HEX_DUMP>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %esi,%r15d
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
lea    0x20(%rsp),%r14
mov    $0x400,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
lea    0xe83(%rip),%rdi
call   1040 <puts@plt>
lea    0xe56(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r15d,%edx
call   1080 <sprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe36(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r15d,%r15d
jle    1224 <HEX_DUMP+0xc4>
lea    0xe2a(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl (%rbx),%esi
lea    0xe1f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl (%rbx),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
mov    $0x2e,%r14d
cmovb  %r14d,%eax
mov    %al,(%rsp)
movb   $0x0,0x1(%rsp)
cmp    $0x1,%r15d
jne    124c <HEX_DUMP+0xec>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe0b(%rip),%rdi
call   1040 <puts@plt>
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15d,%r15d
mov    $0x1,%ebp
lea    0xdc0(%rip),%r13
jmp    128f <HEX_DUMP+0x12f>
nopl   (%rax)
movzbl (%rbx,%rbp,1),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl (%rbx,%rbp,1),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
cmovb  %r14d,%eax
mov    %al,(%rsp,%r12,1)
movb   $0x0,0x1(%rsp,%r12,1)
add    $0x1,%rbp
cmp    %rbp,%r15
je     1224 <HEX_DUMP+0xc4>
mov    %rbp,%r12
and    $0xf,%r12
jne    1260 <HEX_DUMP+0x100>
lea    0xd6f(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd63(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1260 <HEX_DUMP+0x100>

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

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