#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_ReadPage(int, unsigned char *);
void NandFlash_to_SDRAM(unsigned long nand_addr, unsigned char *sdram_addr,
                        int size) {
  int i;
  for (i = (nand_addr >> 11); size > 0;) {
    NF_ReadPage(i, sdram_addr);
    sdram_addr += 2048;
    size -= 2048;
    i++;
  }
}


x86 assembly (clang, -O0):
<NandFlash_to_SDRAM>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
shr    $0xb,%rax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    116b <NandFlash_to_SDRAM+0x5b>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <NF_ReadPage@plt>
mov    -0x10(%rbp),%rax
add    $0x800,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x800,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112e <NandFlash_to_SDRAM+0x1e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NandFlash_to_SDRAM>:
push   %rbp
push   %r14
push   %rbx
test   %edx,%edx
jle    1154 <NandFlash_to_SDRAM+0x44>
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
shr    $0xb,%rbp
add    $0x800,%r14d
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <NF_ReadPage@plt>
add    $0x800,%rbx
add    $0x1,%ebp
add    $0xfffff800,%r14d
cmp    $0x800,%r14d
ja     1130 <NandFlash_to_SDRAM+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @NandFlash_to_SDRAM(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
%8 = load i64, i64* %4
%9 = lshr i64 %8, 11
%10 = trunc i64 %9 to i32
store i32 %10, i32* %7
br label %11
11: ; preds = %14, %3
%12 = load i32, i32* %6
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = load i32, i32* %7
%16 = load i8*, i8** %5
%17 = call i32 @NF_ReadPage(i32 %15, i8* %16)
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 2048
store i8* %19, i8** %5
%20 = load i32, i32* %6
%21 = sub nsw i32 %20, 2048
store i32 %21, i32* %6
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %11
24: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @NandFlash_to_SDRAM(i64 %0, i8* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %17
5: ; preds = %3
%6 = lshr i64 %0, 11
%7 = trunc i64 %6 to i32
br label %8
8: ; preds = %5, %8
%9 = phi i32 [ %15, %8 ], [ %7, %5 ]
%10 = phi i32 [ %14, %8 ], [ %2, %5 ]
%11 = phi i8* [ %13, %8 ], [ %1, %5 ]
%12 = tail call i32 @NF_ReadPage(i32 %9, i8* %11)
%13 = getelementptr inbounds i8, i8* %11, i64 2048
%14 = add nsw i32 %10, -2048
%15 = add nsw i32 %9, 1
%16 = icmp ugt i32 %10, 2048
br i1 %16, label %8, label %17
17: ; preds = %8, %3
ret void
}