void EEPROMRead(unsigned long *pulData, unsigned long ulAddress,
                unsigned long ulCount) {
  DEBUG_ASSERT(pulData);
  DEBUG_ASSERT(
      ulAddress <
      (((((*((volatile unsigned long *)(0x400AF000)))) & 0x0000FFFF) >> 0) *
       4));
  DEBUG_ASSERT(
      (ulAddress + ulCount) <=
      (((((*((volatile unsigned long *)(0x400AF000)))) & 0x0000FFFF) >> 0) *
       4));
  DEBUG_ASSERT((ulAddress & 3) == 0);
  DEBUG_ASSERT((ulCount & 3) == 0);
  (*((volatile unsigned long *)(0x400AF004))) = ((ulAddress) >> 6);
  (*((volatile unsigned long *)(0x400AF008))) = (((ulAddress) >> 2) & 0x0F);
  ulCount /= 4;
  while (ulCount) {
    *pulData = (*((volatile unsigned long *)(0x400AF014)));
    pulData++;
    ulCount--;
    if ((*((volatile unsigned long *)(0x400AF008))) == 0) {
      (*((volatile unsigned long *)(0x400AF004))) += 1;
    }
  }
}


x86 assembly (clang, -O0):
<EEPROMRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1030 <DEBUG_ASSERT@plt>
mov    -0x10(%rbp),%rax
mov    $0x400af000,%ecx
mov    (%rcx),%rcx
and    $0xffff,%rcx
shr    $0x0,%rcx
shl    $0x2,%rcx
cmp    %rcx,%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <DEBUG_ASSERT@plt>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    $0x400af000,%ecx
mov    (%rcx),%rcx
and    $0xffff,%rcx
shr    $0x0,%rcx
shl    $0x2,%rcx
cmp    %rcx,%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <DEBUG_ASSERT@plt>
mov    -0x10(%rbp),%rax
and    $0x3,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <DEBUG_ASSERT@plt>
mov    -0x18(%rbp),%rax
and    $0x3,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <DEBUG_ASSERT@plt>
mov    -0x10(%rbp),%rcx
shr    $0x6,%rcx
mov    $0x400af004,%eax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rcx
shr    $0x2,%rcx
and    $0xf,%rcx
mov    $0x400af008,%eax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
shr    $0x2,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1250 <EEPROMRead+0x140>
mov    $0x400af014,%eax
mov    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    $0x400af008,%eax
mov    (%rax),%rax
cmp    $0x0,%rax
jne    124b <EEPROMRead+0x13b>
mov    $0x400af004,%eax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    $0x400af004,%eax
mov    %rcx,(%rax)
jmp    11f3 <EEPROMRead+0xe3>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EEPROMRead>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <DEBUG_ASSERT@plt>
mov    0x400af000,%rax
40
movzwl %ax,%eax
shl    $0x2,%rax
xor    %edi,%edi
cmp    %r15,%rax
seta   %dil
xor    %eax,%eax
call   1030 <DEBUG_ASSERT@plt>
lea    (%r14,%r15,1),%rax
mov    0x400af000,%rcx
40
movzwl %cx,%ecx
shl    $0x2,%rcx
xor    %edi,%edi
cmp    %rcx,%rax
setbe  %dil
xor    %eax,%eax
call   1030 <DEBUG_ASSERT@plt>
xor    %edi,%edi
test   $0x3,%r15b
sete   %dil
xor    %eax,%eax
call   1030 <DEBUG_ASSERT@plt>
xor    %edi,%edi
test   $0x3,%r14b
sete   %dil
xor    %eax,%eax
call   1030 <DEBUG_ASSERT@plt>
mov    %r15,%rax
shr    $0x6,%rax
mov    %rax,0x400af004
40
shr    $0x2,%r15d
and    $0xf,%r15d
mov    %r15,0x400af008
40
cmp    $0x4,%r14
jb     11ea <EEPROMRead+0xda>
mov    %r14,%rcx
shr    $0x2,%rcx
test   $0x4,%r14b
jne    11c6 <EEPROMRead+0xb6>
mov    %rcx,%rax
cmp    $0x1,%rcx
je     11ea <EEPROMRead+0xda>
jmp    11ff <EEPROMRead+0xef>
mov    0x400af014,%rax
40
mov    %rax,(%rbx)
add    $0x8,%rbx
lea    -0x1(%rcx),%rax
cmpq   $0x0,0x400af008
je     11f0 <EEPROMRead+0xe0>
cmp    $0x1,%rcx
jne    11ff <EEPROMRead+0xef>
pop    %rbx
pop    %r14
pop    %r15
ret
addq   $0x1,0x400af004
40 01
cmp    $0x1,%rcx
je     11ea <EEPROMRead+0xda>
xor    %ecx,%ecx
jmp    1219 <EEPROMRead+0x109>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x2,%rcx
cmp    %rcx,%rax
je     11ea <EEPROMRead+0xda>
mov    0x400af014,%rdx
40
mov    %rdx,(%rbx,%rcx,8)
cmpq   $0x0,0x400af008
jne    1239 <EEPROMRead+0x129>
addq   $0x1,0x400af004
40 01
mov    0x400af014,%rdx
40
mov    %rdx,0x8(%rbx,%rcx,8)
cmpq   $0x0,0x400af008
jne    1210 <EEPROMRead+0x100>
addq   $0x1,0x400af004
40 01
jmp    1210 <EEPROMRead+0x100>

