#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ readfile(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *name;
  int fd;
  if (argc < 2)
    readfile("<stdin>", 0);
  else
    while ((name = *++argv) != NULL) {
      if ((fd = open(name, O_RDONLY)) >= 0) {
        readfile(name, fd);
        close(fd);
      } else {
        fprintf(stderr, "Can't open: %s\n", name);
      }
    }
  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)
cmpl   $0x2,-0x8(%rbp)
jge    1173 <main+0x33>
lea    0xe99(%rip),%rdi
xor    %esi,%esi
call   1060 <readfile@plt>
jmp    11f3 <main+0xb3>
jmp    1178 <main+0x38>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11ee <main+0xae>
mov    -0x18(%rbp),%rdi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     11d0 <main+0x90>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <readfile@plt>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
jmp    11e9 <main+0xa9>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe24(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1178 <main+0x38>
jmp    11f3 <main+0xb3>
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
jge    1160 <main+0x20>
lea    0xea9(%rip),%rdi
xor    %esi,%esi
call   1060 <readfile@plt>
jmp    11d0 <main+0x90>
mov    %rsi,%r15
mov    0x8(%rsi),%rbx
test   %rbx,%rbx
je     11d0 <main+0x90>
add    $0x10,%r15
mov    0x2e71(%rip),%r12
mov    0x2e5a(%rip),%r13
lea    0xe83(%rip),%r14
jmp    11ab <main+0x6b>
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    (%r15),%rbx
add    $0x8,%r15
test   %rbx,%rbx
je     11d0 <main+0x90>
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
js     1190 <main+0x50>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <readfile@plt>
mov    %ebp,%edi
call   1030 <close@plt>
jmp    119f <main+0x5f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"<stdin>\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"Can't open: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @readfile(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 0)
br label %35
12: ; preds = %2
br label %13
13: ; preds = %33, %12
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i32 1
store i8** %15, i8*** %5
%16 = load i8*, i8** %15
store i8* %16, i8** %6
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %34
18: ; preds = %13
%19 = load i8*, i8** %6
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %7
%22 = icmp sge i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = load i32, i32* %7
%26 = call i32 @readfile(i8* %24, i32 %25)
%27 = load i32, i32* %7
%28 = call i32 @close(i32 %27)
br label %33
29: ; preds = %18
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %6
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %29, %23
br label %13
34: ; preds = %13
br label %35
35: ; preds = %34, %10
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"<stdin>\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"Can't open: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %26, label %10
8: ; preds = %2
%9 = tail call i32 @readfile(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 0)
br label %26
10: ; preds = %4, %22
%11 = phi i8* [ %24, %22 ], [ %6, %4 ]
%12 = phi i8** [ %23, %22 ], [ %5, %4 ]
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %11, i32 %13)
%15 = icmp sgt i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = tail call i32 @readfile(i8* %11, i32 %14)
%18 = tail call i32 @close(i32 %14)
br label %22
19: ; preds = %10
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %22
22: ; preds = %19, %16
%23 = getelementptr inbounds i8*, i8** %12, i64 1
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %10
26: ; preds = %22, %4, %8
ret i32 0
}