#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 */
char EOF;
int atoi(char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fidopen(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getline(char **, size_t *, int /*<<< orphan*/ *);
int More(size_t argc, const char **argv) {
  char *_line = NULL;
  size_t _lno = 0;
  int page = 25;
  if (argc >= 2) {
    page = atoi(argv[1]);
  }
  char c;
  FILE *fin = fidopen(0, "r");
  FILE *fout = fidopen(1, "w");
  FILE *fkbd = fidopen(1, "r");
  int atend = 1;
  size_t count = 0;
  while ((c = fgetc(fin)) != EOF) {
    if (atend) {
      count++;
      atend = 0;
      if (count % page == 0) {
        fprintf(fout, "press enter to continue:");
        (void)getline(&_line, &_lno, fkbd);
      }
    }
    fprintf(fout, "%c", c);
    if (c == '\n')
      atend = 1;
  }
  fclose(fin);
  fclose(fout);
  fclose(fkbd);
  free(_line);
  return 0;
}


x86 assembly (clang, -O0):
<More>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x19,-0x24(%rbp)
cmpq   $0x2,-0x8(%rbp)
jb     11b2 <More+0x42>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x24(%rbp)
xor    %edi,%edi
lea    0xe45(%rip),%rsi
call   1070 <fidopen@plt>
mov    %rax,-0x30(%rbp)
mov    $0x1,%edi
lea    0xe32(%rip),%rsi
call   1070 <fidopen@plt>
mov    %rax,-0x38(%rbp)
mov    $0x1,%edi
lea    0xe1b(%rip),%rsi
call   1070 <fidopen@plt>
mov    %rax,-0x40(%rbp)
movl   $0x1,-0x44(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x25(%rbp)
movsbl %al,%eax
mov    0x2dd5(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12a9 <More+0x139>
cmpl   $0x0,-0x44(%rbp)
je     127a <More+0x10a>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x50(%rbp),%rax
movslq -0x24(%rbp),%rcx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    1275 <More+0x105>
mov    -0x38(%rbp),%rdi
lea    0xda7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x40(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <getline@plt>
jmp    127a <More+0x10a>
mov    -0x38(%rbp),%rdi
movsbl -0x25(%rbp),%edx
lea    0xd94(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movsbl -0x25(%rbp),%eax
cmp    $0xa,%eax
jne    12a4 <More+0x134>
movl   $0x1,-0x44(%rbp)
jmp    11fd <More+0x8d>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<More>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    $0x19,%r13d
cmp    $0x2,%rdi
jb     11b8 <More+0x38>
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
movslq %eax,%r13
lea    0xe41(%rip),%rbx
xor    %edi,%edi
mov    %rbx,%rsi
call   1070 <fidopen@plt>
mov    %rax,%r14
lea    0xe2f(%rip),%rsi
mov    $0x1,%r15d
mov    $0x1,%edi
call   1070 <fidopen@plt>
mov    %rax,%r12
mov    $0x1,%edi
mov    %rbx,%rsi
call   1070 <fidopen@plt>
mov    %rax,(%rsp)
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    0x2de0(%rip),%rax
cmp    (%rax),%bpl
jne    1241 <More+0xc1>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    (%rsp),%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
jmp    127f <More+0xff>
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %bpl,%ebp
mov    %ebp,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
xor    %r15d,%r15d
cmp    $0xa,%bpl
sete   %r15b
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    0x2d6e(%rip),%rax
cmp    (%rax),%bpl
je     120d <More+0x8d>
test   %r15d,%r15d
je     1250 <More+0xd0>
add    $0x1,%rbx
mov    %rbx,%rax
or     %r13,%rax
shr    $0x20,%rax
je     12b0 <More+0x130>
mov    %rbx,%rax
xor    %edx,%edx
div    %r13
test   %rdx,%rdx
jne    1250 <More+0xd0>
jmp    12bc <More+0x13c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%eax
xor    %edx,%edx
div    %r13d
test   %rdx,%rdx
jne    1250 <More+0xd0>
mov    $0x18,%esi
mov    $0x1,%edx
lea    0xd37(%rip),%rdi
mov    %r12,%rcx
call   10a0 <fwrite@plt>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    (%rsp),%rdx
call   1090 <getline@plt>
jmp    1250 <More+0xd0>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@EOF = global i8 0
@.str.2 = [25 x i8] c"press enter to continue:\00"
@.str.3 = [3 x i8] c"%c\00"
define i32 @More(i64 %0, i8** %1) {
%3 = alloca i64
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i64
store i64 %0, i64* %3
store i8** %1, i8*** %4
store i8* null, i8** %5
store i64 0, i64* %6
store i32 25, i32* %7
%14 = load i64, i64* %3
%15 = icmp uge i64 %14, 2
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8**, i8*** %4
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %7
br label %21
21: ; preds = %16, %2
%22 = call i32* @fidopen(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %9
%23 = call i32* @fidopen(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %10
%24 = call i32* @fidopen(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %24, i32** %11
store i32 1, i32* %12
store i64 0, i64* %13
br label %25
25: ; preds = %58, %21
%26 = load i32*, i32** %9
%27 = call signext i8 @fgetc(i32* %26)
store i8 %27, i8* %8
%28 = sext i8 %27 to i32
%29 = load i8, i8* @EOF
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %28, %30
br i1 %31, label %32, label %59
32: ; preds = %25
%33 = load i32, i32* %12
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %49
35: ; preds = %32
%36 = load i64, i64* %13
%37 = add i64 %36, 1
store i64 %37, i64* %13
store i32 0, i32* %12
%38 = load i64, i64* %13
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = urem i64 %38, %40
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %35
%44 = load i32*, i32** %10
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%46 = load i32*, i32** %11
%47 = call i32 @getline(i8** %5, i64* %6, i32* %46)
br label %48
48: ; preds = %43, %35
br label %49
49: ; preds = %48, %32
%50 = load i32*, i32** %10
%51 = load i8, i8* %8
%52 = sext i8 %51 to i32
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %52)
%54 = load i8, i8* %8
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 10
br i1 %56, label %57, label %58
57: ; preds = %49
store i32 1, i32* %12
br label %58
58: ; preds = %57, %49
br label %25
59: ; preds = %25
%60 = load i32*, i32** %9
%61 = call i32 @fclose(i32* %60)
%62 = load i32*, i32** %10
%63 = call i32 @fclose(i32* %62)
%64 = load i32*, i32** %11
%65 = call i32 @fclose(i32* %64)
%66 = load i8*, i8** %5
%67 = call i32 @free(i8* %66)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@EOF = global i8 0
@.str.2 = [25 x i8] c"press enter to continue:\00"
define i32 @More(i64 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = icmp ugt i64 %0, 1
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = sext i32 %11 to i64
br label %13
13: ; preds = %8, %2
%14 = phi i64 [ %12, %8 ], [ 25, %2 ]
%15 = tail call i32* @fidopen(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32* @fidopen(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32* @fidopen(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = call signext i8 @fgetc(i32* %15)
%19 = load i8, i8* @EOF
%20 = icmp eq i8 %18, %19
br i1 %20, label %42, label %21
21: ; preds = %13, %34
%22 = phi i8 [ %39, %34 ], [ %18, %13 ]
%23 = phi i64 [ %35, %34 ], [ 0, %13 ]
%24 = phi i32 [ %38, %34 ], [ 1, %13 ]
%25 = sext i8 %22 to i32
%26 = icmp eq i32 %24, 0
br i1 %26, label %34, label %27
27: ; preds = %21
%28 = add i64 %23, 1
%29 = urem i64 %28, %14
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = call i64 @fwrite(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 24, i64 1, i32* %16)
%33 = call i32 @getline(i8** %3, i64* %4, i32* %17)
br label %34
34: ; preds = %27, %31, %21
%35 = phi i64 [ %28, %31 ], [ %28, %27 ], [ %23, %21 ]
%36 = call i32 @fputc(i32 %25, i32* %16)
%37 = icmp eq i8 %22, 10
%38 = zext i1 %37 to i32
%39 = call signext i8 @fgetc(i32* %15)
%40 = load i8, i8* @EOF
%41 = icmp eq i8 %39, %40
br i1 %41, label %42, label %21
42: ; preds = %34, %13
%43 = call i32 @fclose(i32* %15)
%44 = call i32 @fclose(i32* %16)
%45 = call i32 @fclose(i32* %17)
%46 = load i8*, i8** %3
%47 = call i32 @free(i8* %46)
ret i32 0
}