long FlashProgram(unsigned long *pulData, unsigned long ulAddress,
                  unsigned long ulCount) {
  ;
  ;
  (*((volatile unsigned long *)(0x400FD000 + 0x00000014))) =
      (0x00000001 | 0x00000200 | 0x00000400 | 0x00002000);
  {
    while (ulCount) {
      (*((volatile unsigned long *)(0x400FD000 + 0x00000000))) =
          ulAddress & ~(0x7F);
      while (
          ((ulAddress & 0x7C) ||
           ((*((volatile unsigned long *)(0x400FD000 + 0x00000030))) == 0)) &&
          (ulCount != 0)) {
        (*((volatile unsigned long *)(0x400FD000 + 0x00000100 +
                                      (ulAddress & 0x7C)))) = *pulData++;
        ulAddress += 4;
        ulCount -= 4;
      }
      (*((volatile unsigned long *)(0x400FD000 + 0x00000020))) =
          0xA4420000 | 0x00000001;
      while ((*((volatile unsigned long *)(0x400FD000 + 0x00000020))) &
             0x00000001) {
      }
    }
  }
  if ((*((volatile unsigned long *)(0x400FD000 + 0x0000000C))) &
      (0x00000001 | 0x00000200 | 0x00000400 | 0x00002000)) {
    return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<FlashProgram>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x400fd014,%eax
movq   $0x2601,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     11e8 <FlashProgram+0xe8>
mov    -0x18(%rbp),%rcx
and    $0xffffffffffffff80,%rcx
mov    $0x400fd000,%eax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
and    $0x7c,%rax
cmp    $0x0,%rax
jne    1160 <FlashProgram+0x60>
mov    $0x400fd030,%eax
mov    (%rax),%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jne    116b <FlashProgram+0x6b>
cmpq   $0x0,-0x20(%rbp)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    117b <FlashProgram+0x7b>
jmp    11bb <FlashProgram+0xbb>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
and    $0x7c,%rax
add    $0x400fd100,%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
sub    $0x4,%rax
mov    %rax,-0x20(%rbp)
jmp    1137 <FlashProgram+0x37>
mov    $0x400fd020,%eax
mov    $0xa4420001,%ecx
mov    %rcx,(%rax)
mov    $0x400fd020,%eax
mov    (%rax),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     11e3 <FlashProgram+0xe3>
jmp    11c8 <FlashProgram+0xc8>
jmp    111c <FlashProgram+0x1c>
mov    $0x400fd00c,%eax
mov    (%rax),%rax
and    $0x2601,%rax
cmp    $0x0,%rax
je     120d <FlashProgram+0x10d>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1215 <FlashProgram+0x115>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<FlashProgram>:
movq   $0x2601,0x400fd014
test   %rdx,%rdx
je     11a7 <FlashProgram+0xa7>
mov    $0xa4420001,%r8d
nopl   0x0(%rax,%rax,1)
mov    %rsi,%rcx
and    $0xffffffffffffff80,%rcx
mov    %rcx,0x400fd000
40
jmp    115e <FlashProgram+0x5e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %rdx,%rdx
je     1180 <FlashProgram+0x80>
mov    (%rdi),%rax
add    $0x8,%rdi
or     $0x400fd100,%rcx
mov    %rax,(%rcx)
add    $0x4,%rsi
add    $0xfffffffffffffffc,%rdx
mov    %rsi,%rcx
and    $0x7c,%rcx
jne    1140 <FlashProgram+0x40>
cmpq   $0x0,0x400fd030
jne    1182 <FlashProgram+0x82>
test   %rdx,%rdx
jne    1145 <FlashProgram+0x45>
jmp    1182 <FlashProgram+0x82>
nopl   0x0(%rax)
xor    %edx,%edx
mov    %r8,0x400fd020
40
nopw   0x0(%rax,%rax,1)
testq  $0x1,0x400fd020
jne    1190 <FlashProgram+0x90>
test   %rdx,%rdx
jne    1120 <FlashProgram+0x20>
mov    0x400fd00c,%rax
40
and    $0x2601,%eax
neg    %rax
sbb    %rax,%rax
ret

LLVM IR (-O0):
define i64 @FlashProgram(i64* %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i64
store i64* %0, i64** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store volatile i64 9729, i64* inttoptr (i64 1074778132 to i64*)
br label %8
8: ; preds = %44, %3
%9 = load i64, i64* %7
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %45
11: ; preds = %8
%12 = load i64, i64* %6
%13 = and i64 %12, -128
store volatile i64 %13, i64* inttoptr (i64 1074778112 to i64*)
br label %14
14: ; preds = %26, %11
%15 = load i64, i64* %6
%16 = and i64 %15, 124
%17 = icmp ne i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = load volatile i64, i64* inttoptr (i64 1074778160 to i64*)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18, %14
%22 = load i64, i64* %7
%23 = icmp ne i64 %22, 0
br label %24
24: ; preds = %21, %18
%25 = phi i1 [ false, %18 ], [ %23, %21 ]
br i1 %25, label %26, label %38
26: ; preds = %24
%27 = load i64*, i64** %5
%28 = getelementptr inbounds i64, i64* %27, i32 1
store i64* %28, i64** %5
%29 = load i64, i64* %27
%30 = load i64, i64* %6
%31 = and i64 %30, 124
%32 = add i64 1074778368, %31
%33 = inttoptr i64 %32 to i64*
store volatile i64 %29, i64* %33
%34 = load i64, i64* %6
%35 = add i64 %34, 4
store i64 %35, i64* %6
%36 = load i64, i64* %7
%37 = sub i64 %36, 4
store i64 %37, i64* %7
br label %14
38: ; preds = %24
store volatile i64 2755788801, i64* inttoptr (i64 1074778144 to i64*)
br label %39
39: ; preds = %43, %38
%40 = load volatile i64, i64* inttoptr (i64 1074778144 to i64*)
%41 = and i64 %40, 1
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %39
br label %39
44: ; preds = %39
br label %8
45: ; preds = %8
%46 = load volatile i64, i64* inttoptr (i64 1074778124 to i64*)
%47 = and i64 %46, 9729
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %45
store i64 -1, i64* %4
br label %51
50: ; preds = %45
store i64 0, i64* %4
br label %51
51: ; preds = %50, %49
%52 = load i64, i64* %4
ret i64 %52
}

LLVM IR (-O2):
define i64 @FlashProgram(i64* nocapture %0, i64 %1, i64 %2) {
store volatile i64 9729, i64* inttoptr (i64 1074778132 to i64*)
%4 = icmp eq i64 %2, 0
br i1 %4, label %38, label %7
5: ; preds = %34
%6 = icmp eq i64 %33, 0
br i1 %6, label %38, label %7
7: ; preds = %3, %5
%8 = phi i64 [ %33, %5 ], [ %2, %3 ]
%9 = phi i64 [ %14, %5 ], [ %1, %3 ]
%10 = phi i64* [ %13, %5 ], [ %0, %3 ]
%11 = and i64 %9, -128
store volatile i64 %11, i64* inttoptr (i64 1074778112 to i64*)
br label %12
12: ; preds = %25, %7
%13 = phi i64* [ %10, %7 ], [ %26, %25 ]
%14 = phi i64 [ %9, %7 ], [ %30, %25 ]
%15 = phi i64 [ %8, %7 ], [ %31, %25 ]
%16 = and i64 %14, 124
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = load volatile i64, i64* inttoptr (i64 1074778160 to i64*)
%20 = icmp eq i64 %19, 0
%21 = icmp ne i64 %15, 0
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %25, label %32
23: ; preds = %12
%24 = icmp eq i64 %15, 0
br i1 %24, label %32, label %25
25: ; preds = %18, %23
%26 = getelementptr inbounds i64, i64* %13, i64 1
%27 = load i64, i64* %13
%28 = or i64 %16, 1074778368
%29 = inttoptr i64 %28 to i64*
store volatile i64 %27, i64* %29
%30 = add i64 %14, 4
%31 = add i64 %15, -4
br label %12
32: ; preds = %18, %23
%33 = phi i64 [ %15, %18 ], [ 0, %23 ]
store volatile i64 2755788801, i64* inttoptr (i64 1074778144 to i64*)
br label %34
34: ; preds = %34, %32
%35 = load volatile i64, i64* inttoptr (i64 1074778144 to i64*)
%36 = and i64 %35, 1
%37 = icmp eq i64 %36, 0
br i1 %37, label %5, label %34
38: ; preds = %5, %3
%39 = load volatile i64, i64* inttoptr (i64 1074778124 to i64*)
%40 = and i64 %39, 9729
%41 = icmp ne i64 %40, 0
%42 = sext i1 %41 to i64
ret i64 %42
}