// File: Ciaxur[P]yagb-emu/include/imgui/imgui.cpp
// Function: ImGui::ItemAdd(ImRect const&, unsigned int, ImRect const*)
bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg)
{
    ImGuiContext& g = *GImGui;
    ImGuiWindow* window = g.CurrentWindow;

    if (id != 0)
    {
        // Navigation processing runs prior to clipping early-out
        //  (a) So that NavInitRequest can be honored, for newly opened windows to select a default widget
        //  (b) So that we can scroll up/down past clipped items. This adds a small O(N) cost to regular navigation requests
        //      unfortunately, but it is still limited to one window. It may not scale very well for windows with ten of
        //      thousands of item, but at least NavMoveRequest is only set on user interaction, aka maximum once a frame.
        //      We could early out with "if (is_clipped && !g.NavInitRequest) return false;" but when we wouldn't be able
        //      to reach unclipped widgets. This would work if user had explicit scrolling control (e.g. mapped on a stick).
        // We intentionally don't check if g.NavWindow != NULL because g.NavAnyRequest should only be set when it is non null.
        // If we crash on a NULL g.NavWindow we need to fix the bug elsewhere.
        window->DC.NavLayerActiveMaskNext |= (1 << window->DC.NavLayerCurrent);
        if (g.NavId == id || g.NavAnyRequest)
            if (g.NavWindow->RootWindowForNav == window->RootWindowForNav)
                if (window == g.NavWindow || ((window->Flags | g.NavWindow->Flags) & ImGuiWindowFlags_NavFlattened))
                    NavProcessItem(window, nav_bb_arg ? *nav_bb_arg : bb, id);

        // [DEBUG] Item Picker tool, when enabling the "extended" version we perform the check in ItemAdd()
#ifdef IMGUI_DEBUG_TOOL_ITEM_PICKER_EX
        if (id == g.DebugItemPickerBreakId)
        {
            IM_DEBUG_BREAK();
            g.DebugItemPickerBreakId = 0;
        }
#endif
    }

    // Equivalent to calling SetLastItemData()
    window->DC.LastItemId = id;
    window->DC.LastItemRect = bb;
    window->DC.LastItemStatusFlags = ImGuiItemStatusFlags_None;
    g.NextItemData.Flags = ImGuiNextItemDataFlags_None;

#ifdef IMGUI_ENABLE_TEST_ENGINE
    if (id != 0)
        IMGUI_TEST_ENGINE_ITEM_ADD(nav_bb_arg ? *nav_bb_arg : bb, id);
#endif

    // Clipping test
    const bool is_clipped = IsClippedEx(bb, id, false);
    if (is_clipped)
        return false;
    //if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG]

    // We need to calculate this now to take account of the current clipping rectangle (as items like Selectable may change them)
    if (IsMouseHoveringRect(bb.Min, bb.Max))
        window->DC.LastItemStatusFlags |= ImGuiItemStatusFlags_HoveredRect;
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq 0x13ccd6(%rip), %rax    # 0x212f40
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq 0x1ae0(%rax), %rax
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0xd6350
movq -0x30(%rbp), %rax
movl 0x14c(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
orl 0x154(%rax), %ecx
movl %ecx, 0x154(%rax)
movq -0x28(%rbp), %rax
movl 0x1c98(%rax), %eax
cmpl -0x14(%rbp), %eax
je 0xd62ca
movq -0x28(%rbp), %rax
testb $0x1, 0x1ce8(%rax)
je 0xd634e
movq -0x28(%rbp), %rax
movq 0x1c90(%rax), %rax
movq 0x3a0(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x3a0(%rcx), %rax
jne 0xd634c
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq 0x1c90(%rcx), %rax
je 0xd6319
movq -0x30(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x28(%rbp), %rcx
movq 0x1c90(%rcx), %rcx
orl 0xc(%rcx), %eax
andl $0x800000, %eax         # imm = 0x800000
cmpl $0x0, %eax
je 0xd634a
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xd6332
movq -0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0xd633a
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0xdc340
jmp 0xd634c
jmp 0xd634e
jmp 0xd6350
movl -0x14(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x124(%rax)
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, 0x12c(%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x134(%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0x128(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x1bf8(%rax)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
xorl %edx, %edx
callq 0xca6e0
andb $0x1, %al
movb %al, -0x31(%rbp)
testb $0x1, -0x31(%rbp)
je 0xd63b5
movb $0x0, -0x1(%rbp)
jmp 0xd63e8
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
movl $0x1, %edx
callq 0xca5f0
testb $0x1, %al
jne 0xd63d1
jmp 0xd63e4
movq -0x30(%rbp), %rax
movl 0x128(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x128(%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)