#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 */
#define KEY_DOWN 129
#define KEY_UP 128
int /*<<< orphan*/ draw_arrow(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ erase_arrow(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ erase_window(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ flushinp();
int /*<<< orphan*/ getch();
int /*<<< orphan*/ mvwaddstr(int /*<<< orphan*/ *, int /*<<< orphan*/,
                             int /*<<< orphan*/, char *);
int /*<<< orphan*/ mvwprintw(int /*<<< orphan*/ *, int, int, char *, int);
int /*<<< orphan*/ *newwin(int, int, int, int);
int /*<<< orphan*/ pressed(int, int);
int tolower(int /*<<< orphan*/);
int /*<<< orphan*/ wrefresh(int /*<<< orphan*/ *);
int level_select() {
  WINDOW *win = newwin(15, 37, 5, 43);
  int input;
  int active = 1;
  mvwaddstr(win, 0, 0, "Choose a level; press space or enter.");
  for (input = 1; input <= 13; input++) {
    mvwprintw(win, input, 2, "%d", input);
  }
  while (true) {
    draw_arrow(win, active, 0);
    wrefresh(win);
    input = tolower(getch());
    flushinp();
    switch (input) {
    case KEY_UP:
      erase_arrow(win, active, 0);
      if (active > 1) {
        active--;
        break;
      }
      active = 13;
      break;
    case KEY_DOWN:
      erase_arrow(win, active, 0);
      if (active < 13) {
        active++;
        break;
      }
      active = 1;
      break;
    default:
      if (input == '\n' || input == ' ') {
        erase_window(win, 15, 37);
        return active;
      } else if (pressed(10, input) || input == 27) {
        erase_window(win, 15, 37);
        return -1;
      }
      break;
    }
  }
}


x86 assembly (clang, -O0):
<level_select>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0xf,%edi
mov    $0x25,%esi
mov    $0x5,%edx
mov    $0x2b,%ecx
call   1040 <newwin@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
xor    %edx,%edx
lea    0xe17(%rip),%rcx
mov    %edx,%esi
call   10c0 <mvwaddstr@plt>
movl   $0x1,-0x14(%rbp)
cmpl   $0xd,-0x14(%rbp)
jg     122b <level_select+0x7b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%r8d
mov    $0x2,%edx
lea    0xe0e(%rip),%rcx
call   1080 <mvwprintw@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f7 <level_select+0x47>
jmp    1230 <level_select+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
xor    %edx,%edx
mov    %edx,-0x24(%rbp)
call   1050 <draw_arrow@plt>
mov    -0x10(%rbp),%rdi
call   1030 <wrefresh@plt>
mov    -0x24(%rbp),%eax
mov    %al,-0x1d(%rbp)
call   1070 <getch@plt>
mov    %eax,%edi
call   1060 <tolower@plt>
mov    %eax,%ecx
mov    -0x1d(%rbp),%al
mov    %ecx,-0x14(%rbp)
call   10b0 <flushinp@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x80,%eax
je     1292 <level_select+0xe2>
jmp    127f <level_select+0xcf>
mov    -0x1c(%rbp),%eax
sub    $0x81,%eax
je     12c4 <level_select+0x114>
jmp    12f6 <level_select+0x146>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
xor    %edx,%edx
call   1090 <erase_arrow@plt>
cmpl   $0x1,-0x18(%rbp)
jle    12b8 <level_select+0x108>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1371 <level_select+0x1c1>
movl   $0xd,-0x18(%rbp)
jmp    1371 <level_select+0x1c1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
xor    %edx,%edx
call   1090 <erase_arrow@plt>
cmpl   $0xd,-0x18(%rbp)
jge    12ea <level_select+0x13a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1371 <level_select+0x1c1>
movl   $0x1,-0x18(%rbp)
jmp    1371 <level_select+0x1c1>
cmpl   $0xa,-0x14(%rbp)
je     130a <level_select+0x15a>
cmpl   $0x20,-0x14(%rbp)
jne    1328 <level_select+0x178>
mov    -0x10(%rbp),%rdi
mov    $0xf,%esi
mov    $0x25,%edx
call   10a0 <erase_window@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1376 <level_select+0x1c6>
mov    -0x14(%rbp),%esi
mov    $0xa,%edi
call   10d0 <pressed@plt>
cmp    $0x0,%eax
jne    1348 <level_select+0x198>
cmpl   $0x1b,-0x14(%rbp)
jne    1367 <level_select+0x1b7>
mov    -0x10(%rbp),%rdi
mov    $0xf,%esi
mov    $0x25,%edx
call   10a0 <erase_window@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1376 <level_select+0x1c6>
jmp    136c <level_select+0x1bc>
jmp    1371 <level_select+0x1c1>
jmp    1230 <level_select+0x80>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<level_select>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xf,%edi
mov    $0x25,%esi
mov    $0x5,%edx
mov    $0x2b,%ecx
call   1040 <newwin@plt>
mov    %rax,%r15
lea    0xe22(%rip),%rcx
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <mvwaddstr@plt>
lea    0xe35(%rip),%r14
mov    $0x1,%r12d
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    %r14,%rcx
mov    $0x1,%r8d
call   1080 <mvwprintw@plt>
mov    %r15,%rdi
mov    $0x2,%esi
mov    $0x2,%edx
mov    %r14,%rcx
mov    $0x2,%r8d
call   1080 <mvwprintw@plt>
mov    %r15,%rdi
mov    $0x3,%esi
mov    $0x2,%edx
mov    %r14,%rcx
mov    $0x3,%r8d
call   1080 <mvwprintw@plt>
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x2,%edx
mov    %r14,%rcx
mov    $0x4,%r8d
call   1080 <mvwprintw@plt>
mov    %r15,%rdi
mov    $0x5,%esi
mov    $0x2,%edx
mov    %r14,%rcx
mov    $0x5,%r8d
call   1080 <mvwprintw@plt>
mov    %r15,%rdi
mov    $0x6,%esi
mov    $0x2,%edx
mov    %r14,%rcx
mov    $0x6,%r8d
call   1080 <mvwprintw@plt>
mov    %r15,%rdi
mov    $0x7,%esi
mov    $0x2,%edx
mov    %r14,%rcx
mov    $0x7,%r8d
call   1080 <mvwprintw@plt>
mov    %r15,%rdi
mov    $0x8,%esi
mov    $0x2,%edx
mov    %r14,%rcx
mov    $0x8,%r8d
call   1080 <mvwprintw@plt>
mov    %r15,%rdi
mov    $0x9,%esi
mov    $0x2,%edx
mov    %r14,%rcx
mov    $0x9,%r8d
call   1080 <mvwprintw@plt>
mov    %r15,%rdi
mov    $0xa,%esi
mov    $0x2,%edx
mov    %r14,%rcx
mov    $0xa,%r8d
call   1080 <mvwprintw@plt>
mov    %r15,%rdi
mov    $0xb,%esi
mov    $0x2,%edx
mov    %r14,%rcx
mov    $0xb,%r8d
call   1080 <mvwprintw@plt>
mov    %r15,%rdi
mov    $0xc,%esi
mov    $0x2,%edx
mov    %r14,%rcx
mov    $0xc,%r8d
call   1080 <mvwprintw@plt>
mov    $0xd,%r13d
mov    %r15,%rdi
mov    $0xd,%esi
mov    $0x2,%edx
mov    %r14,%rcx
mov    $0xd,%r8d
call   1080 <mvwprintw@plt>
mov    $0x1,%r14d
mov    $0xffffffff,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14d,%esi
xor    %edx,%edx
call   1050 <draw_arrow@plt>
mov    %r15,%rdi
call   1030 <wrefresh@plt>
xor    %eax,%eax
call   1070 <getch@plt>
mov    %eax,%edi
call   1060 <tolower@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   10b0 <flushinp@plt>
cmp    $0x7f,%ebp
jg     13b0 <level_select+0x200>
cmp    $0xa,%ebp
je     1419 <level_select+0x269>
cmp    $0x20,%ebp
jne    13c0 <level_select+0x210>
jmp    1419 <level_select+0x269>
nopl   (%rax)
cmp    $0x81,%ebp
je     13d7 <level_select+0x227>
cmp    $0x80,%ebp
je     13f8 <level_select+0x248>
mov    $0xa,%edi
mov    %ebp,%esi
call   10d0 <pressed@plt>
test   %eax,%eax
jne    141c <level_select+0x26c>
cmp    $0x1b,%ebp
jne    1370 <level_select+0x1c0>
jmp    141c <level_select+0x26c>
mov    %r15,%rdi
mov    %r14d,%esi
xor    %edx,%edx
call   1090 <erase_arrow@plt>
cmp    $0xd,%r14d
lea    0x1(%r14),%eax
cmovge %r12d,%eax
mov    %eax,%r14d
jmp    1370 <level_select+0x1c0>
mov    %r15,%rdi
mov    %r14d,%esi
xor    %edx,%edx
call   1090 <erase_arrow@plt>
cmp    $0x2,%r14d
lea    -0x1(%r14),%eax
cmovl  %r13d,%eax
mov    %eax,%r14d
jmp    1370 <level_select+0x1c0>
mov    %r14d,%ebx
mov    %r15,%rdi
mov    $0xf,%esi
mov    $0x25,%edx
call   10a0 <erase_window@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Choose a level; press space or enter.\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @level_select() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = call i32* @newwin(i32 15, i32 37, i32 5, i32 43)
store i32* %5, i32** %2
store i32 1, i32* %4
%6 = load i32*, i32** %2
%7 = call i32 @mvwaddstr(i32* %6, i32 0, i32 0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %8
8: ; preds = %16, %0
%9 = load i32, i32* %3
%10 = icmp sle i32 %9, 13
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i32*, i32** %2
%13 = load i32, i32* %3
%14 = load i32, i32* %3
%15 = call i32 @mvwprintw(i32* %12, i32 %13, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %11
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %8
19: ; preds = %8
br label %20
20: ; preds = %19, %72
%21 = load i32*, i32** %2
%22 = load i32, i32* %4
%23 = call i32 @draw_arrow(i32* %21, i32 %22, i32 0)
%24 = load i32*, i32** %2
%25 = call i32 @wrefresh(i32* %24)
%26 = call i32 (...) @getch()
%27 = call i32 @tolower(i32 %26)
store i32 %27, i32* %3
%28 = call i32 (...) @flushinp()
%29 = load i32, i32* %3
switch i32 %29, label %50 [
i32 128, label %30
i32 129, label %40
]
30: ; preds = %20
%31 = load i32*, i32** %2
%32 = load i32, i32* %4
%33 = call i32 @erase_arrow(i32* %31, i32 %32, i32 0)
%34 = load i32, i32* %4
%35 = icmp sgt i32 %34, 1
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = load i32, i32* %4
%38 = add nsw i32 %37, -1
store i32 %38, i32* %4
br label %72
39: ; preds = %30
store i32 13, i32* %4
br label %72
40: ; preds = %20
%41 = load i32*, i32** %2
%42 = load i32, i32* %4
%43 = call i32 @erase_arrow(i32* %41, i32 %42, i32 0)
%44 = load i32, i32* %4
%45 = icmp slt i32 %44, 13
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 1
store i32 %48, i32* %4
br label %72
49: ; preds = %40
store i32 1, i32* %4
br label %72
50: ; preds = %20
%51 = load i32, i32* %3
%52 = icmp eq i32 %51, 10
br i1 %52, label %56, label %53
53: ; preds = %50
%54 = load i32, i32* %3
%55 = icmp eq i32 %54, 32
br i1 %55, label %56, label %60
56: ; preds = %53, %50
%57 = load i32*, i32** %2
%58 = call i32 @erase_window(i32* %57, i32 15, i32 37)
%59 = load i32, i32* %4
store i32 %59, i32* %1
br label %73
60: ; preds = %53
%61 = load i32, i32* %3
%62 = call i32 @pressed(i32 10, i32 %61)
%63 = icmp ne i32 %62, 0
br i1 %63, label %67, label %64
64: ; preds = %60
%65 = load i32, i32* %3
%66 = icmp eq i32 %65, 27
br i1 %66, label %67, label %70
67: ; preds = %64, %60
%68 = load i32*, i32** %2
%69 = call i32 @erase_window(i32* %68, i32 15, i32 37)
store i32 -1, i32* %1
br label %73
70: ; preds = %64
br label %71
71: ; preds = %70
br label %72
72: ; preds = %71, %49, %46, %39, %36
br label %20
73: ; preds = %67, %56
%74 = load i32, i32* %1
ret i32 %74
}

LLVM IR (-O2):
@.str = [38 x i8] c"Choose a level; press space or enter.\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @level_select() {
%1 = tail call i32* @newwin(i32 15, i32 37, i32 5, i32 43)
%2 = tail call i32 @mvwaddstr(i32* %1, i32 0, i32 0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @mvwprintw(i32* %1, i32 1, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 1)
%4 = tail call i32 @mvwprintw(i32* %1, i32 2, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%5 = tail call i32 @mvwprintw(i32* %1, i32 3, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 3)
%6 = tail call i32 @mvwprintw(i32* %1, i32 4, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 4)
%7 = tail call i32 @mvwprintw(i32* %1, i32 5, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 5)
%8 = tail call i32 @mvwprintw(i32* %1, i32 6, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 6)
%9 = tail call i32 @mvwprintw(i32* %1, i32 7, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 7)
%10 = tail call i32 @mvwprintw(i32* %1, i32 8, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 8)
%11 = tail call i32 @mvwprintw(i32* %1, i32 9, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 9)
%12 = tail call i32 @mvwprintw(i32* %1, i32 10, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 10)
%13 = tail call i32 @mvwprintw(i32* %1, i32 11, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 11)
%14 = tail call i32 @mvwprintw(i32* %1, i32 12, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 12)
%15 = tail call i32 @mvwprintw(i32* %1, i32 13, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 13)
br label %16
16: ; preds = %29, %0
%17 = phi i32 [ 1, %0 ], [ %30, %29 ]
br label %18
18: ; preds = %16, %36
%19 = tail call i32 @draw_arrow(i32* %1, i32 %17, i32 0)
%20 = tail call i32 @wrefresh(i32* %1)
%21 = tail call i32 (...) @getch()
%22 = tail call i32 @tolower(i32 %21)
%23 = tail call i32 (...) @flushinp()
switch i32 %22, label %36 [
i32 128, label %24
i32 129, label %31
i32 32, label %41
i32 10, label %41
]
24: ; preds = %18
%25 = tail call i32 @erase_arrow(i32* %1, i32 %17, i32 0)
%26 = icmp sgt i32 %17, 1
%27 = add nsw i32 %17, -1
%28 = select i1 %26, i32 %27, i32 13
br label %29
29: ; preds = %24, %31
%30 = phi i32 [ %35, %31 ], [ %28, %24 ]
br label %16
31: ; preds = %18
%32 = tail call i32 @erase_arrow(i32* %1, i32 %17, i32 0)
%33 = icmp slt i32 %17, 13
%34 = add nsw i32 %17, 1
%35 = select i1 %33, i32 %34, i32 1
br label %29
36: ; preds = %18
%37 = tail call i32 @pressed(i32 10, i32 %22)
%38 = icmp ne i32 %37, 0
%39 = icmp eq i32 %22, 27
%40 = select i1 %38, i1 true, i1 %39
br i1 %40, label %41, label %18
41: ; preds = %36, %18, %18
%42 = phi i32 [ %17, %18 ], [ %17, %18 ], [ -1, %36 ]
%43 = tail call i32 @erase_window(i32* %1, i32 15, i32 37)
ret i32 %42
}