unsigned long EEPROMProgram(unsigned long *pulData, unsigned long ulAddress,
                            unsigned long ulCount) {
  unsigned long ulStatus;
  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);
  do {
    ulStatus = (*((volatile unsigned long *)(0x400AF018)));
  } while (ulStatus & 0x00000001);
  (*((volatile unsigned long *)(0x400AF004))) = ((ulAddress) >> 6);
  (*((volatile unsigned long *)(0x400AF008))) = (((ulAddress) >> 2) & 0x0F);
  ulCount /= 4;
  while (ulCount) {
    if ((((*((volatile unsigned long *)(0x400FE000))) &
          (0x70000000 | 0x00FF0000)) == (0x10000000 | 0x00050000)) &&
        (((*((volatile unsigned long *)(0x400FE000))) &
          (0x0000FF00 | 0x000000FF)) == (0x00000000 | 0x00000000))) {
      EEPROMSetSectorMask(ulAddress);
      ulAddress += 4;
    }
    (*((volatile unsigned long *)(0x400AF014))) = *pulData;
    do {
      ulStatus = (*((volatile unsigned long *)(0x400AF018)));
    } while (ulStatus & 0x00000001);
    if (ulStatus & (0x00000010 | 0x00000100)) {
      if ((((*((volatile unsigned long *)(0x400FE000))) &
            (0x70000000 | 0x00FF0000)) == (0x10000000 | 0x00050000)) &&
          (((*((volatile unsigned long *)(0x400FE000))) &
            (0x0000FF00 | 0x000000FF)) == (0x00000000 | 0x00000000))) {
        EEPROMClearSectorMask();
      }
      return (ulStatus);
    }
    pulData++;
    ulCount--;
    if ((*((volatile unsigned long *)(0x400AF008))) == 0) {
      (*((volatile unsigned long *)(0x400AF004))) += 1;
    }
  }
  if ((((*((volatile unsigned long *)(0x400FE000))) &
        (0x70000000 | 0x00FF0000)) == (0x10000000 | 0x00050000)) &&
      (((*((volatile unsigned long *)(0x400FE000))) &
        (0x0000FF00 | 0x000000FF)) == (0x00000000 | 0x00000000))) {
    EEPROMClearSectorMask();
  }
  return ((*((volatile unsigned long *)(0x400AF018))));
}


