#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*/ print_debug(char *);
int /*<<< orphan*/ print_debug_hex32(unsigned long);
int /*<<< orphan*/ write_phys(unsigned long, unsigned long);
void ram_fill(unsigned long start, unsigned long stop) {
  unsigned long addr;
  print_debug("DRAM fill: ");
  print_debug_hex32(start);
  print_debug("-");
  print_debug_hex32(stop);
  print_debug("\r\n");
  for (addr = start; addr < stop; addr += 4) {
    if ((addr & 0xffff) == 0) {
      print_debug_hex32(addr);
      print_debug("\r");
    }
    write_phys(addr, addr);
  };
  print_debug_hex32(addr);
  print_debug("\r\nDRAM filled\r\n");
}


x86 assembly (clang, -O0):
<ram_fill>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb9(%rip),%rdi
call   1050 <print_debug@plt>
mov    -0x8(%rbp),%rdi
call   1040 <print_debug_hex32@plt>
lea    0xeb0(%rip),%rdi
call   1050 <print_debug@plt>
mov    -0x10(%rbp),%rdi
call   1040 <print_debug_hex32@plt>
lea    0xeac(%rip),%rdi
call   1050 <print_debug@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11d3 <ram_fill+0xa3>
mov    -0x18(%rbp),%rax
and    $0xffff,%rax
cmp    $0x0,%rax
jne    11b5 <ram_fill+0x85>
mov    -0x18(%rbp),%rdi
call   1040 <print_debug_hex32@plt>
lea    0xe5e(%rip),%rdi
call   1050 <print_debug@plt>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <write_phys@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    117e <ram_fill+0x4e>
mov    -0x18(%rbp),%rdi
call   1040 <print_debug_hex32@plt>
lea    0xe2d(%rip),%rdi
call   1050 <print_debug@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ram_fill>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xebe(%rip),%rdi
call   1050 <print_debug@plt>
mov    %rbx,%rdi
call   1040 <print_debug_hex32@plt>
lea    0xeb6(%rip),%rdi
call   1050 <print_debug@plt>
mov    %r14,%rdi
call   1040 <print_debug_hex32@plt>
lea    0xeb3(%rip),%rdi
call   1050 <print_debug@plt>
cmp    %r14,%rbx
jae    11ab <ram_fill+0x7b>
lea    0xe93(%rip),%r15
jmp    1194 <ram_fill+0x64>
nopl   (%rax)
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1030 <write_phys@plt>
add    $0x4,%rbx
cmp    %r14,%rbx
jae    11ab <ram_fill+0x7b>
test   %bx,%bx
jne    1180 <ram_fill+0x50>
mov    %rbx,%rdi
call   1040 <print_debug_hex32@plt>
mov    %r15,%rdi
call   1050 <print_debug@plt>
jmp    1180 <ram_fill+0x50>
mov    %rbx,%rdi
call   1040 <print_debug_hex32@plt>
lea    0xe56(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <print_debug@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"DRAM fill: \00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [3 x i8] c"\0D\0A\00"
@.str.3 = [2 x i8] c"\0D\00"
@.str.4 = [16 x i8] c"\0D\0ADRAM filled\0D\0A\00"
define void @ram_fill(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%6 = call i32 @print_debug(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = load i64, i64* %3
%8 = call i32 @print_debug_hex32(i64 %7)
%9 = call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = load i64, i64* %4
%11 = call i32 @print_debug_hex32(i64 %10)
%12 = call i32 @print_debug(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%13 = load i64, i64* %3
store i64 %13, i64* %5
br label %14
14: ; preds = %30, %2
%15 = load i64, i64* %5
%16 = load i64, i64* %4
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %33
18: ; preds = %14
%19 = load i64, i64* %5
%20 = and i64 %19, 65535
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i64, i64* %5
%24 = call i32 @print_debug_hex32(i64 %23)
%25 = call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %22, %18
%27 = load i64, i64* %5
%28 = load i64, i64* %5
%29 = call i32 @write_phys(i64 %27, i64 %28)
br label %30
30: ; preds = %26
%31 = load i64, i64* %5
%32 = add i64 %31, 4
store i64 %32, i64* %5
br label %14
33: ; preds = %14
%34 = load i64, i64* %5
%35 = call i32 @print_debug_hex32(i64 %34)
%36 = call i32 @print_debug(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"DRAM fill: \00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [3 x i8] c"\0D\0A\00"
@.str.3 = [2 x i8] c"\0D\00"
@.str.4 = [16 x i8] c"\0D\0ADRAM filled\0D\0A\00"
define void @ram_fill(i64 %0, i64 %1) {
%3 = tail call i32 @print_debug(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @print_debug_hex32(i64 %0)
%5 = tail call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @print_debug_hex32(i64 %1)
%7 = tail call i32 @print_debug(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp ult i64 %0, %1
br i1 %8, label %9, label %20
9: ; preds = %2, %16
%10 = phi i64 [ %18, %16 ], [ %0, %2 ]
%11 = and i64 %10, 65535
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = tail call i32 @print_debug_hex32(i64 %10)
%15 = tail call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %13, %9
%17 = tail call i32 @write_phys(i64 %10, i64 %10)
%18 = add i64 %10, 4
%19 = icmp ult i64 %18, %1
br i1 %19, label %9, label %20
20: ; preds = %16, %2
%21 = phi i64 [ %0, %2 ], [ %18, %16 ]
%22 = tail call i32 @print_debug_hex32(i64 %21)
%23 = tail call i32 @print_debug(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
ret void
}