#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*/ clear_RnB();
int /*<<< orphan*/ deselect_chip();
int /*<<< orphan*/ nand_addr(unsigned int);
int /*<<< orphan*/ nand_cmd(int);
int /*<<< orphan*/ select_chip();
int /*<<< orphan*/ wait_RnB();
int NF_erase(unsigned addr) {
  int ret;
  select_chip();
  clear_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 = *((unsigned volatile char *)0x70200010);
  deselect_chip();
  return ret;
}


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

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

LLVM IR (-O0):
define i32 @NF_erase(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 (...) @select_chip()
%5 = call i32 (...) @clear_RnB()
%6 = call i32 @nand_cmd(i32 96)
%7 = load i32, i32* %2
%8 = and i32 %7, 255
%9 = call i32 @nand_addr(i32 %8)
%10 = load i32, i32* %2
%11 = lshr i32 %10, 8
%12 = and i32 %11, 255
%13 = call i32 @nand_addr(i32 %12)
%14 = load i32, i32* %2
%15 = lshr i32 %14, 16
%16 = and i32 %15, 255
%17 = call i32 @nand_addr(i32 %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 (...) @deselect_chip()
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @NF_erase(i32 %0) {
%2 = tail call i32 (...) @select_chip()
%3 = tail call i32 (...) @clear_RnB()
%4 = tail call i32 @nand_cmd(i32 96)
%5 = and i32 %0, 255
%6 = tail call i32 @nand_addr(i32 %5)
%7 = lshr i32 %0, 8
%8 = and i32 %7, 255
%9 = tail call i32 @nand_addr(i32 %8)
%10 = lshr i32 %0, 16
%11 = and i32 %10, 255
%12 = tail call i32 @nand_addr(i32 %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 (...) @deselect_chip()
ret i32 %17
}