// File: /workspace/github_c_makefile_star2_O0/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
subq $0xd0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
je 0x2440
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x1bd7(%rip), %rdi      # 0x4004
movb $0x0, %al
callq 0x20f0
movl $0x1, -0x4(%rbp)
jmp 0x2a2e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x30c0
cmpl $0x0, %eax
je 0x246c
leaq 0x1bd0(%rip), %rdi      # 0x4029
movb $0x0, %al
callq 0x20f0
movl $0x1, -0x4(%rbp)
jmp 0x2a2e
leaq 0x5cd(%rip), %rax       # 0x2a40
movq %rax, -0xb8(%rbp)
leaq -0xb8(%rbp), %rdi
addq $0x8, %rdi
callq 0x2160
movl $0x0, -0x30(%rbp)
movl $0x2, %edi
leaq -0xb8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x2090
leaq 0x5b3(%rip), %rdi       # 0x2a60
callq 0x3aa0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x3ac0
callq 0x2110
leaq 0x5a5(%rip), %rdi       # 0x2a70
callq 0x3d20
callq 0x20e0
movq 0x3b04(%rip), %rax      # 0x5fe0
movq (%rax), %rdi
movl $0x1, %esi
callq 0x2130
xorl %edi, %edi
callq 0x3310
callq 0x2a90
xorl %eax, %eax
movq 0x3ae2(%rip), %rcx      # 0x5fe0
cmpq (%rcx), %rax
je 0x251c
movq 0x3ad6(%rip), %rax      # 0x5fe0
movq (%rax), %rax
movswl 0x4(%rax), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x2529
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0xbc(%rbp)
jmp 0x2529
movl -0xbc(%rbp), %eax
movl %eax, -0x18(%rbp)
xorl %eax, %eax
movq 0x3aa5(%rip), %rcx      # 0x5fe0
cmpq (%rcx), %rax
je 0x2559
movq 0x3a99(%rip), %rax      # 0x5fe0
movq (%rax), %rax
movswl 0x6(%rax), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x2566
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0xc0(%rbp)
jmp 0x2566
movl -0xc0(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x18(%rbp)
movq 0x3a61(%rip), %rax      # 0x5fe0
movq (%rax), %rdi
callq 0x20b0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0x25a4
movl $0x0, 0x3c16(%rip)      # 0x61b0
movl $0x0, 0x3bec(%rip)      # 0x6190
movl -0x14(%rbp), %eax
movl %eax, -0xc4(%rbp)
subl $0xa, %eax
je 0x2988
jmp 0x25b8
movl -0xc4(%rbp), %eax
subl $0xd, %eax
je 0x2988
jmp 0x25c9
movl -0xc4(%rbp), %eax
subl $0x1b, %eax
je 0x29af
jmp 0x25da
movl -0xc4(%rbp), %eax
subl $0x7f, %eax
je 0x29b8
jmp 0x25eb
movl -0xc4(%rbp), %eax
subl $0x102, %eax            # imm = 0x102
je 0x27cc
jmp 0x25fe
movl -0xc4(%rbp), %eax
subl $0x103, %eax            # imm = 0x103
je 0x275a
jmp 0x2611
movl -0xc4(%rbp), %eax
addl $0xfffffefc, %eax       # imm = 0xFFFFFEFC
subl $0x2, %eax
jb 0x2978
jmp 0x2627
movl -0xc4(%rbp), %eax
subl $0x106, %eax            # imm = 0x106
je 0x2927
jmp 0x263a
movl -0xc4(%rbp), %eax
subl $0x107, %eax            # imm = 0x107
je 0x29b8
jmp 0x264d
movl -0xc4(%rbp), %eax
subl $0x109, %eax            # imm = 0x109
je 0x2737
jmp 0x2660
movl -0xc4(%rbp), %eax
subl $0x10d, %eax            # imm = 0x10D
je 0x2927
jmp 0x2673
movl -0xc4(%rbp), %eax
subl $0x10e, %eax            # imm = 0x10E
je 0x2940
jmp 0x2686
movl -0xc4(%rbp), %eax
subl $0x10f, %eax            # imm = 0x10F
je 0x2746
jmp 0x2699
movl -0xc4(%rbp), %eax
subl $0x110, %eax            # imm = 0x110
je 0x27b8
jmp 0x26ac
movl -0xc4(%rbp), %eax
subl $0x111, %eax            # imm = 0x111
je 0x296e
jmp 0x26bf
movl -0xc4(%rbp), %eax
subl $0x112, %eax            # imm = 0x112
je 0x2737
jmp 0x26ce
movl -0xc4(%rbp), %eax
subl $0x152, %eax            # imm = 0x152
je 0x2852
jmp 0x26e1
movl -0xc4(%rbp), %eax
subl $0x153, %eax            # imm = 0x153
je 0x28cc
jmp 0x26f4
movl -0xc4(%rbp), %eax
subl $0x157, %eax            # imm = 0x157
je 0x2988
jmp 0x2707
movl -0xc4(%rbp), %eax
subl $0x168, %eax            # imm = 0x168
je 0x2940
jmp 0x271a
movl -0xc4(%rbp), %eax
subl $0x19a, %eax            # imm = 0x19A
jne 0x29e3
jmp 0x272d
callq 0x3090
jmp 0x2a29
movl $0x1, 0x3a6f(%rip)      # 0x61b0
jmp 0x2a29
movl 0x3a68(%rip), %edi      # 0x61b4
movl 0x3a62(%rip), %esi      # 0x61b4
subl $0x1, %esi
callq 0x3460
movl 0x3a54(%rip), %eax      # 0x61b4
addl $-0x1, %eax
movl %eax, 0x3a4b(%rip)      # 0x61b4
cmpl $0x0, 0x3a44(%rip)      # 0x61b4
jge 0x2781
movl 0x3a3c(%rip), %eax      # 0x61b4
addl $0x1, %eax
movl %eax, 0x3a33(%rip)      # 0x61b4
movl 0x3a31(%rip), %eax      # 0x61b8
cmpl 0x3a27(%rip), %eax      # 0x61b4
jle 0x27b3
movl 0x3a23(%rip), %eax      # 0x61b8
addl $-0x1, %eax
movl %eax, 0x3a1a(%rip)      # 0x61b8
cmpl $0x0, 0x3a13(%rip)      # 0x61b8
jge 0x27b1
movl $0x0, 0x3a07(%rip)      # 0x61b8
jmp 0x27b3
jmp 0x2a29
movl 0x39f6(%rip), %edi      # 0x61b4
movl 0x39f0(%rip), %esi      # 0x61b4
addl $0x1, %esi
callq 0x3460
movl 0x39e2(%rip), %eax      # 0x61b4
addl $0x1, %eax
movl %eax, 0x39d9(%rip)      # 0x61b4
movl 0x39d3(%rip), %eax      # 0x61b4
movl %eax, -0xc8(%rbp)
callq 0x3450
movl %eax, %ecx
movl -0xc8(%rbp), %eax
cmpl %ecx, %eax
jl 0x2807
movl 0x39b6(%rip), %eax      # 0x61b4
addl $-0x1, %eax
movl %eax, 0x39ad(%rip)      # 0x61b4
movl 0x39a7(%rip), %eax      # 0x61b4
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x284d
movl 0x399b(%rip), %eax      # 0x61b8
addl $0x1, %eax
movl %eax, 0x3992(%rip)      # 0x61b8
movl 0x398c(%rip), %eax      # 0x61b8
movl 0x3982(%rip), %ecx      # 0x61b4
subl -0x18(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x284b
movl 0x3976(%rip), %eax      # 0x61b8
addl $-0x1, %eax
movl %eax, 0x396d(%rip)      # 0x61b8
jmp 0x284d
jmp 0x2a29
movl -0x18(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
addl 0x3955(%rip), %eax      # 0x61b8
movl %eax, 0x394f(%rip)      # 0x61b8
movl -0x18(%rbp), %eax
addl 0x3946(%rip), %eax      # 0x61b8
movl %eax, -0xcc(%rbp)
callq 0x3450
movl %eax, %ecx
movl -0xcc(%rbp), %eax
cmpl %ecx, %eax
jle 0x289a
movl 0x3929(%rip), %eax      # 0x61b8
addl $-0x1, %eax
movl %eax, 0x3920(%rip)      # 0x61b8
jmp 0x2869
cmpl $0x0, 0x3917(%rip)      # 0x61b8
jge 0x28ad
movl $0x0, 0x390b(%rip)      # 0x61b8
movl 0x3901(%rip), %eax      # 0x61b4
cmpl 0x38ff(%rip), %eax      # 0x61b8
jge 0x28c7
movl 0x38f7(%rip), %eax      # 0x61b8
movl %eax, 0x38ed(%rip)      # 0x61b4
jmp 0x2a29
movl -0x18(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl 0x38d9(%rip), %eax      # 0x61b8
subl %ecx, %eax
movl %eax, 0x38d1(%rip)      # 0x61b8
cmpl $0x0, 0x38ca(%rip)      # 0x61b8
jge 0x28fa
movl $0x0, 0x38be(%rip)      # 0x61b8
movl 0x38b4(%rip), %eax      # 0x61b4
movl -0x18(%rbp), %ecx
addl 0x38af(%rip), %ecx      # 0x61b8
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x2922
movl -0x18(%rbp), %eax
addl 0x389f(%rip), %eax      # 0x61b8
subl $0x1, %eax
movl %eax, 0x3892(%rip)      # 0x61b4
jmp 0x2a29
movl $0x0, 0x3887(%rip)      # 0x61b8
movl $0x0, 0x3879(%rip)      # 0x61b4
jmp 0x2a29
callq 0x3450
subl -0x18(%rbp), %eax
cmpl $0x0, %eax
jle 0x295b
callq 0x3450
subl -0x18(%rbp), %eax
movl %eax, 0x385d(%rip)      # 0x61b8
callq 0x3450
subl $0x1, %eax
movl %eax, 0x384b(%rip)      # 0x61b4
jmp 0x2a29
callq 0x3530
jmp 0x2a29
movl 0x3836(%rip), %edi      # 0x61b4
callq 0x3310
jmp 0x2a29
leaq 0x3831(%rip), %rdi      # 0x61c0
callq 0x3610
cmpl $0x0, %eax
jne 0x29ad
movl $0x0, 0x3815(%rip)      # 0x61b8
movl $0x0, 0x3807(%rip)      # 0x61b4
jmp 0x2a29
movl $0x0, -0x4(%rbp)
jmp 0x2a2e
leaq 0x3801(%rip), %rdi      # 0x61c0
callq 0x20d0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jle 0x29e1
movl -0x20(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x37e3(%rip), %rax      # 0x61c0
movb $0x0, (%rax,%rcx)
jmp 0x2a29
callq 0x22f0
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x4000, %eax           # imm = 0x4000
cmpl $0x0, %eax
jne 0x29ff
jmp 0x2a29
leaq 0x37ba(%rip), %rdi      # 0x61c0
callq 0x20d0
movl %eax, -0x20(%rbp)
cmpl $0x30, -0x20(%rbp)
jg 0x2a27
movl -0x14(%rbp), %eax
movb %al, %dl
movslq -0x20(%rbp), %rcx
leaq 0x379c(%rip), %rax      # 0x61c0
movb %dl, (%rax,%rcx)
jmp 0x2a29
jmp 0x24f0
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw (%rax,%rax)