// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %r13
movss %xmm1, -0x3c(%rbp)
movss %xmm0, -0x2c(%rbp)
movq %rdi, %r14
testq %rdx, %rdx
movss %xmm2, -0x30(%rbp)
jne 0x35474
movq %r13, %rdi
callq 0x72e0
movss -0x30(%rbp), %xmm2
movq %rax, %r15
addq %r13, %r15
movq %rbx, -0x68(%rbp)
cmpq %r13, %r15
jbe 0x35601
movss -0x2c(%rbp), %xmm0
divss (%r14), %xmm0
movss %xmm0, -0x34(%rbp)
leaq 0x50(%r14), %r12
xorps %xmm3, %xmm3
xorps %xmm4, %xmm4
xorl %ebx, %ebx
xorps %xmm5, %xmm5
ucomiss %xmm4, %xmm2
jbe 0x354ef
testq %rbx, %rbx
jne 0x354e6
movaps %xmm2, %xmm1
subss %xmm5, %xmm1
movq %r14, %rdi
movss -0x34(%rbp), %xmm0
movq %r13, %rsi
movq %r15, %rdx
movaps %xmm3, -0x60(%rbp)
movaps %xmm5, -0x50(%rbp)
callq 0x352b2
movaps -0x50(%rbp), %xmm5
xorps %xmm4, %xmm4
movss -0x30(%rbp), %xmm2
movaps -0x60(%rbp), %xmm3
xorl %ebx, %ebx
cmpq %r13, %rax
sete %bl
addq %rax, %rbx
cmpq %rbx, %r13
jae 0x3559a
movsbl (%r13), %ecx
movl %ecx, -0x38(%rbp)
testl %ecx, %ecx
js 0x35501
leaq 0x1(%r13), %rax
jmp 0x35538
movaps %xmm5, -0x50(%rbp)
movaps %xmm3, -0x60(%rbp)
leaq -0x38(%rbp), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x880a
cltq
addq %r13, %rax
movl -0x38(%rbp), %ecx
testl %ecx, %ecx
je 0x3565c
movaps -0x60(%rbp), %xmm3
movss -0x30(%rbp), %xmm2
xorps %xmm4, %xmm4
movaps -0x50(%rbp), %xmm5
cmpl $0x1f, %ecx
ja 0x35572
cmpl $0xd, %ecx
je 0x3556d
cmpl $0xa, %ecx
jne 0x35572
movaps %xmm5, %xmm0
cmpless %xmm3, %xmm0
movaps %xmm0, %xmm1
andps %xmm3, %xmm1
andnps %xmm5, %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]
xorps %xmm5, %xmm5
movaps %xmm0, %xmm3
movaps %xmm5, %xmm0
jmp 0x355f0
movslq %ecx, %rdx
shlq $0x2, %rdx
addq 0x60(%r14), %rdx
cmpl 0x58(%r14), %ecx
cmovgeq %r12, %rdx
movss (%rdx), %xmm0
mulss -0x34(%rbp), %xmm0
addss %xmm5, %xmm0
ucomiss -0x3c(%rbp), %xmm0
jb 0x355f0
jmp 0x35607
ucomiss %xmm3, %xmm5
jbe 0x355a3
movss %xmm5, %xmm3            # xmm3 = xmm5[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]
xorps %xmm0, %xmm0
cmpq %r15, %r13
jae 0x355eb
movq %r15, %rax
subq %r13, %rax
movzbl (%r13), %ecx
cmpl $0x9, %ecx
je 0x355d3
cmpl $0x20, %ecx
jne 0x355e0
incq %r13
decq %rax
jne 0x355c4
movq %r15, %rax
jmp 0x355ee
xorl %eax, %eax
cmpb $0xa, %cl
sete %al
addq %rax, %r13
movq %r13, %rax
xorl %ebx, %ebx
movaps %xmm0, %xmm5
movq %rax, %r13
cmpq %r15, %rax
jb 0x3549f
jmp 0x35607
xorps %xmm5, %xmm5
xorps %xmm3, %xmm3
movq -0x68(%rbp), %rax
testq %rax, %rax
je 0x35613
movq %r13, (%rax)
ucomiss %xmm3, %xmm5
jbe 0x3561c
movss %xmm5, %xmm3            # xmm3 = xmm5[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 %xmm5, %xmm1
orps %xmm2, %xmm1
movd %xmm1, %eax
testb $0x1, %al
jne 0x35641
movaps %xmm3, %xmm0
jmp 0x3564d
addss -0x2c(%rbp), %xmm0
movlhps %xmm3, %xmm0            # xmm0 = xmm0[0],xmm3[0]
shufps $0xe2, %xmm3, %xmm0     # xmm0 = xmm0[2,0],xmm3[2,3]
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r13
movaps -0x60(%rbp), %xmm3
movaps -0x50(%rbp), %xmm5
jmp 0x35607