#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 */
scalar_t__ EOF;
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 *, ...);
scalar_t__ fputs(char *, int /*<<< orphan*/ *);
int pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char line[4096];
  FILE *fpin, *fpout;
  if (argc != 2) {
    fprintf(stderr, "usage: a.out <pathname>");
    exit(1);
  }
  if ((fpin = fopen(argv[1], "r")) == NULL) {
    fprintf(stderr, "can't open %s", argv[1]);
    exit(1);
  }
  if ((fpout = popen("${PAGER:-more}", "w")) == NULL) {
    fprintf(stderr, "popen error");
    exit(1);
  }
  while (fgets(line, 4096, fpin) != NULL) {
    if (fputs(line, fpout) == EOF) {
      fprintf(stderr, "fputs error to pipe");
      exit(1);
    }
  }
  if (ferror(fpin)) {
    fprintf(stderr, "fgets error");
    exit(1);
  }
  if (pclose(fpout) == -1) {
    fprintf(stderr, "pclose error");
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c4 <main+0x44>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe9b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x1018(%rbp)
cmp    $0x0,%rax
jne    1212 <main+0x92>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe0d(%rip),%rdi
lea    0xe15(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x1020(%rbp)
cmp    $0x0,%rax
jne    1257 <main+0xd7>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    125c <main+0xdc>
lea    -0x1010(%rbp),%rdi
mov    -0x1018(%rbp),%rdx
mov    $0x1000,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12c7 <main+0x147>
lea    -0x1010(%rbp),%rdi
mov    -0x1020(%rbp),%rsi
call   1050 <fputs@plt>
mov    0x2d50(%rip),%rcx
cmp    (%rcx),%rax
jne    12c2 <main+0x142>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    125c <main+0xdc>
mov    -0x1018(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12fe <main+0x17e>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x1020(%rbp),%rdi
call   1040 <pclose@plt>
cmp    $0xffffffff,%eax
jne    1334 <main+0x1b4>
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
lea    0xd40(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1008,%rsp
cmp    $0x2,%edi
jne    11d0 <main+0x50>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xecd(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
jne    11f1 <main+0x71>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe59(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %rax,%r14
lea    0xe2b(%rip),%rdi
lea    0xe33(%rip),%rsi
call   1080 <popen@plt>
test   %rax,%rax
jne    121e <main+0x9e>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
jmp    11e0 <main+0x60>
mov    %rax,%r15
mov    %rsp,%rbx
mov    0x2dbd(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     126b <main+0xeb>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fputs@plt>
cmp    (%r12),%rax
jne    1230 <main+0xb0>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
jmp    11e0 <main+0x60>
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    129a <main+0x11a>
mov    %r15,%rdi
call   1040 <pclose@plt>
cmp    $0xffffffff,%eax
jne    12af <main+0x12f>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    0xdce(%rip),%rsi
jmp    11e0 <main+0x60>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
jmp    11e0 <main+0x60>
xor    %edi,%edi
call   10a0 <exit@plt>

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

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