#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*/ select_chip();
int /*<<< orphan*/ send_addr(unsigned long);
int /*<<< orphan*/ send_cmd(int);
int /*<<< orphan*/ wait_RnB();
void NF_ReadPage(unsigned long addr, unsigned char *buff) {
  int i;
  select_chip();
  clear_RnB();
  send_cmd(0x00);
  send_addr(0x00);
  send_addr(0x00);
  send_addr(addr & 0xff);
  send_addr((addr >> 8) & 0xff);
  send_addr((addr >> 16) & 0xff);
  send_cmd(0x30);
  wait_RnB();
  for (i = 0; i < 2048; i++) {
    buff[i] = (*(volatile unsigned char *)0x4E000010);
  }
  deselect_chip();
}


x86 assembly (clang, -O0):
<NF_ReadPage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <select_chip@plt>
mov    $0x0,%al
call   1070 <clear_RnB@plt>
xor    %edi,%edi
call   1080 <send_cmd@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <send_addr@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <send_addr@plt>
mov    -0x8(%rbp),%rdi
and    $0xff,%rdi
call   1040 <send_addr@plt>
mov    -0x8(%rbp),%rdi
shr    $0x8,%rdi
and    $0xff,%rdi
call   1040 <send_addr@plt>
mov    -0x8(%rbp),%rdi
shr    $0x10,%rdi
and    $0xff,%rdi
call   1040 <send_addr@plt>
mov    $0x30,%edi
call   1080 <send_cmd@plt>
mov    $0x0,%al
call   1060 <wait_RnB@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x800,-0x14(%rbp)
jge    1214 <NF_ReadPage+0xb4>
mov    $0x4e000010,%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_ReadPage+0x87>
mov    $0x0,%al
call   1030 <deselect_chip@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NF_ReadPage>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <select_chip@plt>
xor    %eax,%eax
call   1070 <clear_RnB@plt>
xor    %edi,%edi
call   1080 <send_cmd@plt>
xor    %edi,%edi
call   1040 <send_addr@plt>
xor    %edi,%edi
call   1040 <send_addr@plt>
movzbl %r15b,%edi
call   1040 <send_addr@plt>
mov    %r15,%rax
movzbl %ah,%edi
call   1040 <send_addr@plt>
shr    $0x10,%r15d
movzbl %r15b,%edi
call   1040 <send_addr@plt>
mov    $0x30,%edi
call   1080 <send_cmd@plt>
xor    %eax,%eax
call   1060 <wait_RnB@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x4e000010,%eax
4e
mov    %al,(%r14,%rbx,1)
movzbl 0x4e000010,%eax
4e
mov    %al,0x1(%r14,%rbx,1)
movzbl 0x4e000010,%eax
4e
mov    %al,0x2(%r14,%rbx,1)
movzbl 0x4e000010,%eax
4e
mov    %al,0x3(%r14,%rbx,1)
add    $0x4,%rbx
cmp    $0x800,%rbx
jne    11d0 <NF_ReadPage+0x70>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <deselect_chip@plt>

LLVM IR (-O0):
define void @NF_ReadPage(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_chip()
%7 = call i32 (...) @clear_RnB()
%8 = call i32 @send_cmd(i32 0)
%9 = call i32 @send_addr(i64 0)
%10 = call i32 @send_addr(i64 0)
%11 = load i64, i64* %3
%12 = and i64 %11, 255
%13 = call i32 @send_addr(i64 %12)
%14 = load i64, i64* %3
%15 = lshr i64 %14, 8
%16 = and i64 %15, 255
%17 = call i32 @send_addr(i64 %16)
%18 = load i64, i64* %3
%19 = lshr i64 %18, 16
%20 = and i64 %19, 255
%21 = call i32 @send_addr(i64 %20)
%22 = call i32 @send_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, 2048
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = load volatile i8, i8* inttoptr (i64 1308622864 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 (...) @deselect_chip()
ret void
}

LLVM IR (-O2):
define void @NF_ReadPage(i64 %0, i8* nocapture writeonly %1) {
%3 = tail call i32 (...) @select_chip()
%4 = tail call i32 (...) @clear_RnB()
%5 = tail call i32 @send_cmd(i32 0)
%6 = tail call i32 @send_addr(i64 0)
%7 = tail call i32 @send_addr(i64 0)
%8 = and i64 %0, 255
%9 = tail call i32 @send_addr(i64 %8)
%10 = lshr i64 %0, 8
%11 = and i64 %10, 255
%12 = tail call i32 @send_addr(i64 %11)
%13 = lshr i64 %0, 16
%14 = and i64 %13, 255
%15 = tail call i32 @send_addr(i64 %14)
%16 = tail call i32 @send_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 1308622864 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 1308622864 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 1308622864 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 1308622864 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, 2048
br i1 %32, label %33, label %18
33: ; preds = %18
%34 = tail call i32 (...) @deselect_chip()
ret void
}