#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 O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dump_file(int, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int j;
  for (j = 1; j < argc; ++j) {
    int fd = open(argv[j], O_RDONLY | 0);
    if (fd == -1)
      perror(argv[j]);
    else {
      dump_file(fd, stdout);
      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)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d5 <main+0x95>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
or     $0x0,%esi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11a9 <main+0x69>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <perror@plt>
jmp    11c2 <main+0x82>
mov    -0x18(%rbp),%edi
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
call   1030 <dump_file@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
jmp    11c7 <main+0x87>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115d <main+0x1d>
xor    %eax,%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
cmp    $0x2,%edi
jl     11ac <main+0x6c>
mov    %rsi,%r15
mov    %edi,%r14d
mov    $0x1,%ebx
mov    0x2e86(%rip),%r12
mov    0x2e6f(%rip),%r13
nopl   0x0(%rax)
mov    (%r15,%rbx,8),%rdi
mov    (%r12),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11a1 <main+0x61>
mov    %eax,%ebp
mov    0x0(%r13),%esi
mov    %eax,%edi
call   1030 <dump_file@plt>
mov    %ebp,%edi
call   1040 <close@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1170 <main+0x30>
jmp    11ac <main+0x6c>
mov    (%r15,%rbx,8),%rdi
call   1060 <perror@plt>
jmp    1196 <main+0x56>
xor    %eax,%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
@stdout = 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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
br label %8
8: ; preds = %37, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %40
12: ; preds = %8
%13 = load i8**, i8*** %5
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDONLY
%19 = or i32 %18, 0
%20 = call i32 @open(i8* %17, i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %30
23: ; preds = %12
%24 = load i8**, i8*** %5
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @perror(i8* %28)
br label %36
30: ; preds = %12
%31 = load i32, i32* %7
%32 = load i32, i32* @stdout
%33 = call i32 @dump_file(i32 %31, i32 %32)
%34 = load i32, i32* %7
%35 = call i32 @close(i32 %34)
br label %36
36: ; preds = %30, %23
br label %37
37: ; preds = %36
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %8
40: ; preds = %8
ret i32 0
}

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