// File: /workspace/github_cpp_makefile_star2_O2/donfreiday[P]gb/./imgui/imgui_draw.cpp
// Function: ImFont::CalcTextSizeA(float, float, float, char const*, char const*, char const**) const
ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end, const char** remaining) const
{
    if (!text_end)
        text_end = text_begin + strlen(text_begin); // FIXME-OPT: Need to avoid this.

    const float line_height = size;
    const float scale = size / FontSize;

    ImVec2 text_size = ImVec2(0,0);
    float line_width = 0.0f;

    const bool word_wrap_enabled = (wrap_width > 0.0f);
    const char* word_wrap_eol = NULL;

    const char* s = text_begin;
    while (s < text_end)
    {
        if (word_wrap_enabled)
        {
            // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature.
            if (!word_wrap_eol)
            {
                word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - line_width);
                if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
                    word_wrap_eol++;    // +1 may not be a character start point in UTF-8 but it's ok because we use s >= word_wrap_eol below
            }

            if (s >= word_wrap_eol)
            {
                if (text_size.x < line_width)
                    text_size.x = line_width;
                text_size.y += line_height;
                line_width = 0.0f;
                word_wrap_eol = NULL;

                // Wrapping skips upcoming blanks
                while (s < text_end)
                {
                    const char c = *s;
                    if (ImCharIsSpace(c)) { s++; } else if (c == '\n') { s++; break; } else { break; }
                }
                continue;
            }
        }

        // Decode and advance source
        const char* prev_s = s;
        unsigned int c = (unsigned int)*s;
        if (c < 0x80)
        {
            s += 1;
        }
        else
        {
            s += ImTextCharFromUtf8(&c, s, text_end);
            if (c == 0)
                break;
        }

        if (c < 32)
        {
            if (c == '\n')
            {
                text_size.x = ImMax(text_size.x, line_width);
                text_size.y += line_height;
                line_width = 0.0f;
                continue;
            }
            if (c == '\r')
                continue;
        }

        const float char_width = ((int)c < IndexXAdvance.Size ? IndexXAdvance[(int)c] : FallbackXAdvance) * scale;
        if (line_width + char_width >= max_width)
        {
            s = prev_s;
            break;
        }

        line_width += char_width;
    }

    if (text_size.x < line_width)
        text_size.x = line_width;

    if (line_width > 0 || text_size.y == 0.0f)
        text_size.y += line_height;

    if (remaining)
        *remaining = s;

    return text_size;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, -0x68(%rbp)
