#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int STDIN_FILENO;
int /*<<< orphan*/ cat(int, int *);
int close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  int err = EXIT_SUCCESS, fd;
  if (argc == 1) {
    cat(STDIN_FILENO, &err);
  }
  for (argv++; *argv; argv++) {
    if (!strcmp(*argv, "-")) {
      cat(STDIN_FILENO, &err);
    } else {
      if ((fd = open(*argv, O_RDONLY)) == -1) {
        perror("cat: open");
        err = EXIT_FAILURE;
        continue;
      }
      cat(fd, &err);
      if (close(fd) == -1) {
        perror("cat: close");
        err = EXIT_FAILURE;
        continue;
      }
    }
  }
  return err;
}


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)
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    118e <main+0x3e>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
call   1070 <cat@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     126e <main+0x11e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe4a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11db <main+0x8b>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
call   1070 <cat@plt>
jmp    1258 <main+0x108>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1219 <main+0xc9>
lea    0xdff(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    125d <main+0x10d>
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1070 <cat@plt>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    1253 <main+0x103>
lea    0xdcf(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    125d <main+0x10d>
jmp    1258 <main+0x108>
jmp    125d <main+0x10d>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    119a <main+0x4a>
mov    -0x14(%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
mov    %rsi,%rbx
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
cmp    $0x1,%edi
jne    1183 <main+0x33>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rsp),%rsi
call   1070 <cat@plt>
mov    0x8(%rbx),%rbp
test   %rbp,%rbp
je     1224 <main+0xd4>
add    $0x10,%rbx
lea    0xe65(%rip),%r14
mov    0x2e26(%rip),%r12
lea    0x4(%rsp),%r15
mov    0x2e3a(%rip),%r13
jmp    11c8 <main+0x78>
mov    (%r12),%edi
mov    %r15,%rsi
call   1070 <cat@plt>
mov    (%rbx),%rbp
add    $0x8,%rbx
test   %rbp,%rbp
je     1224 <main+0xd4>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11b0 <main+0x60>
mov    0x0(%r13),%esi
mov    %rbp,%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1209 <main+0xb9>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r15,%rsi
call   1070 <cat@plt>
mov    %ebp,%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    11bc <main+0x6c>
lea    0xe05(%rip),%rdi
jmp    1210 <main+0xc0>
lea    0xdf2(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
jmp    11bc <main+0x6c>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
@STDIN_FILENO = global i32 0
@.str = [2 x i8] c"-\00"
@O_RDONLY = global i32 0
@.str.1 = [10 x i8] c"cat: open\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [11 x i8] c"cat: 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
%8 = load i32, i32* @EXIT_SUCCESS
store i32 %8, i32* %6
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @STDIN_FILENO
%13 = call i32 @cat(i32 %12, i32* %6)
br label %14
14: ; preds = %11, %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i32 1
store i8** %16, i8*** %5
br label %17
17: ; preds = %49, %14
%18 = load i8**, i8*** %5
%19 = load i8*, i8** %18
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %52
21: ; preds = %17
%22 = load i8**, i8*** %5
%23 = load i8*, i8** %22
%24 = call i32 @strcmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = load i32, i32* @STDIN_FILENO
%28 = call i32 @cat(i32 %27, i32* %6)
br label %48
29: ; preds = %21
%30 = load i8**, i8*** %5
%31 = load i8*, i8** %30
%32 = load i32, i32* @O_RDONLY
%33 = call i32 @open(i8* %31, i32 %32)
store i32 %33, i32* %7
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
store i32 %37, i32* %6
br label %49
38: ; preds = %29
%39 = load i32, i32* %7
%40 = call i32 @cat(i32 %39, i32* %6)
%41 = load i32, i32* %7
%42 = call i32 @close(i32 %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %38
%45 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
store i32 %46, i32* %6
br label %49
47: ; preds = %38
br label %48
48: ; preds = %47, %26
br label %49
49: ; preds = %48, %44, %35
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i32 1
store i8** %51, i8*** %5
br label %17
52: ; preds = %17
%53 = load i32, i32* %6
ret i32 %53
}

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