// File: /workspace/github_c_makefile_star2_O2/kobolt[P]curses-collection/difftree/navi.c
// Function: diff_navi_loop
void diff_navi_loop(diff_node_t *node, char *root1, char *root2)
{
  int c, maxy, maxx, list_size;

  initscr();
  atexit(diff_navi_exit_handler);
  if (has_colors()) {
    start_color();
    init_pair(COLOR_EQUAL,            COLOR_WHITE,   COLOR_BLACK);
    init_pair(COLOR_DIFFERS,          COLOR_MAGENTA, COLOR_BLACK);
    init_pair(COLOR_ADDED,            COLOR_BLUE,    COLOR_BLACK);
    init_pair(COLOR_MISSING,          COLOR_RED,     COLOR_BLACK);
    init_pair(COLOR_SELECTED_EQUAL,   COLOR_BLACK,   COLOR_WHITE);
    init_pair(COLOR_SELECTED_DIFFERS, COLOR_MAGENTA, COLOR_WHITE);
    init_pair(COLOR_SELECTED_ADDED,   COLOR_BLUE,    COLOR_WHITE);
    init_pair(COLOR_SELECTED_MISSING, COLOR_RED,     COLOR_WHITE);
  }
  noecho();
  keypad(stdscr, TRUE);

  while (1) {
    list_size = diff_navi_list_size(node);
    diff_navi_update_screen(node);
    getmaxyx(stdscr, maxy, maxx);
    c = getch();

    switch (c) {
    case KEY_RESIZE:
      diff_navi_winch_handler(node);
      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_LEFT:
    case '-':
      diff_navi_list_expand(node, selected_entry + 1, false);
      break;

    case KEY_RIGHT:
    case '+':
      diff_navi_list_expand(node, selected_entry + 1, true);
      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':
      /* For ease of use, attempt to expand with "Enter" as well: */
      diff_navi_list_expand(node, selected_entry + 1, true);
      diff_navi_call_program(node, selected_entry + 1, root1, root2);
      break;

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3028, %rsp           # imm = 0x3028
movq %rdx, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, %r15
callq 0x2150
leaq 0x418(%rip), %rdi       # 0x325a
callq 0x3890
callq 0x2030
testb %al, %al
je 0x2ec5
callq 0x2160
pushq $0x1
popq %rbx
pushq $0x7
popq %rbp
movl %ebx, %edi
movl %ebp, %esi
xorl %edx, %edx
callq 0x2210
pushq $0x2
popq %rdi
pushq $0x5
popq %r14
movl %r14d, %esi
xorl %edx, %edx
callq 0x2210
pushq $0x3
popq %rdi
pushq $0x4
popq %r12
movl %r12d, %esi
xorl %edx, %edx
callq 0x2210
movl %r12d, %edi
movl %ebx, %esi
xorl %edx, %edx
callq 0x2210
movl %r14d, %edi
xorl %esi, %esi
movl %ebp, %edx
callq 0x2210
pushq $0x6
popq %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0x2210
movl %ebp, %edi
movl %r12d, %esi
movl %ebp, %edx
callq 0x2210
pushq $0x8
popq %rdi
movl %ebx, %esi
movl %ebp, %edx
callq 0x2210
callq 0x2110
movq 0x3107(%rip), %r13      # 0x5fd8
movq (%r13), %rdi
pushq $0x1
popq %rsi
callq 0x21b0
pushq $-0x1
popq %r12
leaq 0x11b8(%rip), %rbp      # 0x40a0
movq %r15, %rdi
callq 0x325f
movl %eax, %r14d
movq %r15, %rdi
callq 0x32a6
movq (%r13), %rdi
movl %r12d, %ebx
testq %rdi, %rdi
je 0x2f0d
movswl 0x4(%rdi), %ebx
incl %ebx
callq 0x20d0
leal -0x102(%rax), %ecx
cmpl $0x3, %ecx
jbe 0x2f89
cmpl $0xa, %eax
je 0x2fca
cmpl $0xd, %eax
je 0x2fca
cmpl $0x2b, %eax
je 0x3052
cmpl $0x2d, %eax
je 0x303b
cmpl $0x152, %eax            # imm = 0x152
je 0x306a
cmpl $0x153, %eax            # imm = 0x153
je 0x30ac
cmpl $0x157, %eax            # imm = 0x157
je 0x2fca
cmpl $0x19a, %eax            # imm = 0x19A
je 0x311e
cmpl $0x1b, %eax
je 0x3141
cmpl $0x51, %eax
je 0x3141
cmpl $0x71, %eax
jne 0x2ee8
jmp 0x3141
movslq (%rbp,%rcx,4), %rax
addq %rbp, %rax
jmpq *%rax
movl 0x31f3(%rip), %eax      # 0x618c
leal 0x1(%rax), %ecx
cmpl %r14d, %ecx
cmovll %ecx, %eax
movl %eax, 0x31e4(%rip)      # 0x618c
subl %ebx, %eax
jl 0x2ee8
movl 0x31da(%rip), %ecx      # 0x6190
xorl %edx, %edx
cmpl %eax, %ecx
setle %dl
addl %ecx, %edx
movl %edx, 0x31cb(%rip)      # 0x6190
jmp 0x2ee8
movl 0x31bc(%rip), %esi      # 0x618c
incl %esi
movq %r15, %rdi
pushq $0x1
popq %rdx
callq 0x3423
movl 0x31a9(%rip), %esi      # 0x618c
incl %esi
andl $0x0, 0xc(%rsp)
movq %r15, %rdi
leaq 0xc(%rsp), %rdx
callq 0x378f
testq %rax, %rax
je 0x2ee8
movq %rax, %rbx
cmpl $0x2, 0x4(%rax)
jne 0x2ee8
callq 0x22a0
callq 0x22d0
cmpl $-0x1, %eax
je 0x312b
testl %eax, %eax
jle 0x3153
movl %eax, %edi
leaq 0x20(%rsp), %rsi
xorl %edx, %edx
callq 0x2240
jmp 0x312b
movl 0x314b(%rip), %esi      # 0x618c
incl %esi
movq %r15, %rdi
xorl %edx, %edx
callq 0x3423
jmp 0x2ee8
movl 0x3134(%rip), %esi      # 0x618c
incl %esi
movq %r15, %rdi
pushq $0x1
popq %rdx
callq 0x3423
jmp 0x2ee8
movl %ebx, %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
movl 0x3118(%rip), %ecx      # 0x6190
addl %ebx, %ecx
addl %eax, %ecx
cmpl %ecx, %r14d
cmovll %r14d, %ecx
subl %ebx, %ecx
testl %ecx, %ecx
movl $0x0, %eax
cmovlel %eax, %ecx
movl %ecx, 0x30fb(%rip)      # 0x6190
cmpl %ecx, 0x30f1(%rip)      # 0x618c
jge 0x2ee8
movl %ecx, 0x30e5(%rip)      # 0x618c
jmp 0x2ee8
movl %ebx, %eax
cltd
pushq $-0x2
popq %rcx
idivl %ecx
addl 0x30d6(%rip), %eax      # 0x6190
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
movl %eax, 0x30c6(%rip)      # 0x6190
addl %ebx, %eax
cmpl %eax, 0x30ba(%rip)      # 0x618c
jl 0x2ee8
decl %eax
movl %eax, 0x30ac(%rip)      # 0x618c
jmp 0x2ee8
movl 0x30a1(%rip), %ecx      # 0x618c
xorl %eax, %eax
testl %ecx, %ecx
setg %al
subl %eax, %ecx
movl %ecx, 0x3092(%rip)      # 0x618c
movl 0x3090(%rip), %eax      # 0x6190
cmpl %ecx, %eax
jle 0x2ee8
cmpl $0x2, %eax
pushq $0x1
popq %rcx
cmovll %ecx, %eax
decl %eax
movl %eax, 0x3077(%rip)      # 0x6190
jmp 0x2ee8
callq 0x22a0
movq %r15, %rdi
callq 0x32a6
callq 0x2080
movq (%r13), %rdi
pushq $0x1
popq %rsi
callq 0x21b0
jmp 0x2ee8
addq $0x3028, %rsp           # imm = 0x3028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4(%rsp), %rdi
callq 0x2190
callq 0x22d0
cmpl $-0x1, %eax
je 0x3253
testl %eax, %eax
jle 0x31a4
movl 0x4(%rsp), %edi
xorl %esi, %esi
callq 0x2120
movl 0x4(%rsp), %edi
callq 0x2180
movl 0x8(%rsp), %edi
callq 0x2180
leaq 0xf5d(%rip), %rdi       # 0x40f0
movq %rdi, %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x22b0
jmp 0x3253
leaq 0x1020(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x2507
leaq 0xe41(%rip), %r12       # 0x4004
leaq 0x20(%rsp), %r14
movl $0x1000, %esi           # imm = 0x1000
movq %r14, %rdi
movq %r12, %rdx
movq 0x10(%rsp), %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2140
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x2507
leaq 0x2020(%rsp), %rbx
movl $0x1000, %esi           # imm = 0x1000
movq %rbx, %rdi
movq %r12, %rdx
movq 0x18(%rsp), %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2140
movl 0x8(%rsp), %edi
pushq $0x1
popq %rsi
callq 0x2120
movl 0x4(%rsp), %edi
callq 0x2180
movl 0x8(%rsp), %edi
callq 0x2180
leaq 0xebc(%rip), %rdi       # 0x40f5
leaq 0xeba(%rip), %rdx       # 0x40fa
movq %rdi, %rsi
movq %r14, %rcx
movq %rbx, %r8
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x22b0
xorl %edi, %edi
callq 0x20a0