LLVM IR (-O0):
define void @EEPROMRead(i64* %0, i64 %1, i64 %2) {
%4 = alloca i64*
%5 = alloca i64
%6 = alloca i64
store i64* %0, i64** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%7 = load i64*, i64** %4
%8 = call i32 (i64*, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i64*, ...)*)(i64* %7)
%9 = load i64, i64* %5
%10 = load volatile i64, i64* inttoptr (i64 1074458624 to i64*)
%11 = and i64 %10, 65535
%12 = lshr i64 %11, 0
%13 = mul i64 %12, 4
%14 = icmp ult i64 %9, %13
%15 = zext i1 %14 to i32
%16 = call i32 (i32, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i32, ...)*)(i32 %15)
%17 = load i64, i64* %5
%18 = load i64, i64* %6
%19 = add i64 %17, %18
%20 = load volatile i64, i64* inttoptr (i64 1074458624 to i64*)
%21 = and i64 %20, 65535
%22 = lshr i64 %21, 0
%23 = mul i64 %22, 4
%24 = icmp ule i64 %19, %23
%25 = zext i1 %24 to i32
%26 = call i32 (i32, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i32, ...)*)(i32 %25)
%27 = load i64, i64* %5
%28 = and i64 %27, 3
%29 = icmp eq i64 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 (i32, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i32, ...)*)(i32 %30)
%32 = load i64, i64* %6
%33 = and i64 %32, 3
%34 = icmp eq i64 %33, 0
%35 = zext i1 %34 to i32
%36 = call i32 (i32, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i32, ...)*)(i32 %35)
%37 = load i64, i64* %5
%38 = lshr i64 %37, 6
store volatile i64 %38, i64* inttoptr (i64 1074458628 to i64*)
%39 = load i64, i64* %5
%40 = lshr i64 %39, 2
%41 = and i64 %40, 15
store volatile i64 %41, i64* inttoptr (i64 1074458632 to i64*)
%42 = load i64, i64* %6
%43 = udiv i64 %42, 4
store i64 %43, i64* %6
br label %44
44: ; preds = %59, %3
%45 = load i64, i64* %6
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %60
47: ; preds = %44
%48 = load volatile i64, i64* inttoptr (i64 1074458644 to i64*)
%49 = load i64*, i64** %4
store i64 %48, i64* %49
%50 = load i64*, i64** %4
%51 = getelementptr inbounds i64, i64* %50, i32 1
store i64* %51, i64** %4
%52 = load i64, i64* %6
%53 = add i64 %52, -1
store i64 %53, i64* %6
%54 = load volatile i64, i64* inttoptr (i64 1074458632 to i64*)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %47
%57 = load volatile i64, i64* inttoptr (i64 1074458628 to i64*)
%58 = add i64 %57, 1
store volatile i64 %58, i64* inttoptr (i64 1074458628 to i64*)
br label %59
59: ; preds = %56, %47
br label %44
60: ; preds = %44
ret void
}

