unsigned char Nand_ReadPage(const int page, unsigned char *const buffer) {
  int i;
  Nand_Reset();
  { (*(volatile unsigned *)0x4E000004) &= ~(1 << 1); };
  { (*(volatile unsigned *)0x4E000020) |= (1 << 2); };
  { (*(volatile unsigned *)0x4E000008) = (0x00); };
  { (*(volatile unsigned *)0x4E00000C) = (0x0); };
  { (*(volatile unsigned *)0x4E00000C) = (0x0); };
  { (*(volatile unsigned *)0x4E00000C) = (page & 0xff); };
  { (*(volatile unsigned *)0x4E00000C) = ((page >> 8) & 0xff); };
  { (*(volatile unsigned *)0x4E00000C) = ((page >> 16) & 0xff); };
  { (*(volatile unsigned *)0x4E000008) = (0x30); };
  {
    while (!((*(volatile unsigned *)0x4E000020) & (1 << 2)))
      ;
  };
  for (i = 0; i < 2048; i++) {
    buffer[i] = ((*(volatile unsigned char *)0x4E000010));
  }
  { (*(volatile unsigned *)0x4E000020) |= (1 << 2); };
  { (*(volatile unsigned *)0x4E000004) |= (1 << 1); };
}


x86 assembly (clang, -O0):
<Nand_ReadPage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <Nand_Reset@plt>
mov    $0x4e000004,%eax
mov    (%rax),%ecx
and    $0xfffffffd,%ecx
mov    $0x4e000004,%eax
mov    %ecx,(%rax)
mov    $0x4e000020,%eax
mov    (%rax),%ecx
or     $0x4,%ecx
mov    $0x4e000020,%eax
mov    %ecx,(%rax)
mov    $0x4e000008,%eax
movl   $0x0,(%rax)
mov    $0x4e00000c,%eax
movl   $0x0,(%rax)
mov    $0x4e00000c,%eax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%ecx
and    $0xff,%ecx
mov    $0x4e00000c,%eax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    $0x4e00000c,%eax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    $0x4e00000c,%eax
mov    %ecx,(%rax)
mov    $0x4e000008,%eax
movl   $0x30,(%rax)
mov    $0x4e000020,%eax
mov    (%rax),%eax
and    $0x4,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c9 <Nand_ReadPage+0xb9>
jmp    11ce <Nand_ReadPage+0xbe>
jmp    11aa <Nand_ReadPage+0x9a>
movl   $0x0,-0x14(%rbp)
cmpl   $0x800,-0x14(%rbp)
jge    1202 <Nand_ReadPage+0xf2>
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    11d5 <Nand_ReadPage+0xc5>
mov    $0x4e000020,%eax
mov    (%rax),%ecx
or     $0x4,%ecx
mov    $0x4e000020,%eax
mov    %ecx,(%rax)
mov    $0x4e000004,%eax
mov    (%rax),%ecx
or     $0x2,%ecx
mov    $0x4e000004,%eax
mov    %ecx,(%rax)
movzbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Nand_ReadPage>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <Nand_Reset@plt>
andl   $0xfffffffd,0x4e000004
fd
orl    $0x4,0x4e000020
04
movl   $0x0,0x4e000008
movl   $0x0,0x4e00000c
movl   $0x0,0x4e00000c
mov    %ebp,%ecx
movzbl %cl,%eax
mov    %eax,0x4e00000c
movzbl %ch,%eax
mov    %eax,0x4e00000c
shr    $0x10,%ecx
movzbl %cl,%eax
mov    %eax,0x4e00000c
movl   $0x30,0x4e000008
xchg   %ax,%ax
testl  $0x4,0x4e000020
je     1180 <Nand_ReadPage+0x70>
xor    %eax,%eax
nop
movzbl 0x4e000010,%ecx
4e
mov    %cl,(%rbx,%rax,1)
movzbl 0x4e000010,%ecx
4e
mov    %cl,0x1(%rbx,%rax,1)
movzbl 0x4e000010,%ecx
4e
mov    %cl,0x2(%rbx,%rax,1)
movzbl 0x4e000010,%ecx
4e
mov    %cl,0x3(%rbx,%rax,1)
add    $0x4,%rax
cmp    $0x800,%rax
jne    1190 <Nand_ReadPage+0x80>
orl    $0x4,0x4e000020
04
orl    $0x2,0x4e000004
02
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @Nand_ReadPage(i32 %0, i8* %1) {
%3 = alloca i8
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = call i32 (...) @Nand_Reset()
%8 = load volatile i32, i32* inttoptr (i64 1308622852 to i32*)
%9 = and i32 %8, -3
store volatile i32 %9, i32* inttoptr (i64 1308622852 to i32*)
%10 = load volatile i32, i32* inttoptr (i64 1308622880 to i32*)
%11 = or i32 %10, 4
store volatile i32 %11, i32* inttoptr (i64 1308622880 to i32*)
store volatile i32 0, i32* inttoptr (i64 1308622856 to i32*)
store volatile i32 0, i32* inttoptr (i64 1308622860 to i32*)
store volatile i32 0, i32* inttoptr (i64 1308622860 to i32*)
%12 = load i32, i32* %4
%13 = and i32 %12, 255
store volatile i32 %13, i32* inttoptr (i64 1308622860 to i32*)
%14 = load i32, i32* %4
%15 = ashr i32 %14, 8
%16 = and i32 %15, 255
store volatile i32 %16, i32* inttoptr (i64 1308622860 to i32*)
%17 = load i32, i32* %4
%18 = ashr i32 %17, 16
%19 = and i32 %18, 255
store volatile i32 %19, i32* inttoptr (i64 1308622860 to i32*)
store volatile i32 48, i32* inttoptr (i64 1308622856 to i32*)
br label %20
20: ; preds = %25, %2
%21 = load volatile i32, i32* inttoptr (i64 1308622880 to i32*)
%22 = and i32 %21, 4
%23 = icmp ne i32 %22, 0
%24 = xor i1 %23, true
br i1 %24, label %25, label %26
25: ; preds = %20
br label %20
26: ; preds = %20
store i32 0, i32* %6
br label %27
27: ; preds = %36, %26
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 2048
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%32 = load i8*, i8** %5
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %31, i8* %35
br label %36
36: ; preds = %30
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %27
39: ; preds = %27
%40 = load volatile i32, i32* inttoptr (i64 1308622880 to i32*)
%41 = or i32 %40, 4
store volatile i32 %41, i32* inttoptr (i64 1308622880 to i32*)
%42 = load volatile i32, i32* inttoptr (i64 1308622852 to i32*)
%43 = or i32 %42, 2
store volatile i32 %43, i32* inttoptr (i64 1308622852 to i32*)
%44 = load i8, i8* %3
ret i8 %44
}

