#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 */
unsigned long dimm_base(int);
int /*<<< orphan*/ print_debug(char *);
int /*<<< orphan*/ print_debug_hex32(unsigned long);
void dimms_read(unsigned long offset) {
  int i;
  for (i = 0; i < 8; i++) {
    unsigned long dummy;
    unsigned long addr;
    unsigned long next_base;
    next_base = dimm_base(i + 1);
    addr = dimm_base(i);
    if (addr == next_base) {
      continue;
    }
    addr += offset;
    print_debug("Reading ");
    print_debug_hex32(addr);
    print_debug("\n");
    dummy = *((volatile unsigned long *)(addr));
    print_debug("Reading ");
    print_debug_hex32(addr ^ 0xddf8);
    print_debug("\n");
    dummy = *((volatile unsigned long *)(addr ^ 0xdff8));
    print_debug("Read ");
    print_debug_hex32(addr);
    print_debug_hex32(addr ^ 0xddf8);
    print_debug("\n");
  }
}


x86 assembly (clang, -O0):
<dimms_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    122b <dimms_read+0xfb>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1030 <dimm_base@plt>
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <dimm_base@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    117b <dimms_read+0x4b>
jmp    121d <dimms_read+0xed>
mov    -0x8(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe72(%rip),%rdi
call   1050 <print_debug@plt>
mov    -0x20(%rbp),%rdi
call   1040 <print_debug_hex32@plt>
lea    0xe66(%rip),%rdi
call   1050 <print_debug@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
lea    0xe46(%rip),%rdi
call   1050 <print_debug@plt>
mov    -0x20(%rbp),%rdi
xor    $0xddf8,%rdi
call   1040 <print_debug_hex32@plt>
lea    0xe33(%rip),%rdi
call   1050 <print_debug@plt>
mov    -0x20(%rbp),%rax
xor    $0xdff8,%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
lea    0xe18(%rip),%rdi
call   1050 <print_debug@plt>
mov    -0x20(%rbp),%rdi
call   1040 <print_debug_hex32@plt>
mov    -0x20(%rbp),%rdi
xor    $0xddf8,%rdi
call   1040 <print_debug_hex32@plt>
lea    0xdf1(%rip),%rdi
call   1050 <print_debug@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1143 <dimms_read+0x13>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dimms_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
xor    %r14d,%r14d
lea    0xec1(%rip),%r15
jmp    115a <dimms_read+0x2a>
nopw   0x0(%rax,%rax,1)
cmp    $0x8,%r14d
je     11fb <dimms_read+0xcb>
mov    %r14d,%ebx
lea    0x1(%rbx),%r14d
mov    %r14d,%edi
call   1030 <dimm_base@plt>
mov    %rax,%rbp
mov    %ebx,%edi
call   1030 <dimm_base@plt>
cmp    %rbp,%rax
je     1150 <dimms_read+0x20>
mov    %rax,%rbx
mov    %rax,%r12
add    %r13,%r12
lea    0xe78(%rip),%rbp
mov    %rbp,%rdi
call   1050 <print_debug@plt>
mov    %r12,%rdi
call   1040 <print_debug_hex32@plt>
mov    %r15,%rdi
call   1050 <print_debug@plt>
mov    (%rbx,%r13,1),%rax
mov    %rbp,%rdi
call   1050 <print_debug@plt>
mov    %r12,%rbx
xor    $0xddf8,%rbx
mov    %rbx,%rdi
call   1040 <print_debug_hex32@plt>
mov    %r15,%rdi
call   1050 <print_debug@plt>
mov    %r12,%rax
xor    $0xdff8,%rax
mov    (%rax),%rax
lea    0xe32(%rip),%rdi
call   1050 <print_debug@plt>
mov    %r12,%rdi
call   1040 <print_debug_hex32@plt>
mov    %rbx,%rdi
call   1040 <print_debug_hex32@plt>
mov    %r15,%rdi
call   1050 <print_debug@plt>
jmp    1150 <dimms_read+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"Reading \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [6 x i8] c"Read \00"
define void @dimms_read(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i64 %0, i64* %2
store i32 0, i32* %3
br label %7
7: ; preds = %47, %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 8
br i1 %9, label %10, label %50
10: ; preds = %7
%11 = load i32, i32* %3
%12 = add nsw i32 %11, 1
%13 = call i64 @dimm_base(i32 %12)
store i64 %13, i64* %6
%14 = load i32, i32* %3
%15 = call i64 @dimm_base(i32 %14)
store i64 %15, i64* %5
%16 = load i64, i64* %5
%17 = load i64, i64* %6
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %10
br label %47
20: ; preds = %10
%21 = load i64, i64* %2
%22 = load i64, i64* %5
%23 = add i64 %22, %21
store i64 %23, i64* %5
%24 = call i32 @print_debug(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%25 = load i64, i64* %5
%26 = call i32 @print_debug_hex32(i64 %25)
%27 = call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = load i64, i64* %5
%29 = inttoptr i64 %28 to i64*
%30 = load volatile i64, i64* %29
store i64 %30, i64* %4
%31 = call i32 @print_debug(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%32 = load i64, i64* %5
%33 = xor i64 %32, 56824
%34 = call i32 @print_debug_hex32(i64 %33)
%35 = call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%36 = load i64, i64* %5
%37 = xor i64 %36, 57336
%38 = inttoptr i64 %37 to i64*
%39 = load volatile i64, i64* %38
store i64 %39, i64* %4
%40 = call i32 @print_debug(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%41 = load i64, i64* %5
%42 = call i32 @print_debug_hex32(i64 %41)
%43 = load i64, i64* %5
%44 = xor i64 %43, 56824
%45 = call i32 @print_debug_hex32(i64 %44)
%46 = call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %20, %19
%48 = load i32, i32* %3
%49 = add nsw i32 %48, 1
store i32 %49, i32* %3
br label %7
50: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"Reading \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [6 x i8] c"Read \00"
define void @dimms_read(i64 %0) {
br label %2
2: ; preds = %1, %26
%3 = phi i32 [ 0, %1 ], [ %4, %26 ]
%4 = add nuw nsw i32 %3, 1
%5 = tail call i64 @dimm_base(i32 %4)
%6 = tail call i64 @dimm_base(i32 %3)
%7 = icmp eq i64 %6, %5
br i1 %7, label %26, label %8
8: ; preds = %2
%9 = add i64 %6, %0
%10 = tail call i32 @print_debug(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @print_debug_hex32(i64 %9)
%12 = tail call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = inttoptr i64 %9 to i64*
%14 = load volatile i64, i64* %13
%15 = tail call i32 @print_debug(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%16 = xor i64 %9, 56824
%17 = tail call i32 @print_debug_hex32(i64 %16)
%18 = tail call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = xor i64 %9, 57336
%20 = inttoptr i64 %19 to i64*
%21 = load volatile i64, i64* %20
%22 = tail call i32 @print_debug(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%23 = tail call i32 @print_debug_hex32(i64 %9)
%24 = tail call i32 @print_debug_hex32(i64 %16)
%25 = tail call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %2, %8
%27 = icmp eq i32 %4, 8
br i1 %27, label %28, label %2
28: ; preds = %26
ret void
}