// File: donfreiday[P]gb/./imgui/imgui.cpp
// Function: ImGui::Combo(char const*, int*, bool (*)(void*, int, char const**), void*, int, int)
bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int height_in_items)
{
    ImGuiWindow* window = GetCurrentWindow();
    if (window->SkipItems)
        return false;

    ImGuiState& g = *GImGui;
    const ImGuiStyle& style = g.Style;
    const ImGuiID id = window->GetID(label);
    const float w = CalcItemWidth();

    const ImVec2 label_size = CalcTextSize(label, NULL, true);
    const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
    const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
    ItemSize(total_bb, style.FramePadding.y);
    if (!ItemAdd(total_bb, &id))
        return false;

    const float arrow_size = (g.FontSize + style.FramePadding.x * 2.0f);
    const bool hovered = IsHovered(frame_bb, id);

    const ImRect value_bb(frame_bb.Min, frame_bb.Max - ImVec2(arrow_size, 0.0f));
    RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
    RenderFrame(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y), frame_bb.Max, window->Color(hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button), true, style.FrameRounding); // FIXME-ROUNDING
    RenderCollapseTriangle(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y) + style.FramePadding, true);

    if (*current_item >= 0 && *current_item < items_count)
    {
        const char* item_text;
        if (items_getter(data, *current_item, &item_text))
            RenderTextClipped(frame_bb.Min + style.FramePadding, value_bb.Max, item_text, NULL, NULL);
    }

    if (label_size.x > 0)
        RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);

    bool menu_toggled = false;
    if (hovered)
    {
        g.HoveredId = id;
        if (g.IO.MouseClicked[0])
        {
            SetActiveID(0);
            if (IsPopupOpen(id))
            {
                ClosePopup(id);
            }
            else
            {
                FocusWindow(window);
                ImGui::OpenPopup(label);
                menu_toggled = true;
            }
        }
    }

    bool value_changed = false;
    if (IsPopupOpen(id))
    {
        // Size default to hold ~7 items
        if (height_in_items < 0)
            height_in_items = 7;

        float popup_height = (label_size.y + style.ItemSpacing.y) * ImMin(items_count, height_in_items) + (style.FramePadding.y * 3);
        ImRect popup_rect(ImVec2(frame_bb.Min.x, frame_bb.Max.y), ImVec2(frame_bb.Max.x, frame_bb.Max.y + popup_height));
        popup_rect.Max.y = ImMin(popup_rect.Max.y, g.IO.DisplaySize.y - style.DisplaySafeAreaPadding.y); // Adhoc height limit for Combo. Ideally should be handled in Begin() along with other popups size, we want to have the possibility of moving the popup above as well.
        ImGui::SetNextWindowPos(popup_rect.Min);
        ImGui::SetNextWindowSize(popup_rect.GetSize());
        ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style.FramePadding);

        const ImGuiWindowFlags flags = ImGuiWindowFlags_ComboBox | ((window->Flags & ImGuiWindowFlags_ShowBorders) ? ImGuiWindowFlags_ShowBorders : 0);
        if (BeginPopupEx(label, flags))
        {
            // Display items
            ImGui::Spacing();
            for (int i = 0; i < items_count; i++)
            {
                ImGui::PushID((void*)(intptr_t)i);
                const bool item_selected = (i == *current_item);
                const char* item_text;
                if (!items_getter(data, i, &item_text))
                    item_text = "*Unknown item*";
                if (ImGui::Selectable(item_text, item_selected))
                {
                    SetActiveID(0);
                    value_changed = true;
                    *current_item = i;
                }
                if (item_selected && menu_toggled)
                    ImGui::SetScrollHere();
                ImGui::PopID();
            }
            ImGui::EndPopup();
        }
        ImGui::PopStyleVar();
    }
    return value_changed;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
