// File: 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
subq $0x1e0, %rsp            # imm = 0x1E0
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
callq 0x2e220
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
testb $0x1, 0x74(%rax)
je 0x29356
movb $0x0, -0x1(%rbp)
jmp 0x29b7d
movq 0x50163(%rip), %rax     # 0x794c0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x13e8, %rax           # imm = 0x13E8
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xbc60
movl %eax, -0x3c(%rbp)
callq 0x185e0
movss %xmm0, -0x40(%rbp)
movq -0x30(%rbp), %rax
movss 0x1718(%rax), %xmm1
movq -0x38(%rbp), %rax
movss 0x24(%rax), %xmm0
addss %xmm0, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x44(%rbp)
movq -0x28(%rbp), %rax
movl 0x178(%rax), %eax
movl %eax, -0x48(%rbp)
cmpl $-0x2, -0x48(%rbp)
je 0x293c8
cmpl $-0x1, -0x48(%rbp)
jne 0x293e8
movq -0x30(%rbp), %rdi
addq $0x27a8, %rdi           # imm = 0x27A8
movl -0x3c(%rbp), %esi
xorl %edx, %edx
callq 0xa7d0
movl $0x3, %ecx
cltd
idivl %ecx
movl %edx, -0x48(%rbp)
movq -0x18(%rbp), %rax
movss (%rax), %xmm0
movss %xmm0, -0x60(%rbp)
movq -0x18(%rbp), %rax
movss 0x4(%rax), %xmm0
movss %xmm0, -0x5c(%rbp)
movq -0x18(%rbp), %rax
movss 0x8(%rax), %xmm0
movss %xmm0, -0x58(%rbp)
movq -0x18(%rbp), %rax
movss 0xc(%rax), %xmm0
movss %xmm0, -0x54(%rbp)
cmpl $0x1, -0x48(%rbp)
jne 0x2944d
movss -0x60(%rbp), %xmm0
movss -0x5c(%rbp), %xmm1
movss -0x58(%rbp), %xmm2
leaq -0x60(%rbp), %rdi
leaq -0x60(%rbp), %rsi
addq $0x4, %rsi
leaq -0x60(%rbp), %rdx
addq $0x8, %rdx
callq 0xa230
movss -0x60(%rbp), %xmm0
movss 0x31c32(%rip), %xmm2    # 0x5b08c
mulss %xmm2, %xmm0
movss 0x31bbe(%rip), %xmm1    # 0x5b024
addss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x70(%rbp)
movss -0x5c(%rbp), %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x6c(%rbp)
movss -0x58(%rbp), %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x68(%rbp)
movss -0x54(%rbp), %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x64(%rbp)
movzbl -0x19(%rbp), %eax
andl $0x1, %eax
addl $0x3, %eax
movl %eax, -0x74(%rbp)
movb $0x0, -0x75(%rbp)
callq 0x211c0
movq -0x10(%rbp), %rdi
callq 0x1b8c0
movl -0x48(%rbp), %eax
subl $0x1, %eax
sete -0x76(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x1a0(%rbp)
subl $0x2, %eax
jb 0x294fa
jmp 0x294e6
movl -0x1a0(%rbp), %eax
subl $0x2, %eax
je 0x2979d
jmp 0x2993b
movss -0x40(%rbp), %xmm0
movss -0x44(%rbp), %xmm1
movq -0x38(%rbp), %rax
movss 0x34(%rax), %xmm2
addss %xmm2, %xmm1
subss %xmm1, %xmm0
movss %xmm0, -0x7c(%rbp)
movss -0x7c(%rbp), %xmm0
movq -0x38(%rbp), %rax
movss 0x20(%rax), %xmm1
movss 0x34(%rax), %xmm2
addss %xmm1, %xmm1
addss %xmm2, %xmm1
movl -0x74(%rbp), %eax
movl %eax, %ecx
decl %ecx
cvtsi2ss %ecx, %xmm2
mulss %xmm2, %xmm1
subss %xmm1, %xmm0
cvtsi2ss %eax, %xmm1
divss %xmm1, %xmm0
cvttps2dq %xmm0, %xmm0
cvtdq2ps %xmm0, %xmm1
movss 0x31ab9(%rip), %xmm0    # 0x5b018
movss %xmm0, -0x1a8(%rbp)
callq 0xb7c0
movaps %xmm0, %xmm1
movss -0x1a8(%rbp), %xmm0
movss %xmm1, -0x80(%rbp)
movss -0x7c(%rbp), %xmm1
movss -0x80(%rbp), %xmm4
movq -0x38(%rbp), %rax
movss 0x20(%rax), %xmm2
movss 0x34(%rax), %xmm3
addss %xmm2, %xmm2
addss %xmm4, %xmm2
addss %xmm3, %xmm2
movl -0x74(%rbp), %eax
decl %eax
cvtsi2ss %eax, %xmm3
mulss %xmm3, %xmm2
subss %xmm2, %xmm1
cvttps2dq %xmm1, %xmm1
cvtdq2ps %xmm1, %xmm1
callq 0xb7c0
movss %xmm0, -0x84(%rbp)
movss -0x80(%rbp), %xmm0
movss %xmm0, -0x1a4(%rbp)
leaq 0x32d99(%rip), %rdi     # 0x5c372
xorl %edx, %edx
movl %edx, %esi
movss 0x31a97(%rip), %xmm0    # 0x5b07c
callq 0x10930
movss -0x1a4(%rbp), %xmm1
movlpd %xmm0, -0x90(%rbp)
movss -0x90(%rbp), %xmm0
ucomiss %xmm1, %xmm0
setae %al
andb $0x1, %al
movb %al, -0x85(%rbp)
movq 0x4d509(%rip), %rax     # 0x76b20
movq %rax, -0xb0(%rbp)
movq 0x4d503(%rip), %rax     # 0x76b28
movq %rax, -0xa8(%rbp)
movq 0x4d4fd(%rip), %rax     # 0x76b30
movq %rax, -0xa0(%rbp)
movq 0x4d4f7(%rip), %rax     # 0x76b38
movq %rax, -0x98(%rbp)
leaq -0x110(%rbp), %rdi
leaq 0x4d4ea(%rip), %rsi     # 0x76b40
movl $0x60, %edx
callq 0x7080
testb $0x1, -0x85(%rbp)
je 0x29679
leaq -0x110(%rbp), %rax
movq %rax, -0x1b0(%rbp)
jmp 0x296b3
testb $0x1, -0x76(%rbp)
je 0x29693
leaq -0x110(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x1b8(%rbp)
jmp 0x296a5
leaq -0x110(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x1b8(%rbp)
movq -0x1b8(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movq -0x1b0(%rbp), %rax
movq %rax, -0x118(%rbp)
movss -0x80(%rbp), %xmm0
callq 0xafc0
movl $0x0, -0x11c(%rbp)
movl -0x11c(%rbp), %eax
cmpl -0x74(%rbp), %eax
jge 0x2978e
cmpl $0x0, -0x11c(%rbp)
jle 0x296fe
movq -0x38(%rbp), %rax
movss 0x34(%rax), %xmm1
xorps %xmm0, %xmm0
callq 0x1a5e0
movl -0x11c(%rbp), %eax
addl $0x1, %eax
cmpl -0x74(%rbp), %eax
jne 0x29719
movss -0x84(%rbp), %xmm0
callq 0xafc0
movslq -0x11c(%rbp), %rax
movq -0xb0(%rbp,%rax,8), %rdi
movslq -0x11c(%rbp), %rax
leaq -0x70(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
movq -0x118(%rbp), %rax
movslq -0x11c(%rbp), %rcx
movq (%rax,%rcx,8), %r8
movss 0x318c4(%rip), %xmm0    # 0x5b018
xorl %edx, %edx
movl $0xff, %ecx
callq 0x22800
andb $0x1, %al
movzbl %al, %ecx
movb -0x75(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
orl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x75(%rbp)
movl -0x11c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
jmp 0x296d5
callq 0xb0f0
callq 0xb0f0
jmp 0x2993b
movss -0x40(%rbp), %xmm0
subss -0x44(%rbp), %xmm0
movss %xmm0, -0x120(%rbp)
testb $0x1, -0x19(%rbp)
je 0x297e2
leaq -0x160(%rbp), %rdi
movl -0x70(%rbp), %ecx
movl -0x6c(%rbp), %r8d
movl -0x68(%rbp), %r9d
movl -0x64(%rbp), %eax
movl $0x40, %esi
leaq 0x32b8a(%rip), %rdx     # 0x5c360
movl %eax, (%rsp)
movb $0x0, %al
callq 0x95a0
jmp 0x29807
leaq -0x160(%rbp), %rdi
movl -0x70(%rbp), %ecx
movl -0x6c(%rbp), %r8d
movl -0x68(%rbp), %r9d
movl $0x40, %esi
leaq 0x32bc0(%rip), %rdx     # 0x5c3c0
movb $0x0, %al
callq 0x95a0
movss -0x120(%rbp), %xmm0
movq -0x38(%rbp), %rax
subss 0x34(%rax), %xmm0
callq 0xafc0
leaq -0x160(%rbp), %rsi
leaq 0x32ba3(%rip), %rdi     # 0x5c3ce
movl $0x40, %edx
movl $0x6, %ecx
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %r8
callq 0xb040
andb $0x1, %al
movzbl %al, %ecx
movb -0x75(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
orl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x75(%rbp)
callq 0xb0f0
leaq -0x160(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x23, %ecx
movb %al, -0x1b9(%rbp)
je 0x2989b
movq -0x168(%rbp), %rax
movsbl (%rax), %edi
callq 0x29b90
movb %al, -0x1b9(%rbp)
movb -0x1b9(%rbp), %al
testb $0x1, %al
jne 0x298a7
jmp 0x298bb
movq -0x168(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x168(%rbp)
jmp 0x2986f
movl $0x0, -0x64(%rbp)
movl $0x0, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
testb $0x1, -0x19(%rbp)
je 0x29910
movq -0x168(%rbp), %rdi
leaq -0x70(%rbp), %rdx
leaq -0x70(%rbp), %rcx
addq $0x4, %rcx
leaq -0x70(%rbp), %r8
addq $0x8, %r8
leaq -0x70(%rbp), %r9
addq $0xc, %r9
leaq 0x32a5a(%rip), %rsi     # 0x5c361
movb $0x0, %al
callq 0x70c0
jmp 0x29939
movq -0x168(%rbp), %rdi
leaq -0x70(%rbp), %rdx
leaq -0x70(%rbp), %rcx
addq $0x4, %rcx
leaq -0x70(%rbp), %r8
addq $0x8, %r8
leaq 0x32a8f(%rip), %rsi     # 0x5c3c1
movb $0x0, %al
callq 0x70c0
jmp 0x2993b
movq -0x38(%rbp), %rax
movss 0x34(%rax), %xmm1
xorps %xmm0, %xmm0
callq 0x1a5e0
movq -0x18(%rbp), %rax
movss (%rax), %xmm0
movq -0x18(%rbp), %rax
movss 0x4(%rax), %xmm1
movq -0x18(%rbp), %rax
movss 0x8(%rax), %xmm2
leaq -0x178(%rbp), %rdi
movss 0x316a3(%rip), %xmm3    # 0x5b018
callq 0x2d2b0
leaq -0x178(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x28f80
testb $0x1, %al
jne 0x29993
jmp 0x299b4
movq -0x30(%rbp), %rdi
addq $0x27a8, %rdi           # imm = 0x27A8
movl -0x3c(%rbp), %esi
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl $0x3, %ecx
cltd
idivl %ecx
callq 0xab80
movq -0x28(%rbp), %rax
cmpl $-0x1, 0x178(%rax)
jne 0x29a76
movq -0x38(%rbp), %rax
movss 0x34(%rax), %xmm1
xorps %xmm0, %xmm0
callq 0x1a5e0
movq 0x4d1c3(%rip), %rax     # 0x76ba0
movq %rax, -0x190(%rbp)
movq 0x4d1bd(%rip), %rax     # 0x76ba8
movq %rax, -0x188(%rbp)
movq 0x4d1b7(%rip), %rax     # 0x76bb0
movq %rax, -0x180(%rbp)
movslq -0x48(%rbp), %rax
movq -0x190(%rbp,%rax,8), %rax
movq %rax, -0x1c8(%rbp)
leaq -0x198(%rbp), %rdi
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0x2d280
movq -0x1c8(%rbp), %rdi
leaq -0x198(%rbp), %rsi
movl $0x10, %edx
callq 0x1aa80
testb $0x1, %al
jne 0x29a43
jmp 0x29a64
movq -0x30(%rbp), %rdi
addq $0x27a8, %rdi           # imm = 0x27A8
movl -0x3c(%rbp), %esi
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl $0x3, %ecx
cltd
idivl %ecx
callq 0xab80
xorps %xmm0, %xmm0
movss 0x3160d(%rip), %xmm1    # 0x5b07c
callq 0x1a5e0
jmp 0x29a87
movq -0x38(%rbp), %rax
movss 0x34(%rax), %xmm1
xorps %xmm0, %xmm0
callq 0x1a5e0
movq -0x10(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10230
movq -0x1d0(%rbp), %rdi
movq %rax, %rsi
callq 0xf8c0
movl $0x0, -0x19c(%rbp)
cmpl $0x4, -0x19c(%rbp)
jge 0x29af8
movslq -0x19c(%rbp), %rax
cvtsi2ssl -0x70(%rbp,%rax,4), %xmm0
movss 0x315b6(%rip), %xmm1    # 0x5b08c
divss %xmm1, %xmm0
movslq -0x19c(%rbp), %rax
movss %xmm0, -0x60(%rbp,%rax,4)
movl -0x19c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x19c(%rbp)
jmp 0x29ab8
cmpl $0x1, -0x48(%rbp)
jne 0x29b26
movss -0x60(%rbp), %xmm0
movss -0x5c(%rbp), %xmm1
movss -0x58(%rbp), %xmm2
leaq -0x60(%rbp), %rdi
leaq -0x60(%rbp), %rsi
addq $0x4, %rsi
leaq -0x60(%rbp), %rdx
addq $0x8, %rdx
callq 0xa390
testb $0x1, -0x75(%rbp)
je 0x29b6b
movss -0x60(%rbp), %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, (%rax)
movss -0x5c(%rbp), %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0x4(%rax)
movss -0x58(%rbp), %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0x8(%rax)
testb $0x1, -0x19(%rbp)
je 0x29b69
movss -0x54(%rbp), %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0xc(%rax)
jmp 0x29b6b
callq 0x1b550
callq 0x21490
movb -0x75(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
nopl (%rax,%rax)