#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*/ DEBUG_ASSERT(int);
unsigned long EEPROMBlockProtectSet(unsigned long ulBlock,
                                    unsigned long ulProtect) {
  DEBUG_ASSERT(
      ulBlock <
      ((((*((volatile unsigned long *)(0x400AF000)))) & 0x07FF0000) >> 16));
  (*((volatile unsigned long *)(0x400AF004))) = ulBlock;
  (*((volatile unsigned long *)(0x400AF030))) = ulProtect;
  while ((*((volatile unsigned long *)(0x400AF018))) & 0x00000001) {
  }
  return ((*((volatile unsigned long *)(0x400AF018))));
}


x86 assembly (clang, -O0):
<EEPROMBlockProtectSet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
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
call   1030 <DEBUG_ASSERT@plt>
mov    -0x8(%rbp),%rcx
mov    $0x400af004,%eax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rcx
mov    $0x400af030,%eax
mov    %rcx,(%rax)
mov    $0x400af018,%eax
mov    (%rax),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     117a <EEPROMBlockProtectSet+0x6a>
jmp    115f <EEPROMBlockProtectSet+0x4f>
mov    $0x400af018,%eax
mov    (%rax),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EEPROMBlockProtectSet>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x400af000,%rax
40
shr    $0x10,%eax
and    $0x7ff,%eax
xor    %edi,%edi
cmp    %rbx,%rax
seta   %dil
call   1030 <DEBUG_ASSERT@plt>
mov    %rbx,0x400af004
40
mov    %r14,0x400af030
40
nopl   0x0(%rax,%rax,1)
mov    0x400af018,%rax
40
test   $0x1,%al
jne    1150 <EEPROMBlockProtectSet+0x40>
mov    0x400af018,%rax
40
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @EEPROMBlockProtectSet(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%5 = load i64, i64* %3
%6 = load volatile i64, i64* inttoptr (i64 1074458624 to i64*)
%7 = and i64 %6, 134152192
%8 = lshr i64 %7, 16
%9 = icmp ult i64 %5, %8
%10 = zext i1 %9 to i32
%11 = call i32 @DEBUG_ASSERT(i32 %10)
%12 = load i64, i64* %3
store volatile i64 %12, i64* inttoptr (i64 1074458628 to i64*)
%13 = load i64, i64* %4
store volatile i64 %13, i64* inttoptr (i64 1074458672 to i64*)
br label %14
14: ; preds = %18, %2
%15 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
%16 = and i64 %15, 1
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
br label %14
19: ; preds = %14
%20 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
ret i64 %20
}

LLVM IR (-O2):
define i64 @EEPROMBlockProtectSet(i64 %0, i64 %1) {
%3 = load volatile i64, i64* inttoptr (i64 1074458624 to i64*)
%4 = lshr i64 %3, 16
%5 = and i64 %4, 2047
%6 = icmp ugt i64 %5, %0
%7 = zext i1 %6 to i32
%8 = tail call i32 @DEBUG_ASSERT(i32 %7)
store volatile i64 %0, i64* inttoptr (i64 1074458628 to i64*)
store volatile i64 %1, i64* inttoptr (i64 1074458672 to i64*)
br label %9
9: ; preds = %9, %2
%10 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
%11 = and i64 %10, 1
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %9
13: ; preds = %9
%14 = load volatile i64, i64* inttoptr (i64 1074458648 to i64*)
ret i64 %14
}