#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 */
struct winsize {
  scalar_t__ ws_row;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ TIOCGWINSZ;
int /*<<< orphan*/ do_more(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getopt(int, char **, char *);
scalar_t__ ioctl(int /*<<< orphan*/, int /*<<< orphan*/, struct winsize *);
scalar_t__ optind;
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ warn(char *, char *);
int main(int argc, char *argv[]) {
  struct winsize ws;
  int ch;
  FILE *fp = NULL;
  int height = 25;
  int rval = 0;
  while ((ch = getopt(argc, argv, "")) != -1)
    switch (ch) {
    case '?':
    default:
      fprintf(stderr, "usage: more [file ...]\n");
      exit(1);
    }
  argc -= optind;
  argv += optind;
  if (ioctl(0, TIOCGWINSZ, &ws) == 0)
    height = (int)ws.ws_row;
  if (*argv) {
    for (; *argv; ++argv) {
      if ((fp = fopen(*argv, "r")) == NULL) {
        warn("%s", *argv);
        ++argv;
        rval = 1;
        continue;
      }
      do_more(fp, height);
      (void)fclose(fp);
    }
  } else
    do_more(stdin, height);
  exit(rval);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x19,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe5d(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     1200 <main+0x80>
mov    -0x1c(%rbp),%eax
sub    $0x3f,%eax
jne    11e1 <main+0x61>
jmp    11dc <main+0x5c>
jmp    11e1 <main+0x61>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x18(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jne    124f <main+0xcf>
mov    -0x18(%rbp),%rax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     12e7 <main+0x167>
jmp    1262 <main+0xe2>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     12e2 <main+0x162>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xd9a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12bc <main+0x13c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd7b(%rip),%rdi
call   1030 <warn@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    12d1 <main+0x151>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1070 <do_more@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1262 <main+0xe2>
jmp    12f9 <main+0x179>
mov    0x2cfa(%rip),%rax
mov    (%rax),%rdi
mov    -0x2c(%rbp),%esi
call   1070 <do_more@plt>
mov    -0x30(%rbp),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
lea    0xe82(%rip),%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
jne    11f2 <main+0x72>
mov    0x2e3a(%rip),%rax
mov    (%rax),%rbx
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
xor    %edi,%edi
call   1050 <ioctl@plt>
mov    $0x19,%r13d
test   %rax,%rax
jne    11cb <main+0x4b>
mov    (%rsp),%r13d
mov    0x0(%rbp,%rbx,8),%rdi
test   %rdi,%rdi
jne    1211 <main+0x91>
mov    0x2e0c(%rip),%rax
mov    (%rax),%rdi
mov    %r13d,%esi
call   1070 <do_more@plt>
xor    %r12d,%r12d
mov    %r12d,%edi
call   10a0 <exit@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0x0(,%rbx,8),%rbx
add    %rbp,%rbx
xor    %r12d,%r12d
lea    0xdf2(%rip),%r14
lea    0xded(%rip),%r15
jmp    1253 <main+0xd3>
nop
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r13d,%esi
call   1070 <do_more@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
je     11ea <main+0x6a>
mov    %r14,%rsi
call   1080 <fopen@plt>
test   %rax,%rax
jne    1230 <main+0xb0>
mov    (%rbx),%rsi
mov    %r15,%rdi
call   1030 <warn@plt>
add    $0x8,%rbx
mov    $0x1,%r12d
jmp    1246 <main+0xc6>

LLVM IR (-O0):
%struct.winsize = type { i64 }
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [24 x i8] c"usage: more [file ...]\0A\00"
@optind = global i64 0
@TIOCGWINSZ = global i32 0
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
@stdin = global i32* null
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.winsize
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %8
store i32 25, i32* %9
store i32 0, i32* %10
br label %11
11: ; preds = %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %7
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %23
16: ; preds = %11
%17 = load i32, i32* %7
switch i32 %17, label %19 [
i32 63, label %18
]
18: ; preds = %16
br label %19
19: ; preds = %16, %18
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %11
%24 = load i64, i64* @optind
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = sub nsw i64 %26, %24
%28 = trunc i64 %27 to i32
store i32 %28, i32* %4
%29 = load i64, i64* @optind
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 %29
store i8** %31, i8*** %5
%32 = load i32, i32* @TIOCGWINSZ
%33 = call i64 @ioctl(i32 0, i32 %32, %struct.winsize* %6)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %23
%36 = getelementptr inbounds %struct.winsize, %struct.winsize* %6, i32 0, i32 0
%37 = load i64, i64* %36
%38 = trunc i64 %37 to i32
store i32 %38, i32* %9
br label %39
39: ; preds = %35, %23
%40 = load i8**, i8*** %5
%41 = load i8*, i8** %40
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %69
43: ; preds = %39
br label %44
44: ; preds = %65, %43
%45 = load i8**, i8*** %5
%46 = load i8*, i8** %45
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %68
48: ; preds = %44
%49 = load i8**, i8*** %5
%50 = load i8*, i8** %49
%51 = call i32* @fopen(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %51, i32** %8
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %59
53: ; preds = %48
%54 = load i8**, i8*** %5
%55 = load i8*, i8** %54
%56 = call i32 @warn(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %55)
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i32 1
store i8** %58, i8*** %5
store i32 1, i32* %10
br label %65
59: ; preds = %48
%60 = load i32*, i32** %8
%61 = load i32, i32* %9
%62 = call i32 @do_more(i32* %60, i32 %61)
%63 = load i32*, i32** %8
%64 = call i32 @fclose(i32* %63)
br label %65
65: ; preds = %59, %53
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i32 1
store i8** %67, i8*** %5
br label %44
68: ; preds = %44
br label %73
69: ; preds = %39
%70 = load i32*, i32** @stdin
%71 = load i32, i32* %9
%72 = call i32 @do_more(i32* %70, i32 %71)
br label %73
73: ; preds = %69, %68
%74 = load i32, i32* %10
%75 = call i32 @exit(i32 %74)
unreachable
}

LLVM IR (-O2):
%struct.winsize = type { i64 }
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [24 x i8] c"usage: more [file ...]\0A\00"
@optind = global i64 0
@TIOCGWINSZ = global i32 0
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
@stdin = global i32* null
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.winsize
%4 = bitcast %struct.winsize* %3 to i8*
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, -1
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = load i64, i64* @optind
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i32, i32* @TIOCGWINSZ
%15 = call i64 @ioctl(i32 0, i32 %14, %struct.winsize* %3)
%16 = icmp eq i64 %15, 0
%17 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 0
%18 = load i64, i64* %17
%19 = trunc i64 %18 to i32
%20 = select i1 %16, i32 %19, i32 25
%21 = load i8*, i8** %13
%22 = icmp eq i8* %21, null
br i1 %22, label %42, label %23
23: ; preds = %11, %36
%24 = phi i32 [ %38, %36 ], [ 0, %11 ]
%25 = phi i8** [ %39, %36 ], [ %13, %11 ]
%26 = phi i8* [ %40, %36 ], [ %21, %11 ]
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = load i8*, i8** %25
%31 = call i32 @warn(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds i8*, i8** %25, i64 1
br label %36
33: ; preds = %23
%34 = call i32 @do_more(i32* %27, i32 %20)
%35 = call i32 @fclose(i32* %27)
br label %36
36: ; preds = %33, %29
%37 = phi i8** [ %32, %29 ], [ %25, %33 ]
%38 = phi i32 [ 1, %29 ], [ %24, %33 ]
%39 = getelementptr inbounds i8*, i8** %37, i64 1
%40 = load i8*, i8** %39
%41 = icmp eq i8* %40, null
br i1 %41, label %45, label %23
42: ; preds = %11
%43 = load i32*, i32** @stdin
%44 = call i32 @do_more(i32* %43, i32 %20)
br label %45
45: ; preds = %36, %42
%46 = phi i32 [ 0, %42 ], [ %38, %36 ]
%47 = call i32 @exit(i32 %46)
unreachable
}