#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_page_read(int, unsigned char *);
void nand_to_ram(unsigned long start_addr, unsigned char *sdram_addr,
                 int size) {
  int i;
  for (i = 0; i < 4; i++, sdram_addr += 2048) {
    NF_page_read(i, sdram_addr);
  }
  size -= 1024 * 8;
  for (i = 4; size > 0;) {
    NF_page_read(i, sdram_addr);
    size -= 4096;
    sdram_addr += 4096;
    i++;
  }
}


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   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    115c <nand_to_ram+0x4c>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <NF_page_read@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x800,%rax
mov    %rax,-0x10(%rbp)
jmp    112a <nand_to_ram+0x1a>
mov    -0x14(%rbp),%eax
sub    $0x2000,%eax
mov    %eax,-0x14(%rbp)
movl   $0x4,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11ab <nand_to_ram+0x9b>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <NF_page_read@plt>
mov    -0x14(%rbp),%eax
sub    $0x1000,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1000,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116e <nand_to_ram+0x5e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nand_to_ram>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r15
xor    %edi,%edi
call   1030 <NF_page_read@plt>
lea    0x800(%r15),%rsi
mov    $0x1,%edi
call   1030 <NF_page_read@plt>
lea    0x1000(%r15),%rsi
mov    $0x2,%edi
call   1030 <NF_page_read@plt>
lea    0x1800(%r15),%rsi
mov    $0x3,%edi
call   1030 <NF_page_read@plt>
cmp    $0x2001,%r14d
jl     11a4 <nand_to_ram+0x94>
add    $0x2000,%r15
add    $0xffffdfff,%r14d
shr    $0xc,%r14d
not    %r14d
mov    $0x4,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r15,%rsi
call   1030 <NF_page_read@plt>
add    $0x1000,%r15
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x4,%eax
jne    1180 <nand_to_ram+0x70>
pop    %rbx
pop    %r14
pop    %r15
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
store i64 %0, i64* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %15, %3
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 4
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = load i32, i32* %7
%13 = load i8*, i8** %5
%14 = call i32 @NF_page_read(i32 %12, i8* %13)
br label %15
15: ; preds = %11
%16 = load i32, i32* %7
%17 = add nsw i32 %16, 1
store i32 %17, i32* %7
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 2048
store i8* %19, i8** %5
br label %8
20: ; preds = %8
%21 = load i32, i32* %6
%22 = sub nsw i32 %21, 8192
store i32 %22, i32* %6
store i32 4, i32* %7
br label %23
23: ; preds = %26, %20
%24 = load i32, i32* %6
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = load i32, i32* %7
%28 = load i8*, i8** %5
%29 = call i32 @NF_page_read(i32 %27, i8* %28)
%30 = load i32, i32* %6
%31 = sub nsw i32 %30, 4096
store i32 %31, i32* %6
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 4096
store i8* %33, i8** %5
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %23
36: ; preds = %23
ret void
}

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