// File: /workspace/github_cpp_makefile_star2_O3/fulhax[P]ncpamixer/src/ui/tab.cpp
// Function: Tab::handleMouse(int, int, int)
void Tab::handleMouse(int x, int y, int button)
{
    if (object == nullptr) {
        return;
    }

    int baseY = 0;
    int current_block = 0;
    int BLOCK_SIZE = getBlockSize();

    total_blocks = (ui.height - 2) / BLOCK_SIZE;
    int blocks_drawn = 0;

    bool more_up = false;
    bool more_down = false;

    for (auto &i : *object) {
        auto item = i.second;
        if (current_block <= selected_block - total_blocks) {
            current_block++;
            more_up = true;
            continue;
        }

        if (blocks_drawn >= total_blocks) {
            more_down = true;
            break;
        }

        blocks_drawn++;

        if (has_volume) {
            if (handleMouseVolumeBar(item, x, y, ui.width, ui.height, 0, baseY + 3, button)) {
                return;
            }
        } else { // Configuration
            if (item->active_attribute != nullptr) {
                if (handleMouseDropDown(item, x, y, ui.width - 2, 2, 1, baseY + 2)) {
                    return;
                }
            }
        }

        unsigned int len = 0;
        unsigned int sink_pos = 0;
        PaObject* toggle_item = nullptr;

        if (toggle != nullptr) {
            auto rel = toggle->find(i.second->getRelation());

            if (rel != toggle->end()) {
                char *name = rel->second->name;

                if (name != nullptr) {
                    len = strlen(name);
                    sink_pos = ui.width - 1 - len;
                    toggle_item = rel->second;
                }
            }
        } else {
            if (i.second->active_attribute != nullptr && has_volume) {
                len = strlen(i.second->active_attribute->description);
                sink_pos = ui.width - 1 - len;
                toggle_item = i.second;
            }
        }

        if (toggle_item != nullptr) {
            auto save_selected_index = selected_index;
            auto save_selected_block = selected_block;

            selected_index = i.first;
            selected_block = current_block;

            bool done = handleMouseDropDown(toggle_item, x, y, len, 1, sink_pos, baseY + 1);

            selected_index = save_selected_index;
            selected_block = save_selected_block;

            if (done) {
                return;
            }
        }

        baseY += BLOCK_SIZE;
        current_block++;
    }

    if (more_up) {
        if (handleMouseMoreUp(x, y, 4, 1, (ui.width / 2) - 4, 0)) {
            return;
        }
    }

    if (more_down) {
        if (handleMouseMoreDown(x, y, 4, 1, (ui.width / 2) - 4, ui.height - 2)) {
            return;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, 0x30(%rsp)
movl %edx, 0xc(%rsp)
movq 0x10(%rdi), %r15
testq %r15, %r15
je 0xebb2
movq %rdi, %rbx
leaq 0x9f26(%rip), %rdx      # 0x187f8
movzbl 0x101(%rdx), %eax
andl $0x1, %eax
xorl $0x5, %eax
movzbl 0x102(%rdx), %ecx
subl %ecx, %eax
cmpb $0x0, 0x8(%rdi)
movl $0x5, %ecx
cmovnel %eax, %ecx
movl 0xc(%rdx), %eax
addl $-0x2, %eax
cltd
movl %ecx, 0x24(%rsp)
idivl %ecx
movl %eax, 0x24(%rdi)
movq 0x18(%r15), %r12
addq $0x8, %r15
cmpq %r15, %r12
je 0xebb2
movl %esi, %r14d
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
movl $0x0, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movl %esi, 0x1c(%rsp)
movq %r15, 0x38(%rsp)
movl 0x20(%rbx), %ecx
movl 0x24(%rbx), %eax
subl %eax, %ecx
movb $0x1, %r13b
cmpl %ecx, %ebp
jle 0xe998
cmpl %eax, 0x20(%rsp)
jge 0xeb14
movq 0x28(%r12), %rsi
cmpb $0x1, 0x8(%rbx)
jne 0xe9a4
leaq 0x9e90(%rip), %rax      # 0x187f8
movl 0x8(%rax), %r8d
movq 0x10(%rsp), %rax
addl $0x3, %eax
subq $0x8, %rsp
movl %r14d, %edx
movl 0x14(%rsp), %ecx
pushq 0x38(%rsp)
pushq %rax
pushq $0x0
callq 0xebd8
addq $0x20, %rsp
testb %al, %al
je 0xe9ef
jmp 0xebb2
movb $0x1, %al
movq %rax, 0x28(%rsp)
jmp 0xeafc
cmpq $0x0, 0x230(%rsi)
je 0xe9ef
testl %r14d, %r14d
setg %al
leaq 0x9e3d(%rip), %rcx      # 0x187f8
movl 0x8(%rcx), %ecx
movq 0x10(%rsp), %r8
leal 0x2(%r8), %edx
decl %ecx
cmpl %r14d, %ecx
setg %cl
movl 0xc(%rsp), %edi
cmpl %edi, %edx
setle %dl
andb %al, %dl
leal 0x5(%r8), %eax
cmpl %edi, %eax
setg %al
andb %dl, %al
andb %cl, %al
cmpb $0x1, %al
je 0xebc1
movq 0x18(%rbx), %r15
movq 0x28(%r12), %r13
testq %r15, %r15
je 0xea62
movq (%r13), %rax
movq %r13, %rdi
callq *0x18(%rax)
movq 0x10(%r15), %rcx
addq $0x8, %r15
testq %rcx, %rcx
je 0xea3a
movq %r15, %rdx
xorl %esi, %esi
cmpl %eax, 0x20(%rcx)
setb %sil
cmovaeq %rcx, %rdx
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0xea17
cmpq %r15, %rdx
je 0xea3a
cmpl 0x20(%rdx), %eax
cmovaeq %rdx, %r15
movq 0x18(%rbx), %rax
addq $0x8, %rax
cmpq %rax, %r15
je 0xeae2
movq 0x28(%r15), %r13
leaq 0x10(%r13), %rdi
callq 0x62b0
testq %r13, %r13
jne 0xea80
jmp 0xeae2
movq 0x230(%r13), %rdi
testq %rdi, %rdi
je 0xeae2
cmpb $0x1, 0x8(%rbx)
jne 0xeae2
addq $0x107, %rdi            # imm = 0x107
callq 0x62b0
movl %eax, %ecx
notl %ecx
leaq 0x9d6d(%rip), %rdx      # 0x187f8
addl 0x8(%rdx), %ecx
movl 0xc(%rbx), %r14d
movl 0x20(%rbx), %r15d
movl 0x20(%r12), %edx
movl %edx, 0xc(%rbx)
movl %ebp, 0x20(%rbx)
movl 0x1c(%rsp), %esi
cmpl %esi, %ecx
setle %dl
addl %ecx, %eax
cmpl %esi, %eax
setg %al
movl 0xc(%rsp), %esi
movq 0x10(%rsp), %rdi
cmpl %esi, %edi
setl %cl
andb %dl, %cl
andb %al, %cl
leal 0x4(%rdi), %eax
cmpl %esi, %eax
setg %al
andb %cl, %al
cmpb $0x1, %al
je 0xeb9f
movl %r14d, 0xc(%rbx)
movl %r15d, 0x20(%rbx)
movl 0x1c(%rsp), %r14d
incl 0x20(%rsp)
movq 0x10(%rsp), %rax
addl 0x24(%rsp), %eax
movq %rax, 0x10(%rsp)
movq 0x38(%rsp), %r15
movb $0x1, %r13b
incl %ebp
movq %r12, %rdi
callq 0x6440
movq %rax, %r12
cmpq %r15, %rax
jne 0xe93d
jmp 0xeb17
xorl %r13d, %r13d
testb $0x1, 0x28(%rsp)
je 0xeb4e
cmpl $0x0, 0xc(%rsp)
jne 0xeb4e
leaq 0x9ccc(%rip), %rax      # 0x187f8
movl 0x8(%rax), %ecx
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
sarl %eax
cmpl %r14d, %eax
jle 0xeb4e
addl $-0x4, %eax
cmpl %r14d, %eax
jg 0xeb4e
leaq 0x3e39(%rip), %rax      # 0x12985
jmp 0xeb8d
testb %r13b, %r13b
jne 0xebb2
leaq 0x9c9e(%rip), %rax      # 0x187f8
movl 0xc(%rax), %eax
addl $-0x2, %eax
cmpl 0xc(%rsp), %eax
jne 0xebb2
leaq 0x9c8b(%rip), %rax      # 0x187f8
movl 0x8(%rax), %ecx
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
sarl %eax
cmpl %r14d, %eax
jle 0xebb2
addl $-0x4, %eax
cmpl %r14d, %eax
jg 0xebb2
leaq 0x3e00(%rip), %rax      # 0x1298d
leaq 0x40(%rsp), %rsi
movq %rax, (%rsi)
movq %rbx, %rdi
callq 0xe130
jmp 0xebb2
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe71a
movl %r14d, 0xc(%rbx)
movl %r15d, 0x20(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe71a
nop