#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*/ errno;
int /*<<< orphan*/ exit(int);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, ...);
char *getenv(char *);
int pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ *stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  FILE *pipe;
  char line[128], *pager;
  FILE *fp;
  if (argc != 2) {
    perror("usage: a.out <pathname>");
    exit(1);
  }
  if ((pager = getenv("PAGER")) == NULL)
    pager = "/usr/bin/more";
  if ((pipe = popen(pager, "w")) == NULL) {
    fprintf(stderr, "Unable to open pipe to %s: %s\n", pager, strerror(errno));
    exit(1);
  }
  if ((fp = fopen(argv[1], "r")) == NULL) {
    fprintf(stderr, "can't open %s\n", argv[1]);
    exit(1);
  }
  while (fgets(line, 128, fp) != NULL) {
    fprintf(pipe, "==> %s", line);
  }
  if (ferror(fp)) {
    perror("fgets error");
    exit(1);
  }
  if (pclose(pipe) == -1) {
    perror("pclose error");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d9 <main+0x39>
lea    0xe36(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xe38(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0xa8(%rbp)
cmp    $0x0,%rax
jne    1204 <main+0x64>
lea    0xe21(%rip),%rax
mov    %rax,-0xa8(%rbp)
mov    -0xa8(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    127b <main+0xdb>
mov    0x2db4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0xc0(%rbp)
mov    -0xa8(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0xc0(%rbp),%rdi
mov    -0xb8(%rbp),%rdx
mov    %rax,%rcx
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf0(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0xb0(%rbp)
cmp    $0x0,%rax
jne    12ca <main+0x12a>
mov    0x2d39(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd94(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    12cf <main+0x12f>
lea    -0xa0(%rbp),%rdi
mov    -0xb0(%rbp),%rdx
mov    $0x80,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     130f <main+0x16f>
mov    -0x18(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    0xd59(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    12cf <main+0x12f>
mov    -0xb0(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     133b <main+0x19b>
lea    0xd37(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1050 <pclose@plt>
cmp    $0xffffffff,%eax
jne    1363 <main+0x1c3>
lea    0xd1b(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
cmp    $0x2,%edi
jne    1288 <main+0xe8>
mov    %rsi,%r15
lea    0xe57(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe4e(%rip),%rbx
cmovne %rax,%rbx
lea    0xe51(%rip),%rsi
mov    %rbx,%rdi
call   1080 <popen@plt>
test   %rax,%rax
je     1291 <main+0xf1>
mov    %rax,%r14
mov    0x8(%r15),%rdi
lea    0xe80(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12ca <main+0x12a>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1255 <main+0xb5>
lea    0xe35(%rip),%r15
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    1230 <main+0x90>
mov    %r12,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    12f0 <main+0x150>
mov    %r14,%rdi
call   1050 <pclose@plt>
cmp    $0xffffffff,%eax
je     12f9 <main+0x159>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd71(%rip),%rdi
jmp    1300 <main+0x160>
mov    0x2d48(%rip),%rax
mov    (%rax),%r14
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd7e(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d0f(%rip),%rax
mov    (%rax),%rdi
mov    0x8(%r15),%rdx
lea    0xd6e(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd6c(%rip),%rdi
jmp    1300 <main+0x160>
lea    0xd6f(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"usage: a.out <pathname>\00"
@.str.1 = [6 x i8] c"PAGER\00"
@.str.2 = [14 x i8] c"/usr/bin/more\00"
@.str.3 = [2 x i8] c"w\00"
@stderr = global i32* null
@.str.4 = [31 x i8] c"Unable to open pipe to %s: %s\0A\00"
@errno = global i32 0
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [15 x i8] c"can't open %s\0A\00"
@.str.7 = [7 x i8] c"==> %s\00"
@.str.8 = [12 x i8] c"fgets error\00"
@.str.9 = [13 x i8] c"pclose error\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [128 x i8]
%8 = alloca i8*
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i8* %16, i8** %8
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %15
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8** %8
br label %19
19: ; preds = %18, %15
%20 = load i8*, i8** %8
%21 = call i32* @popen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %21, i32** %6
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %30
23: ; preds = %19
%24 = load i32*, i32** @stderr
%25 = load i8*, i8** %8
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %25, i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %19
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %34, i32** %9
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %43
36: ; preds = %30
%37 = load i32*, i32** @stderr
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %30
br label %44
44: ; preds = %49, %43
%45 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%46 = load i32*, i32** %9
%47 = call i32* @fgets(i8* %45, i32 128, i32* %46)
%48 = icmp ne i32* %47, null
br i1 %48, label %49, label %53
49: ; preds = %44
%50 = load i32*, i32** %6
%51 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%52 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %51)
br label %44
53: ; preds = %44
%54 = load i32*, i32** %9
%55 = call i64 @ferror(i32* %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %53
%61 = load i32*, i32** %6
%62 = call i32 @pclose(i32* %61)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %67
64: ; preds = %60
%65 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %60
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"usage: a.out <pathname>\00"
@.str.1 = [6 x i8] c"PAGER\00"
@.str.2 = [14 x i8] c"/usr/bin/more\00"
@.str.3 = [2 x i8] c"w\00"
@stderr = global i32* null
@.str.4 = [31 x i8] c"Unable to open pipe to %s: %s\0A\00"
@errno = global i32 0
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [15 x i8] c"can't open %s\0A\00"
@.str.7 = [7 x i8] c"==> %s\00"
@.str.8 = [12 x i8] c"fgets error\00"
@.str.9 = [13 x i8] c"pclose error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i8* %10, null
%12 = select i1 %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %10
%13 = tail call i32* @popen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %21
15: ; preds = %9
%16 = load i32*, i32** @stderr
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %12, i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %9
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = tail call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = call i32* @fgets(i8* %4, i32 128, i32* %24)
%28 = icmp eq i32* %27, null
br i1 %28, label %38, label %34
29: ; preds = %21
%30 = load i32*, i32** @stderr
%31 = load i8*, i8** %22
%32 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %31)
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %26, %34
%35 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %4)
%36 = call i32* @fgets(i8* %4, i32 128, i32* %24)
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %34
38: ; preds = %34, %26
%39 = call i64 @ferror(i32* %24)
%40 = icmp eq i64 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %38
%45 = call i32 @pclose(i32* %13)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %44
ret i32 0
}