#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(int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fputs(char *, int /*<<< orphan*/);
int reply;
int /*<<< orphan*/ stdout;
void do_more(FILE *fp) {
  char line[512];
  int num_of_lines = 0;
  int see_more(FILE *), reply;
  FILE *fp_tty;
  fp_tty = fopen("/dev/tty", "r");
  if (fp_tty == NULL)
    exit(1);
  while (fgets(line, 512, fp)) {
    if (num_of_lines == 24) {
      reply = see_more(fp_tty);
      if (reply == 0)
        break;
      num_of_lines -= reply;
    }
    if (fputs(line, stdout) == EOF)
      exit(1);
    num_of_lines++;
  }
}


x86 assembly (clang, -O0):
<do_more>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x214(%rbp)
lea    0xe90(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
jne    119b <do_more+0x4b>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11a0 <do_more+0x50>
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1247 <do_more+0xf7>
cmpl   $0x18,-0x214(%rbp)
jne    1204 <do_more+0xb4>
mov    -0x220(%rbp),%rdi
call   1030 <see_more@plt>
mov    %eax,-0x218(%rbp)
cmpl   $0x0,-0x218(%rbp)
jne    11f0 <do_more+0xa0>
jmp    1247 <do_more+0xf7>
mov    -0x218(%rbp),%ecx
mov    -0x214(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x214(%rbp)
lea    -0x210(%rbp),%rdi
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2dc8(%rip),%rcx
cmp    (%rcx),%rax
jne    1233 <do_more+0xe3>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x214(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x214(%rbp)
jmp    11a0 <do_more+0x50>
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    %rdi,%r15
lea    0xe95(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1204 <do_more+0xb4>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11f2 <do_more+0xa2>
xor    %ebp,%ebp
mov    0x2e37(%rip),%r12
mov    %rsp,%rbx
mov    0x2e3d(%rip),%r13
nopl   0x0(%rax,%rax,1)
cmp    $0x18,%ebp
jne    11c8 <do_more+0x78>
mov    %r14,%rdi
call   1030 <see_more@plt>
test   %eax,%eax
je     11f2 <do_more+0xa2>
mov    $0x18,%ebp
sub    %eax,%ebp
mov    (%r12),%esi
mov    %rbx,%rdi
call   1040 <fputs@plt>
cmp    0x0(%r13),%rax
je     1204 <do_more+0xb4>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11b0 <do_more+0x60>
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1070 <exit@plt>

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

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