#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);
int /*<<< orphan*/ printf(char *, ...);
void MemDump(void *memptr, unsigned offset, unsigned length) {
  int i;
  int currentPost;
  unsigned total;
  total = offset + length;
  printf("\n-----------MEMORY DUMP---------------\n");
  if (offset <= 5000 && total <= 5000) {
    for (i = offset; i < total; i += 16) {
      currentPost = i;
      printf("\n%04X ", i);
      while (currentPost < (i + 16)) {
        if (currentPost != total) {
          printf("%02X ", ((unsigned char *)memptr)[currentPost]);
          currentPost++;
        }
      }
      printf("\n      ");
      currentPost = i;
      while (currentPost < (i + 16)) {
        if (currentPost != total) {
          if (isprint(((unsigned char *)memptr)[currentPost])) {
            printf("%c  ", ((unsigned char *)memptr)[currentPost]);
          } else {
            printf(".  ");
          }
          currentPost++;
        }
      }
      printf("\n");
    }
    printf("\n");
  } else {
    printf("\nExceeded max buffer size, 5000(1388 HEX)\n");
  }
}


x86 assembly (clang, -O0):
<MemDump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1388,-0xc(%rbp)
ja     1287 <MemDump+0x167>
cmpl   $0x1388,-0x1c(%rbp)
ja     1287 <MemDump+0x167>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    1274 <MemDump+0x154>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x10,%ecx
cmp    %ecx,%eax
jge    11d1 <MemDump+0xb1>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11cc <MemDump+0xac>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118c <MemDump+0x6c>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x10,%ecx
cmp    %ecx,%eax
jge    1258 <MemDump+0x138>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1253 <MemDump+0x133>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     123c <MemDump+0x11c>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124a <MemDump+0x12a>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11e5 <MemDump+0xc5>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x14(%rbp)
jmp    1169 <MemDump+0x49>
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1295 <MemDump+0x175>
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MemDump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xec4(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x1388,%ebx
ja     125c <MemDump+0x11c>
add    %ebx,%r12d
cmp    $0x1388,%r12d
ja     125c <MemDump+0x11c>
cmp    %ebx,%r12d
jbe    1276 <MemDump+0x136>
lea    0xe8f(%rip),%r15
jmp    11a6 <MemDump+0x66>
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r13d,%ebx
cmp    %r12d,%r13d
jae    1276 <MemDump+0x136>
mov    %r15,%rbp
lea    0xe50(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10(%rbx),%r13d
mov    %ebx,%r15d
jmp    11d8 <MemDump+0x98>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%r15d
cmp    %r13d,%eax
jge    1200 <MemDump+0xc0>
mov    %r12d,%eax
cmp    %r12d,%r15d
je     11d0 <MemDump+0x90>
movslq %r15d,%rax
movzbl (%r14,%rax,1),%esi
lea    0xe18(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r15d
mov    %r15d,%eax
jmp    11d0 <MemDump+0x90>
nop
lea    0xe06(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%r15
jmp    122d <MemDump+0xed>
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebx
mov    %ebx,%eax
mov    %eax,%ebx
cmp    %r13d,%eax
jge    1190 <MemDump+0x50>
mov    %r12d,%eax
cmp    %r12d,%ebx
je     1222 <MemDump+0xe2>
movslq %ebx,%rbp
movzbl (%r14,%rbp,1),%edi
call   1060 <isprint@plt>
test   %rax,%rax
je     1213 <MemDump+0xd3>
movzbl (%r14,%rbp,1),%esi
lea    0xdc2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    121d <MemDump+0xdd>
lea    0xde2(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str.1 = [7 x i8] c"\0A%04X \00"
@.str.2 = [6 x i8] c"%02X \00"
@.str.3 = [8 x i8] c"\0A \00"
@.str.4 = [5 x i8] c"%c \00"
@.str.5 = [4 x i8] c". \00"
@str = [39 x i8] c"\0A-----------MEMORY DUMP---------------\00"
@str.8 = [42 x i8] c"\0AExceeded max buffer size, 5000(1388 HEX)\00"
define void @MemDump(i8* nocapture %0, i32 %1, i32 %2) {
%4 = add i32 %2, %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%6 = icmp ult i32 %1, 5001
%7 = icmp ult i32 %4, 5001
%8 = and i1 %6, %7
br i1 %8, label %9, label %55
9: ; preds = %3
%10 = icmp ugt i32 %4, %1
br i1 %10, label %11, label %53
11: ; preds = %9, %50
%12 = phi i32 [ %14, %50 ], [ %1, %9 ]
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = add nsw i32 %12, 16
br label %15
15: ; preds = %11, %25
%16 = phi i32 [ %12, %11 ], [ %26, %25 ]
%17 = icmp eq i32 %16, %4
br i1 %17, label %25, label %18
18: ; preds = %15
%19 = sext i32 %16 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = add nsw i32 %16, 1
br label %25
25: ; preds = %18, %15
%26 = phi i32 [ %24, %18 ], [ %4, %15 ]
%27 = icmp slt i32 %26, %14
br i1 %27, label %15, label %28
28: ; preds = %25
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %47
%31 = phi i32 [ %12, %28 ], [ %48, %47 ]
%32 = icmp eq i32 %31, %4
br i1 %32, label %47, label %33
33: ; preds = %30
%34 = sext i32 %31 to i64
%35 = getelementptr inbounds i8, i8* %0, i64 %34
%36 = load i8, i8* %35
%37 = tail call i64 @isprint(i8 zeroext %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %33
%40 = load i8, i8* %35
%41 = zext i8 %40 to i32
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %41)
br label %45
43: ; preds = %33
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %45
45: ; preds = %43, %39
%46 = add nsw i32 %31, 1
br label %47
47: ; preds = %45, %30
%48 = phi i32 [ %46, %45 ], [ %4, %30 ]
%49 = icmp slt i32 %48, %14
br i1 %49, label %30, label %50
50: ; preds = %47
%51 = tail call i32 @putchar(i32 10)
%52 = icmp ult i32 %14, %4
br i1 %52, label %11, label %53
53: ; preds = %50, %9
%54 = tail call i32 @putchar(i32 10)
br label %57
55: ; preds = %3
%56 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.8, i64 0, i64 0))
br label %57
57: ; preds = %55, %53
ret void
}