// File: /workspace/github_cpp_makefile_star2_O1/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 $0x18, %rsp
movl %edi, %ebx
movq 0xa5ee2(%rip), %r12     # 0xfdcd0
movq 0x1ae0(%r12), %rax
movl 0x1c80(%r12), %r14d
testb $0x20, %sil
je 0x57e12
cmpl %r14d, 0x1c70(%r12)
jg 0x57ff2
movq $0x0, -0x38(%rbp)
movslq 0xc8(%rax), %rcx
testq %rcx, %rcx
jle 0x58001
movq 0x1c90(%r12), %rdx
movq %rdx, -0x40(%rbp)
movl 0x1a68(%r12), %edx
movl %edx, -0x2c(%rbp)
movq 0xd0(%rax), %rax
movl -0x4(%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
callq 0x5803f
leaq -0x38(%rbp), %r13
movlps %xmm0, (%r13)
leaq 0x128(%r12), %r15
movq %r15, %rdi
callq 0x4806b
testb %al, %al
cmovneq %r15, %r13
movq (%r13), %r13
movl 0x1c70(%r12), %r15d
cmpl %r14d, %r15d
jle 0x57ed1
testl %r14d, %r14d
js 0x58020
movq 0x1c78(%r12), %rax
leaq (%r14,%r14,2), %rcx
shlq $0x4, %rcx
cmpl %ebx, (%rax,%rcx)
jne 0x57ebf
addq %rcx, %rax
movl 0x1a68(%r12), %ecx
decl %ecx
cmpl %ecx, 0x18(%rax)
jne 0x57ebf
movl -0x2c(%rbp), %ecx
movl %ecx, 0x18(%rax)
jmp 0x57ff2
movl %r14d, %edi
xorl %esi, %esi
callq 0x58144
movl 0x1c70(%r12), %r15d
movl 0x1c74(%r12), %eax
cmpl %eax, %r15d
jne 0x57f99
incl %r15d
testl %eax, %eax
je 0x57ef6
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
addl %eax, %ecx
jmp 0x57efb
movl $0x8, %ecx
cmpl %r15d, %ecx
cmovgl %ecx, %r15d
cmpl %r15d, %eax
jge 0x57f99
movslq %r15d, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rdi
movq 0xa5db3(%rip), %rax     # 0xfdcd0
testq %rax, %rax
je 0x57f28
incl 0x3b4(%rax)
movq 0xa5db1(%rip), %rsi     # 0xfdce0
callq *0xa15db(%rip)          # 0xf9510
movq %rax, %r14
movq 0x1c78(%r12), %rsi
testq %rsi, %rsi
je 0x57f89
movslq 0x1c70(%r12), %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rdx
movq %r14, %rdi
callq 0xc080
movq 0x1c78(%r12), %rdi
testq %rdi, %rdi
je 0x57f7c
movq 0xa5d5f(%rip), %rax     # 0xfdcd0
testq %rax, %rax
je 0x57f7c
decl 0x3b4(%rax)
movq 0xa5d5d(%rip), %rsi     # 0xfdce0
callq *0xa158f(%rip)          # 0xf9518
movq %r14, 0x1c78(%r12)
movl %r15d, 0x1c74(%r12)
movq 0x1c78(%r12), %rax
movslq 0x1c70(%r12), %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movl %ebx, (%rax,%rcx)
movl $0x0, 0x4(%rax,%rcx)
movq $0x0, 0x8(%rax,%rcx)
movq -0x40(%rbp), %rdx
movq %rdx, 0x10(%rax,%rcx)
movl -0x2c(%rbp), %edx
movl %edx, 0x18(%rax,%rcx)
movl -0x30(%rbp), %edx
movl %edx, 0x1c(%rax,%rcx)
movq -0x38(%rbp), %rdx
movq %rdx, 0x20(%rax,%rcx)
movq %r13, 0x28(%rax,%rcx)
incl 0x1c70(%r12)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x779d2(%rip), %rdi     # 0xcf9da
leaq 0x6367c(%rip), %rsi     # 0xbb68b
leaq 0x649e2(%rip), %rcx     # 0xbc9f8
movl $0x666, %edx            # imm = 0x666
callq 0xc140
leaq 0x63651(%rip), %rdi     # 0xbb678
leaq 0x6365d(%rip), %rsi     # 0xbb68b
leaq 0x64b15(%rip), %rcx     # 0xbcb4a
movl $0x65c, %edx            # imm = 0x65C
callq 0xc140