#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printpages(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  FILE *fp;
  char *prog = argv[0];
  int linecount = 0;
  if (argc == 1) {
    fprintf(stderr, "No files given");
    printpages(stdin, stdout);
  } else
    while (--argc > 0)
      if ((fp = fopen(*++argv, "r")) == NULL) {
        fprintf(stderr, "%s: can't open %s\n", prog, *argv);
        exit(1);
      } else {
        fprintf(stdout, "\n\n\t\t\tFile: %s\n\n", *argv);
        printpages(fp, stdout);
        fclose(fp);
      }
  if (ferror(stdout)) {
    fprintf(stderr, "%s: error writing stdout\n", prog);
    exit(2);
  }
  exit(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)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11c6 <main+0x66>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%rdi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
call   1060 <printpages@plt>
jmp    1279 <main+0x119>
jmp    11cb <main+0x6b>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    1274 <main+0x114>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe18(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1236 <main+0xd6>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdd7(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d71(%rip),%rax
mov    (%rax),%esi
call   1060 <printpages@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
jmp    11cb <main+0x6b>
jmp    1279 <main+0x119>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12b6 <main+0x156>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xd8f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rsi),%rax
cmp    $0x1,%edi
mov    %rax,(%rsp)
jne    11a8 <main+0x48>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%rdi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
call   1060 <printpages@plt>
jmp    1214 <main+0xb4>
jle    1214 <main+0xb4>
mov    %rsi,%rbx
mov    %edi,%r13d
add    $0x1,%r13d
add    $0x8,%rbx
lea    0xe50(%rip),%r15
mov    0x2e0a(%rip),%r14
lea    0xe57(%rip),%r12
nopl   (%rax)
mov    (%rbx),%rdi
mov    %r15,%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1253 <main+0xf3>
mov    %rax,%rbp
mov    (%r14),%edi
mov    (%rbx),%rdx
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14),%esi
mov    %rbp,%rdi
call   1060 <printpages@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
add    $0xffffffff,%r13d
add    $0x8,%rbx
cmp    $0x2,%r13d
jg     11d0 <main+0x70>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
test   %rax,%rax
jne    122e <main+0xce>
xor    %edi,%edi
call   1080 <exit@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
lea    0xdf6(%rip),%rsi
mov    (%rsp),%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rcx
lea    0xdab(%rip),%rsi
mov    (%rsp),%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"No files given\00"
@stdin = global i32* null
@stdout = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"%s: can't open %s\0A\00"
@.str.3 = [16 x i8] c"\0A\0A\09\09\09File: %s\0A\0A\00"
@.str.4 = [26 x i8] c"%s: error writing stdout\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 i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
store i8* %11, i8** %7
store i32 0, i32* %8
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%17 = load i32*, i32** @stdin
%18 = load i32, i32* @stdout
%19 = call i32 @printpages(i32* %17, i32 %18)
br label %50
20: ; preds = %2
br label %21
21: ; preds = %48, %20
%22 = load i32, i32* %4
%23 = add nsw i32 %22, -1
store i32 %23, i32* %4
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %49
25: ; preds = %21
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i32 1
store i8** %27, i8*** %5
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %6
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %38
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %7
%34 = load i8**, i8*** %5
%35 = load i8*, i8** %34
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %33, i8* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %25
%39 = load i32, i32* @stdout
%40 = load i8**, i8*** %5
%41 = load i8*, i8** %40
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %41)
%43 = load i32*, i32** %6
%44 = load i32, i32* @stdout
%45 = call i32 @printpages(i32* %43, i32 %44)
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
br label %48
48: ; preds = %38
br label %21
49: ; preds = %21
br label %50
50: ; preds = %49, %14
%51 = load i32, i32* @stdout
%52 = call i64 @ferror(i32 %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %50
%55 = load i32, i32* @stderr
%56 = load i8*, i8** %7
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %56)
%58 = call i32 @exit(i32 2)
unreachable
59: ; preds = %50
%60 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"No files given\00"
@stdin = global i32* null
@stdout = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"%s: can't open %s\0A\00"
@.str.3 = [16 x i8] c"\0A\0A\09\09\09File: %s\0A\0A\00"
@.str.4 = [26 x i8] c"%s: error writing stdout\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = icmp eq i32 %0, 1
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = icmp sgt i32 %0, 1
br i1 %6, label %13, label %34
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%10 = load i32*, i32** @stdin
%11 = load i32, i32* @stdout
%12 = tail call i32 @printpages(i32* %10, i32 %11)
br label %34
13: ; preds = %5, %25
%14 = phi i32 [ %26, %25 ], [ %0, %5 ]
%15 = phi i8** [ %16, %25 ], [ %1, %5 ]
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %25
20: ; preds = %13
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %16
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %3, i8* %22)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %13
%26 = add nsw i32 %14, -1
%27 = load i32, i32* @stdout
%28 = load i8*, i8** %16
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @stdout
%31 = tail call i32 @printpages(i32* %18, i32 %30)
%32 = tail call i32 @fclose(i32* %18)
%33 = icmp sgt i32 %14, 2
br i1 %33, label %13, label %34
34: ; preds = %25, %5, %7
%35 = load i32, i32* @stdout
%36 = tail call i64 @ferror(i32 %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%41 = tail call i32 @exit(i32 2)
unreachable
42: ; preds = %34
%43 = tail call i32 @exit(i32 0)
unreachable
}