#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__ readAck(int);
scalar_t__ sendCommand(int, int);
int write(int, unsigned int *, int);
int eraseFlash(int fd) {
  unsigned data[2] = {0xFF, 0x00};
  if (sendCommand(fd, 0x43))
    return -1;
  if (write(fd, data, 2) != 2)
    return -1;
  if (readAck(fd))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<eraseFlash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x43,%esi
call   1030 <sendCommand@plt>
cmp    $0x0,%rax
je     1169 <eraseFlash+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <eraseFlash+0x84>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
cmp    $0x2,%eax
je     118f <eraseFlash+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <eraseFlash+0x84>
mov    -0x8(%rbp),%edi
call   1050 <readAck@plt>
cmp    $0x0,%rax
je     11ad <eraseFlash+0x7d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <eraseFlash+0x84>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eraseFlash>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
movq   $0xff,(%rsp)
mov    $0x43,%esi
call   1030 <sendCommand@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1171 <eraseFlash+0x41>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1040 <write@plt>
cmp    $0x2,%eax
jne    1171 <eraseFlash+0x41>
mov    %ebx,%edi
call   1050 <readAck@plt>
neg    %rax
sbb    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.eraseFlash.data = [2 x i32] [i32 255, i32 0]
define i32 @eraseFlash(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x i32]
store i32 %0, i32* %3
%5 = bitcast [2 x i32]* %4 to i8*
%6 = load i32, i32* %3
%7 = call i64 @sendCommand(i32 %6, i32 67)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %22
10: ; preds = %1
%11 = load i32, i32* %3
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%13 = call i32 @write(i32 %11, i32* %12, i32 2)
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %16
15: ; preds = %10
store i32 -1, i32* %2
br label %22
16: ; preds = %10
%17 = load i32, i32* %3
%18 = call i64 @readAck(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 -1, i32* %2
br label %22
21: ; preds = %16
store i32 0, i32* %2
br label %22
22: ; preds = %21, %20, %15, %9
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
define i32 @eraseFlash(i32 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
store i64 255, i64* %2
%4 = tail call i64 @sendCommand(i32 %0, i32 67)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = bitcast i64* %2 to i32*
%8 = call i32 @write(i32 %0, i32* %7, i32 2)
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = tail call i64 @readAck(i32 %0)
%12 = icmp ne i64 %11, 0
%13 = sext i1 %12 to i32
br label %14
14: ; preds = %10, %6, %1
%15 = phi i32 [ -1, %1 ], [ -1, %6 ], [ %13, %10 ]
ret i32 %15
}