#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*/ sw_printf(char *, int, int);
int /*<<< orphan*/ sw_sdram_init();
int /*<<< orphan*/ sw_usleep(int);
int sdramtest(int argc, char *argv[]) {
  int *addr = (int *)0x40008000;
  int *endaddr = (int *)0x44000000;
  int *p;
  sw_sdram_init();
  while (1) {
    p = addr;
    while (p < endaddr) {
      *p = (int)p;
      p += (4 * 4 * 4 * 4 * 4);
    }
    p = addr;
    while (p < endaddr) {
      sw_printf("%x: %x\n\r", (int)p, *p);
      p += (4 * 4 * 4 * 4 * 4);
      sw_usleep(1 * 1000);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<sdramtest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x40008000,%eax
mov    %rax,-0x18(%rbp)
mov    $0x44000000,%eax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <sw_sdram_init@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    118d <sdramtest+0x5d>
mov    -0x28(%rbp),%rax
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1000,%rax
mov    %rax,-0x28(%rbp)
jmp    1160 <sdramtest+0x30>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11d8 <sdramtest+0xa8>
mov    -0x28(%rbp),%rax
mov    %eax,%esi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
lea    0xe4a(%rip),%rdi
call   1030 <sw_printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1000,%rax
mov    %rax,-0x28(%rbp)
mov    $0x3e8,%edi
call   1050 <sw_usleep@plt>
jmp    1195 <sdramtest+0x65>
jmp    1158 <sdramtest+0x28>

x86 assembly (clang, -O2):
<sdramtest>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <sw_sdram_init@plt>
mov    $0x40008000,%r14d
lea    0xeb5(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14d,(%r14)
add    $0x1000,%r14
cmp    $0x44000000,%r14
jb     1150 <sdramtest+0x20>
mov    $0x40008000,%r14d
mov    $0x40008000,%ebp
mov    $0x40008000,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rbx),%edx
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <sw_printf@plt>
add    $0x1000,%rbx
mov    $0x3e8,%edi
call   1050 <sw_usleep@plt>
add    $0x1000,%ebp
cmp    $0x44000000,%rbx
jb     1180 <sdramtest+0x50>
jmp    1150 <sdramtest+0x20>

LLVM IR (-O0):
@.str = [9 x i8] c"%x: %x\0A\0D\00"
define i32 @sdramtest(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32* inttoptr (i64 1073774592 to i32*), i32** %5
store i32* inttoptr (i64 1140850688 to i32*), i32** %6
%8 = call i32 (...) @sw_sdram_init()
br label %9
9: ; preds = %2, %36
%10 = load i32*, i32** %5
store i32* %10, i32** %7
br label %11
11: ; preds = %15, %9
%12 = load i32*, i32** %7
%13 = load i32*, i32** %6
%14 = icmp ult i32* %12, %13
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = load i32*, i32** %7
%17 = ptrtoint i32* %16 to i32
%18 = load i32*, i32** %7
store i32 %17, i32* %18
%19 = load i32*, i32** %7
%20 = getelementptr inbounds i32, i32* %19, i64 1024
store i32* %20, i32** %7
br label %11
21: ; preds = %11
%22 = load i32*, i32** %5
store i32* %22, i32** %7
br label %23
23: ; preds = %27, %21
%24 = load i32*, i32** %7
%25 = load i32*, i32** %6
%26 = icmp ult i32* %24, %25
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = load i32*, i32** %7
%29 = ptrtoint i32* %28 to i32
%30 = load i32*, i32** %7
%31 = load i32, i32* %30
%32 = call i32 @sw_printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %29, i32 %31)
%33 = load i32*, i32** %7
%34 = getelementptr inbounds i32, i32* %33, i64 1024
store i32* %34, i32** %7
%35 = call i32 @sw_usleep(i32 1000)
br label %23
36: ; preds = %23
br label %9
}

LLVM IR (-O2):
@.str = [9 x i8] c"%x: %x\0A\0D\00"
define i32 @sdramtest(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @sw_sdram_init()
br label %4
4: ; preds = %10, %2
%5 = phi i32* [ inttoptr (i64 1073774592 to i32*), %2 ], [ %11, %10 ]
%6 = ptrtoint i32* %5 to i64
%7 = trunc i64 %6 to i32
store i32 %7, i32* %5
%8 = getelementptr inbounds i32, i32* %5, i64 1024
%9 = icmp ult i32* %8, inttoptr (i64 1140850688 to i32*)
br i1 %9, label %10, label %12
10: ; preds = %12, %4
%11 = phi i32* [ %8, %4 ], [ inttoptr (i64 1073774592 to i32*), %12 ]
br label %4
12: ; preds = %4, %12
%13 = phi i32* [ %18, %12 ], [ inttoptr (i64 1073774592 to i32*), %4 ]
%14 = ptrtoint i32* %13 to i64
%15 = trunc i64 %14 to i32
%16 = load i32, i32* %13
%17 = tail call i32 @sw_printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %16)
%18 = getelementptr inbounds i32, i32* %13, i64 1024
%19 = tail call i32 @sw_usleep(i32 1000)
%20 = icmp ult i32* %18, inttoptr (i64 1140850688 to i32*)
br i1 %20, label %12, label %10
}