#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 /*<<< orphan*/ O_RDONLY;
int STDIN_FILENO;
int cat(int, char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, char *);
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv, char **envp) {
  int err, fd, i;
  if (argc <= 1)
    err = cat(STDIN_FILENO, "stdin");
  for (i = 1; i < argc; i++) {
    fd = open(argv[i], O_RDONLY);
    if (fd < 0) {
      printf("cat: %s: %s\n", argv[i], strerror(errno));
      err = EXIT_FAILURE;
    } else {
      err = cat(fd, argv[i]);
    }
    close(fd);
  }
  return err;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     118c <main+0x3c>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1070 <cat@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1235 <main+0xe5>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1208 <main+0xb8>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
lea    0xe14(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    121f <main+0xcf>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1070 <cat@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1193 <main+0x43>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     1183 <main+0x33>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <cat@plt>
mov    %rsi,%r15
mov    %edi,%r12d
mov    $0x1,%ebx
mov    0x2e53(%rip),%r14
jmp    11bd <main+0x6d>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r13,%rsi
call   1070 <cat@plt>
mov    %eax,%r13d
mov    %ebp,%edi
call   1040 <close@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
je     11ff <main+0xaf>
mov    (%r15,%rbx,8),%rdi
mov    (%r14),%esi
call   1050 <open@plt>
mov    %eax,%ebp
mov    (%r15,%rbx,8),%r13
test   %eax,%eax
jns    11a0 <main+0x50>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe1e(%rip),%rdi
mov    %r13,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%r13d
jmp    11ad <main+0x5d>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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