#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 */
#define KEY_DOWN 131
#define KEY_NPAGE 130
#define KEY_PPAGE 129
#define KEY_UP 128
int /*<<< orphan*/ O_ONEVALUE;
int /*<<< orphan*/ REQ_DOWN_ITEM;
int /*<<< orphan*/ REQ_TOGGLE_ITEM;
int /*<<< orphan*/ REQ_UP_ITEM;
int atoi(int /*<<< orphan*/);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ *current_item(int /*<<< orphan*/ *);
int /*<<< orphan*/ curs_set(int);
int /*<<< orphan*/ derwin(int /*<<< orphan*/ *, int, int, int, int);
int /*<<< orphan*/ free_item(int /*<<< orphan*/ *);
int /*<<< orphan*/ free_menu(int /*<<< orphan*/ *);
int getch();
int /*<<< orphan*/ getmaxyx(int /*<<< orphan*/ *, int, int);
int item_count(int /*<<< orphan*/ *);
int /*<<< orphan*/ item_description(int /*<<< orphan*/ *);
int item_value(int /*<<< orphan*/ *);
int /*<<< orphan*/ keypad(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ menu_driver(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ menu_opts_off(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *new_item(char *, char *);
int /*<<< orphan*/ *new_menu(int /*<<< orphan*/ **);
int /*<<< orphan*/ pos_menu_cursor(int /*<<< orphan*/ *);
int /*<<< orphan*/ post_menu(int /*<<< orphan*/ *);
int /*<<< orphan*/ printLabel(int /*<<< orphan*/ *, int, int, char *);
int /*<<< orphan*/ scrollConsole(int);
int /*<<< orphan*/ set_menu_format(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ set_menu_mark(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ set_menu_sub(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int strlen(char *);
int /*<<< orphan*/ unpost_menu(int /*<<< orphan*/ *);
int /*<<< orphan*/ wrefresh(int /*<<< orphan*/ *);
int createScrollList(WINDOW *my_menu_win, int height, int width, int y, int x,
                     char **choices, char **desc, int n_choices,
                     int chooseEnabled, int *chooses) {
  ITEM **my_items;
  MENU *my_menu;
  int i, my_choice = -1, c = 0, choosenCount, maxx, maxy;
  char choosenCountBuffer[100];
  getmaxyx(my_menu_win, maxy, maxx);
  my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));
  for (i = 0; i < n_choices; i++)
    my_items[i] = new_item(choices[i], desc[i]);
  my_items[n_choices] = (ITEM *)NULL;
  my_menu = new_menu((ITEM **)my_items);
  if (chooses != NULL)
    menu_opts_off(my_menu, O_ONEVALUE);
  keypad(my_menu_win, 1);
  curs_set(0);
  set_menu_sub(my_menu, derwin(my_menu_win, height - 2, width - 2, y, x));
  set_menu_format(my_menu, height - y + 1, 1);
  set_menu_mark(my_menu, "* ");
  post_menu(my_menu);
  wrefresh(my_menu_win);
  while (c != 27) {
    if (chooses != NULL) {
      choosenCount = 0;
      for (i = 0; i < item_count(my_menu); i++) {
        if (item_value(my_items[i]) == 1)
          choosenCount++;
      }
      sprintf(choosenCountBuffer, "Num. de contatos escolhidos: %i",
              choosenCount);
      printLabel(my_menu_win, height + 1,
                 (maxx - strlen(choosenCountBuffer)) / 2, choosenCountBuffer);
    }
    c = getch();
    switch (c) {
    case KEY_DOWN:
      menu_driver(my_menu, REQ_DOWN_ITEM);
      break;
    case KEY_UP:
      menu_driver(my_menu, REQ_UP_ITEM);
      break;
    case KEY_NPAGE:
      scrollConsole(1);
      break;
    case ' ':
      if (chooses != NULL)
        menu_driver(my_menu, REQ_TOGGLE_ITEM);
      break;
    case KEY_PPAGE:
      scrollConsole(-1);
      break;
    case 10:
      if (chooseEnabled == 1) {
        if (chooses != NULL && choosenCount == 0)
          continue;
        my_choice = atoi(item_description(current_item(my_menu)));
        pos_menu_cursor(my_menu);
        c = 27;
      }
      break;
    }
    wrefresh(my_menu_win);
  }
  if (chooses != NULL) {
    for (i = 0; i < item_count(my_menu); ++i) {
      if (item_value(my_items[i]) == 1)
        chooses[i] = atoi(item_description(my_items[i]));
      else
        chooses[i] = -1;
    }
  }
  wrefresh(my_menu_win);
  unpost_menu(my_menu);
  free_menu(my_menu);
  for (i = 0; i <= n_choices; ++i)
    free_item(my_items[i]);
  curs_set(1);
  return my_choice;
}


x86 assembly (clang, -O0):
<createScrollList>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
movl   $0xffffffff,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x48(%rbp),%esi
mov    -0x44(%rbp),%edx
call   1100 <getmaxyx@plt>
mov    0x18(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1110 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    0x18(%rbp),%eax
jge    136c <createScrollList+0xac>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1150 <new_item@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1326 <createScrollList+0x66>
mov    -0x28(%rbp),%rax
movslq 0x18(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rdi
call   1140 <new_menu@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,0x28(%rbp)
je     13a6 <createScrollList+0xe6>
mov    -0x30(%rbp),%rdi
mov    0x2c49(%rip),%rax
mov    (%rax),%esi
call   11a0 <menu_opts_off@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   10b0 <keypad@plt>
xor    %edi,%edi
call   11d0 <curs_set@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x2,%esi
mov    -0x10(%rbp),%edx
sub    $0x2,%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   11e0 <derwin@plt>
mov    -0xb8(%rbp),%rdi
mov    %eax,%esi
call   10f0 <set_menu_sub@plt>
mov    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    -0x14(%rbp),%esi
add    $0x1,%esi
mov    $0x1,%edx
call   1180 <set_menu_format@plt>
mov    -0x30(%rbp),%rdi
lea    0xbee(%rip),%rsi
call   1120 <set_menu_mark@plt>
mov    -0x30(%rbp),%rdi
call   1080 <post_menu@plt>
mov    -0x8(%rbp),%rdi
call   10a0 <wrefresh@plt>
cmpl   $0x1b,-0x3c(%rbp)
je     1670 <createScrollList+0x3b0>
cmpq   $0x0,0x28(%rbp)
je     1513 <createScrollList+0x253>
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0xbc(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <item_count@plt>
mov    %eax,%ecx
mov    -0xbc(%rbp),%eax
cmp    %ecx,%eax
jge    14a4 <createScrollList+0x1e4>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1130 <item_value@plt>
cmp    $0x1,%eax
jne    1491 <createScrollList+0x1d1>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1496 <createScrollList+0x1d6>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    144c <createScrollList+0x18c>
lea    -0xb0(%rbp),%rdi
mov    -0x40(%rbp),%edx
lea    0xb4e(%rip),%rsi
call   11b0 <sprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0xd0(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0xc0(%rbp)
lea    -0xb0(%rbp),%rdi
call   1090 <strlen@plt>
mov    -0xd0(%rbp),%rdi
mov    -0xc4(%rbp),%esi
mov    %eax,%ecx
mov    -0xc0(%rbp),%eax
sub    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    -0xb0(%rbp),%rcx
call   11c0 <printLabel@plt>
xor    %eax,%eax
call   1160 <getch@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0xd4(%rbp)
sub    $0xa,%eax
je     160e <createScrollList+0x34e>
jmp    1534 <createScrollList+0x274>
mov    -0xd4(%rbp),%eax
sub    $0x20,%eax
je     15dd <createScrollList+0x31d>
jmp    1548 <createScrollList+0x288>
mov    -0xd4(%rbp),%eax
sub    $0x80,%eax
je     15b7 <createScrollList+0x2f7>
jmp    155e <createScrollList+0x29e>
mov    -0xd4(%rbp),%eax
sub    $0x81,%eax
je     15ff <createScrollList+0x33f>
jmp    1574 <createScrollList+0x2b4>
mov    -0xd4(%rbp),%eax
sub    $0x82,%eax
je     15ce <createScrollList+0x30e>
jmp    158a <createScrollList+0x2ca>
mov    -0xd4(%rbp),%eax
sub    $0x83,%eax
jne    1662 <createScrollList+0x3a2>
jmp    15a0 <createScrollList+0x2e0>
mov    -0x30(%rbp),%rdi
mov    0x2a1d(%rip),%rax
mov    (%rax),%esi
call   1070 <menu_driver@plt>
jmp    1662 <createScrollList+0x3a2>
mov    -0x30(%rbp),%rdi
mov    0x2a16(%rip),%rax
mov    (%rax),%esi
call   1070 <menu_driver@plt>
jmp    1662 <createScrollList+0x3a2>
mov    $0x1,%edi
call   10c0 <scrollConsole@plt>
jmp    1662 <createScrollList+0x3a2>
cmpq   $0x0,0x28(%rbp)
je     15fa <createScrollList+0x33a>
mov    -0x30(%rbp),%rdi
mov    0x29dd(%rip),%rax
mov    (%rax),%esi
call   1070 <menu_driver@plt>
jmp    1662 <createScrollList+0x3a2>
mov    $0xffffffff,%edi
call   10c0 <scrollConsole@plt>
jmp    1662 <createScrollList+0x3a2>
cmpl   $0x1,0x20(%rbp)
jne    165d <createScrollList+0x39d>
cmpq   $0x0,0x28(%rbp)
je     1632 <createScrollList+0x372>
cmpl   $0x0,-0x40(%rbp)
jne    1632 <createScrollList+0x372>
jmp    1429 <createScrollList+0x169>
mov    -0x30(%rbp),%rdi
call   1040 <current_item@plt>
mov    %rax,%rdi
call   1030 <item_description@plt>
mov    %eax,%edi
call   1190 <atoi@plt>
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1170 <pos_menu_cursor@plt>
movl   $0x1b,-0x3c(%rbp)
jmp    1662 <createScrollList+0x3a2>
mov    -0x8(%rbp),%rdi
call   10a0 <wrefresh@plt>
jmp    1429 <createScrollList+0x169>
cmpq   $0x0,0x28(%rbp)
je     170f <createScrollList+0x44f>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0xd8(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <item_count@plt>
mov    %eax,%ecx
mov    -0xd8(%rbp),%eax
cmp    %ecx,%eax
jge    170a <createScrollList+0x44a>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1130 <item_value@plt>
cmp    $0x1,%eax
jne    16e8 <createScrollList+0x428>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <item_description@plt>
mov    %eax,%edi
call   1190 <atoi@plt>
mov    %eax,%edx
mov    0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    16f7 <createScrollList+0x437>
mov    0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
jmp    16fc <createScrollList+0x43c>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1682 <createScrollList+0x3c2>
jmp    170f <createScrollList+0x44f>
mov    -0x8(%rbp),%rdi
call   10a0 <wrefresh@plt>
mov    -0x30(%rbp),%rdi
call   1060 <unpost_menu@plt>
mov    -0x30(%rbp),%rdi
call   10e0 <free_menu@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    0x18(%rbp),%eax
jg     175c <createScrollList+0x49c>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10d0 <free_item@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1731 <createScrollList+0x471>
mov    $0x1,%edi
call   11d0 <curs_set@plt>
mov    -0x38(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createScrollList>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %r9,%rbp
mov    %r8d,0x1c(%rsp)
mov    %ecx,0x4(%rsp)
mov    %edx,%r13d
mov    %rsi,0x10(%rsp)
mov    0xc8(%rsp),%ebx
mov    %rdi,0x8(%rsp)
call   1100 <getmaxyx@plt>
lea    0x1(%rbx),%edi
mov    %edi,0x18(%rsp)
mov    $0x8,%esi
call   1110 <calloc@plt>
mov    %rax,%r15
test   %ebx,%ebx
jle    134b <createScrollList+0x8b>
mov    0xc0(%rsp),%r12
mov    0xc8(%rsp),%eax
mov    %eax,%ebx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%rbp,%r14,8),%rdi
mov    (%r12,%r14,8),%rsi
call   1150 <new_item@plt>
mov    %rax,(%r15,%r14,8)
add    $0x1,%r14
cmp    %r14,%rbx
jne    1330 <createScrollList+0x70>
mov    0xc8(%rsp),%eax
cltq
movq   $0x0,(%r15,%rax,8)
mov    %r15,%rdi
call   1140 <new_menu@plt>
mov    %rax,%rbp
cmpq   $0x0,0xd8(%rsp)
je     1383 <createScrollList+0xc3>
mov    0x2c6f(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   11a0 <menu_opts_off@plt>
mov    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%esi
call   10b0 <keypad@plt>
xor    %edi,%edi
call   11d0 <curs_set@plt>
mov    0x10(%rsp),%rbx
lea    -0x2(%rbx),%esi
add    $0xfffffffe,%r13d
mov    %r14,%rdi
mov    %r13d,%edx
mov    0x4(%rsp),%r12d
mov    %r12d,%ecx
mov    0x1c(%rsp),%r8d
call   11e0 <derwin@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   10f0 <set_menu_sub@plt>
add    $0x1,%ebx
mov    %rbx,0x10(%rsp)
mov    %ebx,%esi
sub    %r12d,%esi
mov    %rbp,%rdi
mov    $0x1,%edx
call   1180 <set_menu_format@plt>
lea    0xc25(%rip),%rsi
mov    %rbp,%rdi
call   1120 <set_menu_mark@plt>
mov    %rbp,%rdi
call   1080 <post_menu@plt>
mov    %r14,%rdi
call   10a0 <wrefresh@plt>
movl   $0xffffffff,0x4(%rsp)
ff
lea    0x20(%rsp),%r13
xor    %r12d,%r12d
mov    0xd8(%rsp),%rbx
jmp    143a <createScrollList+0x17a>
mov    $0xffffffff,%edi
call   10c0 <scrollConsole@plt>
mov    $0x81,%r12d
nopl   (%rax)
mov    0x8(%rsp),%rdi
call   10a0 <wrefresh@plt>
mov    %r14d,%eax
cmp    $0x1b,%r12d
je     15db <createScrollList+0x31b>
mov    %eax,%r14d
test   %rbx,%rbx
je     14c9 <createScrollList+0x209>
mov    %rbp,%rdi
call   1050 <item_count@plt>
test   %eax,%eax
jle    1490 <createScrollList+0x1d0>
xor    %ebx,%ebx
xor    %r14d,%r14d
mov    (%r15,%rbx,8),%rdi
call   1130 <item_value@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
sete   %cl
add    %ecx,%r14d
add    $0x1,%rbx
mov    %rbp,%rdi
call   1050 <item_count@plt>
cltq
cmp    %rax,%rbx
jl     1460 <createScrollList+0x1a0>
jmp    1493 <createScrollList+0x1d3>
nopl   0x0(%rax)
xor    %r14d,%r14d
mov    %r13,%rdi
lea    0xb76(%rip),%rsi
mov    %r14d,%edx
call   11b0 <sprintf@plt>
mov    %r13,%rdi
call   1090 <strlen@plt>
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
xor    %edx,%edx
mov    %r13,%rcx
call   11c0 <printLabel@plt>
mov    0xd8(%rsp),%rbx
xor    %eax,%eax
call   1160 <getch@plt>
cmp    $0xa,%eax
jne    1530 <createScrollList+0x270>
cmpl   $0x1,0xd0(%rsp)
01
jne    15d0 <createScrollList+0x310>
test   %rbx,%rbx
je     14f9 <createScrollList+0x239>
xor    %eax,%eax
mov    $0xa,%r12d
test   %r14d,%r14d
je     143d <createScrollList+0x17d>
mov    %rbp,%rdi
call   1040 <current_item@plt>
mov    %rax,%rdi
call   1030 <item_description@plt>
mov    %eax,%edi
call   1190 <atoi@plt>
mov    %eax,0x4(%rsp)
mov    %rbp,%rdi
call   1170 <pos_menu_cursor@plt>
mov    $0x1b,%r12d
jmp    1430 <createScrollList+0x170>
nopw   0x0(%rax,%rax,1)
mov    %eax,%r12d
lea    -0x80(%r12),%eax
cmp    $0x3,%eax
ja     1570 <createScrollList+0x2b0>
lea    0xabc(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2a84(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1070 <menu_driver@plt>
mov    $0x80,%r12d
jmp    1430 <createScrollList+0x170>
nopl   0x0(%rax)
cmp    $0x20,%r12d
jne    1430 <createScrollList+0x170>
mov    $0x20,%r12d
test   %rbx,%rbx
je     1430 <createScrollList+0x170>
mov    0x2a40(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1070 <menu_driver@plt>
jmp    1430 <createScrollList+0x170>
mov    $0x1,%edi
call   10c0 <scrollConsole@plt>
mov    $0x82,%r12d
jmp    1430 <createScrollList+0x170>
mov    0x2a0d(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1070 <menu_driver@plt>
mov    $0x83,%r12d
jmp    1430 <createScrollList+0x170>
mov    $0xa,%r12d
jmp    1430 <createScrollList+0x170>
test   %rbx,%rbx
je     1635 <createScrollList+0x375>
mov    %rbp,%rdi
call   1050 <item_count@plt>
test   %eax,%eax
jle    1635 <createScrollList+0x375>
xor    %ebx,%ebx
jmp    160e <createScrollList+0x34e>
mov    0xd8(%rsp),%rcx
mov    %eax,(%rcx,%rbx,4)
add    $0x1,%rbx
mov    %rbp,%rdi
call   1050 <item_count@plt>
cltq
cmp    %rax,%rbx
jge    1635 <createScrollList+0x375>
mov    (%r15,%rbx,8),%rdi
call   1130 <item_value@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x1,%ecx
jne    15f0 <createScrollList+0x330>
mov    (%r15,%rbx,8),%rdi
call   1030 <item_description@plt>
mov    %eax,%edi
call   1190 <atoi@plt>
jmp    15f0 <createScrollList+0x330>
mov    0x8(%rsp),%rdi
call   10a0 <wrefresh@plt>
mov    %rbp,%rdi
call   1060 <unpost_menu@plt>
mov    %rbp,%rdi
call   10e0 <free_menu@plt>
mov    0xc8(%rsp),%eax
test   %eax,%eax
js     1672 <createScrollList+0x3b2>
mov    0x18(%rsp),%ebx
xor    %ebp,%ebp
mov    (%r15,%rbp,8),%rdi
call   10d0 <free_item@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1660 <createScrollList+0x3a0>
mov    $0x1,%edi
call   11d0 <curs_set@plt>
mov    0x4(%rsp),%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_ONEVALUE = global i32 0
@.str = [3 x i8] c"* \00"
@.str.1 = [32 x i8] c"Num. de contatos escolhidos: %i\00"
@REQ_DOWN_ITEM = global i32 0
@REQ_UP_ITEM = global i32 0
@REQ_TOGGLE_ITEM = global i32 0
define i32 @createScrollList(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4, i8** %5, i8** %6, i32 %7, i32 %8, i32* %9) {
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8**
%17 = alloca i8**
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32*
%21 = alloca i32**
%22 = alloca i32*
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca [100 x i8]
store i32* %0, i32** %11
store i32 %1, i32* %12
store i32 %2, i32* %13
store i32 %3, i32* %14
store i32 %4, i32* %15
store i8** %5, i8*** %16
store i8** %6, i8*** %17
store i32 %7, i32* %18
store i32 %8, i32* %19
store i32* %9, i32** %20
store i32 -1, i32* %24
store i32 0, i32* %25
%30 = load i32*, i32** %11
%31 = load i32, i32* %28
%32 = load i32, i32* %27
%33 = call i32 @getmaxyx(i32* %30, i32 %31, i32 %32)
%34 = load i32, i32* %18
%35 = add nsw i32 %34, 1
%36 = call i64 @calloc(i32 %35, i32 8)
%37 = inttoptr i64 %36 to i32**
store i32** %37, i32*** %21
store i32 0, i32* %23
br label %38
38: ; preds = %58, %10
%39 = load i32, i32* %23
%40 = load i32, i32* %18
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %61
42: ; preds = %38
%43 = load i8**, i8*** %16
%44 = load i32, i32* %23
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = load i8**, i8*** %17
%49 = load i32, i32* %23
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = call i32* @new_item(i8* %47, i8* %52)
%54 = load i32**, i32*** %21
%55 = load i32, i32* %23
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32*, i32** %54, i64 %56
store i32* %53, i32** %57
br label %58
58: ; preds = %42
%59 = load i32, i32* %23
%60 = add nsw i32 %59, 1
store i32 %60, i32* %23
br label %38
61: ; preds = %38
%62 = load i32**, i32*** %21
%63 = load i32, i32* %18
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32*, i32** %62, i64 %64
store i32* null, i32** %65
%66 = load i32**, i32*** %21
%67 = call i32* @new_menu(i32** %66)
store i32* %67, i32** %22
%68 = load i32*, i32** %20
%69 = icmp ne i32* %68, null
br i1 %69, label %70, label %74
70: ; preds = %61
%71 = load i32*, i32** %22
%72 = load i32, i32* @O_ONEVALUE
%73 = call i32 @menu_opts_off(i32* %71, i32 %72)
br label %74
74: ; preds = %70, %61
%75 = load i32*, i32** %11
%76 = call i32 @keypad(i32* %75, i32 1)
%77 = call i32 @curs_set(i32 0)
%78 = load i32*, i32** %22
%79 = load i32*, i32** %11
%80 = load i32, i32* %12
%81 = sub nsw i32 %80, 2
%82 = load i32, i32* %13
%83 = sub nsw i32 %82, 2
%84 = load i32, i32* %14
%85 = load i32, i32* %15
%86 = call i32 @derwin(i32* %79, i32 %81, i32 %83, i32 %84, i32 %85)
%87 = call i32 @set_menu_sub(i32* %78, i32 %86)
%88 = load i32*, i32** %22
%89 = load i32, i32* %12
%90 = load i32, i32* %14
%91 = sub nsw i32 %89, %90
%92 = add nsw i32 %91, 1
%93 = call i32 @set_menu_format(i32* %88, i32 %92, i32 1)
%94 = load i32*, i32** %22
%95 = call i32 @set_menu_mark(i32* %94, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%96 = load i32*, i32** %22
%97 = call i32 @post_menu(i32* %96)
%98 = load i32*, i32** %11
%99 = call i32 @wrefresh(i32* %98)
br label %100
100: ; preds = %182, %173, %74
%101 = load i32, i32* %25
%102 = icmp ne i32 %101, 27
br i1 %102, label %103, label %185
103: ; preds = %100
%104 = load i32*, i32** %20
%105 = icmp ne i32* %104, null
br i1 %105, label %106, label %141
106: ; preds = %103
store i32 0, i32* %26
store i32 0, i32* %23
br label %107
107: ; preds = %124, %106
%108 = load i32, i32* %23
%109 = load i32*, i32** %22
%110 = call i32 @item_count(i32* %109)
%111 = icmp slt i32 %108, %110
br i1 %111, label %112, label %127
112: ; preds = %107
%113 = load i32**, i32*** %21
%114 = load i32, i32* %23
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds i32*, i32** %113, i64 %115
%117 = load i32*, i32** %116
%118 = call i32 @item_value(i32* %117)
%119 = icmp eq i32 %118, 1
br i1 %119, label %120, label %123
120: ; preds = %112
%121 = load i32, i32* %26
%122 = add nsw i32 %121, 1
store i32 %122, i32* %26
br label %123
123: ; preds = %120, %112
br label %124
124: ; preds = %123
%125 = load i32, i32* %23
%126 = add nsw i32 %125, 1
store i32 %126, i32* %23
br label %107
127: ; preds = %107
%128 = getelementptr inbounds [100 x i8], [100 x i8]* %29, i64 0, i64 0
%129 = load i32, i32* %26
%130 = call i32 @sprintf(i8* %128, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %129)
%131 = load i32*, i32** %11
%132 = load i32, i32* %12
%133 = add nsw i32 %132, 1
%134 = load i32, i32* %27
%135 = getelementptr inbounds [100 x i8], [100 x i8]* %29, i64 0, i64 0
%136 = call i32 @strlen(i8* %135)
%137 = sub nsw i32 %134, %136
%138 = sdiv i32 %137, 2
%139 = getelementptr inbounds [100 x i8], [100 x i8]* %29, i64 0, i64 0
%140 = call i32 @printLabel(i32* %131, i32 %133, i32 %138, i8* %139)
br label %141
141: ; preds = %127, %103
%142 = call i32 (...) @getch()
store i32 %142, i32* %25
%143 = load i32, i32* %25
switch i32 %143, label %182 [
i32 131, label %144
i32 128, label %148
i32 130, label %152
i32 32, label %154
i32 129, label %162
i32 10, label %164
]
144: ; preds = %141
%145 = load i32*, i32** %22
%146 = load i32, i32* @REQ_DOWN_ITEM
%147 = call i32 @menu_driver(i32* %145, i32 %146)
br label %182
148: ; preds = %141
%149 = load i32*, i32** %22
%150 = load i32, i32* @REQ_UP_ITEM
%151 = call i32 @menu_driver(i32* %149, i32 %150)
br label %182
152: ; preds = %141
%153 = call i32 @scrollConsole(i32 1)
br label %182
154: ; preds = %141
%155 = load i32*, i32** %20
%156 = icmp ne i32* %155, null
br i1 %156, label %157, label %161
157: ; preds = %154
%158 = load i32*, i32** %22
%159 = load i32, i32* @REQ_TOGGLE_ITEM
%160 = call i32 @menu_driver(i32* %158, i32 %159)
br label %161
161: ; preds = %157, %154
br label %182
162: ; preds = %141
%163 = call i32 @scrollConsole(i32 -1)
br label %182
164: ; preds = %141
%165 = load i32, i32* %19
%166 = icmp eq i32 %165, 1
br i1 %166, label %167, label %181
167: ; preds = %164
%168 = load i32*, i32** %20
%169 = icmp ne i32* %168, null
br i1 %169, label %170, label %174
170: ; preds = %167
%171 = load i32, i32* %26
%172 = icmp eq i32 %171, 0
br i1 %172, label %173, label %174
173: ; preds = %170
br label %100
174: ; preds = %170, %167
%175 = load i32*, i32** %22
%176 = call i32* @current_item(i32* %175)
%177 = call i32 @item_description(i32* %176)
%178 = call i32 @atoi(i32 %177)
store i32 %178, i32* %24
%179 = load i32*, i32** %22
%180 = call i32 @pos_menu_cursor(i32* %179)
store i32 27, i32* %25
br label %181
181: ; preds = %174, %164
br label %182
182: ; preds = %141, %181, %162, %161, %152, %148, %144
%183 = load i32*, i32** %11
%184 = call i32 @wrefresh(i32* %183)
br label %100
185: ; preds = %100
%186 = load i32*, i32** %20
%187 = icmp ne i32* %186, null
br i1 %187, label %188, label %224
188: ; preds = %185
store i32 0, i32* %23
br label %189
189: ; preds = %220, %188
%190 = load i32, i32* %23
%191 = load i32*, i32** %22
%192 = call i32 @item_count(i32* %191)
%193 = icmp slt i32 %190, %192
br i1 %193, label %194, label %223
194: ; preds = %189
%195 = load i32**, i32*** %21
%196 = load i32, i32* %23
%197 = sext i32 %196 to i64
%198 = getelementptr inbounds i32*, i32** %195, i64 %197
%199 = load i32*, i32** %198
%200 = call i32 @item_value(i32* %199)
%201 = icmp eq i32 %200, 1
br i1 %201, label %202, label %214
202: ; preds = %194
%203 = load i32**, i32*** %21
%204 = load i32, i32* %23
%205 = sext i32 %204 to i64
%206 = getelementptr inbounds i32*, i32** %203, i64 %205
%207 = load i32*, i32** %206
%208 = call i32 @item_description(i32* %207)
%209 = call i32 @atoi(i32 %208)
%210 = load i32*, i32** %20
%211 = load i32, i32* %23
%212 = sext i32 %211 to i64
%213 = getelementptr inbounds i32, i32* %210, i64 %212
store i32 %209, i32* %213
br label %219
214: ; preds = %194
%215 = load i32*, i32** %20
%216 = load i32, i32* %23
%217 = sext i32 %216 to i64
%218 = getelementptr inbounds i32, i32* %215, i64 %217
store i32 -1, i32* %218
br label %219
219: ; preds = %214, %202
br label %220
220: ; preds = %219
%221 = load i32, i32* %23
%222 = add nsw i32 %221, 1
store i32 %222, i32* %23
br label %189
223: ; preds = %189
br label %224
224: ; preds = %223, %185
%225 = load i32*, i32** %11
%226 = call i32 @wrefresh(i32* %225)
%227 = load i32*, i32** %22
%228 = call i32 @unpost_menu(i32* %227)
%229 = load i32*, i32** %22
%230 = call i32 @free_menu(i32* %229)
store i32 0, i32* %23
br label %231
231: ; preds = %242, %224
%232 = load i32, i32* %23
%233 = load i32, i32* %18
%234 = icmp sle i32 %232, %233
br i1 %234, label %235, label %245
235: ; preds = %231
%236 = load i32**, i32*** %21
%237 = load i32, i32* %23
%238 = sext i32 %237 to i64
%239 = getelementptr inbounds i32*, i32** %236, i64 %238
%240 = load i32*, i32** %239
%241 = call i32 @free_item(i32* %240)
br label %242
242: ; preds = %235
%243 = load i32, i32* %23
%244 = add nsw i32 %243, 1
store i32 %244, i32* %23
br label %231
245: ; preds = %231
%246 = call i32 @curs_set(i32 1)
%247 = load i32, i32* %24
ret i32 %247
}

LLVM IR (-O2):
@O_ONEVALUE = global i32 0
@.str = [3 x i8] c"* \00"
@.str.1 = [32 x i8] c"Num. de contatos escolhidos: %i\00"
@REQ_DOWN_ITEM = global i32 0
@REQ_UP_ITEM = global i32 0
@REQ_TOGGLE_ITEM = global i32 0
define i32 @createScrollList(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4, i8** nocapture %5, i8** nocapture %6, i32 %7, i32 %8, i32* writeonly %9) {
%11 = alloca [100 x i8]
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%13 = tail call i32 @getmaxyx(i32* %0, i32 undef, i32 undef)
%14 = add i32 %7, 1
%15 = tail call i64 @calloc(i32 %14, i32 8)
%16 = inttoptr i64 %15 to i32**
%17 = icmp sgt i32 %7, 0
br i1 %17, label %18, label %30
18: ; preds = %10
%19 = zext i32 %7 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 0, %18 ], [ %28, %20 ]
%22 = getelementptr inbounds i8*, i8** %5, i64 %21
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8*, i8** %6, i64 %21
%25 = load i8*, i8** %24
%26 = tail call i32* @new_item(i8* %23, i8* %25)
%27 = getelementptr inbounds i32*, i32** %16, i64 %21
store i32* %26, i32** %27
%28 = add nuw nsw i64 %21, 1
%29 = icmp eq i64 %28, %19
br i1 %29, label %30, label %20
30: ; preds = %20, %10
%31 = sext i32 %7 to i64
%32 = getelementptr inbounds i32*, i32** %16, i64 %31
store i32* null, i32** %32
%33 = tail call i32* @new_menu(i32** %16)
%34 = icmp ne i32* %9, null
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i32, i32* @O_ONEVALUE
%37 = tail call i32 @menu_opts_off(i32* %33, i32 %36)
br label %38
38: ; preds = %35, %30
%39 = tail call i32 @keypad(i32* %0, i32 1)
%40 = tail call i32 @curs_set(i32 0)
%41 = add nsw i32 %1, -2
%42 = add nsw i32 %2, -2
%43 = tail call i32 @derwin(i32* %0, i32 %41, i32 %42, i32 %3, i32 %4)
%44 = tail call i32 @set_menu_sub(i32* %33, i32 %43)
%45 = add i32 %1, 1
%46 = sub i32 %45, %3
%47 = tail call i32 @set_menu_format(i32* %33, i32 %46, i32 1)
%48 = tail call i32 @set_menu_mark(i32* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%49 = tail call i32 @post_menu(i32* %33)
%50 = tail call i32 @wrefresh(i32* %0)
%51 = icmp eq i32 %8, 1
br label %52
52: ; preds = %108, %38
%53 = phi i32 [ %109, %108 ], [ -1, %38 ]
%54 = phi i32 [ %110, %108 ], [ 0, %38 ]
%55 = phi i32 [ %83, %108 ], [ undef, %38 ]
br label %56
56: ; preds = %52, %100
%57 = phi i32 [ 10, %100 ], [ %54, %52 ]
%58 = phi i32 [ 0, %100 ], [ %55, %52 ]
%59 = icmp eq i32 %57, 27
br i1 %59, label %112, label %60
60: ; preds = %56
br i1 %34, label %61, label %82
61: ; preds = %60
%62 = call i32 @item_count(i32* %33)
%63 = icmp sgt i32 %62, 0
br i1 %63, label %64, label %77
64: ; preds = %61, %64
%65 = phi i64 [ %73, %64 ], [ 0, %61 ]
%66 = phi i32 [ %72, %64 ], [ 0, %61 ]
%67 = getelementptr inbounds i32*, i32** %16, i64 %65
%68 = load i32*, i32** %67
%69 = call i32 @item_value(i32* %68)
%70 = icmp eq i32 %69, 1
%71 = zext i1 %70 to i32
%72 = add nuw nsw i32 %66, %71
%73 = add nuw nsw i64 %65, 1
%74 = call i32 @item_count(i32* %33)
%75 = sext i32 %74 to i64
%76 = icmp slt i64 %73, %75
br i1 %76, label %64, label %77
77: ; preds = %64, %61
%78 = phi i32 [ 0, %61 ], [ %72, %64 ]
%79 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %78)
%80 = call i32 @strlen(i8* %12)
%81 = call i32 @printLabel(i32* %0, i32 %45, i32 0, i8* %12)
br label %82
82: ; preds = %77, %60
%83 = phi i32 [ %78, %77 ], [ %58, %60 ]
%84 = call i32 (...) @getch()
switch i32 %84, label %108 [
i32 131, label %85
i32 128, label %88
i32 130, label %91
i32 32, label %93
i32 129, label %97
i32 10, label %99
]
85: ; preds = %82
%86 = load i32, i32* @REQ_DOWN_ITEM
%87 = call i32 @menu_driver(i32* %33, i32 %86)
br label %108
88: ; preds = %82
%89 = load i32, i32* @REQ_UP_ITEM
%90 = call i32 @menu_driver(i32* %33, i32 %89)
br label %108
91: ; preds = %82
%92 = call i32 @scrollConsole(i32 1)
br label %108
93: ; preds = %82
br i1 %34, label %94, label %108
94: ; preds = %93
%95 = load i32, i32* @REQ_TOGGLE_ITEM
%96 = call i32 @menu_driver(i32* %33, i32 %95)
br label %108
97: ; preds = %82
%98 = call i32 @scrollConsole(i32 -1)
br label %108
99: ; preds = %82
br i1 %51, label %100, label %108
100: ; preds = %99
%101 = icmp eq i32 %83, 0
%102 = select i1 %34, i1 %101, i1 false
br i1 %102, label %56, label %103
103: ; preds = %100
%104 = call i32* @current_item(i32* %33)
%105 = call i32 @item_description(i32* %104)
%106 = call i32 @atoi(i32 %105)
%107 = call i32 @pos_menu_cursor(i32* %33)
br label %108
108: ; preds = %99, %82, %103, %93, %94, %97, %91, %88, %85
%109 = phi i32 [ %106, %103 ], [ %53, %97 ], [ %53, %94 ], [ %53, %93 ], [ %53, %91 ], [ %53, %88 ], [ %53, %85 ], [ %53, %82 ], [ %53, %99 ]
%110 = phi i32 [ 27, %103 ], [ 129, %97 ], [ 32, %94 ], [ 32, %93 ], [ 130, %91 ], [ 128, %88 ], [ 131, %85 ], [ 10, %99 ], [ %84, %82 ]
%111 = call i32 @wrefresh(i32* %0)
br label %52
112: ; preds = %56
br i1 %34, label %113, label %133
113: ; preds = %112
%114 = call i32 @item_count(i32* %33)
%115 = icmp sgt i32 %114, 0
br i1 %115, label %116, label %133
116: ; preds = %113, %126
%117 = phi i64 [ %129, %126 ], [ 0, %113 ]
%118 = getelementptr inbounds i32*, i32** %16, i64 %117
%119 = load i32*, i32** %118
%120 = call i32 @item_value(i32* %119)
%121 = icmp eq i32 %120, 1
br i1 %121, label %122, label %126
122: ; preds = %116
%123 = load i32*, i32** %118
%124 = call i32 @item_description(i32* %123)
%125 = call i32 @atoi(i32 %124)
br label %126
126: ; preds = %116, %122
%127 = phi i32 [ %125, %122 ], [ -1, %116 ]
%128 = getelementptr inbounds i32, i32* %9, i64 %117
store i32 %127, i32* %128
%129 = add nuw nsw i64 %117, 1
%130 = call i32 @item_count(i32* %33)
%131 = sext i32 %130 to i64
%132 = icmp slt i64 %129, %131
br i1 %132, label %116, label %133
133: ; preds = %126, %113, %112
%134 = call i32 @wrefresh(i32* %0)
%135 = call i32 @unpost_menu(i32* %33)
%136 = call i32 @free_menu(i32* %33)
%137 = icmp slt i32 %7, 0
br i1 %137, label %147, label %138
138: ; preds = %133
%139 = zext i32 %14 to i64
br label %140
140: ; preds = %138, %140
%141 = phi i64 [ 0, %138 ], [ %145, %140 ]
%142 = getelementptr inbounds i32*, i32** %16, i64 %141
%143 = load i32*, i32** %142
%144 = call i32 @free_item(i32* %143)
%145 = add nuw nsw i64 %141, 1
%146 = icmp eq i64 %145, %139
br i1 %146, label %147, label %140
147: ; preds = %140, %133
%148 = call i32 @curs_set(i32 1)
ret i32 %53
}