// File: /workspace/github_c_makefile_star2_O3/kobolt[P]curses-collection/playlist/ui.c
// Function: main
int main(int argc, char *argv[])
{
  int c, maxy, maxx, len;
  struct sigaction sa;

  if (argc != 3) {
    printf("Usage: %s <playlist file> <program>\n", argv[0]);
    return 1;
  }
  
  if (list_import_file(argv[1]) != 0) {
    printf("Error: Unable to open playlist file.\n");
    return 1;
  }

  sa.sa_handler = interrupt_handler;
  sigemptyset(&sa.sa_mask);
  sa.sa_flags = 0;
  sigaction(SIGINT, &sa, NULL);

  play_finished_handler_install(finished_handler);
  play_set_program(argv[2]);

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

  list_request(0); /* Start right away at startup. */

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

    /* Don't close the help if interrupted. */
    if (c > 0) {
      help_hint_active = help_window_active = 0;
    }

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

    case KEY_F(10):
    case KEY_F(1):
      help_window_active = 1;
      break;

    case KEY_F(7):
      list_swap(selected_entry, selected_entry - 1);
    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_F(8):
      list_swap(selected_entry, selected_entry + 1);
    case KEY_DOWN:
      selected_entry++;
      if (selected_entry >= list_size_get())
        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_get())
        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_HOME:
    case KEY_F(5):
      scroll_offset = 0;
      selected_entry = 0;
      break;

    case KEY_END:
    case KEY_F(6):
      if (list_size_get() - maxy > 0)
        scroll_offset = list_size_get() - maxy;
      selected_entry = list_size_get() - 1;
      break;

    case KEY_F(9):
      list_shuffle();
      break;

    case KEY_LEFT:
    case KEY_RIGHT:
      list_request(selected_entry);
      break;

    case KEY_ENTER:
    case '\n':
    case '\r':
      if (list_filter_apply(file_filter) == 0) {
        scroll_offset = 0;
        selected_entry = 0;
      }
      break;

    case '\e': /* Escape */
      return 0;

    case KEY_BACKSPACE:
    case 0x7f:
      len = strlen(file_filter);
      if (len > 0)
        file_filter[len - 1] = '\0';
      break;

    default:
      if (! isprint(c))
        break;
      len = strlen(file_filter);
      if (len <= FILTER_LIMIT - 2)
        file_filter[len] = c;
      break;
    }
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %r15
cmpl $0x3, %edi
jne 0x2443
movq 0x8(%r15), %rdi
callq 0x2cfc
testl %eax, %eax
je 0x246b
leaq 0x1db1(%rip), %rdi      # 0x41ed
callq 0x2090
jmp 0x2454
movq (%r15), %rsi
leaq 0x1bfb(%rip), %rdi      # 0x4048
xorl %eax, %eax
callq 0x2100
movl $0x1, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x383(%rip), %rax       # 0x27f5
leaq -0xb8(%rbp), %r14
movq %rax, -0x8(%r14)
movq %r14, %rdi
callq 0x2170
movl $0x0, 0x80(%r14)
xorl %ebx, %ebx
leaq -0xc0(%rbp), %rsi
movl $0x2, %edi
xorl %edx, %edx
callq 0x20a0
leaq 0x354(%rip), %rdi       # 0x2800
callq 0x3368
movq 0x10(%r15), %rdi
callq 0x3375
callq 0x2120
leaq 0x346(%rip), %rdi       # 0x280c
callq 0x3590
callq 0x20f0
movq 0x3b09(%rip), %r12      # 0x5fe0
movq (%r12), %rdi
movl $0x1, %esi
callq 0x2140
xorl %edi, %edi
callq 0x2e7b
leaq 0x1b11(%rip), %r13      # 0x4004
callq 0x2820
movq (%r12), %rdi
testq %rdi, %rdi
je 0x250b
movswl 0x4(%rdi), %r15d
decl %r15d
jmp 0x2511
movl $0xfffffffd, %r15d      # imm = 0xFFFFFFFD
callq 0x20c0
movl %eax, %r14d
testl %eax, %eax
jle 0x252b
movb $0x0, 0x3c8c(%rip)      # 0x61b0
movb $0x1, 0x3c89(%rip)      # 0x61b4
cmpl $0x151, %r14d           # imm = 0x151
jg 0x2561
cmpl $0x7e, %r14d
jle 0x25af
leal -0x102(%r14), %eax
cmpl $0x10, %eax
ja 0x2667
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movl 0x3c5e(%rip), %edi      # 0x61b8
callq 0x2e7b
jmp 0x24f3
cmpl $0x156, %r14d           # imm = 0x156
jle 0x25e8
cmpl $0x157, %r14d           # imm = 0x157
je 0x25bf
cmpl $0x168, %r14d           # imm = 0x168
je 0x2631
cmpl $0x19a, %r14d           # imm = 0x19A
jne 0x27b1
callq 0x2290
callq 0x2820
callq 0x2060
movq (%r12), %rdi
movl $0x1, %esi
callq 0x2140
jmp 0x24f3
cmpl $0xa, %r14d
je 0x25bf
cmpl $0xd, %r14d
jne 0x27ab
leaq 0x3bfa(%rip), %rdi      # 0x61c0
callq 0x3045
testl %eax, %eax
jne 0x24f3
xorl %eax, %eax
movl %eax, 0x3be1(%rip)      # 0x61bc
xorl %ebx, %ebx
movl %eax, 0x3bd5(%rip)      # 0x61b8
jmp 0x24f3
cmpl $0x152, %r14d           # imm = 0x152
je 0x2697
cmpl $0x153, %r14d           # imm = 0x153
jne 0x27b1
movl %r15d, %ecx
shrl $0x1f, %ecx
addl %r15d, %ecx
sarl %ecx
movl 0x3ba9(%rip), %eax      # 0x61bc
subl %ecx, %eax
testl %eax, %eax
cmovlel %ebx, %eax
movl %eax, 0x3b9c(%rip)      # 0x61bc
addl %r15d, %eax
cmpl %eax, 0x3b8f(%rip)      # 0x61b8
jl 0x24f3
jmp 0x264e
callq 0x2f4f
cmpl %r15d, %eax
jle 0x2649
callq 0x2f4f
subl %r15d, %eax
movl %eax, 0x3b73(%rip)      # 0x61bc
callq 0x2f4f
decl %eax
movl %eax, 0x3b62(%rip)      # 0x61b8
jmp 0x24f3
movb $0x1, 0x3b4e(%rip)      # 0x61b0
jmp 0x24f3
cmpl $0x7f, %r14d
jne 0x27b1
leaq 0x3b48(%rip), %rdi      # 0x61c0
callq 0x20e0
testl %eax, %eax
jle 0x24f3
decl %eax
leaq 0x3b32(%rip), %rcx      # 0x61c0
movb $0x0, (%rax,%rcx)
jmp 0x24f3
movl %r15d, %r14d
shrl $0x1f, %r14d
addl %r15d, %r14d
sarl %r14d
addl 0x3b11(%rip), %r14d     # 0x61bc
movl %r14d, 0x3b0a(%rip)     # 0x61bc
addl %r15d, %r14d
callq 0x2f4f
cmpl %eax, %r14d
jle 0x26d7
movl 0x3af7(%rip), %eax      # 0x61bc
leal -0x1(%rax), %ecx
movl %ecx, 0x3aee(%rip)      # 0x61bc
leal (%rax,%r15), %r14d
decl %r14d
jmp 0x26b5
movl 0x3adf(%rip), %eax      # 0x61bc
testl %eax, %eax
jns 0x26ed
movl $0x0, 0x3ad1(%rip)      # 0x61bc
xorl %eax, %eax
cmpl %eax, 0x3ac5(%rip)      # 0x61b8
jge 0x24f3
jmp 0x2650
callq 0x2fcd
jmp 0x24f3
movl 0x3aaa(%rip), %edi      # 0x61b8
leal -0x1(%rdi), %esi
callq 0x2f5b
movl 0x3a9c(%rip), %ecx      # 0x61b8
xorl %eax, %eax
testl %ecx, %ecx
setg %al
subl %eax, %ecx
movl %ecx, 0x3a8d(%rip)      # 0x61b8
movl 0x3a8b(%rip), %eax      # 0x61bc
cmpl %ecx, %eax
jle 0x24f3
cmpl $0x2, %eax
movl $0x1, %ecx
cmovll %ecx, %eax
decl %eax
movl %eax, 0x3a70(%rip)      # 0x61bc
jmp 0x24f3
movl 0x3a61(%rip), %edi      # 0x61b8
leal 0x1(%rdi), %esi
callq 0x2f5b
movl 0x3a52(%rip), %r14d     # 0x61b8
incl %r14d
movl %r14d, 0x3a48(%rip)     # 0x61b8
callq 0x2f4f
movl 0x3a3d(%rip), %ecx      # 0x61b8
cmpl %eax, %r14d
jl 0x2788
decl %ecx
movl %ecx, 0x3a30(%rip)      # 0x61b8
subl %r15d, %ecx
jl 0x24f3
movl 0x3a25(%rip), %eax      # 0x61bc
xorl %edx, %edx
cmpl %ecx, %eax
setle %dl
addl %eax, %edx
movl %edx, 0x3a16(%rip)      # 0x61bc
jmp 0x24f3
cmpl $0x1b, %r14d
je 0x27ee
callq 0x2300
movq (%rax), %rax
movslq %r14d, %rcx
testb $0x40, 0x1(%rax,%rcx,2)
je 0x24f3
leaq 0x39f2(%rip), %rdi      # 0x61c0
callq 0x20e0
cmpl $0x30, %eax
jg 0x24f3
cltq
leaq 0x39db(%rip), %rcx      # 0x61c0
movb %r14b, (%rax,%rcx)
jmp 0x24f3
xorl %eax, %eax
jmp 0x2459