// File: Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: ImGui::CollapsingHeader(char const*, bool*, int)
bool ImGui::CollapsingHeader(const char* label, bool* p_visible, ImGuiTreeNodeFlags flags)
{
    ImGuiWindow* window = GetCurrentWindow();
    if (window->SkipItems)
        return false;

    if (p_visible && !*p_visible)
        return false;

    ImGuiID id = window->GetID(label);
    flags |= ImGuiTreeNodeFlags_CollapsingHeader;
    if (p_visible)
        flags |= ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_ClipLabelForTrailingButton;
    bool is_open = TreeNodeBehavior(id, flags, label);
    if (p_visible != NULL)
    {
        // Create a small overlapping close button
        // FIXME: We can evolve this into user accessible helpers to add extra buttons on title bars, headers, etc.
        // FIXME: CloseButton can overlap into text, need find a way to clip the text somehow.
        ImGuiContext& g = *GImGui;
        ImGuiLastItemDataBackup last_item_backup;
        float button_size = g.FontSize;
        float button_x = ImMax(window->DC.LastItemRect.Min.x, window->DC.LastItemRect.Max.x - g.Style.FramePadding.x * 2.0f - button_size);
        float button_y = window->DC.LastItemRect.Min.y;
        ImGuiID close_button_id = GetIDWithSeed("#CLOSE", NULL, id);
        if (CloseButton(close_button_id, ImVec2(button_x, button_y)))
            *p_visible = false;
        last_item_backup.Restore();
    }

    return is_open;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
callq 0xeb270
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
testb $0x1, 0x93(%rax)
je 0x152655
movb $0x0, -0x1(%rbp)
jmp 0x15279a
cmpq $0x0, -0x18(%rbp)
je 0x15266e
movq -0x18(%rbp), %rax
testb $0x1, (%rax)
jne 0x15266e
movb $0x0, -0x1(%rbp)
jmp 0x15279a
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xc9910
movl %eax, -0x2c(%rbp)
movl -0x1c(%rbp), %eax
orl $0x1a, %eax
movl %eax, -0x1c(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x15269d
movl -0x1c(%rbp), %eax
orl $0x100004, %eax         # imm = 0x100004
movl %eax, -0x1c(%rbp)
movl -0x2c(%rbp), %edi
movl -0x1c(%rbp), %esi
movq -0x10(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x151110
andb $0x1, %al
movb %al, -0x2d(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x152792
leaq 0xc0879(%rip), %rax     # 0x212f40
movq (%rax), %rax
movq %rax, -0x38(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x1625d0
movq -0x38(%rbp), %rax
movss 0x1980(%rax), %xmm0
movss %xmm0, -0x64(%rbp)
movq -0x28(%rbp), %rax
movss 0x12c(%rax), %xmm0
movq -0x28(%rbp), %rax
movss 0x134(%rax), %xmm2
movq -0x38(%rbp), %rax
movss 0x1598(%rax), %xmm1
movd %xmm1, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
addss %xmm1, %xmm1
addss %xmm2, %xmm1
subss -0x64(%rbp), %xmm1
callq 0x139050
movss %xmm0, -0x68(%rbp)
movq -0x28(%rbp), %rax
movss 0x130(%rax), %xmm0
movss %xmm0, -0x6c(%rbp)
movl -0x2c(%rbp), %edx
leaq 0x2442b(%rip), %rdi     # 0x176b76
xorl %eax, %eax
movl %eax, %esi
callq 0xdb5e0
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x7c(%rbp)
movss -0x68(%rbp), %xmm0
movss -0x6c(%rbp), %xmm1
leaq -0x78(%rbp), %rdi
callq 0xbf4c0
movl -0x7c(%rbp), %edi
leaq -0x78(%rbp), %rsi
callq 0x13ae80
testb $0x1, %al
jne 0x152782
jmp 0x152789
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
leaq -0x60(%rbp), %rdi
callq 0x162610
movb -0x2d(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)