#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 KEY_DOWN;
int KEY_UP;
int getch();
int /*<<< orphan*/ mvaddch(int, int /*<<< orphan*/, char);
int /*<<< orphan*/ mvprintw(int, int, char *);
int /*<<< orphan*/ printw(char *);
int /*<<< orphan*/ refresh();
void main_menu(unsigned char *currow) {
  int key = 0;
  printw("=== MAIN MENU ===");
  mvprintw(2, 1, "1: New Game");
  mvprintw(3, 1, "2: Load Game");
  mvprintw(4, 1, "3: Quit Game");
  while (key != '\n' && key != '\r') {
    if (*currow == 1) {
      mvaddch(2, 0, '>');
      mvaddch(3, 0, ' ');
      mvaddch(4, 0, ' ');
      refresh();
    } else if (*currow == 2) {
      mvaddch(2, 0, ' ');
      mvaddch(3, 0, '>');
      mvaddch(4, 0, ' ');
      refresh();
    } else if (*currow == 3) {
      mvaddch(2, 0, ' ');
      mvaddch(3, 0, ' ');
      mvaddch(4, 0, '>');
      refresh();
    }
    key = getch();
    if (key == KEY_UP && *currow != 1)
      (*currow)--;
    else if (key == KEY_UP && *currow == 1)
      *currow = 3;
    else if (key == KEY_DOWN && *currow != 3)
      (*currow)++;
    else if (key == KEY_DOWN && *currow == 3)
      *currow = 1;
  }
  return;
}


