#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*/ printf(char *, unsigned int, unsigned int);
void show_memory(volatile char *mem_ptr, int length) {
  volatile int *index;
  for (index = (int *)mem_ptr; index < (int *)(mem_ptr + length);
       index = index + 1) {
    printf("MEM(0x%08x) = 0x%08x\r\n", (unsigned int)index,
           (unsigned int)*index);
  }
  return;
}


x86 assembly (clang, -O0):
<show_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0xc(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    1168 <show_memory+0x58>
mov    -0x18(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xeae(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    1127 <show_memory+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_memory>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    114a <show_memory+0x3a>
mov    %rdi,%r12
movslq %esi,%r15
add    %rdi,%r15
lea    0xed4(%rip),%r14
mov    %rdi,%rbx
nop
mov    (%rbx),%edx
mov    %r14,%rdi
mov    %r12d,%esi
call   1030 <printf@plt>
add    $0x4,%rbx
add    $0x4,%r12d
cmp    %r15,%rbx
jb     1130 <show_memory+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [23 x i8] c"MEM(0x%08x) = 0x%08x\0D\0A\00"
define void @show_memory(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = bitcast i8* %6 to i32*
store i32* %7, i32** %5
br label %8
8: ; preds = %22, %2
%9 = load i32*, i32** %5
%10 = load i8*, i8** %3
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = bitcast i8* %13 to i32*
%15 = icmp ult i32* %9, %14
br i1 %15, label %16, label %25
16: ; preds = %8
%17 = load i32*, i32** %5
%18 = ptrtoint i32* %17 to i32
%19 = load i32*, i32** %5
%20 = load volatile i32, i32* %19
%21 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %20)
br label %22
22: ; preds = %16
%23 = load i32*, i32** %5
%24 = getelementptr inbounds i32, i32* %23, i64 1
store i32* %24, i32** %5
br label %8
25: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"MEM(0x%08x) = 0x%08x\0D\0A\00"
define void @show_memory(i8* %0, i32 %1) {
%3 = sext i32 %1 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = bitcast i8* %4 to i32*
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %17
7: ; preds = %2
%8 = bitcast i8* %0 to i32*
br label %9
9: ; preds = %7, %9
%10 = phi i32* [ %15, %9 ], [ %8, %7 ]
%11 = ptrtoint i32* %10 to i64
%12 = trunc i64 %11 to i32
%13 = load volatile i32, i32* %10
%14 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
%15 = getelementptr inbounds i32, i32* %10, i64 1
%16 = icmp ult i32* %15, %5
br i1 %16, label %9, label %17
17: ; preds = %9, %2
ret void
}