#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 close(int);
int open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  int fd;
  for (int i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "-"))
      fd = 0;
    else
      fd = open(argv[i], O_RDONLY, 0666);
    if (fd != -1) {
      cat(fd);
      if (fd != 0 && close(fd) == -1)
        perror("close");
    } else
      perror(argv[i]);
  }
  if (argc == 1)
    cat(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   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    122a <main+0xda>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe74(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11a6 <main+0x56>
movl   $0x0,-0x14(%rbp)
jmp    11c8 <main+0x78>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
mov    $0x1b6,%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     1206 <main+0xb6>
mov    -0x14(%rbp),%edi
call   1070 <cat@plt>
cmpl   $0x0,-0x14(%rbp)
je     1201 <main+0xb1>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    1201 <main+0xb1>
lea    0xe06(%rip),%rdi
call   1060 <perror@plt>
jmp    1217 <main+0xc7>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <perror@plt>
jmp    121c <main+0xcc>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116d <main+0x1d>
cmpl   $0x1,-0x8(%rbp)
jne    123b <main+0xeb>
xor    %edi,%edi
call   1070 <cat@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
mov    %edi,0x4(%rsp)
cmp    $0x2,%edi
jl     11f5 <main+0xa5>
mov    %rsi,%rbx
mov    0x4(%rsp),%r13d
mov    $0x1,%r15d
lea    0xe83(%rip),%r12
mov    0x2e64(%rip),%r14
jmp    11a0 <main+0x50>
cs nopw 0x0(%rax,%rax,1)
xor    %edi,%edi
call   1070 <cat@plt>
add    $0x1,%r15
cmp    %r15,%r13
je     11f5 <main+0xa5>
mov    (%rbx,%r15,8),%rbp
mov    %rbp,%rdi
mov    %r12,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1190 <main+0x40>
mov    (%r14),%esi
mov    %rbp,%rdi
mov    $0x1b6,%edx
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11ea <main+0x9a>
mov    %eax,%ebp
mov    %eax,%edi
call   1070 <cat@plt>
test   %ebp,%ebp
je     1197 <main+0x47>
mov    %ebp,%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    1197 <main+0x47>
lea    0xe1a(%rip),%rdi
jmp    11ee <main+0x9e>
mov    (%rbx,%r15,8),%rdi
call   1060 <perror@plt>
jmp    1197 <main+0x47>
cmpl   $0x1,0x4(%rsp)
jne    1203 <main+0xb3>
xor    %edi,%edi
call   1070 <cat@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"
@O_RDONLY = global i32 0
@.str.1 = [6 x i8] c"close\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
store i32 1, i32* %7
br label %8
8: ; preds = %52, %2
%9 = load i32, i32* %7
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %55
12: ; preds = %8
%13 = load i8**, i8*** %5
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = call i32 @strcmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %12
store i32 0, i32* %6
br label %29
21: ; preds = %12
%22 = load i8**, i8*** %5
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* %26, i32 %27, i32 438)
store i32 %28, i32* %6
br label %29
29: ; preds = %21, %20
%30 = load i32, i32* %6
%31 = icmp ne i32 %30, -1
br i1 %31, label %32, label %44
32: ; preds = %29
%33 = load i32, i32* %6
%34 = call i32 @cat(i32 %33)
%35 = load i32, i32* %6
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %32
%38 = load i32, i32* %6
%39 = call i32 @close(i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %41, %37, %32
br label %51
44: ; preds = %29
%45 = load i8**, i8*** %5
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = call i32 @perror(i8* %49)
br label %51
51: ; preds = %44, %43
br label %52
52: ; preds = %51
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
br label %8
55: ; preds = %8
%56 = load i32, i32* %4
%57 = icmp eq i32 %56, 1
br i1 %57, label %58, label %60
58: ; preds = %55
%59 = call i32 @cat(i32 0)
br label %60
60: ; preds = %58, %55
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@O_RDONLY = global i32 0
@.str.1 = [6 x i8] c"close\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %8
6: ; preds = %31, %2
%7 = icmp eq i32 %0, 1
br i1 %7, label %34, label %36
8: ; preds = %4, %31
%9 = phi i64 [ 1, %4 ], [ %32, %31 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = tail call i32 @cat(i32 0)
br label %31
16: ; preds = %8
%17 = load i32, i32* @O_RDONLY
%18 = tail call i32 @open(i8* %11, i32 %17, i32 438)
%19 = icmp eq i32 %18, -1
br i1 %19, label %28, label %20
20: ; preds = %16
%21 = tail call i32 @cat(i32 %18)
%22 = icmp eq i32 %18, 0
br i1 %22, label %31, label %23
23: ; preds = %20
%24 = tail call i32 @close(i32 %18)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %31
28: ; preds = %16
%29 = load i8*, i8** %10
%30 = tail call i32 @perror(i8* %29)
br label %31
31: ; preds = %14, %28, %26, %23, %20
%32 = add nuw nsw i64 %9, 1
%33 = icmp eq i64 %32, %5
br i1 %33, label %6, label %8
34: ; preds = %6
%35 = tail call i32 @cat(i32 0)
br label %36
36: ; preds = %34, %6
ret i32 0
}