LLVM IR (-O2):
define void @EEPROMRead(i64* %0, i64 %1, i64 %2) {
%4 = tail call i32 (i64*, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i64*, ...)*)(i64* %0)
%5 = load volatile i64, i64* inttoptr (i64 1074458624 to i64*)
%6 = shl i64 %5, 2
%7 = and i64 %6, 262140
%8 = icmp ugt i64 %7, %1
%9 = zext i1 %8 to i32
%10 = tail call i32 (i32, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i32, ...)*)(i32 %9)
%11 = add i64 %2, %1
%12 = load volatile i64, i64* inttoptr (i64 1074458624 to i64*)
%13 = shl i64 %12, 2
%14 = and i64 %13, 262140
%15 = icmp ule i64 %11, %14
%16 = zext i1 %15 to i32
%17 = tail call i32 (i32, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i32, ...)*)(i32 %16)
%18 = and i64 %1, 3
%19 = icmp eq i64 %18, 0
%20 = zext i1 %19 to i32
%21 = tail call i32 (i32, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i32, ...)*)(i32 %20)
%22 = and i64 %2, 3
%23 = icmp eq i64 %22, 0
%24 = zext i1 %23 to i32
%25 = tail call i32 (i32, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i32, ...)*)(i32 %24)
%26 = lshr i64 %1, 6
store volatile i64 %26, i64* inttoptr (i64 1074458628 to i64*)
%27 = lshr i64 %1, 2
%28 = and i64 %27, 15
store volatile i64 %28, i64* inttoptr (i64 1074458632 to i64*)
%29 = icmp ult i64 %2, 4
br i1 %29, label %68, label %30
30: ; preds = %3
%31 = lshr i64 %2, 2
%32 = and i64 %2, 4
%33 = icmp eq i64 %32, 0
br i1 %33, label %43, label %34
34: ; preds = %30
%35 = load volatile i64, i64* inttoptr (i64 1074458644 to i64*)
store i64 %35, i64* %0
%36 = getelementptr inbounds i64, i64* %0, i64 1
%37 = add nsw i64 %31, -1
%38 = load volatile i64, i64* inttoptr (i64 1074458632 to i64*)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %34
%41 = load volatile i64, i64* inttoptr (i64 1074458628 to i64*)
%42 = add i64 %41, 1
store volatile i64 %42, i64* inttoptr (i64 1074458628 to i64*)
br label %43
43: ; preds = %34, %40, %30
%44 = phi i64 [ %31, %30 ], [ %37, %40 ], [ %37, %34 ]
%45 = phi i64* [ %0, %30 ], [ %36, %40 ], [ %36, %34 ]
%46 = icmp eq i64 %31, 1
br i1 %46, label %68, label %47
47: ; preds = %43, %66
%48 = phi i64 [ %60, %66 ], [ %44, %43 ]
%49 = phi i64* [ %59, %66 ], [ %45, %43 ]
%50 = load volatile i64, i64* inttoptr (i64 1074458644 to i64*)
store i64 %50, i64* %49
%51 = getelementptr inbounds i64, i64* %49, i64 1
%52 = load volatile i64, i64* inttoptr (i64 1074458632 to i64*)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %47
%55 = load volatile i64, i64* inttoptr (i64 1074458628 to i64*)
%56 = add i64 %55, 1
store volatile i64 %56, i64* inttoptr (i64 1074458628 to i64*)
br label %57
57: ; preds = %54, %47
%58 = load volatile i64, i64* inttoptr (i64 1074458644 to i64*)
store i64 %58, i64* %51
%59 = getelementptr inbounds i64, i64* %49, i64 2
%60 = add nsw i64 %48, -2
%61 = load volatile i64, i64* inttoptr (i64 1074458632 to i64*)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %57
%64 = load volatile i64, i64* inttoptr (i64 1074458628 to i64*)
%65 = add i64 %64, 1
store volatile i64 %65, i64* inttoptr (i64 1074458628 to i64*)
br label %66
66: ; preds = %63, %57
%67 = icmp eq i64 %60, 0
br i1 %67, label %68, label %47
68: ; preds = %43, %66, %3
ret void
}