callq 0x2e220
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
testb $0x1, 0x74(%rax)
je 0x2681f
movb $0x0, -0x1(%rbp)
jmp 0x26faa
movq 0x52c9a(%rip), %rax     # 0x794c0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
addq $0x13e8, %rax           # imm = 0x13E8
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, -0x190(%rbp)
callq 0xbc60
movl %eax, -0x4c(%rbp)
callq 0x185e0
movq -0x190(%rbp), %rsi
movss %xmm0, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %edx
movss 0x34807(%rip), %xmm0    # 0x5b07c
callq 0x10930
movlpd %xmm0, -0x58(%rbp)
movq -0x38(%rbp), %rax
addq $0xa8, %rax
movq %rax, -0x180(%rbp)
movss -0x50(%rbp), %xmm0
movss -0x54(%rbp), %xmm1
leaq -0x80(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x2d280
movq -0x188(%rbp), %rsi
movq -0x180(%rbp), %rdi
callq 0xc7e0
movlpd %xmm0, -0x78(%rbp)
movq -0x48(%rbp), %rdi
addq $0x20, %rdi
movss 0x347e6(%rip), %xmm0    # 0x5b0b8
callq 0xe4b0
movlpd %xmm0, -0x88(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0xc7e0
movq -0x180(%rbp), %rsi
movlpd %xmm0, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x2eb40
leaq -0x68(%rbp), %rax
movq %rax, -0x178(%rbp)
leaq -0x68(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x170(%rbp)
movss -0x58(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x26947
movq -0x48(%rbp), %rax
movss 0x34(%rax), %xmm0
addss -0x58(%rbp), %xmm0
movss %xmm0, -0x194(%rbp)
jmp 0x26954
xorps %xmm0, %xmm0
movss %xmm0, -0x194(%rbp)
jmp 0x26954
movss -0x194(%rbp), %xmm0
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
xorps %xmm1, %xmm1
callq 0x2d280
movq -0x170(%rbp), %rdi
movq -0x1a0(%rbp), %rsi
callq 0xc7e0
movq -0x178(%rbp), %rsi
movlpd %xmm0, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x2eb40
movq -0x48(%rbp), %rax
movss 0x24(%rax), %xmm0
leaq -0x98(%rbp), %rdi
callq 0xc060
leaq -0x98(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0xc0a0
testb $0x1, %al
jne 0x269d9
movb $0x0, -0x1(%rbp)
jmp 0x26faa
movq -0x40(%rbp), %rax
movss 0x1718(%rax), %xmm1
movq -0x48(%rbp), %rax
movss 0x20(%rax), %xmm0
addss %xmm0, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0xac(%rbp)
movl -0x4c(%rbp), %esi
leaq -0x68(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
xorl %edx, %edx
callq 0xc3f0
movb %al, -0xad(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movss -0xac(%rbp), %xmm0
leaq -0xd0(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
xorps %xmm1, %xmm1
callq 0x2d280
movq -0x1c8(%rbp), %rdi
movq -0x1c0(%rbp), %rsi
callq 0xdf20
movq -0x1b8(%rbp), %rsi
movlpd %xmm0, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rdx
callq 0x2eb40
movq -0x68(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x38(%rbp), %rdi
movl $0x6, %esi
movss 0x3457a(%rip), %xmm0    # 0x5b018
movss %xmm0, -0x1b0(%rbp)
callq 0x2ea40
movl %eax, %edi
movq -0x48(%rbp), %rax
movss 0x28(%rax), %xmm2
movsd -0xd8(%rbp), %xmm0
movsd -0xe0(%rbp), %xmm1
movl $0x1, %esi
movl %esi, -0x1ac(%rbp)
callq 0x10a20
movss -0x64(%rbp), %xmm1
movss -0x60(%rbp), %xmm0
movss -0xac(%rbp), %xmm2
subss %xmm2, %xmm0
leaq -0xe8(%rbp), %rdi
callq 0x2d280
movss -0x1b0(%rbp), %xmm0
movq -0x60(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x38(%rbp), %rdi
movzbl -0xad(%rbp), %esi
andl $0x1, %esi
addl $0x15, %esi
callq 0x2ea40
movl -0x1ac(%rbp), %esi
movl %eax, %edi
movq -0x48(%rbp), %rax
movss 0x28(%rax), %xmm2
movsd -0xe8(%rbp), %xmm0
movsd -0xf0(%rbp), %xmm1
callq 0x10a20
movss -0x64(%rbp), %xmm1
movss -0x60(%rbp), %xmm0
movss -0xac(%rbp), %xmm2
subss %xmm2, %xmm0
leaq -0x100(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x2d280
movq -0x1a8(%rbp), %rdi
movq -0x48(%rbp), %rsi
addq $0x20, %rsi
callq 0xc7e0
movlpd %xmm0, -0xf8(%rbp)
movsd -0xf8(%rbp), %xmm0
movl $0x1, %edi
movss 0x34477(%rip), %xmm1    # 0x5b018
xorl %esi, %esi
callq 0x10b80
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jl 0x26c35
movq -0x18(%rbp), %rax
movl (%rax), %eax
cmpl -0x2c(%rbp), %eax
jge 0x26c35
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl (%rcx), %esi
leaq -0x108(%rbp), %rdx
callq *%rax
testb $0x1, %al
jne 0x26bdd
jmp 0x26c33
movq -0x48(%rbp), %rsi
addq $0x20, %rsi
leaq -0x68(%rbp), %rdi
callq 0xc7e0
movlpd %xmm0, -0x110(%rbp)
leaq -0xc0(%rbp), %rsi
addq $0x8, %rsi
movq -0x108(%rbp), %rdx
leaq -0x110(%rbp), %rdi
xorl %eax, %eax
movl %eax, %r8d
movl $0x9, %r9d
movq %r8, %rcx
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0x105f0
jmp 0x26c35
movss -0x58(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x26c88
movss -0x64(%rbp), %xmm1
movss -0x60(%rbp), %xmm0
movq -0x48(%rbp), %rax
movss 0x24(%rax), %xmm2
movss 0x34(%rax), %xmm3
addss %xmm3, %xmm0
addss %xmm2, %xmm1
leaq -0x118(%rbp), %rdi
callq 0x2d280
movq -0x10(%rbp), %rdi
movsd -0x118(%rbp), %xmm0
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x10100
movb $0x0, -0x119(%rbp)
testb $0x1, -0xad(%rbp)
je 0x26cf2
movl -0x4c(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x1788(%rax)
movq -0x40(%rbp), %rax
testb $0x1, 0x354(%rax)
je 0x26cf0
xorl %edi, %edi
xorl %eax, %eax
movl %eax, %esi
callq 0xbe60
movl -0x4c(%rbp), %edi
callq 0x15840
testb $0x1, %al
jne 0x26ccb
jmp 0x26cd5
movl -0x4c(%rbp), %edi
callq 0x159b0
jmp 0x26cee
movq -0x38(%rbp), %rdi
callq 0xef00
movq -0x10(%rbp), %rdi
callq 0x15330
movb $0x1, -0x119(%rbp)
jmp 0x26cf0
jmp 0x26cf2
movb $0x0, -0x11a(%rbp)
movl -0x4c(%rbp), %edi
callq 0x15840
testb $0x1, %al
jne 0x26d0a
jmp 0x26f9f
cmpl $0x0, -0x30(%rbp)
jge 0x26d17
movl $0x7, -0x30(%rbp)
movss -0x54(%rbp), %xmm0
movq -0x48(%rbp), %rax
movss 0x30(%rax), %xmm1
addss %xmm1, %xmm0
movss %xmm0, -0x1e4(%rbp)
movl -0x2c(%rbp), %edi
movl -0x30(%rbp), %esi
callq 0x22cd0
movss -0x1e4(%rbp), %xmm0
cvtsi2ss %eax, %xmm2
movq -0x48(%rbp), %rax
movss 0x24(%rax), %xmm1
movss 0x3431b(%rip), %xmm3    # 0x5b074
mulss %xmm3, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x120(%rbp)
movss -0x68(%rbp), %xmm0
movss -0x5c(%rbp), %xmm1
leaq -0x138(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x2d280
movss -0x60(%rbp), %xmm0
movss -0x5c(%rbp), %xmm1
movss -0x120(%rbp), %xmm2
addss %xmm2, %xmm1
leaq -0x140(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x2d280
movq -0x1e0(%rbp), %rsi
movq -0x1d8(%rbp), %rdx
leaq -0x130(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x2eb40
movss -0x124(%rbp), %xmm0
movq -0x40(%rbp), %rax
movss 0xc(%rax), %xmm1
movq -0x48(%rbp), %rax
movss 0x6c(%rax), %xmm2
subss %xmm2, %xmm1
callq 0xe370
movq -0x1d0(%rbp), %rdi
movss %xmm0, -0x124(%rbp)
xorl %esi, %esi
callq 0x19450
movq -0x1d0(%rbp), %rdi
callq 0x2e250
movlpd %xmm0, -0x148(%rbp)
leaq -0x148(%rbp), %rdi
xorl %esi, %esi
callq 0xe790
movq -0x48(%rbp), %rsi
addq $0x20, %rsi
movl $0x1, %edi
callq 0x18ae0
movq -0x38(%rbp), %rax
movl 0xc(%rax), %edx
andl $0x80, %edx
xorl %eax, %eax
movl $0x80, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
orl $0x800000, %eax         # imm = 0x800000
movl %eax, -0x14c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14c(%rbp), %esi
callq 0x155e0
testb $0x1, %al
jne 0x26e7e
jmp 0x26f95
callq 0x27110
movl $0x0, -0x150(%rbp)
movl -0x150(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x26f90
movslq -0x150(%rbp), %rdi
callq 0x1b500
movl -0x150(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
sete %al
andb $0x1, %al
movb %al, -0x151(%rbp)
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rdi
movl -0x150(%rbp), %esi
leaq -0x160(%rbp), %rdx
callq *%rax
testb $0x1, %al
jne 0x26ee8
leaq 0x353b4(%rip), %rax     # 0x5c295
movq %rax, -0x160(%rbp)
movq -0x160(%rbp), %rax
movq %rax, -0x1f0(%rbp)
movb -0x151(%rbp), %al
movb %al, -0x1f1(%rbp)
leaq -0x168(%rbp), %rdi
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0x2d280
movb -0x1f1(%rbp), %al
movq -0x1f0(%rbp), %rdi
xorl %edx, %edx
leaq -0x168(%rbp), %rcx
andb $0x1, %al
movzbl %al, %esi
callq 0x27150
testb $0x1, %al
jne 0x26f3a
jmp 0x26f58
xorl %edi, %edi
xorl %eax, %eax
movl %eax, %esi
callq 0xbe60
movb $0x1, -0x11a(%rbp)
movl -0x150(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
testb $0x1, -0x151(%rbp)
je 0x26f77
testb $0x1, -0x119(%rbp)
je 0x26f77
movss 0x340b2(%rip), %xmm0    # 0x5b024
callq 0x1a030
callq 0x1b550
movl -0x150(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x150(%rbp)
jmp 0x26e8d
callq 0x15910
movl $0x1, %edi
callq 0x159f0
movb -0x11a(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
nopl (%rax,%rax)