#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 */
char *build_ascii(char *, int);
int /*<<< orphan*/ monitor_write(char *);
int /*<<< orphan*/ monitor_write_hex(char *);
int /*<<< orphan*/ monitor_write_hex_byte(int /*<<< orphan*/);
void memory_read_area(char *startp, char *endp) {
  int counter = 0;
  char *p = startp;
  char *asc;
  monitor_write("\n start : ");
  monitor_write_hex(startp);
  monitor_write("\n end : ");
  monitor_write_hex(endp);
  monitor_write("\n------------------------ \n ");
  while (p != endp) {
    if (counter == 0) {
      monitor_write("    ");
      monitor_write(asc);
      counter = 15;
      monitor_write("\n");
      monitor_write_hex(p);
      monitor_write("  : ");
    } else {
      counter = counter - 1;
    }
    asc = build_ascii(p, counter);
    monitor_write_hex_byte(*p++);
  }
  for (counter; counter != 0; counter--) {
    monitor_write("  ");
  }
  monitor_write("    ");
  monitor_write(asc);
  monitor_write("\n");
}


x86 assembly (clang, -O0):
<memory_read_area>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe9a(%rip),%rdi
call   1060 <monitor_write@plt>
mov    -0x8(%rbp),%rdi
call   1050 <monitor_write_hex@plt>
lea    0xe90(%rip),%rdi
call   1060 <monitor_write@plt>
mov    -0x10(%rbp),%rdi
call   1050 <monitor_write_hex@plt>
lea    0xe84(%rip),%rdi
call   1060 <monitor_write@plt>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1224 <memory_read_area+0xe4>
cmpl   $0x0,-0x14(%rbp)
jne    11ef <memory_read_area+0xaf>
lea    0xe7d(%rip),%rdi
call   1060 <monitor_write@plt>
mov    -0x28(%rbp),%rdi
call   1060 <monitor_write@plt>
movl   $0xf,-0x14(%rbp)
lea    0xe66(%rip),%rdi
call   1060 <monitor_write@plt>
mov    -0x20(%rbp),%rdi
call   1050 <monitor_write_hex@plt>
lea    0xe53(%rip),%rdi
call   1060 <monitor_write@plt>
jmp    11f8 <memory_read_area+0xb8>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <build_ascii@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%edi
call   1040 <monitor_write_hex_byte@plt>
jmp    1195 <memory_read_area+0x55>
cmpl   $0x0,-0x14(%rbp)
je     1248 <memory_read_area+0x108>
lea    0xdfe(%rip),%rdi
call   1060 <monitor_write@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1224 <memory_read_area+0xe4>
lea    0xde2(%rip),%rdi
call   1060 <monitor_write@plt>
mov    -0x28(%rbp),%rdi
call   1060 <monitor_write@plt>
lea    0xdd2(%rip),%rdi
call   1060 <monitor_write@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memory_read_area>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xea8(%rip),%rdi
call   1060 <monitor_write@plt>
mov    %rbx,%rdi
call   1050 <monitor_write_hex@plt>
lea    0xe9f(%rip),%rdi
call   1060 <monitor_write@plt>
mov    %r14,%rdi
call   1050 <monitor_write_hex@plt>
lea    0xe94(%rip),%rdi
call   1060 <monitor_write@plt>
cmp    %r14,%rbx
je     1230 <memory_read_area+0xf0>
xor    %r15d,%r15d
lea    0xe9e(%rip),%r13
lea    0xe99(%rip),%rbp
jmp    1201 <memory_read_area+0xc1>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe7a(%rip),%rdi
call   1060 <monitor_write@plt>
mov    %r12,%rdi
call   1060 <monitor_write@plt>
mov    %r13,%rdi
call   1060 <monitor_write@plt>
mov    %rbx,%rdi
call   1050 <monitor_write_hex@plt>
mov    %rbp,%rdi
call   1060 <monitor_write@plt>
mov    $0xf,%r15d
mov    %rbx,%rdi
mov    %r15d,%esi
call   1030 <build_ascii@plt>
mov    %rax,%r12
movsbl (%rbx),%edi
add    $0x1,%rbx
call   1040 <monitor_write_hex_byte@plt>
cmp    %r14,%rbx
je     120c <memory_read_area+0xcc>
test   %r15d,%r15d
je     11b0 <memory_read_area+0x70>
add    $0xffffffff,%r15d
jmp    11e2 <memory_read_area+0xa2>
test   %r15d,%r15d
je     1230 <memory_read_area+0xf0>
lea    0xe1b(%rip),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <monitor_write@plt>
add    $0xffffffff,%r15d
jne    1220 <memory_read_area+0xe0>
jmp    1230 <memory_read_area+0xf0>
lea    0xdfa(%rip),%rdi
call   1060 <monitor_write@plt>
mov    %r12,%rdi
call   1060 <monitor_write@plt>
lea    0xdeb(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <monitor_write@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"\0A start : \00"
@.str.1 = [9 x i8] c"\0A end : \00"
@.str.2 = [29 x i8] c"\0A------------------------ \0A \00"
@.str.3 = [5 x i8] c" \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [5 x i8] c" : \00"
@.str.6 = [3 x i8] c" \00"
define void @memory_read_area(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%8 = load i8*, i8** %3
store i8* %8, i8** %6
%9 = call i32 @monitor_write(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%10 = load i8*, i8** %3
%11 = call i32 @monitor_write_hex(i8* %10)
%12 = call i32 @monitor_write(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%13 = load i8*, i8** %4
%14 = call i32 @monitor_write_hex(i8* %13)
%15 = call i32 @monitor_write(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %34, %2
%17 = load i8*, i8** %6
%18 = load i8*, i8** %4
%19 = icmp ne i8* %17, %18
br i1 %19, label %20, label %43
20: ; preds = %16
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = call i32 @monitor_write(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%25 = load i8*, i8** %7
%26 = call i32 @monitor_write(i8* %25)
store i32 15, i32* %5
%27 = call i32 @monitor_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%28 = load i8*, i8** %6
%29 = call i32 @monitor_write_hex(i8* %28)
%30 = call i32 @monitor_write(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %34
31: ; preds = %20
%32 = load i32, i32* %5
%33 = sub nsw i32 %32, 1
store i32 %33, i32* %5
br label %34
34: ; preds = %31, %23
%35 = load i8*, i8** %6
%36 = load i32, i32* %5
%37 = call i8* @build_ascii(i8* %35, i32 %36)
store i8* %37, i8** %7
%38 = load i8*, i8** %6
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %6
%40 = load i8, i8* %38
%41 = sext i8 %40 to i32
%42 = call i32 @monitor_write_hex_byte(i32 %41)
br label %16
43: ; preds = %16
%44 = load i32, i32* %5
br label %45
45: ; preds = %50, %43
%46 = load i32, i32* %5
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %45
%49 = call i32 @monitor_write(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %50
50: ; preds = %48
%51 = load i32, i32* %5
%52 = add nsw i32 %51, -1
store i32 %52, i32* %5
br label %45
53: ; preds = %45
%54 = call i32 @monitor_write(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%55 = load i8*, i8** %7
%56 = call i32 @monitor_write(i8* %55)
%57 = call i32 @monitor_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"\0A start : \00"
@.str.1 = [9 x i8] c"\0A end : \00"
@.str.2 = [29 x i8] c"\0A------------------------ \0A \00"
@.str.3 = [5 x i8] c" \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [5 x i8] c" : \00"
@.str.6 = [3 x i8] c" \00"
define void @memory_read_area(i8* %0, i8* %1) {
%3 = tail call i32 @monitor_write(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @monitor_write_hex(i8* %0)
%5 = tail call i32 @monitor_write(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @monitor_write_hex(i8* %1)
%7 = tail call i32 @monitor_write(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i8* %0, %1
br i1 %8, label %37, label %11
9: ; preds = %24
%10 = icmp eq i32 %25, 0
br i1 %10, label %37, label %32
11: ; preds = %2, %24
%12 = phi i8* [ %26, %24 ], [ undef, %2 ]
%13 = phi i8* [ %27, %24 ], [ %0, %2 ]
%14 = phi i32 [ %25, %24 ], [ 0, %2 ]
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = tail call i32 @monitor_write(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%18 = tail call i32 @monitor_write(i8* %12)
%19 = tail call i32 @monitor_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%20 = tail call i32 @monitor_write_hex(i8* %13)
%21 = tail call i32 @monitor_write(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %24
22: ; preds = %11
%23 = add nsw i32 %14, -1
br label %24
24: ; preds = %22, %16
%25 = phi i32 [ 15, %16 ], [ %23, %22 ]
%26 = tail call i8* @build_ascii(i8* %13, i32 %25)
%27 = getelementptr inbounds i8, i8* %13, i64 1
%28 = load i8, i8* %13
%29 = sext i8 %28 to i32
%30 = tail call i32 @monitor_write_hex_byte(i32 %29)
%31 = icmp eq i8* %27, %1
br i1 %31, label %9, label %11
32: ; preds = %9, %32
%33 = phi i32 [ %35, %32 ], [ %25, %9 ]
%34 = tail call i32 @monitor_write(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%35 = add nsw i32 %33, -1
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %32
37: ; preds = %32, %2, %9
%38 = phi i8* [ %26, %9 ], [ undef, %2 ], [ %26, %32 ]
%39 = tail call i32 @monitor_write(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%40 = tail call i32 @monitor_write(i8* %38)
%41 = tail call i32 @monitor_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}