#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*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/);
int /*<<< orphan*/ fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ gui_term();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *strerror(int /*<<< orphan*/);
void input_reopen() {
  fclose(stdin);
  stdin = fopen("/dev/tty", "r");
  if (!stdin) {
    gui_term();
    fprintf(stderr, "uvi: freopen(\"/dev/tty\", \"r\", stdin) = %s\n",
            strerror(errno));
    exit(1);
  }
}


x86 assembly (clang, -O0):
<input_reopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
lea    0xe83(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1060 <fopen@plt>
mov    %eax,%ecx
mov    0x2e56(%rip),%rax
mov    %ecx,(%rax)
mov    0x2e4d(%rip),%rax
cmpl   $0x0,(%rax)
jne    11e1 <input_reopen+0x81>
mov    $0x0,%al
call   1050 <gui_term@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x4(%rbp),%edi
mov    %rax,%rdx
lea    0xe39(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<input_reopen>:
push   %rbx
mov    0x2e80(%rip),%rbx
mov    (%rbx),%edi
call   1030 <fclose@plt>
lea    0xe8a(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1060 <fopen@plt>
mov    %eax,(%rbx)
test   %eax,%eax
je     118a <input_reopen+0x2a>
pop    %rbx
ret
xor    %eax,%eax
call   1050 <gui_term@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%ebx
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe5c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [9 x i8] c"/dev/tty\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [43 x i8] c"uvi: freopen(\22/dev/tty\22, \22r\22, stdin) = %s\0A\00"
@errno = global i32 0
define void @input_reopen() {
%1 = load i32, i32* @stdin
%2 = call i32 @fclose(i32 %1)
%3 = call i32 @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 %3, i32* @stdin
%4 = load i32, i32* @stdin
%5 = icmp ne i32 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %0
%7 = call i32 (...) @gui_term()
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [9 x i8] c"/dev/tty\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [43 x i8] c"uvi: freopen(\22/dev/tty\22, \22r\22, stdin) = %s\0A\00"
@errno = global i32 0
define void @input_reopen() {
%1 = load i32, i32* @stdin
%2 = tail call i32 @fclose(i32 %1)
%3 = tail call i32 @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 %3, i32* @stdin
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %0
%6 = tail call i32 (...) @gui_term()
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %0
ret void
}