// File: /workspace/github_c_makefile_star2_O0/kobolt[P]curses-collection/menu/menu.c
// Function: main
int main(int argc, char *argv[])
{
  int c, maxy, maxx;
  char line[TEXT_LIMIT], *p;
  FILE *fh;

  if (argc != 2) {
    printf("Usage: %s <file with menu lines>\n", argv[0]);
    return 0;
  }

  fh = fopen(argv[1], "r");
  if (fh == NULL) {
    printf("Error: Unable to open menu file for reading.\n");
    return 0;
  }

  while (fgets(line, TEXT_LIMIT, fh) != NULL) {
    for (p = line; *p != '\0'; p++) {
      if ((*p == '\r') || (*p == '\n')) {
        *p = '\0';
        break;
      }
    }
    strncpy(list[list_size], line, TEXT_LIMIT);
    list_size++;
    if (list_size == ENTRY_LIMIT)
      break;
  }
  fclose(fh);

  signal(SIGINT, interrupt_handler);

  initscr();
  atexit(exit_handler);
  noecho();
  keypad(stdscr, TRUE);

  while (1) {
    update_screen();
    getmaxyx(stdscr, maxy, maxx);
    c = getch();

    switch (c) {
    case KEY_RESIZE:
      /* Use this event instead of SIGWINCH for better portability. */
      winch_handler();
      break;

    case KEY_UP:
      selected_entry--;
      if (selected_entry < 0)
        selected_entry++;
      if (scroll_offset > selected_entry) {
        scroll_offset--;
        if (scroll_offset < 0)
          scroll_offset = 0;
      }
      break;

    case KEY_DOWN:
      selected_entry++;
      if (selected_entry >= list_size)
        selected_entry--;
      if (selected_entry > maxy - 1) {
        scroll_offset++;
        if (scroll_offset > selected_entry - maxy + 1)
          scroll_offset--;
      }
      break;

    case KEY_NPAGE:
      scroll_offset += maxy / 2;
      while (maxy + scroll_offset > list_size)
        scroll_offset--;
      if (scroll_offset < 0)
        scroll_offset = 0;
      if (selected_entry < scroll_offset)
        selected_entry = scroll_offset;
      break;

    case KEY_PPAGE:
      scroll_offset -= maxy / 2;
      if (scroll_offset < 0)
        scroll_offset = 0;
      if (selected_entry > maxy + scroll_offset - 1)
        selected_entry = maxy + scroll_offset - 1;
      break;

    case KEY_ENTER:
    case '\n':
    case '\r':
      /* Need to start at 1 to differentiate between a valid selection
         and other kinds of exits, that returns 0. */
      return selected_entry + 1;

    case '\e': /* Escape */
    case 'Q':
    case 'q':
      return 0;
    }

  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
je 0x12d0
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0xd47(%rip), %rdi       # 0x2004
movb $0x0, %al
callq 0x10a0
movl $0x0, -0x4(%rbp)
jmp 0x1731
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xd47(%rip), %rsi       # 0x2026
callq 0x1100
movq %rax, -0xb0(%rbp)
cmpq $0x0, -0xb0(%rbp)
jne 0x130f
leaq 0xd2c(%rip), %rdi       # 0x2028
movb $0x0, %al
callq 0x10a0
movl $0x0, -0x4(%rbp)
jmp 0x1731
jmp 0x1311
leaq -0xa0(%rbp), %rdi
movq -0xb0(%rbp), %rdx
movl $0x80, %esi
callq 0x10e0
cmpq $0x0, %rax
je 0x13d8
leaq -0xa0(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x1390
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xd, %eax
je 0x136e
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x137a
movq -0xa8(%rbp), %rax
movb $0x0, (%rax)
jmp 0x1390
jmp 0x137c
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
jmp 0x1341
movslq 0xacd9(%rip), %rax      # 0xc070
leaq 0x2d52(%rip), %rdi      # 0x40f0
shlq $0x7, %rax
addq %rax, %rdi
leaq -0xa0(%rbp), %rsi
movl $0x80, %edx
callq 0x1050
movl 0xacb4(%rip), %eax      # 0xc070
addl $0x1, %eax
movl %eax, 0xacab(%rip)      # 0xc070
cmpl $0xff, 0xaca1(%rip)     # 0xc070
jne 0x13d3
jmp 0x13d8
jmp 0x1311
movq -0xb0(%rbp), %rdi
callq 0x1070
movl $0x2, %edi
leaq 0x350(%rip), %rsi       # 0x1740
callq 0x10f0
callq 0x10b0
leaq 0x35f(%rip), %rdi       # 0x1760
callq 0x1ad0
callq 0x1090
movq 0x2bce(%rip), %rax      # 0x3fe0
movq (%rax), %rdi
movl $0x1, %esi
callq 0x10c0
callq 0x1770
xorl %eax, %eax
movq 0x2bb3(%rip), %rcx      # 0x3fe0
cmpq (%rcx), %rax
je 0x144b
movq 0x2ba7(%rip), %rax      # 0x3fe0
movq (%rax), %rax
movswl 0x4(%rax), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x1458
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0xb4(%rbp)
jmp 0x1458
movl -0xb4(%rbp), %eax
movl %eax, -0x18(%rbp)
xorl %eax, %eax
movq 0x2b76(%rip), %rcx      # 0x3fe0
cmpq (%rcx), %rax
je 0x1488
movq 0x2b6a(%rip), %rax      # 0x3fe0
movq (%rax), %rax
movswl 0x6(%rax), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0x1495
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0xb8(%rbp)
jmp 0x1495
movl -0xb8(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq 0x2b3b(%rip), %rax      # 0x3fe0
movq (%rax), %rdi
callq 0x1060
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0xbc(%rbp)
subl $0xa, %eax
je 0x1715
jmp 0x14c4
movl -0xbc(%rbp), %eax
subl $0xd, %eax
je 0x1715
jmp 0x14d5
movl -0xbc(%rbp), %eax
subl $0x1b, %eax
je 0x1723
jmp 0x14e6
movl -0xbc(%rbp), %eax
subl $0x51, %eax
je 0x1723
jmp 0x14f7
movl -0xbc(%rbp), %eax
subl $0x71, %eax
je 0x1723
jmp 0x1508
movl -0xbc(%rbp), %eax
subl $0x102, %eax            # imm = 0x102
je 0x15de
jmp 0x151b
movl -0xbc(%rbp), %eax
subl $0x103, %eax            # imm = 0x103
je 0x1580
jmp 0x152a
movl -0xbc(%rbp), %eax
subl $0x152, %eax            # imm = 0x152
je 0x1655
jmp 0x153d
movl -0xbc(%rbp), %eax
subl $0x153, %eax            # imm = 0x153
je 0x16bd
jmp 0x1550
movl -0xbc(%rbp), %eax
subl $0x157, %eax            # imm = 0x157
je 0x1715
jmp 0x1563
movl -0xbc(%rbp), %eax
subl $0x19a, %eax            # imm = 0x19A
jne 0x172c
jmp 0x1576
callq 0x1aa0
jmp 0x172c
movl 0xaaee(%rip), %eax      # 0xc074
addl $-0x1, %eax
movl %eax, 0xaae5(%rip)      # 0xc074
cmpl $0x0, 0xaade(%rip)      # 0xc074
jge 0x15a7
movl 0xaad6(%rip), %eax      # 0xc074
addl $0x1, %eax
movl %eax, 0xaacd(%rip)      # 0xc074
movl 0xaacb(%rip), %eax      # 0xc078
cmpl 0xaac1(%rip), %eax      # 0xc074
jle 0x15d9
movl 0xaabd(%rip), %eax      # 0xc078
addl $-0x1, %eax
movl %eax, 0xaab4(%rip)      # 0xc078
cmpl $0x0, 0xaaad(%rip)      # 0xc078
jge 0x15d7
movl $0x0, 0xaaa1(%rip)      # 0xc078
jmp 0x15d9
jmp 0x172c
movl 0xaa90(%rip), %eax      # 0xc074
addl $0x1, %eax
movl %eax, 0xaa87(%rip)      # 0xc074
movl 0xaa81(%rip), %eax      # 0xc074
cmpl 0xaa77(%rip), %eax      # 0xc070
jl 0x160a
movl 0xaa73(%rip), %eax      # 0xc074
addl $-0x1, %eax
movl %eax, 0xaa6a(%rip)      # 0xc074
movl 0xaa64(%rip), %eax      # 0xc074
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x1650
movl 0xaa58(%rip), %eax      # 0xc078
addl $0x1, %eax
movl %eax, 0xaa4f(%rip)      # 0xc078
movl 0xaa49(%rip), %eax      # 0xc078
movl 0xaa3f(%rip), %ecx      # 0xc074
subl -0x18(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x164e
movl 0xaa33(%rip), %eax      # 0xc078
addl $-0x1, %eax
movl %eax, 0xaa2a(%rip)      # 0xc078
jmp 0x1650
jmp 0x172c
movl -0x18(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
addl 0xaa12(%rip), %eax      # 0xc078
movl %eax, 0xaa0c(%rip)      # 0xc078
movl -0x18(%rbp), %eax
addl 0xaa03(%rip), %eax      # 0xc078
cmpl 0xa9f5(%rip), %eax      # 0xc070
jle 0x168e
movl 0xa9f5(%rip), %eax      # 0xc078
addl $-0x1, %eax
movl %eax, 0xa9ec(%rip)      # 0xc078
jmp 0x166c
cmpl $0x0, 0xa9e3(%rip)      # 0xc078
jge 0x16a1
movl $0x0, 0xa9d7(%rip)      # 0xc078
movl 0xa9cd(%rip), %eax      # 0xc074
cmpl 0xa9cb(%rip), %eax      # 0xc078
jge 0x16bb
movl 0xa9c3(%rip), %eax      # 0xc078
movl %eax, 0xa9b9(%rip)      # 0xc074
jmp 0x172c
movl -0x18(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl 0xa9a8(%rip), %eax      # 0xc078
subl %ecx, %eax
movl %eax, 0xa9a0(%rip)      # 0xc078
cmpl $0x0, 0xa999(%rip)      # 0xc078
jge 0x16eb
movl $0x0, 0xa98d(%rip)      # 0xc078
movl 0xa983(%rip), %eax      # 0xc074
movl -0x18(%rbp), %ecx
addl 0xa97e(%rip), %ecx      # 0xc078
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x1713
movl -0x18(%rbp), %eax
addl 0xa96e(%rip), %eax      # 0xc078
subl $0x1, %eax
movl %eax, 0xa961(%rip)      # 0xc074
jmp 0x172c
movl 0xa959(%rip), %eax      # 0xc074
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x1731
movl $0x0, -0x4(%rbp)
jmp 0x1731
jmp 0x141f
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)