long FlashProgram(unsigned long *pulData, unsigned long ulAddress,
                  unsigned long ulCount) {
  ;
  ;
  (*((volatile unsigned long *)(0x400FD014))) = 0x00000001;
  while (ulCount) {
    (*((volatile unsigned long *)(0x400FD000))) = ulAddress;
    (*((volatile unsigned long *)(0x400FD004))) = *pulData;
    (*((volatile unsigned long *)(0x400FD008))) = 0xA4420000 | 0x00000001;
    while ((*((volatile unsigned long *)(0x400FD008))) & 0x00000001) {
    }
    pulData++;
    ulAddress += 4;
    ulCount -= 4;
  }
  if ((*((volatile unsigned long *)(0x400FD00C))) & 0x00000001) {
    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   $0x1,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     1193 <FlashProgram+0x93>
mov    -0x18(%rbp),%rcx
mov    $0x400fd000,%eax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    $0x400fd004,%eax
mov    %rcx,(%rax)
mov    $0x400fd008,%eax
mov    $0xa4420001,%ecx
mov    %rcx,(%rax)
mov    $0x400fd008,%eax
mov    (%rax),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     116a <FlashProgram+0x6a>
jmp    114f <FlashProgram+0x4f>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
sub    $0x4,%rax
mov    %rax,-0x20(%rbp)
jmp    111c <FlashProgram+0x1c>
mov    $0x400fd00c,%eax
mov    (%rax),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     11b6 <FlashProgram+0xb6>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11be <FlashProgram+0xbe>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<FlashProgram>:
movq   $0x1,0x400fd014
test   %rdx,%rdx
je     115b <FlashProgram+0x5b>
mov    $0xa4420001,%eax
cs nopw 0x0(%rax,%rax,1)
mov    %rsi,0x400fd000
40
mov    (%rdi),%rcx
mov    %rcx,0x400fd004
40
mov    %rax,0x400fd008
40
nopl   0x0(%rax,%rax,1)
mov    0x400fd008,%rcx
40
test   $0x1,%cl
jne    1140 <FlashProgram+0x40>
add    $0x8,%rdi
add    $0x4,%rsi
add    $0xfffffffffffffffc,%rdx
jne    1120 <FlashProgram+0x20>
mov    0x400fd00c,%rax
40
and    $0x1,%eax
neg    %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 1, i64* inttoptr (i64 1074778132 to i64*)
br label %8
8: ; preds = %20, %3
%9 = load i64, i64* %7
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = load i64, i64* %6
store volatile i64 %12, i64* inttoptr (i64 1074778112 to i64*)
%13 = load i64*, i64** %5
%14 = load i64, i64* %13
store volatile i64 %14, i64* inttoptr (i64 1074778116 to i64*)
store volatile i64 2755788801, i64* inttoptr (i64 1074778120 to i64*)
br label %15
15: ; preds = %19, %11
%16 = load volatile i64, i64* inttoptr (i64 1074778120 to i64*)
%17 = and i64 %16, 1
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
br label %15
20: ; preds = %15
%21 = load i64*, i64** %5
%22 = getelementptr inbounds i64, i64* %21, i32 1
store i64* %22, i64** %5
%23 = load i64, i64* %6
%24 = add i64 %23, 4
store i64 %24, i64* %6
%25 = load i64, i64* %7
%26 = sub i64 %25, 4
store i64 %26, i64* %7
br label %8
27: ; preds = %8
%28 = load volatile i64, i64* inttoptr (i64 1074778124 to i64*)
%29 = and i64 %28, 1
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store i64 -1, i64* %4
br label %33
32: ; preds = %27
store i64 0, i64* %4
br label %33
33: ; preds = %32, %31
%34 = load i64, i64* %4
ret i64 %34
}

LLVM IR (-O2):
define i64 @FlashProgram(i64* nocapture %0, i64 %1, i64 %2) {
store volatile i64 1, i64* inttoptr (i64 1074778132 to i64*)
%4 = icmp eq i64 %2, 0
br i1 %4, label %19, label %5
5: ; preds = %3, %14
%6 = phi i64 [ %17, %14 ], [ %2, %3 ]
%7 = phi i64 [ %16, %14 ], [ %1, %3 ]
%8 = phi i64* [ %15, %14 ], [ %0, %3 ]
store volatile i64 %7, i64* inttoptr (i64 1074778112 to i64*)
%9 = load i64, i64* %8
store volatile i64 %9, i64* inttoptr (i64 1074778116 to i64*)
store volatile i64 2755788801, i64* inttoptr (i64 1074778120 to i64*)
br label %10
10: ; preds = %10, %5
%11 = load volatile i64, i64* inttoptr (i64 1074778120 to i64*)
%12 = and i64 %11, 1
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %10
14: ; preds = %10
%15 = getelementptr inbounds i64, i64* %8, i64 1
%16 = add i64 %7, 4
%17 = add i64 %6, -4
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %5
19: ; preds = %14, %3
%20 = load volatile i64, i64* inttoptr (i64 1074778124 to i64*)
%21 = and i64 %20, 1
%22 = sub nsw i64 0, %21
ret i64 %22
}