#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 /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int /*<<< orphan*/);
int dup(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *getenv(char *);
int more(int /*<<< orphan*/ *);
scalar_t__ open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *fp;
  char *name;
  int next;
  if (argc == 1) {
    next = dup(0);
    close(0);
    name = getenv("CTTY");
    if (!name) {
      fprintf(stderr, "%s: CTTY not set\n", argv[0]);
      return -1;
    }
    if (open(name, O_RDWR) == 0) {
      fp = fdopen(next, "r");
      if (fp)
        more(fp);
    } else {
      perror("more (CTTY)");
    }
  } else
    while (argc-- > 1) {
      name = *(++argv);
      fp = fopen(name, "r");
      if (fp == NULL) {
        perror(name);
        return 1;
      }
      printf("<< %s >>\n", name);
      next = more(fp);
      fclose(fp);
      if (!next)
        break;
    }
  return 0;
}


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)
cmpl   $0x1,-0x8(%rbp)
jne    127d <main+0xcd>
xor    %edi,%edi
call   1060 <dup@plt>
mov    %eax,-0x24(%rbp)
xor    %edi,%edi
call   1070 <close@plt>
lea    0xe18(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1224 <main+0x74>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf2(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1326 <main+0x176>
mov    -0x20(%rbp),%rdi
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
cmp    $0x0,%rax
jne    126c <main+0xbc>
mov    -0x24(%rbp),%edi
lea    0xdcd(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1267 <main+0xb7>
mov    -0x18(%rbp),%rdi
call   1090 <more@plt>
jmp    1278 <main+0xc8>
lea    0xda6(%rip),%rdi
call   10d0 <perror@plt>
jmp    131f <main+0x16f>
jmp    1282 <main+0xd2>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x1,%eax
jle    131a <main+0x16a>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xd5f(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12e1 <main+0x131>
mov    -0x20(%rbp),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1326 <main+0x176>
mov    -0x20(%rbp),%rsi
lea    0xd39(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <more@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0x24(%rbp)
jne    1315 <main+0x165>
jmp    131a <main+0x16a>
jmp    1282 <main+0xd2>
jmp    131f <main+0x16f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
cmp    $0x1,%edi
jne    1229 <main+0x79>
xor    %edi,%edi
call   1060 <dup@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   1070 <close@plt>
lea    0xe26(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     128c <main+0xdc>
mov    0x2df9(%rip),%rcx
mov    (%rcx),%esi
mov    %rax,%rdi
call   10b0 <open@plt>
test   %rax,%rax
jne    12bd <main+0x10d>
lea    0xe0e(%rip),%rsi
mov    %ebp,%edi
call   10a0 <fdopen@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     12ab <main+0xfb>
mov    %rax,%rdi
call   1090 <more@plt>
jmp    12ab <main+0xfb>
mov    %edi,%ebp
add    $0x8,%r13
lea    0xdef(%rip),%r12
xor    %r14d,%r14d
nopl   0x0(%rax)
cmp    $0x2,%ebp
jl     12ab <main+0xfb>
mov    0x0(%r13),%r15
mov    %r15,%rdi
lea    0xdc4(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12ce <main+0x11e>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1090 <more@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x8,%r13
add    $0xffffffff,%ebp
test   %r15d,%r15d
jne    1240 <main+0x90>
jmp    12ab <main+0xfb>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xd65(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd55(%rip),%rdi
call   10d0 <perror@plt>
xor    %r14d,%r14d
jmp    12ab <main+0xfb>
mov    %r15,%rdi
call   10d0 <perror@plt>
mov    $0x1,%r14d
jmp    12ab <main+0xfb>

LLVM IR (-O0):
@.str = [5 x i8] c"CTTY\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"%s: CTTY not set\0A\00"
@O_RDWR = global i32 0
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [12 x i8] c"more (CTTY)\00"
@.str.4 = [10 x i8] c"<< %s >>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %40
11: ; preds = %2
%12 = call i32 @dup(i32 0)
store i32 %12, i32* %8
%13 = call i32 @close(i32 0)
%14 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = icmp ne i8* %15, null
br i1 %16, label %23, label %17
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %21)
store i32 -1, i32* %3
br label %69
23: ; preds = %11
%24 = load i8*, i8** %7
%25 = load i32, i32* @O_RDWR
%26 = call i64 @open(i8* %24, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %23
%29 = load i32, i32* %8
%30 = call i32* @fdopen(i32 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %30, i32** %6
%31 = load i32*, i32** %6
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i32*, i32** %6
%35 = call i32 @more(i32* %34)
br label %36
36: ; preds = %33, %28
br label %39
37: ; preds = %23
%38 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %36
br label %68
40: ; preds = %2
br label %41
41: ; preds = %66, %40
%42 = load i32, i32* %4
%43 = add nsw i32 %42, -1
store i32 %43, i32* %4
%44 = icmp sgt i32 %42, 1
br i1 %44, label %45, label %67
45: ; preds = %41
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i32 1
store i8** %47, i8*** %5
%48 = load i8*, i8** %47
store i8* %48, i8** %7
%49 = load i8*, i8** %7
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %50, i32** %6
%51 = load i32*, i32** %6
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %56
53: ; preds = %45
%54 = load i8*, i8** %7
%55 = call i32 @perror(i8* %54)
store i32 1, i32* %3
br label %69
56: ; preds = %45
%57 = load i8*, i8** %7
%58 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %57)
%59 = load i32*, i32** %6
%60 = call i32 @more(i32* %59)
store i32 %60, i32* %8
%61 = load i32*, i32** %6
%62 = call i32 @fclose(i32* %61)
%63 = load i32, i32* %8
%64 = icmp ne i32 %63, 0
br i1 %64, label %66, label %65
65: ; preds = %56
br label %67
66: ; preds = %56
br label %41
67: ; preds = %65, %41
br label %68
68: ; preds = %67, %39
store i32 0, i32* %3
br label %69
69: ; preds = %68, %53, %17
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@.str = [5 x i8] c"CTTY\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"%s: CTTY not set\0A\00"
@O_RDWR = global i32 0
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [12 x i8] c"more (CTTY)\00"
@.str.4 = [10 x i8] c"<< %s >>\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %24
4: ; preds = %2
%5 = tail call i32 @dup(i32 0)
%6 = tail call i32 @close(i32 0)
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %41
13: ; preds = %4
%14 = load i32, i32* @O_RDWR
%15 = tail call i64 @open(i8* %7, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = tail call i32* @fdopen(i32 %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %41, label %20
20: ; preds = %17
%21 = tail call i32 @more(i32* %18)
br label %41
22: ; preds = %13
%23 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %41
24: ; preds = %2, %36
%25 = phi i32 [ %27, %36 ], [ %0, %2 ]
%26 = phi i8** [ %30, %36 ], [ %1, %2 ]
%27 = add nsw i32 %25, -1
%28 = icmp sgt i32 %25, 1
br i1 %28, label %29, label %41
29: ; preds = %24
%30 = getelementptr inbounds i8*, i8** %26, i64 1
%31 = load i8*, i8** %30
%32 = tail call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = tail call i32 @perror(i8* %31)
br label %41
36: ; preds = %29
%37 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%38 = tail call i32 @more(i32* %32)
%39 = tail call i32 @fclose(i32* %32)
%40 = icmp eq i32 %38, 0
br i1 %40, label %41, label %24
41: ; preds = %36, %24, %17, %20, %22, %34, %9
%42 = phi i32 [ -1, %9 ], [ 1, %34 ], [ 0, %22 ], [ 0, %20 ], [ 0, %17 ], [ 0, %24 ], [ 0, %36 ]
ret i32 %42
}