// File: /workspace/github_cpp_makefile_star2_O1/fulhax[P]ncpamixer/src/ui/tab.cpp
// Function: Tab::dropDown(int, int, std::map<unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>, unsigned int, unsigned int, unsigned int)
uint32_t Tab::dropDown(
    int x,
    int y,
    std::map<uint32_t, std::string> objects,
    uint32_t current,
    uint32_t width,
    uint32_t height
)
{
    if (objects.empty()) {
        return -1;
    }

    bool autowidth = false;
    bool autoheight = false;

    if (width == 0) {
        autowidth = true;
    }

    if (height == 0) {
        autoheight = true;
    }

    uint32_t selected = 0;

    std::vector<ITEM *> items;
    MENU *menu = 0;
    WINDOW *menu_win = 0;

    for (auto &i : objects) {
        ITEM *item = new_item(i.second.c_str(), nullptr);
        set_item_opts(item, O_SELECTABLE);
        set_item_userptr(item, static_cast<void*>(&i));

        items.push_back(item);

        if (i.first == current) {
            selected = items.size() - 1;
        }

        if (autowidth) {
            width = (width < strlen(i.second.c_str()) + 3) ?
                    strlen(i.second.c_str()) :
                    width;
        }

        if (autoheight) {
            height = (height < 5) ? height + 1 : 5;
        }
    }

    items.push_back(new_item(nullptr, nullptr));
    menu = new_menu(&items[0]);

    if (x < 0) {
        x = ui.width - (width + 2);
    }

    menu_win = newwin(height + 2, width + 2, y, x);
    keypad(menu_win, true);

    set_menu_win(menu, menu_win);
    set_menu_sub(menu, derwin(menu_win, height + 1, width, 1, 1));
    set_menu_format(menu, height, 1);

    wbkgd(menu_win, COLOR_PAIR(COLOR_BORDER));
    //set_menu_back(menu, COLOR_PAIR(7));
    set_menu_fore(menu, COLOR_PAIR(COLOR_DROPDOWN_SELECTED));
    set_menu_grey(menu, COLOR_PAIR(COLOR_DROPDOWN_UNSELECTED));

    //set_menu_mark(menu, "* ");
    set_menu_mark(menu, "");
    menu_opts_on(menu, O_ONEVALUE);
    menu_opts_off(menu, O_SHOWDESC);
    menu_opts_off(menu, O_NONCYCLIC);

    box(menu_win, 0, 0);

    post_menu(menu);
    set_current_item(menu, items[selected]);

    wrefresh(menu_win);

    bool selecting = true;

    while (selecting) {
        int input = wgetch(menu_win);

        if (input == ERR) {
            continue;
        }

#ifdef KEY_MOUSE
        if (input == KEY_MOUSE) {
            MEVENT mevent;
            int ok;

            ok = getmouse(&mevent);
            if (ok != OK) {
                continue;
            }

            if (mevent.bstate & BUTTON1_PRESSED) {
                if (mevent.y < y || mevent.y > y + (int)height + 1 ||
                    mevent.x < x || mevent.x > x + (int)width + 1) {
                    clrtoeol();

                    ITEM *item = current_item(menu);
                    selected = static_cast<std::pair<uint32_t, std::string>*>(
                                   item_userptr(item)
                               )->first;

                    selecting = false;
                    continue;
                }
            }

            if (mevent.y == y || mevent.y == y + (int)height + 1 ||
                mevent.x == x || mevent.x == x + (int)width + 1) {
                continue;
            }

            if (mevent.bstate & BUTTON1_PRESSED) {
                int top = top_row(menu);
                int idx = mevent.y - y - 1 + top;
                ITEM** its = menu_items(menu);
                int itc = item_count(menu);
                if (idx < itc) {
                    ITEM* item = its[idx];
                    set_current_item(menu, item);
                    selected = static_cast<std::pair<uint32_t, std::string>*>(
                                   item_userptr(item)
                               )->first;
                }

                selecting = false;
                continue;
            }
#if NCURSES_MOUSE_VERSION > 1
            else if (mevent.bstate & BUTTON4_PRESSED) {
                menu_driver(menu, REQ_UP_ITEM);
            } else if (mevent.bstate & BUTTON5_PRESSED) {
                menu_driver(menu, REQ_DOWN_ITEM);
            }
#endif
        }
#endif

        if (input == KEY_RESIZE) {
            selecting = false;
            continue;
        }

        std::string key = std::to_string(input);
        
        std::string event = config.getString(("keycode." +  key).c_str(), "unbound");

        if (!strcmp("unbound", event.c_str())) {
            continue;
        }

        if (!strcmp("select", event.c_str())) {
            clrtoeol();

            ITEM *item = current_item(menu);
            selected = static_cast<std::pair<uint32_t, std::string>*>(
                            item_userptr(item)
                       )->first;

            selecting = false;
        } else if (!strcmp("move_down", event.c_str())) {
            menu_driver(menu, REQ_DOWN_ITEM);
        } else if (!strcmp("move_up", event.c_str())) {
            menu_driver(menu, REQ_UP_ITEM);
        } else if (!strcmp("page_up", event.c_str())) {
            menu_driver(menu, REQ_SCR_UPAGE);
        } else if (!strcmp("page_down", event.c_str())) {
            menu_driver(menu, REQ_SCR_DPAGE);
        } else if (!strcmp("quit", event.c_str())) {
            selecting = false;
        }

        wrefresh(menu_win);
    }

    unpost_menu(menu);
    free_menu(menu);

    for (auto i : items) {
        if (i != nullptr)
            free_item(i);
    }

    items.clear();
    refresh();

    return selected;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movl %r8d, (%rsp)
movq %rsi, 0x60(%rsp)
cmpq $0x0, 0x28(%rdx)
je 0xf1b0
movl %r9d, %r13d
movq %rdx, %rbx
movl %edi, 0x38(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x18(%rdx), %r14
addq $0x8, %rbx
cmpq %rbx, %r14
je 0xf1bb
movl %ecx, %r15d
movq $0x0, 0x18(%rsp)
movl (%rsp), %eax
movq %rax, 0x10(%rsp)
movl %r13d, %ebp
movl %ecx, 0xc(%rsp)
movq 0x28(%r14), %rdi
xorl %esi, %esi
callq 0x65d0
movq %rax, 0x40(%rsp)
movq %rax, %rdi
movl $0x1, %esi
callq 0x6b80
leaq 0x20(%r14), %r12
movq 0x40(%rsp), %rdi
movq %r12, %rsi
callq 0x6270
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0xf12a
movq 0x40(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x28(%rsp)
jmp 0xf139
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x10178
cmpl %r15d, (%r12)
jne 0xf154
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
shrq $0x3, %rax
decl %eax
movq %rax, 0x18(%rsp)
cmpl $0x0, (%rsp)
jne 0xf180
movq 0x10(%rsp), %r15
movl %r15d, %r12d
movq 0x28(%r14), %rdi
callq 0x62b0
leaq 0x3(%rax), %rcx
cmpq %r12, %rcx
cmovbel %r15d, %eax
movl 0xc(%rsp), %r15d
movq %rax, 0x10(%rsp)
leal 0x1(%rbp), %r12d
cmpl $0x5, %ebp
movl $0x5, %eax
cmovael %eax, %r12d
testl %r13d, %r13d
cmovnel %ebp, %r12d
movq %r14, %rdi
callq 0x6440
movq %rax, %r14
movl %r12d, %ebp
cmpq %rbx, %rax
jne 0xf0e0
jmp 0xf1cf
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0xf7b3
movq $0x0, 0x18(%rsp)
movl %r13d, %r12d
movl (%rsp), %eax
movq %rax, 0x10(%rsp)
xorl %edi, %edi
xorl %esi, %esi
callq 0x65d0
leaq 0x40(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x20(%rsp), %rdi
callq 0x102b4
movq 0x20(%rsp), %rdi
callq 0x6380
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %r15
movq %rax, %r14
leaq 0x95f0(%rip), %rax      # 0x187f8
movl 0x8(%rax), %ecx
leal 0x2(%r15), %esi
subl %esi, %ecx
movl 0x38(%rsp), %eax
testl %eax, %eax
cmovnsl %eax, %ecx
leal 0x2(%r12), %edi
movq 0x60(%rsp), %rdx
movq %rcx, 0x38(%rsp)
callq 0x65e0
movq %rax, %r13
movq %rax, %rdi
movl $0x1, %esi
callq 0x6250
movq %r14, %rdi
movq %r13, %rsi
callq 0x63e0
leal 0x1(%r12), %esi
movq %r13, %rdi
movl %r15d, %edx
movl $0x1, %ecx
movl $0x1, %r8d
callq 0x6480
movq %r14, %rdi
movq %rax, %rsi
callq 0x6090
movq %r14, %rdi
movl %r12d, %esi
movl $0x1, %edx
callq 0x6720
movq %r13, %rdi
movl $0xd00, %esi            # imm = 0xD00
callq 0x69f0
movq %r14, %rdi
movl $0xb00, %esi            # imm = 0xB00
callq 0x61c0
movq %r14, %rdi
movl $0xc00, %esi            # imm = 0xC00
callq 0x60f0
leaq 0x2237(%rip), %rsi      # 0x114e4
movq %r14, %rdi
callq 0x6260
movq %r14, %rdi
movl $0x1, %esi
callq 0x6b20
movq %r14, %rdi
movl $0x2, %esi
callq 0x6a90
movq %r14, %rdi
movl $0x20, %esi
callq 0x6a90
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x6b10
movq %r14, %rdi
callq 0x6840
movl %ebx, %eax
movq 0x20(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
movq %r14, %rdi
callq 0x6100
movq %r13, %rdi
callq 0x6670
movq 0x60(%rsp), %rax
leal (%rax,%r12), %ecx
incl %ecx
movl %ecx, 0xc(%rsp)
movq 0x38(%rsp), %rcx
leal 0x1(%r15,%rcx), %ecx
movl %ecx, 0x10(%rsp)
notl %eax
movl %eax, 0x6c(%rsp)
movb $0x1, %bpl
leaq 0x40(%rsp), %r15
movq %r14, (%rsp)
movq %r13, %rdi
callq 0x6240
movl %eax, %ebx
cmpl $-0x1, %eax
je 0xf745
cmpl $0x199, %ebx            # imm = 0x199
jne 0xf37a
movq %r15, %rdi
callq 0x69c0
testl %eax, %eax
je 0xf3f0
xorl %r12d, %r12d
testb %r12b, %r12b
leaq 0x40(%rsp), %r15
movq (%rsp), %r14
je 0xf745
cmpl $0x19a, %ebx            # imm = 0x19A
jne 0xf389
xorl %ebp, %ebp
jmp 0xf745
movl %ebx, %r14d
negl %r14d
cmovsl %ebx, %r14d
movl $0x1, %r12d
cmpl $0xa, %r14d
jb 0xf4bf
movl $0x4, %r12d
movl %r14d, %eax
movl $0xd1b71759, %edx       # imm = 0xD1B71759
cmpl $0x63, %eax
jbe 0xf4b6
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0xf4bc
cmpl $0x2710, %eax           # imm = 0x2710
jb 0xf4bf
movl %eax, %ecx
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %r12d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0xf3b1
addl $-0x3, %r12d
jmp 0xf4bf
movl 0x50(%rsp), %eax
testb $0x2, %al
jne 0xf464
movl 0x48(%rsp), %ecx
xorl %r12d, %r12d
cmpl 0x60(%rsp), %ecx
je 0xf368
cmpl 0xc(%rsp), %ecx
je 0xf368
movl 0x44(%rsp), %ecx
xorl %r12d, %r12d
cmpl 0x38(%rsp), %ecx
je 0xf368
cmpl 0x10(%rsp), %ecx
je 0xf368
testb $0x2, %al
jne 0xf685
movl $0x202, %esi            # imm = 0x202
btl $0x10, %eax
movq (%rsp), %rdi
jb 0xf457
movl $0x203, %esi            # imm = 0x203
movb $0x1, %r12b
btl $0x15, %eax
jae 0xf368
movb $0x1, %r12b
callq 0x64d0
jmp 0xf368
movl 0x48(%rsp), %ecx
cmpl 0x60(%rsp), %ecx
jl 0xf488
cmpl 0xc(%rsp), %ecx
jg 0xf488
movl 0x44(%rsp), %ecx
cmpl 0x38(%rsp), %ecx
jl 0xf488
cmpl 0x10(%rsp), %ecx
jle 0xf3f8
movq 0x8b11(%rip), %rax      # 0x17fa0
movq (%rax), %rdi
callq 0x6610
movq (%rsp), %rdi
callq 0x68f0
movq %rax, %rdi
callq 0x6960
movl (%rax), %eax
movq %rax, 0x18(%rsp)
xorl %ebp, %ebp
jmp 0xf365
addl $-0x2, %r12d
jmp 0xf4bf
decl %r12d
shrl $0x1f, %ebx
leal (%r12,%rbx), %esi
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movl $0x2d, %edx
callq 0x66b0
movl %ebx, %edi
addq 0x40(%rsp), %rdi
movl %r12d, %esi
movl %r14d, %edx
callq 0xac05
leaq 0x98(%rsp), %rdi
leaq 0x3390(%rip), %rsi      # 0x12893
movq %r15, %rdx
callq 0xd41a
movq 0x98(%rsp), %rbx
leaq 0x80(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x70(%rsp), %r12
movq %r12, %rdi
leaq 0x3351(%rip), %rsi      # 0x12880
leaq 0x3351(%rip), %rdx      # 0x12887
callq 0x73f0
movq (%rsp), %r14
leaq 0xb8(%rsp), %rdi
leaq 0x9252(%rip), %rsi      # 0x187a0
movq %rbx, %rdx
movq %r12, %rcx
callq 0xa47a
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0xf57b
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x65c0
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0xf5a0
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x65c0
movq 0xb8(%rsp), %rbx
leaq 0x32d1(%rip), %rdi      # 0x12880
movq %rbx, %rsi
callq 0x67f0
testl %eax, %eax
je 0xf704
leaq 0x34ab(%rip), %rdi      # 0x12a71
movq %rbx, %rsi
callq 0x67f0
testl %eax, %eax
je 0xf643
leaq 0x33b4(%rip), %rdi      # 0x1298d
movq %rbx, %rsi
callq 0x67f0
testl %eax, %eax
je 0xf670
leaq 0x3395(%rip), %rdi      # 0x12985
movq %rbx, %rsi
callq 0x67f0
testl %eax, %eax
je 0xf677
leaq 0x3475(%rip), %rdi      # 0x12a78
movq %rbx, %rsi
callq 0x67f0
testl %eax, %eax
je 0xf67e
leaq 0x346a(%rip), %rdi      # 0x12a80
movq %rbx, %rsi
callq 0x67f0
testl %eax, %eax
je 0xf6ef
leaq 0x326f(%rip), %rdi      # 0x1289c
movq %rbx, %rsi
callq 0x67f0
testl %eax, %eax
movzbl %bpl, %ebp
cmovel %eax, %ebp
jmp 0xf6fc
movq 0x8956(%rip), %rax      # 0x17fa0
movq (%rax), %rdi
callq 0x6610
movq %r14, %rdi
callq 0x68f0
movq %rax, %rdi
callq 0x6960
movl (%rax), %eax
movq %rax, 0x18(%rsp)
xorl %ebp, %ebp
jmp 0xf6fc
movl $0x203, %esi            # imm = 0x203
jmp 0xf6f4
movl $0x202, %esi            # imm = 0x202
jmp 0xf6f4
movl $0x207, %esi            # imm = 0x207
jmp 0xf6f4
movq (%rsp), %r15
movq %r15, %rdi
callq 0x67a0
movl %eax, %r14d
addl 0x6c(%rsp), %r14d
addl 0x48(%rsp), %r14d
movq %r15, %rdi
callq 0x6160
movq %rax, 0x90(%rsp)
movq %r15, %rdi
callq 0x62d0
xorl %ebp, %ebp
movl $0x0, %r12d
cmpl %eax, %r14d
jge 0xf368
movslq %r14d, %rax
movq 0x90(%rsp), %rcx
movq (%rcx,%rax,8), %r14
movq (%rsp), %rdi
movq %r14, %rsi
callq 0x6100
movq %r14, %rdi
callq 0x6960
jmp 0xf4a8
movl $0x206, %esi            # imm = 0x206
movq %r14, %rdi
callq 0x64d0
movq %r13, %rdi
callq 0x6670
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0xf729
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x65c0
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0xf745
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x65c0
testb $0x1, %bpl
jne 0xf33a
movq %r14, %rdi
callq 0x6460
movq 0x18(%rsp), %r12
movq %r14, %rdi
callq 0x6210
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r14
cmpq %r14, %rbx
je 0xf786
movq (%rbx), %rdi
testq %rdi, %rdi
je 0xf780
callq 0x66e0
addq $0x8, %rbx
jmp 0xf76e
movq 0x20(%rsp), %rax
cmpq %rax, 0x28(%rsp)
je 0xf797
movq %rax, 0x28(%rsp)
callq 0x6a10
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xf7b3
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x65c0
movl %r12d, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xf88e
jmp 0xf88e
jmp 0xf88e
jmp 0xf88e
jmp 0xf88e
jmp 0xf88e
jmp 0xf88e
jmp 0xf840
movq %rax, %rbx
jmp 0xf868
jmp 0xf88e
movq %rax, %rbx
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0xf821
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x65c0
jmp 0xf821
movq %rax, %rbx
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0xf868
movq 0xa8(%rsp), %rsi
jmp 0xf860
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0xf868
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x65c0
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0xf891
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x65c0
jmp 0xf891
jmp 0xf88e
jmp 0xf88e
jmp 0xf88e
jmp 0xf88e
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xf8a8
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x65c0
movq %rbx, %rdi
callq 0x6a80