#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*/ TRUE;
int /*<<< orphan*/ cbreak();
int /*<<< orphan*/ clear();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ keypad(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ meta(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ newterm(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                           int /*<<< orphan*/ *);
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ raw();
int /*<<< orphan*/ set_term(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdscr;
void curses_start() {
  FILE *fd;
  if (!(fd = fopen("/dev/tty", "r+"))) {
    fprintf(stderr, "failed to open /dev/tty\n");
    exit(1);
  }
  set_term(newterm(NULL, fd, fd));
  cbreak();
  noecho();
  clear();
  raw();
  keypad(stdscr, TRUE);
  meta(stdscr, TRUE);
}


x86 assembly (clang, -O0):
<curses_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe41(%rip),%rdi
lea    0xe43(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    11f8 <curses_start+0x48>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%rsi
mov    -0x8(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
call   1070 <newterm@plt>
mov    %eax,%edi
call   1090 <set_term@plt>
mov    $0x0,%al
call   1030 <cbreak@plt>
mov    $0x0,%al
call   10b0 <noecho@plt>
mov    $0x0,%al
call   10d0 <clear@plt>
mov    $0x0,%al
call   1050 <raw@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
call   1040 <keypad@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    0x2d8d(%rip),%rax
mov    (%rax),%esi
call   1080 <meta@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<curses_start>:
push   %r14
push   %rbx
push   %rax
lea    0xe45(%rip),%rdi
lea    0xe47(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1225 <curses_start+0x75>
xor    %edi,%edi
mov    %rax,%rsi
mov    %rax,%rdx
call   1070 <newterm@plt>
mov    %eax,%edi
call   1090 <set_term@plt>
xor    %eax,%eax
call   1030 <cbreak@plt>
xor    %eax,%eax
call   10b0 <noecho@plt>
xor    %eax,%eax
call   10d0 <clear@plt>
xor    %eax,%eax
call   1050 <raw@plt>
mov    0x2de5(%rip),%r14
mov    (%r14),%edi
mov    0x2dd3(%rip),%rbx
mov    (%rbx),%esi
call   1040 <keypad@plt>
mov    (%r14),%edi
mov    (%rbx),%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <meta@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/tty\00"
@.str.1 = [3 x i8] c"r+\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"failed to open /dev/tty\0A\00"
@stdscr = global i32 0
@TRUE = global i32 0
define void @curses_start() {
%1 = alloca i32*
%2 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %2, i32** %1
%3 = icmp ne i32* %2, null
br i1 %3, label %8, label %4
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = load i32*, i32** %1
%10 = load i32*, i32** %1
%11 = call i32 @newterm(i32* null, i32* %9, i32* %10)
%12 = call i32 @set_term(i32 %11)
%13 = call i32 (...) @cbreak()
%14 = call i32 (...) @noecho()
%15 = call i32 (...) @clear()
%16 = call i32 (...) @raw()
%17 = load i32, i32* @stdscr
%18 = load i32, i32* @TRUE
%19 = call i32 @keypad(i32 %17, i32 %18)
%20 = load i32, i32* @stdscr
%21 = load i32, i32* @TRUE
%22 = call i32 @meta(i32 %20, i32 %21)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/tty\00"
@.str.1 = [3 x i8] c"r+\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"failed to open /dev/tty\0A\00"
@stdscr = global i32 0
@TRUE = global i32 0
define void @curses_start() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call i32 @newterm(i32* null, i32* %1, i32* %1)
%9 = tail call i32 @set_term(i32 %8)
%10 = tail call i32 (...) @cbreak()
%11 = tail call i32 (...) @noecho()
%12 = tail call i32 (...) @clear()
%13 = tail call i32 (...) @raw()
%14 = load i32, i32* @stdscr
%15 = load i32, i32* @TRUE
%16 = tail call i32 @keypad(i32 %14, i32 %15)
%17 = load i32, i32* @stdscr
%18 = load i32, i32* @TRUE
%19 = tail call i32 @meta(i32 %17, i32 %18)
ret void
}