#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
void hex_dump(unsigned char *data, int size, char *caption, int verbose) {
  int i;
  int j;
  char temp[8];
  char buffer[128];
  char *ascii;
  memset(buffer, 0, 128);
  if (verbose && caption)
    printf("---------> %s <--------- (%d bytes from %p)\n", caption, size,
           data);
  printf("        +0          +4          +8          +c            0   4   8  "
         " c   \n");
  ascii = buffer + 58;
  memset(buffer, ' ', 58 + 16);
  buffer[58 + 16] = '\n';
  buffer[58 + 17] = '\0';
  buffer[0] = '+';
  buffer[1] = '0';
  buffer[2] = '0';
  buffer[3] = '0';
  buffer[4] = '0';
  for (i = 0, j = 0; i < size; i++, j++) {
    if (j == 16) {
      printf("%s", buffer);
      memset(buffer, ' ', 58 + 16);
      sprintf(temp, "+%04x", i);
      memcpy(buffer, temp, 5);
      j = 0;
    }
    sprintf(temp, "%02x", 0xff & data[i]);
    memcpy(buffer + 8 + (j * 3), temp, 2);
    if ((data[i] > 31) && (data[i] < 127))
      ascii[j] = data[i];
    else
      ascii[j] = '.';
  }
  if (j != 0)
    printf("%s", buffer);
}


