#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);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int fd;
  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);
      }
  exit(0);
}


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)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    118c <main+0x3c>
xor    %edi,%edi
mov    $0x1,%esi
call   1050 <filecopy@plt>
jmp    121b <main+0xcb>
jmp    1191 <main+0x41>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    1216 <main+0xc6>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11fc <main+0xac>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xe13(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1050 <filecopy@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
jmp    1191 <main+0x41>
jmp    121b <main+0xcb>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x1,%edi
jne    1170 <main+0x20>
xor    %edi,%edi
mov    $0x1,%esi
call   1050 <filecopy@plt>
xor    %edi,%edi
call   1070 <exit@plt>
jle    11c4 <main+0x74>
mov    %rsi,%r15
mov    %edi,%ebp
mov    (%rsi),%r14
add    $0x1,%ebp
add    $0x8,%r15
mov    0x2e60(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    (%r15),%rdi
mov    (%r12),%esi
xor    %edx,%edx
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11cb <main+0x7b>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x1,%esi
call   1050 <filecopy@plt>
mov    %ebx,%edi
call   1030 <close@plt>
add    $0xffffffff,%ebp
add    $0x8,%r15
cmp    $0x2,%ebp
jg     1190 <main+0x40>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rcx
lea    0xe22(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <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"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
store i8* %10, i8** %7
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %2
br label %39
14: ; preds = %2
br label %15
15: ; preds = %37, %14
%16 = load i32, i32* %4
%17 = add nsw i32 %16, -1
store i32 %17, i32* %4
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %38
19: ; preds = %15
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i32 1
store i8** %21, i8*** %5
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23, i32 0)
store i32 %24, i32* %6
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %33
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %7
%29 = load i8**, i8*** %5
%30 = load i8*, i8** %29
%31 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %28, i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %19
%34 = load i32, i32* %6
%35 = load i32, i32* %6
%36 = call i32 @close(i32 %35)
br label %37
37: ; preds = %33
br label %15
38: ; preds = %15
br label %39
39: ; preds = %38, %13
%40 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"%s: can't open %s\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 @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 = tail call i32 @exit(i32 0)
unreachable
}