#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *, char *);
int /*<<< orphan*/ filecopy(int, int);
int open(char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd;
  if (argc == 1) {
    filecopy(0, 1);
  } else
    while (--argc > 0)
      if ((fd = open(*++argv, O_RDONLY)) == -1) {
        error("cat:can't open %s", *argv);
      } else {
        filecopy(fd, 1);
        close(fd);
      }
  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    1171 <main+0x31>
xor    %edi,%edi
mov    $0x1,%esi
call   1040 <filecopy@plt>
jmp    11ec <main+0xac>
jmp    1176 <main+0x36>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11e7 <main+0xa7>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11cd <main+0x8d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3d(%rip),%rdi
call   1050 <error@plt>
jmp    11e2 <main+0xa2>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1040 <filecopy@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
jmp    1176 <main+0x36>
jmp    11ec <main+0xac>
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    115b <main+0x1b>
xor    %edi,%edi
mov    $0x1,%esi
call   1040 <filecopy@plt>
jmp    11c1 <main+0x81>
jle    11c1 <main+0x81>
mov    %rsi,%rbx
mov    %edi,%r15d
add    $0x1,%r15d
add    $0x8,%rbx
mov    0x2e76(%rip),%r12
lea    0xe87(%rip),%r14
jmp    11a3 <main+0x63>
nopl   0x0(%rax,%rax,1)
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <filecopy@plt>
mov    %ebp,%edi
call   1030 <close@plt>
add    $0xffffffff,%r15d
add    $0x8,%rbx
cmp    $0x2,%r15d
jbe    11c1 <main+0x81>
mov    (%rbx),%rdi
mov    (%r12),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
jne    1180 <main+0x40>
mov    (%rbx),%rsi
mov    %r14,%rdi
call   1050 <error@plt>
jmp    1195 <main+0x55>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [18 x i8] c"cat:can't open %s\00"
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 %11
9: ; preds = %2
%10 = call i32 @filecopy(i32 0, i32 1)
br label %34
11: ; preds = %2
br label %12
12: ; preds = %32, %11
%13 = load i32, i32* %4
%14 = add nsw i32 %13, -1
store i32 %14, i32* %4
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %33
16: ; preds = %12
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i32 1
store i8** %18, i8*** %5
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %6
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = load i8*, i8** %24
%26 = call i32 @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %25)
br label %32
27: ; preds = %16
%28 = load i32, i32* %6
%29 = call i32 @filecopy(i32 %28, i32 1)
%30 = load i32, i32* %6
%31 = call i32 @close(i32 %30)
br label %32
32: ; preds = %27, %23
br label %12
33: ; preds = %12
br label %34
34: ; preds = %33, %9
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [18 x i8] c"cat:can't open %s\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 %8, label %25
6: ; preds = %2
%7 = tail call i32 @filecopy(i32 0, i32 1)
br label %25
8: ; preds = %4, %23
%9 = phi i32 [ %11, %23 ], [ %0, %4 ]
%10 = phi i8** [ %12, %23 ], [ %1, %4 ]
%11 = add nsw i32 %9, -1
%12 = getelementptr inbounds i8*, i8** %10, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %8
%18 = load i8*, i8** %12
%19 = tail call i32 @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %23
20: ; preds = %8
%21 = tail call i32 @filecopy(i32 %15, i32 1)
%22 = tail call i32 @close(i32 %15)
br label %23
23: ; preds = %20, %17
%24 = icmp ugt i32 %9, 2
br i1 %24, label %8, label %25
25: ; preds = %23, %4, %6
ret i32 0
}