int nandll_read_page(unsigned char *buf, unsigned long addr) {
  int i;
  int page_size = 2048;
  ((*(volatile unsigned long *)(0x70200000 + 0x04)) &= ~(1 << 1));
  (*(volatile unsigned long *)(0x70200000 + 0x08)) = 0;
  (*(volatile unsigned long *)(0x70200000 + 0x0c)) = 0;
  (*(volatile unsigned long *)(0x70200000 + 0x0c)) = 0;
  (*(volatile unsigned long *)(0x70200000 + 0x0c)) = (addr)&0xff;
  (*(volatile unsigned long *)(0x70200000 + 0x0c)) = (addr >> 8) & 0xff;
  (*(volatile unsigned long *)(0x70200000 + 0x0c)) = (addr >> 16) & 0xff;
  (*(volatile unsigned long *)(0x70200000 + 0x08)) = 0x30;
  do {
    while (!((*(volatile unsigned long *)(0x70200000 + 0x28)) & (1 << 0)))
      ;
  } while (0);
  for (i = 0; i < page_size; i++) {
    *buf++ = (*(volatile unsigned char *)(0x70200000 + 0x10));
  }
  ((*(volatile unsigned long *)(0x70200000 + 0x04)) |= (1 << 1));
  return 0;
}


x86 assembly (clang, -O0):
<nandll_read_page>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x800,-0x18(%rbp)
mov    $0x70200004,%eax
mov    (%rax),%rcx
and    $0xfffffffffffffffd,%rcx
mov    $0x70200004,%eax
mov    %rcx,(%rax)
mov    $0x70200008,%eax
movq   $0x0,(%rax)
mov    $0x7020000c,%eax
movq   $0x0,(%rax)
mov    $0x7020000c,%eax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rcx
and    $0xff,%rcx
mov    $0x7020000c,%eax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rcx
shr    $0x8,%rcx
and    $0xff,%rcx
mov    $0x7020000c,%eax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rcx
shr    $0x10,%rcx
and    $0xff,%rcx
mov    $0x7020000c,%eax
mov    %rcx,(%rax)
mov    $0x70200008,%eax
movq   $0x30,(%rax)
jmp    119d <nandll_read_page+0x9d>
mov    $0x70200028,%eax
mov    (%rax),%rax
and    $0x1,%rax
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11bf <nandll_read_page+0xbf>
jmp    11c4 <nandll_read_page+0xc4>
jmp    119d <nandll_read_page+0x9d>
jmp    11c9 <nandll_read_page+0xc9>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1202 <nandll_read_page+0x102>
mov    $0x70200010,%eax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d0 <nandll_read_page+0xd0>
mov    $0x70200004,%eax
mov    (%rax),%rcx
or     $0x2,%rcx
mov    $0x70200004,%eax
mov    %rcx,(%rax)
xor    %eax,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<nandll_read_page>:
andq   $0xfffffffffffffffd,0x70200004
70 fd
mov    %rsi,%rax
movq   $0x0,0x70200008
movq   $0x0,0x7020000c
movq   $0x0,0x7020000c
movzbl %al,%ecx
mov    %rcx,0x7020000c
70
movzbl %ah,%ecx
mov    %rcx,0x7020000c
70
shr    $0x10,%eax
movzbl %al,%eax
mov    %rax,0x7020000c
70
movq   $0x30,0x70200008
testq  $0x1,0x70200028
je     1160 <nandll_read_page+0x60>
xor    %eax,%eax
movzbl 0x70200010,%ecx
70
mov    %cl,(%rdi,%rax,1)
movzbl 0x70200010,%ecx
70
mov    %cl,0x1(%rdi,%rax,1)
movzbl 0x70200010,%ecx
70
mov    %cl,0x2(%rdi,%rax,1)
movzbl 0x70200010,%ecx
70
mov    %cl,0x3(%rdi,%rax,1)
movzbl 0x70200010,%ecx
70
mov    %cl,0x4(%rdi,%rax,1)
movzbl 0x70200010,%ecx
70
mov    %cl,0x5(%rdi,%rax,1)
movzbl 0x70200010,%ecx
70
mov    %cl,0x6(%rdi,%rax,1)
movzbl 0x70200010,%ecx
70
mov    %cl,0x7(%rdi,%rax,1)
add    $0x8,%rax
cmp    $0x800,%eax
jne    1170 <nandll_read_page+0x70>
orq    $0x2,0x70200004
70 02
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @nandll_read_page(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
store i32 2048, i32* %6
%7 = load volatile i64, i64* inttoptr (i64 1881145348 to i64*)
%8 = and i64 %7, -3
store volatile i64 %8, i64* inttoptr (i64 1881145348 to i64*)
store volatile i64 0, i64* inttoptr (i64 1881145352 to i64*)
store volatile i64 0, i64* inttoptr (i64 1881145356 to i64*)
store volatile i64 0, i64* inttoptr (i64 1881145356 to i64*)
%9 = load i64, i64* %4
%10 = and i64 %9, 255
store volatile i64 %10, i64* inttoptr (i64 1881145356 to i64*)
%11 = load i64, i64* %4
%12 = lshr i64 %11, 8
%13 = and i64 %12, 255
store volatile i64 %13, i64* inttoptr (i64 1881145356 to i64*)
%14 = load i64, i64* %4
%15 = lshr i64 %14, 16
%16 = and i64 %15, 255
store volatile i64 %16, i64* inttoptr (i64 1881145356 to i64*)
store volatile i64 48, i64* inttoptr (i64 1881145352 to i64*)
br label %17
17: ; preds = %2
br label %18
18: ; preds = %23, %17
%19 = load volatile i64, i64* inttoptr (i64 1881145384 to i64*)
%20 = and i64 %19, 1
%21 = icmp ne i64 %20, 0
%22 = xor i1 %21, true
br i1 %22, label %23, label %24
23: ; preds = %18
br label %18
24: ; preds = %18
br label %25
25: ; preds = %24
store i32 0, i32* %5
br label %26
26: ; preds = %34, %25
%27 = load i32, i32* %5
%28 = load i32, i32* %6
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %37
30: ; preds = %26
%31 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %3
store i8 %31, i8* %32
br label %34
34: ; preds = %30
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %26
37: ; preds = %26
%38 = load volatile i64, i64* inttoptr (i64 1881145348 to i64*)
%39 = or i64 %38, 2
store volatile i64 %39, i64* inttoptr (i64 1881145348 to i64*)
ret i32 0
}

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