x86 assembly (clang, -O0):
<EEPROMProgram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1040 <DEBUG_ASSERT@plt>
mov    -0x18(%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   1040 <DEBUG_ASSERT@plt>
mov    -0x18(%rbp),%rax
add    -0x20(%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   1040 <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   1040 <DEBUG_ASSERT@plt>
mov    -0x20(%rbp),%rax
and    $0x3,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1040 <DEBUG_ASSERT@plt>
mov    $0x400af018,%eax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    11e3 <EEPROMProgram+0xb3>
mov    -0x18(%rbp),%rcx
shr    $0x6,%rcx
mov    $0x400af004,%eax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
shr    $0x2,%rcx
and    $0xf,%rcx
mov    $0x400af008,%eax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
shr    $0x2,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     134f <EEPROMProgram+0x21f>
mov    $0x400fe000,%eax
mov    (%rax),%rax
and    $0x70ff0000,%rax
cmp    $0x10050000,%rax
jne    1285 <EEPROMProgram+0x155>
mov    $0x400fe000,%eax
mov    (%rax),%rax
and    $0xffff,%rax
cmp    $0x0,%rax
jne    1285 <EEPROMProgram+0x155>
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1050 <EEPROMSetSectorMask@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    $0x400af014,%eax
mov    %rcx,(%rax)
mov    $0x400af018,%eax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    1294 <EEPROMProgram+0x164>
mov    -0x28(%rbp),%rax
and    $0x110,%rax
cmp    $0x0,%rax
je     130c <EEPROMProgram+0x1dc>
mov    $0x400fe000,%eax
mov    (%rax),%rax
and    $0x70ff0000,%rax
cmp    $0x10050000,%rax
jne    12ff <EEPROMProgram+0x1cf>
mov    $0x400fe000,%eax
mov    (%rax),%rax
and    $0xffff,%rax
cmp    $0x0,%rax
jne    12ff <EEPROMProgram+0x1cf>
mov    $0x0,%al
call   1030 <EEPROMClearSectorMask@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1394 <EEPROMProgram+0x264>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    $0x400af008,%eax
mov    (%rax),%rax
cmp    $0x0,%rax
jne    134a <EEPROMProgram+0x21a>
mov    $0x400af004,%eax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    $0x400af004,%eax
mov    %rcx,(%rax)
jmp    1231 <EEPROMProgram+0x101>
mov    $0x400fe000,%eax
mov    (%rax),%rax
and    $0x70ff0000,%rax
cmp    $0x10050000,%rax
jne    1388 <EEPROMProgram+0x258>
mov    $0x400fe000,%eax
mov    (%rax),%rax
and    $0xffff,%rax
cmp    $0x0,%rax
jne    1388 <EEPROMProgram+0x258>
mov    $0x0,%al
call   1030 <EEPROMClearSectorMask@plt>
mov    $0x400af018,%eax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EEPROMProgram>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
xor    %eax,%eax
call   1040 <DEBUG_ASSERT@plt>
mov    0x400af000,%rax
40
movzwl %ax,%eax
shl    $0x2,%rax
xor    %edi,%edi
cmp    %r14,%rax
seta   %dil
xor    %eax,%eax
call   1040 <DEBUG_ASSERT@plt>
lea    (%r15,%r14,1),%rax
mov    0x400af000,%rcx
40
movzwl %cx,%ecx
shl    $0x2,%rcx
xor    %edi,%edi
cmp    %rcx,%rax
setbe  %dil
xor    %eax,%eax
call   1040 <DEBUG_ASSERT@plt>
xor    %edi,%edi
test   $0x3,%r14b
sete   %dil
xor    %eax,%eax
call   1040 <DEBUG_ASSERT@plt>
xor    %edi,%edi
test   $0x3,%r15b
sete   %dil
xor    %eax,%eax
call   1040 <DEBUG_ASSERT@plt>
nopl   0x0(%rax)
mov    0x400af018,%rax
40
test   $0x1,%al
jne    11b0 <EEPROMProgram+0x80>
mov    %r14,%rax
shr    $0x6,%rax
mov    %rax,0x400af004
40
mov    %r14d,%eax
shr    $0x2,%eax
and    $0xf,%eax
mov    %rax,0x400af008
40
cmp    $0x4,%r15
jae    1221 <EEPROMProgram+0xf1>
mov    0x400fe000,%rax
40
and    $0x70ff0000,%eax
cmp    $0x10050000,%eax
jne    120a <EEPROMProgram+0xda>
mov    0x400fe000,%rax
40
test   %ax,%ax
jne    120a <EEPROMProgram+0xda>
xor    %eax,%eax
call   1030 <EEPROMClearSectorMask@plt>
mov    0x400af018,%rbx
40
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
shr    $0x2,%r15
jmp    1239 <EEPROMProgram+0x109>
nopw   0x0(%rax,%rax,1)
add    $0x8,%r12
test   %r15,%r15
je     11e2 <EEPROMProgram+0xb2>
mov    0x400fe000,%rax
40
and    $0x70ff0000,%eax
cmp    $0x10050000,%eax
jne    1270 <EEPROMProgram+0x140>
mov    0x400fe000,%rax
40
test   %ax,%ax
jne    1270 <EEPROMProgram+0x140>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <EEPROMSetSectorMask@plt>
add    $0x4,%r14
nopl   0x0(%rax,%rax,1)
mov    (%r12),%rax
mov    %rax,0x400af014
40
nopl   0x0(%rax)
mov    0x400af018,%rbx
40
test   $0x1,%bl
jne    1280 <EEPROMProgram+0x150>
test   $0x110,%ebx
jne    12af <EEPROMProgram+0x17f>
add    $0xffffffffffffffff,%r15
cmpq   $0x0,0x400af008
jne    1230 <EEPROMProgram+0x100>
addq   $0x1,0x400af004
40 01
jmp    1230 <EEPROMProgram+0x100>
mov    0x400fe000,%rax
40
and    $0x70ff0000,%eax
cmp    $0x10050000,%eax
jne    1212 <EEPROMProgram+0xe2>
mov    0x400fe000,%rax
40
test   %ax,%ax
jne    1212 <EEPROMProgram+0xe2>
xor    %eax,%eax
call   1030 <EEPROMClearSectorMask@plt>
jmp    1212 <EEPROMProgram+0xe2>

LLVM IR (-O0):
define i64 @EEPROMProgram(i64* %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i64* %0, i64** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%9 = load i64*, i64** %5
%10 = call i32 (i64*, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i64*, ...)*)(i64* %9)
%11 = load i64, i64* %6
%12 = load volatile i64, i64* inttoptr (i64 1074458624 to i64*)
%13 = and i64 %12, 65535
%14 = lshr i64 %13, 0
%15 = mul i64 %14, 4
%16 = icmp ult i64 %11, %15
%17 = zext i1 %16 to i32
%18 = call i32 (i32, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i32, ...)*)(i32 %17)
%19 = load i64, i64* %6
%20 = load i64, i64* %7
%21 = add i64 %19, %20
%22 = load volatile i64, i64* inttoptr (i64 1074458624 to i64*)
%23 = and i64 %22, 65535
%24 = lshr i64 %23, 0
%25 = mul i64 %24, 4
%26 = icmp ule i64 %21, %25
%27 = zext i1 %26 to i32
%28 = call i32 (i32, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i32, ...)*)(i32 %27)
%29 = load i64, i64* %6
%30 = and i64 %29, 3
%31 = icmp eq i64 %30, 0
%32 = zext i1 %31 to i32
%33 = call i32 (i32, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i32, ...)*)(i32 %32)
%34 = load i64, i64* %7
%35 = and i64 %34, 3
%36 = icmp eq i64 %35, 0
%37 = zext i1 %36 to i32
%38 = call i32 (i32, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i32, ...)*)(i32 %37)
br label %39
39: ; preds = %41, %3
%40 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
store i64 %40, i64* %8
br label %41
41: ; preds = %39
%42 = load i64, i64* %8
%43 = and i64 %42, 1
%44 = icmp ne i64 %43, 0
br i1 %44, label %39, label %45
45: ; preds = %41
%46 = load i64, i64* %6
%47 = lshr i64 %46, 6
store volatile i64 %47, i64* inttoptr (i64 1074458628 to i64*)
%48 = load i64, i64* %6
%49 = lshr i64 %48, 2
%50 = and i64 %49, 15
store volatile i64 %50, i64* inttoptr (i64 1074458632 to i64*)
%51 = load i64, i64* %7
%52 = udiv i64 %51, 4
store i64 %52, i64* %7
br label %53
53: ; preds = %104, %45
%54 = load i64, i64* %7
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %105
56: ; preds = %53
%57 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%58 = and i64 %57, 1895759872
%59 = icmp eq i64 %58, 268763136
br i1 %59, label %60, label %69
60: ; preds = %56
%61 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%62 = and i64 %61, 65535
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %69
64: ; preds = %60
%65 = load i64, i64* %6
%66 = call i32 (i64, ...) bitcast (i32 (...)* @EEPROMSetSectorMask to i32 (i64, ...)*)(i64 %65)
%67 = load i64, i64* %6
%68 = add i64 %67, 4
store i64 %68, i64* %6
br label %69
69: ; preds = %64, %60, %56
%70 = load i64*, i64** %5
%71 = load i64, i64* %70
store volatile i64 %71, i64* inttoptr (i64 1074458644 to i64*)
br label %72
72: ; preds = %74, %69
%73 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
store i64 %73, i64* %8
br label %74
74: ; preds = %72
%75 = load i64, i64* %8
%76 = and i64 %75, 1
%77 = icmp ne i64 %76, 0
br i1 %77, label %72, label %78
78: ; preds = %74
%79 = load i64, i64* %8
%80 = and i64 %79, 272
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %94
82: ; preds = %78
%83 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%84 = and i64 %83, 1895759872
%85 = icmp eq i64 %84, 268763136
br i1 %85, label %86, label %92
86: ; preds = %82
%87 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%88 = and i64 %87, 65535
%89 = icmp eq i64 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %86
%91 = call i32 (...) @EEPROMClearSectorMask()
br label %92
92: ; preds = %90, %86, %82
%93 = load i64, i64* %8
store i64 %93, i64* %4
br label %117
94: ; preds = %78
%95 = load i64*, i64** %5
%96 = getelementptr inbounds i64, i64* %95, i32 1
store i64* %96, i64** %5
%97 = load i64, i64* %7
%98 = add i64 %97, -1
store i64 %98, i64* %7
%99 = load volatile i64, i64* inttoptr (i64 1074458632 to i64*)
%100 = icmp eq i64 %99, 0
br i1 %100, label %101, label %104
101: ; preds = %94
%102 = load volatile i64, i64* inttoptr (i64 1074458628 to i64*)
%103 = add i64 %102, 1
store volatile i64 %103, i64* inttoptr (i64 1074458628 to i64*)
br label %104
104: ; preds = %101, %94
br label %53
105: ; preds = %53
%106 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%107 = and i64 %106, 1895759872
%108 = icmp eq i64 %107, 268763136
br i1 %108, label %109, label %115
109: ; preds = %105
%110 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%111 = and i64 %110, 65535
%112 = icmp eq i64 %111, 0
br i1 %112, label %113, label %115
113: ; preds = %109
%114 = call i32 (...) @EEPROMClearSectorMask()
br label %115
115: ; preds = %113, %109, %105
%116 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
store i64 %116, i64* %4
br label %117
117: ; preds = %115, %92
%118 = load i64, i64* %4
ret i64 %118
}

