// File: /workspace/github_cpp_makefile_star2_O1/Ciaxur[P]yagb-emu/include/imgui/imgui.cpp
// Function: ImGui::ClosePopupToLevel(int, bool)
void ImGui::ClosePopupToLevel(int remaining, bool restore_focus_to_window_under_popup)
{
    ImGuiContext& g = *GImGui;
    IMGUI_DEBUG_LOG_POPUP("ClosePopupToLevel(%d), restore_focus_to_window_under_popup=%d\n", remaining, restore_focus_to_window_under_popup);
    IM_ASSERT(remaining >= 0 && remaining < g.OpenPopupStack.Size);

    // Trim open popup stack
    ImGuiWindow* focus_window = g.OpenPopupStack[remaining].SourceWindow;
    ImGuiWindow* popup_window = g.OpenPopupStack[remaining].Window;
    g.OpenPopupStack.resize(remaining);

    if (restore_focus_to_window_under_popup)
    {
        if (focus_window && !focus_window->WasActive && popup_window)
        {
            // Fallback
            FocusTopMostWindowUnderOne(popup_window, NULL);
        }
        else
        {
            if (g.NavLayer == ImGuiNavLayer_Main && focus_window)
                focus_window = NavRestoreLastChildNavWindow(focus_window);
            FocusWindow(focus_window);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testl %edi, %edi
js 0x582e6
movl %edi, %r15d
movq 0xa5b69(%rip), %r12     # 0xfdcd0
cmpl %edi, 0x1c70(%r12)
jle 0x582e6
movl %esi, %ebx
movq 0x1c78(%r12), %rax
movl %r15d, %ecx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movq 0x8(%rax,%rcx), %rdi
movq 0x10(%rax,%rcx), %r13
movl 0x1c74(%r12), %eax
cmpl %r15d, %eax
jge 0x58267
testl %eax, %eax
je 0x581bb
movl %eax, %r14d
shrl $0x1f, %r14d
addl %eax, %r14d
sarl %r14d
addl %eax, %r14d
jmp 0x581c1
movl $0x8, %r14d
cmpl %r15d, %r14d
cmovlel %r15d, %r14d
cmpl %r14d, %eax
jge 0x58267
movq %rdi, -0x38(%rbp)
movl %r14d, %eax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rdi
testq %r12, %r12
je 0x581ed
incl 0x3b4(%r12)
movq 0xa5aec(%rip), %rsi     # 0xfdce0
callq *0xa1316(%rip)          # 0xf9510
movq 0x1c78(%r12), %rsi
testq %rsi, %rsi
je 0x58253
movslq 0x1c70(%r12), %rcx
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rdx
movq %rax, -0x30(%rbp)
movq %rax, %rdi
callq 0xc080
movq 0x1c78(%r12), %rdi
testq %rdi, %rdi
je 0x58242
movq 0xa5a99(%rip), %rax     # 0xfdcd0
testq %rax, %rax
je 0x58242
decl 0x3b4(%rax)
movq 0xa5a97(%rip), %rsi     # 0xfdce0
callq *0xa12c9(%rip)          # 0xf9518
movq -0x30(%rbp), %rax
movq %rax, 0x1c78(%r12)
movl %r14d, 0x1c74(%r12)
movq -0x38(%rbp), %rdi
movl %r15d, 0x1c70(%r12)
testb %bl, %bl
je 0x582c2
testq %r13, %r13
je 0x58287
testq %rdi, %rdi
sete %al
orb 0x8f(%r13), %al
je 0x582d1
testq %r13, %r13
je 0x582ac
cmpl $0x0, 0x1cdc(%r12)
jne 0x582ac
movq 0x3a8(%r13), %rdi
testq %rdi, %rdi
je 0x582ac
cmpb $0x0, 0x8f(%rdi)
jne 0x582af
movq %r13, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x47d9b
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %esi, %esi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4c27b
leaq 0x61e38(%rip), %rdi     # 0xba125
leaq 0x5fe71(%rip), %rsi     # 0xb8165
leaq 0x61e5e(%rip), %rcx     # 0xba159
movl $0x1f5a, %edx           # imm = 0x1F5A
callq 0xc140