#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*/ Delay(int);
int /*<<< orphan*/ NF_ADDR(unsigned int);
int /*<<< orphan*/ NF_CMD(int);
void *NF_RDDATA();
int /*<<< orphan*/ NF_WAITRB();
int /*<<< orphan*/ NF_nFCE_H();
int /*<<< orphan*/ NF_nFCE_L();
int NF_ReadPage(unsigned int block, unsigned int page, unsigned char *buffer,
                unsigned char *spareBuf) {
  int i;
  unsigned int blockPage;
  unsigned char *bufPt = buffer;
  int ret;
  page = page & 0x1f;
  blockPage = (block << 5) + page;
  NF_nFCE_L();
  NF_CMD(0x00);
  NF_ADDR(0);
  NF_ADDR(blockPage & 0xff);
  NF_ADDR((blockPage >> 8) & 0x7f);
  Delay(1);
  NF_WAITRB();
  for (i = 0; i < (512); i++) {
    *bufPt++ = NF_RDDATA();
  }
  if (spareBuf != NULL) {
    for (i = 0; i < 16; i++)
      spareBuf[i] = NF_RDDATA();
    ret = spareBuf[5];
  } else {
    NF_CMD(0x50);
    NF_ADDR(5);
    NF_ADDR(blockPage & 0xff);
    NF_ADDR((blockPage >> 8) & 0x7f);
    Delay(1);
    NF_WAITRB();
    ret = NF_RDDATA();
  }
  NF_nFCE_H();
  return ret;
}


