#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*/ Nand_Init();
int /*<<< orphan*/ Nand_ReadPage(int, unsigned char *);
int nand_read_ll(int start_page, int read_pages, unsigned char *buffer) {
  int i;
  Nand_Init();
  for (i = 0; i < read_pages; i++) {
    Nand_ReadPage(start_page, buffer + 2048 * i);
    start_page++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<nand_read_ll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    $0x0,%al
call   1040 <Nand_Init@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    117a <nand_read_ll+0x5a>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
shl    $0xb,%eax
cltq
add    %rax,%rsi
call   1030 <Nand_ReadPage@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1140 <nand_read_ll+0x20>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nand_read_ll>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%r14d
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <Nand_Init@plt>
test   %r14d,%r14d
jle    115a <nand_read_ll+0x3a>
mov    %r14d,%ebx
xchg   %ax,%ax
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <Nand_ReadPage@plt>
add    $0x1,%ebp
add    $0x800,%r15
add    $0xffffffffffffffff,%rbx
jne    1140 <nand_read_ll+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @nand_read_ll(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = call i32 (...) @Nand_Init()
store i32 0, i32* %7
br label %9
9: ; preds = %23, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %26
13: ; preds = %9
%14 = load i32, i32* %4
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = mul nsw i32 2048, %16
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = call i32 @Nand_ReadPage(i32 %14, i8* %19)
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %23
23: ; preds = %13
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %9
26: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
define i32 @nand_read_ll(i32 %0, i32 %1, i8* %2) {
%4 = tail call i32 (...) @Nand_Init()
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %17
6: ; preds = %3
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %15, %8 ]
%10 = phi i32 [ %0, %6 ], [ %14, %8 ]
%11 = shl nsw i64 %9, 11
%12 = getelementptr inbounds i8, i8* %2, i64 %11
%13 = tail call i32 @Nand_ReadPage(i32 %10, i8* %12)
%14 = add nsw i32 %10, 1
%15 = add nuw nsw i64 %9, 1
%16 = icmp eq i64 %15, %7
br i1 %16, label %17, label %8
17: ; preds = %8, %3
ret i32 0
}