#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 */
typedef int uint32_t;
typedef int int32_t;

/* Variables and functions */
int32_t FlashProgram(uint32_t *pui32Data, uint32_t ui32Address,
                     uint32_t ui32Count) {
  ;
  ;
  (*((volatile unsigned long *)(0x400FD014))) =
      (0x00000001 | 0x00000200 | 0x00000400 | 0x00002000);
  while (ui32Count) {
    (*((volatile unsigned long *)(0x400FD000))) = ui32Address & ~(0x7f);
    while (((ui32Address & 0x7c) ||
            ((*((volatile unsigned long *)(0x400FD030))) == 0)) &&
           (ui32Count != 0)) {
      (*((volatile unsigned long *)(0x400FD100 + (ui32Address & 0x7c)))) =
          *pui32Data++;
      ui32Address += 4;
      ui32Count -= 4;
    }
    (*((volatile unsigned long *)(0x400FD020))) = 0xA4420000 | 0x00000001;
    while ((*((volatile unsigned long *)(0x400FD020))) & 0x00000001) {
    }
  }
  if ((*((volatile unsigned long *)(0x400FD00C))) &
      (0x00000001 | 0x00000200 | 0x00000400 | 0x00002000)) {
    return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<FlashProgram>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    $0x400fd014,%eax
movq   $0x2601,(%rax)
cmpl   $0x0,-0x18(%rbp)
je     11db <FlashProgram+0xdb>
mov    -0x14(%rbp),%eax
and    $0xffffff80,%eax
movslq %eax,%rcx
mov    $0x400fd000,%eax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%eax
and    $0x7c,%eax
cmp    $0x0,%eax
jne    115b <FlashProgram+0x5b>
mov    $0x400fd030,%eax
mov    (%rax),%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
jne    1165 <FlashProgram+0x65>
cmpl   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1175 <FlashProgram+0x75>
jmp    11ae <FlashProgram+0xae>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
movslq (%rax),%rcx
mov    -0x14(%rbp),%eax
and    $0x7c,%eax
add    $0x400fd100,%eax
cltq
mov    %rcx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x18(%rbp)
jmp    1135 <FlashProgram+0x35>
mov    $0x400fd020,%eax
mov    $0xa4420001,%ecx
mov    %rcx,(%rax)
mov    $0x400fd020,%eax
mov    (%rax),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     11d6 <FlashProgram+0xd6>
jmp    11bb <FlashProgram+0xbb>
jmp    111a <FlashProgram+0x1a>
mov    $0x400fd00c,%eax
mov    (%rax),%rax
and    $0x2601,%rax
cmp    $0x0,%rax
je     11ff <FlashProgram+0xff>
movl   $0xffffffff,-0x4(%rbp)
jmp    1206 <FlashProgram+0x106>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<FlashProgram>:
movq   $0x2601,0x400fd014
test   %edx,%edx
je     11a6 <FlashProgram+0xa6>
mov    $0xa4420001,%r8d
nopw   0x0(%rax,%rax,1)
mov    %esi,%ecx
and    $0xffffff80,%ecx
movslq %ecx,%rcx
mov    %rcx,0x400fd000
40
jmp    115d <FlashProgram+0x5d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   %edx,%edx
je     1180 <FlashProgram+0x80>
movslq (%rdi),%rax
add    $0x4,%rdi
mov    %ecx,%ecx
or     $0x400fd100,%rcx
mov    %rax,(%rcx)
add    $0x4,%esi
add    $0xfffffffc,%edx
mov    %esi,%ecx
and    $0x7c,%ecx
jne    1140 <FlashProgram+0x40>
cmpq   $0x0,0x400fd030
jne    1182 <FlashProgram+0x82>
test   %edx,%edx
jne    1144 <FlashProgram+0x44>
jmp    1182 <FlashProgram+0x82>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %edx,%edx
mov    %r8,0x400fd020
40
nopw   0x0(%rax,%rax,1)
testq  $0x1,0x400fd020
jne    1190 <FlashProgram+0x90>
test   %edx,%edx
jne    1120 <FlashProgram+0x20>
mov    0x400fd00c,%rax
40
and    $0x2601,%eax
neg    %rax
sbb    %eax,%eax
ret

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

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