#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 */
int /*<<< orphan*/ ASSERT(int);
int32_t FlashProgram(uint32_t *pui32Data, uint32_t ui32Address,
                     uint32_t ui32Count) {
  ASSERT(!(ui32Address & 3));
  ASSERT(!(ui32Count & 3));
  (*((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
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <ASSERT@plt>
mov    -0x18(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <ASSERT@plt>
mov    $0x400fd014,%eax
movl   $0x2601,(%rax)
cmpl   $0x0,-0x18(%rbp)
je     1211 <FlashProgram+0x101>
mov    -0x14(%rbp),%ecx
and    $0xffffff80,%ecx
mov    $0x400fd000,%eax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
and    $0x7c,%eax
cmp    $0x0,%eax
jne    1198 <FlashProgram+0x88>
mov    $0x400fd030,%eax
mov    (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
jne    11a2 <FlashProgram+0x92>
cmpl   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11b2 <FlashProgram+0xa2>
jmp    11e9 <FlashProgram+0xd9>
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    1174 <FlashProgram+0x64>
mov    $0x400fd020,%eax
movl   $0xa4420001,(%rax)
mov    $0x400fd020,%eax
mov    (%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     120c <FlashProgram+0xfc>
jmp    11f4 <FlashProgram+0xe4>
jmp    115d <FlashProgram+0x4d>
mov    $0x400fd00c,%eax
mov    (%rax),%eax
and    $0x2601,%eax
cmp    $0x0,%eax
je     1232 <FlashProgram+0x122>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <FlashProgram+0x129>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FlashProgram>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r14
xor    %edi,%edi
test   $0x3,%bl
sete   %dil
call   1030 <ASSERT@plt>
xor    %edi,%edi
test   $0x3,%bpl
sete   %dil
call   1030 <ASSERT@plt>
movl   $0x2601,0x400fd014
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %ebp,%ebp
je     11cf <FlashProgram+0xbf>
mov    %ebx,%eax
and    $0xffffff80,%eax
mov    %eax,0x400fd000
jmp    118b <FlashProgram+0x7b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   %ebp,%ebp
je     11b0 <FlashProgram+0xa0>
mov    (%r14),%ecx
add    $0x4,%r14
mov    %eax,%eax
or     $0x400fd100,%rax
mov    %ecx,(%rax)
add    $0x4,%ebx
add    $0xfffffffc,%ebp
mov    %ebx,%eax
and    $0x7c,%eax
jne    1170 <FlashProgram+0x60>
cmpl   $0x0,0x400fd030
jne    11b2 <FlashProgram+0xa2>
test   %ebp,%ebp
jne    1174 <FlashProgram+0x64>
jmp    11b2 <FlashProgram+0xa2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %ebp,%ebp
movl   $0xa4420001,0x400fd020
nopl   (%rax)
testl  $0x1,0x400fd020
jne    11c0 <FlashProgram+0xb0>
jmp    1150 <FlashProgram+0x40>
mov    $0x2601,%eax
and    0x400fd00c,%eax
neg    %eax
sbb    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
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
%8 = load i32, i32* %6
%9 = and i32 %8, 3
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
%12 = zext i1 %11 to i32
%13 = call i32 @ASSERT(i32 %12)
%14 = load i32, i32* %7
%15 = and i32 %14, 3
%16 = icmp ne i32 %15, 0
%17 = xor i1 %16, true
%18 = zext i1 %17 to i32
%19 = call i32 @ASSERT(i32 %18)
store volatile i32 9729, i32* inttoptr (i64 1074778132 to i32*)
br label %20
20: ; preds = %57, %3
%21 = load i32, i32* %7
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %58
23: ; preds = %20
%24 = load i32, i32* %6
%25 = and i32 %24, -128
store volatile i32 %25, i32* inttoptr (i64 1074778112 to i32*)
br label %26
26: ; preds = %38, %23
%27 = load i32, i32* %6
%28 = and i32 %27, 124
%29 = icmp ne i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %26
%31 = load volatile i32, i32* inttoptr (i64 1074778160 to i32*)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30, %26
%34 = load i32, i32* %7
%35 = icmp ne i32 %34, 0
br label %36
36: ; preds = %33, %30
%37 = phi i1 [ false, %30 ], [ %35, %33 ]
br i1 %37, label %38, label %51
38: ; preds = %36
%39 = load i32*, i32** %5
%40 = getelementptr inbounds i32, i32* %39, i32 1
store i32* %40, i32** %5
%41 = load i32, i32* %39
%42 = load i32, i32* %6
%43 = and i32 %42, 124
%44 = add nsw i32 1074778368, %43
%45 = sext i32 %44 to i64
%46 = inttoptr i64 %45 to i32*
store volatile i32 %41, i32* %46
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 4
store i32 %48, i32* %6
%49 = load i32, i32* %7
%50 = sub nsw i32 %49, 4
store i32 %50, i32* %7
br label %26
51: ; preds = %36
store volatile i32 -1539178495, i32* inttoptr (i64 1074778144 to i32*)
br label %52
52: ; preds = %56, %51
%53 = load volatile i32, i32* inttoptr (i64 1074778144 to i32*)
%54 = and i32 %53, 1
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %52
br label %52
57: ; preds = %52
br label %20
58: ; preds = %20
%59 = load volatile i32, i32* inttoptr (i64 1074778124 to i32*)
%60 = and i32 %59, 9729
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %58
store i32 -1, i32* %4
br label %64
63: ; preds = %58
store i32 0, i32* %4
br label %64
64: ; preds = %63, %62
%65 = load i32, i32* %4
ret i32 %65
}

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