// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movl %esi, %r15d
leaq 0x69ee7(%rip), %rax     # 0xe3ce0
movq (%rax), %r14
movq 0x1ae0(%r14), %rsi
movb $0x1, 0x90(%rsi)
btl $0xe, %r8d
jb 0x79e98
movq %rdx, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
xorl %eax, %eax
testb $0x7, %r8b
sete %al
leal (%rax,%r8), %r13d
addl $0x20, %r13d
orl %r8d, %eax
testw $0x3f0, %r8w            # imm = 0x3F0
cmovnel %eax, %r13d
movq 0x1ae8(%r14), %rax
movq %rax, -0x38(%rbp)
btl $0xb, %r13d
jae 0x79e5a
cmpq %rsi, 0x1af0(%r14)
je 0x79f34
xorl %ebx, %ebx
movq %rsi, -0x58(%rbp)
movq %rdi, -0x60(%rbp)
movl %r15d, %esi
callq 0x37658
movb 0x2004(%r14), %cl
testb %al, %al
je 0x79ebd
movb $0x1, %r12b
testb $0x1, %cl
je 0x79ec0
cmpl %r15d, 0x2024(%r14)
jne 0x79ec0
movb 0x2008(%r14), %r12b
andb $0x2, %r12b
shrb %r12b
jmp 0x79ec0
testq %rdx, %rdx
je 0x79ea0
movb $0x0, (%rdx)
testq %rcx, %rcx
je 0x79ea8
movb $0x0, (%rcx)
cmpl %r15d, 0x1b30(%r14)
jne 0x79eb6
callq 0x37444
xorl %esi, %esi
jmp 0x7a3b9
xorl %r12d, %r12d
notb %cl
btl $0x9, %r13d
setae %al
orb %cl, %al
testb $0x1, %al
jne 0x79f45
testb $0x4, 0x2008(%r14)
jne 0x79f45
pushq $0x20
popq %rdi
callq 0x374fd
testb %al, %al
je 0x79f45
movl %r15d, %edi
callq 0x37452
movss 0x1b28(%r14), %xmm1
addss 0x229fd(%rip), %xmm1    # 0x9c8fc
movaps %xmm1, %xmm0
subss 0x18(%r14), %xmm0
movss 0x229f4(%rip), %xmm2    # 0x9c904
xorps %xmm3, %xmm3
callq 0x40041
testl %eax, %eax
je 0x79f42
movl %r15d, 0x2080(%r14)
movq -0x58(%rbp), %rdi
callq 0x37fa1
movb $0x1, %r12b
movb $0x1, %sil
jmp 0x79f47
movq %rsi, 0x1ae8(%r14)
movb $0x1, %bl
jmp 0x79e5c
movb $0x1, %r12b
xorl %esi, %esi
testb %bl, %bl
je 0x79f56
movq -0x38(%rbp), %rax
movq %rax, 0x1ae8(%r14)
btl $0xc, %r13d
setae %al
movl %r12d, %ecx
xorb $0x1, %cl
orb %al, %cl
jne 0x79f7e
movl 0x1b20(%r14), %eax
cmpl %r15d, %eax
sete %cl
testl %eax, %eax
sete %al
orb %cl, %al
jmp 0x79f81
testb %r12b, %r12b
movq -0x58(%rbp), %r12
je 0x79fbe
btl $0x10, %r13d
jb 0x79fca
testb $0x1, %r13b
je 0x79fa5
xorl %ebx, %ebx
cmpb $0x0, 0x420(%r14)
movl $0x0, %eax
jne 0x7a019
movl %r13d, %ecx
andl $0x2, %ecx
je 0x79ff5
cmpb $0x0, 0x421(%r14)
je 0x79ff5
xorl %eax, %eax
pushq $0x1
popq %rbx
jmp 0x7a013
movl $0x0, -0x38(%rbp)
jmp 0x7a19c
cmpb $0x0, 0x140(%r14)
jne 0x7a18a
cmpb $0x0, 0x141(%r14)
jne 0x7a18a
cmpb $0x0, 0x142(%r14)
je 0x79f8e
jmp 0x7a18a
testb $0x4, %r13b
jne 0x7a002
pushq $-0x1
popq %rbx
movb $0x1, %al
jmp 0x7a013
movb 0x422(%r14), %al
xorb $0x1, %al
movzbl %al, %ebx
negl %ebx
orl $0x2, %ebx
testb $0x1, %r13b
je 0x7a030
cmpb $0x0, 0x42a(%r14)
je 0x7a02a
movb $0x1, %dil
xorl %edx, %edx
jmp 0x7a066
movl %r13d, %ecx
andl $0x2, %ecx
testl %ecx, %ecx
je 0x7a046
cmpb $0x0, 0x42b(%r14)
je 0x7a046
pushq $0x1
popq %rdx
movb $0x1, %dil
jmp 0x7a066
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
testb $0x4, %r13b
jne 0x7a055
xorl %edi, %edi
jmp 0x7a066
movb 0x42c(%r14), %dil
testb %dil, %dil
pushq $0x2
popq %rcx
cmovneq %rcx, %rdx
testb %al, %al
jne 0x7a10d
cmpl %r15d, 0x1b30(%r14)
je 0x7a10d
testb $0x60, %r13b
movq %rdx, -0x38(%rbp)
movl %edi, -0x2c(%rbp)
je 0x7a0c1
movl %esi, -0x3c(%rbp)
movl %r15d, %edi
movq %r12, %rsi
callq 0x3739b
movl %ebx, 0x1b6c(%r14)
btl $0x12, %r13d
jb 0x7a0af
movl %r15d, %edi
movq %r12, %rsi
callq 0x454cc
movq %r12, %rdi
callq 0x37fa1
movl -0x3c(%rbp), %esi
movq -0x38(%rbp), %rdx
movl -0x2c(%rbp), %edi
testb $0x10, %r13b
jne 0x7a0db
btl $0x8, %r13d
jae 0x7a10d
movl %ebx, %eax
cmpb $0x1, 0x425(%r14,%rax)
jne 0x7a10d
btl $0x11, %r13d
jb 0x7a0ef
movl %r15d, %edi
movq %r12, %rsi
callq 0x3739b
jmp 0x7a0f4
callq 0x37444
movl %ebx, 0x1b6c(%r14)
movq %r12, %rdi
callq 0x37fa1
movb $0x1, %sil
movq -0x38(%rbp), %rdx
movl -0x2c(%rbp), %edi
testb %r13b, %r13b
jns 0x7a143
testb %dil, %dil
je 0x7a143
movb $0x1, %bl
btl $0xa, %r13d
jae 0x7a13c
movss 0x450(%r14,%rdx,4), %xmm0
ucomiss 0x94(%r14), %xmm0
movzbl %sil, %ebx
pushq $0x1
popq %rax
cmovbl %eax, %ebx
callq 0x37444
movl %ebx, %esi
btl $0xa, %r13d
jae 0x7a18a
cmpl %r15d, 0x1b30(%r14)
jne 0x7a18a
movslq 0x1b6c(%r14), %rdi
movss 0x43c(%r14,%rdi,4), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x7a18a
movl %esi, %ebx
pushq $0x1
popq %r12
movl %r12d, %esi
callq 0x401cd
movl %ebx, %esi
movzbl %sil, %esi
testb %al, %al
cmovnel %r12d, %esi
movq -0x58(%rbp), %r12
movb $0x1, %al
movl %eax, -0x38(%rbp)
testb %sil, %sil
je 0x7a19c
movb $0x1, 0x1ce6(%r14)
cmpl %r15d, 0x1c98(%r14)
jne 0x7a1eb
cmpb $0x0, 0x1ce6(%r14)
jne 0x7a1eb
cmpb $0x1, 0x1ce7(%r14)
jne 0x7a1eb
movl 0x1b30(%r14), %eax
testl %eax, %eax
sete %cl
cmpl %r15d, %eax
sete %dl
orb %cl, %dl
je 0x7a1d8
btl $0x13, %r13d
jae 0x7a1e6
jmp 0x7a1eb
btl $0x13, %r13d
jb 0x7a1eb
cmpl 0x54(%r12), %eax
jne 0x7a1eb
movb $0x1, %al
movl %eax, -0x38(%rbp)
cmpl %r15d, 0x1ca4(%r14)
jne 0x7a286
cmpl %r15d, 0x1ca0(%r14)
sete %r12b
movl %esi, %ebx
movl %r13d, %esi
shrl $0x9, %esi
andl $0x2, %esi
incl %esi
xorl %edi, %edi
callq 0x4c450
movl %ebx, %esi
movl %eax, %ebx
orb %r12b, %bl
movzbl %sil, %r12d
pushq $0x1
popq %rax
cmovnel %eax, %r12d
jne 0x7a234
cmpl %r15d, 0x1b30(%r14)
jne 0x7a286
movl %r15d, 0x1ca0(%r14)
movl %r15d, %edi
movl %r15d, -0x3c(%rbp)
movq -0x58(%rbp), %r15
movq %r15, %rsi
callq 0x3739b
movl %r13d, -0x2c(%rbp)
shrl $0x12, %r13d
andl $0x1, %r13d
xorb $0x1, %bl
orb %r13b, %bl
jne 0x7a27b
movl -0x3c(%rbp), %ebx
movl %ebx, %edi
movq %r15, %rsi
callq 0x454cc
movl %r12d, %esi
movl -0x2c(%rbp), %r13d
movl %ebx, %r15d
jmp 0x7a286
movl %r12d, %esi
movl -0x2c(%rbp), %r13d
movl -0x3c(%rbp), %r15d
cmpl %r15d, 0x1b30(%r14)
jne 0x7a2f9
movl 0x1b68(%r14), %eax
cmpl $0x2, %eax
je 0x7a308
cmpl $0x1, %eax
jne 0x7a31a
cmpb $0x1, 0x1b3c(%r14)
jne 0x7a2d4
movss 0x128(%r14), %xmm0
movss 0x12c(%r14), %xmm1
movq -0x60(%rbp), %rax
subss (%rax), %xmm0
subss 0x4(%rax), %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 0x7a3d8
movb $0x1, %al
cmpb $0x0, 0x130(%r14,%rcx)
je 0x7a326
movl %esi, %ebx
jmp 0x7a381
xorl %eax, %eax
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rdx
jmp 0x7a3a7
cmpl %r15d, 0x1ca4(%r14)
je 0x7a31a
movl %esi, %ebx
callq 0x37444
movl %ebx, %esi
xorl %eax, %eax
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rdx
jmp 0x7a39a
testb $0x40, %r13b
jne 0x7a337
movl %r13d, %eax
shrb $0x5, %al
andb -0x38(%rbp), %al
je 0x7a378
cmpb $0x0, 0x2004(%r14)
jne 0x7a378
btl $0x8, %r13d
jb 0x7a34c
xorl %eax, %eax
jmp 0x7a354
movb 0x434(%r14,%rcx), %al
btl $0xa, %r13d
jb 0x7a35f
xorl %ecx, %ecx
jmp 0x7a374
movss 0x450(%r14,%rcx,4), %xmm0
ucomiss 0x94(%r14), %xmm0
setae %cl
testb %al, %al
je 0x7a3ca
movl %esi, %ebx
callq 0x37444
xorl %eax, %eax
btl $0x12, %r13d
jb 0x7a390
movb $0x1, 0x1ce6(%r14)
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rdx
movl %ebx, %esi
testb %sil, %sil
je 0x7a3a7
movb $0x1, 0x1b3f(%r14)
testq %rdx, %rdx
je 0x7a3b2
movl -0x38(%rbp), %edi
movb %dil, (%rdx)
testq %rcx, %rcx
je 0x7a3b9
movb %al, (%rcx)
movl %esi, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl %sil, %eax
testb %cl, %cl
pushq $0x1
popq %rbx
cmovnel %eax, %ebx
jmp 0x7a37a
leaq 0x3e008(%rip), %rdi     # 0xb83e7
leaq 0x3dfa2(%rip), %rsi     # 0xb8388
leaq 0x3e035(%rip), %rcx     # 0xb8422
movl $0x273, %edx            # imm = 0x273
callq 0xc140