#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;
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int print_page(char *filename, FILE *fp, int maxlines) {
  char line[10000];
  int count = 0;
  char *status;
  while (((status = fgets(line, 10000, fp)) != NULL) && count < maxlines - 1) {
    printf("%s", line);
    count++;
  }
  if (status != NULL) {
    return 0;
  } else {
    return EOF;
  }
}


x86 assembly (clang, -O0):
<print_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2750,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x2734(%rbp)
lea    -0x2730(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x2710,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
mov    %rcx,-0x2740(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x2741(%rbp)
je     1188 <print_page+0x68>
mov    -0x2734(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
setl   %al
mov    %al,-0x2741(%rbp)
mov    -0x2741(%rbp),%al
test   $0x1,%al
jne    119b <print_page+0x7b>
jmp    11c2 <print_page+0xa2>
lea    -0x2730(%rbp),%rsi
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2734(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2734(%rbp)
jmp    1140 <print_page+0x20>
cmpq   $0x0,-0x2740(%rbp)
je     11dc <print_page+0xbc>
movl   $0x0,-0x4(%rbp)
jmp    11e8 <print_page+0xc8>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2750,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_page>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2710,%rsp
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rsp,%rdi
mov    $0x2710,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
setne  %cl
je     119d <print_page+0x7d>
cmp    $0x2,%r12d
jl     119d <print_page+0x7d>
add    $0xffffffff,%r12d
mov    $0x1,%ebp
lea    0xe9d(%rip),%r15
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x2710,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
setne  %cl
je     119d <print_page+0x7d>
lea    0x1(%rbp),%eax
cmp    %r12d,%ebp
mov    %eax,%ebp
jl     1170 <print_page+0x50>
xor    %eax,%eax
test   %cl,%cl
jne    11ac <print_page+0x8c>
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
add    $0x2710,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@EOF = global i32 0
define i32 @print_page(i8* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [10000 x i8]
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 0, i32* %9
br label %11
11: ; preds = %23, %3
%12 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%13 = load i32*, i32** %6
%14 = call i8* @fgets(i8* %12, i32 10000, i32* %13)
store i8* %14, i8** %10
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i32, i32* %9
%18 = load i32, i32* %7
%19 = sub nsw i32 %18, 1
%20 = icmp slt i32 %17, %19
br label %21
21: ; preds = %16, %11
%22 = phi i1 [ false, %11 ], [ %20, %16 ]
br i1 %22, label %23, label %28
23: ; preds = %21
%24 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i32, i32* %9
%27 = add nsw i32 %26, 1
store i32 %27, i32* %9
br label %11
28: ; preds = %21
%29 = load i8*, i8** %10
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %32
31: ; preds = %28
store i32 0, i32* %4
br label %34
32: ; preds = %28
%33 = load i32, i32* @EOF
store i32 %33, i32* %4
br label %34
34: ; preds = %32, %31
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@EOF = global i32 0
define i32 @print_page(i8* nocapture readnone %0, i32* nocapture %1, i32 %2) {
%4 = alloca [10000 x i8]
%5 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%6 = call i8* @fgets(i8* %5, i32 10000, i32* %1)
%7 = icmp ne i8* %6, null
%8 = add nsw i32 %2, -1
%9 = icmp sgt i32 %2, 1
%10 = and i1 %7, %9
br i1 %10, label %11, label %19
11: ; preds = %3, %11
%12 = phi i32 [ %14, %11 ], [ 0, %3 ]
%13 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%14 = add nuw nsw i32 %12, 1
%15 = call i8* @fgets(i8* %5, i32 10000, i32* %1)
%16 = icmp ne i8* %15, null
%17 = icmp slt i32 %14, %8
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %11, label %19
19: ; preds = %11, %3
%20 = phi i1 [ %7, %3 ], [ %16, %11 ]
%21 = load i32, i32* @EOF
%22 = select i1 %20, i32 0, i32 %21
ret i32 %22
}