#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ run();
int /*<<< orphan*/ setup(int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  FILE *stream = stdin;
  int file_flag = 0;
  if (argc > 1) {
    stream = fopen(argv[1], "r");
    if (NULL != stream)
      file_flag = 1;
    else
      stream = stdin;
  }
  setup(stream);
  run();
  if (file_flag)
    fclose(stream);
  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)
mov    0x2e8b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11b8 <main+0x78>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7c(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     11a5 <main+0x65>
movl   $0x1,-0x1c(%rbp)
jmp    11b3 <main+0x73>
mov    0x2e3c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11b8 <main+0x78>
mov    -0x18(%rbp),%rdi
call   1060 <setup@plt>
mov    $0x0,%al
call   1040 <run@plt>
cmpl   $0x0,-0x1c(%rbp)
je     11db <main+0x9b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e9d(%rip),%r14
cmp    $0x2,%edi
jl     1171 <main+0x31>
mov    0x8(%rsi),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
sete   %bpl
jne    1177 <main+0x37>
mov    (%r14),%rbx
jmp    1177 <main+0x37>
mov    (%r14),%rbx
mov    $0x1,%bpl
mov    %rbx,%rdi
call   1060 <setup@plt>
xor    %eax,%eax
call   1040 <run@plt>
test   %bpl,%bpl
jne    1193 <main+0x53>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
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
%8 = load i32*, i32** @stdin
store i32* %8, i32** %6
store i32 0, i32* %7
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %22
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = icmp ne i32* null, %16
br i1 %17, label %18, label %19
18: ; preds = %11
store i32 1, i32* %7
br label %21
19: ; preds = %11
%20 = load i32*, i32** @stdin
store i32* %20, i32** %6
br label %21
21: ; preds = %19, %18
br label %22
22: ; preds = %21, %2
%23 = load i32*, i32** %6
%24 = call i32 @setup(i32* %23)
%25 = call i32 (...) @run()
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32*, i32** %6
%30 = call i32 @fclose(i32* %29)
br label %31
31: ; preds = %28, %22
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32*, i32** @stdin
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
%10 = load i32*, i32** @stdin
%11 = select i1 %9, i32* %10, i32* %8
br label %12
12: ; preds = %5, %2
%13 = phi i32* [ %3, %2 ], [ %11, %5 ]
%14 = phi i1 [ true, %2 ], [ %9, %5 ]
%15 = tail call i32 @setup(i32* %13)
%16 = tail call i32 (...) @run()
br i1 %14, label %19, label %17
17: ; preds = %12
%18 = tail call i32 @fclose(i32* %13)
br label %19
19: ; preds = %17, %12
ret i32 0
}