// File: Ciaxur[P]yagb-emu/include/imgui/imgui.cpp
// Function: ImGui::CloseCurrentPopup()
void ImGui::CloseCurrentPopup()
{
    ImGuiContext& g = *GImGui;
    int popup_idx = g.BeginPopupStack.Size - 1;
    if (popup_idx < 0 || popup_idx >= g.OpenPopupStack.Size || g.BeginPopupStack[popup_idx].PopupId != g.OpenPopupStack[popup_idx].PopupId)
        return;

    // Closing a menu closes its top-most parent popup (unless a modal)
    while (popup_idx > 0)
    {
        ImGuiWindow* popup_window = g.OpenPopupStack[popup_idx].Window;
        ImGuiWindow* parent_popup_window = g.OpenPopupStack[popup_idx - 1].Window;
        bool close_parent = false;
        if (popup_window && (popup_window->Flags & ImGuiWindowFlags_ChildMenu))
            if (parent_popup_window == NULL || !(parent_popup_window->Flags & ImGuiWindowFlags_Modal))
                close_parent = true;
        if (!close_parent)
            break;
        popup_idx--;
    }
    IMGUI_DEBUG_LOG_POPUP("CloseCurrentPopup %d -> %d\n", g.BeginPopupStack.Size - 1, popup_idx);
    ClosePopupToLevel(popup_idx, true);

    // A common pattern is to close a popup when selecting a menu item/selectable that will open another window.
    // To improve this usage pattern, we avoid nav highlight for a single frame in the parent window.
    // Similarly, we could avoid mouse hover highlight in this window but it is less visually problematic.
    if (ImGuiWindow* window = g.NavWindow)
        window->DC.NavHideHighlightOneFrame = true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq 0x134c61(%rip), %rax    # 0x212f40
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x1c80(%rax), %eax
subl $0x1, %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jl 0xde33d
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x1c70(%rcx), %eax
jge 0xde33d
movq -0x8(%rbp), %rdi
addq $0x1c80, %rdi           # imm = 0x1C80
movl -0xc(%rbp), %esi
callq 0xeb4c0
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
addq $0x1c70, %rdi           # imm = 0x1C70
movl -0xc(%rbp), %esi
callq 0xeb4c0
movq %rax, %rcx
movl -0x34(%rbp), %eax
cmpl (%rcx), %eax
je 0xde342
jmp 0xde405
jmp 0xde344
cmpl $0x0, -0xc(%rbp)
jle 0xde3d7
movq -0x8(%rbp), %rdi
addq $0x1c70, %rdi           # imm = 0x1C70
movl -0xc(%rbp), %esi
callq 0xeb4c0
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
addq $0x1c70, %rdi           # imm = 0x1C70
movl -0xc(%rbp), %esi
subl $0x1, %esi
callq 0xeb4c0
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movb $0x0, -0x21(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xde3c1
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x10000000, %eax       # imm = 0x10000000
cmpl $0x0, %eax
je 0xde3c1
cmpq $0x0, -0x20(%rbp)
je 0xde3bb
movq -0x20(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x8000000, %eax        # imm = 0x8000000
cmpl $0x0, %eax
jne 0xde3bf
movb $0x1, -0x21(%rbp)
jmp 0xde3c1
testb $0x1, -0x21(%rbp)
jne 0xde3c9
jmp 0xde3d7
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xde344
movl -0xc(%rbp), %edi
movl $0x1, %esi
callq 0xde1b0
movq -0x8(%rbp), %rax
movq 0x1c90(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xde405
movq -0x30(%rbp), %rax
movb $0x1, 0x15c(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)