#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 open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  int fd1;
  void filecopy(int f, int t);
  if (argc == 1)
    filecopy(0, 1);
  else {
    while (--argc > 0)
      if ((fd1 = open(*++argv, O_RDONLY, 0)) == -1) {
        printf("unix cat: can't open %s\n", *argv);
        return 1;
      } else {
        filecopy(fd1, 1);
        close(fd1);
      }
  }
  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   1050 <filecopy@plt>
jmp    11f5 <main+0xb5>
jmp    1176 <main+0x36>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11f0 <main+0xb0>
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
xor    %edx,%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11d6 <main+0x96>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fc <main+0xbc>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1050 <filecopy@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
jmp    1176 <main+0x36>
jmp    11f5 <main+0xb5>
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   %rbx
push   %rax
cmp    $0x1,%edi
jne    115d <main+0x1d>
xor    %r14d,%r14d
xor    %edi,%edi
mov    $0x1,%esi
call   1050 <filecopy@plt>
jmp    11cd <main+0x8d>
mov    %edi,%ebp
xor    %r14d,%r14d
cmp    $0x2,%edi
jl     11cd <main+0x8d>
mov    %rsi,%r15
add    $0x1,%ebp
add    $0x8,%r15
mov    0x2e70(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    (%r15),%rdi
mov    (%r14),%esi
xor    %edx,%edx
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11b8 <main+0x78>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x1,%esi
call   1050 <filecopy@plt>
mov    %ebx,%edi
call   1040 <close@plt>
add    $0xffffffff,%ebp
add    $0x8,%r15
cmp    $0x2,%ebp
jg     1180 <main+0x40>
xor    %r14d,%r14d
jmp    11cd <main+0x8d>
mov    (%r15),%rsi
lea    0xe3e(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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