#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 /*<<< orphan*/ filecopy(int, int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int i, fd;
  if (argc == 1) {
    filecopy(0, 1);
    return 0;
  }
  for (i = 1; i < argc; i++) {
    if ((fd = open(argv[i], O_RDONLY, 0)) == -1) {
      error("[%s]: Could not open file %s, aborting...\n", argv[0], argv[i]);
    }
    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)
cmpl   $0x1,-0x8(%rbp)
jne    1178 <main+0x38>
xor    %edi,%edi
mov    $0x1,%esi
call   1040 <filecopy@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fc <main+0xbc>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f5 <main+0xb5>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    11d2 <main+0x92>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe33(%rip),%rdi
call   1050 <error@plt>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   1040 <filecopy@plt>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117f <main+0x3f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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    11c4 <main+0x84>
jle    11c4 <main+0x84>
mov    %rsi,%r12
mov    %edi,%r15d
mov    $0x1,%ebx
mov    0x2e76(%rip),%r13
lea    0xe87(%rip),%r14
jmp    119c <main+0x5c>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    $0x1,%esi
call   1040 <filecopy@plt>
mov    %ebp,%edi
call   1030 <close@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
je     11c4 <main+0x84>
mov    (%r12,%rbx,8),%rdi
mov    0x0(%r13),%esi
xor    %edx,%edx
call   1060 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1180 <main+0x40>
mov    (%r12),%rsi
mov    (%r12,%rbx,8),%rdx
mov    %r14,%rdi
call   1050 <error@plt>
jmp    1180 <main+0x40>
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 = [43 x i8] c"[%s]: Could not open file %s, aborting...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @filecopy(i32 0, i32 1)
store i32 0, i32* %3
br label %45
12: ; preds = %2
store i32 1, i32* %6
br label %13
13: ; preds = %41, %12
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %44
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%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* %7
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %36
26: ; preds = %17
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = load i8**, i8*** %5
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
%34 = load i8*, i8** %33
%35 = call i32 @error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %29, i8* %34)
br label %36
36: ; preds = %26, %17
%37 = load i32, i32* %7
%38 = call i32 @filecopy(i32 %37, i32 1)
%39 = load i32, i32* %7
%40 = call i32 @close(i32 %39)
br label %41
41: ; preds = %36
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %13
44: ; preds = %13
store i32 0, i32* %3
br label %45
45: ; preds = %44, %10
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [43 x i8] c"[%s]: Could not open file %s, aborting...\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %26
6: ; preds = %4
%7 = zext i32 %0 to i64
br label %10
8: ; preds = %2
%9 = tail call i32 @filecopy(i32 0, i32 1)
br label %26
10: ; preds = %6, %21
%11 = phi i64 [ 1, %6 ], [ %24, %21 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%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 %21
17: ; preds = %10
%18 = load i8*, i8** %1
%19 = load i8*, i8** %12
%20 = tail call i32 @error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %19)
br label %21
21: ; preds = %17, %10
%22 = tail call i32 @filecopy(i32 %15, i32 1)
%23 = tail call i32 @close(i32 %15)
%24 = add nuw nsw i64 %11, 1
%25 = icmp eq i64 %24, %7
br i1 %25, label %26, label %10
26: ; preds = %21, %4, %8
ret i32 0
}