// File: /workspace/github_cpp_makefile_star2_O2/Ciaxur[P]yagb-emu/include/imgui/imgui.cpp
// Function: ImGui::RenderTextEllipsis(ImDrawList*, ImVec2 const&, ImVec2 const&, float, float, char const*, char const*, ImVec2 const*)
void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, float clip_max_x, float ellipsis_max_x, const char* text, const char* text_end_full, const ImVec2* text_size_if_known)
{
    ImGuiContext& g = *GImGui;
    if (text_end_full == NULL)
        text_end_full = FindRenderedTextEnd(text);
    const ImVec2 text_size = text_size_if_known ? *text_size_if_known : CalcTextSize(text, text_end_full, false, 0.0f);

    //draw_list->AddLine(ImVec2(pos_max.x, pos_min.y - 4), ImVec2(pos_max.x, pos_max.y + 4), IM_COL32(0, 0, 255, 255));
    //draw_list->AddLine(ImVec2(ellipsis_max_x, pos_min.y-2), ImVec2(ellipsis_max_x, pos_max.y+2), IM_COL32(0, 255, 0, 255));
    //draw_list->AddLine(ImVec2(clip_max_x, pos_min.y), ImVec2(clip_max_x, pos_max.y), IM_COL32(255, 0, 0, 255));
    // FIXME: We could technically remove (last_glyph->AdvanceX - last_glyph->X1) from text_size.x here and save a few pixels.
    if (text_size.x > pos_max.x - pos_min.x)
    {
        // Hello wo...
        // |       |   |
        // min   max   ellipsis_max
        //          <-> this is generally some padding value

        const ImFont* font = draw_list->_Data->Font;
        const float font_size = draw_list->_Data->FontSize;
        const char* text_end_ellipsis = NULL;

        ImWchar ellipsis_char = font->EllipsisChar;
        int ellipsis_char_count = 1;
        if (ellipsis_char == (ImWchar)-1)
        {
            ellipsis_char = (ImWchar)'.';
            ellipsis_char_count = 3;
        }
        const ImFontGlyph* glyph = font->FindGlyph(ellipsis_char);

        float ellipsis_glyph_width = glyph->X1;                 // Width of the glyph with no padding on either side
        float ellipsis_total_width = ellipsis_glyph_width;      // Full width of entire ellipsis

        if (ellipsis_char_count > 1)
        {
            // Full ellipsis size without free spacing after it.
            const float spacing_between_dots = 1.0f * (draw_list->_Data->FontSize / font->FontSize);
            ellipsis_glyph_width = glyph->X1 - glyph->X0 + spacing_between_dots;
            ellipsis_total_width = ellipsis_glyph_width * (float)ellipsis_char_count - spacing_between_dots;
        }

        // We can now claim the space between pos_max.x and ellipsis_max.x
        const float text_avail_width = ImMax((ImMax(pos_max.x, ellipsis_max_x) - ellipsis_total_width) - pos_min.x, 1.0f);
        float text_size_clipped_x = font->CalcTextSizeA(font_size, text_avail_width, 0.0f, text, text_end_full, &text_end_ellipsis).x;
        if (text == text_end_ellipsis && text_end_ellipsis < text_end_full)
        {
            // Always display at least 1 character if there's no room for character + ellipsis
            text_end_ellipsis = text + ImTextCountUtf8BytesFromChar(text, text_end_full);
            text_size_clipped_x = font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, text, text_end_ellipsis).x;
        }
        while (text_end_ellipsis > text && ImCharIsBlankA(text_end_ellipsis[-1]))
        {
            // Trim trailing space before ellipsis (FIXME: Supporting non-ascii blanks would be nice, for this we need a function to backtrack in UTF-8 text)
            text_end_ellipsis--;
            text_size_clipped_x -= font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, text_end_ellipsis, text_end_ellipsis + 1).x; // Ascii blanks are always 1 byte
        }

        // Render text, render ellipsis
        RenderTextClippedEx(draw_list, pos_min, ImVec2(clip_max_x, pos_max.y), text, text_end_ellipsis, &text_size, ImVec2(0.0f, 0.0f));
        float ellipsis_x = pos_min.x + text_size_clipped_x;
        if (ellipsis_x + ellipsis_total_width <= ellipsis_max_x)
            for (int i = 0; i < ellipsis_char_count; i++)
            {
                font->RenderChar(draw_list, font_size, ImVec2(ellipsis_x, pos_min.y), GetColorU32(ImGuiCol_Text), ellipsis_char);
                ellipsis_x += ellipsis_glyph_width;
            }
    }
    else
    {
        RenderTextClippedEx(draw_list, pos_min, ImVec2(clip_max_x, pos_max.y), text, text_end_full, &text_size, ImVec2(0.0f, 0.0f));
    }

    if (g.LogEnabled)
        LogRenderedText(&pos_min, text, text_end_full);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r9, %r15
