// File: /workspace/github_cpp_makefile_star2_O3/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, %ebx
movq 0xa4ff1(%rip), %r12     # 0xfbcd0
movq 0x1ae0(%r12), %rax
movl 0x1c80(%r12), %r14d
testb $0x20, %sil
je 0x56d03
cmpl %r14d, 0x1c70(%r12)
jg 0x56edc
movslq 0xc8(%rax), %rcx
testq %rcx, %rcx
jle 0x56eeb
movq 0x1c90(%r12), %rdx
movq %rdx, -0x38(%rbp)
movl 0x1a68(%r12), %edx
movl %edx, -0x2c(%rbp)
movq 0xd0(%rax), %rax
movl -0x4(%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
callq 0x56f29
leaq -0x58(%rbp), %r13
movaps %xmm0, -0x50(%rbp)
movlps %xmm0, (%r13)
leaq 0x128(%r12), %r15
movq %r15, %rdi
callq 0x4750f
testb %al, %al
cmovneq %r15, %r13
movq (%r13), %r13
movl 0x1c70(%r12), %eax
cmpl %r14d, %eax
jle 0x56dbe
testl %r14d, %r14d
js 0x56f0a
movq 0x1c78(%r12), %rax
leaq (%r14,%r14,2), %rcx
shlq $0x4, %rcx
cmpl %ebx, (%rax,%rcx)
jne 0x56dac
addq %rcx, %rax
movl 0x1a68(%r12), %ecx
decl %ecx
cmpl %ecx, 0x18(%rax)
jne 0x56dac
movl -0x2c(%rbp), %ecx
movl %ecx, 0x18(%rax)
jmp 0x56edc
movl %r14d, %edi
xorl %esi, %esi
callq 0x5702e
movl 0x1c70(%r12), %eax
cmpl 0x1c74(%r12), %eax
jne 0x56ddd
leal 0x1(%rax), %r15d
testl %eax, %eax
je 0x56dea
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
addl %eax, %ecx
jmp 0x56def
movq 0x1c78(%r12), %r14
jmp 0x56e8c
movl $0x8, %ecx
cmpl %r15d, %ecx
cmovgl %ecx, %r15d
movslq %r15d, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rdi
movq 0xa4ec8(%rip), %rax     # 0xfbcd0
testq %rax, %rax
je 0x56e13
incl 0x3b4(%rax)
movq 0xa4ec6(%rip), %rsi     # 0xfbce0
callq *0xa06f0(%rip)          # 0xf7510
movq %rax, %r14
movq 0x1c78(%r12), %rsi
testq %rsi, %rsi
je 0x56e74
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 0x56e67
movq 0xa4e74(%rip), %rax     # 0xfbcd0
testq %rax, %rax
je 0x56e67
decl 0x3b4(%rax)
movq 0xa4e72(%rip), %rsi     # 0xfbce0
callq *0xa06a4(%rip)          # 0xf7518
movq %r14, 0x1c78(%r12)
movl %r15d, 0x1c74(%r12)
movl 0x1c70(%r12), %eax
cltq
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movl %ebx, (%r14,%rax)
movl $0x0, 0x4(%r14,%rax)
movq $0x0, 0x8(%r14,%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0x10(%r14,%rax)
movl -0x2c(%rbp), %ecx
movl %ecx, 0x18(%r14,%rax)
movl -0x30(%rbp), %ecx
movl %ecx, 0x1c(%r14,%rax)
movaps -0x50(%rbp), %xmm0
movlps %xmm0, 0x20(%r14,%rax)
movq %r13, 0x28(%r14,%rax)
incl 0x1c70(%r12)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x76ab8(%rip), %rdi     # 0xcd9aa
leaq 0x62792(%rip), %rsi     # 0xb968b
leaq 0x63af8(%rip), %rcx     # 0xba9f8
movl $0x666, %edx            # imm = 0x666
callq 0xc140
leaq 0x62767(%rip), %rdi     # 0xb9678
leaq 0x62773(%rip), %rsi     # 0xb968b
leaq 0x63c2b(%rip), %rcx     # 0xbab4a
movl $0x65c, %edx            # imm = 0x65C
callq 0xc140