#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int status;
  int fd;
  int i;
  for (i = 1; i < argc; i++) {
    char buffer[1024];
    fd = open(argv[i], O_RDONLY);
    if (fd < 0) {
      perror("open(2)");
      exit(EXIT_FAILURE);
    }
    while ((status = read(fd, buffer, sizeof(buffer))) > 0 &&
           write(1, buffer, status) == status)
      errno = 0;
    if (errno != 0) {
      perror("read(2)/write(2)");
      exit(EXIT_FAILURE);
    }
    (void)close(fd);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1283 <main+0x123>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11cd <main+0x6d>
lea    0xe46(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11d2 <main+0x72>
mov    -0x18(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x421(%rbp)
jle    121c <main+0xbc>
lea    -0x420(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
cmp    -0x14(%rbp),%eax
sete   %al
mov    %al,-0x421(%rbp)
mov    -0x421(%rbp),%al
test   $0x1,%al
jne    122f <main+0xcf>
jmp    1242 <main+0xe2>
mov    0x2da2(%rip),%rax
movq   $0x0,(%rax)
jmp    11d2 <main+0x72>
mov    0x2d8f(%rip),%rax
cmpq   $0x0,(%rax)
je     126d <main+0x10d>
lea    0xdae(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1180 <main+0x20>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,0x8(%rsp)
cmp    $0x2,%edi
jl     1216 <main+0xb6>
mov    %edi,%r12d
mov    $0x1,%r13d
lea    0x10(%rsp),%r15
mov    0x2e44(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x8(%rsp),%rax
mov    (%rax,%r13,8),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     1224 <main+0xc4>
mov    %eax,%ebp
nopl   (%rax)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1200 <main+0xa0>
mov    $0x1,%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    %ebx,%eax
jne    1200 <main+0xa0>
movq   $0x0,(%r14)
jmp    11c0 <main+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpq   $0x0,(%r14)
jne    122d <main+0xcd>
mov    %ebp,%edi
call   1040 <close@plt>
add    $0x1,%r13
cmp    %r12,%r13
jne    11a0 <main+0x40>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xdd5(%rip),%rdi
jmp    1234 <main+0xd4>
lea    0xdd4(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [8 x i8] c"open(2)\00"
@EXIT_FAILURE = global i32 0
@errno = global i64 0
@.str.1 = [17 x i8] c"read(2)/write(2)\00"
@EXIT_SUCCESS = 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
%9 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %8
br label %10
10: ; preds = %53, %2
%11 = load i32, i32* %8
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %56
14: ; preds = %10
%15 = load i8**, i8*** %5
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %14
%25 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %14
br label %29
29: ; preds = %42, %28
%30 = load i32, i32* %7
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%32 = call i32 @read(i32 %30, i8* %31, i32 1024)
store i32 %32, i32* %6
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %29
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%36 = load i32, i32* %6
%37 = call i32 @write(i32 1, i8* %35, i32 %36)
%38 = load i32, i32* %6
%39 = icmp eq i32 %37, %38
br label %40
40: ; preds = %34, %29
%41 = phi i1 [ false, %29 ], [ %39, %34 ]
br i1 %41, label %42, label %43
42: ; preds = %40
store i64 0, i64* @errno
br label %29
43: ; preds = %40
%44 = load i64, i64* @errno
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %43
%47 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %43
%51 = load i32, i32* %7
%52 = call i32 @close(i32 %51)
br label %53
53: ; preds = %50
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
br label %10
56: ; preds = %10
%57 = load i32, i32* @EXIT_SUCCESS
%58 = call i32 @exit(i32 %57)
unreachable
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [8 x i8] c"open(2)\00"
@EXIT_FAILURE = global i32 0
@errno = global i64 0
@.str.1 = [17 x i8] c"read(2)/write(2)\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %40
5: ; preds = %2
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %5, %36
%9 = phi i64 [ 1, %5 ], [ %38, %36 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %8
%16 = call i32 @read(i32 %13, i8* %6, i32 1024)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %22, label %29
18: ; preds = %8
%19 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %15, %26
%23 = phi i32 [ %27, %26 ], [ %16, %15 ]
%24 = call i32 @write(i32 1, i8* %6, i32 %23)
%25 = icmp eq i32 %24, %23
br i1 %25, label %26, label %29
26: ; preds = %22
store i64 0, i64* @errno
%27 = call i32 @read(i32 %13, i8* %6, i32 1024)
%28 = icmp sgt i32 %27, 0
br i1 %28, label %22, label %29
29: ; preds = %22, %26, %15
%30 = load i64, i64* @errno
%31 = icmp eq i64 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %29
%33 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = tail call i32 @exit(i32 %34)
unreachable
36: ; preds = %29
%37 = tail call i32 @close(i32 %13)
%38 = add nuw nsw i64 %9, 1
%39 = icmp eq i64 %38, %7
br i1 %39, label %40, label %8
40: ; preds = %36, %2
%41 = load i32, i32* @EXIT_SUCCESS
%42 = tail call i32 @exit(i32 %41)
unreachable
}