// File: Ciaxur[P]yagb-emu/include/imgui/imgui.cpp
// Function: ImGui::FocusWindow(ImGuiWindow*)
void ImGui::FocusWindow(ImGuiWindow* window)
{
    ImGuiContext& g = *GImGui;

    if (g.NavWindow != window)
    {
        g.NavWindow = window;
        if (window && g.NavDisableMouseHover)
            g.NavMousePosDirty = true;
        g.NavInitRequest = false;
        g.NavId = window ? window->NavLastIds[0] : 0; // Restore NavId
        g.NavFocusScopeId = 0;
        g.NavIdIsAlive = false;
        g.NavLayer = ImGuiNavLayer_Main;
        //IMGUI_DEBUG_LOG("FocusWindow(\"%s\")\n", window ? window->Name : NULL);
    }

    // Close popups if any
    ClosePopupsOverWindow(window, false);

    // Move the root window to the top of the pile
    IM_ASSERT(window == NULL || window->RootWindow != NULL);
    ImGuiWindow* focus_front_window = window ? window->RootWindow : NULL; // NB: In docking branch this is window->RootWindowDockStop
    ImGuiWindow* display_front_window = window ? window->RootWindow : NULL;

    // Steal active widgets. Some of the cases it triggers includes:
    // - Focus a window while an InputText in another window is active, if focus happens before the old InputText can run.
    // - When using Nav to activate menu items (due to timing of activating on press->new window appears->losing ActiveId)
    if (g.ActiveId != 0 && g.ActiveIdWindow && g.ActiveIdWindow->RootWindow != focus_front_window)
        if (!g.ActiveIdNoClearOnFocusLoss)
            ClearActiveID();

    // Passing NULL allow to disable keyboard focus
    if (!window)
        return;

    // Bring to front
    BringWindowToFocusFront(focus_front_window);
    if (((window->Flags | display_front_window->Flags) & ImGuiWindowFlags_NoBringToFrontOnFocus) == 0)
        BringWindowToDisplayFront(display_front_window);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq 0x147bad(%rip), %rax    # 0x212f40
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x1c90(%rax), %rax
cmpq -0x8(%rbp), %rax
je 0xcb436
movq -0x8(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x1c90(%rax)
cmpq $0x0, -0x8(%rbp)
je 0xcb3da
movq -0x10(%rbp), %rax
testb $0x1, 0x1ce7(%rax)
je 0xcb3da
movq -0x10(%rbp), %rax
movb $0x1, 0x1ce5(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x1ce9(%rax)
cmpq $0x0, -0x8(%rbp)
je 0xcb3fb
movq -0x8(%rbp), %rax
movl 0x3b0(%rax), %eax
movl %eax, -0x24(%rbp)
jmp 0xcb402
xorl %eax, %eax
movl %eax, -0x24(%rbp)
jmp 0xcb402
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c98(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x1c9c(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x1ce4(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x1cdc(%rax)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0xcbdc0
movb $0x1, %al
cmpq $0x0, -0x8(%rbp)
movb %al, -0x25(%rbp)
je 0xcb45f
movq -0x8(%rbp), %rax
cmpq $0x0, 0x390(%rax)
setne %al
movb %al, -0x25(%rbp)
movb -0x25(%rbp), %al
testb $0x1, %al
jne 0xcb468
jmp 0xcb46a
jmp 0xcb489
leaq 0xa8dc7(%rip), %rdi     # 0x174238
leaq 0xa7a91(%rip), %rsi     # 0x172f09
movl $0x1889, %edx           # imm = 0x1889
leaq 0xa8de5(%rip), %rcx     # 0x174269
callq 0xd180
cmpq $0x0, -0x8(%rbp)
je 0xcb4a1
movq -0x8(%rbp), %rax
movq 0x390(%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0xcb4a9
xorl %eax, %eax
movq %rax, -0x30(%rbp)
jmp 0xcb4a9
movq -0x30(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0xcb4c9
movq -0x8(%rbp), %rax
movq 0x390(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0xcb4d1
xorl %eax, %eax
movq %rax, -0x38(%rbp)
jmp 0xcb4d1
movq -0x38(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1b30(%rax)
je 0xcb520
movq -0x10(%rbp), %rax
cmpq $0x0, 0x1b60(%rax)
je 0xcb520
movq -0x10(%rbp), %rax
movq 0x1b60(%rax), %rax
movq 0x390(%rax), %rax
cmpq -0x18(%rbp), %rax
je 0xcb520
movq -0x10(%rbp), %rax
testb $0x1, 0x1b3e(%rax)
jne 0xcb51e
callq 0xca040
jmp 0xcb520
cmpq $0x0, -0x8(%rbp)
jne 0xcb529
jmp 0xcb553
movq -0x18(%rbp), %rdi
callq 0xd9c20
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x20(%rbp), %rcx
orl 0xc(%rcx), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
jne 0xcb553
movq -0x20(%rbp), %rdi
callq 0xd9d20
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)