#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 BUFSIZ;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  char buf[BUFSIZ];
  int fd, n;
  if (argc == 1) {
    n = read(0, buf, BUFSIZ);
    write(1, buf, n);
  }
  while (--argc > 0) {
    fd = open(*(++argv), O_RDONLY, 0);
    n = read(fd, buf, BUFSIZ);
    write(1, buf, n);
    close(fd);
  }
  return 0;
}


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    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11b4 <main+0x74>
mov    -0x30(%rbp),%rsi
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
xor    %edi,%edi
call   1050 <read@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    11b9 <main+0x79>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    1227 <main+0xe7>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <open@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
call   1050 <read@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
jmp    11b9 <main+0x79>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e83(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r14
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
cmp    $0x1,%edi
jne    1188 <main+0x48>
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <read@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    11e8 <main+0xa8>
jle    11e8 <main+0xa8>
mov    %rsi,%r15
mov    %edi,%ebx
add    $0x1,%ebx
add    $0x8,%r15
mov    0x2e4b(%rip),%r13
nopl   (%rax)
mov    (%r15),%rdi
mov    0x0(%r13),%esi
xor    %edx,%edx
call   1060 <open@plt>
mov    %eax,%r12d
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
mov    %r14,%rsi
call   1050 <read@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r12d,%edi
call   1040 <close@plt>
add    $0xffffffff,%ebx
add    $0x8,%r15
cmp    $0x2,%ebx
ja     11a0 <main+0x60>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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