LLVM IR (-O2):
define zeroext i8 @Nand_ReadPage(i32 %0, i8* nocapture writeonly %1) {
%3 = tail call i32 (...) @Nand_Reset()
%4 = load volatile i32, i32* inttoptr (i64 1308622852 to i32*)
%5 = and i32 %4, -3
store volatile i32 %5, i32* inttoptr (i64 1308622852 to i32*)
%6 = load volatile i32, i32* inttoptr (i64 1308622880 to i32*)
%7 = or i32 %6, 4
store volatile i32 %7, i32* inttoptr (i64 1308622880 to i32*)
store volatile i32 0, i32* inttoptr (i64 1308622856 to i32*)
store volatile i32 0, i32* inttoptr (i64 1308622860 to i32*)
store volatile i32 0, i32* inttoptr (i64 1308622860 to i32*)
%8 = and i32 %0, 255
store volatile i32 %8, i32* inttoptr (i64 1308622860 to i32*)
%9 = lshr i32 %0, 8
%10 = and i32 %9, 255
store volatile i32 %10, i32* inttoptr (i64 1308622860 to i32*)
%11 = lshr i32 %0, 16
%12 = and i32 %11, 255
store volatile i32 %12, i32* inttoptr (i64 1308622860 to i32*)
store volatile i32 48, i32* inttoptr (i64 1308622856 to i32*)
br label %13
13: ; preds = %13, %2
%14 = load volatile i32, i32* inttoptr (i64 1308622880 to i32*)
%15 = and i32 %14, 4
%16 = icmp eq i32 %15, 0
br i1 %16, label %13, label %17
17: ; preds = %13, %17
%18 = phi i64 [ %30, %17 ], [ 0, %13 ]
%19 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%20 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 %19, i8* %20
%21 = or i64 %18, 1
%22 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%23 = getelementptr inbounds i8, i8* %1, i64 %21
store i8 %22, i8* %23
%24 = or i64 %18, 2
%25 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%26 = getelementptr inbounds i8, i8* %1, i64 %24
store i8 %25, i8* %26
%27 = or i64 %18, 3
%28 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%29 = getelementptr inbounds i8, i8* %1, i64 %27
store i8 %28, i8* %29
%30 = add nuw nsw i64 %18, 4
%31 = icmp eq i64 %30, 2048
br i1 %31, label %32, label %17
32: ; preds = %17
%33 = load volatile i32, i32* inttoptr (i64 1308622880 to i32*)
%34 = or i32 %33, 4
store volatile i32 %34, i32* inttoptr (i64 1308622880 to i32*)
%35 = load volatile i32, i32* inttoptr (i64 1308622852 to i32*)
%36 = or i32 %35, 2
store volatile i32 %36, i32* inttoptr (i64 1308622852 to i32*)
ret i8 undef
}