#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*/ clean_RnB();
int /*<<< orphan*/ delselect_ship();
int /*<<< orphan*/ nand_addr(unsigned long);
int /*<<< orphan*/ nand_cmd(int);
int /*<<< orphan*/ select_ship();
int /*<<< orphan*/ wait_RnB();
int NF_Erase(unsigned long addr) {
  int ret;
  select_ship();
  clean_RnB();
  nand_cmd(0x60);
  nand_addr(addr & 0xff);
  nand_addr((addr >> 8) & (0xff));
  nand_addr((addr >> 16) & (0xff));
  nand_cmd(0xD0);
  wait_RnB();
  nand_cmd(0x70);
  ret = (*((volatile unsigned char *)0x70200010));
  delselect_ship();
  return ret;
}


x86 assembly (clang, -O0):
<NF_Erase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <select_ship@plt>
mov    $0x0,%al
call   1030 <clean_RnB@plt>
mov    $0x60,%edi
call   1070 <nand_cmd@plt>
mov    -0x8(%rbp),%rdi
and    $0xff,%rdi
call   1060 <nand_addr@plt>
mov    -0x8(%rbp),%rdi
shr    $0x8,%rdi
and    $0xff,%rdi
call   1060 <nand_addr@plt>
mov    -0x8(%rbp),%rdi
shr    $0x10,%rdi
and    $0xff,%rdi
call   1060 <nand_addr@plt>
mov    $0xd0,%edi
call   1070 <nand_cmd@plt>
mov    $0x0,%al
call   1080 <wait_RnB@plt>
mov    $0x70,%edi
call   1070 <nand_cmd@plt>
mov    $0x70200010,%eax
mov    (%rax),%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1050 <delselect_ship@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NF_Erase>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <select_ship@plt>
xor    %eax,%eax
call   1030 <clean_RnB@plt>
mov    $0x60,%edi
call   1070 <nand_cmd@plt>
movzbl %bl,%edi
call   1060 <nand_addr@plt>
movzbl %bh,%edi
call   1060 <nand_addr@plt>
shr    $0x10,%ebx
movzbl %bl,%edi
call   1060 <nand_addr@plt>
mov    $0xd0,%edi
call   1070 <nand_cmd@plt>
xor    %eax,%eax
call   1080 <wait_RnB@plt>
mov    $0x70,%edi
call   1070 <nand_cmd@plt>
movzbl 0x70200010,%ebx
70
xor    %eax,%eax
call   1050 <delselect_ship@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @NF_Erase(i64 %0) {
%2 = alloca i64
%3 = alloca i32
store i64 %0, i64* %2
%4 = call i32 (...) @select_ship()
%5 = call i32 (...) @clean_RnB()
%6 = call i32 @nand_cmd(i32 96)
%7 = load i64, i64* %2
%8 = and i64 %7, 255
%9 = call i32 @nand_addr(i64 %8)
%10 = load i64, i64* %2
%11 = lshr i64 %10, 8
%12 = and i64 %11, 255
%13 = call i32 @nand_addr(i64 %12)
%14 = load i64, i64* %2
%15 = lshr i64 %14, 16
%16 = and i64 %15, 255
%17 = call i32 @nand_addr(i64 %16)
%18 = call i32 @nand_cmd(i32 208)
%19 = call i32 (...) @wait_RnB()
%20 = call i32 @nand_cmd(i32 112)
%21 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%22 = zext i8 %21 to i32
store i32 %22, i32* %3
%23 = call i32 (...) @delselect_ship()
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @NF_Erase(i64 %0) {
%2 = tail call i32 (...) @select_ship()
%3 = tail call i32 (...) @clean_RnB()
%4 = tail call i32 @nand_cmd(i32 96)
%5 = and i64 %0, 255
%6 = tail call i32 @nand_addr(i64 %5)
%7 = lshr i64 %0, 8
%8 = and i64 %7, 255
%9 = tail call i32 @nand_addr(i64 %8)
%10 = lshr i64 %0, 16
%11 = and i64 %10, 255
%12 = tail call i32 @nand_addr(i64 %11)
%13 = tail call i32 @nand_cmd(i32 208)
%14 = tail call i32 (...) @wait_RnB()
%15 = tail call i32 @nand_cmd(i32 112)
%16 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%17 = zext i8 %16 to i32
%18 = tail call i32 (...) @delselect_ship()
ret i32 %17
}