#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*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putchar(int);
int serv_open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    fprintf(stderr, "Usage: %s filename1 [filename2] [filename3] ...\n",
            argv[0]);
    exit(EXIT_FAILURE);
  }
  int i;
  for (i = 1; i < argc; i++) {
    int fd = serv_open(argv[i], O_RDONLY);
    if (fd < 0) {
      fprintf(stderr, "Couldn't open %s: %s\n", argv[i], strerror(errno));
      continue;
    }
    FILE *fptr = fdopen(fd, "r");
    if (fptr == NULL) {
      fprintf(stderr, "Couldn't get file pointer for %s: %s\n", argv[i],
              strerror(errno));
      close(fd);
      continue;
    }
    int c;
    while ((c = getc(fptr)) != EOF)
      putchar(c);
    fclose(fptr);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11dc <main+0x4c>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    130e <main+0x17e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
call   1050 <serv_open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    125d <main+0xcd>
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1300 <main+0x170>
mov    -0x18(%rbp),%edi
lea    0xde0(%rip),%rsi
call   1080 <fdopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12ca <main+0x13a>
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xd93(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
jmp    1300 <main+0x170>
jmp    12cf <main+0x13f>
mov    -0x20(%rbp),%rdi
call   10b0 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2cfe(%rip),%rcx
cmp    (%rcx),%eax
je     12f7 <main+0x167>
mov    -0x24(%rbp),%edi
call   1030 <putchar@plt>
jmp    12cf <main+0x13f>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e3 <main+0x53>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
cmp    $0x2,%edi
jl     12c3 <main+0x133>
mov    %edi,%r12d
mov    $0x1,%r15d
mov    0x2e29(%rip),%r14
mov    %r12,(%rsp)
jmp    11d5 <main+0x45>
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x1,%r15
cmp    %r12,%r15
je     12b2 <main+0x122>
mov    0x0(%r13,%r15,8),%rdi
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
call   1050 <serv_open@plt>
test   %eax,%eax
js     1230 <main+0xa0>
mov    %eax,%ebp
mov    %eax,%edi
lea    0xe50(%rip),%rsi
call   1080 <fdopen@plt>
test   %rax,%rax
je     1270 <main+0xe0>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   10b0 <getc@plt>
cmp    (%r14),%eax
je     11c0 <main+0x30>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1210 <main+0x80>
cs nopw 0x0(%rax,%rax,1)
mov    0x2d99(%rip),%rax
mov    (%rax),%ebx
mov    0x0(%r13,%r15,8),%rbp
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %ebx,%edi
lea    0xddc(%rip),%rsi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    11c8 <main+0x38>
nopw   0x0(%rax,%rax,1)
mov    0x2d59(%rip),%rax
mov    (%rax),%ebx
mov    0x0(%r13,%r15,8),%r12
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %ebx,%edi
lea    0xdb4(%rip),%rsi
mov    %r12,%rdx
mov    (%rsp),%r12
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    11c8 <main+0x38>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xd29(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [49 x i8] c"Usage: %s filename1 [filename2] [filename3] ...\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [22 x i8] c"Couldn't open %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [38 x i8] c"Couldn't get file pointer for %s: %s\0A\00"
@EOF = 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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
store i32 1, i32* %6
br label %21
21: ; preds = %74, %20
%22 = load i32, i32* %6
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %77
25: ; preds = %21
%26 = load i8**, i8*** %5
%27 = load i32, i32* %6
%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 @serv_open(i8* %30, i32 %31)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %45
35: ; preds = %25
%36 = load i32, i32* @stderr
%37 = load i8**, i8*** %5
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %41, i8* %43)
br label %74
45: ; preds = %25
%46 = load i32, i32* %7
%47 = call i32* @fdopen(i32 %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %47, i32** %8
%48 = load i32*, i32** %8
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %62
50: ; preds = %45
%51 = load i32, i32* @stderr
%52 = load i8**, i8*** %5
%53 = load i32, i32* %6
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %56, i8* %58)
%60 = load i32, i32* %7
%61 = call i32 @close(i32 %60)
br label %74
62: ; preds = %45
br label %63
63: ; preds = %68, %62
%64 = load i32*, i32** %8
%65 = call i32 @getc(i32* %64)
store i32 %65, i32* %9
%66 = load i32, i32* @EOF
%67 = icmp ne i32 %65, %66
br i1 %67, label %68, label %71
68: ; preds = %63
%69 = load i32, i32* %9
%70 = call i32 @putchar(i32 %69)
br label %63
71: ; preds = %63
%72 = load i32*, i32** %8
%73 = call i32 @fclose(i32* %72)
br label %74
74: ; preds = %71, %50, %35
%75 = load i32, i32* %6
%76 = add nsw i32 %75, 1
store i32 %76, i32* %6
br label %21
77: ; preds = %21
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [49 x i8] c"Usage: %s filename1 [filename2] [filename3] ...\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [22 x i8] c"Couldn't open %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [38 x i8] c"Couldn't get file pointer for %s: %s\0A\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %12
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %4, %47
%13 = phi i64 [ 1, %4 ], [ %48, %47 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDONLY
%17 = tail call i32 @serv_open(i8* %15, i32 %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %14
%22 = load i32, i32* @errno
%23 = tail call i8* @strerror(i32 %22)
%24 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %23)
br label %47
25: ; preds = %12
%26 = tail call i32* @fdopen(i32 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = tail call i32 @getc(i32* %26)
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %45, label %39
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %14
%35 = load i32, i32* @errno
%36 = tail call i8* @strerror(i32 %35)
%37 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %34, i8* %36)
%38 = tail call i32 @close(i32 %17)
br label %47
39: ; preds = %28, %39
%40 = phi i32 [ %42, %39 ], [ %29, %28 ]
%41 = tail call i32 @putchar(i32 %40)
%42 = tail call i32 @getc(i32* %26)
%43 = load i32, i32* @EOF
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %39
45: ; preds = %39, %28
%46 = tail call i32 @fclose(i32* %26)
br label %47
47: ; preds = %32, %45, %19
%48 = add nuw nsw i64 %13, 1
%49 = icmp eq i64 %48, %5
br i1 %49, label %50, label %12
50: ; preds = %47
ret i32 0
}