#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 /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
extern void do_more(FILE *fp, FILE *fp_tty) {
  char line[512];
  int num_of_lines = 0;
  int reply;
  while (fgets(line, 512, fp)) {
    if (num_of_lines == 24) {
      reply = see_more(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    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x214(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x200,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     122a <do_more+0xda>
cmpl   $0x18,-0x214(%rbp)
jne    11d7 <do_more+0x87>
mov    -0x10(%rbp),%rdi
call   1030 <see_more@plt>
mov    %eax,-0x218(%rbp)
cmpl   $0x0,-0x218(%rbp)
jne    11c3 <do_more+0x73>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x218(%rbp),%ecx
mov    -0x214(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x214(%rbp)
lea    -0x210(%rbp),%rdi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    0x2df5(%rip),%rcx
cmp    (%rcx),%rax
jne    1216 <do_more+0xc6>
lea    0xdfd(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x214(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x214(%rbp)
jmp    116d <do_more+0x1d>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_more>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11d2 <do_more+0x82>
xor    %ebp,%ebp
mov    0x2e53(%rip),%r12
mov    %rsp,%rbx
mov    0x2e59(%rip),%r13
nop
cmp    $0x18,%ebp
jne    11a8 <do_more+0x58>
mov    %r14,%rdi
call   1030 <see_more@plt>
test   %eax,%eax
je     11f0 <do_more+0xa0>
mov    $0x18,%ebp
sub    %eax,%ebp
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <fputs@plt>
cmp    0x0(%r13),%rax
je     11e4 <do_more+0x94>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    1190 <do_more+0x40>
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe15(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dd9(%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) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [512 x i8]
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 0, i32* %6
br label %8
8: ; preds = %38, %2
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%10 = load i32*, i32** %3
%11 = call i64 @fgets(i8* %9, i32 512, i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %41
13: ; preds = %8
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 24
br i1 %15, label %16, label %28
16: ; preds = %13
%17 = load i32*, i32** %4
%18 = call i32 @see_more(i32* %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* @EXIT_SUCCESS
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %16
%25 = load i32, i32* %7
%26 = load i32, i32* %6
%27 = sub nsw i32 %26, %25
store i32 %27, i32* %6
br label %28
28: ; preds = %24, %13
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%30 = load i32, i32* @stdout
%31 = call i64 @fputs(i8* %29, i32 %30)
%32 = load i64, i64* @EOF
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %28
%35 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%36 = load i32, i32* @EXIT_SUCCESS
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %28
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %8
41: ; preds = %8
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* nocapture %0, i32* %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = call i64 @fgets(i8* %4, i32 512, i32* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %32, label %11
7: ; preds = %22
%8 = add nsw i32 %23, 1
%9 = call i64 @fgets(i8* %4, i32 512, i32* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %32, label %11
11: ; preds = %2, %7
%12 = phi i32 [ %8, %7 ], [ 0, %2 ]
%13 = icmp eq i32 %12, 24
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = call i32 @see_more(i32* %1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @EXIT_SUCCESS
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %14
%21 = sub nsw i32 24, %15
br label %22
22: ; preds = %20, %11
%23 = phi i32 [ %21, %20 ], [ %12, %11 ]
%24 = load i32, i32* @stdout
%25 = call i64 @fputs(i8* %4, i32 %24)
%26 = load i64, i64* @EOF
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %7
28: ; preds = %22
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%30 = load i32, i32* @EXIT_SUCCESS
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %7, %2
ret void
}