#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);
long FlashErase(unsigned long ulAddress) {
  DEBUG_ASSERT(!(ulAddress & (0x00000400 - 1)));
  (*((volatile unsigned long *)(0x400FD014))) =
      (0x00000001 | 0x00000200 | 0x00000800);
  (*((volatile unsigned long *)(0x400FD000))) = ulAddress;
  (*((volatile unsigned long *)(0x400FD008))) = 0xA4420000 | 0x00000002;
  while ((*((volatile unsigned long *)(0x400FD008))) & 0x00000002) {
  }
  if ((*((volatile unsigned long *)(0x400FD00C))) &
      (0x00000001 | 0x00000200 | 0x00000800)) {
    return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<FlashErase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
and    $0x3ff,%rax
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <DEBUG_ASSERT@plt>
mov    $0x400fd014,%eax
movq   $0xa01,(%rax)
mov    -0x10(%rbp),%rcx
mov    $0x400fd000,%eax
mov    %rcx,(%rax)
mov    $0x400fd008,%eax
mov    $0xa4420002,%ecx
mov    %rcx,(%rax)
mov    $0x400fd008,%eax
mov    (%rax),%rax
and    $0x2,%rax
cmp    $0x0,%rax
je     1179 <FlashErase+0x69>
jmp    115e <FlashErase+0x4e>
mov    $0x400fd00c,%eax
mov    (%rax),%rax
and    $0xa01,%rax
cmp    $0x0,%rax
je     119e <FlashErase+0x8e>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11a6 <FlashErase+0x96>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FlashErase>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   $0x3ff,%ebx
sete   %dil
call   1030 <DEBUG_ASSERT@plt>
movq   $0xa01,0x400fd014
mov    %rbx,0x400fd000
40
mov    $0xa4420002,%eax
mov    %rax,0x400fd008
40
cs nopw 0x0(%rax,%rax,1)
testq  $0x2,0x400fd008
jne    1150 <FlashErase+0x40>
mov    0x400fd00c,%rax
40
and    $0xa01,%eax
neg    %rax
sbb    %rax,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @FlashErase(i64 %0) {
%2 = alloca i64
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i64, i64* %3
%5 = and i64 %4, 1023
%6 = icmp ne i64 %5, 0
%7 = xor i1 %6, true
%8 = zext i1 %7 to i32
%9 = call i32 @DEBUG_ASSERT(i32 %8)
store volatile i64 2561, i64* inttoptr (i64 1074778132 to i64*)
%10 = load i64, i64* %3
store volatile i64 %10, i64* inttoptr (i64 1074778112 to i64*)
store volatile i64 2755788802, i64* inttoptr (i64 1074778120 to i64*)
br label %11
11: ; preds = %15, %1
%12 = load volatile i64, i64* inttoptr (i64 1074778120 to i64*)
%13 = and i64 %12, 2
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
br label %11
16: ; preds = %11
%17 = load volatile i64, i64* inttoptr (i64 1074778124 to i64*)
%18 = and i64 %17, 2561
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i64 -1, i64* %2
br label %22
21: ; preds = %16
store i64 0, i64* %2
br label %22
22: ; preds = %21, %20
%23 = load i64, i64* %2
ret i64 %23
}

LLVM IR (-O2):
define i64 @FlashErase(i64 %0) {
%2 = and i64 %0, 1023
%3 = icmp eq i64 %2, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @DEBUG_ASSERT(i32 %4)
store volatile i64 2561, i64* inttoptr (i64 1074778132 to i64*)
store volatile i64 %0, i64* inttoptr (i64 1074778112 to i64*)
store volatile i64 2755788802, i64* inttoptr (i64 1074778120 to i64*)
br label %6
6: ; preds = %6, %1
%7 = load volatile i64, i64* inttoptr (i64 1074778120 to i64*)
%8 = and i64 %7, 2
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %6
10: ; preds = %6
%11 = load volatile i64, i64* inttoptr (i64 1074778124 to i64*)
%12 = and i64 %11, 2561
%13 = icmp ne i64 %12, 0
%14 = sext i1 %13 to i64
ret i64 %14
}