#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*/ catrw(int);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd;
  if (argc == 1)
    catrw(0);
  else {
    while (--argc && (fd = open(*++argv, O_RDWR))) {
      catrw(fd);
      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    115c <main+0x2c>
xor    %edi,%edi
call   1040 <catrw@plt>
jmp    11cf <main+0x9f>
jmp    1161 <main+0x31>
mov    -0x8(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x15(%rbp)
je     11a5 <main+0x75>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11b5 <main+0x85>
jmp    11ca <main+0x9a>
mov    -0x14(%rbp),%edi
call   1040 <catrw@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
jmp    1161 <main+0x31>
jmp    11cf <main+0x9f>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x1,%edi
jne    1146 <main+0x16>
xor    %edi,%edi
call   1040 <catrw@plt>
jmp    118a <main+0x5a>
mov    %rsi,%r15
mov    %edi,%r14d
mov    $0x1,%ebx
mov    0x2e90(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdi
mov    (%r12),%esi
call   1050 <open@plt>
test   %eax,%eax
je     118a <main+0x5a>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <catrw@plt>
mov    %ebp,%edi
call   1030 <close@plt>
add    $0x1,%rbx
cmp    %ebx,%r14d
jne    1160 <main+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @catrw(i32 0)
br label %31
11: ; preds = %2
br label %12
12: ; preds = %25, %11
%13 = load i32, i32* %4
%14 = add nsw i32 %13, -1
store i32 %14, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i32 1
store i8** %18, i8*** %5
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDWR
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %6
%22 = icmp ne i32 %21, 0
br label %23
23: ; preds = %16, %12
%24 = phi i1 [ false, %12 ], [ %22, %16 ]
br i1 %24, label %25, label %30
25: ; preds = %23
%26 = load i32, i32* %6
%27 = call i32 @catrw(i32 %26)
%28 = load i32, i32* %6
%29 = call i32 @close(i32 %28)
br label %12
30: ; preds = %23
br label %31
31: ; preds = %30, %9
ret i32 0
}

LLVM IR (-O2):
@O_RDWR = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = add nsw i32 %0, -1
br label %8
6: ; preds = %2
%7 = tail call i32 @catrw(i32 0)
br label %21
8: ; preds = %4, %16
%9 = phi i32 [ %19, %16 ], [ %5, %4 ]
%10 = phi i8** [ %11, %16 ], [ %1, %4 ]
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDWR
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %8
%17 = tail call i32 @catrw(i32 %14)
%18 = tail call i32 @close(i32 %14)
%19 = add nsw i32 %9, -1
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %8
21: ; preds = %16, %8, %6
ret i32 0
}