#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 /*<<< orphan*/ do_cat(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  int i;
  if (argc == 1) {
    do_cat(stdin);
  } else {
    for (i = 1; i < argc; i++) {
      FILE *f;
      f = fopen(argv[i], "r");
      if (!f) {
        perror(argv[i]);
        exit(1);
      }
      do_cat(f);
      fclose(f);
    }
  }
  exit(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    1184 <main+0x34>
mov    0x2e71(%rip),%rax
mov    (%rax),%rdi
call   1030 <do_cat@plt>
jmp    11fe <main+0xae>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f9 <main+0xa9>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe56(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d9 <main+0x89>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1030 <do_cat@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118b <main+0x3b>
jmp    11fe <main+0xae>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x1,%edi
jne    1174 <main+0x24>
mov    0x2e83(%rip),%rax
mov    (%rax),%rdi
call   1030 <do_cat@plt>
xor    %edi,%edi
call   1070 <exit@plt>
jle    11bd <main+0x6d>
mov    %rsi,%r15
mov    %edi,%r12d
mov    $0x1,%r13d
lea    0xe77(%rip),%r14
nopl   0x0(%rax)
mov    (%r15,%r13,8),%rdi
mov    %r14,%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11c4 <main+0x74>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <do_cat@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x1,%r13
cmp    %r13,%r12
jne    1190 <main+0x40>
xor    %edi,%edi
call   1070 <exit@plt>
mov    (%r15,%r13,8),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
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 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %28
6: ; preds = %4
%7 = zext i32 %0 to i64
br label %11
8: ; preds = %2
%9 = load i32*, i32** @stdin
%10 = tail call i32 @do_cat(i32* %9)
br label %28
11: ; preds = %6, %23
%12 = phi i64 [ 1, %6 ], [ %26, %23 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = and i64 %12, 4294967295
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = tail call i32 @perror(i8* %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %11
%24 = tail call i32 @do_cat(i32* %15)
%25 = tail call i32 @fclose(i32* %15)
%26 = add nuw nsw i64 %12, 1
%27 = icmp eq i64 %26, %7
br i1 %27, label %28, label %11
28: ; preds = %23, %4, %8
%29 = tail call i32 @exit(i32 0)
unreachable
}