// File: /workspace/github_cpp_makefile_star2_O2/donfreiday[P]gb/./imgui/imgui.cpp
// Function: ImGui::ColorEdit4(char const*, float*, bool)
bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha)
{
    ImGuiWindow* window = GetCurrentWindow();
    if (window->SkipItems)
        return false;

    ImGuiState& g = *GImGui;
    const ImGuiStyle& style = g.Style;
    const ImGuiID id = window->GetID(label);
    const float w_full = CalcItemWidth();
    const float square_sz = (g.FontSize + style.FramePadding.y * 2.0f);

    ImGuiColorEditMode edit_mode = window->DC.ColorEditMode;
    if (edit_mode == ImGuiColorEditMode_UserSelect || edit_mode == ImGuiColorEditMode_UserSelectShowButton)
        edit_mode = g.ColorEditModeStorage.GetInt(id, 0) % 3;

    float f[4] = { col[0], col[1], col[2], col[3] };

    if (edit_mode == ImGuiColorEditMode_HSV)
        ImGui::ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]);

    int i[4] = { (int)(f[0] * 255.0f + 0.5f), (int)(f[1] * 255.0f + 0.5f), (int)(f[2] * 255.0f + 0.5f), (int)(f[3] * 255.0f + 0.5f) };

    int components = alpha ? 4 : 3;
    bool value_changed = false;

    ImGui::BeginGroup();
    ImGui::PushID(label);

    const bool hsv = (edit_mode == 1);
    switch (edit_mode)
    {
    case ImGuiColorEditMode_RGB:
    case ImGuiColorEditMode_HSV:
        {
            // RGB/HSV 0..255 Sliders
            const float w_items_all = w_full - (square_sz + style.ItemInnerSpacing.x);
            const float w_item_one  = ImMax(1.0f, (float)(int)((w_items_all - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components));
            const float w_item_last = ImMax(1.0f, (float)(int)(w_items_all - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)));

            const bool hide_prefix = (w_item_one <= CalcTextSize("M:999").x);
            const char* ids[4] = { "##X", "##Y", "##Z", "##W" };
            const char* fmt_table[3][4] =
            {
                {   "%3.0f",   "%3.0f",   "%3.0f",   "%3.0f" },
                { "R:%3.0f", "G:%3.0f", "B:%3.0f", "A:%3.0f" },
                { "H:%3.0f", "S:%3.0f", "V:%3.0f", "A:%3.0f" }
            };
            const char** fmt = hide_prefix ? fmt_table[0] : hsv ? fmt_table[2] : fmt_table[1];

            ImGui::PushItemWidth(w_item_one);
            for (int n = 0; n < components; n++)
            {
                if (n > 0)
                    ImGui::SameLine(0, style.ItemInnerSpacing.x);
                if (n + 1 == components)
                    ImGui::PushItemWidth(w_item_last);
                value_changed |= ImGui::DragInt(ids[n], &i[n], 1.0f, 0, 255, fmt[n]);
            }
            ImGui::PopItemWidth();
            ImGui::PopItemWidth();
        }
        break;
    case ImGuiColorEditMode_HEX:
        {
            // RGB Hexadecimal Input
            const float w_slider_all = w_full - square_sz;
            char buf[64];
            if (alpha)
                ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X%02X", i[0], i[1], i[2], i[3]);
            else
                ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X", i[0], i[1], i[2]);
            ImGui::PushItemWidth(w_slider_all - style.ItemInnerSpacing.x);
            value_changed |= ImGui::InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase);
            ImGui::PopItemWidth();
            char* p = buf;
            while (*p == '#' || ImCharIsSpace(*p))
                p++;

            // Treat at unsigned (%X is unsigned)
            i[0] = i[1] = i[2] = i[3] = 0;
            if (alpha)
                sscanf(p, "%02X%02X%02X%02X", (unsigned int*)&i[0], (unsigned int*)&i[1], (unsigned int*)&i[2], (unsigned int*)&i[3]);
            else
                sscanf(p, "%02X%02X%02X", (unsigned int*)&i[0], (unsigned int*)&i[1], (unsigned int*)&i[2]);
        }
        break;
    }

    ImGui::SameLine(0, style.ItemInnerSpacing.x);

    const ImVec4 col_display(col[0], col[1], col[2], 1.0f);
    if (ImGui::ColorButton(col_display))
        g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3); // Don't set local copy of 'edit_mode' right away!

    if (window->DC.ColorEditMode == ImGuiColorEditMode_UserSelectShowButton)
    {
        ImGui::SameLine(0, style.ItemInnerSpacing.x);
        const char* button_titles[3] = { "RGB", "HSV", "HEX" };
        if (ButtonEx(button_titles[edit_mode], ImVec2(0,0), ImGuiButtonFlags_DontClosePopups))
            g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3); // Don't set local copy of 'edit_mode' right away!
        ImGui::SameLine();
    }
    else
    {
        ImGui::SameLine(0, style.ItemInnerSpacing.x);
    }

    ImGui::TextUnformatted(label, FindTextDisplayEnd(label));

    // Convert back
    for (int n = 0; n < 4; n++)
        f[n] = i[n] / 255.0f;
    if (edit_mode == 1)
        ImGui::ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]);

    if (value_changed)
    {
        col[0] = f[0];
        col[1] = f[1];
        col[2] = f[2];
        if (alpha)
            col[3] = f[3];
    }

    ImGui::PopID();
    ImGui::EndGroup();

    return value_changed;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movl %edx, -0x30(%rbp)
