#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 uint16_t;

/* Variables and functions */
scalar_t__ isprint(int);
int mem_read_8(int);
int /*<<< orphan*/ printf(char *, ...);
void mem_dump(uint16_t start, uint16_t end) {
  int i, j;
  for (i = start; i <= end; i += 16) {
    printf("%04X  ", i);
    for (j = 0; j < 16; j++) {
      if (i + j <= end) {
        printf("%02x ", mem_read_8(i + j));
      } else {
        printf("   ");
      }
      if (j == 7) {
        printf(" ");
      }
    }
    printf(" |");
    for (j = 0; j < 16; j++) {
      if (i + j <= end) {
        printf("%c", isprint(mem_read_8(i + j)) ? mem_read_8(i + j) : '.');
      }
    }
    printf("|\n");
  }
}


x86 assembly (clang, -O0):
<mem_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1284 <mem_dump+0x154>
mov    -0xc(%rbp),%esi
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x10,-0x10(%rbp)
jge    11da <mem_dump+0xaa>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11a1 <mem_dump+0x71>
mov    -0xc(%rbp),%edi
add    -0x10(%rbp),%edi
call   1040 <mem_read_8@plt>
mov    %eax,%esi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11af <mem_dump+0x7f>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x7,-0x10(%rbp)
jne    11c7 <mem_dump+0x97>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11cc <mem_dump+0x9c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1168 <mem_dump+0x38>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x10,-0x10(%rbp)
jge    1268 <mem_dump+0x138>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1255 <mem_dump+0x125>
mov    -0xc(%rbp),%edi
add    -0x10(%rbp),%edi
call   1040 <mem_read_8@plt>
mov    %eax,%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     1237 <mem_dump+0x107>
mov    -0xc(%rbp),%edi
add    -0x10(%rbp),%edi
call   1040 <mem_read_8@plt>
mov    %eax,-0x14(%rbp)
jmp    1244 <mem_dump+0x114>
mov    $0x2e,%eax
mov    %eax,-0x14(%rbp)
jmp    1244 <mem_dump+0x114>
mov    -0x14(%rbp),%esi
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125a <mem_dump+0x12a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11ef <mem_dump+0xbf>
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0xc(%rbp)
jmp    1144 <mem_dump+0x14>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %esi,%edi
jle    116e <mem_dump+0x1e>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %esi,%r15d
mov    %edi,%ebx
lea    0xe93(%rip),%r12
lea    0xe86(%rip),%r14
jmp    11a7 <mem_dump+0x57>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe7b(%rip),%rdi
call   1040 <puts@plt>
add    $0x10,%ebx
cmp    %r15d,%ebx
mov    %rbp,%r12
jg     115f <mem_dump+0xf>
lea    0xe52(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebp,%ebp
jmp    11c8 <mem_dump+0x78>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0x10,%ebp
je     1220 <mem_dump+0xd0>
lea    (%rbx,%rbp,1),%edi
cmp    %r15d,%edi
jle    11f0 <mem_dump+0xa0>
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x7,%ebp
jne    11c0 <mem_dump+0x70>
jmp    1206 <mem_dump+0xb6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1060 <mem_read_8@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x7,%ebp
jne    11c0 <mem_dump+0x70>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    11c0 <mem_dump+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rbp
xor    %r13d,%r13d
lea    0xde4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    125d <mem_dump+0x10d>
cs nopw 0x0(%rax,%rax,1)
mov    %r12d,%edi
call   1060 <mem_read_8@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
add    $0x1,%r13d
cmp    $0x10,%r13d
je     1190 <mem_dump+0x40>
lea    (%rbx,%r13,1),%r12d
cmp    %r15d,%r12d
jg     124f <mem_dump+0xff>
mov    %r12d,%edi
call   1060 <mem_read_8@plt>
mov    %eax,%edi
call   1070 <isprint@plt>
test   %rax,%rax
jne    1240 <mem_dump+0xf0>
mov    $0x2e,%edi
jmp    124a <mem_dump+0xfa>

LLVM IR (-O0):
@.str = [7 x i8] c"%04X \00"
@.str.1 = [6 x i8] c"%02x \00"
@.str.2 = [4 x i8] c" \00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [3 x i8] c" |\00"
@.str.5 = [3 x i8] c"%c\00"
@.str.6 = [3 x i8] c"|\0A\00"
define void @mem_dump(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
store i32 %7, i32* %5
br label %8
8: ; preds = %74, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %77
12: ; preds = %8
%13 = load i32, i32* %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 0, i32* %6
br label %15
15: ; preds = %38, %12
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 16
br i1 %17, label %18, label %41
18: ; preds = %15
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = add nsw i32 %19, %20
%22 = load i32, i32* %4
%23 = icmp sle i32 %21, %22
br i1 %23, label %24, label %30
24: ; preds = %18
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = add nsw i32 %25, %26
%28 = call i32 @mem_read_8(i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %32
30: ; preds = %18
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %24
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, 7
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %32
br label %38
38: ; preds = %37
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %15
41: ; preds = %15
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %6
br label %43
43: ; preds = %69, %41
%44 = load i32, i32* %6
%45 = icmp slt i32 %44, 16
br i1 %45, label %46, label %72
46: ; preds = %43
%47 = load i32, i32* %5
%48 = load i32, i32* %6
%49 = add nsw i32 %47, %48
%50 = load i32, i32* %4
%51 = icmp sle i32 %49, %50
br i1 %51, label %52, label %68
52: ; preds = %46
%53 = load i32, i32* %5
%54 = load i32, i32* %6
%55 = add nsw i32 %53, %54
%56 = call i32 @mem_read_8(i32 %55)
%57 = call i64 @isprint(i32 %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %64
59: ; preds = %52
%60 = load i32, i32* %5
%61 = load i32, i32* %6
%62 = add nsw i32 %60, %61
%63 = call i32 @mem_read_8(i32 %62)
br label %65
64: ; preds = %52
br label %65
65: ; preds = %64, %59
%66 = phi i32 [ %63, %59 ], [ 46, %64 ]
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %65, %46
br label %69
69: ; preds = %68
%70 = load i32, i32* %6
%71 = add nsw i32 %70, 1
store i32 %71, i32* %6
br label %43
72: ; preds = %43
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %74
74: ; preds = %72
%75 = load i32, i32* %5
%76 = add nsw i32 %75, 16
store i32 %76, i32* %5
br label %8
77: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%04X \00"
@.str.1 = [6 x i8] c"%02x \00"
@.str.2 = [4 x i8] c" \00"
@.str.4 = [3 x i8] c" |\00"
@str = [2 x i8] c"|\00"
define void @mem_dump(i32 %0, i32 %1) {
%3 = icmp sgt i32 %0, %1
br i1 %3, label %45, label %4
4: ; preds = %2, %41
%5 = phi i32 [ %43, %41 ], [ %0, %2 ]
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %7
7: ; preds = %4, %20
%8 = phi i32 [ 0, %4 ], [ %21, %20 ]
%9 = add nsw i32 %8, %5
%10 = icmp sgt i32 %9, %1
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = tail call i32 @mem_read_8(i32 %9)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %16
14: ; preds = %7
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = icmp eq i32 %8, 7
br i1 %17, label %18, label %20
18: ; preds = %16
%19 = tail call i32 @putchar(i32 32)
br label %20
20: ; preds = %16, %18
%21 = add nuw nsw i32 %8, 1
%22 = icmp eq i32 %21, 16
br i1 %22, label %23, label %7
23: ; preds = %20
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %25
25: ; preds = %23, %38
%26 = phi i32 [ 0, %23 ], [ %39, %38 ]
%27 = add nsw i32 %26, %5
%28 = icmp sgt i32 %27, %1
br i1 %28, label %38, label %29
29: ; preds = %25
%30 = tail call i32 @mem_read_8(i32 %27)
%31 = tail call i64 @isprint(i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %29
%34 = tail call i32 @mem_read_8(i32 %27)
br label %35
35: ; preds = %29, %33
%36 = phi i32 [ %34, %33 ], [ 46, %29 ]
%37 = tail call i32 @putchar(i32 %36)
br label %38
38: ; preds = %25, %35
%39 = add nuw nsw i32 %26, 1
%40 = icmp eq i32 %39, 16
br i1 %40, label %41, label %25
41: ; preds = %38
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%43 = add nsw i32 %5, 16
%44 = icmp sgt i32 %43, %1
br i1 %44, label %45, label %4
45: ; preds = %41, %2
ret void
}