#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int print_page(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ print_title_count(char *, int);
int /*<<< orphan*/ printf(char *, char *);
void print_file(char *filename, int maxlines) {
  FILE *fp;
  int status = 0;
  int page_count = 0;
  fp = fopen(filename, "r");
  if (fp == NULL) {
    printf("error: couldn't open %s\n", filename);
    exit(1);
  }
  page_count = 1;
  print_title_count(filename, page_count);
  while ((status = print_page(filename, fp, maxlines)) != EOF) {
    page_count++;
    print_title_count(filename, page_count);
  }
}


x86 assembly (clang, -O0):
<print_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a6 <print_file+0x56>
mov    -0x8(%rbp),%rsi
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1050 <print_title_count@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <print_page@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e15(%rip),%rcx
cmp    (%rcx),%eax
je     11f5 <print_file+0xa5>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1050 <print_title_count@plt>
jmp    11b9 <print_file+0x69>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ca <print_file+0x7a>
mov    %rax,%r15
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <print_title_count@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <print_page@plt>
mov    0x2e54(%rip),%r12
cmp    (%r12),%eax
je     11c1 <print_file+0x71>
mov    $0x2,%ebp
nop
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <print_title_count@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <print_page@plt>
add    $0x1,%ebp
cmp    (%r12),%eax
jne    11a0 <print_file+0x50>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe31(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [25 x i8] c"error: couldn't open %s\0A\00"
@EOF = global i32 0
define void @print_file(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %6
store i32 0, i32* %7
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
store i32 1, i32* %7
%17 = load i8*, i8** %3
%18 = load i32, i32* %7
%19 = call i32 @print_title_count(i8* %17, i32 %18)
br label %20
20: ; preds = %27, %16
%21 = load i8*, i8** %3
%22 = load i32*, i32** %5
%23 = load i32, i32* %4
%24 = call i32 @print_page(i8* %21, i32* %22, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* @EOF
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %33
27: ; preds = %20
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
%30 = load i8*, i8** %3
%31 = load i32, i32* %7
%32 = call i32 @print_title_count(i8* %30, i32 %31)
br label %20
33: ; preds = %20
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [25 x i8] c"error: couldn't open %s\0A\00"
@EOF = global i32 0
define void @print_file(i8* %0, i32 %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = tail call i32 @print_title_count(i8* %0, i32 1)
%10 = tail call i32 @print_page(i8* %0, i32* %3, i32 %1)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %20, label %13
13: ; preds = %8, %13
%14 = phi i32 [ %15, %13 ], [ 1, %8 ]
%15 = add nuw nsw i32 %14, 1
%16 = tail call i32 @print_title_count(i8* %0, i32 %15)
%17 = tail call i32 @print_page(i8* %0, i32* %3, i32 %1)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %13
20: ; preds = %13, %8
ret void
}