#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*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ filecopy(int, int /*<<< orphan*/);
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;
  char *prog = argv[0];
  if (argc == 1) {
    filecopy(STDIN_FILENO, STDOUT_FILENO);
  } else {
    while (--argc > 0) {
      if ((fd = open(argv[1], O_RDONLY, 0)) == -1) {
        fprintf(stderr, "%s: can't open %s\n", prog, argv[1]);
        exit(EXIT_FAILURE);
      } else {
        filecopy(fd, STDOUT_FILENO);
        close(fd);
      }
    }
  }
  return 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    1197 <main+0x47>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
call   1050 <filecopy@plt>
jmp    1224 <main+0xd4>
jmp    119c <main+0x4c>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    121f <main+0xcf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1201 <main+0xb1>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe12(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
call   1050 <filecopy@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
jmp    119c <main+0x4c>
jmp    1224 <main+0xd4>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jne    1179 <main+0x29>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
call   1050 <filecopy@plt>
jmp    11d0 <main+0x80>
jle    11d0 <main+0x80>
mov    %rsi,%r15
mov    %edi,%ebp
mov    (%rsi),%r14
add    $0x1,%ebp
mov    0x2e53(%rip),%r12
mov    0x2e5c(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x8(%r15),%rdi
mov    (%r12),%esi
xor    %edx,%edx
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11e1 <main+0x91>
mov    %eax,%ebx
mov    0x0(%r13),%esi
mov    %eax,%edi
call   1050 <filecopy@plt>
mov    %ebx,%edi
call   1030 <close@plt>
add    $0xffffffff,%ebp
cmp    $0x2,%ebp
jg     11a0 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rcx
lea    0xe0b(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

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

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