// File: /workspace/github_cpp_makefile_star2_O1/Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: ImGui::ButtonBehavior(ImRect const&, unsigned int, bool*, bool*, int)
bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags)
{
    ImGuiContext& g = *GImGui;
    ImGuiWindow* window = GetCurrentWindow();

    if (flags & ImGuiButtonFlags_Disabled)
    {
        if (out_hovered) *out_hovered = false;
        if (out_held) *out_held = false;
        if (g.ActiveId == id) ClearActiveID();
        return false;
    }

    // Default only reacts to left mouse button
    if ((flags & ImGuiButtonFlags_MouseButtonMask_) == 0)
        flags |= ImGuiButtonFlags_MouseButtonDefault_;

    // Default behavior requires click + release inside bounding box
    if ((flags & ImGuiButtonFlags_PressedOnMask_) == 0)
        flags |= ImGuiButtonFlags_PressedOnDefault_;

    ImGuiWindow* backup_hovered_window = g.HoveredWindow;
    const bool flatten_hovered_children = (flags & ImGuiButtonFlags_FlattenChildren) && g.HoveredRootWindow == window;
    if (flatten_hovered_children)
        g.HoveredWindow = window;

#ifdef IMGUI_ENABLE_TEST_ENGINE
    if (id != 0 && window->DC.LastItemId != id)
        IMGUI_TEST_ENGINE_ITEM_ADD(bb, id);
#endif

    bool pressed = false;
    bool hovered = ItemHoverable(bb, id);

    // Drag source doesn't report as hovered
    if (hovered && g.DragDropActive && g.DragDropPayload.SourceId == id && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoDisableHover))
        hovered = false;

    // Special mode for Drag and Drop where holding button pressed for a long time while dragging another item triggers the button
    if (g.DragDropActive && (flags & ImGuiButtonFlags_PressedOnDragDropHold) && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoHoldToOpenOthers))
        if (IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))
        {
            hovered = true;
            SetHoveredID(id);
            if (CalcTypematicRepeatAmount(g.HoveredIdTimer + 0.0001f - g.IO.DeltaTime, g.HoveredIdTimer + 0.0001f, DRAGDROP_HOLD_TO_OPEN_TIMER, 0.00f))
            {
                pressed = true;
                g.DragDropHoldJustPressedId = id;
                FocusWindow(window);
            }
        }

    if (flatten_hovered_children)
        g.HoveredWindow = backup_hovered_window;

    // AllowOverlap mode (rarely used) requires previous frame HoveredId to be null or to match. This allows using patterns where a later submitted widget overlaps a previous one.
    if (hovered && (flags & ImGuiButtonFlags_AllowItemOverlap) && (g.HoveredIdPreviousFrame != id && g.HoveredIdPreviousFrame != 0))
        hovered = false;

    // Mouse handling
    if (hovered)
    {
        if (!(flags & ImGuiButtonFlags_NoKeyModifiers) || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt))
        {
            // Poll buttons
            int mouse_button_clicked = -1;
            int mouse_button_released = -1;
            if ((flags & ImGuiButtonFlags_MouseButtonLeft) && g.IO.MouseClicked[0])         { mouse_button_clicked = 0; }
            else if ((flags & ImGuiButtonFlags_MouseButtonRight) && g.IO.MouseClicked[1])   { mouse_button_clicked = 1; }
            else if ((flags & ImGuiButtonFlags_MouseButtonMiddle) && g.IO.MouseClicked[2])  { mouse_button_clicked = 2; }
            if ((flags & ImGuiButtonFlags_MouseButtonLeft) && g.IO.MouseReleased[0])        { mouse_button_released = 0; }
            else if ((flags & ImGuiButtonFlags_MouseButtonRight) && g.IO.MouseReleased[1])  { mouse_button_released = 1; }
            else if ((flags & ImGuiButtonFlags_MouseButtonMiddle) && g.IO.MouseReleased[2]) { mouse_button_released = 2; }

            if (mouse_button_clicked != -1 && g.ActiveId != id)
            {
                if (flags & (ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClickReleaseAnywhere))
                {
                    SetActiveID(id, window);
                    g.ActiveIdMouseButton = mouse_button_clicked;
                    if (!(flags & ImGuiButtonFlags_NoNavFocus))
                        SetFocusID(id, window);
                    FocusWindow(window);
                }
                if ((flags & ImGuiButtonFlags_PressedOnClick) || ((flags & ImGuiButtonFlags_PressedOnDoubleClick) && g.IO.MouseDoubleClicked[mouse_button_clicked]))
                {
                    pressed = true;
                    if (flags & ImGuiButtonFlags_NoHoldingActiveId)
                        ClearActiveID();
                    else
                        SetActiveID(id, window); // Hold on ID
                    g.ActiveIdMouseButton = mouse_button_clicked;
                    FocusWindow(window);
                }
            }
            if ((flags & ImGuiButtonFlags_PressedOnRelease) && mouse_button_released != -1)
            {
                // Repeat mode trumps on release behavior
                const bool has_repeated_at_least_once = (flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[mouse_button_released] >= g.IO.KeyRepeatDelay;
                if (!has_repeated_at_least_once)
                    pressed = true;
                ClearActiveID();
            }

            // 'Repeat' mode acts when held regardless of _PressedOn flags (see table above).
            // Relies on repeat logic of IsMouseClicked() but we may as well do it ourselves if we end up exposing finer RepeatDelay/RepeatRate settings.
            if (g.ActiveId == id && (flags & ImGuiButtonFlags_Repeat))
                if (g.IO.MouseDownDuration[g.ActiveIdMouseButton] > 0.0f && IsMouseClicked(g.ActiveIdMouseButton, true))
                    pressed = true;
        }

        if (pressed)
            g.NavDisableHighlight = true;
    }

    // Gamepad/Keyboard navigation
    // We report navigated item as hovered but we don't set g.HoveredId to not interfere with mouse.
    if (g.NavId == id && !g.NavDisableHighlight && g.NavDisableMouseHover && (g.ActiveId == 0 || g.ActiveId == id || g.ActiveId == window->MoveId))
        if (!(flags & ImGuiButtonFlags_NoHoveredOnFocus))
            hovered = true;
    if (g.NavActivateDownId == id)
    {
        bool nav_activated_by_code = (g.NavActivateId == id);
        bool nav_activated_by_inputs = IsNavInputTest(ImGuiNavInput_Activate, (flags & ImGuiButtonFlags_Repeat) ? ImGuiInputReadMode_Repeat : ImGuiInputReadMode_Pressed);
        if (nav_activated_by_code || nav_activated_by_inputs)
            pressed = true;
        if (nav_activated_by_code || nav_activated_by_inputs || g.ActiveId == id)
        {
            // Set active id so it can be queried by user via IsItemActive(), equivalent of holding the mouse button.
            g.NavActivateId = id; // This is so SetActiveId assign a Nav source
            SetActiveID(id, window);
            if ((nav_activated_by_code || nav_activated_by_inputs) && !(flags & ImGuiButtonFlags_NoNavFocus))
                SetFocusID(id, window);
        }
    }

    // Process while held
    bool held = false;
    if (g.ActiveId == id)
    {
        if (g.ActiveIdSource == ImGuiInputSource_Mouse)
        {
            if (g.ActiveIdIsJustActivated)
                g.ActiveIdClickOffset = g.IO.MousePos - bb.Min;

            const int mouse_button = g.ActiveIdMouseButton;
            IM_ASSERT(mouse_button >= 0 && mouse_button < ImGuiMouseButton_COUNT);
            if (g.IO.MouseDown[mouse_button])
            {
                held = true;
            }
            else
            {
                bool release_in = hovered && (flags & ImGuiButtonFlags_PressedOnClickRelease) != 0;
                bool release_anywhere = (flags & ImGuiButtonFlags_PressedOnClickReleaseAnywhere) != 0;
                if ((release_in || release_anywhere) && !g.DragDropActive)
                {
                    // Report as pressed when releasing the mouse (this is the most common path)
                    bool is_double_click_release = (flags & ImGuiButtonFlags_PressedOnDoubleClick) && g.IO.MouseDownWasDoubleClick[mouse_button];
                    bool is_repeating_already = (flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[mouse_button] >= g.IO.KeyRepeatDelay; // Repeat mode trumps <on release>
                    if (!is_double_click_release && !is_repeating_already)
                        pressed = true;
                }
                ClearActiveID();
            }
            if (!(flags & ImGuiButtonFlags_NoNavFocus))
                g.NavDisableHighlight = true;
        }
        else if (g.ActiveIdSource == ImGuiInputSource_Nav)
        {
            // When activated using Nav, we hold on the ActiveID until activation button is released
            if (g.NavActivateDownId != id)
                ClearActiveID();
        }
        if (pressed)
            g.ActiveIdHasBeenPressedBefore = true;
    }

    if (out_hovered) *out_hovered = hovered;
    if (out_held) *out_held = held;

    return pressed;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r12
movl %esi, %r13d
leaq 0x6b442(%rip), %rax     # 0xfdcd0
movq (%rax), %r14
movq 0x1ae0(%r14), %rcx
movb $0x1, 0x90(%rcx)
btl $0xe, %r8d
jb 0x928d4
movq %rdx, -0x58(%rbp)
xorl %eax, %eax
testb $0x7, %r8b
sete %al
leal (%rax,%r8), %r15d
addl $0x20, %r15d
orl %r8d, %eax
testl $0x3f0, %r8d            # imm = 0x3F0
cmovnel %eax, %r15d
btl $0xb, %r15d
jb 0x928fb
xorl %ebx, %ebx
jmp 0x92905
testq %rdx, %rdx
je 0x928dc
movb $0x0, (%rdx)
testq %r12, %r12
je 0x928e6
movb $0x0, (%r12)
cmpl %r13d, 0x1b30(%r14)
jne 0x928f4
callq 0x46c46
xorl %eax, %eax
jmp 0x92e67
cmpq %rcx, 0x1af0(%r14)
sete %bl
movq 0x1ae8(%r14), %rax
movq %rax, -0x38(%rbp)
testb %bl, %bl
je 0x9291b
movq %rcx, 0x1ae8(%r14)
movq %rcx, -0x50(%rbp)
movq %rdi, -0x68(%rbp)
movl %r13d, %esi
callq 0x46e45
movl %eax, %esi
testb %al, %al
je 0x92952
cmpb $0x1, 0x2004(%r14)
jne 0x92952
cmpl %r13d, 0x2024(%r14)
jne 0x92952
movb 0x2008(%r14), %al
andb $0x2, %al
shrb %al
andb %al, %sil
xorl %r8d, %r8d
btl $0x9, %r15d
jae 0x929f2
cmpb $0x0, 0x2004(%r14)
je 0x929f2
testb $0x4, 0x2008(%r14)
jne 0x929db
movq %r12, -0x40(%rbp)
movl %esi, %r12d
movl $0x20, %edi
callq 0x46d03
testb %al, %al
je 0x929e0
movl %r13d, %edi
callq 0x46c54
movss 0x1b28(%r14), %xmm1
addss 0x24f26(%rip), %xmm1    # 0xb78cc
movaps %xmm1, %xmm0
subss 0x18(%r14), %xmm0
movss 0x24f1d(%rip), %xmm2    # 0xb78d4
xorps %xmm3, %xmm3
callq 0x524b7
testl %eax, %eax
je 0x929e8
movl %r13d, 0x2080(%r14)
movq -0x50(%rbp), %rdi
callq 0x47d9b
movb $0x1, %sil
movb $0x1, %r8b
jmp 0x929ee
xorl %r8d, %r8d
jmp 0x929f2
xorl %r8d, %r8d
movl %r12d, %esi
jmp 0x929ee
movb $0x1, %sil
xorl %r8d, %r8d
movq -0x40(%rbp), %r12
testb %bl, %bl
je 0x92a01
movq -0x38(%rbp), %rax
movq %rax, 0x1ae8(%r14)
btl $0xc, %r15d
setae %al
movl %esi, %ecx
xorb $0x1, %cl
orb %al, %cl
jne 0x92a29
movl 0x1b20(%r14), %eax
cmpl %r13d, %eax
sete %cl
testl %eax, %eax
sete %al
orb %cl, %al
andb %al, %sil
testb %sil, %sil
je 0x92c79
btl $0x10, %r15d
jb 0x92a69
testb $0x1, %r15b
je 0x92a50
xorl %eax, %eax
cmpb $0x0, 0x420(%r14)
movl $0x0, %edx
jne 0x92ab4
testb $0x2, %r15b
je 0x92a94
cmpb $0x0, 0x421(%r14)
je 0x92a94
movl $0x1, %edx
xorl %eax, %eax
jmp 0x92ab4
cmpb $0x0, 0x140(%r14)
jne 0x92c6c
cmpb $0x0, 0x141(%r14)
jne 0x92c6c
cmpb $0x0, 0x142(%r14)
je 0x92a39
jmp 0x92c6c
testb $0x4, %r15b
jne 0x92aa3
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movb $0x1, %al
jmp 0x92ab4
movb 0x422(%r14), %al
xorb $0x1, %al
movzbl %al, %edx
negl %edx
orl $0x2, %edx
testb $0x1, %r15b
je 0x92aca
cmpb $0x0, 0x42a(%r14)
je 0x92aca
movb $0x1, %bl
xorl %edi, %edi
jmp 0x92b04
testb $0x2, %r15b
je 0x92ae3
cmpb $0x0, 0x42b(%r14)
je 0x92ae3
movl $0x1, %edi
movb $0x1, %bl
jmp 0x92b04
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
testb $0x4, %r15b
jne 0x92af2
xorl %ebx, %ebx
jmp 0x92b04
movb 0x42c(%r14), %bl
testb %bl, %bl
movl $0x2, %ecx
cmovneq %rcx, %rdi
testb %al, %al
jne 0x92bd2
cmpl %r13d, 0x1b30(%r14)
je 0x92bd2
movl %edx, -0x44(%rbp)
testb $0x60, %r15b
movq %r12, -0x40(%rbp)
movb %sil, -0x29(%rbp)
movq %rdi, -0x60(%rbp)
je 0x92b75
movl %r8d, -0x38(%rbp)
movl %r13d, %edi
movq -0x50(%rbp), %r12
movq %r12, %rsi
callq 0x46b95
movl -0x44(%rbp), %eax
movl %eax, 0x1b6c(%r14)
btl $0x12, %r15d
jb 0x92b5d
movl %r13d, %edi
movq %r12, %rsi
callq 0x58de3
movq %r12, %rdi
callq 0x47d9b
movb -0x29(%rbp), %sil
movl -0x38(%rbp), %r8d
movq -0x40(%rbp), %r12
movq -0x60(%rbp), %rdi
testb $0x10, %r15b
jne 0x92b90
btl $0x8, %r15d
jae 0x92bd2
movl -0x44(%rbp), %eax
cmpb $0x1, 0x425(%r14,%rax)
jne 0x92bd2
btl $0x11, %r15d
jb 0x92ba8
movl %r13d, %edi
movq -0x50(%rbp), %r12
movq %r12, %rsi
callq 0x46b95
jmp 0x92bb1
callq 0x46c46
movq -0x50(%rbp), %r12
movl -0x44(%rbp), %eax
movl %eax, 0x1b6c(%r14)
movq %r12, %rdi
callq 0x47d9b
movb $0x1, %r8b
movb -0x29(%rbp), %sil
movq -0x40(%rbp), %r12
movq -0x60(%rbp), %rdi
testb %r15b, %r15b
setns %al
xorb $0x1, %bl
orb %al, %bl
jne 0x92c16
movb %sil, -0x29(%rbp)
movb $0x1, %bl
btl $0xa, %r15d
jae 0x92c0a
movss 0x450(%r14,%rdi,4), %xmm0
ucomiss 0x94(%r14), %xmm0
movzbl %r8b, %eax
movl $0x1, %ebx
cmovael %eax, %ebx
callq 0x46c46
movl %ebx, %r8d
movb -0x29(%rbp), %sil
btl $0xa, %r15d
jae 0x92c6c
cmpl %r13d, 0x1b30(%r14)
jne 0x92c6c
movslq 0x1b6c(%r14), %rdi
movss 0x43c(%r14,%rdi,4), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x92c6c
movq %r12, -0x40(%rbp)
movl %esi, %r12d
movl $0x1, %esi
movl %r8d, %ebx
callq 0x52641
movl %ebx, %r8d
movl %r12d, %esi
movq -0x40(%rbp), %r12
movzbl %r8b, %r8d
testb %al, %al
movl $0x1, %eax
cmovnel %eax, %r8d
testb %r8b, %r8b
je 0x92c79
movb $0x1, 0x1ce6(%r14)
cmpl %r13d, 0x1c98(%r14)
jne 0x92cc8
cmpb $0x0, 0x1ce6(%r14)
jne 0x92cc8
cmpb $0x1, 0x1ce7(%r14)
jne 0x92cc8
movl 0x1b30(%r14), %eax
testl %eax, %eax
sete %cl
cmpl %r13d, %eax
sete %dl
orb %cl, %dl
je 0x92cb5
btl $0x13, %r15d
jae 0x92cc5
jmp 0x92cc8
btl $0x13, %r15d
jb 0x92cc8
movq -0x50(%rbp), %rcx
cmpl 0x54(%rcx), %eax
jne 0x92cc8
movb $0x1, %sil
movl %r8d, -0x38(%rbp)
cmpl %r13d, 0x1ca4(%r14)
jne 0x92d6a
movb %sil, -0x29(%rbp)
movq %r12, -0x40(%rbp)
cmpl %r13d, 0x1ca0(%r14)
sete %r12b
movl %r15d, %esi
shrl $0x9, %esi
andl $0x2, %esi
incl %esi
xorl %edi, %edi
callq 0x59005
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
seta %bl
orb %r12b, %bl
movzbl -0x38(%rbp), %eax
movl $0x1, %ecx
cmovel %eax, %ecx
movl %ecx, -0x38(%rbp)
jne 0x92d24
cmpl %r13d, 0x1b30(%r14)
jne 0x92d62
movl %r13d, 0x1ca0(%r14)
movl %r13d, %edi
movq -0x50(%rbp), %r12
movq %r12, %rsi
callq 0x46b95
movl %r15d, %eax
shrl $0x12, %eax
andl $0x1, %eax
xorb $0x1, %bl
orb %al, %bl
movq -0x40(%rbp), %rbx
jne 0x92d59
movl %r13d, %edi
movq %r12, %rsi
callq 0x58de3
movb -0x29(%rbp), %sil
movq %rbx, %r12
jmp 0x92d6a
movq -0x40(%rbp), %r12
movb -0x29(%rbp), %sil
cmpl %r13d, 0x1b30(%r14)
jne 0x92e1c
movl 0x1b68(%r14), %eax
cmpl $0x2, %eax
je 0x92e27
cmpl $0x1, %eax
movl -0x38(%rbp), %eax
jne 0x92e44
cmpb $0x1, 0x1b3c(%r14)
jne 0x92dc7
movss 0x128(%r14), %xmm0
movss 0x12c(%r14), %xmm1
movq -0x68(%rbp), %rcx
subss (%rcx), %xmm0
subss 0x4(%rcx), %xmm1
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movlps %xmm0, 0x1b58(%r14)
movl 0x1b6c(%r14), %ecx
cmpq $0x5, %rcx
jae 0x92ec8
movb $0x1, %dl
cmpb $0x0, 0x130(%r14,%rcx)
jne 0x92e0b
testb $0x40, %r15b
jne 0x92df6
movl %r15d, %edx
shrb $0x5, %dl
andb %sil, %dl
je 0x92e00
cmpb $0x0, 0x2004(%r14)
je 0x92e76
movl %esi, %ebx
callq 0x46c46
xorl %edx, %edx
movl %ebx, %esi
btl $0x12, %r15d
jb 0x92e3b
movb $0x1, 0x1ce6(%r14)
jmp 0x92e3b
xorl %edx, %edx
movq -0x58(%rbp), %rcx
movl -0x38(%rbp), %eax
jmp 0x92e56
cmpl %r13d, 0x1ca4(%r14)
je 0x92e39
movl %esi, %ebx
callq 0x46c46
movl %ebx, %esi
xorl %edx, %edx
movq -0x58(%rbp), %rcx
movl -0x38(%rbp), %eax
jmp 0x92e4a
xorl %edx, %edx
movq -0x58(%rbp), %rcx
testb %al, %al
je 0x92e56
movb $0x1, 0x1b3f(%r14)
testq %rcx, %rcx
je 0x92e5e
movb %sil, (%rcx)
testq %r12, %r12
je 0x92e67
movb %dl, (%r12)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
btl $0x8, %r15d
jb 0x92e81
xorl %edx, %edx
jmp 0x92e89
movb 0x434(%r14,%rcx), %dl
btl $0xa, %r15d
jb 0x92e94
xorl %ecx, %ecx
jmp 0x92ea9
movss 0x450(%r14,%rcx,4), %xmm0
ucomiss 0x94(%r14), %xmm0
setae %cl
movl %esi, %ebx
testb %dl, %dl
jne 0x92e02
movzbl %al, %eax
testb %cl, %cl
movl $0x1, %ecx
cmovnel %eax, %ecx
movl %ecx, -0x38(%rbp)
jmp 0x92e02
leaq 0x402d8(%rip), %rdi     # 0xd31a7
leaq 0x40272(%rip), %rsi     # 0xd3148
leaq 0x40305(%rip), %rcx     # 0xd31e2
movl $0x273, %edx            # imm = 0x273
callq 0xc140