#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*/ ERROR();
int /*<<< orphan*/ PROGRAM();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  if (argc > 1)
    do {
      if (freopen(argv[1], "r", stdin) == NULL)
        exit(1);
    } while (0);
  if (!PROGRAM())
    ERROR();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11a0 <main+0x60>
jmp    1165 <main+0x25>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e74(%rip),%rax
mov    (%rax),%edx
lea    0xe83(%rip),%rsi
call   1030 <freopen@plt>
cmp    $0x0,%rax
jne    1196 <main+0x56>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    119b <main+0x5b>
jmp    11a0 <main+0x60>
mov    $0x0,%al
call   1040 <PROGRAM@plt>
cmp    $0x0,%eax
jne    11b7 <main+0x77>
mov    $0x0,%al
call   1050 <ERROR@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x2,%edi
jl     1164 <main+0x24>
mov    0x8(%rsi),%rdi
mov    0x2e97(%rip),%rax
mov    (%rax),%edx
lea    0xea6(%rip),%rsi
call   1030 <freopen@plt>
test   %rax,%rax
je     117a <main+0x3a>
xor    %eax,%eax
call   1040 <PROGRAM@plt>
test   %eax,%eax
jne    1176 <main+0x36>
xor    %eax,%eax
call   1050 <ERROR@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp sgt i32 %6, 1
br i1 %7, label %8, label %20
8: ; preds = %2
br label %9
9: ; preds = %8
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @stdin
%14 = call i32* @freopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %9
br label %19
19: ; preds = %18
br label %20
20: ; preds = %19, %2
%21 = call i32 (...) @PROGRAM()
%22 = icmp ne i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = call i32 (...) @ERROR()
br label %25
25: ; preds = %23, %20
ret i32 0
}

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