// File: /workspace/github_cpp_makefile_star2_O2/Ciaxur[P]yagb-emu/include/imgui/imgui.cpp
// Function: ImGui::OpenPopupEx(unsigned int, int)
void ImGui::OpenPopupEx(ImGuiID id, ImGuiPopupFlags popup_flags)
{
    ImGuiContext& g = *GImGui;
    ImGuiWindow* parent_window = g.CurrentWindow;
    const int current_stack_size = g.BeginPopupStack.Size;

    if (popup_flags & ImGuiPopupFlags_NoOpenOverExistingPopup)
        if (IsPopupOpen(0u, ImGuiPopupFlags_AnyPopupId))
            return;

    ImGuiPopupData popup_ref; // Tagged as new ref as Window will be set back to NULL if we write this into OpenPopupStack.
    popup_ref.PopupId = id;
    popup_ref.Window = NULL;
    popup_ref.SourceWindow = g.NavWindow;
    popup_ref.OpenFrameCount = g.FrameCount;
    popup_ref.OpenParentId = parent_window->IDStack.back();
    popup_ref.OpenPopupPos = NavCalcPreferredRefPos();
    popup_ref.OpenMousePos = IsMousePosValid(&g.IO.MousePos) ? g.IO.MousePos : popup_ref.OpenPopupPos;

    IMGUI_DEBUG_LOG_POPUP("OpenPopupEx(0x%08X)\n", id);
    if (g.OpenPopupStack.Size < current_stack_size + 1)
    {
        g.OpenPopupStack.push_back(popup_ref);
    }
    else
    {
        // Gently handle the user mistakenly calling OpenPopup() every frame. It is a programming mistake! However, if we were to run the regular code path, the ui
        // would become completely unusable because the popup will always be in hidden-while-calculating-size state _while_ claiming focus. Which would be a very confusing
        // situation for the programmer. Instead, we silently allow the popup to proceed, it will keep reappearing and the programming error will be more obvious to understand.
        if (g.OpenPopupStack[current_stack_size].PopupId == id && g.OpenPopupStack[current_stack_size].OpenFrameCount == g.FrameCount - 1)
        {
            g.OpenPopupStack[current_stack_size].OpenFrameCount = popup_ref.OpenFrameCount;
        }
        else
        {
            // Close child popups if any, then flag popup for open/reopen
            ClosePopupToLevel(current_stack_size, false);
            g.OpenPopupStack.push_back(popup_ref);
        }

        // When reopening a popup we first refocus its parent, otherwise if its parent is itself a popup it would get closed by ClosePopupsOverWindow().
        // This is equivalent to what ClosePopupToLevel() does.
        //if (g.OpenPopupStack[current_stack_size].PopupId == id)
        //    FocusWindow(parent_window);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edi, %r14d
movq 0x9f597(%rip), %r12     # 0xe3ce0
movq 0x1ae0(%r12), %r15
movl 0x1c80(%r12), %ebx
testb $0x20, %sil
je 0x44773
xorl %edi, %edi
movl $0x80, %esi
callq 0x384af
testb %al, %al
jne 0x44845
xorps %xmm0, %xmm0
leaq -0x40(%rbp), %r13
movaps %xmm0, -0x20(%r13)
movaps %xmm0, (%r13)
movaps %xmm0, -0x10(%r13)
movl %r14d, -0x20(%r13)
movq 0x1c90(%r12), %rax
movq %rax, -0x10(%r13)
movl 0x1a68(%r12), %eax
movl %eax, -0x2c(%rbp)
movl %eax, -0x8(%r13)
addq $0xc8, %r15
movq %r15, %rdi
callq 0x4a148
movl (%rax), %eax
movl %eax, -0x4(%r13)
callq 0x44854
movlps %xmm0, (%r13)
leaq 0x128(%r12), %r15
movq %r15, %rdi
callq 0x381f3
testb %al, %al
cmoveq %r13, %r15
movq (%r15), %rax
movq %rax, 0x8(%r13)
leaq 0x1c70(%r12), %r15
cmpl %ebx, 0x1c70(%r12)
jle 0x44839
movq %r15, %rdi
movl %ebx, %esi
callq 0x4b386
cmpl %r14d, (%rax)
jne 0x44830
movq %r15, %rdi
movl %ebx, %esi
callq 0x4b386
movl 0x1a68(%r12), %ecx
decl %ecx
cmpl %ecx, 0x18(%rax)
jne 0x44830
movq %r15, %rdi
movl %ebx, %esi
callq 0x4b386
movl -0x2c(%rbp), %ecx
movl %ecx, 0x18(%rax)
jmp 0x44845
movl %ebx, %edi
xorl %esi, %esi
callq 0x44963
leaq -0x60(%rbp), %rsi
movq %r15, %rdi
callq 0x4b442
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq