#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_char(char);
int /*<<< orphan*/ print_debug_hex32(unsigned long);
int /*<<< orphan*/ print_err(char *);
int /*<<< orphan*/ print_err_char(char);
int /*<<< orphan*/ print_err_hex32(unsigned long);
unsigned long read_phys(unsigned long);
void ram_verify(unsigned long start, unsigned long stop) {
  unsigned long addr;
  print_debug("DRAM verify: ");
  print_debug_hex32(start);
  print_debug_char('-');
  print_debug_hex32(stop);
  print_debug("\r\n");
  for (addr = start; addr < stop; addr += 4) {
    unsigned long value;
    if ((addr & 0xffff) == 0) {
      print_debug_hex32(addr);
      print_debug("\r");
    }
    value = read_phys(addr);
    if (value != addr) {
      print_err_hex32(addr);
      print_err_char(':');
      print_err_hex32(value);
      print_err("\r\n");
    }
  }
  print_debug_hex32(addr);
  print_debug("\r\nDRAM verified\r\n");
}


x86 assembly (clang, -O0):
<ram_verify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe79(%rip),%rdi
call   1060 <print_debug@plt>
mov    -0x8(%rbp),%rdi
call   1050 <print_debug_hex32@plt>
mov    $0x2d,%edi
call   1080 <print_debug_char@plt>
mov    -0x10(%rbp),%rdi
call   1050 <print_debug_hex32@plt>
lea    0xe70(%rip),%rdi
call   1060 <print_debug@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    124c <ram_verify+0xdc>
mov    -0x18(%rbp),%rax
and    $0xffff,%rax
cmp    $0x0,%rax
jne    11f3 <ram_verify+0x83>
mov    -0x18(%rbp),%rdi
call   1050 <print_debug_hex32@plt>
lea    0xe20(%rip),%rdi
call   1060 <print_debug@plt>
mov    -0x18(%rbp),%rdi
call   1070 <read_phys@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1236 <ram_verify+0xc6>
mov    -0x18(%rbp),%rdi
call   1090 <print_err_hex32@plt>
mov    $0x3a,%edi
call   1040 <print_err_char@plt>
mov    -0x20(%rbp),%rdi
call   1090 <print_err_hex32@plt>
lea    0xdee(%rip),%rdi
call   1030 <print_err@plt>
jmp    123b <ram_verify+0xcb>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    11bc <ram_verify+0x4c>
mov    -0x18(%rbp),%rdi
call   1050 <print_debug_hex32@plt>
lea    0xdb4(%rip),%rdi
call   1060 <print_debug@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ram_verify>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe7a(%rip),%rdi
call   1060 <print_debug@plt>
mov    %rbx,%rdi
call   1050 <print_debug_hex32@plt>
mov    $0x2d,%edi
call   1080 <print_debug_char@plt>
mov    %r14,%rdi
call   1050 <print_debug_hex32@plt>
lea    0xe73(%rip),%rdi
call   1060 <print_debug@plt>
cmp    %r14,%rbx
jae    1222 <ram_verify+0xb2>
lea    0xe51(%rip),%r15
lea    0xe5b(%rip),%r12
jmp    11d9 <ram_verify+0x69>
cs nopw 0x0(%rax,%rax,1)
add    $0x4,%rbx
cmp    %r14,%rbx
jae    1222 <ram_verify+0xb2>
test   %bx,%bx
jne    11ee <ram_verify+0x7e>
mov    %rbx,%rdi
call   1050 <print_debug_hex32@plt>
mov    %r15,%rdi
call   1060 <print_debug@plt>
mov    %rbx,%rdi
call   1070 <read_phys@plt>
cmp    %rax,%rbx
je     11d0 <ram_verify+0x60>
mov    %rax,%r13
mov    %rbx,%rdi
call   1090 <print_err_hex32@plt>
mov    $0x3a,%edi
call   1040 <print_err_char@plt>
mov    %r13,%rdi
call   1090 <print_err_hex32@plt>
mov    %r12,%rdi
call   1030 <print_err@plt>
jmp    11d0 <ram_verify+0x60>
mov    %rbx,%rdi
call   1050 <print_debug_hex32@plt>
lea    0xddf(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1060 <print_debug@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"DRAM verify: \00"
@.str.1 = [3 x i8] c"\0D\0A\00"
@.str.2 = [2 x i8] c"\0D\00"
@.str.3 = [18 x i8] c"\0D\0ADRAM verified\0D\0A\00"
define void @ram_verify(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%7 = call i32 @print_debug(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%8 = load i64, i64* %3
%9 = call i32 @print_debug_hex32(i64 %8)
%10 = call i32 @print_debug_char(i8 signext 45)
%11 = load i64, i64* %4
%12 = call i32 @print_debug_hex32(i64 %11)
%13 = call i32 @print_debug(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = load i64, i64* %3
store i64 %14, i64* %5
br label %15
15: ; preds = %41, %2
%16 = load i64, i64* %5
%17 = load i64, i64* %4
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %44
19: ; preds = %15
%20 = load i64, i64* %5
%21 = and i64 %20, 65535
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i64, i64* %5
%25 = call i32 @print_debug_hex32(i64 %24)
%26 = call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %23, %19
%28 = load i64, i64* %5
%29 = call i64 @read_phys(i64 %28)
store i64 %29, i64* %6
%30 = load i64, i64* %6
%31 = load i64, i64* %5
%32 = icmp ne i64 %30, %31
br i1 %32, label %33, label %40
33: ; preds = %27
%34 = load i64, i64* %5
%35 = call i32 @print_err_hex32(i64 %34)
%36 = call i32 @print_err_char(i8 signext 58)
%37 = load i64, i64* %6
%38 = call i32 @print_err_hex32(i64 %37)
%39 = call i32 @print_err(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %40
40: ; preds = %33, %27
br label %41
41: ; preds = %40
%42 = load i64, i64* %5
%43 = add i64 %42, 4
store i64 %43, i64* %5
br label %15
44: ; preds = %15
%45 = load i64, i64* %5
%46 = call i32 @print_debug_hex32(i64 %45)
%47 = call i32 @print_debug(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"DRAM verify: \00"
@.str.1 = [3 x i8] c"\0D\0A\00"
@.str.2 = [2 x i8] c"\0D\00"
@.str.3 = [18 x i8] c"\0D\0ADRAM verified\0D\0A\00"
define void @ram_verify(i64 %0, i64 %1) {
%3 = tail call i32 @print_debug(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @print_debug_hex32(i64 %0)
%5 = tail call i32 @print_debug_char(i8 signext 45)
%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.1, i64 0, i64 0))
%8 = icmp ult i64 %0, %1
br i1 %8, label %9, label %27
9: ; preds = %2, %24
%10 = phi i64 [ %25, %24 ], [ %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.2, i64 0, i64 0))
br label %16
16: ; preds = %13, %9
%17 = tail call i64 @read_phys(i64 %10)
%18 = icmp eq i64 %17, %10
br i1 %18, label %24, label %19
19: ; preds = %16
%20 = tail call i32 @print_err_hex32(i64 %10)
%21 = tail call i32 @print_err_char(i8 signext 58)
%22 = tail call i32 @print_err_hex32(i64 %17)
%23 = tail call i32 @print_err(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %19, %16
%25 = add i64 %10, 4
%26 = icmp ult i64 %25, %1
br i1 %26, label %9, label %27
27: ; preds = %24, %2
%28 = phi i64 [ %0, %2 ], [ %25, %24 ]
%29 = tail call i32 @print_debug_hex32(i64 %28)
%30 = tail call i32 @print_debug(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
ret void
}