// File: /workspace/github_cpp_makefile_star2_O2/fulhax[P]ncpamixer/src/ui/tab.cpp
// Function: Tab::draw()
void Tab::draw()
{
    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) {
        if (current_block <= selected_block - total_blocks) {
            current_block++;
            more_up = true;
            continue;
        }

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

        blocks_drawn++;

        float perc = static_cast<float>(i.second->volume) /
                     (PA_VOLUME_NORM * 1.5f);

        if (has_volume) {
            if (ui.static_bar) {
                volumeBar(ui.width, ui.height, 0, baseY + 3, perc, perc);
            } else {
                volumeBar(ui.width, ui.height, 0, baseY + 3, perc, i.second->peak);
            }
        } else { // Configuration
            if (i.first == selected_index) {
                wattron(ui.window, COLOR_PAIR(COLOR_SELECTED));
            } else {
                wattron(ui.window, COLOR_PAIR(COLOR_DEFAULT));
            }

            if (i.second->active_attribute != nullptr) {
                mvwaddstr(
                    ui.window,
                    baseY + 3,
                    3,
                    i.second->active_attribute->description
                );
                borderBox(ui.width - 2, 2, 1, baseY + 2);
            }

            if (i.first == selected_index) {
                wattroff(ui.window, COLOR_PAIR(COLOR_SELECTED));
            } else {
                wattroff(ui.window, COLOR_PAIR(COLOR_DEFAULT));
            }
        }

        if (current_block == selected_block) {
            wattron(ui.window, COLOR_PAIR(COLOR_SELECTED));
        } else {
            wattron(ui.window, COLOR_PAIR(COLOR_DEFAULT));
        }

        char label[255] = {0};
        std::string app = {0};

        int toggle_len = 0;

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

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

                if (name != nullptr) {
                    unsigned int len = strlen(name);
                    unsigned int sink_pos = ui.width - 1 - len;

                    mvwaddstr(
                        ui.window,
                        baseY + 1,
                        sink_pos,
                        name
                    );

                    toggle_len += strlen(name);
                }
            }
        } else {
            if (i.second->active_attribute != nullptr && has_volume) {
                unsigned int len = strlen(
                                       i.second->active_attribute->description
                                   );

                unsigned int sink_pos = ui.width - 1 - len;

                mvwaddstr(
                    ui.window,
                    baseY + 1,
                    sink_pos,
                    i.second->active_attribute->description
                );

                toggle_len += strlen(i.second->active_attribute->description);
            }
        }

        const char *app_name = i.second->getAppName();

        if (app_name != nullptr && strlen(i.second->getAppName()) > 0) {
            app = std::string(i.second->getAppName()) + ": " +
                  std::string(i.second->name);
        } else {
            app = i.second->name;
        }

        if (i.second->is_default) {
            app = ui.indicator + app;
        }

        bool dots = false;

        while (1) {
            if (has_volume) {
                if (i.second->mute) {
                    snprintf(
                        label,
                        sizeof(label),
                        "%s%s (muted)",
                        app.c_str(),
                        (dots) ? "..." : ""
                    );
                } else {
                    snprintf(
                        label,
                        sizeof(label),
                        "%s%s (%d%%)",
                        app.c_str(),
                        (dots) ? "..." : "",
                        static_cast<int>(perc * (1.5f * 100.f) + 0.1f)
                    );
                }
            } else {
                snprintf(
                    label,
                    sizeof(label),
                    "%s%s",
                    app.c_str(),
                    (dots) ? "..." : ""
                );
            }

            int output_len = strlen(label);
            int volume_len = (has_volume) ? 4 : 1;

            if ((output_len + toggle_len + volume_len) > ui.width) {
                if (app.length() > 0) {
                    app.resize(app.length() - 1);
                } else {
                    break;
                }

                dots = true;
            } else {
                break;
            }
        }

        mvwaddstr(ui.window, baseY + 1, 1, label);

        if (current_block == selected_block) {
            wattroff(ui.window, COLOR_PAIR(COLOR_SELECTED));
        } else {
            wattroff(ui.window, COLOR_PAIR(COLOR_DEFAULT));
        }

        baseY += BLOCK_SIZE;
        current_block++;
    }

    if (more_up) {
        mvwaddstr(
            ui.window,
            0,
            (ui.width / 2) - 4,
            "\u2191\u2191\u2191\u2191"
        );
    }

    if (more_down) {
        mvwaddstr(
            ui.window,
            ui.height - 2,
            (ui.width / 2) - 4,
            "\u2193\u2193\u2193\u2193"
        );
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1e8, %rsp            # imm = 0x1E8
movq 0x10(%rdi), %rsi
testq %rsi, %rsi
je 0xcbe4
movq %rdi, %r14
leaq 0xc22c(%rip), %r12      # 0x18828
movzbl 0x101(%r12), %eax
andl $0x1, %eax
xorl $0x5, %eax
movzbl 0x102(%r12), %ecx
subl %ecx, %eax
cmpb $0x0, 0x8(%rdi)
pushq $0x5
popq %rcx
cmovnel %eax, %ecx
movl 0xc(%r12), %eax
addl $-0x2, %eax
cltd
movl %ecx, 0x20(%rsp)
idivl %ecx
movl %eax, 0x24(%rdi)
movq 0x18(%rsi), %rbx
addq $0x8, %rsi
movq %rsi, 0x50(%rsp)
movl $0xe0, %eax
addq 0xb975(%rip), %rax      # 0x17fc0
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %r13
movq $0x0, 0x48(%rsp)
movl $0x0, 0x14(%rsp)
xorl %ebp, %ebp
xorl %r15d, %r15d
cmpq 0x50(%rsp), %rbx
je 0xcb6a
movl 0x20(%r14), %ecx
movl 0x24(%r14), %eax
subl %eax, %ecx
cmpl %ecx, %ebp
jle 0xc6e2
cmpl %eax, 0x14(%rsp)
jge 0xcb6a
movq 0x28(%rbx), %rax
movl 0x214(%rax), %ecx
cvtsi2ss %rcx, %xmm0
divss 0x5293(%rip), %xmm0     # 0x11938
movss %xmm0, 0xc(%rsp)
cmpb $0x1, 0x8(%r14)
movq %r15, 0x18(%rsp)
jne 0xc6ee
movl 0x8(%r12), %edi
movl 0xc(%r12), %esi
leal 0x3(%r15), %ecx
cmpb $0x1, 0x103(%r12)
jne 0xc780
movss 0xc(%rsp), %xmm0
movaps %xmm0, %xmm1
jmp 0xc78e
movb $0x1, %al
movq %rax, 0x48(%rsp)
jmp 0xcb58
movl 0x20(%rbx), %eax
xorl %esi, %esi
cmpl 0xc(%r14), %eax
sete %sil
movq 0x10(%r12), %rdi
shll $0x8, %esi
addl $0x900, %esi            # imm = 0x900
xorl %edx, %edx
callq 0x62e0
movq 0x28(%rbx), %rax
cmpq $0x0, 0x230(%rax)
je 0xc76b
movq 0x10(%r12), %rdi
leal 0x3(%r15), %esi
pushq $0x3
popq %rdx
callq 0x6610
cmpl $-0x1, %eax
je 0xc754
movq 0x10(%r12), %rdi
movq 0x28(%rbx), %rax
movq 0x230(%rax), %rsi
movl $0x107, %eax            # imm = 0x107
addq %rax, %rsi
pushq $-0x1
popq %rdx
callq 0x61f0
movl 0x8(%r12), %edi
addl $-0x2, %edi
leal 0x2(%r15), %ecx
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0xce80
movl 0x20(%rbx), %eax
movq 0x10(%r12), %rdi
cmpl 0xc(%r14), %eax
jne 0xc795
movl $0xa00, %esi            # imm = 0xA00
jmp 0xc79a
movss 0x228(%rax), %xmm1
movss 0xc(%rsp), %xmm0
callq 0xcc52
jmp 0xc7a1
movl $0x900, %esi            # imm = 0x900
xorl %edx, %edx
callq 0x6760
xorl %esi, %esi
movl %ebp, 0x24(%rsp)
cmpl 0x20(%r14), %ebp
sete %sil
movq %r12, %r15
movq 0x10(%r12), %rdi
shll $0x8, %esi
addl $0x900, %esi            # imm = 0x900
xorl %edx, %edx
callq 0x62e0
movl $0xff, %edx
leaq 0xe0(%rsp), %rdi
xorl %esi, %esi
callq 0x6360
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
andw $0x0, 0x38(%rsp)
movq $0x1, 0x30(%rsp)
movq 0x18(%r14), %r12
testq %r12, %r12
je 0xc86a
movq 0x28(%rbx), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movl %eax, 0x60(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x93a8
movq 0x18(%r14), %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
je 0xc8f1
movq 0x28(%rax), %r12
addq $0x10, %r12
movq %r12, %rdi
callq 0x62a0
notl %eax
addl 0x8(%r15), %eax
movq 0x10(%r15), %rdi
movq 0x18(%rsp), %rcx
leal 0x1(%rcx), %esi
movl %eax, %edx
callq 0x6610
cmpl $-0x1, %eax
je 0xc8e4
movq 0x10(%r15), %rdi
movq %r12, %rsi
pushq $-0x1
popq %rdx
callq 0x61f0
jmp 0xc8e4
movq 0x28(%rbx), %rax
movq 0x230(%rax), %rdi
xorl %r12d, %r12d
testq %rdi, %rdi
je 0xc8f4
cmpb $0x1, 0x8(%r14)
jne 0xc8f4
addq $0x107, %rdi            # imm = 0x107
callq 0x62a0
notl %eax
movq %r15, %r12
addl 0x8(%r15), %eax
movq 0x10(%r15), %rdi
movq 0x18(%rsp), %rcx
leal 0x1(%rcx), %esi
movl %eax, %edx
callq 0x6610
cmpl $-0x1, %eax
je 0xc8d1
movq 0x10(%r12), %rdi
movq 0x28(%rbx), %rax
movq 0x230(%rax), %rsi
movl $0x107, %eax            # imm = 0x107
addq %rax, %rsi
pushq $-0x1
popq %rdx
callq 0x61f0
movq 0x28(%rbx), %rax
movq 0x230(%rax), %r12
movl $0x107, %eax            # imm = 0x107
addq %rax, %r12
movq %r12, %rdi
callq 0x62a0
movq %rax, %r12
jmp 0xc8f4
xorl %r12d, %r12d
movq 0x28(%rbx), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
testq %rax, %rax
je 0xc9c6
movq 0x28(%rbx), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
cmpb $0x0, (%rax)
je 0xc9c6
movq 0x28(%rbx), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
leaq 0xa0(%rsp), %rbp
movq %rbp, %rdi
movq %rax, %rsi
leaq 0x13(%rsp), %rdx
callq 0xa1f6
leaq 0xc0(%rsp), %rdi
movq %rbp, %rsi
leaq 0x501e(%rip), %rdx      # 0x1196c
callq 0xe4b8
movq 0x28(%rbx), %rsi
addq $0x10, %rsi
leaq 0x80(%rsp), %rdi
leaq 0x12(%rsp), %rdx
callq 0xa1f6
leaq 0x60(%rsp), %r13
movq %r13, %rdi
leaq 0xc0(%rsp), %rbp
movq %rbp, %rsi
leaq 0x80(%rsp), %rdx
callq 0xe451
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x6720
movq %r13, %rdi
callq 0x62b0
leaq 0x80(%rsp), %rdi
callq 0x62b0
movq %rbp, %rdi
callq 0x62b0
leaq 0xa0(%rsp), %rdi
callq 0x62b0
jmp 0xc9d8
movq 0x28(%rbx), %rsi
addq $0x10, %rsi
leaq 0x28(%rsp), %rdi
callq 0x6b90
movq 0x28(%rbx), %rax
cmpb $0x1, 0x20e(%rax)
jne 0xca12
leaq 0x60(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq %rdi, %r13
leaq 0x28(%rsp), %rbp
movq %rbp, %rdx
callq 0xe4d7
movq %rbp, %rdi
movq %r13, %rsi
callq 0x6720
movq %r13, %rdi
callq 0x62b0
incl 0x14(%rsp)
movss 0xc(%rsp), %xmm0
mulss 0x4f18(%rip), %xmm0     # 0x1193c
addss 0x4f14(%rip), %xmm0     # 0x11940
cvttss2si %xmm0, %ebp
leaq 0x3ab8(%rip), %r8       # 0x104ef
cmpb $0x1, 0x8(%r14)
jne 0xca69
movq 0x28(%rbx), %rax
movq 0x28(%rsp), %rcx
cmpb $0x1, 0x218(%rax)
jne 0xca8e
movl $0xff, %esi
leaq 0xe0(%rsp), %r13
movq %r13, %rdi
leaq 0x4f08(%rip), %rdx      # 0x1196f
jmp 0xca85
movq 0x28(%rsp), %rcx
movl $0xff, %esi
leaq 0xe0(%rsp), %r13
movq %r13, %rdi
leaq 0x4f07(%rip), %rdx      # 0x1198c
xorl %eax, %eax
callq 0x69c0
jmp 0xcaaf
movl $0xff, %esi
leaq 0xe0(%rsp), %r13
movq %r13, %rdi
leaq 0x4edb(%rip), %rdx      # 0x11980
movl %ebp, %r9d
xorl %eax, %eax
callq 0x69c0
movq %r13, %rdi
callq 0x62a0
movzbl 0x8(%r14), %ecx
leal (%rcx,%rcx,2), %ecx
addl %r12d, %eax
addl %ecx, %eax
incl %eax
cmpl 0x8(%r15), %eax
jle 0xcaef
movq 0x30(%rsp), %rsi
testq %rsi, %rsi
je 0xcaef
decq %rsi
leaq 0x28(%rsp), %rdi
callq 0x67e0
leaq 0x4e92(%rip), %r8       # 0x1197c
jmp 0xca37
movq %r15, %r12
movq 0x10(%r15), %rdi
movq 0x18(%rsp), %r15
leal 0x1(%r15), %esi
pushq $0x1
popq %rdx
callq 0x6610
leaq 0xe0(%rsp), %rsi
movl 0x24(%rsp), %ebp
cmpl $-0x1, %eax
je 0xcb25
movq 0x10(%r12), %rdi
pushq $-0x1
popq %rdx
callq 0x61f0
xorl %esi, %esi
cmpl 0x20(%r14), %ebp
sete %sil
movq 0x10(%r12), %rdi
shll $0x8, %esi
addl $0x900, %esi            # imm = 0x900
xorl %edx, %edx
callq 0x6760
addl 0x20(%rsp), %r15d
leaq 0x28(%rsp), %rdi
callq 0x62b0
leaq 0x60(%rsp), %r13
incl %ebp
movq %rbx, %rdi
callq 0x6450
movq %rax, %rbx
jmp 0xc66b
testb $0x1, 0x48(%rsp)
je 0xcba4
movq 0x10(%r12), %rdi
movl 0x8(%r12), %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
leal -0x4(%rax), %edx
xorl %esi, %esi
callq 0x6610
cmpl $-0x1, %eax
je 0xcba4
movq 0x10(%r12), %rdi
leaq 0x4df5(%rip), %rsi      # 0x11991
pushq $-0x1
popq %rdx
callq 0x61f0
cmpq 0x50(%rsp), %rbx
je 0xcbe4
movq 0x10(%r12), %rdi
movl 0x8(%r12), %eax
movl 0xc(%r12), %esi
addl $-0x2, %esi
cltd
pushq $0x2
popq %rcx
idivl %ecx
leal -0x4(%rax), %edx
callq 0x6610
cmpl $-0x1, %eax
je 0xcbe4
movq 0x10(%r12), %rdi
leaq 0x4dc2(%rip), %rsi      # 0x1199e
pushq $-0x1
popq %rdx
callq 0x61f0
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xcc3c
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x62b0
jmp 0xcc0d
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x62b0
jmp 0xcc1f
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x62b0
jmp 0xcc3f
jmp 0xcc3c
jmp 0xcc3c
jmp 0xcc3c
jmp 0xcc3c
jmp 0xcc3c
jmp 0xcc3c
jmp 0xcc3c
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x62b0
movq %rbx, %rdi
callq 0x6ac0
nop