unsigned long EEPROMBlockPasswordSet(unsigned long ulBlock,
                                     unsigned long *pulPassword,
                                     unsigned long ulCount) {
  unsigned long ulReg;
  DEBUG_ASSERT(pulPassword);
  DEBUG_ASSERT(
      ulBlock <
      ((((*((volatile unsigned long *)(0x400AF000)))) & 0x07FF0000) >> 16));
  DEBUG_ASSERT(ulCount <= 3);
  (*((volatile unsigned long *)(0x400AF004))) = ulBlock;
  ulReg = 0x400AF034;
  while (ulCount) {
    (*((volatile unsigned long *)(ulReg))) = *pulPassword;
    pulPassword++;
    ulReg += 4;
    ulCount--;
    while ((*((volatile unsigned long *)(0x400AF018))) & 0x00000001) {
    }
  }
  return ((*((volatile unsigned long *)(0x400AF018))));
}


x86 assembly (clang, -O0):
<EEPROMBlockPasswordSet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1030 <DEBUG_ASSERT@plt>
mov    -0x8(%rbp),%rax
mov    $0x400af000,%ecx
mov    (%rcx),%rcx
and    $0x7ff0000,%rcx
shr    $0x10,%rcx
cmp    %rcx,%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <DEBUG_ASSERT@plt>
cmpq   $0x3,-0x18(%rbp)
setbe  %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <DEBUG_ASSERT@plt>
mov    -0x8(%rbp),%rcx
mov    $0x400af004,%eax
mov    %rcx,(%rax)
movq   $0x400af034,-0x20(%rbp)
40
cmpq   $0x0,-0x18(%rbp)
je     11dd <EEPROMBlockPasswordSet+0xcd>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    $0x400af018,%eax
mov    (%rax),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     11d8 <EEPROMBlockPasswordSet+0xc8>
jmp    11bd <EEPROMBlockPasswordSet+0xad>
jmp    1180 <EEPROMBlockPasswordSet+0x70>
mov    $0x400af018,%eax
mov    (%rax),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EEPROMBlockPasswordSet>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
xor    %eax,%eax
call   1030 <DEBUG_ASSERT@plt>
mov    0x400af000,%rax
40
shr    $0x10,%eax
and    $0x7ff,%eax
xor    %edi,%edi
cmp    %r15,%rax
seta   %dil
xor    %eax,%eax
call   1030 <DEBUG_ASSERT@plt>
xor    %edi,%edi
cmp    $0x4,%r14
setb   %dil
xor    %eax,%eax
call   1030 <DEBUG_ASSERT@plt>
mov    %r15,0x400af004
40
test   %r14,%r14
je     11fc <EEPROMBlockPasswordSet+0xec>
mov    $0x400af034,%eax
cmp    $0x1,%r14
je     11db <EEPROMBlockPasswordSet+0xcb>
mov    %r14,%rcx
and    $0xfffffffffffffffe,%rcx
mov    $0x400af034,%eax
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rbx),%rsi
mov    %rsi,(%rax)
cs nopw 0x0(%rax,%rax,1)
testq  $0x1,0x400af018
jne    11a0 <EEPROMBlockPasswordSet+0x90>
mov    0x8(%rbx),%rsi
mov    %rsi,0x4(%rax)
add    $0x8,%rax
nopw   0x0(%rax,%rax,1)
mov    0x400af018,%rsi
40
test   $0x1,%sil
jne    11c0 <EEPROMBlockPasswordSet+0xb0>
add    $0x10,%rbx
add    $0x2,%rdx
cmp    %rcx,%rdx
jne    1190 <EEPROMBlockPasswordSet+0x80>
test   $0x1,%r14b
je     11fc <EEPROMBlockPasswordSet+0xec>
mov    (%rbx),%rcx
mov    %rcx,(%rax)
nopw   0x0(%rax,%rax,1)
mov    0x400af018,%rax
40
test   $0x1,%al
jne    11f0 <EEPROMBlockPasswordSet+0xe0>
mov    0x400af018,%rax
40
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @EEPROMBlockPasswordSet(i64 %0, i64* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %4
store i64* %1, i64** %5
store i64 %2, i64* %6
%8 = load i64*, i64** %5
%9 = call i32 (i64*, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i64*, ...)*)(i64* %8)
%10 = load i64, i64* %4
%11 = load volatile i64, i64* inttoptr (i64 1074458624 to i64*)
%12 = and i64 %11, 134152192
%13 = lshr i64 %12, 16
%14 = icmp ult i64 %10, %13
%15 = zext i1 %14 to i32
%16 = call i32 (i32, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i32, ...)*)(i32 %15)
%17 = load i64, i64* %6
%18 = icmp ule i64 %17, 3
%19 = zext i1 %18 to i32
%20 = call i32 (i32, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i32, ...)*)(i32 %19)
%21 = load i64, i64* %4
store volatile i64 %21, i64* inttoptr (i64 1074458628 to i64*)
store i64 1074458676, i64* %7
br label %22
22: ; preds = %41, %3
%23 = load i64, i64* %6
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %42
25: ; preds = %22
%26 = load i64*, i64** %5
%27 = load i64, i64* %26
%28 = load i64, i64* %7
%29 = inttoptr i64 %28 to i64*
store volatile i64 %27, i64* %29
%30 = load i64*, i64** %5
%31 = getelementptr inbounds i64, i64* %30, i32 1
store i64* %31, i64** %5
%32 = load i64, i64* %7
%33 = add i64 %32, 4
store i64 %33, i64* %7
%34 = load i64, i64* %6
%35 = add i64 %34, -1
store i64 %35, i64* %6
br label %36
36: ; preds = %40, %25
%37 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
%38 = and i64 %37, 1
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %36
br label %36
41: ; preds = %36
br label %22
42: ; preds = %22
%43 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
ret i64 %43
}

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