#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();
void NF_PageRead(unsigned long addr, unsigned char *buff) {
  int i;
  select_ship();
  clean_RnB();
  nand_cmd(0x00);
  nand_addr(0x00);
  nand_addr(0x00);
  nand_addr(addr & 0xff);
  nand_addr((addr >> 8) & (0xff));
  nand_addr((addr >> 16) & (0xff));
  nand_cmd(0x30);
  wait_RnB();
  for (i = 0; i < 1024 * 4; i++) {
    buff[i] = (*((volatile unsigned char *)0x70200010));
  }
  delselect_ship();
}


x86 assembly (clang, -O0):
<NF_PageRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <select_ship@plt>
mov    $0x0,%al
call   1030 <clean_RnB@plt>
xor    %edi,%edi
call   1070 <nand_cmd@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <nand_addr@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <nand_addr@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    $0x30,%edi
call   1070 <nand_cmd@plt>
mov    $0x0,%al
call   1080 <wait_RnB@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x1000,-0x14(%rbp)
jge    1214 <NF_PageRead+0xb4>
mov    $0x70200010,%eax
mov    (%rax),%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e7 <NF_PageRead+0x87>
mov    $0x0,%al
call   1050 <delselect_ship@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NF_PageRead>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <select_ship@plt>
xor    %eax,%eax
call   1030 <clean_RnB@plt>
xor    %edi,%edi
call   1070 <nand_cmd@plt>
xor    %edi,%edi
call   1060 <nand_addr@plt>
xor    %edi,%edi
call   1060 <nand_addr@plt>
movzbl %r15b,%edi
call   1060 <nand_addr@plt>
mov    %r15,%rax
movzbl %ah,%edi
call   1060 <nand_addr@plt>
shr    $0x10,%r15d
movzbl %r15b,%edi
call   1060 <nand_addr@plt>
mov    $0x30,%edi
call   1070 <nand_cmd@plt>
xor    %eax,%eax
call   1080 <wait_RnB@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x70200010,%eax
70
mov    %al,(%r14,%rbx,1)
movzbl 0x70200010,%eax
70
mov    %al,0x1(%r14,%rbx,1)
movzbl 0x70200010,%eax
70
mov    %al,0x2(%r14,%rbx,1)
movzbl 0x70200010,%eax
70
mov    %al,0x3(%r14,%rbx,1)
add    $0x4,%rbx
cmp    $0x1000,%rbx
jne    11d0 <NF_PageRead+0x70>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <delselect_ship@plt>

LLVM IR (-O0):
define void @NF_PageRead(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
store i64 %0, i64* %3
store i8* %1, i8** %4
%6 = call i32 (...) @select_ship()
%7 = call i32 (...) @clean_RnB()
%8 = call i32 @nand_cmd(i32 0)
%9 = call i32 @nand_addr(i64 0)
%10 = call i32 @nand_addr(i64 0)
%11 = load i64, i64* %3
%12 = and i64 %11, 255
%13 = call i32 @nand_addr(i64 %12)
%14 = load i64, i64* %3
%15 = lshr i64 %14, 8
%16 = and i64 %15, 255
%17 = call i32 @nand_addr(i64 %16)
%18 = load i64, i64* %3
%19 = lshr i64 %18, 16
%20 = and i64 %19, 255
%21 = call i32 @nand_addr(i64 %20)
%22 = call i32 @nand_cmd(i32 48)
%23 = call i32 (...) @wait_RnB()
store i32 0, i32* %5
br label %24
24: ; preds = %33, %2
%25 = load i32, i32* %5
%26 = icmp slt i32 %25, 4096
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%29 = load i8*, i8** %4
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 %28, i8* %32
br label %33
33: ; preds = %27
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %24
36: ; preds = %24
%37 = call i32 (...) @delselect_ship()
ret void
}

LLVM IR (-O2):
define void @NF_PageRead(i64 %0, i8* nocapture writeonly %1) {
%3 = tail call i32 (...) @select_ship()
%4 = tail call i32 (...) @clean_RnB()
%5 = tail call i32 @nand_cmd(i32 0)
%6 = tail call i32 @nand_addr(i64 0)
%7 = tail call i32 @nand_addr(i64 0)
%8 = and i64 %0, 255
%9 = tail call i32 @nand_addr(i64 %8)
%10 = lshr i64 %0, 8
%11 = and i64 %10, 255
%12 = tail call i32 @nand_addr(i64 %11)
%13 = lshr i64 %0, 16
%14 = and i64 %13, 255
%15 = tail call i32 @nand_addr(i64 %14)
%16 = tail call i32 @nand_cmd(i32 48)
%17 = tail call i32 (...) @wait_RnB()
br label %18
18: ; preds = %18, %2
%19 = phi i64 [ 0, %2 ], [ %31, %18 ]
%20 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%21 = getelementptr inbounds i8, i8* %1, i64 %19
store i8 %20, i8* %21
%22 = or i64 %19, 1
%23 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%24 = getelementptr inbounds i8, i8* %1, i64 %22
store i8 %23, i8* %24
%25 = or i64 %19, 2
%26 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%27 = getelementptr inbounds i8, i8* %1, i64 %25
store i8 %26, i8* %27
%28 = or i64 %19, 3
%29 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%30 = getelementptr inbounds i8, i8* %1, i64 %28
store i8 %29, i8* %30
%31 = add nuw nsw i64 %19, 4
%32 = icmp eq i64 %31, 4096
br i1 %32, label %33, label %18
33: ; preds = %18
%34 = tail call i32 (...) @delselect_ship()
ret void
}