#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*/ EEPROMClearSectorMask();
int /*<<< orphan*/ EEPROMSetSectorMask(unsigned long);
unsigned long EEPROMProgram(unsigned long *pulData, unsigned long ulAddress,
                            unsigned long ulCount) {
  unsigned long ulStatus;
  ;
  ;
  ;
  ;
  ;
  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    $0x400af018,%eax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    1134 <EEPROMProgram+0x14>
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     129e <EEPROMProgram+0x17e>
mov    $0x400fe000,%eax
mov    (%rax),%rax
and    $0x70ff0000,%rax
cmp    $0x10050000,%rax
jne    11d4 <EEPROMProgram+0xb4>
mov    $0x400fe000,%eax
mov    (%rax),%rax
and    $0xffff,%rax
cmp    $0x0,%rax
jne    11d4 <EEPROMProgram+0xb4>
mov    -0x18(%rbp),%rdi
call   1040 <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    11e3 <EEPROMProgram+0xc3>
mov    -0x28(%rbp),%rax
and    $0x110,%rax
cmp    $0x0,%rax
je     125b <EEPROMProgram+0x13b>
mov    $0x400fe000,%eax
mov    (%rax),%rax
and    $0x70ff0000,%rax
cmp    $0x10050000,%rax
jne    124e <EEPROMProgram+0x12e>
mov    $0x400fe000,%eax
mov    (%rax),%rax
and    $0xffff,%rax
cmp    $0x0,%rax
jne    124e <EEPROMProgram+0x12e>
mov    $0x0,%al
call   1030 <EEPROMClearSectorMask@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12e3 <EEPROMProgram+0x1c3>
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    1299 <EEPROMProgram+0x179>
mov    $0x400af004,%eax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    $0x400af004,%eax
mov    %rcx,(%rax)
jmp    1182 <EEPROMProgram+0x62>
mov    $0x400fe000,%eax
mov    (%rax),%rax
and    $0x70ff0000,%rax
cmp    $0x10050000,%rax
jne    12d7 <EEPROMProgram+0x1b7>
mov    $0x400fe000,%eax
mov    (%rax),%rax
and    $0xffff,%rax
cmp    $0x0,%rax
jne    12d7 <EEPROMProgram+0x1b7>
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
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x400af018,%rax
40
test   $0x1,%al
jne    1140 <EEPROMProgram+0x20>
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    11b1 <EEPROMProgram+0x91>
mov    0x400fe000,%rax
40
and    $0x70ff0000,%eax
cmp    $0x10050000,%eax
jne    119a <EEPROMProgram+0x7a>
mov    0x400fe000,%rax
40
test   %ax,%ax
jne    119a <EEPROMProgram+0x7a>
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    11c9 <EEPROMProgram+0xa9>
nopw   0x0(%rax,%rax,1)
add    $0x8,%r12
test   %r15,%r15
je     1172 <EEPROMProgram+0x52>
mov    0x400fe000,%rax
40
and    $0x70ff0000,%eax
cmp    $0x10050000,%eax
jne    1200 <EEPROMProgram+0xe0>
mov    0x400fe000,%rax
40
test   %ax,%ax
jne    1200 <EEPROMProgram+0xe0>
mov    %r14,%rdi
call   1040 <EEPROMSetSectorMask@plt>
add    $0x4,%r14
cs nopw 0x0(%rax,%rax,1)
mov    (%r12),%rax
mov    %rax,0x400af014
40
nopl   0x0(%rax)
mov    0x400af018,%rbx
40
test   $0x1,%bl
jne    1210 <EEPROMProgram+0xf0>
test   $0x110,%ebx
jne    123f <EEPROMProgram+0x11f>
add    $0xffffffffffffffff,%r15
cmpq   $0x0,0x400af008
jne    11c0 <EEPROMProgram+0xa0>
addq   $0x1,0x400af004
40 01
jmp    11c0 <EEPROMProgram+0xa0>
mov    0x400fe000,%rax
40
and    $0x70ff0000,%eax
cmp    $0x10050000,%eax
jne    11a2 <EEPROMProgram+0x82>
mov    0x400fe000,%rax
40
test   %ax,%ax
jne    11a2 <EEPROMProgram+0x82>
xor    %eax,%eax
call   1030 <EEPROMClearSectorMask@plt>
jmp    11a2 <EEPROMProgram+0x82>

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
br label %9
9: ; preds = %11, %3
%10 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
store i64 %10, i64* %8
br label %11
11: ; preds = %9
%12 = load i64, i64* %8
%13 = and i64 %12, 1
%14 = icmp ne i64 %13, 0
br i1 %14, label %9, label %15
15: ; preds = %11
%16 = load i64, i64* %6
%17 = lshr i64 %16, 6
store volatile i64 %17, i64* inttoptr (i64 1074458628 to i64*)
%18 = load i64, i64* %6
%19 = lshr i64 %18, 2
%20 = and i64 %19, 15
store volatile i64 %20, i64* inttoptr (i64 1074458632 to i64*)
%21 = load i64, i64* %7
%22 = udiv i64 %21, 4
store i64 %22, i64* %7
br label %23
23: ; preds = %74, %15
%24 = load i64, i64* %7
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %75
26: ; preds = %23
%27 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%28 = and i64 %27, 1895759872
%29 = icmp eq i64 %28, 268763136
br i1 %29, label %30, label %39
30: ; preds = %26
%31 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%32 = and i64 %31, 65535
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i64, i64* %6
%36 = call i32 @EEPROMSetSectorMask(i64 %35)
%37 = load i64, i64* %6
%38 = add i64 %37, 4
store i64 %38, i64* %6
br label %39
39: ; preds = %34, %30, %26
%40 = load i64*, i64** %5
%41 = load i64, i64* %40
store volatile i64 %41, i64* inttoptr (i64 1074458644 to i64*)
br label %42
42: ; preds = %44, %39
%43 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
store i64 %43, i64* %8
br label %44
44: ; preds = %42
%45 = load i64, i64* %8
%46 = and i64 %45, 1
%47 = icmp ne i64 %46, 0
br i1 %47, label %42, label %48
48: ; preds = %44
%49 = load i64, i64* %8
%50 = and i64 %49, 272
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %64
52: ; preds = %48
%53 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%54 = and i64 %53, 1895759872
%55 = icmp eq i64 %54, 268763136
br i1 %55, label %56, label %62
56: ; preds = %52
%57 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%58 = and i64 %57, 65535
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = call i32 (...) @EEPROMClearSectorMask()
br label %62
62: ; preds = %60, %56, %52
%63 = load i64, i64* %8
store i64 %63, i64* %4
br label %87
64: ; preds = %48
%65 = load i64*, i64** %5
%66 = getelementptr inbounds i64, i64* %65, i32 1
store i64* %66, i64** %5
%67 = load i64, i64* %7
%68 = add i64 %67, -1
store i64 %68, i64* %7
%69 = load volatile i64, i64* inttoptr (i64 1074458632 to i64*)
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %64
%72 = load volatile i64, i64* inttoptr (i64 1074458628 to i64*)
%73 = add i64 %72, 1
store volatile i64 %73, i64* inttoptr (i64 1074458628 to i64*)
br label %74
74: ; preds = %71, %64
br label %23
75: ; preds = %23
%76 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%77 = and i64 %76, 1895759872
%78 = icmp eq i64 %77, 268763136
br i1 %78, label %79, label %85
79: ; preds = %75
%80 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%81 = and i64 %80, 65535
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %79
%84 = call i32 (...) @EEPROMClearSectorMask()
br label %85
85: ; preds = %83, %79, %75
%86 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
store i64 %86, i64* %4
br label %87
87: ; preds = %85, %62
%88 = load i64, i64* %4
ret i64 %88
}

