#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 */

/* Variables and functions */
int /*<<< orphan*/ FLASH_GetSectors(unsigned int *, unsigned int *);
scalar_t__ FLASH_PrepareSectors(unsigned int, unsigned int);
int /*<<< orphan*/ iap_entry(unsigned int *, unsigned int *);
unsigned int FLASH_WriteData(void *dstAddr, void *srcAddr, unsigned int size) {
  unsigned int iap_command[5], iap_result[3];
  unsigned int startSector, endSector;
  FLASH_GetSectors(&startSector, &endSector);
  if (FLASH_PrepareSectors(startSector, endSector) == 0) {
    iap_command[0] = 51;
    iap_command[1] = (int)dstAddr;
    iap_command[2] = (int)srcAddr;
    iap_command[3] = size;
    iap_command[4] = 14745;
    iap_entry(iap_command, iap_result);
  }
  return iap_result[0];
}


x86 assembly (clang, -O0):
<FLASH_WriteData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0x44(%rbp),%rsi
call   1030 <FLASH_GetSectors@plt>
mov    -0x40(%rbp),%edi
mov    -0x44(%rbp),%esi
call   1040 <FLASH_PrepareSectors@plt>
cmp    $0x0,%rax
jne    1194 <FLASH_WriteData+0x64>
movl   $0x33,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
movl   $0x3999,-0x20(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
call   1050 <iap_entry@plt>
mov    -0x3c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FLASH_WriteData>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <FLASH_GetSectors@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
call   1040 <FLASH_PrepareSectors@plt>
mov    %rax,%rcx
test   %rcx,%rcx
jne    1195 <FLASH_WriteData+0x65>
movl   $0x33,0x10(%rsp)
mov    %ebp,0x14(%rsp)
mov    %ebx,0x18(%rsp)
mov    %r14d,0x1c(%rsp)
movl   $0x3999,0x20(%rsp)
lea    0x10(%rsp),%rdi
lea    0x24(%rsp),%rsi
call   1050 <iap_entry@plt>
mov    0x24(%rsp),%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @FLASH_WriteData(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [5 x i32]
%8 = alloca [3 x i32]
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = call i32 @FLASH_GetSectors(i32* %9, i32* %10)
%12 = load i32, i32* %9
%13 = load i32, i32* %10
%14 = call i64 @FLASH_PrepareSectors(i32 %12, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %30
16: ; preds = %3
%17 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 0
store i32 51, i32* %17
%18 = load i8*, i8** %4
%19 = ptrtoint i8* %18 to i32
%20 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 1
store i32 %19, i32* %20
%21 = load i8*, i8** %5
%22 = ptrtoint i8* %21 to i32
%23 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 2
store i32 %22, i32* %23
%24 = load i32, i32* %6
%25 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 3
store i32 %24, i32* %25
%26 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 4
store i32 14745, i32* %26
%27 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 0
%28 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 0
%29 = call i32 @iap_entry(i32* %27, i32* %28)
br label %30
30: ; preds = %16, %3
%31 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 0
%32 = load i32, i32* %31
ret i32 %32
}

LLVM IR (-O2):
define i32 @FLASH_WriteData(i8* %0, i8* %1, i32 %2) {
%4 = alloca [5 x i32]
%5 = alloca [3 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = bitcast [5 x i32]* %4 to i8*
%9 = bitcast [3 x i32]* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = bitcast i32* %7 to i8*
%12 = call i32 @FLASH_GetSectors(i32* %6, i32* %7)
%13 = load i32, i32* %6
%14 = load i32, i32* %7
%15 = call i64 @FLASH_PrepareSectors(i32 %13, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %3
%18 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 0
store i32 51, i32* %18
%19 = ptrtoint i8* %0 to i64
%20 = trunc i64 %19 to i32
%21 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 1
store i32 %20, i32* %21
%22 = ptrtoint i8* %1 to i64
%23 = trunc i64 %22 to i32
%24 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 2
store i32 %23, i32* %24
%25 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 3
store i32 %2, i32* %25
%26 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 4
store i32 14745, i32* %26
%27 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%28 = call i32 @iap_entry(i32* %18, i32* %27)
%29 = load i32, i32* %27
br label %30
30: ; preds = %17, %3
%31 = phi i32 [ %29, %17 ], [ undef, %3 ]
ret i32 %31
}