unsigned long EEPROMBlockUnlock(unsigned long ulBlock,
                                unsigned long *pulPassword,
                                unsigned long ulCount) {
  DEBUG_ASSERT(pulPassword);
  DEBUG_ASSERT(
      ulBlock <
      ((((*((volatile unsigned long *)(0x400AF000)))) & 0x07FF0000) >> 16));
  DEBUG_ASSERT(ulCount <= 3);
  (*((volatile unsigned long *)(0x400AF004))) = ulBlock;
  (*((volatile unsigned long *)(0x400AF020))) = 0xFFFFFFFF;
  pulPassword += (ulCount - 1);
  while (ulCount) {
    (*((volatile unsigned long *)(0x400AF020))) = *pulPassword--;
    ulCount--;
  }
  return ((*((volatile unsigned long *)(0x400AF020))));
}


x86 assembly (clang, -O0):
<EEPROMBlockUnlock>:
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)
mov    $0x400af020,%eax
mov    $0xffffffff,%ecx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cf <EEPROMBlockUnlock+0xbf>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xfffffffffffffff8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rcx
mov    $0x400af020,%eax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1199 <EEPROMBlockUnlock+0x89>
mov    $0x400af020,%eax
mov    (%rax),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EEPROMBlockUnlock>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
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,%rbx
setb   %dil
xor    %eax,%eax
call   1030 <DEBUG_ASSERT@plt>
mov    %r15,0x400af004
40
mov    $0xffffffff,%eax
mov    %rax,0x400af020
40
test   %rbx,%rbx
je     1230 <EEPROMBlockUnlock+0x120>
lea    -0x1(%rbx),%rcx
lea    (%r14,%rbx,8),%rax
add    $0xfffffffffffffff8,%rax
mov    %rbx,%rdx
and    $0x7,%rdx
je     11ab <EEPROMBlockUnlock+0x9b>
xor    %esi,%esi
xchg   %ax,%ax
mov    (%rax),%rdi
add    $0xfffffffffffffff8,%rax
mov    %rdi,0x400af020
40
add    $0x1,%rsi
cmp    %rsi,%rdx
jne    1190 <EEPROMBlockUnlock+0x80>
sub    %rsi,%rbx
cmp    $0x7,%rcx
jb     1230 <EEPROMBlockUnlock+0x120>
neg    %rbx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
mov    (%rax,%rcx,8),%rdx
mov    %rdx,0x400af020
40
mov    -0x8(%rax,%rcx,8),%rdx
mov    %rdx,0x400af020
40
mov    -0x10(%rax,%rcx,8),%rdx
mov    %rdx,0x400af020
40
mov    -0x18(%rax,%rcx,8),%rdx
mov    %rdx,0x400af020
40
mov    -0x20(%rax,%rcx,8),%rdx
mov    %rdx,0x400af020
40
mov    -0x28(%rax,%rcx,8),%rdx
mov    %rdx,0x400af020
40
mov    -0x30(%rax,%rcx,8),%rdx
mov    %rdx,0x400af020
40
mov    -0x38(%rax,%rcx,8),%rdx
mov    %rdx,0x400af020
40
add    $0xfffffffffffffff8,%rcx
cmp    %rcx,%rbx
jne    11c0 <EEPROMBlockUnlock+0xb0>
mov    0x400af020,%rax
40
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @EEPROMBlockUnlock(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** %5
%8 = call i32 (i64*, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i64*, ...)*)(i64* %7)
%9 = load i64, i64* %4
%10 = load volatile i64, i64* inttoptr (i64 1074458624 to i64*)
%11 = and i64 %10, 134152192
%12 = lshr i64 %11, 16
%13 = icmp ult i64 %9, %12
%14 = zext i1 %13 to i32
%15 = call i32 (i32, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i32, ...)*)(i32 %14)
%16 = load i64, i64* %6
%17 = icmp ule i64 %16, 3
%18 = zext i1 %17 to i32
%19 = call i32 (i32, ...) bitcast (i32 (...)* @DEBUG_ASSERT to i32 (i32, ...)*)(i32 %18)
%20 = load i64, i64* %4
store volatile i64 %20, i64* inttoptr (i64 1074458628 to i64*)
store volatile i64 4294967295, i64* inttoptr (i64 1074458656 to i64*)
%21 = load i64, i64* %6
%22 = sub i64 %21, 1
%23 = load i64*, i64** %5
%24 = getelementptr inbounds i64, i64* %23, i64 %22
store i64* %24, i64** %5
br label %25
25: ; preds = %28, %3
%26 = load i64, i64* %6
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i64*, i64** %5
%30 = getelementptr inbounds i64, i64* %29, i32 -1
store i64* %30, i64** %5
%31 = load i64, i64* %29
store volatile i64 %31, i64* inttoptr (i64 1074458656 to i64*)
%32 = load i64, i64* %6
%33 = add i64 %32, -1
store i64 %33, i64* %6
br label %25
34: ; preds = %25
%35 = load volatile i64, i64* inttoptr (i64 1074458656 to i64*)
ret i64 %35
}

