#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 cat(int);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  int file, returnval;
  char **p;
  returnval = 0;
  if (argc == 1)
    return cat(0);
  for (p = argv + 1; *p != NULL; p++)
    if (!strcmp(*p, "-")) {
      if (cat(0))
        returnval = 1;
    } else if ((file = open(*p, O_RDONLY)) == -1)
      returnval = 1;
    else {
      if (cat(file))
        returnval = 1;
      close(file);
    }
  return returnval;
}


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   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1176 <main+0x36>
xor    %edi,%edi
call   1060 <cat@plt>
mov    %eax,-0x4(%rbp)
jmp    1236 <main+0xf6>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1230 <main+0xf0>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe62(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11c8 <main+0x88>
xor    %edi,%edi
call   1060 <cat@plt>
cmp    $0x0,%eax
je     11c3 <main+0x83>
movl   $0x1,-0x18(%rbp)
jmp    121a <main+0xda>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11f5 <main+0xb5>
movl   $0x1,-0x18(%rbp)
jmp    1215 <main+0xd5>
mov    -0x14(%rbp),%edi
call   1060 <cat@plt>
cmp    $0x0,%eax
je     120d <main+0xcd>
movl   $0x1,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
jmp    121a <main+0xda>
jmp    121f <main+0xdf>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    1182 <main+0x42>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
cmp    $0x1,%edi
jne    114c <main+0xc>
xor    %edi,%edi
jmp    1060 <cat@plt>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x8(%rsi),%rbp
test   %rbp,%rbp
je     11f8 <main+0xb8>
add    $0x10,%rbx
xor    %r15d,%r15d
lea    0xe8b(%rip),%r14
mov    $0x1,%r12d
mov    0x2e66(%rip),%r13
jmp    11a9 <main+0x69>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edi,%edi
call   1060 <cat@plt>
test   %eax,%eax
cmovne %r12d,%r15d
mov    (%rbx),%rbp
add    $0x8,%rbx
test   %rbp,%rbp
je     11fb <main+0xbb>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1190 <main+0x50>
mov    0x0(%r13),%esi
mov    %rbp,%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11f0 <main+0xb0>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <cat@plt>
test   %eax,%eax
cmovne %r12d,%r15d
mov    %ebp,%edi
call   1030 <close@plt>
jmp    119d <main+0x5d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%r15d
jmp    119d <main+0x5d>
xor    %r15d,%r15d
mov    %r15d,%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
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @cat(i32 0)
store i32 %12, i32* %3
br label %52
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
store i8** %15, i8*** %8
br label %16
16: ; preds = %47, %13
%17 = load i8**, i8*** %8
%18 = load i8*, i8** %17
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %50
20: ; preds = %16
%21 = load i8**, i8*** %8
%22 = load i8*, i8** %21
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %20
%26 = call i32 @cat(i32 0)
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 1, i32* %7
br label %29
29: ; preds = %28, %25
br label %46
30: ; preds = %20
%31 = load i8**, i8*** %8
%32 = load i8*, i8** %31
%33 = load i32, i32* @O_RDONLY
%34 = call i32 @open(i8* %32, i32 %33)
store i32 %34, i32* %6
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %37
36: ; preds = %30
store i32 1, i32* %7
br label %45
37: ; preds = %30
%38 = load i32, i32* %6
%39 = call i32 @cat(i32 %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
store i32 1, i32* %7
br label %42
42: ; preds = %41, %37
%43 = load i32, i32* %6
%44 = call i32 @close(i32 %43)
br label %45
45: ; preds = %42, %36
br label %46
46: ; preds = %45, %29
br label %47
47: ; preds = %46
%48 = load i8**, i8*** %8
%49 = getelementptr inbounds i8*, i8** %48, i32 1
store i8** %49, i8*** %8
br label %16
50: ; preds = %16
%51 = load i32, i32* %7
store i32 %51, i32* %3
br label %52
52: ; preds = %50, %11
%53 = load i32, i32* %3
ret i32 %53
}

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