#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 scalar_t__ clock_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
scalar_t__ clock();
int /*<<< orphan*/ error(char *, char *, ...);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ filecopy(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  FILE *fp;
  char *prog = argv[0];
  clock_t start = clock();
  if (argc == 1) {
    filecopy(stdin, stdout);
    return 0;
  }
  while (--argc > 0)
    if ((fp = fopen(*++argv, "r")) == NULL)
      error("%s: cannot open %s\n", prog, *argv);
    else {
      filecopy(fp, stdout);
      (void)fclose(fp);
    }
  if (ferror(stdout) != 0)
    error("%s: error writing stdout\n", prog);
  printf("Run time: %u clock ticks\n", (unsigned)(clock() - start));
  exit(EXIT_SUCCESS);
}


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)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11d6 <main+0x56>
mov    0x2e2b(%rip),%rax
mov    (%rax),%rdi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
call   1070 <filecopy@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret
jmp    11db <main+0x5b>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    1258 <main+0xd8>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xdf9(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1238 <main+0xb8>
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1080 <error@plt>
jmp    1253 <main+0xd3>
mov    -0x18(%rbp),%rdi
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
call   1070 <filecopy@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
jmp    11db <main+0x5b>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1282 <main+0x102>
mov    -0x20(%rbp),%rsi
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1080 <error@plt>
mov    $0x0,%al
call   1040 <clock@plt>
sub    -0x28(%rbp),%rax
mov    %eax,%esi
lea    0xd9a(%rip),%rdi
call   1060 <printf@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%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,%rbx
mov    %edi,%ebp
mov    (%rsi),%r15
xor    %eax,%eax
call   1040 <clock@plt>
cmp    $0x1,%ebp
jne    11c8 <main+0x48>
mov    0x2e42(%rip),%rax
mov    (%rax),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
call   1070 <filecopy@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rax,%r14
jle    122e <main+0xae>
add    $0x1,%ebp
add    $0x8,%rbx
lea    0xe25(%rip),%r12
jmp    1208 <main+0x88>
nopl   (%rax)
mov    %rax,%r13
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   1070 <filecopy@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
add    $0xffffffff,%ebp
add    $0x8,%rbx
cmp    $0x2,%ebp
jbe    122e <main+0xae>
mov    (%rbx),%rdi
mov    %r12,%rsi
call   1090 <fopen@plt>
test   %rax,%rax
jne    11e0 <main+0x60>
mov    (%rbx),%rdx
lea    0xde0(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <error@plt>
jmp    11fc <main+0x7c>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
test   %rax,%rax
je     1252 <main+0xd2>
lea    0xdce(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <error@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14d,%eax
lea    0xdcd(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stdin = global i32* null
@stdout = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [20 x i8] c"%s: cannot open %s\0A\00"
@.str.2 = [26 x i8] c"%s: error writing stdout\0A\00"
@.str.3 = [26 x i8] c"Run time: %u clock ticks\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
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
%12 = call i64 (...) @clock()
store i64 %12, i64* %8
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32*, i32** @stdin
%17 = load i32, i32* @stdout
%18 = call i32 @filecopy(i32* %16, i32 %17)
ret i32 0
19: ; preds = %2
br label %20
20: ; preds = %41, %19
%21 = load i32, i32* %4
%22 = add nsw i32 %21, -1
store i32 %22, i32* %4
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %42
24: ; preds = %20
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i32 1
store i8** %26, i8*** %5
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %28, i32** %6
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %35
30: ; preds = %24
%31 = load i8*, i8** %7
%32 = load i8**, i8*** %5
%33 = load i8*, i8** %32
%34 = call i32 (i8*, i8*, ...) @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %31, i8* %33)
br label %41
35: ; preds = %24
%36 = load i32*, i32** %6
%37 = load i32, i32* @stdout
%38 = call i32 @filecopy(i32* %36, i32 %37)
%39 = load i32*, i32** %6
%40 = call i32 @fclose(i32* %39)
br label %41
41: ; preds = %35, %30
br label %20
42: ; preds = %20
%43 = load i32, i32* @stdout
%44 = call i64 @ferror(i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load i8*, i8** %7
%48 = call i32 (i8*, i8*, ...) @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %46, %42
%50 = call i64 (...) @clock()
%51 = load i64, i64* %8
%52 = sub nsw i64 %50, %51
%53 = trunc i64 %52 to i32
%54 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %53)
%55 = load i32, i32* @EXIT_SUCCESS
%56 = call i32 @exit(i32 %55)
unreachable
}

LLVM IR (-O2):
@stdin = global i32* null
@stdout = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [20 x i8] c"%s: cannot open %s\0A\00"
@.str.2 = [26 x i8] c"%s: error writing stdout\0A\00"
@.str.3 = [26 x i8] c"Run time: %u clock ticks\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i64 (...) @clock()
%5 = icmp eq i32 %0, 1
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = icmp sgt i32 %0, 1
br i1 %7, label %12, label %29
8: ; preds = %2
%9 = load i32*, i32** @stdin
%10 = load i32, i32* @stdout
%11 = tail call i32 @filecopy(i32* %9, i32 %10)
ret i32 0
12: ; preds = %6, %27
%13 = phi i32 [ %15, %27 ], [ %0, %6 ]
%14 = phi i8** [ %16, %27 ], [ %1, %6 ]
%15 = add nsw i32 %13, -1
%16 = getelementptr inbounds i8*, i8** %14, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %12
%21 = load i8*, i8** %16
%22 = tail call i32 (i8*, i8*, ...) @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %21)
br label %27
23: ; preds = %12
%24 = load i32, i32* @stdout
%25 = tail call i32 @filecopy(i32* %18, i32 %24)
%26 = tail call i32 @fclose(i32* %18)
br label %27
27: ; preds = %23, %20
%28 = icmp ugt i32 %13, 2
br i1 %28, label %12, label %29
29: ; preds = %27, %6
%30 = load i32, i32* @stdout
%31 = tail call i64 @ferror(i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %29
%34 = tail call i32 (i8*, i8*, ...) @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %35
35: ; preds = %33, %29
%36 = tail call i64 (...) @clock()
%37 = sub nsw i64 %36, %4
%38 = trunc i64 %37 to i32
%39 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = load i32, i32* @EXIT_SUCCESS
%41 = tail call i32 @exit(i32 %40)
unreachable
}