#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ fputs(char *, int /*<<< orphan*/);
int see_more();
int /*<<< orphan*/ stdout;
void do_more(FILE *fp) {
  char line[512];
  int num_of_lines = 0;
  int reply;
  while (fgets(line, 512, fp)) {
    if (num_of_lines == 24) {
      reply = see_more();
      if (reply == 0)
        break;
      num_of_lines -= reply;
    }
    if (fputs(line, stdout) == EOF)
      exit(EXIT_FAILURE);
    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    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11ff <do_more+0xbf>
cmpl   $0x18,-0x214(%rbp)
jne    11b8 <do_more+0x78>
mov    $0x0,%al
call   1030 <see_more@plt>
mov    %eax,-0x218(%rbp)
cmpl   $0x0,-0x218(%rbp)
jne    11a4 <do_more+0x64>
jmp    11ff <do_more+0xbf>
mov    -0x218(%rbp),%ecx
mov    -0x214(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x214(%rbp)
lea    -0x210(%rbp),%rdi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2e14(%rip),%rcx
cmp    (%rcx),%rax
jne    11eb <do_more+0xab>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x214(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x214(%rbp)
jmp    1159 <do_more+0x19>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_more>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11c0 <do_more+0x80>
mov    0x2e62(%rip),%r15
mov    %rsp,%rbx
mov    0x2e70(%rip),%r12
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
cmp    $0x18,%ebp
jne    1197 <do_more+0x57>
xor    %eax,%eax
call   1030 <see_more@plt>
test   %eax,%eax
je     11c0 <do_more+0x80>
mov    $0x18,%ebp
sub    %eax,%ebp
mov    (%r15),%esi
mov    %rbx,%rdi
call   1040 <fputs@plt>
cmp    (%r12),%rax
je     11d0 <do_more+0x90>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1180 <do_more+0x40>
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@stdout = global i32 0
@EOF = global i64 0
@EXIT_FAILURE = 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 = call i64 @fgets(i8* %3, i32 512, i32* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %27, label %10
6: ; preds = %18
%7 = add nsw i32 %19, 1
%8 = call i64 @fgets(i8* %3, i32 512, i32* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %27, label %10
10: ; preds = %1, %6
%11 = phi i32 [ %7, %6 ], [ 0, %1 ]
%12 = icmp eq i32 %11, 24
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = call i32 (...) @see_more()
%15 = icmp eq i32 %14, 0
br i1 %15, label %27, label %16
16: ; preds = %13
%17 = sub nsw i32 24, %14
br label %18
18: ; preds = %16, %10
%19 = phi i32 [ %17, %16 ], [ %11, %10 ]
%20 = load i32, i32* @stdout
%21 = call i64 @fputs(i8* %3, i32 %20)
%22 = load i64, i64* @EOF
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %6
24: ; preds = %18
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %6, %13, %1
ret void
}