#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, ...);
void print_file(char *filename, FILE *fp) {
  int line_cnt = 0, page_cnt = 1;
  char line[10000];
  printf("%s - PAGE %d\n", filename, page_cnt);
  while (fgets(line, 10000, fp)) {
    if (++line_cnt == 60 + 1) {
      printf("%s - PAGE %d\n", filename, ++page_cnt);
      line_cnt = 0;
    }
    printf("%s", line);
  }
}


x86 assembly (clang, -O0):
<print_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2730,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x2730(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x2710,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11c3 <print_file+0xa3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x3d,%eax
jne    11a9 <print_file+0x89>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
lea    -0x2730(%rbp),%rsi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1156 <print_file+0x36>
add    $0x2730,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2718,%rsp
mov    %rsi,%r13
mov    %rdi,%r14
lea    0xec2(%rip),%rdi
mov    $0x1,%ebp
mov    %r14,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%rdi
mov    $0x2710,%esi
mov    %r13,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11c7 <print_file+0xa7>
lea    0xea0(%rip),%r12
mov    %rsp,%rbx
xor    %r15d,%r15d
jmp    11a2 <print_file+0x82>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x2710,%esi
mov    %r13,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11c7 <print_file+0xa7>
add    $0x1,%r15d
cmp    $0x3d,%r15d
jne    1180 <print_file+0x60>
add    $0x1,%ebp
xor    %r15d,%r15d
lea    0xe47(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1180 <print_file+0x60>
add    $0x2718,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"%s - PAGE %d\0A\00"
@.str.1 = [3 x i8] c"%s\00"
define void @print_file(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [10000 x i8]
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 0, i32* %5
store i32 1, i32* %6
%8 = load i8*, i8** %3
%9 = load i32, i32* %6
%10 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %8, i32 %9)
br label %11
11: ; preds = %25, %2
%12 = getelementptr inbounds [10000 x i8], [10000 x i8]* %7, i64 0, i64 0
%13 = load i32*, i32** %4
%14 = call i64 @fgets(i8* %12, i32 10000, i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %11
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
%19 = icmp eq i32 %18, 61
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i8*, i8** %3
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
%24 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %21, i32 %23)
store i32 0, i32* %5
br label %25
25: ; preds = %20, %16
%26 = getelementptr inbounds [10000 x i8], [10000 x i8]* %7, i64 0, i64 0
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %11
28: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"%s - PAGE %d\0A\00"
@.str.1 = [3 x i8] c"%s\00"
define void @print_file(i8* %0, i32* nocapture %1) {
%3 = alloca [10000 x i8]
%4 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0, i32 1)
%6 = call i64 @fgets(i8* %4, i32 10000, i32* %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %2, %16
%9 = phi i32 [ %18, %16 ], [ 1, %2 ]
%10 = phi i32 [ %17, %16 ], [ 0, %2 ]
%11 = add nsw i32 %10, 1
%12 = icmp eq i32 %11, 61
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = add nsw i32 %9, 1
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %14)
br label %16
16: ; preds = %13, %8
%17 = phi i32 [ 0, %13 ], [ %11, %8 ]
%18 = phi i32 [ %14, %13 ], [ %9, %8 ]
%19 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%20 = call i64 @fgets(i8* %4, i32 10000, i32* %1)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %8
22: ; preds = %16, %2
ret void
}