#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, char);
scalar_t__ scanf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[], char *envp[]) {
  char c;
  int ret = 0;
  if (argc == 1) {
    while (scanf("%c", &c) != EOF)
      printf("%c", c);
  } else {
    int i;
    for (i = 1; i < argc; i++) {
      FILE *f = fopen(argv[i], "r");
      if (!f) {
        fprintf(stderr, "cat: can't open %s\n", argv[i]);
        ret = -1;
        continue;
      }
      while (fscanf(f, "%c", &c) != EOF)
        printf("%c", c);
      fclose(f);
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11ca <main+0x6a>
jmp    1190 <main+0x30>
lea    0xe69(%rip),%rdi
lea    -0x19(%rbp),%rsi
call   1070 <scanf@plt>
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%rax
je     11c5 <main+0x65>
lea    0xe49(%rip),%rdi
movsbl -0x19(%rbp),%esi
call   1040 <printf@plt>
jmp    1190 <main+0x30>
jmp    128b <main+0x12b>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1286 <main+0x126>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe13(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1231 <main+0xd1>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xde5(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x20(%rbp)
jmp    1278 <main+0x118>
jmp    1236 <main+0xd6>
mov    -0x30(%rbp),%rdi
lea    0xdbf(%rip),%rsi
lea    -0x19(%rbp),%rdx
call   1050 <fscanf@plt>
mov    0x2d97(%rip),%rcx
cmp    (%rcx),%rax
je     126f <main+0x10f>
lea    0xd9f(%rip),%rdi
movsbl -0x19(%rbp),%esi
call   1040 <printf@plt>
jmp    1236 <main+0xd6>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d1 <main+0x71>
jmp    128b <main+0x12b>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
jne    11d2 <main+0x72>
lea    0xe86(%rip),%rdi
lea    0xb(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x2e5d(%rip),%r14
movl   $0x0,0xc(%rsp)
cmp    (%r14),%rax
je     1294 <main+0x134>
lea    0xe5d(%rip),%rbx
lea    0xb(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
movsbl 0xb(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <scanf@plt>
cmp    (%r14),%rax
jne    11b0 <main+0x50>
jmp    1294 <main+0x134>
movl   $0x0,0xc(%rsp)
cmp    $0x2,%edi
jl     1294 <main+0x134>
mov    %rsi,%r13
mov    %edi,%eax
mov    %rax,0x10(%rsp)
movl   $0x0,0xc(%rsp)
mov    $0x1,%r12d
lea    0xdfe(%rip),%rbp
lea    0xb(%rsp),%rbx
mov    0x2dda(%rip),%r14
jmp    1223 <main+0xc3>
mov    %r15,%rdi
call   1030 <fclose@plt>
add    $0x1,%r12
cmp    0x10(%rsp),%r12
je     1294 <main+0x134>
mov    0x0(%r13,%r12,8),%rdi
lea    0xdd4(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1270 <main+0x110>
mov    %rax,%r15
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
cmp    (%r14),%rax
je     1210 <main+0xb0>
movsbl 0xb(%rsp),%esi
mov    %rbp,%rdi
call   1040 <printf@plt>
jmp    1240 <main+0xe0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13,%r12,8),%rdx
lea    0xd80(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,0xc(%rsp)
ff
jmp    1218 <main+0xb8>
mov    0xc(%rsp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@EOF = global i64 0
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"cat: can't open %s\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 0, i32* %9
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %23
14: ; preds = %3
br label %15
15: ; preds = %19, %14
%16 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
%17 = load i64, i64* @EOF
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i8, i8* %8
%21 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %20)
br label %15
22: ; preds = %15
br label %61
23: ; preds = %3
store i32 1, i32* %10
br label %24
24: ; preds = %57, %23
%25 = load i32, i32* %10
%26 = load i32, i32* %5
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %60
28: ; preds = %24
%29 = load i8**, i8*** %6
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %34, i32** %11
%35 = load i32*, i32** %11
%36 = icmp ne i32* %35, null
br i1 %36, label %45, label %37
37: ; preds = %28
%38 = load i32, i32* @stderr
%39 = load i8**, i8*** %6
%40 = load i32, i32* %10
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %43)
store i32 -1, i32* %9
br label %57
45: ; preds = %28
br label %46
46: ; preds = %51, %45
%47 = load i32*, i32** %11
%48 = call i64 @fscanf(i32* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
%49 = load i64, i64* @EOF
%50 = icmp ne i64 %48, %49
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = load i8, i8* %8
%53 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %52)
br label %46
54: ; preds = %46
%55 = load i32*, i32** %11
%56 = call i32 @fclose(i32* %55)
br label %57
57: ; preds = %54, %37
%58 = load i32, i32* %10
%59 = add nsw i32 %58, 1
store i32 %59, i32* %10
br label %24
60: ; preds = %24
br label %61
61: ; preds = %60, %22
%62 = load i32, i32* %9
ret i32 %62
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@EOF = global i64 0
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"cat: can't open %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1, i8** nocapture readnone %2) {
%4 = alloca i8
%5 = icmp eq i32 %0, 1
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %47
8: ; preds = %6
%9 = zext i32 %0 to i64
br label %20
10: ; preds = %3
%11 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%12 = load i64, i64* @EOF
%13 = icmp eq i64 %11, %12
br i1 %13, label %47, label %14
14: ; preds = %10, %14
%15 = load i8, i8* %4
%16 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %15)
%17 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%18 = load i64, i64* @EOF
%19 = icmp eq i64 %17, %18
br i1 %19, label %47, label %14
20: ; preds = %8, %43
%21 = phi i64 [ 1, %8 ], [ %45, %43 ]
%22 = phi i32 [ 0, %8 ], [ %44, %43 ]
%23 = getelementptr inbounds i8*, i8** %1, i64 %21
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %31, label %27
27: ; preds = %20
%28 = call i64 @fscanf(i32* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%29 = load i64, i64* @EOF
%30 = icmp eq i64 %28, %29
br i1 %30, label %41, label %35
31: ; preds = %20
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %23
%34 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %43
35: ; preds = %27, %35
%36 = load i8, i8* %4
%37 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %36)
%38 = call i64 @fscanf(i32* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%39 = load i64, i64* @EOF
%40 = icmp eq i64 %38, %39
br i1 %40, label %41, label %35
41: ; preds = %35, %27
%42 = call i32 @fclose(i32* %25)
br label %43
43: ; preds = %41, %31
%44 = phi i32 [ %22, %41 ], [ -1, %31 ]
%45 = add nuw nsw i64 %21, 1
%46 = icmp eq i64 %45, %9
br i1 %46, label %47, label %20
47: ; preds = %43, %14, %6, %10
%48 = phi i32 [ 0, %10 ], [ 0, %6 ], [ 0, %14 ], [ %44, %43 ]
ret i32 %48
}