// File: Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: ImGui::ColorButton(char const*, ImVec4 const&, int, ImVec2)
bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFlags flags, ImVec2 size)
{
    ImGuiWindow* window = GetCurrentWindow();
    if (window->SkipItems)
        return false;

    ImGuiContext& g = *GImGui;
    const ImGuiID id = window->GetID(desc_id);
    float default_size = GetFrameHeight();
    if (size.x == 0.0f)
        size.x = default_size;
    if (size.y == 0.0f)
        size.y = default_size;
    const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
    ItemSize(bb, (size.y >= default_size) ? g.Style.FramePadding.y : 0.0f);
    if (!ItemAdd(bb, id))
        return false;

    bool hovered, held;
    bool pressed = ButtonBehavior(bb, id, &hovered, &held);

    if (flags & ImGuiColorEditFlags_NoAlpha)
        flags &= ~(ImGuiColorEditFlags_AlphaPreview | ImGuiColorEditFlags_AlphaPreviewHalf);

    ImVec4 col_rgb = col;
    if (flags & ImGuiColorEditFlags_InputHSV)
        ColorConvertHSVtoRGB(col_rgb.x, col_rgb.y, col_rgb.z, col_rgb.x, col_rgb.y, col_rgb.z);

    ImVec4 col_rgb_without_alpha(col_rgb.x, col_rgb.y, col_rgb.z, 1.0f);
    float grid_step = ImMin(size.x, size.y) / 2.99f;
    float rounding = ImMin(g.Style.FrameRounding, grid_step * 0.5f);
    ImRect bb_inner = bb;
    float off = 0.0f;
    if ((flags & ImGuiColorEditFlags_NoBorder) == 0)
    {
        off = -0.75f; // The border (using Col_FrameBg) tends to look off when color is near-opaque and rounding is enabled. This offset seemed like a good middle ground to reduce those artifacts.
        bb_inner.Expand(off);
    }
    if ((flags & ImGuiColorEditFlags_AlphaPreviewHalf) && col_rgb.w < 1.0f)
    {
        float mid_x = IM_ROUND((bb_inner.Min.x + bb_inner.Max.x) * 0.5f);
        RenderColorRectWithAlphaCheckerboard(window->DrawList, ImVec2(bb_inner.Min.x + grid_step, bb_inner.Min.y), bb_inner.Max, GetColorU32(col_rgb), grid_step, ImVec2(-grid_step + off, off), rounding, ImDrawCornerFlags_TopRight | ImDrawCornerFlags_BotRight);
        window->DrawList->AddRectFilled(bb_inner.Min, ImVec2(mid_x, bb_inner.Max.y), GetColorU32(col_rgb_without_alpha), rounding, ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_BotLeft);
    }
    else
    {
        // Because GetColorU32() multiplies by the global style Alpha and we don't want to display a checkerboard if the source code had no alpha
        ImVec4 col_source = (flags & ImGuiColorEditFlags_AlphaPreview) ? col_rgb : col_rgb_without_alpha;
        if (col_source.w < 1.0f)
            RenderColorRectWithAlphaCheckerboard(window->DrawList, bb_inner.Min, bb_inner.Max, GetColorU32(col_source), grid_step, ImVec2(off, off), rounding);
        else
            window->DrawList->AddRectFilled(bb_inner.Min, bb_inner.Max, GetColorU32(col_source), rounding, ImDrawCornerFlags_All);
    }
    RenderNavHighlight(bb, id);
    if ((flags & ImGuiColorEditFlags_NoBorder) == 0)
    {
        if (g.Style.FrameBorderSize > 0.0f)
            RenderFrameBorder(bb.Min, bb.Max, rounding);
        else
            window->DrawList->AddRect(bb.Min, bb.Max, GetColorU32(ImGuiCol_FrameBg), rounding); // Color button are often in need of some sort of border
    }

    // Drag and Drop Source
    // NB: The ActiveId test is merely an optional micro-optimization, BeginDragDropSource() does the same test.
    if (g.ActiveId == id && !(flags & ImGuiColorEditFlags_NoDragDrop) && BeginDragDropSource())
    {
        if (flags & ImGuiColorEditFlags_NoAlpha)
            SetDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F, &col_rgb, sizeof(float) * 3, ImGuiCond_Once);
        else
            SetDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F, &col_rgb, sizeof(float) * 4, ImGuiCond_Once);
        ColorButton(desc_id, col, flags);
        SameLine();
        TextEx("Color");
        EndDragDropSource();
    }

    // Tooltip
    if (!(flags & ImGuiColorEditFlags_NoTooltip) && hovered)
        ColorTooltip(desc_id, &col.x, flags & (ImGuiColorEditFlags__InputMask | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaPreview | ImGuiColorEditFlags_AlphaPreviewHalf));

    return pressed;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movlpd %xmm0, -0xc(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movl %edx, -0x24(%rbp)
callq 0xeb270
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
testb $0x1, 0x93(%rax)
je 0x14d60a
movb $0x0, -0x1(%rbp)
jmp 0x14dd10
leaq 0xc592f(%rip), %rax     # 0x212f40
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xc9910
movl %eax, -0x3c(%rbp)
callq 0xdd050
movss %xmm0, -0x40(%rbp)
movss -0xc(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x14d64f
jp 0x14d64f
movss -0x40(%rbp), %xmm0
movss %xmm0, -0xc(%rbp)
movss -0x8(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x14d668
jp 0x14d668
movss -0x40(%rbp), %xmm0
movss %xmm0, -0x8(%rbp)
movq -0x30(%rbp), %rdi
addq $0xd8, %rdi
movq %rdi, -0x108(%rbp)
leaq -0xc(%rbp), %rsi
callq 0x139090
movq -0x108(%rbp), %rsi
movlpd %xmm0, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0xe8660
movss -0x8(%rbp), %xmm0
ucomiss -0x40(%rbp), %xmm0
jb 0x14d6bd
movq -0x38(%rbp), %rax
movss 0x159c(%rax), %xmm0
movss %xmm0, -0x10c(%rbp)
jmp 0x14d6ca
xorps %xmm0, %xmm0
movss %xmm0, -0x10c(%rbp)
jmp 0x14d6ca
movss -0x10c(%rbp), %xmm0
leaq -0x50(%rbp), %rdi
callq 0xdc300
movl -0x3c(%rbp), %esi
leaq -0x50(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
callq 0xd6250
testb $0x1, %al
jne 0x14d6f8
movb $0x0, -0x1(%rbp)
jmp 0x14dd10
movl -0x3c(%rbp), %esi
leaq -0x50(%rbp), %rdi
leaq -0x59(%rbp), %rdx
leaq -0x5a(%rbp), %rcx
xorl %r8d, %r8d
callq 0x139df0
andb $0x1, %al
movb %al, -0x5b(%rbp)
movl -0x24(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x14d72a
movl -0x24(%rbp), %eax
andl $0xfff9ffff, %eax       # imm = 0xFFF9FFFF
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x6c(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x64(%rbp)
movl -0x24(%rbp), %eax
andl $0x10000000, %eax       # imm = 0x10000000
cmpl $0x0, %eax
je 0x14d772
movss -0x6c(%rbp), %xmm0
movss -0x68(%rbp), %xmm1
movss -0x64(%rbp), %xmm2
leaq -0x6c(%rbp), %rdi
leaq -0x6c(%rbp), %rsi
addq $0x4, %rsi
leaq -0x6c(%rbp), %rdx
addq $0x8, %rdx
callq 0xc5c80
movss -0x6c(%rbp), %xmm0
movss -0x68(%rbp), %xmm1
movss -0x64(%rbp), %xmm2
leaq -0x7c(%rbp), %rdi
movss 0x234af(%rip), %xmm3    # 0x170c3c
callq 0xbf4f0
movss -0xc(%rbp), %xmm0
movss -0x8(%rbp), %xmm1
callq 0x13c690
movss 0x40a5b(%rip), %xmm1    # 0x18e204
divss %xmm1, %xmm0
movss %xmm0, -0x80(%rbp)
movq -0x38(%rbp), %rax
movss 0x15a0(%rax), %xmm0
movss 0x24812(%rip), %xmm1    # 0x171fd8
mulss -0x80(%rbp), %xmm1
callq 0x13c690
movss %xmm0, -0x84(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x94(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x8c(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x98(%rbp)
movl -0x24(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0x14d82a
movss 0x3622e(%rip), %xmm0    # 0x183a3c
movss %xmm0, -0x98(%rbp)
movss -0x98(%rbp), %xmm0
leaq -0x94(%rbp), %rdi
callq 0xeb9c0
movl -0x24(%rbp), %eax
andl $0x40000, %eax          # imm = 0x40000
cmpl $0x0, %eax
je 0x14d9af
movss 0x233f9(%rip), %xmm0    # 0x170c3c
ucomiss -0x60(%rbp), %xmm0
jbe 0x14d9af
movss -0x94(%rbp), %xmm0
movss -0x8c(%rbp), %xmm1
addss %xmm1, %xmm0
movss 0x2476f(%rip), %xmm1    # 0x171fd8
mulss %xmm1, %xmm0
addss %xmm1, %xmm0
cvttps2dq %xmm0, %xmm0
cvtdq2ps %xmm0, %xmm0
movss %xmm0, -0x9c(%rbp)
movq -0x30(%rbp), %rax
movq 0x2b8(%rax), %rax
movq %rax, -0x130(%rbp)
movss -0x80(%rbp), %xmm2
movss -0x94(%rbp), %xmm0
movss -0x90(%rbp), %xmm1
addss %xmm2, %xmm0
leaq -0xa4(%rbp), %rdi
callq 0xbf4c0
movq -0x8c(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x6c(%rbp), %rdi
callq 0xc7750
movl %eax, -0x128(%rbp)
movss -0x80(%rbp), %xmm2
movss %xmm2, -0x124(%rbp)
movss -0x98(%rbp), %xmm1
movaps %xmm1, %xmm0
subss %xmm2, %xmm0
leaq -0xb8(%rbp), %rdi
callq 0xbf4c0
movq -0x130(%rbp), %rdi
movl -0x128(%rbp), %esi
movss -0x124(%rbp), %xmm2
movss -0x84(%rbp), %xmm4
movsd -0xa4(%rbp), %xmm0
movsd -0xb0(%rbp), %xmm1
movsd -0xb8(%rbp), %xmm3
movl $0xa, %edx
callq 0x11e200
movq -0x30(%rbp), %rax
movq 0x2b8(%rax), %rax
movq %rax, -0x120(%rbp)
leaq -0x94(%rbp), %rax
movq %rax, -0x118(%rbp)
movss -0x9c(%rbp), %xmm0
movss -0x88(%rbp), %xmm1
leaq -0xc0(%rbp), %rdi
callq 0xbf4c0
leaq -0x7c(%rbp), %rdi
callq 0xc7750
movq -0x120(%rbp), %rdi
movq -0x118(%rbp), %rsi
movl %eax, %ecx
movss -0x84(%rbp), %xmm0
leaq -0xc0(%rbp), %rdx
movl $0x5, %r8d
callq 0x113090
jmp 0x14db16
movl -0x24(%rbp), %eax
andl $0x20000, %eax          # imm = 0x20000
cmpl $0x0, %eax
je 0x14d9c9
leaq -0x6c(%rbp), %rax
movq %rax, -0x138(%rbp)
jmp 0x14d9d6
leaq -0x7c(%rbp), %rax
movq %rax, -0x138(%rbp)
jmp 0x14d9d6
movq -0x138(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0xd0(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0xc8(%rbp)
movss 0x23242(%rip), %xmm0    # 0x170c3c
ucomiss -0xc4(%rbp), %xmm0
jbe 0x14daac
movq -0x30(%rbp), %rax
movq 0x2b8(%rax), %rax
movq %rax, -0x148(%rbp)
movq -0x94(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x8c(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0xc7750
movl %eax, -0x140(%rbp)
movss -0x80(%rbp), %xmm0
movss %xmm0, -0x13c(%rbp)
movss -0x98(%rbp), %xmm1
leaq -0xe8(%rbp), %rdi
movaps %xmm1, %xmm0
callq 0xbf4c0
movq -0x148(%rbp), %rdi
movl -0x140(%rbp), %esi
movss -0x13c(%rbp), %xmm2
movss -0x84(%rbp), %xmm4
movsd -0xd8(%rbp), %xmm0
movsd -0xe0(%rbp), %xmm1
movsd -0xe8(%rbp), %xmm3
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x11e200
jmp 0x14db14
movq -0x30(%rbp), %rax
movq 0x2b8(%rax), %rax
movq %rax, -0x160(%rbp)
leaq -0x94(%rbp), %rax
movq %rax, -0x158(%rbp)
leaq -0x94(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x150(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0xc7750
movq -0x160(%rbp), %rdi
movq -0x158(%rbp), %rsi
movq -0x150(%rbp), %rdx
movl %eax, %ecx
movss -0x84(%rbp), %xmm0
movl $0xf, %r8d
callq 0x113090
jmp 0x14db16
movl -0x3c(%rbp), %esi
leaq -0x50(%rbp), %rdi
movl $0x1, %edx
callq 0xc91e0
movl -0x24(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0x14dbf3
movq -0x38(%rbp), %rax
movss 0x15a4(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x14db81
movq -0x50(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0xf8(%rbp)
movss -0x84(%rbp), %xmm2
movsd -0xf0(%rbp), %xmm0
movsd -0xf8(%rbp), %xmm1
callq 0xc90a0
jmp 0x14dbf1
movq -0x30(%rbp), %rax
movq 0x2b8(%rax), %rax
movq %rax, -0x178(%rbp)
leaq -0x50(%rbp), %rax
movq %rax, -0x170(%rbp)
leaq -0x50(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x168(%rbp)
movl $0x7, %edi
movss 0x23082(%rip), %xmm0    # 0x170c3c
callq 0xc76e0
movq -0x178(%rbp), %rdi
movq -0x170(%rbp), %rsi
movq -0x168(%rbp), %rdx
movl %eax, %ecx
movss -0x84(%rbp), %xmm0
movl $0xf, %r8d
movss 0x23050(%rip), %xmm1    # 0x170c3c
callq 0x112ef0
jmp 0x14dbf3
movq -0x38(%rbp), %rax
movl 0x1b30(%rax), %eax
cmpl -0x3c(%rbp), %eax
jne 0x14dce1
movl -0x24(%rbp), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
jne 0x14dce1
xorl %edi, %edi
callq 0xdfbd0
testb $0x1, %al
jne 0x14dc27
jmp 0x14dce1
movl -0x24(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x14dc4e
leaq 0x2e6e7(%rip), %rdi     # 0x17c320
leaq -0x6c(%rbp), %rsi
movl $0xc, %edx
movl $0x2, %ecx
callq 0xe0030
jmp 0x14dc68
leaq 0x2e6d2(%rip), %rdi     # 0x17c327
leaq -0x6c(%rbp), %rsi
movl $0x10, %edx
movl $0x2, %ecx
callq 0xe0030
movq -0x18(%rbp), %rax
movq %rax, -0x190(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x188(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x17c(%rbp)
leaq -0x100(%rbp), %rdi
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0xbf4c0
movq -0x190(%rbp), %rdi
movq -0x188(%rbp), %rsi
movl -0x17c(%rbp), %edx
movsd -0x100(%rbp), %xmm0
callq 0x14d5d0
xorps %xmm0, %xmm0
movss 0x242bb(%rip), %xmm1    # 0x171f80
callq 0xdc1c0
leaq 0x2e6dc(%rip), %rdi     # 0x17c3ad
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x138a30
callq 0xdff70
movl -0x24(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
jne 0x14dd08
testb $0x1, -0x59(%rbp)
je 0x14dd08
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
andl $0x18060002, %edx       # imm = 0x18060002
callq 0x150890
movb -0x5b(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
nop