// File: Ciaxur[P]yagb-emu/include/imgui/imgui.cpp
// Function: ImGui::NavProcessItem(ImGuiWindow*, ImRect const&, unsigned int)
static void ImGui::NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, const ImGuiID id)
{
    ImGuiContext& g = *GImGui;
    //if (!g.IO.NavActive)  // [2017/10/06] Removed this possibly redundant test but I am not sure of all the side-effects yet. Some of the feature here will need to work regardless of using a _NoNavInputs flag.
    //    return;

    const ImGuiItemFlags item_flags = window->DC.ItemFlags;
    const ImRect nav_bb_rel(nav_bb.Min - window->Pos, nav_bb.Max - window->Pos);

    // Process Init Request
    if (g.NavInitRequest && g.NavLayer == window->DC.NavLayerCurrent)
    {
        // Even if 'ImGuiItemFlags_NoNavDefaultFocus' is on (typically collapse/close button) we record the first ResultId so they can be used as a fallback
        if (!(item_flags & ImGuiItemFlags_NoNavDefaultFocus) || g.NavInitResultId == 0)
        {
            g.NavInitResultId = id;
            g.NavInitResultRectRel = nav_bb_rel;
        }
        if (!(item_flags & ImGuiItemFlags_NoNavDefaultFocus))
        {
            g.NavInitRequest = false; // Found a match, clear request
            NavUpdateAnyRequestFlag();
        }
    }

    // Process Move Request (scoring for navigation)
    // FIXME-NAV: Consider policy for double scoring (scoring from NavScoringRectScreen + scoring from a rect wrapped according to current wrapping policy)
    if ((g.NavId != id || (g.NavMoveRequestFlags & ImGuiNavMoveFlags_AllowCurrentNavId)) && !(item_flags & (ImGuiItemFlags_Disabled | ImGuiItemFlags_NoNav)))
    {
        ImGuiNavMoveResult* result = (window == g.NavWindow) ? &g.NavMoveResultLocal : &g.NavMoveResultOther;
#if IMGUI_DEBUG_NAV_SCORING
        // [DEBUG] Score all items in NavWindow at all times
        if (!g.NavMoveRequest)
            g.NavMoveDir = g.NavMoveDirLast;
        bool new_best = NavScoreItem(result, nav_bb) && g.NavMoveRequest;
#else
        bool new_best = g.NavMoveRequest && NavScoreItem(result, nav_bb);
#endif
        if (new_best)
            NavApplyItemToResult(result, window, id, nav_bb_rel);

        // Features like PageUp/PageDown need to maintain a separate score for the visible set of items.
        const float VISIBLE_RATIO = 0.70f;
        if ((g.NavMoveRequestFlags & ImGuiNavMoveFlags_AlsoScoreVisibleSet) && window->ClipRect.Overlaps(nav_bb))
            if (ImClamp(nav_bb.Max.y, window->ClipRect.Min.y, window->ClipRect.Max.y) - ImClamp(nav_bb.Min.y, window->ClipRect.Min.y, window->ClipRect.Max.y) >= (nav_bb.Max.y - nav_bb.Min.y) * VISIBLE_RATIO)
                if (NavScoreItem(&g.NavMoveResultLocalVisibleSet, nav_bb))
                    NavApplyItemToResult(&g.NavMoveResultLocalVisibleSet, window, id, nav_bb_rel);
    }

    // Update window-relative bounding box of navigated item
    if (g.NavId == id)
    {
        g.NavWindow = window;                                           // Always refresh g.NavWindow, because some operations such as FocusItem() don't have a window.
        g.NavLayer = window->DC.NavLayerCurrent;
        g.NavFocusScopeId = window->DC.NavFocusScopeIdCurrent;
        g.NavIdIsAlive = true;
        g.NavIdTabCounter = window->DC.FocusCounterTabStop;
        window->NavRectRel[window->DC.NavLayerCurrent] = nav_bb_rel;    // Store item bounding box (relative to window position)
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq 0x136be3(%rip), %rax    # 0x212f40
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movl 0x1cc(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x10, %rsi
callq 0xc3c00
movlpd %xmm0, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movq -0x8(%rbp), %rsi
addq $0x10, %rsi
callq 0xc3c00
movlpd %xmm0, -0x44(%rbp)
leaq -0x34(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
leaq -0x44(%rbp), %rdx
callq 0xe8660
movq -0x20(%rbp), %rax
testb $0x1, 0x1ce9(%rax)
je 0xdc42e
movq -0x20(%rbp), %rax
movl 0x1cdc(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x14c(%rcx), %eax
jne 0xdc42e
movl -0x24(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0xdc3ea
movq -0x20(%rbp), %rax
cmpl $0x0, 0x1cec(%rax)
jne 0xdc411
movl -0x14(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x1cec(%rax)
movq -0x20(%rbp), %rax
movq -0x34(%rbp), %rcx
movq %rcx, 0x1cf0(%rax)
movq -0x2c(%rbp), %rcx
movq %rcx, 0x1cf8(%rax)
movl -0x24(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0xdc42c
movq -0x20(%rbp), %rax
movb $0x0, 0x1ce9(%rax)
callq 0xdb260
jmp 0xdc42e
movq -0x20(%rbp), %rax
movl 0x1c98(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0xdc453
movq -0x20(%rbp), %rax
movl 0x1d04(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0xdc61b
movl -0x24(%rbp), %eax
andl $0xc, %eax
cmpl $0x0, %eax
jne 0xdc61b
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x1c90(%rcx), %rax
jne 0xdc486
movq -0x20(%rbp), %rax
addq $0x1d20, %rax           # imm = 0x1D20
movq %rax, -0x98(%rbp)
jmp 0xdc497
movq -0x20(%rbp), %rax
addq $0x1d80, %rax           # imm = 0x1D80
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rcx
xorl %eax, %eax
testb $0x1, 0x1d00(%rcx)
movb %al, -0x99(%rbp)
je 0xdc4db
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rax
movups (%rax), %xmm0
movaps %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
callq 0xe5eb0
movb %al, -0x99(%rbp)
movb -0x99(%rbp), %al
andb $0x1, %al
movb %al, -0x51(%rbp)
testb $0x1, -0x51(%rbp)
je 0xdc500
movq -0x50(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq -0x34(%rbp), %rcx
callq 0xe6440
movss 0x962b8(%rip), %xmm0    # 0x1727c0
movss %xmm0, -0x74(%rbp)
movq -0x20(%rbp), %rax
movl 0x1d04(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0xdc619
movq -0x8(%rbp), %rdi
addq $0x258, %rdi            # imm = 0x258
movq -0x10(%rbp), %rsi
callq 0xe9420
testb $0x1, %al
jne 0xdc540
jmp 0xdc619
movq -0x10(%rbp), %rax
movss 0xc(%rax), %xmm0
movq -0x8(%rbp), %rax
movss 0x25c(%rax), %xmm1
movq -0x8(%rbp), %rax
movss 0x264(%rax), %xmm2
callq 0xe5390
movss %xmm0, -0xa0(%rbp)
movq -0x10(%rbp), %rax
movss 0x4(%rax), %xmm0
movq -0x8(%rbp), %rax
movss 0x25c(%rax), %xmm1
movq -0x8(%rbp), %rax
movss 0x264(%rax), %xmm2
callq 0xe5390
movaps %xmm0, %xmm1
movss -0xa0(%rbp), %xmm0
subss %xmm1, %xmm0
movq -0x10(%rbp), %rax
movss 0xc(%rax), %xmm1
movq -0x10(%rbp), %rax
subss 0x4(%rax), %xmm1
movss 0x96203(%rip), %xmm2    # 0x1727c0
mulss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jb 0xdc617
movq -0x20(%rbp), %rdi
addq $0x1d50, %rdi           # imm = 0x1D50
movq -0x10(%rbp), %rax
movups (%rax), %xmm0
movaps %xmm0, -0x90(%rbp)
movsd -0x90(%rbp), %xmm0
movsd -0x88(%rbp), %xmm1
callq 0xe5eb0
testb $0x1, %al
jne 0xdc5fa
jmp 0xdc615
movq -0x20(%rbp), %rdi
addq $0x1d50, %rdi           # imm = 0x1D50
movq -0x8(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq -0x34(%rbp), %rcx
callq 0xe6440
jmp 0xdc617
jmp 0xdc619
jmp 0xdc61b
movq -0x20(%rbp), %rax
movl 0x1c98(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0xdc6ae
movq -0x8(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x1c90(%rax)
movq -0x8(%rbp), %rax
movl 0x14c(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x1cdc(%rax)
movq -0x8(%rbp), %rax
movl 0x158(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x1c9c(%rax)
movq -0x20(%rbp), %rax
movb $0x1, 0x1ce4(%rax)
movq -0x8(%rbp), %rax
movl 0x1c8(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x1ce0(%rax)
movq -0x8(%rbp), %rax
addq $0x3b8, %rax            # imm = 0x3B8
movq -0x8(%rbp), %rcx
movl 0x14c(%rcx), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x34(%rbp), %rcx
movq %rcx, (%rax)
movq -0x2c(%rbp), %rcx
movq %rcx, 0x8(%rax)
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)