#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ copy(int, int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  if (argc == 1) {
    copy(0, 1);
  } else {
    int file_descriptor;
    while (--argc > 0) {
      if ((file_descriptor = open(*++argv, O_RDONLY, 0)) == -1) {
        printf("cat: can't open %s\n", *argv);
        return EXIT_FAILURE;
      } else {
        copy(file_descriptor, 1);
        close(file_descriptor);
      }
    }
  }
  return EXIT_SUCCESS;
}


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 <copy@plt>
jmp    11fa <main+0xba>
jmp    1176 <main+0x36>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11f5 <main+0xb5>
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    11db <main+0x9b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1206 <main+0xc6>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1050 <copy@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
jmp    1176 <main+0x36>
jmp    11fa <main+0xba>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%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    1162 <main+0x22>
xor    %edi,%edi
mov    $0x1,%esi
call   1050 <copy@plt>
mov    0x2e70(%rip),%r15
jmp    11cc <main+0x8c>
mov    0x2e67(%rip),%r15
jle    11cc <main+0x8c>
mov    %rsi,%r14
mov    %edi,%ebp
add    $0x1,%ebp
add    $0x8,%r14
mov    0x2e6a(%rip),%r12
xchg   %ax,%ax
mov    (%r14),%rdi
mov    (%r12),%esi
xor    %edx,%edx
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11b6 <main+0x76>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x1,%esi
call   1050 <copy@plt>
mov    %ebx,%edi
call   1040 <close@plt>
add    $0xffffffff,%ebp
add    $0x8,%r14
cmp    $0x2,%ebp
jg     1180 <main+0x40>
jmp    11cc <main+0x8c>
mov    (%r14),%rsi
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e0c(%rip),%r15
mov    (%r15),%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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