#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*/ close(int);
int open_file(char *);
int /*<<< orphan*/ output_file(int);
int main(int argc, char **argv) {
  int curr_input_fd;
  int arg_num;
  if (argc == 1)
    arg_num = 0;
  else
    arg_num = 1;
  while (arg_num < argc) {
    if (argc == 1)
      curr_input_fd = open_file("-");
    else
      curr_input_fd = open_file(argv[arg_num]);
    if (curr_input_fd >= 0) {
      output_file(curr_input_fd);
      close(curr_input_fd);
    }
    arg_num++;
  }
  close(1);
  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>
movl   $0x0,-0x18(%rbp)
jmp    1163 <main+0x33>
movl   $0x1,-0x18(%rbp)
jmp    1168 <main+0x38>
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ce <main+0x9e>
cmpl   $0x1,-0x8(%rbp)
jne    1192 <main+0x62>
lea    0xe7b(%rip),%rdi
call   1040 <open_file@plt>
mov    %eax,-0x14(%rbp)
jmp    11a6 <main+0x76>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <open_file@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11c0 <main+0x90>
mov    -0x14(%rbp),%edi
call   1030 <output_file@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1168 <main+0x38>
mov    $0x1,%edi
call   1050 <close@plt>
xor    %eax,%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
xor    %ebp,%ebp
cmp    $0x1,%edi
setne  %bpl
cmp    %edi,%ebp
jge    1191 <main+0x61>
mov    %rsi,%r14
mov    %edi,%r15d
mov    %edi,%r12d
lea    0xea8(%rip),%r13
jmp    1169 <main+0x39>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r12
je     1191 <main+0x61>
mov    %r13,%rdi
cmp    $0x1,%r15d
je     1176 <main+0x46>
mov    (%r14,%rbp,8),%rdi
call   1040 <open_file@plt>
test   %eax,%eax
js     1160 <main+0x30>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <output_file@plt>
mov    %ebx,%edi
call   1050 <close@plt>
jmp    1160 <main+0x30>
mov    $0x1,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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