movq %r8, %r12
movq %rcx, %rbx
movaps %xmm1, -0xb0(%rbp)
movd %xmm0, -0x44(%rbp)
movq %rsi, %r14
movq %rdi, %rcx
movq 0xad592(%rip), %r13     # 0xe3ce0
testq %r8, %r8
movq %rdi, -0x40(%rbp)
movq %rdx, -0x70(%rbp)
jne 0x36770
movq %rbx, %rdi
xorl %esi, %esi
callq 0x36123
movq -0x70(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq %rax, %r12
testq %r15, %r15
je 0x3677a
movq (%r15), %rax
jmp 0x36798
pxor %xmm0, %xmm0
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x365e8
movq -0x70(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq %xmm0, %rax
movq %rax, -0x88(%rbp)
movd %eax, %xmm0
movss (%rdx), %xmm1
subss (%r14), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x36811
movq %r13, -0x98(%rbp)
movq %r12, -0x78(%rbp)
movq 0x38(%rcx), %rax
movq 0x8(%rax), %r13
movss 0x10(%rax), %xmm0
movss %xmm0, -0x2c(%rbp)
andq $0x0, -0x38(%rbp)
movl 0x54(%r13), %r12d
cmpw $-0x1, %r12w
pushq $0x2e
popq %rax
cmovnel %r12d, %eax
movzwl %ax, %r15d
movq %r13, %rdi
movl %r15d, %esi
callq 0x6b25a
xorl %ecx, %ecx
movss 0x10(%rax), %xmm3
cmpw $-0x1, %r12w
sete %cl
movq %rcx, -0x90(%rbp)
je 0x36855
movss %xmm3, -0x48(%rbp)
jmp 0x36889
movss 0x4(%rdx), %xmm0
leaq -0x38(%rbp), %rdx
movss -0x44(%rbp), %xmm1
movss %xmm1, (%rdx)
movss %xmm0, 0x4(%rdx)
leaq -0xa0(%rbp), %rax
andq $0x0, (%rax)
leaq -0x88(%rbp), %r9
movq %rcx, %rdi
movq %r14, %rsi
movq %rbx, %rcx
movq %r12, %r8
pushq $0x0
pushq %rax
callq 0x36445
popq %rax
popq %rcx
jmp 0x369f9
movq -0x40(%rbp), %rcx
movq 0x38(%rcx), %rcx
movss 0x10(%rcx), %xmm0
divss 0x14(%r13), %xmm0
subss 0x8(%rax), %xmm3
movaps %xmm3, %xmm1
addss %xmm0, %xmm1
movss 0x65788(%rip), %xmm3    # 0x9c004
movss %xmm1, -0x48(%rbp)
mulss %xmm1, %xmm3
subss %xmm0, %xmm3
movq -0x78(%rbp), %r12
movq -0x70(%rbp), %rax
movss (%rax), %xmm0
movaps -0xb0(%rbp), %xmm2
movaps %xmm2, %xmm1
cmpless %xmm0, %xmm1
andps %xmm1, %xmm0
andnps %xmm2, %xmm1
orps %xmm0, %xmm1
movss %xmm3, -0x7c(%rbp)
subss %xmm3, %xmm1
subss (%r14), %xmm1
maxss 0x65735(%rip), %xmm1    # 0x9bff8
leaq -0x38(%rbp), %rcx
xorps %xmm2, %xmm2
movq %r13, %rdi
movss -0x2c(%rbp), %xmm0
movq %rbx, %rsi
movq %r12, %rdx
callq 0x6b56a
movaps %xmm0, -0x60(%rbp)
leaq -0x38(%rbp), %rax
movq (%rax), %rax
cmpq %rbx, %rax
setne %cl
cmpq %r12, %rax
setae %al
orb %cl, %al
jne 0x3692e
movq %rbx, %rdi
movq %r12, %rsi
callq 0x34aa7
movslq %eax, %rdx
addq %rbx, %rdx
movq %rdx, -0x38(%rbp)
movss 0x65f5b(%rip), %xmm1    # 0x9c870
xorps %xmm2, %xmm2
movq %r13, %rdi
movss -0x2c(%rbp), %xmm0
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x6b56a
movaps %xmm0, -0x60(%rbp)
movq -0x90(%rbp), %rax
leal 0x1(,%rax,2), %r12d
movq -0x38(%rbp), %r8
cmpq %rbx, %r8
movss -0x2c(%rbp), %xmm0
jbe 0x36988
movzbl -0x1(%r8), %eax
cmpl $0x20, %eax
je 0x3695a
cmpl $0x9, %eax
jne 0x36988
leaq -0x1(%r8), %rsi
movq %rsi, -0x38(%rbp)
xorps %xmm2, %xmm2
movq %r13, %rdi
movss 0x65f00(%rip), %xmm1    # 0x9c870
movq %r8, %rdx
xorl %ecx, %ecx
callq 0x6b56a
movaps -0x60(%rbp), %xmm1
subss %xmm0, %xmm1
movaps %xmm1, -0x60(%rbp)
jmp 0x3693d
movq -0x70(%rbp), %rax
movss 0x4(%rax), %xmm0
leaq -0xa0(%rbp), %rdx
movss -0x44(%rbp), %xmm1
movss %xmm1, (%rdx)
movss %xmm0, 0x4(%rdx)
leaq -0xb8(%rbp), %rax
andq $0x0, (%rax)
leaq -0x88(%rbp), %r9
movq -0x40(%rbp), %rdi
movq %r14, %rsi
movq %rbx, %rcx
pushq $0x0
pushq %rax
callq 0x36445
popq %rax
popq %rcx
movaps -0x60(%rbp), %xmm0
addss (%r14), %xmm0
movss -0x7c(%rbp), %xmm1
movaps %xmm0, -0x60(%rbp)
addss %xmm0, %xmm1
movaps -0xb0(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jae 0x36a23
movq -0x78(%rbp), %r12
movq -0x98(%rbp), %r13
cmpb $0x1, 0x3138(%r13)
jne 0x36a11
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x36222
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subl $0x1, %r12d
jb 0x369ee
movss 0x4(%r14), %xmm0
movaps %xmm0, -0x70(%rbp)
xorl %edi, %edi
movss 0x655bb(%rip), %xmm0    # 0x9bff8
callq 0x35d33
movaps -0x60(%rbp), %xmm1
unpcklps -0x70(%rbp), %xmm1      # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
movq %r13, %rdi
movq -0x40(%rbp), %rsi
movss -0x2c(%rbp), %xmm0
movl %eax, %edx
movl %r15d, %ecx
callq 0x6b794
movaps -0x60(%rbp), %xmm0
addss -0x48(%rbp), %xmm0
movaps %xmm0, -0x60(%rbp)
jmp 0x36a23