#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ footer();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int header(char *, int);
int /*<<< orphan*/ stdout;
void fileprint(FILE *fp, char *fname) {
  int lineno = 1;
  int pageno = 1;
  char line[1000];
  while (fgets(line, 1000, fp) != NULL) {
    if (lineno == 1) {
      lineno = header(fname, pageno);
    }
    (void)fputs(line, stdout);
    if (++lineno > 66 - 3) {
      footer();
      lineno = 1;
      pageno++;
    }
  }
  fprintf(stdout, "\f");
}


x86 assembly (clang, -O0):
<fileprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
lea    -0x400(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x3e8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11ec <fileprint+0x9c>
cmpl   $0x1,-0x14(%rbp)
jne    11a9 <fileprint+0x59>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <header@plt>
mov    %eax,-0x14(%rbp)
lea    -0x400(%rbp),%rdi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x3f,%eax
jle    11e7 <fileprint+0x97>
mov    $0x0,%al
call   1070 <footer@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1171 <fileprint+0x21>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
call   1060 <fprintf@plt>
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileprint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3e8,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsp,%rdi
mov    $0x3e8,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11eb <fileprint+0x9b>
mov    $0x1,%ebp
mov    0x2e58(%rip),%r13
mov    %rsp,%r12
mov    $0x1,%ebx
jmp    11c4 <fileprint+0x74>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <footer@plt>
add    $0x1,%ebp
mov    $0x1,%ebx
mov    %r12,%rdi
mov    $0x3e8,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11eb <fileprint+0x9b>
cmp    $0x1,%ebx
jne    11d5 <fileprint+0x85>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <header@plt>
mov    %eax,%ebx
mov    0x0(%r13),%esi
mov    %r12,%rdi
call   1040 <fputs@plt>
cmp    $0x3f,%ebx
jge    11a0 <fileprint+0x50>
add    $0x1,%ebx
jmp    11af <fileprint+0x5f>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
call   1060 <fprintf@plt>
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [2 x i8] c"\0C\00"
define void @fileprint(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1000 x i8]
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32 1, i32* %5
store i32 1, i32* %6
br label %8
8: ; preds = %31, %2
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%10 = load i32*, i32** %3
%11 = call i32* @fgets(i8* %9, i32 1000, i32* %10)
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %32
13: ; preds = %8
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i8*, i8** %4
%18 = load i32, i32* %6
%19 = call i32 @header(i8* %17, i32 %18)
store i32 %19, i32* %5
br label %20
20: ; preds = %16, %13
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%22 = load i32, i32* @stdout
%23 = call i32 @fputs(i8* %21, i32 %22)
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
%26 = icmp sgt i32 %25, 63
br i1 %26, label %27, label %31
27: ; preds = %20
%28 = call i32 (...) @footer()
store i32 1, i32* %5
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %31
31: ; preds = %27, %20
br label %8
32: ; preds = %8
%33 = load i32, i32* @stdout
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [2 x i8] c"\0C\00"
define void @fileprint(i32* nocapture %0, i8* %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = call i32* @fgets(i8* %4, i32 1000, i32* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %27, label %7
7: ; preds = %2, %22
%8 = phi i32 [ %24, %22 ], [ 1, %2 ]
%9 = phi i32 [ %23, %22 ], [ 1, %2 ]
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @header(i8* %1, i32 %8)
br label %13
13: ; preds = %11, %7
%14 = phi i32 [ %12, %11 ], [ %9, %7 ]
%15 = load i32, i32* @stdout
%16 = call i32 @fputs(i8* %4, i32 %15)
%17 = add nsw i32 %14, 1
%18 = icmp sgt i32 %14, 62
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = call i32 (...) @footer()
%21 = add nsw i32 %8, 1
br label %22
22: ; preds = %19, %13
%23 = phi i32 [ 1, %19 ], [ %17, %13 ]
%24 = phi i32 [ %21, %19 ], [ %8, %13 ]
%25 = call i32* @fgets(i8* %4, i32 1000, i32* %0)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %7
27: ; preds = %22, %2
%28 = load i32, i32* @stdout
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret void
}