#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 uint32_t *)(0x400FD014))) =
      (0x00000001 | 0x00000200 | 0x00000400 | 0x00002000);
  while (ui32Count) {
    (*((volatile uint32_t *)(0x400FD000))) = ui32Address & ~(0x7f);
    while (((ui32Address & 0x7c) ||
            ((*((volatile uint32_t *)(0x400FD030))) == 0)) &&
           (ui32Count != 0)) {
      (*((volatile uint32_t *)(0x400FD100 + (ui32Address & 0x7c)))) =
          *pui32Data++;
      ui32Address += 4;
      ui32Count -= 4;
    }
    (*((volatile uint32_t *)(0x400FD020))) = 0xA4420000 | 0x00000001;
    while ((*((volatile uint32_t *)(0x400FD020))) & 0x00000001) {
    }
  }
  if ((*((volatile uint32_t *)(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
movl   $0x2601,(%rax)
cmpl   $0x0,-0x18(%rbp)
je     11cd <FlashProgram+0xcd>
mov    -0x14(%rbp),%ecx
and    $0xffffff80,%ecx
mov    $0x400fd000,%eax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
and    $0x7c,%eax
cmp    $0x0,%eax
jne    1154 <FlashProgram+0x54>
mov    $0x400fd030,%eax
mov    (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
jne    115e <FlashProgram+0x5e>
cmpl   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    116e <FlashProgram+0x6e>
jmp    11a5 <FlashProgram+0xa5>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%ecx
mov    -0x14(%rbp),%eax
and    $0x7c,%eax
add    $0x400fd100,%eax
cltq
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x18(%rbp)
jmp    1130 <FlashProgram+0x30>
mov    $0x400fd020,%eax
movl   $0xa4420001,(%rax)
mov    $0x400fd020,%eax
mov    (%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11c8 <FlashProgram+0xc8>
jmp    11b0 <FlashProgram+0xb0>
jmp    1119 <FlashProgram+0x19>
mov    $0x400fd00c,%eax
mov    (%rax),%eax
and    $0x2601,%eax
cmp    $0x0,%eax
je     11ee <FlashProgram+0xee>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f5 <FlashProgram+0xf5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<FlashProgram>:
movl   $0x2601,0x400fd014
nopl   0x0(%rax,%rax,1)
test   %edx,%edx
je     118f <FlashProgram+0x8f>
mov    %esi,%eax
and    $0xffffff80,%eax
mov    %eax,0x400fd000
jmp    114a <FlashProgram+0x4a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   %edx,%edx
je     1170 <FlashProgram+0x70>
mov    (%rdi),%ecx
add    $0x4,%rdi
mov    %eax,%eax
or     $0x400fd100,%rax
mov    %ecx,(%rax)
add    $0x4,%esi
add    $0xfffffffc,%edx
mov    %esi,%eax
and    $0x7c,%eax
jne    1130 <FlashProgram+0x30>
cmpl   $0x0,0x400fd030
jne    1172 <FlashProgram+0x72>
test   %edx,%edx
jne    1134 <FlashProgram+0x34>
jmp    1172 <FlashProgram+0x72>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %edx,%edx
movl   $0xa4420001,0x400fd020
nopl   (%rax)
testl  $0x1,0x400fd020
jne    1180 <FlashProgram+0x80>
jmp    1110 <FlashProgram+0x10>
mov    $0x2601,%eax
and    0x400fd00c,%eax
neg    %eax
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 i32 9729, i32* inttoptr (i64 1074778132 to i32*)
br label %8
8: ; preds = %45, %3
%9 = load i32, i32* %7
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %46
11: ; preds = %8
%12 = load i32, i32* %6
%13 = and i32 %12, -128
store volatile i32 %13, i32* inttoptr (i64 1074778112 to i32*)
br label %14
14: ; preds = %26, %11
%15 = load i32, i32* %6
%16 = and i32 %15, 124
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = load volatile i32, i32* inttoptr (i64 1074778160 to i32*)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18, %14
%22 = load i32, i32* %7
%23 = icmp ne i32 %22, 0
br label %24
24: ; preds = %21, %18
%25 = phi i1 [ false, %18 ], [ %23, %21 ]
br i1 %25, label %26, label %39
26: ; preds = %24
%27 = load i32*, i32** %5
%28 = getelementptr inbounds i32, i32* %27, i32 1
store i32* %28, i32** %5
%29 = load i32, i32* %27
%30 = load i32, i32* %6
%31 = and i32 %30, 124
%32 = add nsw i32 1074778368, %31
%33 = sext i32 %32 to i64
%34 = inttoptr i64 %33 to i32*
store volatile i32 %29, i32* %34
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 4
store i32 %36, i32* %6
%37 = load i32, i32* %7
%38 = sub nsw i32 %37, 4
store i32 %38, i32* %7
br label %14
39: ; preds = %24
store volatile i32 -1539178495, i32* inttoptr (i64 1074778144 to i32*)
br label %40
40: ; preds = %44, %39
%41 = load volatile i32, i32* inttoptr (i64 1074778144 to i32*)
%42 = and i32 %41, 1
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %40
br label %40
45: ; preds = %40
br label %8
46: ; preds = %8
%47 = load volatile i32, i32* inttoptr (i64 1074778124 to i32*)
%48 = and i32 %47, 9729
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %46
store i32 -1, i32* %4
br label %52
51: ; preds = %46
store i32 0, i32* %4
br label %52
52: ; preds = %51, %50
%53 = load i32, i32* %4
ret i32 %53
}

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