#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;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int getc(int /*<<< orphan*/ *);
int printf(char *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ read(int, int *, int);
int /*<<< orphan*/ stdout;
void do_more(FILE *fp, int maxlines) {
  int c, len, lines = 0;
  while ((c = getc(fp)) != EOF) {
    if (c == '\n' && ++lines >= maxlines) {
      len = printf("\n--More-- ");
      fflush(stdout);
      read(2, &c, 1);
      printf("\033[1A");
      putc('\r', stdout);
      while (--len >= 0)
        putc(' ', stdout);
      putc('\r', stdout);
      len = 0;
      lines = 0;
    } else
      putchar(c);
  }
  putchar('\n');
}


x86 assembly (clang, -O0):
<do_more>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e5f(%rip),%rcx
cmp    (%rcx),%eax
je     125c <do_more+0xfc>
cmpl   $0xa,-0x10(%rbp)
jne    124c <do_more+0xec>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmp    -0xc(%rbp),%eax
jl     124c <do_more+0xec>
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    $0x2,%edi
lea    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
lea    0xe27(%rip),%rdi
call   1040 <printf@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
mov    $0xd,%edi
call   1060 <putc@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jl     1226 <do_more+0xc6>
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
mov    $0x20,%edi
call   1060 <putc@plt>
jmp    11fc <do_more+0x9c>
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
mov    $0xd,%edi
call   1060 <putc@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
jmp    1257 <do_more+0xf7>
mov    -0x10(%rbp),%eax
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    1176 <do_more+0x16>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_more>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r13d
mov    %rdi,%rbx
call   1080 <getc@plt>
mov    %eax,0x4(%rsp)
mov    0x2e67(%rip),%r14
cmp    (%r14),%eax
jne    119e <do_more+0x3e>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
xor    %ebp,%ebp
mov    0x2e31(%rip),%r15
lea    0xe5d(%rip),%r12
jmp    11c9 <do_more+0x69>
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1080 <getc@plt>
mov    %eax,0x4(%rsp)
cmp    (%r14),%eax
je     1186 <do_more+0x26>
cmp    $0xa,%eax
jne    11b0 <do_more+0x50>
add    $0x1,%ebp
cmp    %r13d,%ebp
jl     11b0 <do_more+0x50>
lea    0xe23(%rip),%rdi
call   1040 <printf@plt>
mov    %eax,%ebp
mov    (%r15),%edi
call   1070 <fflush@plt>
mov    $0x2,%edi
lea    0x4(%rsp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %r12,%rdi
call   1040 <printf@plt>
mov    (%r15),%esi
mov    $0xd,%edi
call   1060 <putc@plt>
test   %ebp,%ebp
jle    1235 <do_more+0xd5>
add    $0x1,%ebp
nopl   0x0(%rax)
mov    (%r15),%esi
mov    $0x20,%edi
call   1060 <putc@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1220 <do_more+0xc0>
mov    (%r15),%esi
mov    $0xd,%edi
call   1060 <putc@plt>
xor    %ebp,%ebp
jmp    11b8 <do_more+0x58>

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

LLVM IR (-O2):
@EOF = global i32 0
@.str = [11 x i8] c"\0A--More-- \00"
@stdout = global i32 0
@.str.1 = [5 x i8] c"\1B[1A\00"
define void @do_more(i32* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @getc(i32* %0)
store i32 %5, i32* %3
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %42, label %8
8: ; preds = %2, %37
%9 = phi i32 [ %39, %37 ], [ %5, %2 ]
%10 = phi i32 [ %38, %37 ], [ 0, %2 ]
%11 = icmp eq i32 %9, 10
br i1 %11, label %12, label %33
12: ; preds = %8
%13 = add nsw i32 %10, 1
%14 = icmp slt i32 %13, %1
br i1 %14, label %33, label %15
15: ; preds = %12
%16 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @stdout
%18 = tail call i32 @fflush(i32 %17)
%19 = call i32 @read(i32 2, i32* %3, i32 1)
%20 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @stdout
%22 = tail call i32 @putc(i8 signext 13, i32 %21)
%23 = icmp sgt i32 %16, 0
br i1 %23, label %24, label %30
24: ; preds = %15, %24
%25 = phi i32 [ %26, %24 ], [ %16, %15 ]
%26 = add nsw i32 %25, -1
%27 = load i32, i32* @stdout
%28 = tail call i32 @putc(i8 signext 32, i32 %27)
%29 = icmp ugt i32 %25, 1
br i1 %29, label %24, label %30
30: ; preds = %24, %15
%31 = load i32, i32* @stdout
%32 = tail call i32 @putc(i8 signext 13, i32 %31)
br label %37
33: ; preds = %12, %8
%34 = phi i32 [ %13, %12 ], [ %10, %8 ]
%35 = trunc i32 %9 to i8
%36 = tail call i32 @putchar(i8 signext %35)
br label %37
37: ; preds = %33, %30
%38 = phi i32 [ 0, %30 ], [ %34, %33 ]
%39 = tail call i32 @getc(i32* %0)
store i32 %39, i32* %3
%40 = load i32, i32* @EOF
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %8
42: ; preds = %37, %2
%43 = tail call i32 @putchar(i8 signext 10)
ret void
}