#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*/ O_RDONLY;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pe_active(int);
int /*<<< orphan*/ pe_exit(int);
int /*<<< orphan*/ pe_idle(int);
int pe_init();
size_t read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int /*<<< orphan*/, char *, size_t);
int main(int argc, char *argv[]) {
  int talpa;
  int fd;
  size_t size;
  char buffer[4096];
  int args = argc - 1;
  int ret;
  if ((talpa = pe_init()) < 0) {
    fprintf(stderr, "Failed to initialize!\n");
    return -1;
  }
  pe_active(talpa);
  while (args > 0) {
    fd = open(argv[args], O_RDONLY);
    if (fd > 0) {
      while ((size = read(fd, buffer, sizeof(buffer))) > 0) {
        ret = write(STDOUT_FILENO, buffer, size);
        if (ret != size) {
          fprintf(stderr, "Unable to write bytes to stdout");
        }
      }
      close(fd);
    } else {
      fprintf(stderr, "%s: %s!\n", argv[args], strerror(errno));
    }
    args--;
  }
  pe_idle(talpa);
  pe_exit(talpa);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1024(%rbp)
mov    $0x0,%al
call   1080 <pe_init@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11fb <main+0x5b>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1336 <main+0x196>
mov    -0x14(%rbp),%edi
call   10a0 <pe_active@plt>
cmpl   $0x0,-0x1024(%rbp)
jle    131f <main+0x17f>
mov    -0x10(%rbp),%rax
movslq -0x1024(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    12ba <main+0x11a>
jmp    123f <main+0x9f>
mov    -0x18(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jbe    12ad <main+0x10d>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,-0x1028(%rbp)
movslq -0x1028(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     12a8 <main+0x108>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
lea    0xd76(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    123f <main+0x9f>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
jmp    130b <main+0x16b>
mov    0x2d0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1034(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1024(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x1030(%rbp)
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x1034(%rbp),%edi
mov    -0x1030(%rbp),%rdx
mov    %rax,%rcx
lea    0xd33(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x1024(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1024(%rbp)
jmp    1203 <main+0x63>
mov    -0x14(%rbp),%edi
call   1040 <pe_idle@plt>
mov    -0x14(%rbp),%edi
call   10c0 <pe_exit@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
xor    %eax,%eax
call   1080 <pe_init@plt>
test   %eax,%eax
js     130a <main+0x16a>
mov    %rbp,0x18(%rsp)
mov    %eax,0x4(%rsp)
mov    %eax,%edi
call   10a0 <pe_active@plt>
cmp    $0x2,%ebx
jl     12f4 <main+0x154>
mov    %ebx,%eax
lea    0x20(%rsp),%r15
mov    0x2e04(%rip),%r14
mov    0x2ddd(%rip),%r13
jmp    121e <main+0x7e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
call   1050 <close@plt>
mov    0x10(%rsp),%rax
mov    0x8(%rsp),%rcx
cmp    $0x2,%rax
mov    %rcx,%rax
jle    12f4 <main+0x154>
mov    %r13,%rbp
mov    %rax,0x10(%rsp)
add    $0xffffffffffffffff,%rax
mov    %rax,0x8(%rsp)
mov    %eax,%r12d
mov    0x18(%rsp),%r13
mov    0x0(%r13,%r12,8),%rdi
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
jle    12c0 <main+0x120>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r15,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
test   %rax,%rax
mov    %rbp,%r13
lea    0xdab(%rip),%rbp
je     1200 <main+0x60>
mov    %rax,%r12
jmp    129b <main+0xfb>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %rax,%r12
test   %rax,%rax
je     1200 <main+0x60>
mov    (%r14),%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <write@plt>
cltq
cmp    %rax,%r12
je     1280 <main+0xe0>
mov    0x0(%r13),%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1280 <main+0xe0>
mov    0x0(%rbp),%ebx
mov    0x0(%r13,%r12,8),%r12
mov    %rbp,%r13
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %ebx,%edi
lea    0xd55(%rip),%rsi
mov    %r12,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1207 <main+0x67>
mov    0x4(%rsp),%ebx
mov    %ebx,%edi
call   1040 <pe_idle@plt>
mov    %ebx,%edi
call   10c0 <pe_exit@plt>
xor    %eax,%eax
jmp    1326 <main+0x186>
mov    0x2cbf(%rip),%rax
mov    (%rax),%edi
lea    0xce6(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x1028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Failed to initialize!\0A\00"
@O_RDONLY = global i32 0
@STDOUT_FILENO = global i32 0
@.str.1 = [32 x i8] c"Unable to write bytes to stdout\00"
@.str.2 = [9 x i8] c"%s: %s!\0A\00"
@errno = 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 i64
%9 = alloca [4096 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 1
store i32 %13, i32* %10
%14 = call i32 (...) @pe_init()
store i32 %14, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %75
19: ; preds = %2
%20 = load i32, i32* %6
%21 = call i32 @pe_active(i32 %20)
br label %22
22: ; preds = %67, %19
%23 = load i32, i32* %10
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %70
25: ; preds = %22
%26 = load i8**, i8*** %5
%27 = load i32, i32* %10
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = load i32, i32* @O_RDONLY
%32 = call i32 @open(i8* %30, i32 %31)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %57
35: ; preds = %25
br label %36
36: ; preds = %53, %35
%37 = load i32, i32* %7
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%39 = call i64 @read(i32 %37, i8* %38, i32 4096)
store i64 %39, i64* %8
%40 = icmp ugt i64 %39, 0
br i1 %40, label %41, label %54
41: ; preds = %36
%42 = load i32, i32* @STDOUT_FILENO
%43 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%44 = load i64, i64* %8
%45 = call i32 @write(i32 %42, i8* %43, i64 %44)
store i32 %45, i32* %11
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = load i64, i64* %8
%49 = icmp ne i64 %47, %48
br i1 %49, label %50, label %53
50: ; preds = %41
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %53
53: ; preds = %50, %41
br label %36
54: ; preds = %36
%55 = load i32, i32* %7
%56 = call i32 @close(i32 %55)
br label %67
57: ; preds = %25
%58 = load i32, i32* @stderr
%59 = load i8**, i8*** %5
%60 = load i32, i32* %10
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8*, i8** %59, i64 %61
%63 = load i8*, i8** %62
%64 = load i32, i32* @errno
%65 = call i8* @strerror(i32 %64)
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %63, i8* %65)
br label %67
67: ; preds = %57, %54
%68 = load i32, i32* %10
%69 = add nsw i32 %68, -1
store i32 %69, i32* %10
br label %22
70: ; preds = %22
%71 = load i32, i32* %6
%72 = call i32 @pe_idle(i32 %71)
%73 = load i32, i32* %6
%74 = call i32 @pe_exit(i32 %73)
store i32 0, i32* %3
br label %75
75: ; preds = %70, %16
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Failed to initialize!\0A\00"
@O_RDONLY = global i32 0
@STDOUT_FILENO = global i32 0
@.str.1 = [32 x i8] c"Unable to write bytes to stdout\00"
@.str.2 = [9 x i8] c"%s: %s!\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (...) @pe_init()
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %52
10: ; preds = %2
%11 = tail call i32 @pe_active(i32 %5)
%12 = icmp sgt i32 %0, 1
br i1 %12, label %13, label %49
13: ; preds = %10
%14 = zext i32 %0 to i64
br label %15
15: ; preds = %13, %47
%16 = phi i64 [ %14, %13 ], [ %17, %47 ]
%17 = add nsw i64 %16, -1
%18 = and i64 %17, 4294967295
%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)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %41
24: ; preds = %15
%25 = call i64 @read(i32 %22, i8* %4, i32 4096)
%26 = icmp eq i64 %25, 0
br i1 %26, label %39, label %27
27: ; preds = %24, %36
%28 = phi i64 [ %37, %36 ], [ %25, %24 ]
%29 = load i32, i32* @STDOUT_FILENO
%30 = call i32 @write(i32 %29, i8* %4, i64 %28)
%31 = sext i32 %30 to i64
%32 = icmp eq i64 %28, %31
br i1 %32, label %36, label %33
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %33, %27
%37 = call i64 @read(i32 %22, i8* %4, i32 4096)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %27
39: ; preds = %36, %24
%40 = tail call i32 @close(i32 %22)
br label %47
41: ; preds = %15
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %19
%44 = load i32, i32* @errno
%45 = tail call i8* @strerror(i32 %44)
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %43, i8* %45)
br label %47
47: ; preds = %41, %39
%48 = icmp sgt i64 %16, 2
br i1 %48, label %15, label %49
49: ; preds = %47, %10
%50 = tail call i32 @pe_idle(i32 %5)
%51 = tail call i32 @pe_exit(i32 %5)
br label %52
52: ; preds = %49, %7
%53 = phi i32 [ -1, %7 ], [ 0, %49 ]
ret i32 %53
}