#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 */
scalar_t__ blankCheckFlash(int, int);
scalar_t__ compareFlash(char *, char *, int);
scalar_t__ eraseFlash(int, int);
scalar_t__ prepareFlash(int, int);
scalar_t__ writeFlash(char *, char *, int);
int saveFlashInner(char *src, int size) {
  char *target = (char *)0x00007000;
  int sector = 7;
  if (blankCheckFlash(sector, sector)) {
    if (prepareFlash(sector, sector))
      return -1;
    if (eraseFlash(sector, sector))
      return -2;
  }
  if (prepareFlash(sector, sector))
    return -3;
  if (writeFlash(src, target, size))
    return -4;
  if (compareFlash(src, target, size))
    return -5;
  return 0;
}


x86 assembly (clang, -O0):
<saveFlashInner>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x7000,%eax
mov    %rax,-0x20(%rbp)
movl   $0x7,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1050 <blankCheckFlash@plt>
cmp    $0x0,%rax
je     11cb <saveFlashInner+0x7b>
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1070 <prepareFlash@plt>
cmp    $0x0,%rax
je     11a5 <saveFlashInner+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    123f <saveFlashInner+0xef>
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1040 <eraseFlash@plt>
cmp    $0x0,%rax
je     11c6 <saveFlashInner+0x76>
movl   $0xfffffffe,-0x4(%rbp)
jmp    123f <saveFlashInner+0xef>
jmp    11cb <saveFlashInner+0x7b>
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1070 <prepareFlash@plt>
cmp    $0x0,%rax
je     11ec <saveFlashInner+0x9c>
movl   $0xfffffffd,-0x4(%rbp)
jmp    123f <saveFlashInner+0xef>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <writeFlash@plt>
cmp    $0x0,%rax
je     1212 <saveFlashInner+0xc2>
movl   $0xfffffffc,-0x4(%rbp)
jmp    123f <saveFlashInner+0xef>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <compareFlash@plt>
cmp    $0x0,%rax
je     1238 <saveFlashInner+0xe8>
movl   $0xfffffffb,-0x4(%rbp)
jmp    123f <saveFlashInner+0xef>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saveFlashInner>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x7,%edi
mov    $0x7,%esi
call   1050 <blankCheckFlash@plt>
test   %rax,%rax
je     11a4 <saveFlashInner+0x54>
mov    $0x7,%edi
mov    $0x7,%esi
call   1070 <prepareFlash@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    11f9 <saveFlashInner+0xa9>
mov    $0x7,%edi
mov    $0x7,%esi
call   1040 <eraseFlash@plt>
mov    %rax,%rcx
mov    $0xfffffffe,%eax
test   %rcx,%rcx
jne    11f9 <saveFlashInner+0xa9>
mov    $0x7,%edi
mov    $0x7,%esi
call   1070 <prepareFlash@plt>
mov    %rax,%rcx
mov    $0xfffffffd,%eax
test   %rcx,%rcx
jne    11f9 <saveFlashInner+0xa9>
mov    $0x7000,%esi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1060 <writeFlash@plt>
mov    %rax,%rcx
mov    $0xfffffffc,%eax
test   %rcx,%rcx
jne    11f9 <saveFlashInner+0xa9>
mov    $0x7000,%esi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <compareFlash@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%rcx,%rcx,4),%eax
add    $0xfffffffb,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @saveFlashInner(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* inttoptr (i64 28672 to i8*), i8** %6
store i32 7, i32* %7
%8 = load i32, i32* %7
%9 = load i32, i32* %7
%10 = call i64 @blankCheckFlash(i32 %8, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %2
%13 = load i32, i32* %7
%14 = load i32, i32* %7
%15 = call i64 @prepareFlash(i32 %13, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 -1, i32* %3
br label %46
18: ; preds = %12
%19 = load i32, i32* %7
%20 = load i32, i32* %7
%21 = call i64 @eraseFlash(i32 %19, i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 -2, i32* %3
br label %46
24: ; preds = %18
br label %25
25: ; preds = %24, %2
%26 = load i32, i32* %7
%27 = load i32, i32* %7
%28 = call i64 @prepareFlash(i32 %26, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %25
store i32 -3, i32* %3
br label %46
31: ; preds = %25
%32 = load i8*, i8** %4
%33 = load i8*, i8** %6
%34 = load i32, i32* %5
%35 = call i64 @writeFlash(i8* %32, i8* %33, i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %31
store i32 -4, i32* %3
br label %46
38: ; preds = %31
%39 = load i8*, i8** %4
%40 = load i8*, i8** %6
%41 = load i32, i32* %5
%42 = call i64 @compareFlash(i8* %39, i8* %40, i32 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38
store i32 -5, i32* %3
br label %46
45: ; preds = %38
store i32 0, i32* %3
br label %46
46: ; preds = %45, %44, %37, %30, %23, %17
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
define i32 @saveFlashInner(i8* %0, i32 %1) {
%3 = tail call i64 @blankCheckFlash(i32 7, i32 7)
%4 = icmp eq i64 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i64 @prepareFlash(i32 7, i32 7)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %21
8: ; preds = %5
%9 = tail call i64 @eraseFlash(i32 7, i32 7)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %8, %2
%12 = tail call i64 @prepareFlash(i32 7, i32 7)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = tail call i64 @writeFlash(i8* %0, i8* inttoptr (i64 28672 to i8*), i32 %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = tail call i64 @compareFlash(i8* %0, i8* inttoptr (i64 28672 to i8*), i32 %1)
%19 = icmp eq i64 %18, 0
%20 = select i1 %19, i32 0, i32 -5
br label %21
21: ; preds = %17, %14, %11, %8, %5
%22 = phi i32 [ -1, %5 ], [ -2, %8 ], [ -3, %11 ], [ -4, %14 ], [ %20, %17 ]
ret i32 %22
}