#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ isascii(unsigned char);
scalar_t__ isprint(unsigned char);
void hexdump(FILE *fp, void *data, size_t size) {
  unsigned char *src;
  int offset, index;
  src = (unsigned char *)data;
  fprintf(fp, "+------+-------------------------------------------------+------"
              "------------+\n");
  for (offset = 0; offset < (int)size; offset += 16) {
    fprintf(fp, "| %04x | ", offset);
    for (index = 0; index < 16; index++) {
      if (offset + index < (int)size) {
        fprintf(fp, "%02x ", 0xff & src[offset + index]);
      } else {
        fprintf(fp, "   ");
      }
    }
    fprintf(fp, "| ");
    for (index = 0; index < 16; index++) {
      if (offset + index < (int)size) {
        if (isascii(src[offset + index]) && isprint(src[offset + index])) {
          fprintf(fp, "%c", src[offset + index]);
        } else {
          fprintf(fp, ".");
        }
      } else {
        fprintf(fp, " ");
      }
    }
    fprintf(fp, " |\n");
  }
  fprintf(fp, "+------+-------------------------------------------------+------"
              "------------+\n");
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    %ecx,%eax
jge    12f8 <hexdump+0x1c8>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xecd(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x10,-0x28(%rbp)
jge    11ff <hexdump+0xcf>
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    %ecx,%eax
jge    11da <hexdump+0xaa>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
and    $0xff,%edx
lea    0xe8b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11ec <hexdump+0xbc>
mov    -0x8(%rbp),%rdi
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11f1 <hexdump+0xc1>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1190 <hexdump+0x60>
mov    -0x8(%rbp),%rdi
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x10,-0x28(%rbp)
jge    12d8 <hexdump+0x1a8>
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    %ecx,%eax
jge    12b3 <hexdump+0x183>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edi
call   1050 <isascii@plt>
cmp    $0x0,%rax
je     129c <hexdump+0x16c>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     129c <hexdump+0x16c>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12ae <hexdump+0x17e>
mov    -0x8(%rbp),%rdi
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12c5 <hexdump+0x195>
mov    -0x8(%rbp),%rdi
lea    0xda3(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12ca <hexdump+0x19a>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1218 <hexdump+0xe8>
mov    -0x8(%rbp),%rdi
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x24(%rbp)
jmp    1165 <hexdump+0x35>
mov    -0x8(%rbp),%rdi
lea    0xcfd(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe95(%rip),%rdi
mov    $0x4e,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %rbp,(%rsp)
test   %ebp,%ebp
jle    12a3 <hexdump+0x153>
movslq (%rsp),%r13
lea    0xec5(%rip),%r14
xor    %r12d,%r12d
jmp    11d2 <hexdump+0x82>
nopl   0x0(%rax)
mov    $0x3,%esi
mov    $0x1,%edx
lea    0xeb2(%rip),%rdi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
add    $0x10,%r12
add    $0x10,%r15
cmp    (%rsp),%r12d
lea    0xe8d(%rip),%r14
jge    12a3 <hexdump+0x153>
mov    %rbx,%rdi
lea    0xe73(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %ebp,%ebp
jmp    1213 <hexdump+0xc3>
nopw   0x0(%rax,%rax,1)
mov    $0x3,%esi
mov    $0x1,%edx
lea    0xe5e(%rip),%rdi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
add    $0x1,%rbp
cmp    $0x10,%rbp
je     1230 <hexdump+0xe0>
lea    (%r12,%rbp,1),%rax
cmp    %r13,%rax
jge    11f0 <hexdump+0xa0>
movzbl (%r15,%rbp,1),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1209 <hexdump+0xb9>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xe15(%rip),%rdi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
xor    %ebp,%ebp
jmp    1269 <hexdump+0x119>
nopl   (%rax)
mov    %r14d,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
add    $0x1,%rbp
cmp    $0x10,%rbp
je     11a0 <hexdump+0x50>
lea    (%r12,%rbp,1),%rax
mov    $0x20,%r14d
cmp    %r13,%rax
jge    1250 <hexdump+0x100>
movzbl (%r15,%rbp,1),%edi
call   1060 <isascii@plt>
mov    $0x2e,%r14d
test   %rax,%rax
je     1250 <hexdump+0x100>
movzbl (%r15,%rbp,1),%edi
call   1050 <isprint@plt>
test   %rax,%rax
je     1250 <hexdump+0x100>
movzbl (%r15,%rbp,1),%r14d
jmp    1250 <hexdump+0x100>
lea    0xd56(%rip),%rdi
mov    $0x4e,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fwrite@plt>

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

LLVM IR (-O2):
@.str = [79 x i8] c"+------+-------------------------------------------------+------------------+\0A\00"
@.str.1 = [10 x i8] c"| %04x | \00"
@.str.2 = [6 x i8] c"%02x \00"
@.str.3 = [4 x i8] c" \00"
@.str.4 = [3 x i8] c"| \00"
@.str.8 = [4 x i8] c" |\0A\00"
define void @hexdump(i32* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = tail call i64 @fwrite(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0), i64 78, i64 1, i32* %0)
%5 = trunc i64 %2 to i32
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %56
7: ; preds = %3
%8 = shl i64 %2, 32
%9 = ashr exact i64 %8, 32
br label %10
10: ; preds = %7, %51
%11 = phi i64 [ 0, %7 ], [ %53, %51 ]
%12 = trunc i64 %11 to i32
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %10, %25
%15 = phi i64 [ 0, %10 ], [ %26, %25 ]
%16 = add nuw nsw i64 %15, %11
%17 = icmp slt i64 %16, %9
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = getelementptr inbounds i8, i8* %1, i64 %16
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %25
23: ; preds = %14
%24 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 3, i64 1, i32* %0)
br label %25
25: ; preds = %18, %23
%26 = add nuw nsw i64 %15, 1
%27 = icmp eq i64 %26, 16
br i1 %27, label %28, label %14
28: ; preds = %25
%29 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %30
30: ; preds = %28, %46
%31 = phi i64 [ 0, %28 ], [ %49, %46 ]
%32 = add nuw nsw i64 %31, %11
%33 = icmp slt i64 %32, %9
br i1 %33, label %34, label %46
34: ; preds = %30
%35 = getelementptr inbounds i8, i8* %1, i64 %32
%36 = load i8, i8* %35
%37 = tail call i64 @isascii(i8 zeroext %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %46, label %39
39: ; preds = %34
%40 = load i8, i8* %35
%41 = tail call i64 @isprint(i8 zeroext %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %39
%44 = load i8, i8* %35
%45 = zext i8 %44 to i32
br label %46
46: ; preds = %30, %34, %39, %43
%47 = phi i32 [ %45, %43 ], [ 46, %39 ], [ 46, %34 ], [ 32, %30 ]
%48 = tail call i32 @fputc(i32 %47, i32* %0)
%49 = add nuw nsw i64 %31, 1
%50 = icmp eq i64 %49, 16
br i1 %50, label %51, label %30
51: ; preds = %46
%52 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64 3, i64 1, i32* %0)
%53 = add nuw i64 %11, 16
%54 = trunc i64 %53 to i32
%55 = icmp slt i32 %54, %5
br i1 %55, label %10, label %56
56: ; preds = %51, %3
%57 = tail call i64 @fwrite(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0), i64 78, i64 1, i32* %0)
ret void
}