#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*/ error(char *, char *, char *);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
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)
        error("%s: can't open %s\n", prog, *argv);
      else {
        filecopy(fd, 1);
        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    117c <main+0x3c>
xor    %edi,%edi
mov    $0x1,%esi
call   1040 <filecopy@plt>
jmp    11fd <main+0xbd>
jmp    1181 <main+0x41>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11f8 <main+0xb8>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11de <main+0x9e>
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe2c(%rip),%rdi
call   1050 <error@plt>
jmp    11f3 <main+0xb3>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1040 <filecopy@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
jmp    1181 <main+0x41>
jmp    11fd <main+0xbd>
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    115e <main+0x1e>
xor    %edi,%edi
mov    $0x1,%esi
call   1040 <filecopy@plt>
jmp    11d6 <main+0x96>
jle    11d6 <main+0x96>
mov    %rsi,%rbx
mov    %edi,%r12d
mov    (%rsi),%r14
add    $0x1,%r12d
add    $0x8,%rbx
mov    0x2e70(%rip),%r13
lea    0xe81(%rip),%r15
jmp    11b3 <main+0x73>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <filecopy@plt>
mov    %ebp,%edi
call   1030 <close@plt>
add    $0xffffffff,%r12d
add    $0x8,%rbx
cmp    $0x2,%r12d
jbe    11d6 <main+0x96>
mov    (%rbx),%rdi
mov    0x0(%r13),%esi
xor    %edx,%edx
call   1060 <open@plt>
cmp    $0xffffffff,%eax
jne    1190 <main+0x50>
mov    (%rbx),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <error@plt>
jmp    11a5 <main+0x65>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = 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 %37
14: ; preds = %2
br label %15
15: ; preds = %35, %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 %36
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 %31
26: ; preds = %19
%27 = load i8*, i8** %7
%28 = load i8**, i8*** %5
%29 = load i8*, i8** %28
%30 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %27, i8* %29)
br label %35
31: ; preds = %19
%32 = load i32, i32* %6
%33 = load i32, i32* %6
%34 = call i32 @close(i32 %33)
br label %35
35: ; preds = %31, %26
br label %15
36: ; preds = %15
br label %37
37: ; preds = %36, %13
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = 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 %24
7: ; preds = %2
tail call void @filecopy(i32 0, i32 1)
br label %24
8: ; preds = %5, %22
%9 = phi i32 [ %11, %22 ], [ %0, %5 ]
%10 = phi i8** [ %12, %22 ], [ %1, %5 ]
%11 = add nsw i32 %9, -1
%12 = getelementptr inbounds i8*, i8** %10, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* %13, i32 %14, i32 0)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %8
%18 = load i8*, i8** %12
%19 = tail call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %18)
br label %22
20: ; preds = %8
tail call void @filecopy(i32 %15, i32 1)
%21 = tail call i32 @close(i32 %15)
br label %22
22: ; preds = %20, %17
%23 = icmp ugt i32 %9, 2
br i1 %23, label %8, label %24
24: ; preds = %22, %5, %7
ret i32 0
}