void nand_read_page2048(unsigned int page, unsigned char *buf) {
  unsigned int i;
  unsigned int *word_buf = (unsigned int *)buf;
  unsigned int word32;
  do {
    (*(volatile unsigned long *)(0x4E000000 + 0x04)) &= (~(1 << 1));
  } while (0);
  do {
    (*(volatile unsigned long *)(0x4E000000 + 0x20)) |= (1 << 2);
  } while (0);
  do {
    (*(volatile unsigned char *)(0x4E000000 + 0x08)) = 0x00;
  } while (0);
  do {
    (*(volatile unsigned char *)(0x4E000000 + 0x0C)) = 0x00;
  } while (0);
  do {
    (*(volatile unsigned char *)(0x4E000000 + 0x0C)) = 0x00;
  } while (0);
  do {
    (*(volatile unsigned char *)(0x4E000000 + 0x0C)) = page & 0xFF;
  } while (0);
  do {
    (*(volatile unsigned char *)(0x4E000000 + 0x0C)) = (page >> 8) & 0xFF;
  } while (0);
  do {
    (*(volatile unsigned char *)(0x4E000000 + 0x0C)) = (page >> 16) & 0xFF;
  } while (0);
  do {
    (*(volatile unsigned char *)(0x4E000000 + 0x08)) = 0x30;
  } while (0);
  while (!((*(volatile unsigned long *)(0x4E000000 + 0x20)) & (1 << 2)))
    ;
  for (i = 0; i < ((1 << 11) >> 2); ++i) {
    word32 = ((*(volatile unsigned char *)(0x4E000000 + 0x10)));
    word32 |= (((*(volatile unsigned char *)(0x4E000000 + 0x10))) << 8);
    word32 |= (((*(volatile unsigned char *)(0x4E000000 + 0x10))) << 16);
    word32 |= (((*(volatile unsigned char *)(0x4E000000 + 0x10))) << 24);
    *word_buf++ = word32;
  }
  do {
    (*(volatile unsigned long *)(0x4E000000 + 0x04)) |= (1 << 1);
  } while (0);
}


