#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);
int checkDramData(volatile unsigned int *pBaseAddress) {
  unsigned int index;
  unsigned int flipCount = 0;
  unsigned int colCounter = 0;
  unsigned int rowCounter = 0;
  unsigned int data = 0xFFFFFFFF;
  for (index = 0; index < (0x10000 * 1); index += 1) {
    if (((index >> 2) % 2) == 0) {
      if ((pBaseAddress[index] & 0xFFFF) != (data & 0xFFFF)) {
        printf("0x%8.8X 0\n\r", (unsigned int)&pBaseAddress[index]);
        ++flipCount;
      }
      if ((pBaseAddress[index] >> 16) != (data & 0xFFFF)) {
        printf("0x%8.8X 1\n\r", (unsigned int)&pBaseAddress[index]);
        ++flipCount;
      }
      ++colCounter;
      if (colCounter == (512 / (4 / 2))) {
        colCounter = 0;
        ++rowCounter;
        data = (rowCounter / 2) % 2 == 0 ? 0xFFFFFFFF : 0x0;
      }
    }
  }
  return flipCount;
}


x86 assembly (clang, -O0):
<checkDramData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x10000,-0xc(%rbp)
jae    123d <checkDramData+0x12d>
mov    -0xc(%rbp),%eax
shr    $0x2,%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    122a <checkDramData+0x11a>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
and    $0xffff,%eax
mov    -0x1c(%rbp),%ecx
and    $0xffff,%ecx
cmp    %ecx,%eax
je     11a3 <checkDramData+0x93>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %eax,%esi
lea    0xe6b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
shr    $0x10,%eax
mov    -0x1c(%rbp),%ecx
and    $0xffff,%ecx
cmp    %ecx,%eax
je     11e6 <checkDramData+0xd6>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %eax,%esi
lea    0xe34(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x100,-0x14(%rbp)
jne    1225 <checkDramData+0x115>
movl   $0x0,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edx
shr    $0x1,%edx
and    $0x1,%edx
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %eax,-0x1c(%rbp)
jmp    122a <checkDramData+0x11a>
jmp    122f <checkDramData+0x11f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113f <checkDramData+0x2f>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkDramData>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %ebx,%ebx
mov    $0xffffffff,%r14d
mov    %edi,%ebp
movl   $0x0,0xc(%rsp)
xor    %r15d,%r15d
xor    %r13d,%r13d
mov    %rdi,0x10(%rsp)
jmp    1150 <checkDramData+0x40>
nopl   (%rax)
add    $0x1,%rbx
add    $0x4,%ebp
cmp    $0x10000,%rbx
je     11cb <checkDramData+0xbb>
test   $0x4,%bl
jne    1140 <checkDramData+0x30>
mov    (%rdi,%rbx,4),%eax
movzwl %ax,%eax
movzwl %r14w,%r12d
cmp    %r12d,%eax
je     117b <checkDramData+0x6b>
lea    0xe95(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    0x10(%rsp),%rdi
add    $0x1,%r13d
mov    (%rdi,%rbx,4),%eax
shr    $0x10,%eax
cmp    %r12d,%eax
je     119d <checkDramData+0x8d>
lea    0xe7f(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    0x10(%rsp),%rdi
add    $0x1,%r13d
add    $0x1,%r15d
cmp    $0x100,%r15d
jne    1140 <checkDramData+0x30>
mov    0xc(%rsp),%r14d
add    $0x1,%r14d
mov    %r14d,0xc(%rsp)
shr    %r14d
and    $0x1,%r14d
add    $0xffffffff,%r14d
xor    %r15d,%r15d
jmp    1140 <checkDramData+0x30>
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"0x%8.8X 0\0A\0D\00"
@.str.1 = [12 x i8] c"0x%8.8X 1\0A\0D\00"
define i32 @checkDramData(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 -1, i32* %7
store i32 0, i32* %3
br label %8
8: ; preds = %70, %1
%9 = load i32, i32* %3
%10 = icmp ult i32 %9, 65536
br i1 %10, label %11, label %73
11: ; preds = %8
%12 = load i32, i32* %3
%13 = lshr i32 %12, 2
%14 = urem i32 %13, 2
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %69
16: ; preds = %11
%17 = load i32*, i32** %2
%18 = load i32, i32* %3
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load volatile i32, i32* %20
%22 = and i32 %21, 65535
%23 = load i32, i32* %7
%24 = and i32 %23, 65535
%25 = icmp ne i32 %22, %24
br i1 %25, label %26, label %35
26: ; preds = %16
%27 = load i32*, i32** %2
%28 = load i32, i32* %3
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = ptrtoint i32* %30 to i32
%32 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %4
%34 = add i32 %33, 1
store i32 %34, i32* %4
br label %35
35: ; preds = %26, %16
%36 = load i32*, i32** %2
%37 = load i32, i32* %3
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load volatile i32, i32* %39
%41 = lshr i32 %40, 16
%42 = load i32, i32* %7
%43 = and i32 %42, 65535
%44 = icmp ne i32 %41, %43
br i1 %44, label %45, label %54
45: ; preds = %35
%46 = load i32*, i32** %2
%47 = load i32, i32* %3
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
%50 = ptrtoint i32* %49 to i32
%51 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %4
%53 = add i32 %52, 1
store i32 %53, i32* %4
br label %54
54: ; preds = %45, %35
%55 = load i32, i32* %5
%56 = add i32 %55, 1
store i32 %56, i32* %5
%57 = load i32, i32* %5
%58 = icmp eq i32 %57, 256
br i1 %58, label %59, label %68
59: ; preds = %54
store i32 0, i32* %5
%60 = load i32, i32* %6
%61 = add i32 %60, 1
store i32 %61, i32* %6
%62 = load i32, i32* %6
%63 = udiv i32 %62, 2
%64 = urem i32 %63, 2
%65 = icmp eq i32 %64, 0
%66 = zext i1 %65 to i64
%67 = select i1 %65, i32 -1, i32 0
store i32 %67, i32* %7
br label %68
68: ; preds = %59, %54
br label %69
69: ; preds = %68, %11
br label %70
70: ; preds = %69
%71 = load i32, i32* %3
%72 = add i32 %71, 1
store i32 %72, i32* %3
br label %8
73: ; preds = %8
%74 = load i32, i32* %4
ret i32 %74
}

LLVM IR (-O2):
@.str = [12 x i8] c"0x%8.8X 0\0A\0D\00"
@.str.1 = [12 x i8] c"0x%8.8X 1\0A\0D\00"
define i32 @checkDramData(i32* %0) {
br label %2
2: ; preds = %1, %40
%3 = phi i64 [ 0, %1 ], [ %45, %40 ]
%4 = phi i32 [ -1, %1 ], [ %44, %40 ]
%5 = phi i32 [ 0, %1 ], [ %43, %40 ]
%6 = phi i32 [ 0, %1 ], [ %42, %40 ]
%7 = phi i32 [ 0, %1 ], [ %41, %40 ]
%8 = and i64 %3, 4
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %40
10: ; preds = %2
%11 = getelementptr inbounds i32, i32* %0, i64 %3
%12 = load volatile i32, i32* %11
%13 = and i32 %12, 65535
%14 = and i32 %4, 65535
%15 = icmp eq i32 %13, %14
br i1 %15, label %21, label %16
16: ; preds = %10
%17 = ptrtoint i32* %11 to i64
%18 = trunc i64 %17 to i32
%19 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = add i32 %7, 1
br label %21
21: ; preds = %16, %10
%22 = phi i32 [ %20, %16 ], [ %7, %10 ]
%23 = load volatile i32, i32* %11
%24 = lshr i32 %23, 16
%25 = icmp eq i32 %24, %14
br i1 %25, label %31, label %26
26: ; preds = %21
%27 = ptrtoint i32* %11 to i64
%28 = trunc i64 %27 to i32
%29 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = add i32 %22, 1
br label %31
31: ; preds = %26, %21
%32 = phi i32 [ %30, %26 ], [ %22, %21 ]
%33 = add i32 %6, 1
%34 = icmp eq i32 %33, 256
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = add i32 %5, 1
%37 = lshr i32 %36, 1
%38 = and i32 %37, 1
%39 = add nsw i32 %38, -1
br label %40
40: ; preds = %2, %35, %31
%41 = phi i32 [ %32, %35 ], [ %32, %31 ], [ %7, %2 ]
%42 = phi i32 [ 0, %35 ], [ %33, %31 ], [ %6, %2 ]
%43 = phi i32 [ %36, %35 ], [ %5, %31 ], [ %5, %2 ]
%44 = phi i32 [ %39, %35 ], [ %4, %31 ], [ %4, %2 ]
%45 = add nuw nsw i64 %3, 1
%46 = icmp eq i64 %45, 65536
br i1 %46, label %47, label %2
47: ; preds = %40
ret i32 %41
}