#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*/ cat(int, int);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char **argv) {
  int i;
  int input_fd;
  int output_fd = 1;
  if (argc < 2) {
    input_fd = 0;
    cat(input_fd, output_fd);
  } else {
    for (i = 1; i < argc; i++) {
      input_fd = open(argv[i], O_RDONLY, 0);
      if (input_fd < 0) {
        printf("Error opening %s\n", argv[i]);
        return -1;
      }
      cat(input_fd, output_fd);
      close(input_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)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    117e <main+0x3e>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1060 <cat@plt>
jmp    1204 <main+0xc4>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ff <main+0xbf>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11de <main+0x9e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe33(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <main+0xcb>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1060 <cat@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1185 <main+0x45>
jmp    1204 <main+0xc4>
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
jge    115d <main+0x1d>
xor    %ebx,%ebx
xor    %edi,%edi
mov    $0x1,%esi
call   1060 <cat@plt>
jmp    11ba <main+0x7a>
mov    %rsi,%r15
mov    %edi,%r14d
mov    $0x1,%ebx
mov    0x2e79(%rip),%r12
nop
mov    (%r15,%rbx,8),%rdi
mov    (%r12),%esi
xor    %edx,%edx
call   1050 <open@plt>
test   %eax,%eax
js     11a5 <main+0x65>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x1,%esi
call   1060 <cat@plt>
mov    %ebp,%edi
call   1040 <close@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1170 <main+0x30>
xor    %ebx,%ebx
jmp    11ba <main+0x7a>
mov    (%r15,%rbx,8),%rsi
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [18 x i8] c"Error opening %s\0A\00"
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 1, i32* %8
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %15
11: ; preds = %2
store i32 0, i32* %7
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = call i32 @cat(i32 %12, i32 %13)
br label %47
15: ; preds = %2
store i32 1, i32* %6
br label %16
16: ; preds = %43, %15
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %46
20: ; preds = %16
%21 = load i8**, i8*** %5
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%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* %7
%28 = load i32, i32* %7
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %20
%31 = load i8**, i8*** %5
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %35)
store i32 -1, i32* %3
br label %48
37: ; preds = %20
%38 = load i32, i32* %7
%39 = load i32, i32* %8
%40 = call i32 @cat(i32 %38, i32 %39)
%41 = load i32, i32* %7
%42 = call i32 @close(i32 %41)
br label %43
43: ; preds = %37
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %16
46: ; preds = %16
br label %47
47: ; preds = %46, %11
store i32 0, i32* %3
br label %48
48: ; preds = %47, %30
%49 = load i32, i32* %3
ret i32 %49
}

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