#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 read(int, int *, int);
int /*<<< orphan*/ write(int, int *, int);
int main(int argc, char **argv) {
  int fd;
  int c;
  if (argc == 1) {
    while (read(0, &c, 1) == 1)
      write(1, &c, 1);
  } else {
    for (int i = 1; i < argc; i++) {
      if ((fd = open(argv[i], O_RDONLY, 0)) == -1)
        return 1;
      while (read(fd, &c, 1) == 1)
        write(1, &c, 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    1198 <main+0x58>
jmp    1165 <main+0x25>
xor    %edi,%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jne    1193 <main+0x53>
mov    $0x1,%edx
lea    -0x18(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
jmp    1165 <main+0x25>
jmp    122e <main+0xee>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1229 <main+0xe9>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11df <main+0x9f>
movl   $0x1,-0x4(%rbp)
jmp    1235 <main+0xf5>
jmp    11e4 <main+0xa4>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jne    1213 <main+0xd3>
mov    $0x1,%edx
lea    -0x18(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
jmp    11e4 <main+0xa4>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119f <main+0x5f>
jmp    122e <main+0xee>
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   %r13
push   %r12
push   %rbx
push   %rax
xor    %r15d,%r15d
cmp    $0x1,%edi
jne    11ab <main+0x6b>
lea    0x4(%rsp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jne    122b <main+0xeb>
lea    0x4(%rsp),%rbx
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
je     1180 <main+0x40>
jmp    122b <main+0xeb>
cmp    $0x2,%edi
jl     122b <main+0xeb>
mov    %rsi,%r14
mov    %edi,%r12d
mov    $0x1,%r13d
lea    0x4(%rsp),%rbx
mov    $0x1,%r15d
jmp    11e0 <main+0xa0>
nopl   0x0(%rax)
mov    %ebp,%edi
call   1040 <close@plt>
add    $0x1,%r13
cmp    %r12,%r13
je     1228 <main+0xe8>
mov    (%r14,%r13,8),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     122b <main+0xeb>
mov    %eax,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jne    11d0 <main+0x90>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1200 <main+0xc0>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %18
11: ; preds = %2
br label %12
12: ; preds = %15, %11
%13 = call i32 @read(i32 0, i32* %7, i32 1)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @write(i32 1, i32* %7, i32 1)
br label %12
17: ; preds = %12
br label %47
18: ; preds = %2
store i32 1, i32* %8
br label %19
19: ; preds = %43, %18
%20 = load i32, i32* %8
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %46
23: ; preds = %19
%24 = load i8**, i8*** %5
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = load i32, i32* @O_RDONLY
%30 = call i32 @open(i8* %28, i32 %29, i32 0)
store i32 %30, i32* %6
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %23
store i32 1, i32* %3
br label %48
33: ; preds = %23
br label %34
34: ; preds = %38, %33
%35 = load i32, i32* %6
%36 = call i32 @read(i32 %35, i32* %7, i32 1)
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @write(i32 1, i32* %7, i32 1)
br label %34
40: ; preds = %34
%41 = load i32, i32* %6
%42 = call i32 @close(i32 %41)
br label %43
43: ; preds = %40
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %19
46: ; preds = %19
br label %47
47: ; preds = %46, %17
store i32 0, i32* %3
br label %48
48: ; preds = %47, %32
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 1
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %35
8: ; preds = %6
%9 = zext i32 %0 to i64
br label %17
10: ; preds = %2
%11 = call i32 @read(i32 0, i32* %3, i32 1)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %35
13: ; preds = %10, %13
%14 = call i32 @write(i32 1, i32* %3, i32 1)
%15 = call i32 @read(i32 0, i32* %3, i32 1)
%16 = icmp eq i32 %15, 1
br i1 %16, label %13, label %35
17: ; preds = %8, %31
%18 = phi i64 [ 1, %8 ], [ %33, %31 ]
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDONLY
%22 = tail call i32 @open(i8* %20, i32 %21, i32 0)
%23 = icmp eq i32 %22, -1
br i1 %23, label %35, label %24
24: ; preds = %17
%25 = call i32 @read(i32 %22, i32* %3, i32 1)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %31
27: ; preds = %24, %27
%28 = call i32 @write(i32 1, i32* %3, i32 1)
%29 = call i32 @read(i32 %22, i32* %3, i32 1)
%30 = icmp eq i32 %29, 1
br i1 %30, label %27, label %31
31: ; preds = %27, %24
%32 = tail call i32 @close(i32 %22)
%33 = add nuw nsw i64 %18, 1
%34 = icmp eq i64 %33, %9
br i1 %34, label %35, label %17
35: ; preds = %31, %17, %13, %6, %10
%36 = phi i32 [ 0, %10 ], [ 0, %6 ], [ 0, %13 ], [ 0, %31 ], [ 1, %17 ]
ret i32 %36
}