LLVM IR (-O2):
define i64 @EEPROMProgram(i64* nocapture %0, i64 %1, i64 %2) {
br label %4
4: ; preds = %4, %3
%5 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
%6 = and i64 %5, 1
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %4
8: ; preds = %4
%9 = lshr i64 %1, 6
store volatile i64 %9, i64* inttoptr (i64 1074458628 to i64*)
%10 = lshr i64 %1, 2
%11 = and i64 %10, 15
store volatile i64 %11, i64* inttoptr (i64 1074458632 to i64*)
%12 = icmp ult i64 %2, 4
br i1 %12, label %59, label %13
13: ; preds = %8
%14 = lshr i64 %2, 2
br label %15
15: ; preds = %13, %57
%16 = phi i64 [ %51, %57 ], [ %14, %13 ]
%17 = phi i64 [ %30, %57 ], [ %1, %13 ]
%18 = phi i64* [ %50, %57 ], [ %0, %13 ]
%19 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%20 = and i64 %19, 1895759872
%21 = icmp eq i64 %20, 268763136
br i1 %21, label %22, label %29
22: ; preds = %15
%23 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%24 = and i64 %23, 65535
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = tail call i32 @EEPROMSetSectorMask(i64 %17)
%28 = add i64 %17, 4
br label %29
29: ; preds = %26, %22, %15
%30 = phi i64 [ %28, %26 ], [ %17, %22 ], [ %17, %15 ]
%31 = load i64, i64* %18
store volatile i64 %31, i64* inttoptr (i64 1074458644 to i64*)
br label %32
32: ; preds = %32, %29
%33 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
%34 = and i64 %33, 1
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %32
36: ; preds = %32
%37 = and i64 %33, 272
%38 = icmp eq i64 %37, 0
br i1 %38, label %49, label %39
39: ; preds = %36
%40 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%41 = and i64 %40, 1895759872
%42 = icmp eq i64 %41, 268763136
br i1 %42, label %43, label %71
43: ; preds = %39
%44 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%45 = and i64 %44, 65535
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %71
47: ; preds = %43
%48 = tail call i32 (...) @EEPROMClearSectorMask()
br label %71
49: ; preds = %36
%50 = getelementptr inbounds i64, i64* %18, i64 1
%51 = add nsw i64 %16, -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 = %49
%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, %49
%58 = icmp eq i64 %51, 0
br i1 %58, label %59, label %15
59: ; preds = %57, %8
%60 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%61 = and i64 %60, 1895759872
%62 = icmp eq i64 %61, 268763136
br i1 %62, label %63, label %69
63: ; preds = %59
%64 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%65 = and i64 %64, 65535
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %63
%68 = tail call i32 (...) @EEPROMClearSectorMask()
br label %69
69: ; preds = %67, %63, %59
%70 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
br label %71
71: ; preds = %39, %43, %47, %69
%72 = phi i64 [ %70, %69 ], [ %33, %47 ], [ %33, %43 ], [ %33, %39 ]
ret i64 %72
}