#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
main() {
  FILE *filer;
  char buffer[64];
  int ct = 0;
  if ((filer = fopen("database.dat", "rb")) == NULL) {
    fprintf(stderr, "open read file error.\n");
    exit(1);
  }
  while (feof(filer) == 0) {
    fread(buffer, 1, 64, filer);
    fwrite(buffer, 1, 64, stdout);
    printf("\n");
    ct++;
  }
  printf("\ncount: %d", ct);
  puts("\n\n[Hit ENTER to close]");
  getchar();
  fclose(filer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x54(%rbp)
lea    0xe43(%rip),%rdi
lea    0xe49(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11f6 <main+0x56>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    11fb <main+0x5b>
mov    -0x10(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%rax
jne    125d <main+0xbd>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x40,%edx
call   1040 <fread@plt>
lea    -0x50(%rbp),%rdi
mov    0x2da8(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x40,%edx
call   10c0 <fwrite@plt>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11fb <main+0x5b>
mov    -0x54(%rbp),%esi
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xdbd(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    0xe3f(%rip),%rdi
lea    0xe45(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     127c <main+0xcc>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <feof@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    1244 <main+0x94>
xor    %ebp,%ebp
mov    %rsp,%r14
mov    0x2de4(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x40,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
mov    (%r15),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x40,%edx
call   10d0 <fwrite@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %rax,%rax
je     1200 <main+0x50>
lea    0xddc(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdd7(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
lea    0xd84(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"database.dat\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"open read file error.\0A\00"
@stdout = global i32 0
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [11 x i8] c"\0Acount: %d\00"
@.str.5 = [23 x i8] c"\0A\0A[Hit ENTER to close]\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [64 x i8]
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
br label %12
12: ; preds = %16, %11
%13 = load i32*, i32** %2
%14 = call i64 @feof(i32* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %12
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%18 = load i32*, i32** %2
%19 = call i32 @fread(i8* %17, i32 1, i32 64, i32* %18)
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%21 = load i32, i32* @stdout
%22 = call i32 @fwrite(i8* %20, i32 1, i32 64, i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %12
26: ; preds = %12
%27 = load i32, i32* %4
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 (...) @getchar()
%31 = load i32*, i32** %2
%32 = call i32 @fclose(i32* %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"database.dat\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"open read file error.\0A\00"
@stdout = global i32 0
@.str.4 = [11 x i8] c"\0Acount: %d\00"
@.str.5 = [23 x i8] c"\0A\0A[Hit ENTER to close]\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i64 @feof(i32* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %21
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %5, %12
%13 = phi i32 [ %18, %12 ], [ 0, %5 ]
%14 = call i32 @fread(i8* %2, i32 1, i32 64, i32* %3)
%15 = load i32, i32* @stdout
%16 = call i32 @fwrite(i8* %2, i32 1, i32 64, i32 %15)
%17 = call i32 @putchar(i32 10)
%18 = add nuw nsw i32 %13, 1
%19 = call i64 @feof(i32* %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %12, label %21
21: ; preds = %12, %5
%22 = phi i32 [ 0, %5 ], [ %18, %12 ]
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%25 = call i32 (...) @getchar()
%26 = call i32 @fclose(i32* %3)
ret i32 0
}