#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int ret = 0;
  int fd = 0;
  void filecopy(int, int);
  char *prog = argv[0];
  if (argc == 1)
    filecopy(0, 1);
  else
    while (--argc > 0)
      if ((fd = open(*++argv, O_RDONLY, 0)) == -1) {
        fprintf(stderr, "%s: can't open %s\n", prog, *argv);
        exit(1);
      } else {
        filecopy(fd, 1);
        close(fd);
      }
  if (ferror(stdout)) {
    fprintf(stderr, "%s: error writing stdout\n", prog);
    exit(2);
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11aa <main+0x4a>
xor    %edi,%edi
mov    $0x1,%esi
call   1060 <filecopy@plt>
jmp    123b <main+0xdb>
jmp    11af <main+0x4f>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    1236 <main+0xd6>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    121c <main+0xbc>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xdf5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   1060 <filecopy@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
jmp    11af <main+0x4f>
jmp    123b <main+0xdb>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1278 <main+0x118>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdac(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    (%rsi),%r14
cmp    $0x1,%edi
jne    117e <main+0x1e>
xor    %edi,%edi
mov    $0x1,%esi
call   1060 <filecopy@plt>
jmp    11d4 <main+0x74>
jle    11d4 <main+0x74>
mov    %rsi,%r15
mov    %edi,%ebp
add    $0x1,%ebp
add    $0x8,%r15
mov    0x2e55(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%rdi
mov    (%r12),%esi
xor    %edx,%edx
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11f2 <main+0x92>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x1,%esi
call   1060 <filecopy@plt>
mov    %ebx,%edi
call   1040 <close@plt>
add    $0xffffffff,%ebp
add    $0x8,%r15
cmp    $0x2,%ebp
jg     11a0 <main+0x40>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1219 <main+0xb9>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rcx
lea    0xdfb(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"%s: can't open %s\0A\00"
@stdout = global i32 0
@.str.1 = [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 %8, label %25
7: ; preds = %2
tail call void @filecopy(i32 0, i32 1)
br label %25
8: ; preds = %5, %21
%9 = phi i32 [ %22, %21 ], [ %0, %5 ]
%10 = phi i8** [ %11, %21 ], [ %1, %5 ]
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13, i32 0)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %21
16: ; preds = %8
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %11
%19 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %8
%22 = add nsw i32 %9, -1
tail call void @filecopy(i32 %14, i32 1)
%23 = tail call i32 @close(i32 %14)
%24 = icmp sgt i32 %9, 2
br i1 %24, label %8, label %25
25: ; preds = %21, %5, %7
%26 = load i32, i32* @stdout
%27 = tail call i64 @ferror(i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%32 = tail call i32 @exit(i32 2)
unreachable
33: ; preds = %25
ret i32 0
}