#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*/ dread(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
void dumpmemory(int start, int end, int width) {
  char data[end - start];
  dread(data, start, (end - start));
  for (int i = start; i < end; i++) {
    if (i % width == 0) {
      printf("\n%04x |", start + i);
    }
    printf(" %02x", data[i] & 0xFF);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<dumpmemory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    %ecx,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
sub    -0x4(%rbp),%edx
call   1040 <dread@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ce <dumpmemory+0xae>
mov    -0x24(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11a0 <dumpmemory+0x80>
mov    -0x4(%rbp),%esi
add    -0x24(%rbp),%esi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
and    $0xff,%esi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1170 <dumpmemory+0x50>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dumpmemory>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%r13d
mov    %esi,%edx
sub    %edi,%edx
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    %r12,%rdi
mov    %r13d,%esi
call   1050 <dread@plt>
cmp    %r13d,%r15d
jle    11c0 <dumpmemory+0x90>
movslq %r13d,%rax
lea    0x0(%r13,%r13,1),%ebx
add    %rax,%r12
jmp    11a3 <dumpmemory+0x73>
nopl   0x0(%rax)
movzbl (%r12),%esi
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
add    $0x1,%r12
add    $0x1,%r13d
cmp    %r13d,%r15d
je     11c0 <dumpmemory+0x90>
mov    %r13d,%eax
cltd
idiv   %r14d
test   %edx,%edx
jne    1180 <dumpmemory+0x50>
lea    0xe4b(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1180 <dumpmemory+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"\0A%04x |\00"
@.str.1 = [6 x i8] c" %02x\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @dumpmemory(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = sub nsw i32 %10, %11
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %7
%15 = alloca i8, i64 %13
store i64 %13, i64* %8
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = load i32, i32* %4
%19 = sub nsw i32 %17, %18
%20 = call i32 @dread(i8* %15, i32 %16, i32 %19)
%21 = load i32, i32* %4
store i32 %21, i32* %9
br label %22
22: ; preds = %44, %3
%23 = load i32, i32* %9
%24 = load i32, i32* %5
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %47
26: ; preds = %22
%27 = load i32, i32* %9
%28 = load i32, i32* %6
%29 = srem i32 %27, %28
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = load i32, i32* %4
%33 = load i32, i32* %9
%34 = add nsw i32 %32, %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %31, %26
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %15, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = and i32 %41, 255
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %36
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
br label %22
47: ; preds = %22
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%49 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"\0A%04x |\00"
@.str.1 = [6 x i8] c" %02x\00"
define void @dumpmemory(i32 %0, i32 %1, i32 %2) {
%4 = sub nsw i32 %1, %0
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @dread(i8* %6, i32 %0, i32 %4)
%8 = icmp sgt i32 %1, %0
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = sext i32 %0 to i64
br label %13
11: ; preds = %22, %3
%12 = call i32 @putchar(i32 10)
ret void
13: ; preds = %9, %22
%14 = phi i64 [ %10, %9 ], [ %27, %22 ]
%15 = trunc i64 %14 to i32
%16 = srem i32 %15, %2
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = trunc i64 %14 to i32
%20 = add i32 %19, %0
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %13
%23 = getelementptr inbounds i8, i8* %6, i64 %14
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = add nsw i64 %14, 1
%28 = trunc i64 %27 to i32
%29 = icmp eq i32 %28, %1
br i1 %29, label %11, label %13
}