#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*/ cpu_mem_read_byte(unsigned char *, unsigned int);
int /*<<< orphan*/ printf(char *, ...);
void _display_memory(unsigned int offset, unsigned int size) {
  for (int i = 0; i < size; i++) {
    unsigned int read_offset = offset + i;
    unsigned char mem_value;
    cpu_mem_read_byte(&mem_value, read_offset);
    if (i % 16 == 0) {
      printf("0x%08x:", read_offset);
    }
    printf(" %02x", mem_value);
    if (i % 16 == 16 - 1 || i == size - 1) {
      printf("\n");
    }
  }
}


x86 assembly (clang, -O0):
<_display_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    11d3 <_display_memory+0xb3>
mov    -0x4(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    -0x11(%rbp),%rdi
call   1040 <cpu_mem_read_byte@plt>
mov    -0xc(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    117b <_display_memory+0x5b>
mov    -0x10(%rbp),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0x11(%rbp),%esi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
je     11b2 <_display_memory+0x92>
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11c0 <_display_memory+0xa0>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c5 <_display_memory+0xa5>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1135 <_display_memory+0x15>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_display_memory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     11b3 <_display_memory+0x83>
mov    %esi,%ebx
mov    %edi,%r14d
neg    %ebx
xor    %r12d,%r12d
jmp    1165 <_display_memory+0x35>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r12d
mov    %ebx,%eax
add    %r12d,%eax
je     11b3 <_display_memory+0x83>
lea    (%rbx,%r12,1),%r15d
lea    (%r14,%r12,1),%ebp
lea    0x7(%rsp),%rdi
mov    %ebp,%esi
call   1050 <cpu_mem_read_byte@plt>
mov    %r12d,%r13d
and    $0xf,%r13d
jne    1192 <_display_memory+0x62>
lea    0xe77(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x7(%rsp),%esi
lea    0xe6a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0xffffffff,%r15d
je     1150 <_display_memory+0x20>
cmp    $0xf,%r13d
jne    115a <_display_memory+0x2a>
jmp    1150 <_display_memory+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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