// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/include/imgui/imgui.cpp
// Function: ImGui::ClosePopupsOverWindow(ImGuiWindow*, bool)
void ImGui::ClosePopupsOverWindow(ImGuiWindow* ref_window, bool restore_focus_to_window_under_popup)
{
    ImGuiContext& g = *GImGui;
    if (g.OpenPopupStack.Size == 0)
        return;

    // Don't close our own child popup windows.
    int popup_count_to_keep = 0;
    if (ref_window)
    {
        // Find the highest popup which is a descendant of the reference window (generally reference window = NavWindow)
        for (; popup_count_to_keep < g.OpenPopupStack.Size; popup_count_to_keep++)
        {
            ImGuiPopupData& popup = g.OpenPopupStack[popup_count_to_keep];
            if (!popup.Window)
                continue;
            IM_ASSERT((popup.Window->Flags & ImGuiWindowFlags_Popup) != 0);
            if (popup.Window->Flags & ImGuiWindowFlags_ChildWindow)
                continue;

            // Trim the stack unless the popup is a direct parent of the reference window (the reference window is often the NavWindow)
            // - With this stack of window, clicking/focusing Popup1 will close Popup2 and Popup3:
            //     Window -> Popup1 -> Popup2 -> Popup3
            // - Each popups may contain child windows, which is why we compare ->RootWindow!
            //     Window -> Popup1 -> Popup1_Child -> Popup2 -> Popup2_Child
            bool ref_window_is_descendent_of_popup = false;
            for (int n = popup_count_to_keep; n < g.OpenPopupStack.Size; n++)
                if (ImGuiWindow* popup_window = g.OpenPopupStack[n].Window)
                    if (popup_window->RootWindow == ref_window->RootWindow)
                    {
                        ref_window_is_descendent_of_popup = true;
                        break;
                    }
            if (!ref_window_is_descendent_of_popup)
                break;
        }
    }
    if (popup_count_to_keep < g.OpenPopupStack.Size) // This test is not required but it allows to set a convenient breakpoint on the statement below
    {
        IMGUI_DEBUG_LOG_POPUP("ClosePopupsOverWindow(\"%s\") -> ClosePopupToLevel(%d)\n", ref_window->Name, popup_count_to_keep);
        ClosePopupToLevel(popup_count_to_keep, restore_focus_to_window_under_popup);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq 0xb4345(%rip), %rdx     # 0xfbcd0
movl 0x1c70(%rdx), %ecx
testq %rcx, %rcx
je 0x47a29
movq %rdi, %rax
xorl %edi, %edi
testq %rax, %rax
je 0x47a16
testl %ecx, %ecx
jle 0x47a16
movq 0x1c78(%rdx), %rdx
leaq 0x8(%rdx), %r8
xorl %edi, %edi
movq %rcx, %r9
leaq (%rdi,%rdi,2), %r10
shlq $0x4, %r10
movq 0x8(%rdx,%r10), %r10
testq %r10, %r10
je 0x47a05
movl 0xc(%r10), %r10d
btl $0x1a, %r10d
jae 0x47a30
btl $0x18, %r10d
jb 0x47a05
movq %r9, %r10
movq %r8, %r11
movq (%r11), %rbx
testq %rbx, %rbx
je 0x479fa
movq 0x390(%rbx), %rbx
cmpq 0x390(%rax), %rbx
je 0x47a05
addq $0x30, %r11
decq %r10
jne 0x479e2
jmp 0x47a16
incq %rdi
addq $0x30, %r8
decq %r9
cmpq %rcx, %rdi
jne 0x479b8
jmp 0x47a29
cmpl %ecx, %edi
jge 0x47a29
movzbl %sil, %esi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x5702e
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x70683(%rip), %rdi     # 0xb80ba
leaq 0x6e727(%rip), %rsi     # 0xb6165
leaq 0x706a9(%rip), %rcx     # 0xb80ee
movl $0x1f3a, %edx           # imm = 0x1F3A
callq 0xc140