#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*/ WINDOW;

/* Variables and functions */
scalar_t__ OK;
int /*<<< orphan*/ TRUE;
scalar_t__ cbreak();
scalar_t__ erase();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ keypad(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ noecho();
scalar_t__ scrollok(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wtimeout(int /*<<< orphan*/ *, int /*<<< orphan*/);
int console_setup_window(WINDOW *w) {
  if (scrollok(w, 1) != OK) {
    fprintf(stderr, "Problem setting scrolling\n");
    return -1;
  }
  if (erase() != OK) {
    fprintf(stderr, "Problem erasing screen\n");
    return -1;
  }
  if (cbreak() != OK) {
    fprintf(stderr, "Error putting terminal in raw mode\n");
    return -1;
  }
  if (noecho() != OK) {
    fprintf(stderr, "Error setting noecho\n");
    return -1;
  }
  if (keypad(w, TRUE) != OK) {
    fprintf(stderr, "Error setting keypad options\n");
    return -1;
  }
  wtimeout(w, 0);
  return 0;
}


x86 assembly (clang, -O0):
<console_setup_window>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1080 <scrollok@plt>
mov    0x2e3f(%rip),%rcx
cmp    (%rcx),%rax
je     11bb <console_setup_window+0x4b>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b8 <console_setup_window+0x148>
mov    $0x0,%al
call   1050 <erase@plt>
mov    0x2e07(%rip),%rcx
cmp    (%rcx),%rax
je     11f3 <console_setup_window+0x83>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b8 <console_setup_window+0x148>
mov    $0x0,%al
call   1030 <cbreak@plt>
mov    0x2dcf(%rip),%rcx
cmp    (%rcx),%rax
je     122b <console_setup_window+0xbb>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b8 <console_setup_window+0x148>
mov    $0x0,%al
call   1090 <noecho@plt>
mov    0x2d97(%rip),%rcx
cmp    (%rcx),%rax
je     1263 <console_setup_window+0xf3>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b8 <console_setup_window+0x148>
mov    -0x10(%rbp),%rdi
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
call   1040 <keypad@plt>
mov    0x2d54(%rip),%rcx
cmp    (%rcx),%rax
je     12a6 <console_setup_window+0x136>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    0xdd8(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b8 <console_setup_window+0x148>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1060 <wtimeout@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<console_setup_window>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x1,%esi
call   1080 <scrollok@plt>
mov    0x2e49(%rip),%rbp
cmp    0x0(%rbp),%rax
jne    11d9 <console_setup_window+0x69>
xor    %eax,%eax
call   1050 <erase@plt>
cmp    0x0(%rbp),%rax
jne    11eb <console_setup_window+0x7b>
xor    %eax,%eax
call   1030 <cbreak@plt>
cmp    0x0(%rbp),%rax
jne    11fd <console_setup_window+0x8d>
xor    %eax,%eax
call   1090 <noecho@plt>
cmp    0x0(%rbp),%rax
jne    120f <console_setup_window+0x9f>
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <keypad@plt>
cmp    0x0(%rbp),%rax
jne    1221 <console_setup_window+0xb1>
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <wtimeout@plt>
jmp    123b <console_setup_window+0xcb>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
jmp    1231 <console_setup_window+0xc1>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
jmp    1231 <console_setup_window+0xc1>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
jmp    1231 <console_setup_window+0xc1>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
jmp    1231 <console_setup_window+0xc1>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@OK = global i64 0
@stderr = global i32 0
@.str = [27 x i8] c"Problem setting scrolling\0A\00"
@.str.1 = [24 x i8] c"Problem erasing screen\0A\00"
@.str.2 = [36 x i8] c"Error putting terminal in raw mode\0A\00"
@.str.3 = [22 x i8] c"Error setting noecho\0A\00"
@TRUE = global i32 0
@.str.4 = [30 x i8] c"Error setting keypad options\0A\00"
define i32 @console_setup_window(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
store i32* %0, i32** %3
%4 = load i32*, i32** %3
%5 = call i64 @scrollok(i32* %4, i32 1)
%6 = load i64, i64* @OK
%7 = icmp ne i64 %5, %6
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %44
11: ; preds = %1
%12 = call i64 (...) @erase()
%13 = load i64, i64* @OK
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %44
18: ; preds = %11
%19 = call i64 (...) @cbreak()
%20 = load i64, i64* @OK
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %44
25: ; preds = %18
%26 = call i64 (...) @noecho()
%27 = load i64, i64* @OK
%28 = icmp ne i64 %26, %27
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %44
32: ; preds = %25
%33 = load i32*, i32** %3
%34 = load i32, i32* @TRUE
%35 = call i64 @keypad(i32* %33, i32 %34)
%36 = load i64, i64* @OK
%37 = icmp ne i64 %35, %36
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %2
br label %44
41: ; preds = %32
%42 = load i32*, i32** %3
%43 = call i32 @wtimeout(i32* %42, i32 0)
store i32 0, i32* %2
br label %44
44: ; preds = %41, %38, %29, %22, %15, %8
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
@OK = global i64 0
@stderr = global i32 0
@.str = [27 x i8] c"Problem setting scrolling\0A\00"
@.str.1 = [24 x i8] c"Problem erasing screen\0A\00"
@.str.2 = [36 x i8] c"Error putting terminal in raw mode\0A\00"
@.str.3 = [22 x i8] c"Error setting noecho\0A\00"
@TRUE = global i32 0
@.str.4 = [30 x i8] c"Error setting keypad options\0A\00"
define i32 @console_setup_window(i32* %0) {
%2 = tail call i64 @scrollok(i32* %0, i32 1)
%3 = load i64, i64* @OK
%4 = icmp eq i64 %2, %3
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %39
8: ; preds = %1
%9 = tail call i64 (...) @erase()
%10 = load i64, i64* @OK
%11 = icmp eq i64 %9, %10
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %39
15: ; preds = %8
%16 = tail call i64 (...) @cbreak()
%17 = load i64, i64* @OK
%18 = icmp eq i64 %16, %17
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %39
22: ; preds = %15
%23 = tail call i64 (...) @noecho()
%24 = load i64, i64* @OK
%25 = icmp eq i64 %23, %24
br i1 %25, label %29, label %26
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %39
29: ; preds = %22
%30 = load i32, i32* @TRUE
%31 = tail call i64 @keypad(i32* %0, i32 %30)
%32 = load i64, i64* @OK
%33 = icmp eq i64 %31, %32
br i1 %33, label %37, label %34
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %39
37: ; preds = %29
%38 = tail call i32 @wtimeout(i32* %0, i32 0)
br label %39
39: ; preds = %37, %34, %26, %19, %12, %5
%40 = phi i32 [ -1, %5 ], [ -1, %12 ], [ -1, %19 ], [ -1, %26 ], [ -1, %34 ], [ 0, %37 ]
ret i32 %40
}