x86 assembly (clang, -O0):
<NF_ReadPage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
and    $0x1f,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x5,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <NF_nFCE_L@plt>
xor    %edi,%edi
call   1080 <NF_CMD@plt>
xor    %edi,%edi
call   1090 <NF_ADDR@plt>
mov    -0x20(%rbp),%edi
and    $0xff,%edi
call   1090 <NF_ADDR@plt>
mov    -0x20(%rbp),%edi
shr    $0x8,%edi
and    $0x7f,%edi
call   1090 <NF_ADDR@plt>
mov    $0x1,%edi
call   1040 <Delay@plt>
mov    $0x0,%al
call   1060 <NF_WAITRB@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x200,-0x1c(%rbp)
jge    1221 <NF_ReadPage+0xb1>
mov    $0x0,%al
call   1070 <NF_RDDATA@plt>
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ec <NF_ReadPage+0x7c>
cmpq   $0x0,-0x18(%rbp)
je     126f <NF_ReadPage+0xff>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jge    125f <NF_ReadPage+0xef>
mov    $0x0,%al
call   1070 <NF_RDDATA@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1233 <NF_ReadPage+0xc3>
mov    -0x18(%rbp),%rax
movzbl 0x5(%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    12ba <NF_ReadPage+0x14a>
mov    $0x50,%edi
call   1080 <NF_CMD@plt>
mov    $0x5,%edi
call   1090 <NF_ADDR@plt>
mov    -0x20(%rbp),%edi
and    $0xff,%edi
call   1090 <NF_ADDR@plt>
mov    -0x20(%rbp),%edi
shr    $0x8,%edi
and    $0x7f,%edi
call   1090 <NF_ADDR@plt>
mov    $0x1,%edi
call   1040 <Delay@plt>
mov    $0x0,%al
call   1060 <NF_WAITRB@plt>
mov    $0x0,%al
call   1070 <NF_RDDATA@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1030 <NF_nFCE_H@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NF_ReadPage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%r13d
mov    %edi,%r12d
and    $0x1f,%r13d
mov    %edi,%ebp
shl    $0x5,%ebp
xor    %eax,%eax
call   1050 <NF_nFCE_L@plt>
xor    %edi,%edi
call   1080 <NF_CMD@plt>
xor    %edi,%edi
call   1090 <NF_ADDR@plt>
movzbl %bpl,%r15d
or     %r13d,%r15d
mov    %r15d,%edi
call   1090 <NF_ADDR@plt>
shr    $0x3,%r12d
and    $0x7f,%r12d
mov    %r12d,%edi
call   1090 <NF_ADDR@plt>
mov    $0x1,%edi
call   1040 <Delay@plt>
xor    %eax,%eax
call   1060 <NF_WAITRB@plt>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
cmp    $0x200,%ebp
jne    11e0 <NF_ReadPage+0x70>
test   %r14,%r14
je     12b5 <NF_ReadPage+0x145>
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %al,(%r14)
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %al,0x1(%r14)
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %al,0x2(%r14)
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %al,0x3(%r14)
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %al,0x4(%r14)
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %al,0x5(%r14)
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %al,0x6(%r14)
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %al,0x7(%r14)
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %al,0x8(%r14)
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %al,0x9(%r14)
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %al,0xa(%r14)
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %al,0xb(%r14)
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %al,0xc(%r14)
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %al,0xd(%r14)
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %al,0xe(%r14)
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %al,0xf(%r14)
movzbl 0x5(%r14),%ebx
jmp    12f4 <NF_ReadPage+0x184>
mov    $0x50,%edi
call   1080 <NF_CMD@plt>
mov    $0x5,%edi
call   1090 <NF_ADDR@plt>
mov    %r15d,%edi
call   1090 <NF_ADDR@plt>
mov    %r12d,%edi
call   1090 <NF_ADDR@plt>
mov    $0x1,%edi
call   1040 <Delay@plt>
xor    %eax,%eax
call   1060 <NF_WAITRB@plt>
xor    %eax,%eax
call   1070 <NF_RDDATA@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <NF_nFCE_H@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @NF_ReadPage(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%13 = load i8*, i8** %7
store i8* %13, i8** %11
%14 = load i32, i32* %6
%15 = and i32 %14, 31
store i32 %15, i32* %6
%16 = load i32, i32* %5
%17 = shl i32 %16, 5
%18 = load i32, i32* %6
%19 = add i32 %17, %18
store i32 %19, i32* %10
%20 = call i32 (...) @NF_nFCE_L()
%21 = call i32 @NF_CMD(i32 0)
%22 = call i32 @NF_ADDR(i32 0)
%23 = load i32, i32* %10
%24 = and i32 %23, 255
%25 = call i32 @NF_ADDR(i32 %24)
%26 = load i32, i32* %10
%27 = lshr i32 %26, 8
%28 = and i32 %27, 127
%29 = call i32 @NF_ADDR(i32 %28)
%30 = call i32 @Delay(i32 1)
%31 = call i32 (...) @NF_WAITRB()
store i32 0, i32* %9
br label %32
32: ; preds = %40, %4
%33 = load i32, i32* %9
%34 = icmp slt i32 %33, 512
br i1 %34, label %35, label %43
35: ; preds = %32
%36 = call i8* (...) @NF_RDDATA()
%37 = ptrtoint i8* %36 to i8
%38 = load i8*, i8** %11
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %11
store i8 %37, i8* %38
br label %40
40: ; preds = %35
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
br label %32
43: ; preds = %32
%44 = load i8*, i8** %8
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %65
46: ; preds = %43
store i32 0, i32* %9
br label %47
47: ; preds = %57, %46
%48 = load i32, i32* %9
%49 = icmp slt i32 %48, 16
br i1 %49, label %50, label %60
50: ; preds = %47
%51 = call i8* (...) @NF_RDDATA()
%52 = ptrtoint i8* %51 to i8
%53 = load i8*, i8** %8
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
store i8 %52, i8* %56
br label %57
57: ; preds = %50
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
store i32 %59, i32* %9
br label %47
60: ; preds = %47
%61 = load i8*, i8** %8
%62 = getelementptr inbounds i8, i8* %61, i64 5
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
store i32 %64, i32* %12
br label %79
65: ; preds = %43
%66 = call i32 @NF_CMD(i32 80)
%67 = call i32 @NF_ADDR(i32 5)
%68 = load i32, i32* %10
%69 = and i32 %68, 255
%70 = call i32 @NF_ADDR(i32 %69)
%71 = load i32, i32* %10
%72 = lshr i32 %71, 8
%73 = and i32 %72, 127
%74 = call i32 @NF_ADDR(i32 %73)
%75 = call i32 @Delay(i32 1)
%76 = call i32 (...) @NF_WAITRB()
%77 = call i8* (...) @NF_RDDATA()
%78 = ptrtoint i8* %77 to i32
store i32 %78, i32* %12
br label %79
79: ; preds = %65, %60
%80 = call i32 (...) @NF_nFCE_H()
%81 = load i32, i32* %12
ret i32 %81
}

LLVM IR (-O2):
define i32 @NF_ReadPage(i32 %0, i32 %1, i8* nocapture writeonly %2, i8* %3) {
%5 = and i32 %1, 31
%6 = shl i32 %0, 5
%7 = tail call i32 (...) @NF_nFCE_L()
%8 = tail call i32 @NF_CMD(i32 0)
%9 = tail call i32 @NF_ADDR(i32 0)
%10 = and i32 %6, 224
%11 = or i32 %10, %5
%12 = tail call i32 @NF_ADDR(i32 %11)
%13 = lshr i32 %6, 8
%14 = and i32 %13, 127
%15 = tail call i32 @NF_ADDR(i32 %14)
%16 = tail call i32 @Delay(i32 1)
%17 = tail call i32 (...) @NF_WAITRB()
br label %18
18: ; preds = %4, %18
%19 = phi i8* [ %2, %4 ], [ %24, %18 ]
%20 = phi i32 [ 0, %4 ], [ %25, %18 ]
%21 = tail call i8* (...) @NF_RDDATA()
%22 = ptrtoint i8* %21 to i64
%23 = trunc i64 %22 to i8
%24 = getelementptr inbounds i8, i8* %19, i64 1
store i8 %23, i8* %19
%25 = add nuw nsw i32 %20, 1
%26 = icmp eq i32 %25, 512
br i1 %26, label %27, label %18
27: ; preds = %18
%28 = icmp eq i8* %3, null
br i1 %28, label %95, label %29
29: ; preds = %27
%30 = tail call i8* (...) @NF_RDDATA()
%31 = ptrtoint i8* %30 to i64
%32 = trunc i64 %31 to i8
store i8 %32, i8* %3
%33 = tail call i8* (...) @NF_RDDATA()
%34 = ptrtoint i8* %33 to i64
%35 = trunc i64 %34 to i8
%36 = getelementptr inbounds i8, i8* %3, i64 1
store i8 %35, i8* %36
%37 = tail call i8* (...) @NF_RDDATA()
%38 = ptrtoint i8* %37 to i64
%39 = trunc i64 %38 to i8
%40 = getelementptr inbounds i8, i8* %3, i64 2
store i8 %39, i8* %40
%41 = tail call i8* (...) @NF_RDDATA()
%42 = ptrtoint i8* %41 to i64
%43 = trunc i64 %42 to i8
%44 = getelementptr inbounds i8, i8* %3, i64 3
store i8 %43, i8* %44
%45 = tail call i8* (...) @NF_RDDATA()
%46 = ptrtoint i8* %45 to i64
%47 = trunc i64 %46 to i8
%48 = getelementptr inbounds i8, i8* %3, i64 4
store i8 %47, i8* %48
%49 = tail call i8* (...) @NF_RDDATA()
%50 = ptrtoint i8* %49 to i64
%51 = trunc i64 %50 to i8
%52 = getelementptr inbounds i8, i8* %3, i64 5
store i8 %51, i8* %52
%53 = tail call i8* (...) @NF_RDDATA()
%54 = ptrtoint i8* %53 to i64
%55 = trunc i64 %54 to i8
%56 = getelementptr inbounds i8, i8* %3, i64 6
store i8 %55, i8* %56
%57 = tail call i8* (...) @NF_RDDATA()
%58 = ptrtoint i8* %57 to i64
%59 = trunc i64 %58 to i8
%60 = getelementptr inbounds i8, i8* %3, i64 7
store i8 %59, i8* %60
%61 = tail call i8* (...) @NF_RDDATA()
%62 = ptrtoint i8* %61 to i64
%63 = trunc i64 %62 to i8
%64 = getelementptr inbounds i8, i8* %3, i64 8
store i8 %63, i8* %64
%65 = tail call i8* (...) @NF_RDDATA()
%66 = ptrtoint i8* %65 to i64
%67 = trunc i64 %66 to i8
%68 = getelementptr inbounds i8, i8* %3, i64 9
store i8 %67, i8* %68
%69 = tail call i8* (...) @NF_RDDATA()
%70 = ptrtoint i8* %69 to i64
%71 = trunc i64 %70 to i8
%72 = getelementptr inbounds i8, i8* %3, i64 10
store i8 %71, i8* %72
%73 = tail call i8* (...) @NF_RDDATA()
%74 = ptrtoint i8* %73 to i64
%75 = trunc i64 %74 to i8
%76 = getelementptr inbounds i8, i8* %3, i64 11
store i8 %75, i8* %76
%77 = tail call i8* (...) @NF_RDDATA()
%78 = ptrtoint i8* %77 to i64
%79 = trunc i64 %78 to i8
%80 = getelementptr inbounds i8, i8* %3, i64 12
store i8 %79, i8* %80
%81 = tail call i8* (...) @NF_RDDATA()
%82 = ptrtoint i8* %81 to i64
%83 = trunc i64 %82 to i8
%84 = getelementptr inbounds i8, i8* %3, i64 13
store i8 %83, i8* %84
%85 = tail call i8* (...) @NF_RDDATA()
%86 = ptrtoint i8* %85 to i64
%87 = trunc i64 %86 to i8
%88 = getelementptr inbounds i8, i8* %3, i64 14
store i8 %87, i8* %88
%89 = tail call i8* (...) @NF_RDDATA()
%90 = ptrtoint i8* %89 to i64
%91 = trunc i64 %90 to i8
%92 = getelementptr inbounds i8, i8* %3, i64 15
store i8 %91, i8* %92
%93 = load i8, i8* %52
%94 = zext i8 %93 to i32
br label %105
95: ; preds = %27
%96 = tail call i32 @NF_CMD(i32 80)
%97 = tail call i32 @NF_ADDR(i32 5)
%98 = tail call i32 @NF_ADDR(i32 %11)
%99 = tail call i32 @NF_ADDR(i32 %14)
%100 = tail call i32 @Delay(i32 1)
%101 = tail call i32 (...) @NF_WAITRB()
%102 = tail call i8* (...) @NF_RDDATA()
%103 = ptrtoint i8* %102 to i64
%104 = trunc i64 %103 to i32
br label %105
105: ; preds = %95, %29
%106 = phi i32 [ %94, %29 ], [ %104, %95 ]
%107 = tail call i32 (...) @NF_nFCE_H()
ret i32 %106
}