long FlashUserSave(void) {
  if (((((*((volatile unsigned long *)(0x400FE000))) & 0x70000000) ==
        0x00000000) ||
       (((*((volatile unsigned long *)(0x400FE000))) &
         (0x70000000 | 0x00FF0000)) == (0x10000000 | 0x00000000)))) {
    return (-1);
  }
  (*((volatile unsigned long *)(0x400FD000))) = 0x80000000;
  (*((volatile unsigned long *)(0x400FD008))) = 0xA4420000 | 0x00000008;
  while ((*((volatile unsigned long *)(0x400FD008))) & 0x00000008) {
  }
  (*((volatile unsigned long *)(0x400FD000))) = 0x80000001;
  (*((volatile unsigned long *)(0x400FD008))) = 0xA4420000 | 0x00000008;
  while ((*((volatile unsigned long *)(0x400FD008))) & 0x00000008) {
  }
  return (0);
}


x86 assembly (clang, -O0):
<FlashUserSave>:
push   %rbp
mov    %rsp,%rbp
mov    $0x400fe000,%eax
mov    (%rax),%rax
and    $0x70000000,%rax
cmp    $0x0,%rax
je     1136 <FlashUserSave+0x36>
mov    $0x400fe000,%eax
mov    (%rax),%rax
and    $0x70ff0000,%rax
cmp    $0x10000000,%rax
jne    1143 <FlashUserSave+0x43>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11b5 <FlashUserSave+0xb5>
mov    $0x400fd000,%eax
mov    $0x80000000,%ecx
mov    %rcx,(%rax)
mov    $0x400fd008,%eax
mov    $0xa4420008,%ecx
mov    %rcx,(%rax)
mov    $0x400fd008,%eax
mov    (%rax),%rax
and    $0x8,%rax
cmp    $0x0,%rax
je     1178 <FlashUserSave+0x78>
jmp    115d <FlashUserSave+0x5d>
mov    $0x400fd000,%eax
mov    $0x80000001,%ecx
mov    %rcx,(%rax)
mov    $0x400fd008,%eax
mov    $0xa4420008,%ecx
mov    %rcx,(%rax)
mov    $0x400fd008,%eax
mov    (%rax),%rax
and    $0x8,%rax
cmp    $0x0,%rax
je     11ad <FlashUserSave+0xad>
jmp    1192 <FlashUserSave+0x92>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<FlashUserSave>:
mov    $0xffffffffffffffff,%rax
testq  $0x70000000,0x400fe000
je     118e <FlashUserSave+0x8e>
mov    0x400fe000,%rcx
40
and    $0x70ff0000,%ecx
cmp    $0x10000000,%ecx
je     118e <FlashUserSave+0x8e>
mov    $0xa4420008,%eax
lea    -0x24420008(%rax),%rcx
mov    %rcx,0x400fd000
40
mov    %rax,0x400fd008
40
nopw   0x0(%rax,%rax,1)
testq  $0x8,0x400fd008
jne    1150 <FlashUserSave+0x50>
lea    -0x24420007(%rax),%rcx
mov    %rcx,0x400fd000
40
mov    %rax,0x400fd008
40
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
testq  $0x8,0x400fd008
jne    1180 <FlashUserSave+0x80>
ret

LLVM IR (-O0):
define i64 @FlashUserSave() {
%1 = alloca i64
%2 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%3 = and i64 %2, 1879048192
%4 = icmp eq i64 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %0
%6 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%7 = and i64 %6, 1895759872
%8 = icmp eq i64 %7, 268435456
br i1 %8, label %9, label %10
9: ; preds = %5, %0
store i64 -1, i64* %1
br label %23
10: ; preds = %5
store volatile i64 2147483648, i64* inttoptr (i64 1074778112 to i64*)
store volatile i64 2755788808, i64* inttoptr (i64 1074778120 to i64*)
br label %11
11: ; preds = %15, %10
%12 = load volatile i64, i64* inttoptr (i64 1074778120 to i64*)
%13 = and i64 %12, 8
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
br label %11
16: ; preds = %11
store volatile i64 2147483649, i64* inttoptr (i64 1074778112 to i64*)
store volatile i64 2755788808, i64* inttoptr (i64 1074778120 to i64*)
br label %17
17: ; preds = %21, %16
%18 = load volatile i64, i64* inttoptr (i64 1074778120 to i64*)
%19 = and i64 %18, 8
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
br label %17
22: ; preds = %17
store i64 0, i64* %1
br label %23
23: ; preds = %22, %9
%24 = load i64, i64* %1
ret i64 %24
}

LLVM IR (-O2):
define i64 @FlashUserSave() {
%1 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%2 = and i64 %1, 1879048192
%3 = icmp eq i64 %2, 0
br i1 %3, label %18, label %4
4: ; preds = %0
%5 = load volatile i64, i64* inttoptr (i64 1074782208 to i64*)
%6 = and i64 %5, 1895759872
%7 = icmp eq i64 %6, 268435456
br i1 %7, label %18, label %8
8: ; preds = %4
store volatile i64 2147483648, i64* inttoptr (i64 1074778112 to i64*)
store volatile i64 2755788808, i64* inttoptr (i64 1074778120 to i64*)
br label %9
9: ; preds = %9, %8
%10 = load volatile i64, i64* inttoptr (i64 1074778120 to i64*)
%11 = and i64 %10, 8
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %9
13: ; preds = %9
store volatile i64 2147483649, i64* inttoptr (i64 1074778112 to i64*)
store volatile i64 2755788808, i64* inttoptr (i64 1074778120 to i64*)
br label %14
14: ; preds = %14, %13
%15 = load volatile i64, i64* inttoptr (i64 1074778120 to i64*)
%16 = and i64 %15, 8
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %14
18: ; preds = %14, %0, %4
%19 = phi i64 [ -1, %4 ], [ -1, %0 ], [ 0, %14 ]
ret i64 %19
}