// File: /workspace/github_c_makefile_star2_O2/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, %r14
pushq $0x1
popq %rbx
cmpl $0x3, %edi
jne 0x2449
movq 0x8(%r14), %rdi
callq 0x2c6c
testl %eax, %eax
je 0x245f
leaq 0x1dae(%rip), %rdi      # 0x41ed
callq 0x2090
jmp 0x27a7
movq (%r14), %rsi
leaq 0x1bf5(%rip), %rdi      # 0x4048
xorl %eax, %eax
callq 0x2100
jmp 0x27a7
leaq 0x355(%rip), %rax       # 0x27bb
leaq -0xb8(%rbp), %rbx
movq %rax, -0x8(%rbx)
movq %rbx, %rdi
callq 0x2170
andl $0x0, 0x80(%rbx)
pushq $0x2
popq %rdi
leaq -0xc0(%rbp), %rsi
xorl %edx, %edx
callq 0x20a0
leaq 0x32e(%rip), %rdi       # 0x27c6
callq 0x328c
movq 0x10(%r14), %rdi
callq 0x3299
callq 0x2120
leaq 0x320(%rip), %rdi       # 0x27d2
callq 0x34a0
callq 0x20f0
movq 0x3b1d(%rip), %rbx      # 0x5fe0
movq (%rbx), %rdi
pushq $0x1
popq %rsi
callq 0x2140
xorl %edi, %edi
callq 0x2dbb
pushq $-0x1
popq %r15
leaq 0x1b24(%rip), %r14      # 0x4004
callq 0x27e6
movq (%rbx), %rdi
pushq $-0x3
popq %r12
testq %rdi, %rdi
je 0x24f9
movswl 0x4(%rdi), %r12d
decl %r12d
callq 0x20c0
movl %eax, %r13d
testl %eax, %eax
jle 0x2513
movb $0x0, 0x3ca4(%rip)      # 0x61b0
movb $0x1, 0x3ca1(%rip)      # 0x61b4
leal -0x102(%r13), %eax
cmpl $0x10, %eax
ja 0x2535
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movl 0x3c8a(%rip), %edi      # 0x61b8
callq 0x2dbb
jmp 0x24e0
cmpl $0xa, %r13d
je 0x25d7
cmpl $0xd, %r13d
je 0x25d7
cmpl $0x7f, %r13d
je 0x2634
cmpl $0x152, %r13d           # imm = 0x152
je 0x2724
cmpl $0x153, %r13d           # imm = 0x153
je 0x2772
cmpl $0x157, %r13d           # imm = 0x157
je 0x25d7
cmpl $0x168, %r13d           # imm = 0x168
je 0x260a
cmpl $0x19a, %r13d           # imm = 0x19A
je 0x2705
cmpl $0x1b, %r13d
je 0x27a5
callq 0x2300
movq (%rax), %rax
movslq %r13d, %rcx
testb $0x40, 0x1(%rax,%rcx,2)
je 0x24e0
leaq 0x3c09(%rip), %rdi      # 0x61c0
callq 0x20e0
cmpl $0x30, %eax
jg 0x24e0
cltq
leaq 0x3bf2(%rip), %rcx      # 0x61c0
movb %r13b, (%rax,%rcx)
jmp 0x24e0
leaq 0x3be2(%rip), %rdi      # 0x61c0
callq 0x2f80
testl %eax, %eax
jne 0x24e0
andl $0x0, 0x3bca(%rip)      # 0x61bc
andl $0x0, 0x3bbf(%rip)      # 0x61b8
jmp 0x24e0
movb $0x1, 0x3bab(%rip)      # 0x61b0
jmp 0x24e0
callq 0x2e8a
cmpl %r12d, %eax
jle 0x2622
callq 0x2e8a
subl %r12d, %eax
movl %eax, 0x3b9a(%rip)      # 0x61bc
callq 0x2e8a
decl %eax
movl %eax, 0x3b89(%rip)      # 0x61b8
jmp 0x24e0
leaq 0x3b85(%rip), %rdi      # 0x61c0
callq 0x20e0
testl %eax, %eax
jle 0x24e0
decl %eax
leaq 0x3b6f(%rip), %rcx      # 0x61c0
movb $0x0, (%rax,%rcx)
jmp 0x24e0
movl 0x3b58(%rip), %edi      # 0x61b8
leal -0x1(%rdi), %esi
callq 0x2e96
movl 0x3b4a(%rip), %ecx      # 0x61b8
xorl %eax, %eax
testl %ecx, %ecx
setg %al
subl %eax, %ecx
movl %ecx, 0x3b3b(%rip)      # 0x61b8
movl 0x3b39(%rip), %eax      # 0x61bc
cmpl %ecx, %eax
jle 0x24e0
cmpl $0x2, %eax
pushq $0x1
popq %rcx
cmovll %ecx, %eax
decl %eax
movl %eax, 0x3b20(%rip)      # 0x61bc
jmp 0x24e0
movl 0x3b11(%rip), %edi      # 0x61b8
leal 0x1(%rdi), %esi
callq 0x2e96
movl 0x3b02(%rip), %r13d     # 0x61b8
incl %r13d
movl %r13d, 0x3af8(%rip)     # 0x61b8
callq 0x2e8a
movl 0x3aed(%rip), %ecx      # 0x61b8
cmpl %eax, %r13d
jl 0x26d8
decl %ecx
movl %ecx, 0x3ae0(%rip)      # 0x61b8
subl %r12d, %ecx
jl 0x24e0
movl 0x3ad5(%rip), %eax      # 0x61bc
xorl %edx, %edx
cmpl %ecx, %eax
setle %dl
addl %eax, %edx
movl %edx, 0x3ac6(%rip)      # 0x61bc
jmp 0x24e0
callq 0x2f06
jmp 0x24e0
callq 0x2290
callq 0x27e6
callq 0x2060
movq (%rbx), %rdi
pushq $0x1
popq %rsi
callq 0x2140
jmp 0x24e0
movl %r12d, %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
movl %eax, %r13d
addl 0x3a85(%rip), %r13d     # 0x61bc
movl %r13d, 0x3a7e(%rip)     # 0x61bc
addl %r12d, %r13d
callq 0x2e8a
cmpl %eax, %r13d
movl %r15d, %r13d
jg 0x2730
movl 0x3a68(%rip), %eax      # 0x61bc
testl %eax, %eax
jns 0x2761
andl $0x0, 0x3a5d(%rip)      # 0x61bc
xorl %eax, %eax
cmpl %eax, 0x3a51(%rip)      # 0x61b8
jge 0x24e0
jmp 0x2629
movl %r12d, %eax
cltd
pushq $-0x2
popq %rcx
idivl %ecx
addl 0x3a3b(%rip), %eax      # 0x61bc
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
movl %eax, 0x3a2b(%rip)      # 0x61bc
addl %r12d, %eax
cmpl %eax, 0x3a1e(%rip)      # 0x61b8
jl 0x24e0
jmp 0x2627
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq