// File: /workspace/github_cpp_makefile_star2_O3/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
movl %esi, %r15d
leaq 0x6b146(%rip), %rax     # 0xfbcd0
movq (%rax), %rbx
movq 0x1ae0(%rbx), %rsi
movb $0x1, 0x90(%rsi)
btl $0xe, %r8d
jb 0x90c2a
movq %rdx, -0x50(%rbp)
movq %rcx, -0x58(%rbp)
xorl %eax, %eax
testb $0x7, %r8b
sete %al
leal (%rax,%r8), %r14d
addl $0x20, %r14d
orl %r8d, %eax
testl $0x3f0, %r8d            # imm = 0x3F0
cmovnel %eax, %r14d
movq 0x1ae8(%rbx), %rax
movq %rax, -0x38(%rbp)
btl $0xb, %r14d
movq %rsi, -0x48(%rbp)
jae 0x90bf0
cmpq %rsi, 0x1af0(%rbx)
je 0x90cc5
xorl %r12d, %r12d
movq %rdi, -0x68(%rbp)
movl %r15d, %esi
callq 0x4632f
movb 0x2004(%rbx), %cl
testb %al, %al
je 0x90c4f
movb $0x1, %r13b
testb $0x1, %cl
je 0x90c52
cmpl %r15d, 0x2024(%rbx)
jne 0x90c52
movb 0x2008(%rbx), %r13b
andb $0x2, %r13b
shrb %r13b
jmp 0x90c52
testq %rdx, %rdx
je 0x90c32
movb $0x0, (%rdx)
testq %rcx, %rcx
je 0x90c3a
movb $0x0, (%rcx)
cmpl %r15d, 0x1b30(%rbx)
jne 0x90c48
callq 0x46130
xorl %esi, %esi
jmp 0x9118a
xorl %r13d, %r13d
notb %cl
btl $0x9, %r14d
setae %al
orb %cl, %al
testb $0x1, %al
jne 0x90cd7
testb $0x4, 0x2008(%rbx)
jne 0x90cd7
movl $0x20, %edi
callq 0x461ed
testb %al, %al
je 0x90cd7
movl %r15d, %edi
callq 0x4613e
movss 0x1b28(%rbx), %xmm1
addss 0x24c3b(%rip), %xmm1    # 0xb58cc
movaps %xmm1, %xmm0
subss 0x18(%rbx), %xmm0
movss 0x24c33(%rip), %xmm2    # 0xb58d4
xorps %xmm3, %xmm3
callq 0x514c9
testl %eax, %eax
je 0x90cd4
movl %r15d, 0x2080(%rbx)
movq -0x48(%rbp), %rdi
callq 0x4726c
movb $0x1, %r13b
movb $0x1, %sil
jmp 0x90cd9
movq %rsi, 0x1ae8(%rbx)
movb $0x1, %r12b
jmp 0x90bf3
movb $0x1, %r13b
xorl %esi, %esi
testb %r12b, %r12b
je 0x90ce9
movq -0x38(%rbp), %rax
movq %rax, 0x1ae8(%rbx)
btl $0xc, %r14d
setae %al
movl %r13d, %ecx
xorb $0x1, %cl
orb %al, %cl
jne 0x90d1c
movl 0x1b20(%rbx), %eax
cmpl %r15d, %eax
sete %cl
testl %eax, %eax
sete %al
orb %cl, %al
jne 0x90d21
movl $0x0, -0x38(%rbp)
jmp 0x90f66
testb %r13b, %r13b
je 0x90d10
btl $0x10, %r14d
jb 0x90d5a
testb $0x1, %r14b
je 0x90d3f
xorl %r13d, %r13d
cmpb $0x0, 0x420(%rbx)
movl $0x0, %eax
jne 0x90dab
movl %r14d, %ecx
andl $0x2, %ecx
je 0x90d82
cmpb $0x0, 0x421(%rbx)
je 0x90d82
movl $0x1, %r13d
xorl %eax, %eax
jmp 0x90da5
cmpb $0x0, 0x140(%rbx)
jne 0x90f55
cmpb $0x0, 0x141(%rbx)
jne 0x90f55
cmpb $0x0, 0x142(%rbx)
je 0x90d28
jmp 0x90f55
testb $0x4, %r14b
jne 0x90d92
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movb $0x1, %al
jmp 0x90da5
movb 0x422(%rbx), %al
xorb $0x1, %al
movzbl %al, %r13d
negl %r13d
orl $0x2, %r13d
testb $0x1, %r14b
je 0x90dc1
cmpb $0x0, 0x42a(%rbx)
je 0x90dbb
movb $0x1, %dil
xorl %edx, %edx
jmp 0x90dfa
movl %r14d, %ecx
andl $0x2, %ecx
testl %ecx, %ecx
je 0x90dd8
cmpb $0x0, 0x42b(%rbx)
je 0x90dd8
movl $0x1, %edx
movb $0x1, %dil
jmp 0x90dfa
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
testb $0x4, %r14b
jne 0x90de7
xorl %edi, %edi
jmp 0x90dfa
movb 0x42c(%rbx), %dil
testb %dil, %dil
movl $0x2, %ecx
cmovneq %rcx, %rdx
testb %al, %al
jne 0x90ed3
cmpl %r15d, 0x1b30(%rbx)
je 0x90ed3
testb $0x60, %r14b
movq %rdx, -0x38(%rbp)
movl %edi, -0x2c(%rbp)
je 0x90e73
movl %esi, -0x3c(%rbp)
movl %r15d, %r12d
movl %r15d, %edi
movl %r13d, %r15d
movl %r14d, %r13d
movq -0x48(%rbp), %r14
movq %r14, %rsi
callq 0x4603f
movl %r15d, -0x5c(%rbp)
movl %r15d, 0x1b6c(%rbx)
movl %r13d, %r15d
btl $0x12, %r13d
jb 0x90e57
movl %r12d, %edi
movq %r14, %rsi
callq 0x57c70
movq %r14, %rdi
callq 0x4726c
movl -0x3c(%rbp), %esi
movl %r15d, %r14d
movl %r12d, %r15d
movl -0x5c(%rbp), %r13d
movq -0x38(%rbp), %rdx
movl -0x2c(%rbp), %edi
testb $0x10, %r14b
jne 0x90e8d
btl $0x8, %r14d
jae 0x90ed3
movl %r13d, %eax
cmpb $0x1, 0x425(%rbx,%rax)
jne 0x90ed3
movl %r15d, %r12d
movl %r14d, %r15d
btl $0x11, %r14d
jb 0x90eab
movl %r12d, %edi
movq -0x48(%rbp), %r14
movq %r14, %rsi
callq 0x4603f
jmp 0x90eb4
callq 0x46130
movq -0x48(%rbp), %r14
movl %r13d, 0x1b6c(%rbx)
movq %r14, %rdi
callq 0x4726c
movb $0x1, %sil
movl %r15d, %r14d
movl %r12d, %r15d
movq -0x38(%rbp), %rdx
movl -0x2c(%rbp), %edi
testb %r14b, %r14b
jns 0x90f0d
testb %dil, %dil
je 0x90f0d
movb $0x1, %r12b
btl $0xa, %r14d
jae 0x90f05
movss 0x450(%rbx,%rdx,4), %xmm0
ucomiss 0x94(%rbx), %xmm0
movzbl %sil, %eax
movl $0x1, %r12d
cmovael %eax, %r12d
callq 0x46130
movl %r12d, %esi
btl $0xa, %r14d
jae 0x90f55
cmpl %r15d, 0x1b30(%rbx)
jne 0x90f55
movslq 0x1b6c(%rbx), %rdi
movss 0x43c(%rbx,%rdi,4), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x90f55
movl $0x1, %r12d
movl %esi, %r13d
movl $0x1, %esi
callq 0x51653
movl %r13d, %esi
movzbl %sil, %esi
testb %al, %al
cmovnel %r12d, %esi
movb $0x1, %al
movl %eax, -0x38(%rbp)
testb %sil, %sil
je 0x90f66
movb $0x1, 0x1ce6(%rbx)
cmpl %r15d, 0x1c98(%rbx)
jne 0x90fb4
cmpb $0x0, 0x1ce6(%rbx)
jne 0x90fb4
cmpb $0x1, 0x1ce7(%rbx)
jne 0x90fb4
movl 0x1b30(%rbx), %eax
testl %eax, %eax
sete %cl
cmpl %r15d, %eax
sete %dl
orb %cl, %dl
je 0x90f9f
btl $0x13, %r14d
jae 0x90faf
jmp 0x90fb4
btl $0x13, %r14d
jb 0x90fb4
movq -0x48(%rbp), %rcx
cmpl 0x54(%rcx), %eax
jne 0x90fb4
movb $0x1, %al
movl %eax, -0x38(%rbp)
cmpl %r15d, 0x1ca4(%rbx)
jne 0x9105f
cmpl %r15d, 0x1ca0(%rbx)
sete %r12b
movl %esi, %r13d
movl %r14d, %esi
shrl $0x9, %esi
andl $0x2, %esi
incl %esi
xorl %edi, %edi
callq 0x57e92
movl %r13d, %esi
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
seta %r13b
orb %r12b, %r13b
movzbl %sil, %eax
movl $0x1, %r12d
cmovel %eax, %r12d
jne 0x9100a
cmpl %r15d, 0x1b30(%rbx)
jne 0x9105f
movl %r15d, 0x1ca0(%rbx)
movl %r15d, %edi
movl %r15d, -0x3c(%rbp)
movq -0x48(%rbp), %r15
movq %r15, %rsi
callq 0x4603f
movl %r14d, -0x2c(%rbp)
shrl $0x12, %r14d
andl $0x1, %r14d
xorb $0x1, %r13b
orb %r14b, %r13b
jne 0x91054
movl -0x3c(%rbp), %r13d
movl %r13d, %edi
movq %r15, %rsi
callq 0x57c70
movl %r12d, %esi
movl -0x2c(%rbp), %r14d
movl %r13d, %r15d
jmp 0x9105f
movl %r12d, %esi
movl -0x2c(%rbp), %r14d
movl -0x3c(%rbp), %r15d
cmpl %r15d, 0x1b30(%rbx)
jne 0x910cc
movl 0x1b68(%rbx), %eax
cmpl $0x2, %eax
je 0x910db
cmpl $0x1, %eax
jne 0x910ef
cmpb $0x1, 0x1b3c(%rbx)
jne 0x910a8
movss 0x128(%rbx), %xmm0
movss 0x12c(%rbx), %xmm1
movq -0x68(%rbp), %rax
subss (%rax), %xmm0
subss 0x4(%rax), %xmm1
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movlps %xmm0, 0x1b58(%rbx)
movl 0x1b6c(%rbx), %ecx
cmpq $0x5, %rcx
jae 0x911ad
movb $0x1, %al
cmpb $0x0, 0x130(%rbx,%rcx)
je 0x910fb
movl %esi, %r15d
jmp 0x91153
xorl %eax, %eax
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %rdx
jmp 0x91178
cmpl %r15d, 0x1ca4(%rbx)
je 0x910ef
movl %esi, %r14d
callq 0x46130
movl %r14d, %esi
xorl %eax, %eax
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %rdx
jmp 0x9116c
testb $0x40, %r14b
jne 0x9110c
movl %r14d, %eax
shrb $0x5, %al
andb -0x38(%rbp), %al
je 0x91149
cmpb $0x0, 0x2004(%rbx)
jne 0x91149
btl $0x8, %r14d
jb 0x91120
xorl %eax, %eax
jmp 0x91127
movb 0x434(%rbx,%rcx), %al
btl $0xa, %r14d
jb 0x91132
xorl %ecx, %ecx
jmp 0x91145
movss 0x450(%rbx,%rcx,4), %xmm0
ucomiss 0x94(%rbx), %xmm0
setae %cl
testb %al, %al
je 0x9119b
movl %esi, %r15d
callq 0x46130
xorl %eax, %eax
btl $0x12, %r14d
jb 0x91161
movb $0x1, 0x1ce6(%rbx)
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %rdx
movl %r15d, %esi
testb %sil, %sil
je 0x91178
movb $0x1, 0x1b3f(%rbx)
testq %rdx, %rdx
je 0x91183
movl -0x38(%rbp), %edi
movb %dil, (%rdx)
testq %rcx, %rcx
je 0x9118a
movb %al, (%rcx)
movl %esi, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl %sil, %eax
testb %cl, %cl
movl $0x1, %r15d
cmovnel %eax, %r15d
jmp 0x9114c
leaq 0x3fec3(%rip), %rdi     # 0xd1077
leaq 0x3fe5d(%rip), %rsi     # 0xd1018
leaq 0x3fef0(%rip), %rcx     # 0xd10b2
movl $0x273, %edx            # imm = 0x273
callq 0xc140