#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*/ cat(int);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  int i, fd;
  if (argc < 2) {
    cat(0);
    return 0;
  }
  for (i = 1; i < argc; i++) {
    if ((fd = open(argv[i], 0, 0)) < 0) {
      printf("cat: cannot open %s\n", argv[i]);
      return 1;
    }
    cat(fd);
    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   $0x2,-0x8(%rbp)
jge    1173 <main+0x33>
xor    %edi,%edi
call   1060 <cat@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f0 <main+0xb0>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e9 <main+0xa9>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11cb <main+0x8b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f0 <main+0xb0>
mov    -0x18(%rbp),%edi
call   1060 <cat@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117a <main+0x3a>
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    $0x2,%edi
jge    1157 <main+0x17>
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <cat@plt>
jmp    11b3 <main+0x73>
mov    %rsi,%r15
mov    %edi,%r14d
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15,%rbx,8),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <open@plt>
test   %eax,%eax
js     119e <main+0x5e>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <cat@plt>
mov    %ebp,%edi
call   1040 <close@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1170 <main+0x30>
xor    %ebx,%ebx
jmp    11b3 <main+0x73>
mov    (%r15,%rbx,8),%rsi
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [21 x i8] c"cat: cannot open %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %8
6: ; preds = %2
%7 = tail call i32 @cat(i32 0)
br label %24
8: ; preds = %4, %19
%9 = phi i64 [ 1, %4 ], [ %22, %19 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = tail call i32 @open(i8* %11, i32 0, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %8
%15 = and i64 %9, 4294967295
%16 = getelementptr inbounds i8*, i8** %1, i64 %15
%17 = load i8*, i8** %16
%18 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %24
19: ; preds = %8
%20 = tail call i32 @cat(i32 %12)
%21 = tail call i32 @close(i32 %12)
%22 = add nuw nsw i64 %9, 1
%23 = icmp eq i64 %22, %5
br i1 %23, label %24, label %8
24: ; preds = %19, %14, %6
%25 = phi i32 [ 0, %6 ], [ 1, %14 ], [ 0, %19 ]
ret i32 %25
}