#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*/ delete_chip();
int /*<<< orphan*/ select_chip();
int /*<<< orphan*/ send_addr(unsigned long);
int /*<<< orphan*/ send_cmd(int);
int /*<<< orphan*/ wait_RnB();
void NF_Page_Erase(unsigned long addr) {
  int i;
  int ret;
  addr = addr / 2048;
  select_chip();
  clear_RnB();
  send_cmd(0x60);
  send_addr(addr & 0xFF);
  send_addr((addr >> 8) & (0xFF));
  send_addr((addr >> 16) & (0xFF));
  send_cmd(0xD0);
  wait_RnB();
  send_cmd(0x70);
  ret = (*(volatile unsigned char *)0x70200010);
  delete_chip();
}


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

x86 assembly (clang, -O2):
<NF_Page_Erase>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %ebx,%eax
shr    $0xb,%eax
movzbl %al,%r14d
xor    %eax,%eax
call   1040 <select_chip@plt>
xor    %eax,%eax
call   1070 <clear_RnB@plt>
mov    $0x60,%edi
call   1080 <send_cmd@plt>
mov    %r14,%rdi
call   1030 <send_addr@plt>
mov    %ebx,%eax
shr    $0x13,%eax
movzbl %al,%edi
call   1030 <send_addr@plt>
shr    $0x1b,%rbx
movzbl %bl,%edi
call   1030 <send_addr@plt>
mov    $0xd0,%edi
call   1080 <send_cmd@plt>
xor    %eax,%eax
call   1050 <wait_RnB@plt>
mov    $0x70,%edi
call   1080 <send_cmd@plt>
mov    0x70200010,%al
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <delete_chip@plt>

LLVM IR (-O0):
define void @NF_Page_Erase(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = udiv i64 %5, 2048
store i64 %6, i64* %2
%7 = call i32 (...) @select_chip()
%8 = call i32 (...) @clear_RnB()
%9 = call i32 @send_cmd(i32 96)
%10 = load i64, i64* %2
%11 = and i64 %10, 255
%12 = call i32 @send_addr(i64 %11)
%13 = load i64, i64* %2
%14 = lshr i64 %13, 8
%15 = and i64 %14, 255
%16 = call i32 @send_addr(i64 %15)
%17 = load i64, i64* %2
%18 = lshr i64 %17, 16
%19 = and i64 %18, 255
%20 = call i32 @send_addr(i64 %19)
%21 = call i32 @send_cmd(i32 208)
%22 = call i32 (...) @wait_RnB()
%23 = call i32 @send_cmd(i32 112)
%24 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%25 = zext i8 %24 to i32
store i32 %25, i32* %4
%26 = call i32 (...) @delete_chip()
ret void
}

LLVM IR (-O2):
define void @NF_Page_Erase(i64 %0) {
%2 = lshr i64 %0, 11
%3 = tail call i32 (...) @select_chip()
%4 = tail call i32 (...) @clear_RnB()
%5 = tail call i32 @send_cmd(i32 96)
%6 = and i64 %2, 255
%7 = tail call i32 @send_addr(i64 %6)
%8 = lshr i64 %0, 19
%9 = and i64 %8, 255
%10 = tail call i32 @send_addr(i64 %9)
%11 = lshr i64 %0, 27
%12 = and i64 %11, 255
%13 = tail call i32 @send_addr(i64 %12)
%14 = tail call i32 @send_cmd(i32 208)
%15 = tail call i32 (...) @wait_RnB()
%16 = tail call i32 @send_cmd(i32 112)
%17 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%18 = tail call i32 (...) @delete_chip()
ret void
}