#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__ EOF;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int see_more(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
extern void do_more(int pagelen, FILE *fp, FILE *fp_tty) {
  char line[512];
  int num_of_lines = 0;
  int reply;
  while (fgets(line, 512, fp)) {
    if (num_of_lines == pagelen) {
      reply = see_more(pagelen, fp_tty);
      if (reply == 0) {
        exit(EXIT_SUCCESS);
      }
      num_of_lines -= reply;
    }
    if (fputs(line, stdout) == EOF) {
      printf("No more lines.\n");
      exit(EXIT_SUCCESS);
    }
    ++num_of_lines;
  }
}


x86 assembly (clang, -O0):
<do_more>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x224(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1232 <do_more+0xe2>
mov    -0x224(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11df <do_more+0x8f>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <see_more@plt>
mov    %eax,-0x228(%rbp)
cmpl   $0x0,-0x228(%rbp)
jne    11cb <do_more+0x7b>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x228(%rbp),%ecx
mov    -0x224(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x224(%rbp)
lea    -0x220(%rbp),%rdi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    0x2ded(%rip),%rcx
cmp    (%rcx),%rax
jne    121e <do_more+0xce>
lea    0xdf5(%rip),%rdi
call   1040 <printf@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x224(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x224(%rbp)
jmp    1170 <do_more+0x20>
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_more>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rdx,0x8(%rsp)
mov    %rsi,%r15
mov    %edi,%r14d
lea    0x10(%rsp),%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11e5 <do_more+0x95>
xor    %ebp,%ebp
mov    0x2e4c(%rip),%r12
lea    0x10(%rsp),%rbx
mov    0x2e50(%rip),%r13
nopl   0x0(%rax,%rax,1)
cmp    %r14d,%ebp
jne    11bb <do_more+0x6b>
mov    %r14d,%edi
mov    0x8(%rsp),%rsi
call   1030 <see_more@plt>
test   %eax,%eax
je     1203 <do_more+0xb3>
mov    %r14d,%ebp
sub    %eax,%ebp
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <fputs@plt>
cmp    0x0(%r13),%rax
je     11f7 <do_more+0xa7>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11a0 <do_more+0x50>
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe02(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
@stdout = global i32 0
@EOF = global i64 0
@.str = [16 x i8] c"No more lines.\0A\00"
define void @do_more(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [512 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 0, i32* %8
br label %10
10: ; preds = %42, %3
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%12 = load i32*, i32** %5
%13 = call i64 @fgets(i8* %11, i32 512, i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %45
15: ; preds = %10
%16 = load i32, i32* %8
%17 = load i32, i32* %4
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = load i32, i32* %4
%21 = load i32*, i32** %6
%22 = call i32 @see_more(i32 %20, i32* %21)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i32, i32* @EXIT_SUCCESS
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %19
%29 = load i32, i32* %9
%30 = load i32, i32* %8
%31 = sub nsw i32 %30, %29
store i32 %31, i32* %8
br label %32
32: ; preds = %28, %15
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%34 = load i32, i32* @stdout
%35 = call i64 @fputs(i8* %33, i32 %34)
%36 = load i64, i64* @EOF
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %42
38: ; preds = %32
%39 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%40 = load i32, i32* @EXIT_SUCCESS
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %32
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %10
45: ; preds = %10
ret void
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@stdout = global i32 0
@EOF = global i64 0
@str = [15 x i8] c"No more lines.\00"
define void @do_more(i32 %0, i32* nocapture %1, i32* %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%6 = call i64 @fgets(i8* %5, i32 512, i32* %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %33, label %12
8: ; preds = %23
%9 = add nsw i32 %24, 1
%10 = call i64 @fgets(i8* %5, i32 512, i32* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %33, label %12
12: ; preds = %3, %8
%13 = phi i32 [ %9, %8 ], [ 0, %3 ]
%14 = icmp eq i32 %13, %0
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = call i32 @see_more(i32 %0, i32* %2)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* @EXIT_SUCCESS
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %15
%22 = sub nsw i32 %0, %16
br label %23
23: ; preds = %21, %12
%24 = phi i32 [ %22, %21 ], [ %13, %12 ]
%25 = load i32, i32* @stdout
%26 = call i64 @fputs(i8* %5, i32 %25)
%27 = load i64, i64* @EOF
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %8
29: ; preds = %23
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%31 = load i32, i32* @EXIT_SUCCESS
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %8, %3
ret void
}