x86 assembly (clang, -O0):
<nand_read_page2048>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x4e000004,%eax
mov    (%rax),%rcx
and    $0xfffffffffffffffd,%rcx
mov    $0x4e000004,%eax
mov    %rcx,(%rax)
jmp    112c <nand_read_page2048+0x2c>
mov    $0x4e000020,%eax
mov    (%rax),%rcx
or     $0x4,%rcx
mov    $0x4e000020,%eax
mov    %rcx,(%rax)
jmp    1145 <nand_read_page2048+0x45>
mov    $0x4e000008,%eax
movb   $0x0,(%rax)
jmp    1152 <nand_read_page2048+0x52>
mov    $0x4e00000c,%eax
movb   $0x0,(%rax)
jmp    115f <nand_read_page2048+0x5f>
mov    $0x4e00000c,%eax
movb   $0x0,(%rax)
jmp    116c <nand_read_page2048+0x6c>
mov    -0x4(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    $0x4e00000c,%eax
mov    %cl,(%rax)
jmp    1182 <nand_read_page2048+0x82>
mov    -0x4(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    $0x4e00000c,%eax
mov    %cl,(%rax)
jmp    119b <nand_read_page2048+0x9b>
mov    -0x4(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    $0x4e00000c,%eax
mov    %cl,(%rax)
jmp    11b4 <nand_read_page2048+0xb4>
mov    $0x4e000008,%eax
movb   $0x30,(%rax)
jmp    11c1 <nand_read_page2048+0xc1>
mov    $0x4e000020,%eax
mov    (%rax),%rax
and    $0x4,%rax
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e3 <nand_read_page2048+0xe3>
jmp    11e8 <nand_read_page2048+0xe8>
jmp    11c1 <nand_read_page2048+0xc1>
movl   $0x0,-0x14(%rbp)
cmpl   $0x200,-0x14(%rbp)
jae    1264 <nand_read_page2048+0x164>
mov    $0x4e000010,%eax
mov    (%rax),%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
mov    $0x4e000010,%eax
mov    (%rax),%al
movzbl %al,%eax
shl    $0x8,%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x4e000010,%eax
mov    (%rax),%al
movzbl %al,%eax
shl    $0x10,%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x4e000010,%eax
mov    (%rax),%al
movzbl %al,%eax
shl    $0x18,%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x20(%rbp)
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ef <nand_read_page2048+0xef>
jmp    1269 <nand_read_page2048+0x169>
mov    $0x4e000004,%eax
mov    (%rax),%rcx
or     $0x2,%rcx
mov    $0x4e000004,%eax
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<nand_read_page2048>:
andq   $0xfffffffffffffffd,0x4e000004
4e fd
mov    %edi,%eax
orq    $0x4,0x4e000020
4e 04
movb   $0x0,0x4e000008
movb   $0x0,0x4e00000c
movb   $0x0,0x4e00000c
mov    %al,0x4e00000c
mov    %ah,0x4e00000c
shr    $0x10,%eax
mov    %al,0x4e00000c
movb   $0x30,0x4e000008
30
nopl   0x0(%rax)
testq  $0x4,0x4e000020
je     1150 <nand_read_page2048+0x50>
xor    %eax,%eax
movzbl 0x4e000010,%ecx
4e
movzbl 0x4e000010,%edx
4e
shl    $0x8,%edx
or     %ecx,%edx
movzbl 0x4e000010,%ecx
4e
shl    $0x10,%ecx
or     %edx,%ecx
movzbl 0x4e000010,%edx
4e
shl    $0x18,%edx
or     %ecx,%edx
mov    %edx,(%rsi,%rax,4)
movzbl 0x4e000010,%ecx
4e
movzbl 0x4e000010,%edx
4e
shl    $0x8,%edx
or     %ecx,%edx
movzbl 0x4e000010,%ecx
4e
shl    $0x10,%ecx
or     %edx,%ecx
movzbl 0x4e000010,%edx
4e
shl    $0x18,%edx
or     %ecx,%edx
mov    %edx,0x4(%rsi,%rax,4)
add    $0x2,%rax
cmp    $0x200,%eax
jne    1160 <nand_read_page2048+0x60>
orq    $0x2,0x4e000004
4e 02
ret

LLVM IR (-O0):
define void @nand_read_page2048(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = bitcast i8* %8 to i32*
store i32* %9, i32** %6
br label %10
10: ; preds = %2
%11 = load volatile i64, i64* inttoptr (i64 1308622852 to i64*)
%12 = and i64 %11, -3
store volatile i64 %12, i64* inttoptr (i64 1308622852 to i64*)
br label %13
13: ; preds = %10
br label %14
14: ; preds = %13
%15 = load volatile i64, i64* inttoptr (i64 1308622880 to i64*)
%16 = or i64 %15, 4
store volatile i64 %16, i64* inttoptr (i64 1308622880 to i64*)
br label %17
17: ; preds = %14
br label %18
18: ; preds = %17
store volatile i8 0, i8* inttoptr (i64 1308622856 to i8*)
br label %19
19: ; preds = %18
br label %20
20: ; preds = %19
store volatile i8 0, i8* inttoptr (i64 1308622860 to i8*)
br label %21
21: ; preds = %20
br label %22
22: ; preds = %21
store volatile i8 0, i8* inttoptr (i64 1308622860 to i8*)
br label %23
23: ; preds = %22
br label %24
24: ; preds = %23
%25 = load i32, i32* %3
%26 = and i32 %25, 255
%27 = trunc i32 %26 to i8
store volatile i8 %27, i8* inttoptr (i64 1308622860 to i8*)
br label %28
28: ; preds = %24
br label %29
29: ; preds = %28
%30 = load i32, i32* %3
%31 = lshr i32 %30, 8
%32 = and i32 %31, 255
%33 = trunc i32 %32 to i8
store volatile i8 %33, i8* inttoptr (i64 1308622860 to i8*)
br label %34
34: ; preds = %29
br label %35
35: ; preds = %34
%36 = load i32, i32* %3
%37 = lshr i32 %36, 16
%38 = and i32 %37, 255
%39 = trunc i32 %38 to i8
store volatile i8 %39, i8* inttoptr (i64 1308622860 to i8*)
br label %40
40: ; preds = %35
br label %41
41: ; preds = %40
store volatile i8 48, i8* inttoptr (i64 1308622856 to i8*)
br label %42
42: ; preds = %41
br label %43
43: ; preds = %48, %42
%44 = load volatile i64, i64* inttoptr (i64 1308622880 to i64*)
%45 = and i64 %44, 4
%46 = icmp ne i64 %45, 0
%47 = xor i1 %46, true
br i1 %47, label %48, label %49
48: ; preds = %43
br label %43
49: ; preds = %43
store i32 0, i32* %5
br label %50
50: ; preds = %74, %49
%51 = load i32, i32* %5
%52 = icmp ult i32 %51, 512
br i1 %52, label %53, label %77
53: ; preds = %50
%54 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%55 = zext i8 %54 to i32
store i32 %55, i32* %7
%56 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%57 = zext i8 %56 to i32
%58 = shl i32 %57, 8
%59 = load i32, i32* %7
%60 = or i32 %59, %58
store i32 %60, i32* %7
%61 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%62 = zext i8 %61 to i32
%63 = shl i32 %62, 16
%64 = load i32, i32* %7
%65 = or i32 %64, %63
store i32 %65, i32* %7
%66 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%67 = zext i8 %66 to i32
%68 = shl i32 %67, 24
%69 = load i32, i32* %7
%70 = or i32 %69, %68
store i32 %70, i32* %7
%71 = load i32, i32* %7
%72 = load i32*, i32** %6
%73 = getelementptr inbounds i32, i32* %72, i32 1
store i32* %73, i32** %6
store i32 %71, i32* %72
br label %74
74: ; preds = %53
%75 = load i32, i32* %5
%76 = add i32 %75, 1
store i32 %76, i32* %5
br label %50
77: ; preds = %50
br label %78
78: ; preds = %77
%79 = load volatile i64, i64* inttoptr (i64 1308622852 to i64*)
%80 = or i64 %79, 2
store volatile i64 %80, i64* inttoptr (i64 1308622852 to i64*)
br label %81
81: ; preds = %78
ret void
}

LLVM IR (-O2):
define void @nand_read_page2048(i32 %0, i8* nocapture writeonly %1) {
%3 = load volatile i64, i64* inttoptr (i64 1308622852 to i64*)
%4 = and i64 %3, -3
store volatile i64 %4, i64* inttoptr (i64 1308622852 to i64*)
%5 = load volatile i64, i64* inttoptr (i64 1308622880 to i64*)
%6 = or i64 %5, 4
store volatile i64 %6, i64* inttoptr (i64 1308622880 to i64*)
store volatile i8 0, i8* inttoptr (i64 1308622856 to i8*)
store volatile i8 0, i8* inttoptr (i64 1308622860 to i8*)
store volatile i8 0, i8* inttoptr (i64 1308622860 to i8*)
%7 = trunc i32 %0 to i8
store volatile i8 %7, i8* inttoptr (i64 1308622860 to i8*)
%8 = lshr i32 %0, 8
%9 = trunc i32 %8 to i8
store volatile i8 %9, i8* inttoptr (i64 1308622860 to i8*)
%10 = lshr i32 %0, 16
%11 = trunc i32 %10 to i8
store volatile i8 %11, i8* inttoptr (i64 1308622860 to i8*)
store volatile i8 48, i8* inttoptr (i64 1308622856 to i8*)
br label %12
12: ; preds = %12, %2
%13 = load volatile i64, i64* inttoptr (i64 1308622880 to i64*)
%14 = and i64 %13, 4
%15 = icmp eq i64 %14, 0
br i1 %15, label %12, label %16
16: ; preds = %12
%17 = bitcast i8* %1 to i32*
br label %18
18: ; preds = %18, %16
%19 = phi i32 [ 0, %16 ], [ %51, %18 ]
%20 = phi i32* [ %17, %16 ], [ %50, %18 ]
%21 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%22 = zext i8 %21 to i32
%23 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%24 = zext i8 %23 to i32
%25 = shl nuw nsw i32 %24, 8
%26 = or i32 %25, %22
%27 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%28 = zext i8 %27 to i32
%29 = shl nuw nsw i32 %28, 16
%30 = or i32 %26, %29
%31 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%32 = zext i8 %31 to i32
%33 = shl nuw i32 %32, 24
%34 = or i32 %30, %33
%35 = getelementptr inbounds i32, i32* %20, i64 1
store i32 %34, i32* %20
%36 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%37 = zext i8 %36 to i32
%38 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%39 = zext i8 %38 to i32
%40 = shl nuw nsw i32 %39, 8
%41 = or i32 %40, %37
%42 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%43 = zext i8 %42 to i32
%44 = shl nuw nsw i32 %43, 16
%45 = or i32 %41, %44
%46 = load volatile i8, i8* inttoptr (i64 1308622864 to i8*)
%47 = zext i8 %46 to i32
%48 = shl nuw i32 %47, 24
%49 = or i32 %45, %48
%50 = getelementptr inbounds i32, i32* %20, i64 2
store i32 %49, i32* %35
%51 = add nuw nsw i32 %19, 2
%52 = icmp eq i32 %51, 512
br i1 %52, label %53, label %18
53: ; preds = %18
%54 = load volatile i64, i64* inttoptr (i64 1308622852 to i64*)
%55 = or i64 %54, 2
store volatile i64 %55, i64* inttoptr (i64 1308622852 to i64*)
ret void
}