#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*/ catFile(int);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int main(int argc, char *argv[]) {
  int inputYet = 0;
  int i;
  for (i = 1; i < argc; i++) {
    inputYet = 1;
    int fd = open(argv[i], O_RDONLY);
    if (fd == -1) {
      perror(argv[i]);
      return 1;
    };
    catFile(fd);
    close(fd);
  };
  if (!inputYet) {
    catFile(0);
  };
  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)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d9 <main+0x99>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11bb <main+0x7b>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f1 <main+0xb1>
mov    -0x1c(%rbp),%edi
call   1040 <catFile@plt>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1164 <main+0x24>
cmpl   $0x0,-0x14(%rbp)
jne    11ea <main+0xaa>
xor    %edi,%edi
call   1040 <catFile@plt>
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   %r12
push   %rbx
cmp    $0x2,%edi
jl     118f <main+0x4f>
mov    %rsi,%r14
mov    %edi,%r15d
mov    $0x1,%ebx
mov    0x2e89(%rip),%r12
nop
mov    (%r14,%rbx,8),%rdi
mov    (%r12),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11a3 <main+0x63>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <catFile@plt>
mov    %ebp,%edi
call   1030 <close@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <main+0x20>
xor    %ebx,%ebx
jmp    1198 <main+0x58>
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <catFile@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14,%rbx,8),%rdi
call   1060 <perror@plt>
mov    $0x1,%ebx
jmp    1198 <main+0x58>

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 1, i32* %7
br label %9
9: ; preds = %35, %2
%10 = load i32, i32* %7
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %38
13: ; preds = %9
store i32 1, i32* %6
%14 = load i8**, i8*** %5
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %30
23: ; preds = %13
%24 = load i8**, i8*** %5
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @perror(i8* %28)
store i32 1, i32* %3
br label %44
30: ; preds = %13
%31 = load i32, i32* %8
%32 = call i32 @catFile(i32 %31)
%33 = load i32, i32* %8
%34 = call i32 @close(i32 %33)
br label %35
35: ; preds = %30
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %9
38: ; preds = %9
%39 = load i32, i32* %6
%40 = icmp ne i32 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %38
%42 = call i32 @catFile(i32 0)
br label %43
43: ; preds = %41, %38
store i32 0, i32* %3
br label %44
44: ; preds = %43, %23
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %23
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %18
%7 = phi i64 [ 1, %4 ], [ %21, %18 ]
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %18
13: ; preds = %6
%14 = and i64 %7, 4294967295
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
%16 = load i8*, i8** %15
%17 = tail call i32 @perror(i8* %16)
br label %25
18: ; preds = %6
%19 = tail call i32 @catFile(i32 %11)
%20 = tail call i32 @close(i32 %11)
%21 = add nuw nsw i64 %7, 1
%22 = icmp eq i64 %21, %5
br i1 %22, label %25, label %6
23: ; preds = %2
%24 = tail call i32 @catFile(i32 0)
br label %25
25: ; preds = %18, %13, %23
%26 = phi i32 [ 0, %23 ], [ 1, %13 ], [ 0, %18 ]
ret i32 %26
}