#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_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ do_cat(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int fd;
  if (argc < 2) {
    do_cat(0);
    return 0;
  }
  for (int i = 1; i < argc; i++) {
    fd = open(argv[i], O_RDWR);
    if (fd < 0) {
      fprintf(stderr, "fopen error :%s\n", argv[i]);
      continue;
    }
    do_cat(fd);
    close(fd);
  }
}


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   $0x2,-0x8(%rbp)
jge    1173 <main+0x33>
xor    %edi,%edi
call   1030 <do_cat@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f1 <main+0xb1>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f1 <main+0xb1>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d3 <main+0x93>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe37(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11e3 <main+0xa3>
mov    -0x14(%rbp),%edi
call   1030 <do_cat@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117a <main+0x3a>
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    $0x2,%edi
jge    1168 <main+0x28>
xor    %edi,%edi
call   1030 <do_cat@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsi,%r12
mov    %edi,%r15d
mov    $0x1,%ebx
mov    0x2e6e(%rip),%r13
lea    0xe7f(%rip),%r14
jmp    11a9 <main+0x69>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <do_cat@plt>
mov    %ebp,%edi
call   1040 <close@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
je     1157 <main+0x17>
mov    (%r12,%rbx,8),%rdi
mov    0x0(%r13),%esi
call   1060 <open@plt>
test   %eax,%eax
jns    1190 <main+0x50>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    (%r12,%rbx,8),%rdx
mov    %r14,%rsi
call   1050 <fprintf@plt>
jmp    11a0 <main+0x60>

LLVM IR (-O0):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"fopen error :%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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @do_cat(i32 0)
store i32 0, i32* %3
br label %43
12: ; preds = %2
store i32 1, i32* %7
br label %13
13: ; preds = %40, %12
%14 = load i32, i32* %7
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %43
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDWR
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %17
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %5
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %40
35: ; preds = %17
%36 = load i32, i32* %6
%37 = call i32 @do_cat(i32 %36)
%38 = load i32, i32* %6
%39 = call i32 @close(i32 %38)
br label %40
40: ; preds = %35, %27
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %13
43: ; preds = %10, %13
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"fopen error :%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 @do_cat(i32 0)
br label %25
8: ; preds = %4, %22
%9 = phi i64 [ 1, %4 ], [ %23, %22 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDWR
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %10
%18 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %22
19: ; preds = %8
%20 = tail call i32 @do_cat(i32 %13)
%21 = tail call i32 @close(i32 %13)
br label %22
22: ; preds = %19, %15
%23 = add nuw nsw i64 %9, 1
%24 = icmp eq i64 %23, %5
br i1 %24, label %25, label %8
25: ; preds = %22, %6
ret i32 0
}