#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;
typedef int /*<<< orphan*/ MENU;
typedef int /*<<< orphan*/ ITEM;

/* Variables and functions */
int /*<<< orphan*/ ACS_HLINE;
int /*<<< orphan*/ ACS_LTEE;
int /*<<< orphan*/ ACS_RTEE;
int /*<<< orphan*/ COLOR_BLACK;
int /*<<< orphan*/ COLOR_PAIR(int);
int /*<<< orphan*/ COLOR_RED;
#define KEY_DOWN 129
#define KEY_UP 128
int /*<<< orphan*/ REQ_DOWN_ITEM;
int /*<<< orphan*/ REQ_UP_ITEM;
int /*<<< orphan*/ SIGWINCH;
scalar_t__ SIG_ERR;
int /*<<< orphan*/ TRUE;
int /*<<< orphan*/ box(int /*<<< orphan*/ *, int /*<<< orphan*/,
                       int /*<<< orphan*/);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ curs_set(int);
int database_number();
int /*<<< orphan*/ derwin(int /*<<< orphan*/ *, int, int, int, double);
int /*<<< orphan*/ get_database(int, char *);
int /*<<< orphan*/ getmaxyx(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ init_pair(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ keypad(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ menu_driver(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ mvwaddch(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ mvwhline(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/,
                            int);
int /*<<< orphan*/ mvwprintw(int /*<<< orphan*/ *, int, int, char *);
int /*<<< orphan*/ *new_item(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *new_menu(int /*<<< orphan*/ **);
int /*<<< orphan*/ *newwin(int, int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ post_menu(int /*<<< orphan*/ *);
int /*<<< orphan*/ print_in_middle(int /*<<< orphan*/ *, int,
                                   int /*<<< orphan*/, int, char *,
                                   int /*<<< orphan*/);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ remove_database(char *);
int /*<<< orphan*/ remove_menu(int /*<<< orphan*/ *, int /*<<< orphan*/ **,
                               int);
int /*<<< orphan*/ set_menu_format(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ set_menu_mark(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ set_menu_spacing(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                    int, int /*<<< orphan*/);
int /*<<< orphan*/ set_menu_sub(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ set_menu_win(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ signal(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdscr;
int wgetch(int /*<<< orphan*/ *);
int /*<<< orphan*/ wrefresh(int /*<<< orphan*/ *);
int main_menu() {
  int i, c, x, y, n;
  int choice = 0;
  n = database_number();
  char **choices;
  choices = (char **)malloc(sizeof(char *) * (n + 3));
  for (i = 0; i < n; i++) {
    choices[i] = (char *)malloc(sizeof(char) * 128);
    if (i < n)
      get_database(i, choices[i]);
  }
  MENU *menu;
  n = i;
  WINDOW *win;
  ITEM **items;
begin_main_menu:
  keypad(stdscr, TRUE);
  init_pair(1, COLOR_RED, COLOR_BLACK);
  items = (ITEM **)calloc(n + 1, sizeof(ITEM *));
  for (i = 0; i < n; i++) {
    items[i] = new_item(choices[i], NULL);
  }
  menu = new_menu((ITEM **)items);
  getmaxyx(stdscr, y, x);
  win = newwin(y, x, 0, 0);
  keypad(win, TRUE);
  set_menu_win(menu, win);
  set_menu_sub(menu, derwin(win, y - 7, 38, 5, 0.4 * x));
  set_menu_format(menu, y - 4, 1);
  set_menu_mark(menu, " * ");
  set_menu_spacing(menu, 0, 2, 0);
  box(win, 0, 0);
  print_in_middle(win, 1, 0, x, "My Menu", COLOR_PAIR(1));
  mvwaddch(win, 2, 0, ACS_LTEE);
  mvwhline(win, 2, 1, ACS_HLINE, x - 2);
  mvwaddch(win, 2, x - 1, ACS_RTEE);
  mvwaddch(win, y - 3, 0, ACS_LTEE);
  mvwhline(win, y - 3, 1, ACS_HLINE, x - 2);
  mvwaddch(win, y - 3, x - 1, ACS_RTEE);
  refresh();
  if (n) {
    if (n > 1)
      mvwprintw(win, y - 2, 2,
                "N:New Database\tR:Remove Database\tS:Sort\t\tQ:Quit");
    else
      mvwprintw(win, y - 2, 2, "N:New Database\tR:Remove Database\tQ:Quit");
    post_menu(menu);
    wrefresh(win);
    for (i = 0; i < choice; i++)
      menu_driver(menu, REQ_DOWN_ITEM);
    while ((c = wgetch(win))) {
      switch (c) {
      case KEY_DOWN:
        menu_driver(menu, REQ_DOWN_ITEM);
        if (choice != (n - 1))
          choice++;
        break;
      case KEY_UP:
        menu_driver(menu, REQ_UP_ITEM);
        if (choice != 0)
          choice--;
        break;
      case 10:
        remove_menu(menu, items, n);
        return choice;
        break;
      case 'n':
      case 'N':
        remove_menu(menu, items, n);
        return n + 1;
      case 'q':
      case 'Q':
        remove_menu(menu, items, n);
        return n + 2;
      case 's':
      case 'S':
        remove_menu(menu, items, n);
        return n + 3;
      case 'r':
      case 'R':
        remove_menu(menu, items, n);
        remove_database(choices[choice]);
        return -1;
      default:
        break;
      }
      wrefresh(win);
      if (signal(SIGWINCH, NULL) != SIG_ERR) {
        remove_menu(menu, items, n);
        wrefresh(win);
        goto begin_main_menu;
      }
    }
  } else {
    mvwprintw(win, y - 2, 2, "N:New Database\tQ:Quit");
    mvwprintw(win, 5, 3 * x / 7, "No database found :(\n");
    wrefresh(win);
    curs_set(0);
    while ((c = wgetch(win))) {
      switch (c) {
      case 'n':
      case 'N':
        remove_menu(menu, items, n);
        curs_set(1);
        return n + 1;
      case 'q':
      case 'Q':
        remove_menu(menu, items, n);
        curs_set(1);
        return n + 2;
      default:
        break;
      }
      if (signal(SIGWINCH, NULL) != SIG_ERR) {
        wrefresh(win);
        goto begin_main_menu;
      }
      wrefresh(win);
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<main_menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   11a0 <database_number@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x3,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1150 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    137f <main_menu+0x8f>
mov    $0x80,%edi
call   1150 <malloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    136c <main_menu+0x7c>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <get_database@plt>
jmp    1371 <main_menu+0x81>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1327 <main_menu+0x37>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2c54(%rip),%rax
mov    (%rax),%rdi
mov    0x2c3a(%rip),%rax
mov    (%rax),%esi
call   1090 <keypad@plt>
mov    0x2bec(%rip),%rax
mov    (%rax),%esi
mov    0x2c1b(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%edi
call   1070 <init_pair@plt>
mov    -0x18(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   10d0 <calloc@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1412 <main_menu+0x122>
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1160 <new_item@plt>
mov    %rax,%rdx
mov    -0x40(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    13d4 <main_menu+0xe4>
mov    -0x40(%rbp),%rdi
call   1120 <new_menu@plt>
mov    %rax,-0x30(%rbp)
mov    0x2bba(%rip),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   10c0 <getmaxyx@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   10a0 <newwin@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    0x2b7e(%rip),%rax
mov    (%rax),%esi
call   1090 <keypad@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <set_menu_win@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x7,%esi
cvtsi2sdl -0x10(%rbp),%xmm1
movsd  0xb7b(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    $0x26,%edx
mov    $0x5,%ecx
call   1210 <derwin@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%esi
call   10b0 <set_menu_sub@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x4,%esi
mov    $0x1,%edx
call   11c0 <set_menu_format@plt>
mov    -0x30(%rbp),%rdi
lea    0xbd6(%rip),%rsi
call   10e0 <set_menu_mark@plt>
mov    -0x30(%rbp),%rdi
xor    %ecx,%ecx
mov    $0x2,%edx
mov    %ecx,%esi
call   11e0 <set_menu_spacing@plt>
mov    -0x38(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1100 <box@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    $0x1,%edi
call   1130 <COLOR_PAIR@plt>
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%ecx
mov    %eax,%r9d
mov    $0x1,%esi
xor    %edx,%edx
lea    0xb86(%rip),%r8
call   11f0 <print_in_middle@plt>
mov    -0x38(%rbp),%rdi
mov    0x2ac2(%rip),%rax
mov    (%rax),%ecx
mov    $0x2,%esi
xor    %edx,%edx
call   11d0 <mvwaddch@plt>
mov    -0x38(%rbp),%rdi
mov    0x2a69(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%r8d
sub    $0x2,%r8d
mov    $0x2,%esi
mov    $0x1,%edx
call   1170 <mvwhline@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
mov    0x2a2f(%rip),%rax
mov    (%rax),%ecx
mov    $0x2,%esi
call   11d0 <mvwaddch@plt>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x3,%esi
mov    0x2a62(%rip),%rax
mov    (%rax),%ecx
xor    %edx,%edx
call   11d0 <mvwaddch@plt>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x3,%esi
mov    0x2a08(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%r8d
sub    $0x2,%r8d
mov    $0x1,%edx
call   1170 <mvwhline@plt>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x3,%esi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
mov    0x29cd(%rip),%rax
mov    (%rax),%ecx
call   11d0 <mvwaddch@plt>
mov    $0x0,%al
call   1180 <refresh@plt>
cmpl   $0x0,-0x18(%rbp)
je     189e <main_menu+0x5ae>
cmpl   $0x1,-0x18(%rbp)
jle    160d <main_menu+0x31d>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x2,%esi
mov    $0x2,%edx
lea    0xaa1(%rip),%rcx
call   11b0 <mvwprintw@plt>
jmp    1628 <main_menu+0x338>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x2,%esi
mov    $0x2,%edx
lea    0xab1(%rip),%rcx
call   11b0 <mvwprintw@plt>
mov    -0x30(%rbp),%rdi
call   1060 <post_menu@plt>
mov    -0x38(%rbp),%rdi
call   1080 <wrefresh@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    166d <main_menu+0x37d>
mov    -0x30(%rbp),%rdi
mov    0x2948(%rip),%rax
mov    (%rax),%esi
call   1050 <menu_driver@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1641 <main_menu+0x351>
jmp    1672 <main_menu+0x382>
mov    -0x38(%rbp),%rdi
call   1190 <wgetch@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     1899 <main_menu+0x5a9>
mov    -0xc(%rbp),%eax
mov    %eax,-0x5c(%rbp)
sub    $0xa,%eax
je     17a4 <main_menu+0x4b4>
jmp    169b <main_menu+0x3ab>
mov    -0x5c(%rbp),%eax
sub    $0x4e,%eax
je     17bf <main_menu+0x4cf>
jmp    16ac <main_menu+0x3bc>
mov    -0x5c(%rbp),%eax
sub    $0x51,%eax
je     17dd <main_menu+0x4ed>
jmp    16bd <main_menu+0x3cd>
mov    -0x5c(%rbp),%eax
sub    $0x52,%eax
je     1819 <main_menu+0x529>
jmp    16ce <main_menu+0x3de>
mov    -0x5c(%rbp),%eax
sub    $0x53,%eax
je     17fb <main_menu+0x50b>
jmp    16df <main_menu+0x3ef>
mov    -0x5c(%rbp),%eax
sub    $0x6e,%eax
je     17bf <main_menu+0x4cf>
jmp    16f0 <main_menu+0x400>
mov    -0x5c(%rbp),%eax
sub    $0x71,%eax
je     17dd <main_menu+0x4ed>
jmp    1701 <main_menu+0x411>
mov    -0x5c(%rbp),%eax
sub    $0x72,%eax
je     1819 <main_menu+0x529>
jmp    1712 <main_menu+0x422>
mov    -0x5c(%rbp),%eax
sub    $0x73,%eax
je     17fb <main_menu+0x50b>
jmp    1723 <main_menu+0x433>
mov    -0x5c(%rbp),%eax
sub    $0x80,%eax
je     177a <main_menu+0x48a>
jmp    1736 <main_menu+0x446>
mov    -0x5c(%rbp),%eax
sub    $0x81,%eax
jne    1846 <main_menu+0x556>
jmp    1749 <main_menu+0x459>
mov    -0x30(%rbp),%rdi
mov    0x284c(%rip),%rax
mov    (%rax),%esi
call   1050 <menu_driver@plt>
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1775 <main_menu+0x485>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    184b <main_menu+0x55b>
mov    -0x30(%rbp),%rdi
mov    0x2833(%rip),%rax
mov    (%rax),%esi
call   1050 <menu_driver@plt>
cmpl   $0x0,-0x1c(%rbp)
je     179f <main_menu+0x4af>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    184b <main_menu+0x55b>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1140 <remove_menu@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    19c9 <main_menu+0x6d9>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1140 <remove_menu@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    19c9 <main_menu+0x6d9>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1140 <remove_menu@plt>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4(%rbp)
jmp    19c9 <main_menu+0x6d9>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1140 <remove_menu@plt>
mov    -0x18(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x4(%rbp)
jmp    19c9 <main_menu+0x6d9>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1140 <remove_menu@plt>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1110 <remove_database@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    19c9 <main_menu+0x6d9>
jmp    184b <main_menu+0x55b>
mov    -0x38(%rbp),%rdi
call   1080 <wrefresh@plt>
mov    0x277d(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   10f0 <signal@plt>
mov    0x2743(%rip),%rcx
cmp    (%rcx),%rax
je     1894 <main_menu+0x5a4>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1140 <remove_menu@plt>
mov    -0x38(%rbp),%rdi
call   1080 <wrefresh@plt>
jmp    1385 <main_menu+0x95>
jmp    1672 <main_menu+0x382>
jmp    19c2 <main_menu+0x6d2>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x2,%esi
mov    $0x2,%edx
lea    0x848(%rip),%rcx
call   11b0 <mvwprintw@plt>
mov    -0x38(%rbp),%rdi
imul   $0x3,-0x10(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
mov    $0x5,%esi
lea    0x83b(%rip),%rcx
call   11b0 <mvwprintw@plt>
mov    -0x38(%rbp),%rdi
call   1080 <wrefresh@plt>
xor    %edi,%edi
call   1200 <curs_set@plt>
mov    -0x38(%rbp),%rdi
call   1190 <wgetch@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     19bd <main_menu+0x6cd>
mov    -0xc(%rbp),%eax
add    $0xffffffb2,%eax
mov    %eax,%ecx
mov    %rcx,-0x68(%rbp)
sub    $0x23,%eax
ja     197a <main_menu+0x68a>
mov    -0x68(%rbp),%rax
lea    0x6e7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1140 <remove_menu@plt>
mov    $0x1,%edi
call   1200 <curs_set@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    19c9 <main_menu+0x6d9>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1140 <remove_menu@plt>
mov    $0x1,%edi
call   1200 <curs_set@plt>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4(%rbp)
jmp    19c9 <main_menu+0x6d9>
jmp    197f <main_menu+0x68f>
mov    0x2652(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   10f0 <signal@plt>
mov    0x2618(%rip),%rcx
cmp    (%rcx),%rax
je     19af <main_menu+0x6bf>
mov    -0x38(%rbp),%rdi
call   1080 <wrefresh@plt>
jmp    1385 <main_menu+0x95>
mov    -0x38(%rbp),%rdi
call   1080 <wrefresh@plt>
jmp    18ec <main_menu+0x5fc>
jmp    19c2 <main_menu+0x6d2>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main_menu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xor    %eax,%eax
call   11a0 <database_number@plt>
mov    %eax,%r14d
lea    0x18(,%r14,8),%edi
call   1150 <malloc@plt>
mov    %rax,%r13
mov    $0x0,%eax
test   %r14d,%r14d
jle    1355 <main_menu+0x65>
mov    %r14d,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0x80,%edi
call   1150 <malloc@plt>
mov    %rax,0x0(%r13,%rbp,8)
mov    %ebp,%edi
mov    %rax,%rsi
call   1040 <get_database@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1330 <main_menu+0x40>
mov    %r14d,%eax
lea    0x1(%rax),%r12d
mov    %eax,%r14d
add    $0xffffffff,%eax
mov    %rax,0x20(%rsp)
mov    0x2c75(%rip),%r15
mov    0x2c5e(%rip),%rax
mov    0x2c17(%rip),%rbx
mov    0x2c48(%rip),%rbp
movl   $0x0,0xc(%rsp)
mov    %r12d,0x1c(%rsp)
mov    (%r15),%rdi
mov    (%rax),%esi
call   1090 <keypad@plt>
mov    (%rbx),%esi
mov    0x0(%rbp),%edx
mov    $0x1,%edi
call   1070 <init_pair@plt>
mov    %r12d,%edi
mov    $0x8,%esi
call   10d0 <calloc@plt>
mov    %rax,%r12
test   %r14,%r14
je     13d9 <main_menu+0xe9>
xor    %ebx,%ebx
nopl   (%rax)
mov    0x0(%r13,%rbx,8),%rdi
xor    %esi,%esi
call   1160 <new_item@plt>
mov    %rax,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    13c0 <main_menu+0xd0>
mov    %r12,%rdi
call   1120 <new_menu@plt>
mov    %rax,%rbx
mov    (%r15),%rdi
call   10c0 <getmaxyx@plt>
xor    %edx,%edx
xor    %ecx,%ecx
call   10a0 <newwin@plt>
mov    %rax,%r15
mov    0x2bd1(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1090 <keypad@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <set_menu_win@plt>
xorps  %xmm0,%xmm0
mov    %r15,%rdi
mov    $0x26,%edx
mov    $0x5,%ecx
call   1210 <derwin@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   10b0 <set_menu_sub@plt>
mov    %rbx,%rdi
mov    $0x1,%edx
call   11c0 <set_menu_format@plt>
mov    %rbx,%rdi
lea    0xd16(%rip),%rsi
call   10e0 <set_menu_mark@plt>
mov    %rbx,0x10(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x2,%edx
xor    %ecx,%ecx
call   11e0 <set_menu_spacing@plt>
mov    %r15,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1100 <box@plt>
mov    $0x1,%edi
call   1130 <COLOR_PAIR@plt>
mov    %r15,%rdi
mov    $0x1,%esi
xor    %edx,%edx
lea    0xcd8(%rip),%r8
mov    %eax,%r9d
call   11f0 <print_in_middle@plt>
mov    0x2b4d(%rip),%rax
mov    (%rax),%ecx
mov    %r15,%rdi
mov    $0x2,%esi
xor    %edx,%edx
call   11d0 <mvwaddch@plt>
mov    0x2af5(%rip),%rbp
mov    0x0(%rbp),%ecx
mov    %r15,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1170 <mvwhline@plt>
mov    0x2ac9(%rip),%rbx
mov    (%rbx),%ecx
mov    %r15,%rdi
mov    $0x2,%esi
call   11d0 <mvwaddch@plt>
mov    0x2b03(%rip),%rax
mov    (%rax),%ecx
mov    %r15,%rdi
xor    %edx,%edx
call   11d0 <mvwaddch@plt>
mov    0x0(%rbp),%ecx
mov    %r15,%rdi
mov    $0x1,%edx
call   1170 <mvwhline@plt>
mov    (%rbx),%ecx
mov    %r15,%rdi
call   11d0 <mvwaddch@plt>
xor    %eax,%eax
call   1180 <refresh@plt>
test   %r14,%r14
jne    15d8 <main_menu+0x2e8>
mov    %r15,%rdi
mov    $0x2,%edx
lea    0xc9a(%rip),%rcx
call   11b0 <mvwprintw@plt>
mov    %r15,%rdi
mov    $0x5,%esi
xor    %edx,%edx
lea    0xc9a(%rip),%rcx
call   11b0 <mvwprintw@plt>
mov    %r15,%rdi
call   1080 <wrefresh@plt>
xor    %edi,%edi
call   1200 <curs_set@plt>
jmp    1592 <main_menu+0x2a2>
cs nopw 0x0(%rax,%rax,1)
test   %eax,%eax
je     17b8 <main_menu+0x4c8>
mov    0x2a69(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   10f0 <signal@plt>
mov    %rax,%rbp
mov    0x2a2e(%rip),%rax
mov    (%rax),%rbx
mov    %r15,%rdi
call   1080 <wrefresh@plt>
cmp    %rbx,%rbp
jne    15b2 <main_menu+0x2c2>
mov    %r15,%rdi
call   1190 <wgetch@plt>
lea    -0x4e(%rax),%ecx
cmp    $0x23,%ecx
ja     1560 <main_menu+0x270>
lea    0xa57(%rip),%rdx
movslq (%rdx,%rcx,4),%rax
add    %rdx,%rax
jmp    *%rax
mov    0x1c(%rsp),%r12d
mov    0x2a22(%rip),%r15
mov    0x2a0b(%rip),%rax
mov    0x29c4(%rip),%rbx
mov    0x29f5(%rip),%rbp
jmp    138d <main_menu+0x9d>
cmp    $0x1,%r14d
mov    0x29bd(%rip),%rbp
lea    0xaa6(%rip),%rbx
jne    15f5 <main_menu+0x305>
lea    0xba9(%rip),%rcx
jmp    15fc <main_menu+0x30c>
lea    0xb70(%rip),%rcx
mov    %r15,%rdi
mov    $0x2,%edx
call   11b0 <mvwprintw@plt>
mov    0x10(%rsp),%rdi
call   1060 <post_menu@plt>
mov    %r15,%rdi
call   1080 <wrefresh@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    169a <main_menu+0x3aa>
mov    %eax,%ebp
mov    0x10(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    0x2969(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <menu_driver@plt>
add    $0xffffffff,%ebp
jne    1630 <main_menu+0x340>
mov    0x2953(%rip),%rbp
lea    0xa3c(%rip),%rbx
jmp    169a <main_menu+0x3aa>
mov    0x0(%rbp),%esi
mov    0x10(%rsp),%rdi
call   1050 <menu_driver@plt>
xor    %eax,%eax
mov    0xc(%rsp),%ecx
cmp    0x20(%rsp),%ecx
setne  %al
add    %eax,%ecx
mov    %ecx,0xc(%rsp)
mov    %r15,%rdi
call   1080 <wrefresh@plt>
mov    0x2953(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   10f0 <signal@plt>
mov    0x291b(%rip),%rcx
cmp    (%rcx),%rax
jne    16ed <main_menu+0x3fd>
mov    %r15,%rdi
call   1190 <wgetch@plt>
lea    -0x4e(%rax),%ecx
cmp    $0x33,%ecx
ja     16db <main_menu+0x3eb>
movslq (%rbx,%rcx,4),%rax
add    %rbx,%rax
jmp    *%rax
mov    0x28fe(%rip),%rax
mov    (%rax),%esi
mov    0x10(%rsp),%rdi
call   1050 <menu_driver@plt>
mov    0xc(%rsp),%eax
sub    $0x1,%eax
mov    $0x0,%ecx
cmovb  %ecx,%eax
mov    %eax,0xc(%rsp)
jmp    1676 <main_menu+0x386>
test   %eax,%eax
je     17b8 <main_menu+0x4c8>
cmp    $0xa,%eax
jne    1676 <main_menu+0x386>
jmp    17e5 <main_menu+0x4f5>
mov    0x10(%rsp),%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1140 <remove_menu@plt>
mov    %r15,%rdi
call   1080 <wrefresh@plt>
mov    0x28d4(%rip),%r15
mov    0x28bd(%rip),%rax
mov    0x2876(%rip),%rbx
mov    0x28a7(%rip),%rbp
mov    0x1c(%rsp),%r12d
jmp    138d <main_menu+0x9d>
mov    0x10(%rsp),%rdi
mov    %r12,%rsi
xor    %edx,%edx
call   1140 <remove_menu@plt>
mov    $0x1,%edi
call   1200 <curs_set@plt>
mov    0x1c(%rsp),%eax
jmp    17bd <main_menu+0x4cd>
mov    0x10(%rsp),%rdi
mov    %r12,%rsi
xor    %edx,%edx
call   1140 <remove_menu@plt>
mov    $0x1,%edi
call   1200 <curs_set@plt>
mov    $0x2,%eax
jmp    17bd <main_menu+0x4cd>
mov    0x10(%rsp),%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1140 <remove_menu@plt>
mov    0x1c(%rsp),%eax
jmp    17bd <main_menu+0x4cd>
mov    0x10(%rsp),%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1140 <remove_menu@plt>
add    $0x2,%r14d
mov    %r14d,%eax
jmp    17bd <main_menu+0x4cd>
mov    0x10(%rsp),%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1140 <remove_menu@plt>
movslq 0xc(%rsp),%rax
mov    0x0(%r13,%rax,8),%rdi
call   1110 <remove_database@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rsp),%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1140 <remove_menu@plt>
add    $0x3,%r14d
mov    %r14d,%eax
jmp    17bd <main_menu+0x4cd>
mov    0x10(%rsp),%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1140 <remove_menu@plt>
mov    0xc(%rsp),%eax
jmp    17bd <main_menu+0x4cd>

LLVM IR (-O0):
@stdscr = global i32* null
@TRUE = global i32 0
@COLOR_RED = global i32 0
@COLOR_BLACK = global i32 0
@.str = [4 x i8] c" * \00"
@.str.1 = [8 x i8] c"My Menu\00"
@ACS_LTEE = global i32 0
@ACS_HLINE = global i32 0
@ACS_RTEE = global i32 0
@.str.2 = [48 x i8] c"N:New Database\09R:Remove Database\09S:Sort\09\09Q:Quit\00"
@.str.3 = [40 x i8] c"N:New Database\09R:Remove Database\09Q:Quit\00"
@REQ_DOWN_ITEM = global i32 0
@REQ_UP_ITEM = global i32 0
@SIGWINCH = global i32 0
@SIG_ERR = global i64 0
@.str.4 = [22 x i8] c"N:New Database\09Q:Quit\00"
@.str.5 = [22 x i8] c"No database found :(\0A\00"
define i32 @main_menu() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32**
store i32 0, i32* %7
%12 = call i32 (...) @database_number()
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = add nsw i32 %13, 3
%15 = sext i32 %14 to i64
%16 = mul i64 8, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8**
store i8** %19, i8*** %8
store i32 0, i32* %2
br label %20
20: ; preds = %43, %0
%21 = load i32, i32* %2
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %46
24: ; preds = %20
%25 = call i64 @malloc(i32 128)
%26 = inttoptr i64 %25 to i8*
%27 = load i8**, i8*** %8
%28 = load i32, i32* %2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
store i8* %26, i8** %30
%31 = load i32, i32* %2
%32 = load i32, i32* %6
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %42
34: ; preds = %24
%35 = load i32, i32* %2
%36 = load i8**, i8*** %8
%37 = load i32, i32* %2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 @get_database(i32 %35, i8* %40)
br label %42
42: ; preds = %34, %24
br label %43
43: ; preds = %42
%44 = load i32, i32* %2
%45 = add nsw i32 %44, 1
store i32 %45, i32* %2
br label %20
46: ; preds = %20
%47 = load i32, i32* %2
store i32 %47, i32* %6
br label %48
48: ; preds = %305, %255, %46
%49 = load i32*, i32** @stdscr
%50 = load i32, i32* @TRUE
%51 = call i32 @keypad(i32* %49, i32 %50)
%52 = load i32, i32* @COLOR_RED
%53 = load i32, i32* @COLOR_BLACK
%54 = call i32 @init_pair(i32 1, i32 %52, i32 %53)
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
%57 = call i64 @calloc(i32 %56, i32 8)
%58 = inttoptr i64 %57 to i32**
store i32** %58, i32*** %11
store i32 0, i32* %2
br label %59
59: ; preds = %74, %48
%60 = load i32, i32* %2
%61 = load i32, i32* %6
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %77
63: ; preds = %59
%64 = load i8**, i8*** %8
%65 = load i32, i32* %2
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8*, i8** %64, i64 %66
%68 = load i8*, i8** %67
%69 = call i32* @new_item(i8* %68, i32* null)
%70 = load i32**, i32*** %11
%71 = load i32, i32* %2
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32*, i32** %70, i64 %72
store i32* %69, i32** %73
br label %74
74: ; preds = %63
%75 = load i32, i32* %2
%76 = add nsw i32 %75, 1
store i32 %76, i32* %2
br label %59
77: ; preds = %59
%78 = load i32**, i32*** %11
%79 = call i32* @new_menu(i32** %78)
store i32* %79, i32** %9
%80 = load i32*, i32** @stdscr
%81 = load i32, i32* %5
%82 = load i32, i32* %4
%83 = call i32 @getmaxyx(i32* %80, i32 %81, i32 %82)
%84 = load i32, i32* %5
%85 = load i32, i32* %4
%86 = call i32* @newwin(i32 %84, i32 %85, i32 0, i32 0)
store i32* %86, i32** %10
%87 = load i32*, i32** %10
%88 = load i32, i32* @TRUE
%89 = call i32 @keypad(i32* %87, i32 %88)
%90 = load i32*, i32** %9
%91 = load i32*, i32** %10
%92 = call i32 @set_menu_win(i32* %90, i32* %91)
%93 = load i32*, i32** %9
%94 = load i32*, i32** %10
%95 = load i32, i32* %5
%96 = sub nsw i32 %95, 7
%97 = load i32, i32* %4
%98 = sitofp i32 %97 to double
%99 = fmul double 4.000000e-01, %98
%100 = call i32 @derwin(i32* %94, i32 %96, i32 38, i32 5, double %99)
%101 = call i32 @set_menu_sub(i32* %93, i32 %100)
%102 = load i32*, i32** %9
%103 = load i32, i32* %5
%104 = sub nsw i32 %103, 4
%105 = call i32 @set_menu_format(i32* %102, i32 %104, i32 1)
%106 = load i32*, i32** %9
%107 = call i32 @set_menu_mark(i32* %106, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%108 = load i32*, i32** %9
%109 = call i32 @set_menu_spacing(i32* %108, i32 0, i32 2, i32 0)
%110 = load i32*, i32** %10
%111 = call i32 @box(i32* %110, i32 0, i32 0)
%112 = load i32*, i32** %10
%113 = load i32, i32* %4
%114 = call i32 @COLOR_PAIR(i32 1)
%115 = call i32 @print_in_middle(i32* %112, i32 1, i32 0, i32 %113, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %114)
%116 = load i32*, i32** %10
%117 = load i32, i32* @ACS_LTEE
%118 = call i32 @mvwaddch(i32* %116, i32 2, i32 0, i32 %117)
%119 = load i32*, i32** %10
%120 = load i32, i32* @ACS_HLINE
%121 = load i32, i32* %4
%122 = sub nsw i32 %121, 2
%123 = call i32 @mvwhline(i32* %119, i32 2, i32 1, i32 %120, i32 %122)
%124 = load i32*, i32** %10
%125 = load i32, i32* %4
%126 = sub nsw i32 %125, 1
%127 = load i32, i32* @ACS_RTEE
%128 = call i32 @mvwaddch(i32* %124, i32 2, i32 %126, i32 %127)
%129 = load i32*, i32** %10
%130 = load i32, i32* %5
%131 = sub nsw i32 %130, 3
%132 = load i32, i32* @ACS_LTEE
%133 = call i32 @mvwaddch(i32* %129, i32 %131, i32 0, i32 %132)
%134 = load i32*, i32** %10
%135 = load i32, i32* %5
%136 = sub nsw i32 %135, 3
%137 = load i32, i32* @ACS_HLINE
%138 = load i32, i32* %4
%139 = sub nsw i32 %138, 2
%140 = call i32 @mvwhline(i32* %134, i32 %136, i32 1, i32 %137, i32 %139)
%141 = load i32*, i32** %10
%142 = load i32, i32* %5
%143 = sub nsw i32 %142, 3
%144 = load i32, i32* %4
%145 = sub nsw i32 %144, 1
%146 = load i32, i32* @ACS_RTEE
%147 = call i32 @mvwaddch(i32* %141, i32 %143, i32 %145, i32 %146)
%148 = call i32 (...) @refresh()
%149 = load i32, i32* %6
%150 = icmp ne i32 %149, 0
br i1 %150, label %151, label %264
151: ; preds = %77
%152 = load i32, i32* %6
%153 = icmp sgt i32 %152, 1
br i1 %153, label %154, label %159
154: ; preds = %151
%155 = load i32*, i32** %10
%156 = load i32, i32* %5
%157 = sub nsw i32 %156, 2
%158 = call i32 @mvwprintw(i32* %155, i32 %157, i32 2, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
br label %164
159: ; preds = %151
%160 = load i32*, i32** %10
%161 = load i32, i32* %5
%162 = sub nsw i32 %161, 2
%163 = call i32 @mvwprintw(i32* %160, i32 %162, i32 2, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
br label %164
164: ; preds = %159, %154
%165 = load i32*, i32** %9
%166 = call i32 @post_menu(i32* %165)
%167 = load i32*, i32** %10
%168 = call i32 @wrefresh(i32* %167)
store i32 0, i32* %2
br label %169
169: ; preds = %177, %164
%170 = load i32, i32* %2
%171 = load i32, i32* %7
%172 = icmp slt i32 %170, %171
br i1 %172, label %173, label %180
173: ; preds = %169
%174 = load i32*, i32** %9
%175 = load i32, i32* @REQ_DOWN_ITEM
%176 = call i32 @menu_driver(i32* %174, i32 %175)
br label %177
177: ; preds = %173
%178 = load i32, i32* %2
%179 = add nsw i32 %178, 1
store i32 %179, i32* %2
br label %169
180: ; preds = %169
br label %181
181: ; preds = %262, %180
%182 = load i32*, i32** %10
%183 = call i32 @wgetch(i32* %182)
store i32 %183, i32* %3
%184 = icmp ne i32 %183, 0
br i1 %184, label %185, label %263
185: ; preds = %181
%186 = load i32, i32* %3
switch i32 %186, label %247 [
i32 129, label %187
i32 128, label %199
i32 10, label %209
i32 110, label %215
i32 78, label %215
i32 113, label %222
i32 81, label %222
i32 115, label %229
i32 83, label %229
i32 114, label %236
i32 82, label %236
]
187: ; preds = %185
%188 = load i32*, i32** %9
%189 = load i32, i32* @REQ_DOWN_ITEM
%190 = call i32 @menu_driver(i32* %188, i32 %189)
%191 = load i32, i32* %7
%192 = load i32, i32* %6
%193 = sub nsw i32 %192, 1
%194 = icmp ne i32 %191, %193
br i1 %194, label %195, label %198
195: ; preds = %187
%196 = load i32, i32* %7
%197 = add nsw i32 %196, 1
store i32 %197, i32* %7
br label %198
198: ; preds = %195, %187
br label %248
199: ; preds = %185
%200 = load i32*, i32** %9
%201 = load i32, i32* @REQ_UP_ITEM
%202 = call i32 @menu_driver(i32* %200, i32 %201)
%203 = load i32, i32* %7
%204 = icmp ne i32 %203, 0
br i1 %204, label %205, label %208
205: ; preds = %199
%206 = load i32, i32* %7
%207 = add nsw i32 %206, -1
store i32 %207, i32* %7
br label %208
208: ; preds = %205, %199
br label %248
209: ; preds = %185
%210 = load i32*, i32** %9
%211 = load i32**, i32*** %11
%212 = load i32, i32* %6
%213 = call i32 @remove_menu(i32* %210, i32** %211, i32 %212)
%214 = load i32, i32* %7
store i32 %214, i32* %1
br label %313
215: ; preds = %185, %185
%216 = load i32*, i32** %9
%217 = load i32**, i32*** %11
%218 = load i32, i32* %6
%219 = call i32 @remove_menu(i32* %216, i32** %217, i32 %218)
%220 = load i32, i32* %6
%221 = add nsw i32 %220, 1
store i32 %221, i32* %1
br label %313
222: ; preds = %185, %185
%223 = load i32*, i32** %9
%224 = load i32**, i32*** %11
%225 = load i32, i32* %6
%226 = call i32 @remove_menu(i32* %223, i32** %224, i32 %225)
%227 = load i32, i32* %6
%228 = add nsw i32 %227, 2
store i32 %228, i32* %1
br label %313
229: ; preds = %185, %185
%230 = load i32*, i32** %9
%231 = load i32**, i32*** %11
%232 = load i32, i32* %6
%233 = call i32 @remove_menu(i32* %230, i32** %231, i32 %232)
%234 = load i32, i32* %6
%235 = add nsw i32 %234, 3
store i32 %235, i32* %1
br label %313
236: ; preds = %185, %185
%237 = load i32*, i32** %9
%238 = load i32**, i32*** %11
%239 = load i32, i32* %6
%240 = call i32 @remove_menu(i32* %237, i32** %238, i32 %239)
%241 = load i8**, i8*** %8
%242 = load i32, i32* %7
%243 = sext i32 %242 to i64
%244 = getelementptr inbounds i8*, i8** %241, i64 %243
%245 = load i8*, i8** %244
%246 = call i32 @remove_database(i8* %245)
store i32 -1, i32* %1
br label %313
247: ; preds = %185
br label %248
248: ; preds = %247, %208, %198
%249 = load i32*, i32** %10
%250 = call i32 @wrefresh(i32* %249)
%251 = load i32, i32* @SIGWINCH
%252 = call i64 @signal(i32 %251, i32* null)
%253 = load i64, i64* @SIG_ERR
%254 = icmp ne i64 %252, %253
br i1 %254, label %255, label %262
255: ; preds = %248
%256 = load i32*, i32** %9
%257 = load i32**, i32*** %11
%258 = load i32, i32* %6
%259 = call i32 @remove_menu(i32* %256, i32** %257, i32 %258)
%260 = load i32*, i32** %10
%261 = call i32 @wrefresh(i32* %260)
br label %48
262: ; preds = %248
br label %181
263: ; preds = %181
br label %312
264: ; preds = %77
%265 = load i32*, i32** %10
%266 = load i32, i32* %5
%267 = sub nsw i32 %266, 2
%268 = call i32 @mvwprintw(i32* %265, i32 %267, i32 2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%269 = load i32*, i32** %10
%270 = load i32, i32* %4
%271 = mul nsw i32 3, %270
%272 = sdiv i32 %271, 7
%273 = call i32 @mvwprintw(i32* %269, i32 5, i32 %272, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%274 = load i32*, i32** %10
%275 = call i32 @wrefresh(i32* %274)
%276 = call i32 @curs_set(i32 0)
br label %277
277: ; preds = %308, %264
%278 = load i32*, i32** %10
%279 = call i32 @wgetch(i32* %278)
store i32 %279, i32* %3
%280 = icmp ne i32 %279, 0
br i1 %280, label %281, label %311
281: ; preds = %277
%282 = load i32, i32* %3
switch i32 %282, label %299 [
i32 110, label %283
i32 78, label %283
i32 113, label %291
i32 81, label %291
]
283: ; preds = %281, %281
%284 = load i32*, i32** %9
%285 = load i32**, i32*** %11
%286 = load i32, i32* %6
%287 = call i32 @remove_menu(i32* %284, i32** %285, i32 %286)
%288 = call i32 @curs_set(i32 1)
%289 = load i32, i32* %6
%290 = add nsw i32 %289, 1
store i32 %290, i32* %1
br label %313
291: ; preds = %281, %281
%292 = load i32*, i32** %9
%293 = load i32**, i32*** %11
%294 = load i32, i32* %6
%295 = call i32 @remove_menu(i32* %292, i32** %293, i32 %294)
%296 = call i32 @curs_set(i32 1)
%297 = load i32, i32* %6
%298 = add nsw i32 %297, 2
store i32 %298, i32* %1
br label %313
299: ; preds = %281
br label %300
300: ; preds = %299
%301 = load i32, i32* @SIGWINCH
%302 = call i64 @signal(i32 %301, i32* null)
%303 = load i64, i64* @SIG_ERR
%304 = icmp ne i64 %302, %303
br i1 %304, label %305, label %308
305: ; preds = %300
%306 = load i32*, i32** %10
%307 = call i32 @wrefresh(i32* %306)
br label %48
308: ; preds = %300
%309 = load i32*, i32** %10
%310 = call i32 @wrefresh(i32* %309)
br label %277
311: ; preds = %277
br label %312
312: ; preds = %311, %263
store i32 -1, i32* %1
br label %313
313: ; preds = %312, %291, %283, %236, %229, %222, %215, %209
%314 = load i32, i32* %1
ret i32 %314
}

LLVM IR (-O2):
@stdscr = global i32* null
@TRUE = global i32 0
@COLOR_RED = global i32 0
@COLOR_BLACK = global i32 0
@.str = [4 x i8] c" * \00"
@.str.1 = [8 x i8] c"My Menu\00"
@ACS_LTEE = global i32 0
@ACS_HLINE = global i32 0
@ACS_RTEE = global i32 0
@.str.2 = [48 x i8] c"N:New Database\09R:Remove Database\09S:Sort\09\09Q:Quit\00"
@.str.3 = [40 x i8] c"N:New Database\09R:Remove Database\09Q:Quit\00"
@REQ_DOWN_ITEM = global i32 0
@REQ_UP_ITEM = global i32 0
@SIGWINCH = global i32 0
@SIG_ERR = global i64 0
@.str.4 = [22 x i8] c"N:New Database\09Q:Quit\00"
@.str.5 = [22 x i8] c"No database found :(\0A\00"
define i32 @main_menu() {
%1 = tail call i32 (...) @database_number()
%2 = shl i32 %1, 3
%3 = add i32 %2, 24
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8**
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = zext i32 %1 to i64
br label %15
9: ; preds = %15, %0
%10 = phi i32 [ 0, %0 ], [ %1, %15 ]
%11 = add nuw nsw i32 %10, 1
%12 = icmp eq i32 %10, 0
%13 = add nsw i32 %10, -1
%14 = zext i32 %10 to i64
br label %131
15: ; preds = %7, %15
%16 = phi i64 [ 0, %7 ], [ %22, %15 ]
%17 = tail call i64 @malloc(i32 128)
%18 = inttoptr i64 %17 to i8*
%19 = getelementptr inbounds i8*, i8** %5, i64 %16
store i8* %18, i8** %19
%20 = trunc i64 %16 to i32
%21 = tail call i32 @get_database(i32 %20, i8* %18)
%22 = add nuw nsw i64 %16, 1
%23 = icmp eq i64 %22, %8
br i1 %23, label %9, label %15
24: ; preds = %148, %131
%25 = load i32*, i32** @stdscr
%26 = load i32, i32* @TRUE
%27 = tail call i32 @keypad(i32* %25, i32 %26)
%28 = load i32, i32* @COLOR_RED
%29 = load i32, i32* @COLOR_BLACK
%30 = tail call i32 @init_pair(i32 1, i32 %28, i32 %29)
%31 = tail call i64 @calloc(i32 %11, i32 8)
%32 = inttoptr i64 %31 to i32**
br i1 %12, label %41, label %33
33: ; preds = %24, %33
%34 = phi i64 [ %39, %33 ], [ 0, %24 ]
%35 = getelementptr inbounds i8*, i8** %5, i64 %34
%36 = load i8*, i8** %35
%37 = tail call i32* @new_item(i8* %36, i32* null)
%38 = getelementptr inbounds i32*, i32** %32, i64 %34
store i32* %37, i32** %38
%39 = add nuw nsw i64 %34, 1
%40 = icmp eq i64 %39, %14
br i1 %40, label %41, label %33
41: ; preds = %33, %24
%42 = tail call i32* @new_menu(i32** %32)
%43 = load i32*, i32** @stdscr
%44 = tail call i32 @getmaxyx(i32* %43, i32 undef, i32 undef)
%45 = tail call i32* @newwin(i32 undef, i32 undef, i32 0, i32 0)
%46 = load i32, i32* @TRUE
%47 = tail call i32 @keypad(i32* %45, i32 %46)
%48 = tail call i32 @set_menu_win(i32* %42, i32* %45)
%49 = tail call i32 @derwin(i32* %45, i32 undef, i32 38, i32 5, double 0.000000e+00)
%50 = tail call i32 @set_menu_sub(i32* %42, i32 %49)
%51 = tail call i32 @set_menu_format(i32* %42, i32 undef, i32 1)
%52 = tail call i32 @set_menu_mark(i32* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%53 = tail call i32 @set_menu_spacing(i32* %42, i32 0, i32 2, i32 0)
%54 = tail call i32 @box(i32* %45, i32 0, i32 0)
%55 = tail call i32 @COLOR_PAIR(i32 1)
%56 = tail call i32 @print_in_middle(i32* %45, i32 1, i32 0, i32 undef, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %55)
%57 = load i32, i32* @ACS_LTEE
%58 = tail call i32 @mvwaddch(i32* %45, i32 2, i32 0, i32 %57)
%59 = load i32, i32* @ACS_HLINE
%60 = tail call i32 @mvwhline(i32* %45, i32 2, i32 1, i32 %59, i32 undef)
%61 = load i32, i32* @ACS_RTEE
%62 = tail call i32 @mvwaddch(i32* %45, i32 2, i32 undef, i32 %61)
%63 = load i32, i32* @ACS_LTEE
%64 = tail call i32 @mvwaddch(i32* %45, i32 undef, i32 0, i32 %63)
%65 = load i32, i32* @ACS_HLINE
%66 = tail call i32 @mvwhline(i32* %45, i32 undef, i32 1, i32 %65, i32 undef)
%67 = load i32, i32* @ACS_RTEE
%68 = tail call i32 @mvwaddch(i32* %45, i32 undef, i32 undef, i32 %67)
%69 = tail call i32 (...) @refresh()
switch i32 %10, label %70 [
i32 0, label %133
i32 1, label %71
]
70: ; preds = %41
br label %71
71: ; preds = %41, %70
%72 = phi i8* [ getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), %70 ], [ getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), %41 ]
%73 = tail call i32 @mvwprintw(i32* %45, i32 undef, i32 2, i8* %72)
%74 = inttoptr i64 %31 to i32**
%75 = tail call i32 @post_menu(i32* %42)
%76 = tail call i32 @wrefresh(i32* %45)
%77 = icmp sgt i32 %132, 0
br i1 %77, label %78, label %84
78: ; preds = %71, %78
%79 = phi i32 [ %82, %78 ], [ 0, %71 ]
%80 = load i32, i32* @REQ_DOWN_ITEM
%81 = tail call i32 @menu_driver(i32* %42, i32 %80)
%82 = add nuw nsw i32 %79, 1
%83 = icmp eq i32 %82, %132
br i1 %83, label %84, label %78
84: ; preds = %78, %71
br label %85
85: ; preds = %84, %121
%86 = phi i32 [ %122, %121 ], [ %132, %84 ]
%87 = tail call i32 @wgetch(i32* %45)
switch i32 %87, label %121 [
i32 0, label %154
i32 129, label %88
i32 128, label %94
i32 10, label %100
i32 110, label %103
i32 78, label %103
i32 113, label %106
i32 81, label %106
i32 115, label %110
i32 83, label %110
i32 114, label %114
i32 82, label %114
]
88: ; preds = %85
%89 = load i32, i32* @REQ_DOWN_ITEM
%90 = tail call i32 @menu_driver(i32* %42, i32 %89)
%91 = icmp ne i32 %86, %13
%92 = zext i1 %91 to i32
%93 = add nsw i32 %86, %92
br label %121
94: ; preds = %85
%95 = load i32, i32* @REQ_UP_ITEM
%96 = tail call i32 @menu_driver(i32* %42, i32 %95)
%97 = icmp eq i32 %86, 0
%98 = add nsw i32 %86, -1
%99 = select i1 %97, i32 0, i32 %98
br label %121
100: ; preds = %85
%101 = inttoptr i64 %31 to i32**
%102 = tail call i32 @remove_menu(i32* %42, i32** %101, i32 %10)
br label %154
103: ; preds = %85, %85
%104 = inttoptr i64 %31 to i32**
%105 = tail call i32 @remove_menu(i32* %42, i32** %104, i32 %10)
br label %154
106: ; preds = %85, %85
%107 = inttoptr i64 %31 to i32**
%108 = tail call i32 @remove_menu(i32* %42, i32** %107, i32 %10)
%109 = add nuw nsw i32 %10, 2
br label %154
110: ; preds = %85, %85
%111 = inttoptr i64 %31 to i32**
%112 = tail call i32 @remove_menu(i32* %42, i32** %111, i32 %10)
%113 = add nuw nsw i32 %10, 3
br label %154
114: ; preds = %85, %85
%115 = inttoptr i64 %31 to i32**
%116 = tail call i32 @remove_menu(i32* %42, i32** %115, i32 %10)
%117 = sext i32 %86 to i64
%118 = getelementptr inbounds i8*, i8** %5, i64 %117
%119 = load i8*, i8** %118
%120 = tail call i32 @remove_database(i8* %119)
br label %154
121: ; preds = %94, %88, %85
%122 = phi i32 [ %86, %85 ], [ %93, %88 ], [ %99, %94 ]
%123 = tail call i32 @wrefresh(i32* %45)
%124 = load i32, i32* @SIGWINCH
%125 = tail call i64 @signal(i32 %124, i32* null)
%126 = load i64, i64* @SIG_ERR
%127 = icmp eq i64 %125, %126
br i1 %127, label %85, label %128
128: ; preds = %121
%129 = tail call i32 @remove_menu(i32* %42, i32** %74, i32 %10)
%130 = tail call i32 @wrefresh(i32* %45)
br label %131
131: ; preds = %9, %128
%132 = phi i32 [ 0, %9 ], [ %122, %128 ]
br label %24
133: ; preds = %41
%134 = tail call i32 @mvwprintw(i32* %45, i32 undef, i32 2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%135 = tail call i32 @mvwprintw(i32* %45, i32 5, i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%136 = tail call i32 @wrefresh(i32* %45)
%137 = tail call i32 @curs_set(i32 0)
br label %138
138: ; preds = %148, %133
%139 = tail call i32 @wgetch(i32* %45)
switch i32 %139, label %148 [
i32 0, label %154
i32 110, label %140
i32 78, label %140
i32 113, label %144
i32 81, label %144
]
140: ; preds = %138, %138
%141 = inttoptr i64 %31 to i32**
%142 = tail call i32 @remove_menu(i32* %42, i32** %141, i32 0)
%143 = tail call i32 @curs_set(i32 1)
br label %154
144: ; preds = %138, %138
%145 = inttoptr i64 %31 to i32**
%146 = tail call i32 @remove_menu(i32* %42, i32** %145, i32 0)
%147 = tail call i32 @curs_set(i32 1)
br label %154
148: ; preds = %138
%149 = load i32, i32* @SIGWINCH
%150 = tail call i64 @signal(i32 %149, i32* null)
%151 = load i64, i64* @SIG_ERR
%152 = icmp eq i64 %150, %151
%153 = tail call i32 @wrefresh(i32* %45)
br i1 %152, label %138, label %24
154: ; preds = %85, %138, %144, %140, %114, %110, %106, %103, %100
%155 = phi i32 [ -1, %114 ], [ %113, %110 ], [ %109, %106 ], [ %11, %103 ], [ %86, %100 ], [ 2, %144 ], [ %11, %140 ], [ -1, %138 ], [ -1, %85 ]
ret i32 %155
}