movq %rdx, %r15
movq %rsi, %rbx
movss %xmm2, -0x34(%rbp)
movss %xmm1, -0x3c(%rbp)
movq %rdi, %r14
testq %rdx, %rdx
movss %xmm0, -0x2c(%rbp)
jne 0x2e7c3
movq %rbx, %rdi
callq 0x7300
movss -0x2c(%rbp), %xmm0
movq %rax, %r15
addq %rbx, %r15
divss (%r14), %xmm0
movss %xmm0, -0x30(%rbp)
leaq 0x58(%r14), %r13
movq %r14, -0x70(%rbp)
leaq 0x50(%r14), %rax
movq %rax, -0x78(%rbp)
xorps %xmm3, %xmm3
xorl %r14d, %r14d
xorps %xmm0, %xmm0
movq %rbx, %r12
movaps %xmm3, -0x50(%rbp)
movaps %xmm0, %xmm4
movq %r12, %rbx
cmpq %r15, %r12
jae 0x2e952
movss -0x34(%rbp), %xmm0
ucomiss 0x7ba8(%rip), %xmm0     # 0x363b0
movaps %xmm4, -0x60(%rbp)
jbe 0x2e84e
testq %r14, %r14
jne 0x2e845
movss -0x34(%rbp), %xmm1
subss %xmm4, %xmm1
movq -0x70(%rbp), %rdi
movss -0x30(%rbp), %xmm0
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2e5d2
movaps -0x60(%rbp), %xmm4
movaps -0x50(%rbp), %xmm3
xorl %r14d, %r14d
cmpq %rbx, %rax
sete %r14b
addq %rax, %r14
cmpq %r14, %rbx
jae 0x2e901
movsbl (%rbx), %esi
movl %esi, -0x38(%rbp)
testl %esi, %esi
js 0x2e85e
leaq 0x1(%rbx), %r12
jmp 0x2e886
leaq -0x38(%rbp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x851f
movslq %eax, %r12
addq %rbx, %r12
movl -0x38(%rbp), %esi
testl %esi, %esi
je 0x2e947
movaps -0x50(%rbp), %xmm3
movaps -0x60(%rbp), %xmm4
cmpl $0x1f, %esi
ja 0x2e895
cmpl $0xd, %esi
je 0x2e8cb
cmpl $0xa, %esi
je 0x2e8d6
movq -0x78(%rbp), %rax
cmpl (%r13), %esi
jge 0x2e8af
movq %r13, %rdi
callq 0x1fdf4
movaps -0x60(%rbp), %xmm4
movaps -0x50(%rbp), %xmm3
movss (%rax), %xmm0
mulss -0x30(%rbp), %xmm0
addss %xmm4, %xmm0
ucomiss -0x3c(%rbp), %xmm0
jb 0x2e7ed
jmp 0x2e952
movq %r12, %rbx
movaps %xmm4, %xmm0
jmp 0x2e7e6
movaps %xmm4, %xmm0
cmpless %xmm3, %xmm0
movaps %xmm0, %xmm1
andps %xmm3, %xmm1
andnps %xmm4, %xmm0
orps %xmm1, %xmm0
shufps $0x55, %xmm3, %xmm3     # xmm3 = xmm3[1,1,1,1]
addss -0x2c(%rbp), %xmm3
unpcklps %xmm3, %xmm0            # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movaps %xmm0, %xmm3
movq %r12, %rbx
jmp 0x2e7e3
ucomiss %xmm3, %xmm4
jbe 0x2e90a
movss %xmm4, %xmm3            # xmm3 = xmm4[0],xmm3[1,2,3]
movaps %xmm3, %xmm0
shufps $0x55, %xmm3, %xmm3     # xmm3 = xmm3[1,1,1,1]
addss -0x2c(%rbp), %xmm3
movlhps %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
shufps $0xe2, %xmm0, %xmm3     # xmm3 = xmm3[2,0],xmm0[2,3]
cmpq %r15, %rbx
jae 0x2e7e0
movzbl (%rbx), %eax
cmpl $0x9, %eax
je 0x2e933
cmpl $0x20, %eax
jne 0x2e938
incq %rbx
jmp 0x2e91d
xorl %ecx, %ecx
cmpb $0xa, %al
sete %cl
addq %rcx, %rbx
jmp 0x2e7e0
movq %r12, %rbx
movaps -0x50(%rbp), %xmm3
movaps -0x60(%rbp), %xmm4
movq -0x68(%rbp), %rax
testq %rax, %rax
je 0x2e95e
movq %rbx, (%rax)
ucomiss %xmm3, %xmm4
jbe 0x2e967
movss %xmm4, %xmm3            # xmm3 = xmm4[0],xmm3[1,2,3]
movaps %xmm3, %xmm0
shufps $0x55, %xmm3, %xmm0     # xmm0 = xmm0[1,1],xmm3[1,1]
xorps %xmm1, %xmm1
movaps %xmm0, %xmm2
cmpeqps %xmm1, %xmm2
cmpltps %xmm4, %xmm1
orps %xmm2, %xmm1
movd %xmm1, %eax
testb $0x1, %al
jne 0x2e98c
movaps %xmm3, %xmm0
jmp 0x2e998
addss -0x2c(%rbp), %xmm0
movlhps %xmm3, %xmm0            # xmm0 = xmm0[0],xmm3[0]
shufps $0xe2, %xmm3, %xmm0     # xmm0 = xmm0[2,0],xmm3[2,3]
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq