#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 uint8_t;
typedef int /*<<< orphan*/ cmd;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ check_rdismb();
int /*<<< orphan*/ disable_infen();
int /*<<< orphan*/ enable_wen();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ spi_transfer(int *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait_ready();
void cmd_erase_flash() {
  uint8_t cmd[1];
  if (check_rdismb()) {
    fprintf(stderr, "flash memory is protected\n");
    exit(EXIT_FAILURE);
  }
  disable_infen();
  enable_wen();
  printf("Erasing flash...\n");
  cmd[0] = 0x62;
  spi_transfer(cmd, sizeof(cmd));
  wait_ready();
}


x86 assembly (clang, -O0):
<cmd_erase_flash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1090 <check_rdismb@plt>
cmp    $0x0,%rax
je     11bc <cmd_erase_flash+0x3c>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1040 <disable_infen@plt>
mov    $0x0,%al
call   10a0 <enable_wen@plt>
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
movl   $0x62,-0x4(%rbp)
lea    -0x4(%rbp),%rdi
mov    $0x4,%esi
call   1070 <spi_transfer@plt>
mov    $0x0,%al
call   1050 <wait_ready@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_erase_flash>:
push   %rax
xor    %eax,%eax
call   1090 <check_rdismb@plt>
test   %rax,%rax
jne    11c7 <cmd_erase_flash+0x47>
xor    %eax,%eax
call   1040 <disable_infen@plt>
xor    %eax,%eax
call   10a0 <enable_wen@plt>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
movl   $0x62,0x4(%rsp)
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
call   1070 <spi_transfer@plt>
xor    %eax,%eax
call   1050 <wait_ready@plt>
pop    %rax
ret
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"flash memory is protected\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [18 x i8] c"Erasing flash...\0A\00"
define void @cmd_erase_flash() {
%1 = alloca [1 x i32]
%2 = call i64 (...) @check_rdismb()
%3 = icmp ne i64 %2, 0
br i1 %3, label %4, label %9
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = call i32 (...) @disable_infen()
%11 = call i32 (...) @enable_wen()
%12 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds [1 x i32], [1 x i32]* %1, i64 0, i64 0
store i32 98, i32* %13
%14 = getelementptr inbounds [1 x i32], [1 x i32]* %1, i64 0, i64 0
%15 = call i32 @spi_transfer(i32* %14, i32 4)
%16 = call i32 (...) @wait_ready()
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"flash memory is protected\0A\00"
@EXIT_FAILURE = global i32 0
@str = [17 x i8] c"Erasing flash...\00"
define void @cmd_erase_flash() {
%1 = alloca [1 x i32]
%2 = bitcast [1 x i32]* %1 to i8*
%3 = tail call i64 (...) @check_rdismb()
%4 = icmp eq i64 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = tail call i32 (...) @disable_infen()
%12 = tail call i32 (...) @enable_wen()
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%14 = getelementptr inbounds [1 x i32], [1 x i32]* %1, i64 0, i64 0
store i32 98, i32* %14
%15 = call i32 @spi_transfer(i32* %14, i32 4)
%16 = call i32 (...) @wait_ready()
ret void
}