LLVM IR (-O2):
define i64 @EEPROMProgram(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)
br label %26
26: ; preds = %26, %3
%27 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
%28 = and i64 %27, 1
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %26
30: ; preds = %26
%31 = lshr i64 %1, 6
store volatile i64 %31, i64* inttoptr (i64 1074458628 to i64*)
%32 = lshr i64 %1, 2
%33 = and i64 %32, 15
store volatile i64 %33, i64* inttoptr (i64 1074458632 to i64*)
%34 = icmp ult i64 %2, 4
br i1 %34, label %81, label %35
35: ; preds = %30
%36 = lshr i64 %2, 2
br label %37
37: ; preds = %35, %79
%38 = phi i64 [ %73, %79 ], [ %36, %35 ]
%39 = phi i64 [ %52, %79 ], [ %1, %35 ]
%40 = phi i64* [ %72, %79 ], [ %0, %35 ]
%41 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%42 = and i64 %41, 1895759872
%43 = icmp eq i64 %42, 268763136
br i1 %43, label %44, label %51
44: ; preds = %37
%45 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%46 = and i64 %45, 65535
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = tail call i32 (i64, ...) bitcast (i32 (...)* @EEPROMSetSectorMask to i32 (i64, ...)*)(i64 %39)
%50 = add i64 %39, 4
br label %51
51: ; preds = %48, %44, %37
%52 = phi i64 [ %50, %48 ], [ %39, %44 ], [ %39, %37 ]
%53 = load i64, i64* %40
store volatile i64 %53, i64* inttoptr (i64 1074458644 to i64*)
br label %54
54: ; preds = %54, %51
%55 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
%56 = and i64 %55, 1
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %54
58: ; preds = %54
%59 = and i64 %55, 272
%60 = icmp eq i64 %59, 0
br i1 %60, label %71, label %61
61: ; preds = %58
%62 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%63 = and i64 %62, 1895759872
%64 = icmp eq i64 %63, 268763136
br i1 %64, label %65, label %93
65: ; preds = %61
%66 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%67 = and i64 %66, 65535
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %93
69: ; preds = %65
%70 = tail call i32 (...) @EEPROMClearSectorMask()
br label %93
71: ; preds = %58
%72 = getelementptr inbounds i64, i64* %40, i64 1
%73 = add nsw i64 %38, -1
%74 = load volatile i64, i64* inttoptr (i64 1074458632 to i64*)
%75 = icmp eq i64 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %71
%77 = load volatile i64, i64* inttoptr (i64 1074458628 to i64*)
%78 = add i64 %77, 1
store volatile i64 %78, i64* inttoptr (i64 1074458628 to i64*)
br label %79
79: ; preds = %76, %71
%80 = icmp eq i64 %73, 0
br i1 %80, label %81, label %37
81: ; preds = %79, %30
%82 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%83 = and i64 %82, 1895759872
%84 = icmp eq i64 %83, 268763136
br i1 %84, label %85, label %91
85: ; preds = %81
%86 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%87 = and i64 %86, 65535
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %85
%90 = tail call i32 (...) @EEPROMClearSectorMask()
br label %91
91: ; preds = %89, %85, %81
%92 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
br label %93
93: ; preds = %61, %65, %69, %91
%94 = phi i64 [ %92, %91 ], [ %55, %69 ], [ %55, %65 ], [ %55, %61 ]
ret i64 %94
}