#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 */
int /*<<< orphan*/ COLOR_PAIR(int);
int /*<<< orphan*/ about_window();
int /*<<< orphan*/ bkgd(int /*<<< orphan*/);
int check_quit();
int /*<<< orphan*/ delete_menu(int /*<<< orphan*/ **, int);
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ **file_menu_list(int /*<<< orphan*/);
int getch();
int /*<<< orphan*/ **help_menu_list(int);
int /*<<< orphan*/ init_scr();
int /*<<< orphan*/ make_menubar(int /*<<< orphan*/ *);
int /*<<< orphan*/ move(int, int);
int /*<<< orphan*/ printw(char *);
int /*<<< orphan*/ refresh();
int scroll_menu(int /*<<< orphan*/ **, int, int, int);
int /*<<< orphan*/ stdscr;
int /*<<< orphan*/ *subwin(int /*<<< orphan*/, int, int, int, int);
int /*<<< orphan*/ touchwin(int /*<<< orphan*/);
int /*<<< orphan*/ werase(int /*<<< orphan*/ *);
int /*<<< orphan*/ wprintw(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ wrefresh(int /*<<< orphan*/ *);
int main() {
  WINDOW *menubar, *statusbar, *about;
  int key;
  init_scr();
  bkgd(COLOR_PAIR(1));
  menubar = subwin(stdscr, 1, 80, 0, 0);
  statusbar = subwin(stdscr, 1, 79, 23, 1);
  make_menubar(menubar);
  move(2, 1);
  printw("Press 'a' or 'h' to open the menus. ");
  printw("ESC or 'q' quits.");
  refresh();
  while (1) {
    WINDOW **menu_items;
    int selected_item;
    key = getch();
    werase(statusbar);
    wrefresh(statusbar);
    if (key == 'a') {
      menu_items = file_menu_list(0);
      selected_item = scroll_menu(menu_items, 4, 20, 0);
      delete_menu(menu_items, 5);
      if (selected_item < 0)
        wprintw(statusbar, "You haven't selected any item");
      else
        wprintw(statusbar, "You have selected menu item %d.", selected_item);
      touchwin(stdscr);
      refresh();
    }
    if (key == 'h') {
      menu_items = help_menu_list(20);
      selected_item = scroll_menu(menu_items, 2, 0, 1);
      delete_menu(menu_items, 3);
      if (selected_item == 1) {
        about_window();
      }
      if (selected_item < 0)
        wprintw(statusbar, "You haven't selected any item");
    }
    if (key == 27 || key == 'q') {
      if (check_quit() == 1)
        break;
    }
    touchwin(stdscr);
    refresh();
  }
  endwin();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10b0 <init_scr@plt>
mov    $0x1,%edi
call   1070 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1140 <bkgd@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
mov    $0x50,%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1050 <subwin@plt>
mov    %rax,-0x10(%rbp)
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%r8d
mov    $0x4f,%edx
mov    $0x17,%ecx
mov    %r8d,%esi
call   1050 <subwin@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   10c0 <make_menubar@plt>
mov    $0x2,%edi
mov    $0x1,%esi
call   1160 <move@plt>
lea    0xd33(%rip),%rdi
call   1060 <printw@plt>
lea    0xd4c(%rip),%rdi
call   1060 <printw@plt>
mov    $0x0,%al
call   1100 <refresh@plt>
mov    $0x0,%al
call   1110 <getch@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1150 <werase@plt>
mov    -0x18(%rbp),%rdi
call   1040 <wrefresh@plt>
cmpl   $0x61,-0x24(%rbp)
jne    1387 <main+0x147>
xor    %edi,%edi
call   10e0 <file_menu_list@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x4,%esi
mov    $0x14,%edx
xor    %ecx,%ecx
call   1090 <scroll_menu@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x5,%esi
call   10f0 <delete_menu@plt>
cmpl   $0x0,-0x34(%rbp)
jge    135d <main+0x11d>
mov    -0x18(%rbp),%rdi
lea    0xce6(%rip),%rsi
mov    $0x0,%al
call   10a0 <wprintw@plt>
jmp    1372 <main+0x132>
mov    -0x18(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xcea(%rip),%rsi
mov    $0x0,%al
call   10a0 <wprintw@plt>
mov    0x2c6f(%rip),%rax
mov    (%rax),%edi
call   1030 <touchwin@plt>
mov    $0x0,%al
call   1100 <refresh@plt>
cmpl   $0x68,-0x24(%rbp)
jne    13f7 <main+0x1b7>
mov    $0x14,%edi
call   1080 <help_menu_list@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x2,%esi
xor    %edx,%edx
mov    $0x1,%ecx
call   1090 <scroll_menu@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x3,%esi
call   10f0 <delete_menu@plt>
cmpl   $0x1,-0x34(%rbp)
jne    13d6 <main+0x196>
mov    $0x0,%al
call   1130 <about_window@plt>
cmpl   $0x0,-0x34(%rbp)
jge    13f2 <main+0x1b2>
mov    -0x18(%rbp),%rdi
lea    0xc4c(%rip),%rsi
mov    $0x0,%al
call   10a0 <wprintw@plt>
jmp    13f7 <main+0x1b7>
cmpl   $0x1b,-0x24(%rbp)
je     140b <main+0x1cb>
cmpl   $0x71,-0x24(%rbp)
jne    1425 <main+0x1e5>
mov    $0x0,%al
call   10d0 <check_quit@plt>
cmp    $0x1,%eax
jne    1420 <main+0x1e0>
jmp    143f <main+0x1ff>
jmp    1425 <main+0x1e5>
mov    0x2bbc(%rip),%rax
mov    (%rax),%edi
call   1030 <touchwin@plt>
mov    $0x0,%al
call   1100 <refresh@plt>
jmp    12e5 <main+0xa5>
mov    $0x0,%al
call   1120 <endwin@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   10b0 <init_scr@plt>
mov    $0x1,%edi
call   1070 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1140 <bkgd@plt>
mov    0x2d7e(%rip),%r13
mov    0x0(%r13),%edi
mov    $0x1,%esi
mov    $0x50,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <subwin@plt>
mov    %rax,%rbp
mov    0x0(%r13),%edi
mov    $0x1,%esi
mov    $0x4f,%edx
mov    $0x17,%ecx
mov    $0x1,%r8d
call   1050 <subwin@plt>
mov    %rax,%r12
mov    %rbp,%rdi
call   10c0 <make_menubar@plt>
mov    $0x2,%edi
mov    $0x1,%esi
call   1160 <move@plt>
lea    0xd3c(%rip),%rdi
call   1060 <printw@plt>
lea    0xd55(%rip),%rdi
call   1060 <printw@plt>
lea    0xd5b(%rip),%r14
lea    0xd72(%rip),%r15
jmp    1309 <main+0xc9>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   10d0 <check_quit@plt>
cmp    $0x1,%eax
je     140d <main+0x1cd>
mov    0x0(%r13),%edi
call   1030 <touchwin@plt>
xor    %eax,%eax
call   1100 <refresh@plt>
xor    %eax,%eax
call   1110 <getch@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1150 <werase@plt>
mov    %r12,%rdi
call   1040 <wrefresh@plt>
cmp    $0x67,%ebp
jg     1380 <main+0x140>
cmp    $0x1b,%ebp
je     12f0 <main+0xb0>
cmp    $0x61,%ebp
jne    1300 <main+0xc0>
xor    %edi,%edi
call   10e0 <file_menu_list@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x4,%esi
mov    $0x14,%edx
xor    %ecx,%ecx
call   1090 <scroll_menu@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x5,%esi
call   10f0 <delete_menu@plt>
mov    %r12,%rdi
test   %ebp,%ebp
js     13ee <main+0x1ae>
mov    %r15,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   10a0 <wprintw@plt>
jmp    13f8 <main+0x1b8>
xchg   %ax,%ax
cmp    $0x68,%ebp
je     1393 <main+0x153>
cmp    $0x71,%ebp
je     12f0 <main+0xb0>
jmp    1300 <main+0xc0>
mov    $0x14,%edi
call   1080 <help_menu_list@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2,%esi
xor    %edx,%edx
mov    $0x1,%ecx
call   1090 <scroll_menu@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x3,%esi
call   10f0 <delete_menu@plt>
cmp    $0x1,%ebp
jne    13d4 <main+0x194>
xor    %eax,%eax
call   1130 <about_window@plt>
jmp    1300 <main+0xc0>
test   %ebp,%ebp
jns    1300 <main+0xc0>
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <wprintw@plt>
jmp    1300 <main+0xc0>
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <wprintw@plt>
mov    0x0(%r13),%edi
call   1030 <touchwin@plt>
xor    %eax,%eax
call   1100 <refresh@plt>
jmp    1300 <main+0xc0>
xor    %eax,%eax
call   1120 <endwin@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdscr = global i32 0
@.str = [37 x i8] c"Press 'a' or 'h' to open the menus. \00"
@.str.1 = [18 x i8] c"ESC or 'q' quits.\00"
@.str.2 = [30 x i8] c"You haven't selected any item\00"
@.str.3 = [32 x i8] c"You have selected menu item %d.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (...) @init_scr()
%9 = call i32 @COLOR_PAIR(i32 1)
%10 = call i32 @bkgd(i32 %9)
%11 = load i32, i32* @stdscr
%12 = call i32* @subwin(i32 %11, i32 1, i32 80, i32 0, i32 0)
store i32* %12, i32** %2
%13 = load i32, i32* @stdscr
%14 = call i32* @subwin(i32 %13, i32 1, i32 79, i32 23, i32 1)
store i32* %14, i32** %3
%15 = load i32*, i32** %2
%16 = call i32 @make_menubar(i32* %15)
%17 = call i32 @move(i32 2, i32 1)
%18 = call i32 @printw(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @printw(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 (...) @refresh()
br label %21
21: ; preds = %0, %79
%22 = call i32 (...) @getch()
store i32 %22, i32* %5
%23 = load i32*, i32** %3
%24 = call i32 @werase(i32* %23)
%25 = load i32*, i32** %3
%26 = call i32 @wrefresh(i32* %25)
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, 97
br i1 %28, label %29, label %48
29: ; preds = %21
%30 = call i32** @file_menu_list(i32 0)
store i32** %30, i32*** %6
%31 = load i32**, i32*** %6
%32 = call i32 @scroll_menu(i32** %31, i32 4, i32 20, i32 0)
store i32 %32, i32* %7
%33 = load i32**, i32*** %6
%34 = call i32 @delete_menu(i32** %33, i32 5)
%35 = load i32, i32* %7
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %29
%38 = load i32*, i32** %3
%39 = call i32 (i32*, i8*, ...) @wprintw(i32* %38, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %44
40: ; preds = %29
%41 = load i32*, i32** %3
%42 = load i32, i32* %7
%43 = call i32 (i32*, i8*, ...) @wprintw(i32* %41, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %40, %37
%45 = load i32, i32* @stdscr
%46 = call i32 @touchwin(i32 %45)
%47 = call i32 (...) @refresh()
br label %48
48: ; preds = %44, %21
%49 = load i32, i32* %5
%50 = icmp eq i32 %49, 104
br i1 %50, label %51, label %68
51: ; preds = %48
%52 = call i32** @help_menu_list(i32 20)
store i32** %52, i32*** %6
%53 = load i32**, i32*** %6
%54 = call i32 @scroll_menu(i32** %53, i32 2, i32 0, i32 1)
store i32 %54, i32* %7
%55 = load i32**, i32*** %6
%56 = call i32 @delete_menu(i32** %55, i32 3)
%57 = load i32, i32* %7
%58 = icmp eq i32 %57, 1
br i1 %58, label %59, label %61
59: ; preds = %51
%60 = call i32 (...) @about_window()
br label %61
61: ; preds = %59, %51
%62 = load i32, i32* %7
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32*, i32** %3
%66 = call i32 (i32*, i8*, ...) @wprintw(i32* %65, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %67
67: ; preds = %64, %61
br label %68
68: ; preds = %67, %48
%69 = load i32, i32* %5
%70 = icmp eq i32 %69, 27
br i1 %70, label %74, label %71
71: ; preds = %68
%72 = load i32, i32* %5
%73 = icmp eq i32 %72, 113
br i1 %73, label %74, label %79
74: ; preds = %71, %68
%75 = call i32 (...) @check_quit()
%76 = icmp eq i32 %75, 1
br i1 %76, label %77, label %78
77: ; preds = %74
br label %83
78: ; preds = %74
br label %79
79: ; preds = %78, %71
%80 = load i32, i32* @stdscr
%81 = call i32 @touchwin(i32 %80)
%82 = call i32 (...) @refresh()
br label %21
83: ; preds = %77
%84 = call i32 (...) @endwin()
%85 = load i32, i32* %1
ret i32 %85
}

LLVM IR (-O2):
@stdscr = global i32 0
@.str = [37 x i8] c"Press 'a' or 'h' to open the menus. \00"
@.str.1 = [18 x i8] c"ESC or 'q' quits.\00"
@.str.2 = [30 x i8] c"You haven't selected any item\00"
@.str.3 = [32 x i8] c"You have selected menu item %d.\00"
define i32 @main() {
%1 = tail call i32 (...) @init_scr()
%2 = tail call i32 @COLOR_PAIR(i32 1)
%3 = tail call i32 @bkgd(i32 %2)
%4 = load i32, i32* @stdscr
%5 = tail call i32* @subwin(i32 %4, i32 1, i32 80, i32 0, i32 0)
%6 = load i32, i32* @stdscr
%7 = tail call i32* @subwin(i32 %6, i32 1, i32 79, i32 23, i32 1)
%8 = tail call i32 @make_menubar(i32* %5)
%9 = tail call i32 @move(i32 2, i32 1)
%10 = tail call i32 @printw(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @printw(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %44, %0
%13 = tail call i32 (...) @refresh()
%14 = tail call i32 (...) @getch()
%15 = tail call i32 @werase(i32* %7)
%16 = tail call i32 @wrefresh(i32* %7)
switch i32 %14, label %44 [
i32 97, label %17
i32 104, label %30
i32 113, label %41
i32 27, label %41
]
17: ; preds = %12
%18 = tail call i32** @file_menu_list(i32 0)
%19 = tail call i32 @scroll_menu(i32** %18, i32 4, i32 20, i32 0)
%20 = tail call i32 @delete_menu(i32** %18, i32 5)
%21 = icmp slt i32 %19, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = tail call i32 (i32*, i8*, ...) @wprintw(i32* %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %26
24: ; preds = %17
%25 = tail call i32 (i32*, i8*, ...) @wprintw(i32* %7, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %19)
br label %26
26: ; preds = %24, %22
%27 = load i32, i32* @stdscr
%28 = tail call i32 @touchwin(i32 %27)
%29 = tail call i32 (...) @refresh()
br label %44
30: ; preds = %12
%31 = tail call i32** @help_menu_list(i32 20)
%32 = tail call i32 @scroll_menu(i32** %31, i32 2, i32 0, i32 1)
%33 = tail call i32 @delete_menu(i32** %31, i32 3)
%34 = icmp eq i32 %32, 1
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = tail call i32 (...) @about_window()
br label %44
37: ; preds = %30
%38 = icmp slt i32 %32, 0
br i1 %38, label %39, label %44
39: ; preds = %37
%40 = tail call i32 (i32*, i8*, ...) @wprintw(i32* %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %44
41: ; preds = %12, %12
%42 = tail call i32 (...) @check_quit()
%43 = icmp eq i32 %42, 1
br i1 %43, label %47, label %44
44: ; preds = %41, %12, %26, %35, %37, %39
%45 = load i32, i32* @stdscr
%46 = tail call i32 @touchwin(i32 %45)
br label %12
47: ; preds = %41
%48 = tail call i32 (...) @endwin()
ret i32 0
}