#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*/ NF_PageRead(int, unsigned char *);
void nand_to_ram(unsigned long start_addr, unsigned char *sdram_addr,
                 int size) {
  int i;
  unsigned int page_shift = 12;
  for (i = 0; i < 4; i++, sdram_addr += (1 << (page_shift - 1))) {
    NF_PageRead(i, sdram_addr);
  }
  for (i = 4; i < (0x3c000 >> page_shift);
       i++, sdram_addr += (1 << page_shift)) {
    NF_PageRead(i, sdram_addr);
  }
}


x86 assembly (clang, -O0):
<nand_to_ram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0xc,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    1172 <nand_to_ram+0x62>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <NF_PageRead@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1131 <nand_to_ram+0x21>
movl   $0x4,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x1c(%rbp),%ecx
mov    $0x3c000,%edx
sar    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
jge    11c4 <nand_to_ram+0xb4>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <NF_PageRead@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1179 <nand_to_ram+0x69>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nand_to_ram>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
xor    %edi,%edi
call   1030 <NF_PageRead@plt>
lea    0x800(%rbx),%rsi
mov    $0x1,%edi
call   1030 <NF_PageRead@plt>
lea    0x1000(%rbx),%rsi
mov    $0x2,%edi
call   1030 <NF_PageRead@plt>
lea    0x1800(%rbx),%rsi
mov    $0x3,%edi
call   1030 <NF_PageRead@plt>
add    $0x2000,%rbx
mov    $0x4,%ebp
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <NF_PageRead@plt>
add    $0x1,%ebp
add    $0x1000,%rbx
cmp    $0x3c,%ebp
jne    1160 <nand_to_ram+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @nand_to_ram(i64 %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i64 %0, i64* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 12, i32* %8
store i32 0, i32* %7
br label %9
9: ; preds = %16, %3
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 4
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = load i32, i32* %7
%14 = load i8*, i8** %5
%15 = call i32 @NF_PageRead(i32 %13, i8* %14)
br label %16
16: ; preds = %12
%17 = load i32, i32* %7
%18 = add nsw i32 %17, 1
store i32 %18, i32* %7
%19 = load i32, i32* %8
%20 = sub i32 %19, 1
%21 = shl i32 1, %20
%22 = load i8*, i8** %5
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i8, i8* %22, i64 %23
store i8* %24, i8** %5
br label %9
25: ; preds = %9
store i32 4, i32* %7
br label %26
26: ; preds = %35, %25
%27 = load i32, i32* %7
%28 = load i32, i32* %8
%29 = ashr i32 245760, %28
%30 = icmp slt i32 %27, %29
br i1 %30, label %31, label %43
31: ; preds = %26
%32 = load i32, i32* %7
%33 = load i8*, i8** %5
%34 = call i32 @NF_PageRead(i32 %32, i8* %33)
br label %35
35: ; preds = %31
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
%38 = load i32, i32* %8
%39 = shl i32 1, %38
%40 = load i8*, i8** %5
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds i8, i8* %40, i64 %41
store i8* %42, i8** %5
br label %26
43: ; preds = %26
ret void
}

LLVM IR (-O2):
define void @nand_to_ram(i64 %0, i8* %1, i32 %2) {
%4 = tail call i32 @NF_PageRead(i32 0, i8* %1)
%5 = getelementptr inbounds i8, i8* %1, i64 2048
%6 = tail call i32 @NF_PageRead(i32 1, i8* %5)
%7 = getelementptr inbounds i8, i8* %1, i64 4096
%8 = tail call i32 @NF_PageRead(i32 2, i8* %7)
%9 = getelementptr inbounds i8, i8* %1, i64 6144
%10 = tail call i32 @NF_PageRead(i32 3, i8* %9)
%11 = getelementptr inbounds i8, i8* %1, i64 8192
br label %12
12: ; preds = %3, %12
%13 = phi i8* [ %17, %12 ], [ %11, %3 ]
%14 = phi i32 [ %16, %12 ], [ 4, %3 ]
%15 = tail call i32 @NF_PageRead(i32 %14, i8* %13)
%16 = add nuw nsw i32 %14, 1
%17 = getelementptr inbounds i8, i8* %13, i64 4096
%18 = icmp eq i32 %16, 60
br i1 %18, label %19, label %12
19: ; preds = %12
ret void
}