int nandll_read_page(unsigned char *buf, unsigned long addr, int large_block) {
  int i;
  int page_size = 512;
  if (large_block == 2)
    page_size = 4096;
  ((*((volatile unsigned long *)0x70200004)) &= ~(1 << 1));
  (*((volatile unsigned long *)0x70200008)) = 0;
  (*((volatile unsigned long *)0x7020000C)) = 0;
  if (large_block)
    (*((volatile unsigned long *)0x7020000C)) = 0;
  (*((volatile unsigned long *)0x7020000C)) = (addr)&0xff;
  (*((volatile unsigned long *)0x7020000C)) = (addr >> 8) & 0xff;
  (*((volatile unsigned long *)0x7020000C)) = (addr >> 16) & 0xff;
  if (large_block)
    (*((volatile unsigned long *)0x70200008)) = 0x30;
  do {
    while (!((*((volatile unsigned long *)0x70200028)) & (1 << 0)))
      ;
  } while (0);
  for (i = 0; i < page_size; i++) {
    *buf++ = (*((volatile unsigned char *)0x70200010));
  }
  ((*((volatile unsigned long *)0x70200004)) |= (1 << 1));
  return 0;
}


x86 assembly (clang, -O0):
<nandll_read_page>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x200,-0x1c(%rbp)
cmpl   $0x2,-0x14(%rbp)
jne    1127 <nandll_read_page+0x27>
movl   $0x1000,-0x1c(%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)
cmpl   $0x0,-0x14(%rbp)
je     1169 <nandll_read_page+0x69>
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)
cmpl   $0x0,-0x14(%rbp)
je     11c0 <nandll_read_page+0xc0>
mov    $0x70200008,%eax
movq   $0x30,(%rax)
jmp    11c5 <nandll_read_page+0xc5>
jmp    11ca <nandll_read_page+0xca>
mov    $0x70200028,%eax
mov    (%rax),%rax
and    $0x1,%rax
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ec <nandll_read_page+0xec>
jmp    11f1 <nandll_read_page+0xf1>
jmp    11ca <nandll_read_page+0xca>
jmp    11f6 <nandll_read_page+0xf6>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    122f <nandll_read_page+0x12f>
mov    $0x70200010,%eax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11fd <nandll_read_page+0xfd>
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>:
cmp    $0x2,%edx
mov    $0x1000,%ecx
mov    $0x200,%eax
cmove  %ecx,%eax
andq   $0xfffffffffffffffd,0x70200004
70 fd
mov    %rsi,%rcx
movq   $0x0,0x70200008
movq   $0x0,0x7020000c
test   %edx,%edx
je     1176 <nandll_read_page+0x76>
movq   $0x0,0x7020000c
movzbl %cl,%edx
mov    %rdx,0x7020000c
70
movzbl %ch,%edx
mov    %rdx,0x7020000c
70
shr    $0x10,%ecx
movzbl %cl,%ecx
mov    %rcx,0x7020000c
70
movq   $0x30,0x70200008
jmp    11a0 <nandll_read_page+0xa0>
movzbl %cl,%edx
mov    %rdx,0x7020000c
70
movzbl %ch,%edx
mov    %rdx,0x7020000c
70
shr    $0x10,%ecx
movzbl %cl,%ecx
mov    %rcx,0x7020000c
70
nopw   0x0(%rax,%rax,1)
testq  $0x1,0x70200028
je     11a0 <nandll_read_page+0xa0>
mov    %eax,%eax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x70200010,%edx
70
mov    %dl,(%rdi,%rcx,1)
movzbl 0x70200010,%edx
70
mov    %dl,0x1(%rdi,%rcx,1)
movzbl 0x70200010,%edx
70
mov    %dl,0x2(%rdi,%rcx,1)
movzbl 0x70200010,%edx
70
mov    %dl,0x3(%rdi,%rcx,1)
movzbl 0x70200010,%edx
70
mov    %dl,0x4(%rdi,%rcx,1)
movzbl 0x70200010,%edx
70
mov    %dl,0x5(%rdi,%rcx,1)
movzbl 0x70200010,%edx
70
mov    %dl,0x6(%rdi,%rcx,1)
movzbl 0x70200010,%edx
70
mov    %dl,0x7(%rdi,%rcx,1)
add    $0x8,%rcx
cmp    %ecx,%eax
jne    11c0 <nandll_read_page+0xc0>
orq    $0x2,0x70200004
70 02
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @nandll_read_page(i8* %0, i64 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
store i32 512, i32* %8
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 4096, i32* %8
br label %12
12: ; preds = %11, %3
%13 = load volatile i64, i64* inttoptr (i64 1881145348 to i64*)
%14 = and i64 %13, -3
store volatile i64 %14, 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*)
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
store volatile i64 0, i64* inttoptr (i64 1881145356 to i64*)
br label %18
18: ; preds = %17, %12
%19 = load i64, i64* %5
%20 = and i64 %19, 255
store volatile i64 %20, i64* inttoptr (i64 1881145356 to i64*)
%21 = load i64, i64* %5
%22 = lshr i64 %21, 8
%23 = and i64 %22, 255
store volatile i64 %23, i64* inttoptr (i64 1881145356 to i64*)
%24 = load i64, i64* %5
%25 = lshr i64 %24, 16
%26 = and i64 %25, 255
store volatile i64 %26, i64* inttoptr (i64 1881145356 to i64*)
%27 = load i32, i32* %6
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %18
store volatile i64 48, i64* inttoptr (i64 1881145352 to i64*)
br label %30
30: ; preds = %29, %18
br label %31
31: ; preds = %30
br label %32
32: ; preds = %37, %31
%33 = load volatile i64, i64* inttoptr (i64 1881145384 to i64*)
%34 = and i64 %33, 1
%35 = icmp ne i64 %34, 0
%36 = xor i1 %35, true
br i1 %36, label %37, label %38
37: ; preds = %32
br label %32
38: ; preds = %32
br label %39
39: ; preds = %38
store i32 0, i32* %7
br label %40
40: ; preds = %48, %39
%41 = load i32, i32* %7
%42 = load i32, i32* %8
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %51
44: ; preds = %40
%45 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %4
store i8 %45, i8* %46
br label %48
48: ; preds = %44
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
store i32 %50, i32* %7
br label %40
51: ; preds = %40
%52 = load volatile i64, i64* inttoptr (i64 1881145348 to i64*)
%53 = or i64 %52, 2
store volatile i64 %53, i64* inttoptr (i64 1881145348 to i64*)
ret i32 0
}

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