movq 0x343ce(%rip), %r14     # 0x50480
movq 0x1758(%r14), %r12
movb $0x1, 0x72(%r12)
cmpb $0x0, 0x74(%r12)
je 0x1c0ce
xorl %ebx, %ebx
jmp 0x1c53c
movq %rsi, %r13
movq %rdi, %rbx
movq %r12, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x9858
movl %eax, %r15d
callq 0x1137a
movss 0x140c(%r14), %xmm1
addss %xmm1, %xmm1
addss 0x1718(%r14), %xmm1
movss %xmm1, -0x44(%rbp)
movaps %xmm0, -0x80(%rbp)
movl 0x178(%r12), %edx
cmpl $-0x2, %edx
jb 0x1c12c
leaq 0x27a8(%r14), %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0x8d34
cltd
pushq $0x3
popq %rcx
idivl %ecx
movq %rdx, -0x88(%rbp)
movq %rbx, -0x90(%rbp)
movss (%r13), %xmm0
leaq -0x5c(%rbp), %rsi
movss %xmm0, -0x4(%rsi)
movss 0x4(%r13), %xmm1
movss %xmm1, (%rsi)
leaq -0x58(%rbp), %rax
movss 0x8(%r13), %xmm2
movss %xmm2, (%rax)
movss 0xc(%r13), %xmm3
movss %xmm3, 0x4(%rax)
cmpl $0x1, %edx
movq %r14, -0x68(%rbp)
movl %r15d, -0x6c(%rbp)
movq %r12, -0xa0(%rbp)
jne 0x1c1a2
leaq -0x60(%rbp), %rbx
movq %rbx, %rdi
movq %rax, %rdx
callq 0x8a14
movss (%rbx), %xmm0
movss 0x4(%rbx), %xmm1
movss 0x8(%rbx), %xmm2
movss 0xc(%rbx), %xmm3
movss 0x1a1ee(%rip), %xmm5    # 0x36398
mulss %xmm5, %xmm0
movss 0x1a21a(%rip), %xmm4    # 0x363d0
addss %xmm4, %xmm0
cvttss2si %xmm0, %r12d
mulss %xmm5, %xmm1
addss %xmm4, %xmm1
cvttss2si %xmm1, %ebx
movl %r12d, -0x40(%rbp)
movl %ebx, -0x3c(%rbp)
mulss %xmm5, %xmm2
addss %xmm4, %xmm2
cvttss2si %xmm2, %r14d
movl %r14d, -0x38(%rbp)
mulss %xmm5, %xmm3
addss %xmm4, %xmm3
cvttss2si %xmm3, %r15d
movl %r15d, -0x34(%rbp)
callq 0x16ed0
movq -0x90(%rbp), %rdi
callq 0x13116
movl $0x0, -0x2c(%rbp)
movq -0x88(%rbp), %rax
cmpl $0x2, %eax
jae 0x1c37a
movq %r13, -0x98(%rbp)
xorl %r15d, %r15d
cmpl $0x1, %eax
sete %r15b
movzbl -0x30(%rbp), %r14d
leal 0x3(%r14), %eax
movq -0x68(%rbp), %rcx
movss 0x1408(%rcx), %xmm0
movss 0x141c(%rcx), %xmm1
movss -0x44(%rbp), %xmm2
addss %xmm1, %xmm2
movaps -0x80(%rbp), %xmm6
subss %xmm2, %xmm6
addss %xmm0, %xmm0
movaps %xmm0, %xmm2
addss %xmm1, %xmm2
leal 0x2(%r14), %ecx
cvtsi2ss %ecx, %xmm3
mulss %xmm3, %xmm2
cvtsi2ss %eax, %xmm4
movaps %xmm6, %xmm5
subss %xmm2, %xmm5
divss %xmm4, %xmm5
cvttps2dq %xmm5, %xmm2
cvtdq2ps %xmm2, %xmm2
movss 0x1a100(%rip), %xmm4    # 0x36390
movaps %xmm4, %xmm5
maxss %xmm2, %xmm5
movss %xmm5, -0x2c(%rbp)
addss %xmm5, %xmm0
addss %xmm1, %xmm0
mulss %xmm3, %xmm0
subss %xmm0, %xmm6
cvttps2dq %xmm6, %xmm0
cvtdq2ps %xmm0, %xmm0
maxss %xmm0, %xmm4
movss %xmm4, -0x80(%rbp)
leaq 0x1b453(%rip), %rdi     # 0x37716
xorl %ebx, %ebx
movss 0x1a0cf(%rip), %xmm0    # 0x3639c
xorl %esi, %esi
xorl %edx, %edx
callq 0xc6e3
shll $0x5, %r15d
movss -0x2c(%rbp), %xmm1
ucomiss %xmm1, %xmm0
leaq 0x318f7(%rip), %rax     # 0x4dbe0
leaq 0x20(%r15,%rax), %r12
cmovaeq %rax, %r12
movaps %xmm1, %xmm0
callq 0x91e1
leal 0xc(,%r14,4), %r14d
leaq -0x4(%r14), %r13
leaq 0x1a26b(%rip), %r15     # 0x36578
movl $0x0, -0x2c(%rbp)
cmpq %rbx, %r14
je 0x1c3a3
testq %rbx, %rbx
je 0x1c336
movq -0x68(%rbp), %rax
movss 0x141c(%rax), %xmm1
xorps %xmm0, %xmm0
callq 0x1254d
cmpq %rbx, %r13
jne 0x1c345
movss -0x80(%rbp), %xmm0
callq 0x91e1
movslq (%rbx,%r15), %rdi
addq %r15, %rdi
leaq (%rbx,%rbp), %rsi
addq $-0x40, %rsi
movq (%r12,%rbx,2), %r8
movss 0x1a030(%rip), %xmm0    # 0x36390
xorl %edx, %edx
movl $0xff, %ecx
callq 0x17c88
movl -0x2c(%rbp), %ecx
orb %al, %cl
movl %ecx, -0x2c(%rbp)
addq $0x4, %rbx
jmp 0x1c314
jne 0x1c3b4
movaps -0x80(%rbp), %xmm0
subss -0x44(%rbp), %xmm0
movaps %xmm0, -0x80(%rbp)
cmpb $0x0, -0x30(%rbp)
je 0x1c553
movl %r15d, (%rsp)
leaq 0x1b366(%rip), %rdx     # 0x37704
jmp 0x1c55a
callq 0x9272
callq 0x9272
movq -0x98(%rbp), %r13
movq -0x68(%rbp), %r14
movss 0x141c(%r14), %xmm1
xorps %xmm0, %xmm0
callq 0x1254d
movq (%r13), %rax
movss 0x8(%r13), %xmm0
leaq -0xf0(%rbp), %rdi
movq %rax, (%rdi)
movss %xmm0, 0x8(%rdi)
movl $0x3f800000, 0xc(%rdi)  # imm = 0x3F800000
pushq $0x1
popq %rdx
xorl %esi, %esi
callq 0x1be68
testb %al, %al
movq -0x88(%rbp), %r15
movl -0x6c(%rbp), %r12d
je 0x1c41b
leaq 0x27a8(%r14), %rdi
leal 0x1(%r15), %eax
cltd
pushq $0x3
popq %rcx
idivl %ecx
movl %r12d, %esi
callq 0x8f22
movq -0xa0(%rbp), %rax
movl 0x178(%rax), %ebx
movss 0x141c(%r14), %xmm1
xorps %xmm0, %xmm0
callq 0x1254d
cmpl $-0x1, %ebx
jne 0x1c492
movslq %r15d, %rax
leaq 0x1a140(%rip), %rcx     # 0x36588
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
leaq -0xa8(%rbp), %rsi
andq $0x0, (%rsi)
pushq $0x10
popq %rdx
callq 0x127e2
testb %al, %al
je 0x1c482
addq $0x27a8, %r14           # imm = 0x27A8
leal 0x1(%r15), %eax
cltd
pushq $0x3
popq %rcx
idivl %ecx
movq %r14, %rdi
movl %r12d, %esi
callq 0x8f22
movss 0x19f12(%rip), %xmm1    # 0x3639c
xorps %xmm0, %xmm0
callq 0x1254d
xorl %ebx, %ebx
movq -0x90(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xc24f
movq %r14, %rdi
movq %rax, %rsi
callq 0xbba1
movss 0x19ee0(%rip), %xmm1    # 0x36398
cmpq $0x4, %rbx
je 0x1c4d3
cvtsi2ssl -0x40(%rbp,%rbx,4), %xmm0
divss %xmm1, %xmm0
movss %xmm0, -0x60(%rbp,%rbx,4)
incq %rbx
jmp 0x1c4b8
cmpl $0x1, %r15d
jne 0x1c4f8
leaq -0x60(%rbp), %rdi
movss (%rdi), %xmm0
movss 0x4(%rdi), %xmm1
movss 0x8(%rdi), %xmm2
leaq -0x5c(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x8ab0
movl -0x2c(%rbp), %ebx
testb $0x1, %bl
je 0x1c532
movss -0x60(%rbp), %xmm0
movss %xmm0, (%r13)
movss -0x5c(%rbp), %xmm0
movss %xmm0, 0x4(%r13)
movss -0x58(%rbp), %xmm0
movss %xmm0, 0x8(%r13)
cmpb $0x0, -0x30(%rbp)
je 0x1c532
movss -0x54(%rbp), %xmm0
movss %xmm0, 0xc(%r13)
callq 0x12ea2
callq 0x170a4
andb $0x1, %bl
movl %ebx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1b20a(%rip), %rdx     # 0x37764
leaq -0xf0(%rbp), %rdi
pushq $0x40
popq %rsi
movl %r12d, %ecx
movl %ebx, %r8d
movl %r14d, %r9d
xorl %eax, %eax
callq 0x83b1
leaq -0x3c(%rbp), %r12
leaq -0x38(%rbp), %r15
leaq -0x34(%rbp), %rbx
movq -0x68(%rbp), %rax
movaps -0x80(%rbp), %xmm0
subss 0x141c(%rax), %xmm0
callq 0x91e1
leaq 0x1b1d6(%rip), %rdi     # 0x37772
leaq -0xf0(%rbp), %r14
pushq $0x40
popq %rdx
pushq $0x6
popq %rcx
movq %r14, %rsi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x9225
movl %eax, -0x2c(%rbp)
callq 0x9272
movabsq $0x900000200, %rax      # imm = 0x900000200
movzbl (%r14), %ecx
cmpq $0x23, %rcx
ja 0x1c5de
btq %rcx, %rax
jae 0x1c5de
incq %r14
jmp 0x1c5c9
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
cmpb $0x0, -0x30(%rbp)
je 0x1c60e
leaq 0x1b113(%rip), %rsi     # 0x37705
leaq -0x40(%rbp), %rdx
movq %r14, %rdi
movq %r12, %rcx
movq %r15, %r8
movq %rbx, %r9
xorl %eax, %eax
callq 0x70c0
jmp 0x1c3b4
leaq 0x1b150(%rip), %rsi     # 0x37765
leaq -0x40(%rbp), %rdx
movq %r14, %rdi
movq %r12, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x70c0
jmp 0x1c3b4