// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0xab6d6(%rip), %r12     # 0xe3ce0
movl 0x1c70(%r12), %eax
testl %eax, %eax
je 0x386b5
movl %esi, %ebx
movq %rdi, %r15
testq %rdi, %rdi
je 0x38694
addq $0x1c70, %r12           # imm = 0x1C70
xorl %r14d, %r14d
cmpl %eax, %r14d
jge 0x38697
movq %r12, %rdi
movl %r14d, %esi
callq 0x4b386
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x3868b
movl 0xc(%rax), %eax
btl $0x1a, %eax
jae 0x386c4
btl $0x18, %eax
jb 0x3868b
movl %r14d, %r13d
movl (%r12), %eax
cmpl %eax, %r13d
jge 0x38697
movq %r12, %rdi
movl %r13d, %esi
callq 0x4b386
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x38686
movq 0x390(%rax), %rax
cmpq 0x390(%r15), %rax
je 0x3868b
incl %r13d
jmp 0x38659
incl %r14d
movl (%r12), %eax
jmp 0x3862e
xorl %r14d, %r14d
cmpl %eax, %r14d
jge 0x386b5
movzbl %bl, %esi
movl %r14d, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x44963
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x66a1f(%rip), %rdi     # 0x9f0ea
leaq 0x64ac3(%rip), %rsi     # 0x9d195
leaq 0x66a45(%rip), %rcx     # 0x9f11e
movl $0x1f3a, %edx           # imm = 0x1F3A
callq 0xc140