x86 assembly (clang, -O0):
<hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
cmpl   $0x0,-0x1c(%rbp)
je     119a <hex_dump+0x5a>
cmpq   $0x0,-0x18(%rbp)
je     119a <hex_dump+0x5a>
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xb0(%rbp),%rax
add    $0x3a,%rax
mov    %rax,-0xb8(%rbp)
lea    -0xb0(%rbp),%rdi
mov    $0x20,%esi
mov    $0x4a,%edx
call   1040 <memset@plt>
movb   $0xa,-0x66(%rbp)
movb   $0x0,-0x65(%rbp)
movb   $0x2b,-0xb0(%rbp)
movb   $0x30,-0xaf(%rbp)
movb   $0x30,-0xae(%rbp)
movb   $0x30,-0xad(%rbp)
movb   $0x30,-0xac(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1330 <hex_dump+0x1f0>
cmpl   $0x10,-0x24(%rbp)
jne    1279 <hex_dump+0x139>
lea    -0xb0(%rbp),%rsi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xb0(%rbp),%rdi
mov    $0x20,%esi
mov    $0x4a,%edx
call   1040 <memset@plt>
lea    -0x2c(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xe24(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0xb0(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
mov    $0x5,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x24(%rbp)
lea    -0x2c(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
and    $0xff,%edx
lea    0xdec(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0xb0(%rbp),%rdi
add    $0x8,%rdi
imul   $0x3,-0x24(%rbp),%eax
cltq
add    %rax,%rdi
lea    -0x2c(%rbp),%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x1f,%eax
jle    1305 <hex_dump+0x1c5>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7f,%eax
jge    1305 <hex_dump+0x1c5>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0xb8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1314 <hex_dump+0x1d4>
mov    -0xb8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x2e,(%rax,%rcx,1)
jmp    1319 <hex_dump+0x1d9>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1209 <hex_dump+0xc9>
cmpl   $0x0,-0x24(%rbp)
je     134f <hex_dump+0x20f>
lea    -0xb0(%rbp),%rsi
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %ecx,%ebx
mov    %rdx,%rbp
mov    %esi,%r15d
mov    %rdi,%r14
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
test   %rbp,%rbp
je     119d <hex_dump+0x4d>
test   %ebx,%ebx
je     119d <hex_dump+0x4d>
lea    0xe73(%rip),%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rdi
mov    $0x20,%esi
mov    $0x4a,%edx
call   1050 <memset@plt>
movw   $0xa,0x5a(%rsp)
movb   $0x2b,0x10(%rsp)
movl   $0x30303030,0x11(%rsp)
30
test   %r15d,%r15d
jle    12b2 <hex_dump+0x162>
mov    %r15d,%r13d
xor    %ebx,%ebx
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%rbp
xor    %r15d,%r15d
jmp    1248 <hex_dump+0xf8>
xchg   %ax,%ax
movzbl (%r14,%rbx,1),%edx
mov    %rbp,%rdi
lea    0xe37(%rip),%rsi
call   1070 <sprintf@plt>
lea    (%r15,%r15,2),%eax
movslq %eax,%rdi
lea    0x18(%rsp),%rax
add    %rax,%rdi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1060 <memcpy@plt>
movzbl (%r14,%rbx,1),%eax
lea    -0x20(%rax),%ecx
cmp    $0x5f,%cl
movslq %r15d,%r15
mov    $0x2e,%ecx
cmovae %ecx,%eax
mov    %al,0x4a(%rsp,%r15,1)
add    $0x1,%rbx
add    $0x1,%r15d
cmp    %rbx,%r13
je     129a <hex_dump+0x14a>
cmp    $0x10,%r15d
jne    11f0 <hex_dump+0xa0>
xor    %r15d,%r15d
lea    0xdd5(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    $0x20,%esi
mov    $0x4a,%edx
call   1050 <memset@plt>
mov    %rbp,%rdi
lea    0xdb2(%rip),%rsi
mov    %ebx,%edx
call   1070 <sprintf@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    $0x5,%edx
call   1060 <memcpy@plt>
jmp    11f0 <hex_dump+0xa0>
test   %r15d,%r15d
je     12b2 <hex_dump+0x162>
lea    0xd87(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"---------> %s <--------- (%d bytes from %p)\0A\00"
@.str.1 = [76 x i8] c" +0 +4 +8 +c 0 4 8 c \0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [6 x i8] c"+%04x\00"
@.str.4 = [5 x i8] c"%02x\00"
define void @hex_dump(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [8 x i8]
%12 = alloca [128 x i8]
%13 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i8 signext 0, i32 128)
%16 = load i32, i32* %8
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %4
%19 = load i8*, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i8*, i8** %7
%23 = load i32, i32* %6
%24 = load i8*, i8** %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %22, i32 %23, i8* %24)
br label %26
26: ; preds = %21, %18, %4
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0))
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%29 = getelementptr inbounds i8, i8* %28, i64 58
store i8* %29, i8** %13
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%31 = call i32 @memset(i8* %30, i8 signext 32, i32 74)
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 74
store i8 10, i8* %32
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 75
store i8 0, i8* %33
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
store i8 43, i8* %34
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 1
store i8 48, i8* %35
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 2
store i8 48, i8* %36
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 3
store i8 48, i8* %37
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 4
store i8 48, i8* %38
store i32 0, i32* %9
store i32 0, i32* %10
br label %39
39: ; preds = %106, %26
%40 = load i32, i32* %9
%41 = load i32, i32* %6
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %111
43: ; preds = %39
%44 = load i32, i32* %10
%45 = icmp eq i32 %44, 16
br i1 %45, label %46, label %57
46: ; preds = %43
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%50 = call i32 @memset(i8* %49, i8 signext 32, i32 74)
%51 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%52 = load i32, i32* %9
%53 = call i32 @sprintf(i8* %51, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %52)
%54 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%55 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%56 = call i32 @memcpy(i8* %54, i8* %55, i32 5)
store i32 0, i32* %10
br label %57
57: ; preds = %46, %43
%58 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%59 = load i8*, i8** %5
%60 = load i32, i32* %9
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
%65 = and i32 255, %64
%66 = call i32 @sprintf(i8* %58, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %65)
%67 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%68 = getelementptr inbounds i8, i8* %67, i64 8
%69 = load i32, i32* %10
%70 = mul nsw i32 %69, 3
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %68, i64 %71
%73 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%74 = call i32 @memcpy(i8* %72, i8* %73, i32 2)
%75 = load i8*, i8** %5
%76 = load i32, i32* %9
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %75, i64 %77
%79 = load i8, i8* %78
%80 = zext i8 %79 to i32
%81 = icmp sgt i32 %80, 31
br i1 %81, label %82, label %100
82: ; preds = %57
%83 = load i8*, i8** %5
%84 = load i32, i32* %9
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %83, i64 %85
%87 = load i8, i8* %86
%88 = zext i8 %87 to i32
%89 = icmp slt i32 %88, 127
br i1 %89, label %90, label %100
90: ; preds = %82
%91 = load i8*, i8** %5
%92 = load i32, i32* %9
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8, i8* %91, i64 %93
%95 = load i8, i8* %94
%96 = load i8*, i8** %13
%97 = load i32, i32* %10
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %96, i64 %98
store i8 %95, i8* %99
br label %105
100: ; preds = %82, %57
%101 = load i8*, i8** %13
%102 = load i32, i32* %10
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i8, i8* %101, i64 %103
store i8 46, i8* %104
br label %105
105: ; preds = %100, %90
br label %106
106: ; preds = %105
%107 = load i32, i32* %9
%108 = add nsw i32 %107, 1
store i32 %108, i32* %9
%109 = load i32, i32* %10
%110 = add nsw i32 %109, 1
store i32 %110, i32* %10
br label %39
111: ; preds = %39
%112 = load i32, i32* %10
%113 = icmp ne i32 %112, 0
br i1 %113, label %114, label %117
114: ; preds = %111
%115 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %115)
br label %117
117: ; preds = %114, %111
ret void
}

LLVM IR (-O2):
@.str = [45 x i8] c"---------> %s <--------- (%d bytes from %p)\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [6 x i8] c"+%04x\00"
@.str.4 = [5 x i8] c"%02x\00"
@str = [75 x i8] c" +0 +4 +8 +c 0 4 8 c \00"
define void @hex_dump(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [8 x i8]
%6 = alloca [128 x i8]
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i8 signext 0, i32 128)
%10 = icmp ne i32 %3, 0
%11 = icmp ne i8* %2, null
%12 = and i1 %11, %10
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %1, i8* %0)
br label %15
15: ; preds = %13, %4
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @str, i64 0, i64 0))
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 58
%18 = call i32 @memset(i8* %8, i8 signext 32, i32 74)
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 74
store i8 10, i8* %19
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 75
store i8 0, i8* %20
store i8 43, i8* %8
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 1
%22 = icmp sgt i32 %1, 0
%23 = bitcast i8* %21 to i32*
store i32 808464432, i32* %23
br i1 %22, label %24, label %60
24: ; preds = %15
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 8
%26 = zext i32 %1 to i64
br label %27
27: ; preds = %24, %37
%28 = phi i64 [ 0, %24 ], [ %53, %37 ]
%29 = phi i32 [ 0, %24 ], [ %54, %37 ]
%30 = icmp eq i32 %29, 16
br i1 %30, label %31, label %37
31: ; preds = %27
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%33 = call i32 @memset(i8* %8, i8 signext 32, i32 74)
%34 = trunc i64 %28 to i32
%35 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = call i32 @memcpy(i8* %8, i8* %7, i32 5)
br label %37
37: ; preds = %31, %27
%38 = phi i32 [ 0, %31 ], [ %29, %27 ]
%39 = getelementptr inbounds i8, i8* %0, i64 %28
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = mul nsw i32 %38, 3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %25, i64 %44
%46 = call i32 @memcpy(i8* %45, i8* %7, i32 2)
%47 = load i8, i8* %39
%48 = add i8 %47, -32
%49 = icmp ult i8 %48, 95
%50 = sext i32 %38 to i64
%51 = getelementptr inbounds i8, i8* %17, i64 %50
%52 = select i1 %49, i8 %47, i8 46
store i8 %52, i8* %51
%53 = add nuw nsw i64 %28, 1
%54 = add nsw i32 %38, 1
%55 = icmp eq i64 %53, %26
br i1 %55, label %56, label %27
56: ; preds = %37
%57 = icmp eq i32 %54, 0
br i1 %57, label %60, label %58
58: ; preds = %56
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %8)
br label %60
60: ; preds = %15, %58, %56
ret void
}