#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(unsigned long, unsigned char *, int);
void copy_2ddr(unsigned long nand_start, unsigned char *buff, int size) {
  unsigned long i;
  int len;
  for (i = (nand_start >> 11); size > 0 && i < 4;) {
    NF_Page_Read(i, buff, 2048);
    buff += 2048;
    size -= 2048;
    i++;
  }
  for (i++; size > 0;) {
    NF_Page_Read(i, buff, 2048 * 4);
    buff += 2048 * 4;
    size -= 2048 * 4;
    i++;
  }
}


x86 assembly (clang, -O0):
<copy_2ddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
shr    $0xb,%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x25(%rbp)
jle    1149 <copy_2ddr+0x39>
cmpq   $0x4,-0x20(%rbp)
setb   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1159 <copy_2ddr+0x49>
jmp    1195 <copy_2ddr+0x85>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x800,%edx
call   1030 <NF_Page_Read@plt>
mov    -0x10(%rbp),%rax
add    $0x800,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x800,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112f <copy_2ddr+0x1f>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11e7 <copy_2ddr+0xd7>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x2000,%edx
call   1030 <NF_Page_Read@plt>
mov    -0x10(%rbp),%rax
add    $0x2000,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x2000,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a1 <copy_2ddr+0x91>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_2ddr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
shr    $0xb,%r15
test   %edx,%edx
jle    117a <copy_2ddr+0x6a>
cmp    $0x1fff,%rdi
ja     117a <copy_2ddr+0x6a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14d,%r12d
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1030 <NF_Page_Read@plt>
add    $0x800,%rbx
lea    -0x800(%r12),%r14d
ff
lea    0x1(%r15),%rbp
cmp    $0x801,%r12d
jb     117d <copy_2ddr+0x6d>
cmp    $0x3,%r15
mov    %rbp,%r15
jb     1140 <copy_2ddr+0x30>
jmp    117d <copy_2ddr+0x6d>
mov    %r15,%rbp
test   %r14d,%r14d
jle    11bb <copy_2ddr+0xab>
add    $0x1,%rbp
add    $0x2000,%r14d
nopl   (%rax)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x2000,%edx
call   1030 <NF_Page_Read@plt>
add    $0x2000,%rbx
add    $0x1,%rbp
add    $0xffffe000,%r14d
cmp    $0x2000,%r14d
ja     1190 <copy_2ddr+0x80>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @copy_2ddr(i64 %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
store i64 %0, i64* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i64, i64* %4
%10 = lshr i64 %9, 11
store i64 %10, i64* %7
br label %11
11: ; preds = %19, %3
%12 = load i32, i32* %6
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i64, i64* %7
%16 = icmp ult i64 %15, 4
br label %17
17: ; preds = %14, %11
%18 = phi i1 [ false, %11 ], [ %16, %14 ]
br i1 %18, label %19, label %29
19: ; preds = %17
%20 = load i64, i64* %7
%21 = load i8*, i8** %5
%22 = call i32 @NF_Page_Read(i64 %20, i8* %21, i32 2048)
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 2048
store i8* %24, i8** %5
%25 = load i32, i32* %6
%26 = sub nsw i32 %25, 2048
store i32 %26, i32* %6
%27 = load i64, i64* %7
%28 = add i64 %27, 1
store i64 %28, i64* %7
br label %11
29: ; preds = %17
%30 = load i64, i64* %7
%31 = add i64 %30, 1
store i64 %31, i64* %7
br label %32
32: ; preds = %35, %29
%33 = load i32, i32* %6
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %45
35: ; preds = %32
%36 = load i64, i64* %7
%37 = load i8*, i8** %5
%38 = call i32 @NF_Page_Read(i64 %36, i8* %37, i32 8192)
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 8192
store i8* %40, i8** %5
%41 = load i32, i32* %6
%42 = sub nsw i32 %41, 8192
store i32 %42, i32* %6
%43 = load i64, i64* %7
%44 = add i64 %43, 1
store i64 %44, i64* %7
br label %32
45: ; preds = %32
ret void
}

LLVM IR (-O2):
define void @copy_2ddr(i64 %0, i8* %1, i32 %2) {
%4 = lshr i64 %0, 11
%5 = icmp sgt i32 %2, 0
%6 = icmp ult i64 %0, 8192
%7 = and i1 %5, %6
br i1 %7, label %13, label %8
8: ; preds = %13, %3
%9 = phi i32 [ %2, %3 ], [ %19, %13 ]
%10 = phi i64 [ %4, %3 ], [ %20, %13 ]
%11 = phi i8* [ %1, %3 ], [ %18, %13 ]
%12 = icmp sgt i32 %9, 0
br i1 %12, label %24, label %33
13: ; preds = %3, %13
%14 = phi i8* [ %18, %13 ], [ %1, %3 ]
%15 = phi i64 [ %20, %13 ], [ %4, %3 ]
%16 = phi i32 [ %19, %13 ], [ %2, %3 ]
%17 = tail call i32 @NF_Page_Read(i64 %15, i8* %14, i32 2048)
%18 = getelementptr inbounds i8, i8* %14, i64 2048
%19 = add nsw i32 %16, -2048
%20 = add nuw nsw i64 %15, 1
%21 = icmp ugt i32 %16, 2048
%22 = icmp ult i64 %15, 3
%23 = and i1 %21, %22
br i1 %23, label %13, label %8
24: ; preds = %8, %24
%25 = phi i64 [ %28, %24 ], [ %10, %8 ]
%26 = phi i8* [ %30, %24 ], [ %11, %8 ]
%27 = phi i32 [ %31, %24 ], [ %9, %8 ]
%28 = add nuw nsw i64 %25, 1
%29 = tail call i32 @NF_Page_Read(i64 %28, i8* %26, i32 8192)
%30 = getelementptr inbounds i8, i8* %26, i64 8192
%31 = add nsw i32 %27, -8192
%32 = icmp ugt i32 %27, 8192
br i1 %32, label %24, label %33
33: ; preds = %24, %8
ret void
}