#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ filecopy(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  FILE *fp;
  if (argc == 1) {
    filecopy(stdin, stdout);
  } else {
    while (--argc > 0) {
      if ((fp = fopen(*++argv, "r")) == NULL) {
        printf("cat: cannot open %s\n", *argv);
        exit(EXIT_FAILURE);
      } else {
        filecopy(fp, stdout);
        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)
cmpl   $0x1,-0x8(%rbp)
jne    118d <main+0x3d>
mov    0x2e71(%rip),%rax
mov    (%rax),%rdi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
call   1050 <filecopy@plt>
jmp    1217 <main+0xc7>
jmp    1192 <main+0x42>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    1212 <main+0xc2>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe42(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f2 <main+0xa2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe23(%rip),%rdi
call   1040 <printf@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
call   1050 <filecopy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1192 <main+0x42>
jmp    1217 <main+0xc7>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x1,%edi
jne    1177 <main+0x27>
mov    0x2e84(%rip),%rax
mov    (%rax),%rdi
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
call   1050 <filecopy@plt>
jmp    11d3 <main+0x83>
jle    11d3 <main+0x83>
mov    %rsi,%r15
mov    %edi,%ebp
add    $0x1,%ebp
add    $0x8,%r15
lea    0xe74(%rip),%r14
mov    0x2e3d(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11de <main+0x8e>
mov    %rax,%rbx
mov    (%r12),%esi
mov    %rax,%rdi
call   1050 <filecopy@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0xffffffff,%ebp
add    $0x8,%r15
cmp    $0x2,%ebp
jg     11a0 <main+0x50>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r15),%rsi
lea    0xe1a(%rip),%rdi
call   1040 <printf@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stdin = global i32* null
@stdout = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [21 x i8] c"cat: cannot open %s\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32*, i32** @stdin
%11 = load i32, i32* @stdout
%12 = call i32 @filecopy(i32* %10, i32 %11)
br label %38
13: ; preds = %2
br label %14
14: ; preds = %36, %13
%15 = load i32, i32* %4
%16 = add nsw i32 %15, -1
store i32 %16, i32* %4
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %37
18: ; preds = %14
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i32 1
store i8** %20, i8*** %5
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %6
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %30
24: ; preds = %18
%25 = load i8**, i8*** %5
%26 = load i8*, i8** %25
%27 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %18
%31 = load i32*, i32** %6
%32 = load i32, i32* @stdout
%33 = call i32 @filecopy(i32* %31, i32 %32)
%34 = load i32*, i32** %6
%35 = call i32 @fclose(i32* %34)
br label %36
36: ; preds = %30
br label %14
37: ; preds = %14
br label %38
38: ; preds = %37, %9
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32* null
@stdout = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [21 x i8] c"cat: cannot open %s\0A\00"
@EXIT_FAILURE = global i32 0
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 %10, label %28
6: ; preds = %2
%7 = load i32*, i32** @stdin
%8 = load i32, i32* @stdout
%9 = tail call i32 @filecopy(i32* %7, i32 %8)
br label %28
10: ; preds = %4, %22
%11 = phi i32 [ %23, %22 ], [ %0, %4 ]
%12 = phi i8** [ %13, %22 ], [ %1, %4 ]
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%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 %22
17: ; preds = %10
%18 = load i8*, i8** %13
%19 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %10
%23 = add nsw i32 %11, -1
%24 = load i32, i32* @stdout
%25 = tail call i32 @filecopy(i32* %15, i32 %24)
%26 = tail call i32 @fclose(i32* %15)
%27 = icmp sgt i32 %11, 2
br i1 %27, label %10, label %28
28: ; preds = %22, %4, %6
ret i32 0
}