#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int getchar();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ putchar(int);
int main(int argc, char **argv) {
  int c = 0;
  FILE *fp = NULL;
  if (argc == 1) {
    while ((c = getchar()) != EOF)
      putchar(c);
    return 0;
  }
  while (argc-- > 1) {
    fp = fopen(*++argv, "r");
    if (fp == NULL) {
      perror("cat");
      return 1;
    }
    while ((c = getc(fp)) != EOF)
      putchar(c);
    fclose(fp);
  }
  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   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11c6 <main+0x66>
jmp    1194 <main+0x34>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e43(%rip),%rcx
cmp    (%rcx),%eax
je     11ba <main+0x5a>
mov    -0x14(%rbp),%edi
call   1030 <putchar@plt>
jmp    1194 <main+0x34>
movl   $0x0,-0x4(%rbp)
jmp    1267 <main+0x107>
jmp    11cb <main+0x6b>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x1,%eax
jle    1260 <main+0x100>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe07(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1225 <main+0xc5>
lea    0xdee(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1267 <main+0x107>
jmp    122a <main+0xca>
mov    -0x20(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dab(%rip),%rcx
cmp    (%rcx),%eax
je     1252 <main+0xf2>
mov    -0x14(%rbp),%edi
call   1030 <putchar@plt>
jmp    122a <main+0xca>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    11cb <main+0x6b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%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
cmp    $0x1,%edi
jne    11a7 <main+0x47>
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e67(%rip),%rbx
cmp    (%rbx),%eax
je     1227 <main+0xc7>
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%rbx),%eax
jne    1190 <main+0x30>
jmp    1227 <main+0xc7>
mov    %edi,%r12d
xor    %r14d,%r14d
cmp    $0x2,%edi
jl     1227 <main+0xc7>
mov    %rsi,%r13
mov    0x2e2c(%rip),%rbx
jmp    11da <main+0x7a>
xchg   %ax,%ax
lea    -0x1(%r12),%r15d
add    $0x8,%r13
mov    %rbp,%rdi
call   1040 <fclose@plt>
cmp    $0x2,%r12d
mov    %r15d,%r12d
jle    1227 <main+0xc7>
mov    0x8(%r13),%rdi
lea    0xe1b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1215 <main+0xb5>
mov    %rax,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1080 <getc@plt>
cmp    (%rbx),%eax
je     11c0 <main+0x60>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1200 <main+0xa0>
lea    0xde6(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"cat\00"
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 = icmp sgt i32 %0, 1
br i1 %5, label %16, label %39
6: ; preds = %2
%7 = tail call i32 (...) @getchar()
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %39, label %10
10: ; preds = %6, %10
%11 = phi i32 [ %13, %10 ], [ %7, %6 ]
%12 = tail call i32 @putchar(i32 %11)
%13 = tail call i32 (...) @getchar()
%14 = load i32, i32* @EOF
%15 = icmp eq i32 %13, %14
br i1 %15, label %39, label %10
16: ; preds = %4, %36
%17 = phi i32 [ %19, %36 ], [ %0, %4 ]
%18 = phi i8** [ %20, %36 ], [ %1, %4 ]
%19 = add nsw i32 %17, -1
%20 = getelementptr inbounds i8*, i8** %18, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %28, label %24
24: ; preds = %16
%25 = tail call i32 @getc(i32* %22)
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %36, label %30
28: ; preds = %16
%29 = tail call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %39
30: ; preds = %24, %30
%31 = phi i32 [ %33, %30 ], [ %25, %24 ]
%32 = tail call i32 @putchar(i32 %31)
%33 = tail call i32 @getc(i32* %22)
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %30
36: ; preds = %30, %24
%37 = tail call i32 @fclose(i32* %22)
%38 = icmp sgt i32 %17, 2
br i1 %38, label %16, label %39
39: ; preds = %36, %10, %4, %6, %28
%40 = phi i32 [ 1, %28 ], [ 0, %6 ], [ 0, %4 ], [ 0, %10 ], [ 0, %36 ]
ret i32 %40
}