LLVM IR (-O2):
define i64 @EEPROMBlockUnlock(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*)
store volatile i64 4294967295, i64* inttoptr (i64 1074458656 to i64*)
%14 = icmp eq i64 %2, 0
br i1 %14, label %54, label %15
15: ; preds = %3
%16 = add i64 %2, -1
%17 = getelementptr inbounds i64, i64* %1, i64 %16
%18 = and i64 %2, 7
%19 = icmp eq i64 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %15, %20
%21 = phi i64 [ %26, %20 ], [ %2, %15 ]
%22 = phi i64* [ %24, %20 ], [ %17, %15 ]
%23 = phi i64 [ %27, %20 ], [ 0, %15 ]
%24 = getelementptr inbounds i64, i64* %22, i64 -1
%25 = load i64, i64* %22
store volatile i64 %25, i64* inttoptr (i64 1074458656 to i64*)
%26 = add i64 %21, -1
%27 = add i64 %23, 1
%28 = icmp eq i64 %27, %18
br i1 %28, label %29, label %20
29: ; preds = %20, %15
%30 = phi i64 [ %2, %15 ], [ %26, %20 ]
%31 = phi i64* [ %17, %15 ], [ %24, %20 ]
%32 = icmp ult i64 %16, 7
br i1 %32, label %54, label %33
33: ; preds = %29, %33
%34 = phi i64 [ %52, %33 ], [ %30, %29 ]
%35 = phi i64* [ %50, %33 ], [ %31, %29 ]
%36 = getelementptr inbounds i64, i64* %35, i64 -1
%37 = load i64, i64* %35
store volatile i64 %37, i64* inttoptr (i64 1074458656 to i64*)
%38 = getelementptr inbounds i64, i64* %35, i64 -2
%39 = load i64, i64* %36
store volatile i64 %39, i64* inttoptr (i64 1074458656 to i64*)
%40 = getelementptr inbounds i64, i64* %35, i64 -3
%41 = load i64, i64* %38
store volatile i64 %41, i64* inttoptr (i64 1074458656 to i64*)
%42 = getelementptr inbounds i64, i64* %35, i64 -4
%43 = load i64, i64* %40
store volatile i64 %43, i64* inttoptr (i64 1074458656 to i64*)
%44 = getelementptr inbounds i64, i64* %35, i64 -5
%45 = load i64, i64* %42
store volatile i64 %45, i64* inttoptr (i64 1074458656 to i64*)
%46 = getelementptr inbounds i64, i64* %35, i64 -6
%47 = load i64, i64* %44
store volatile i64 %47, i64* inttoptr (i64 1074458656 to i64*)
%48 = getelementptr inbounds i64, i64* %35, i64 -7
%49 = load i64, i64* %46
store volatile i64 %49, i64* inttoptr (i64 1074458656 to i64*)
%50 = getelementptr inbounds i64, i64* %35, i64 -8
%51 = load i64, i64* %48
store volatile i64 %51, i64* inttoptr (i64 1074458656 to i64*)
%52 = add i64 %34, -8
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %33
54: ; preds = %29, %33, %3
%55 = load volatile i64, i64* inttoptr (i64 1074458656 to i64*)
ret i64 %55
}