x86 assembly (clang, -O0):
<main_menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe96(%rip),%rdi
call   1030 <printw@plt>
mov    $0x2,%edi
mov    $0x1,%esi
lea    0xe92(%rip),%rdx
call   1070 <mvprintw@plt>
mov    $0x3,%edi
mov    $0x1,%esi
lea    0xe88(%rip),%rdx
call   1070 <mvprintw@plt>
mov    $0x4,%edi
mov    $0x1,%esi
lea    0xe7f(%rip),%rdx
call   1070 <mvprintw@plt>
xor    %eax,%eax
cmpl   $0xa,-0xc(%rbp)
mov    %al,-0xd(%rbp)
je     11ca <main_menu+0x7a>
cmpl   $0xd,-0xc(%rbp)
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    11da <main_menu+0x8a>
jmp    13a5 <main_menu+0x255>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x1,%eax
jne    1229 <main_menu+0xd9>
mov    $0x2,%edi
xor    %esi,%esi
mov    $0x3e,%edx
call   1060 <mvaddch@plt>
mov    $0x3,%edi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <mvaddch@plt>
mov    $0x4,%edi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <mvaddch@plt>
mov    $0x0,%al
call   1040 <refresh@plt>
jmp    12cc <main_menu+0x17c>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x2,%eax
jne    1278 <main_menu+0x128>
mov    $0x2,%edi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <mvaddch@plt>
mov    $0x3,%edi
xor    %esi,%esi
mov    $0x3e,%edx
call   1060 <mvaddch@plt>
mov    $0x4,%edi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <mvaddch@plt>
mov    $0x0,%al
call   1040 <refresh@plt>
jmp    12c7 <main_menu+0x177>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x3,%eax
jne    12c2 <main_menu+0x172>
mov    $0x2,%edi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <mvaddch@plt>
mov    $0x3,%edi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <mvaddch@plt>
mov    $0x4,%edi
xor    %esi,%esi
mov    $0x3e,%edx
call   1060 <mvaddch@plt>
mov    $0x0,%al
call   1040 <refresh@plt>
jmp    12c7 <main_menu+0x177>
jmp    12cc <main_menu+0x17c>
mov    $0x0,%al
call   1050 <getch@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2d00(%rip),%rcx
cmp    (%rcx),%eax
jne    1308 <main_menu+0x1b8>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x1,%eax
je     1308 <main_menu+0x1b8>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
add    $0xff,%cl
mov    %cl,(%rax)
jmp    13a0 <main_menu+0x250>
mov    -0xc(%rbp),%eax
mov    0x2cce(%rip),%rcx
cmp    (%rcx),%eax
jne    1336 <main_menu+0x1e6>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x1,%eax
jne    1336 <main_menu+0x1e6>
mov    -0x8(%rbp),%rax
movb   $0x3,(%rax)
jmp    139b <main_menu+0x24b>
mov    -0xc(%rbp),%eax
mov    0x2ca8(%rip),%rcx
cmp    (%rcx),%eax
jne    1368 <main_menu+0x218>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x3,%eax
je     1368 <main_menu+0x218>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
add    $0x1,%cl
mov    %cl,(%rax)
jmp    1396 <main_menu+0x246>
mov    -0xc(%rbp),%eax
mov    0x2c76(%rip),%rcx
cmp    (%rcx),%eax
jne    1391 <main_menu+0x241>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x3,%eax
jne    1391 <main_menu+0x241>
mov    -0x8(%rbp),%rax
movb   $0x1,(%rax)
jmp    1396 <main_menu+0x246>
jmp    139b <main_menu+0x24b>
jmp    13a0 <main_menu+0x250>
jmp    11b1 <main_menu+0x61>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main_menu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe9b(%rip),%rdi
call   1030 <printw@plt>
lea    0xea1(%rip),%rdx
mov    $0x2,%edi
mov    $0x1,%esi
call   1070 <mvprintw@plt>
lea    0xe97(%rip),%rdx
mov    $0x3,%r15d
mov    $0x3,%edi
mov    $0x1,%esi
call   1070 <mvprintw@plt>
lea    0xe88(%rip),%rdx
mov    $0x4,%edi
mov    $0x1,%esi
call   1070 <mvprintw@plt>
mov    0x2e27(%rip),%r13
mov    0x2e28(%rip),%r12
xor    %eax,%eax
jmp    11e2 <main_menu+0x92>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rbx),%ecx
lea    -0x1(%rcx),%edx
cmp    $0x1,%cl
movzbl %dl,%ecx
cmove  %r15d,%ecx
mov    %cl,(%rbx)
cmp    $0xa,%eax
je     1286 <main_menu+0x136>
cmp    $0xd,%eax
je     1286 <main_menu+0x136>
movzbl (%rbx),%eax
add    $0xff,%al
cmp    $0x2,%al
ja     1250 <main_menu+0x100>
movzbl %al,%ecx
shl    $0x3,%ecx
mov    $0x20203e,%eax
shr    %cl,%eax
mov    $0x203e20,%ebp
shr    %cl,%ebp
mov    $0x3e2020,%r14d
shr    %cl,%r14d
movsbl %al,%edx
mov    $0x2,%edi
xor    %esi,%esi
call   1060 <mvaddch@plt>
movsbl %bpl,%edx
mov    $0x3,%edi
xor    %esi,%esi
call   1060 <mvaddch@plt>
movsbl %r14b,%edx
mov    $0x4,%edi
xor    %esi,%esi
call   1060 <mvaddch@plt>
xor    %eax,%eax
call   1040 <refresh@plt>
xor    %eax,%eax
call   1050 <getch@plt>
cmp    0x0(%r13),%eax
je     11d0 <main_menu+0x80>
cmp    (%r12),%eax
jne    11e2 <main_menu+0x92>
movzbl (%rbx),%ecx
lea    0x1(%rcx),%edx
cmp    $0x3,%cl
movzbl %dl,%ecx
mov    $0x1,%edx
cmove  %edx,%ecx
mov    %cl,(%rbx)
jmp    11e2 <main_menu+0x92>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"=== MAIN MENU ===\00"
@.str.1 = [12 x i8] c"1: New Game\00"
@.str.2 = [13 x i8] c"2: Load Game\00"
@.str.3 = [13 x i8] c"3: Quit Game\00"
@KEY_UP = global i32 0
@KEY_DOWN = global i32 0
define void @main_menu(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%4 = call i32 @printw(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @mvprintw(i32 2, i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @mvprintw(i32 3, i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @mvprintw(i32 4, i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %8
8: ; preds = %100, %1
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 10
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 13
br label %14
14: ; preds = %11, %8
%15 = phi i1 [ false, %8 ], [ %13, %11 ]
br i1 %15, label %16, label %101
16: ; preds = %14
%17 = load i8*, i8** %2
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = call i32 @mvaddch(i32 2, i32 0, i8 signext 62)
%23 = call i32 @mvaddch(i32 3, i32 0, i8 signext 32)
%24 = call i32 @mvaddch(i32 4, i32 0, i8 signext 32)
%25 = call i32 (...) @refresh()
br label %48
26: ; preds = %16
%27 = load i8*, i8** %2
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = icmp eq i32 %29, 2
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = call i32 @mvaddch(i32 2, i32 0, i8 signext 32)
%33 = call i32 @mvaddch(i32 3, i32 0, i8 signext 62)
%34 = call i32 @mvaddch(i32 4, i32 0, i8 signext 32)
%35 = call i32 (...) @refresh()
br label %47
36: ; preds = %26
%37 = load i8*, i8** %2
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = icmp eq i32 %39, 3
br i1 %40, label %41, label %46
41: ; preds = %36
%42 = call i32 @mvaddch(i32 2, i32 0, i8 signext 32)
%43 = call i32 @mvaddch(i32 3, i32 0, i8 signext 32)
%44 = call i32 @mvaddch(i32 4, i32 0, i8 signext 62)
%45 = call i32 (...) @refresh()
br label %46
46: ; preds = %41, %36
br label %47
47: ; preds = %46, %31
br label %48
48: ; preds = %47, %21
%49 = call i32 (...) @getch()
store i32 %49, i32* %3
%50 = load i32, i32* %3
%51 = load i32, i32* @KEY_UP
%52 = icmp eq i32 %50, %51
br i1 %52, label %53, label %62
53: ; preds = %48
%54 = load i8*, i8** %2
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = icmp ne i32 %56, 1
br i1 %57, label %58, label %62
58: ; preds = %53
%59 = load i8*, i8** %2
%60 = load i8, i8* %59
%61 = add i8 %60, -1
store i8 %61, i8* %59
br label %100
62: ; preds = %53, %48
%63 = load i32, i32* %3
%64 = load i32, i32* @KEY_UP
%65 = icmp eq i32 %63, %64
br i1 %65, label %66, label %73
66: ; preds = %62
%67 = load i8*, i8** %2
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
%70 = icmp eq i32 %69, 1
br i1 %70, label %71, label %73
71: ; preds = %66
%72 = load i8*, i8** %2
store i8 3, i8* %72
br label %99
73: ; preds = %66, %62
%74 = load i32, i32* %3
%75 = load i32, i32* @KEY_DOWN
%76 = icmp eq i32 %74, %75
br i1 %76, label %77, label %86
77: ; preds = %73
%78 = load i8*, i8** %2
%79 = load i8, i8* %78
%80 = zext i8 %79 to i32
%81 = icmp ne i32 %80, 3
br i1 %81, label %82, label %86
82: ; preds = %77
%83 = load i8*, i8** %2
%84 = load i8, i8* %83
%85 = add i8 %84, 1
store i8 %85, i8* %83
br label %98
86: ; preds = %77, %73
%87 = load i32, i32* %3
%88 = load i32, i32* @KEY_DOWN
%89 = icmp eq i32 %87, %88
br i1 %89, label %90, label %97
90: ; preds = %86
%91 = load i8*, i8** %2
%92 = load i8, i8* %91
%93 = zext i8 %92 to i32
%94 = icmp eq i32 %93, 3
br i1 %94, label %95, label %97
95: ; preds = %90
%96 = load i8*, i8** %2
store i8 1, i8* %96
br label %97
97: ; preds = %95, %90, %86
br label %98
98: ; preds = %97, %82
br label %99
99: ; preds = %98, %71
br label %100
100: ; preds = %99, %58
br label %8
101: ; preds = %14
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"=== MAIN MENU ===\00"
@.str.1 = [12 x i8] c"1: New Game\00"
@.str.2 = [13 x i8] c"2: Load Game\00"
@.str.3 = [13 x i8] c"3: Quit Game\00"
@KEY_UP = global i32 0
@KEY_DOWN = global i32 0
define void @main_menu(i8* nocapture %0) {
%2 = tail call i32 @printw(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @mvprintw(i32 2, i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @mvprintw(i32 3, i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 @mvprintw(i32 4, i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %6
6: ; preds = %48, %1
%7 = phi i32 [ 0, %1 ], [ %30, %48 ]
switch i32 %7, label %8 [
i32 13, label %49
i32 10, label %49
]
8: ; preds = %6
%9 = load i8, i8* %0
%10 = add i8 %9, -1
%11 = icmp ult i8 %10, 3
br i1 %11, label %12, label %29
12: ; preds = %8
%13 = zext i8 %10 to i24
%14 = shl nuw nsw i24 %13, 3
%15 = lshr i24 2105406, %14
%16 = trunc i24 %15 to i8
%17 = zext i8 %10 to i24
%18 = shl nuw nsw i24 %17, 3
%19 = lshr i24 2113056, %18
%20 = trunc i24 %19 to i8
%21 = zext i8 %10 to i24
%22 = shl nuw nsw i24 %21, 3
%23 = lshr i24 4071456, %22
%24 = trunc i24 %23 to i8
%25 = tail call i32 @mvaddch(i32 2, i32 0, i8 signext %16)
%26 = tail call i32 @mvaddch(i32 3, i32 0, i8 signext %20)
%27 = tail call i32 @mvaddch(i32 4, i32 0, i8 signext %24)
%28 = tail call i32 (...) @refresh()
br label %29
29: ; preds = %8, %12
%30 = tail call i32 (...) @getch()
%31 = load i32, i32* @KEY_UP
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = load i8, i8* %0
%35 = icmp eq i8 %34, 1
%36 = add i8 %34, -1
%37 = select i1 %35, i8 3, i8 %36
br label %46
38: ; preds = %29
%39 = load i32, i32* @KEY_DOWN
%40 = icmp eq i32 %30, %39
br i1 %40, label %41, label %48
41: ; preds = %38
%42 = load i8, i8* %0
%43 = icmp eq i8 %42, 3
%44 = add i8 %42, 1
%45 = select i1 %43, i8 1, i8 %44
br label %46
46: ; preds = %41, %33
%47 = phi i8 [ %37, %33 ], [ %45, %41 ]
store i8 %47, i8* %0
br label %48
48: ; preds = %46, %38
br label %6
49: ; preds = %6, %6
ret void
}