// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/include/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 (ImCharIsBlankA(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) // Malformed UTF-8?
                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 < IndexAdvanceX.Size ? IndexAdvanceX.Data[c] : FallbackAdvanceX) * 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 0x81aac
movq %r13, %rdi
callq 0xc350
movss -0x30(%rbp), %xmm2
movq %rax, %r15
addq %r13, %r15
movq %rbx, -0x68(%rbp)
cmpq %r13, %r15
jbe 0x81c3a
movss -0x2c(%rbp), %xmm0
divss 0x14(%r14), %xmm0
movss %xmm0, -0x34(%rbp)
leaq 0x10(%r14), %r12
xorps %xmm3, %xmm3
xorps %xmm4, %xmm4
xorl %ebx, %ebx
xorps %xmm5, %xmm5
ucomiss %xmm4, %xmm2
jbe 0x81b28
testq %rbx, %rbx
jne 0x81b1f
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 0x818da
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 0x81bd1
movsbl (%r13), %ecx
movl %ecx, -0x38(%rbp)
testl %ecx, %ecx
js 0x81b3a
leaq 0x1(%r13), %rax
jmp 0x81b71
movaps %xmm5, -0x50(%rbp)
movaps %xmm3, -0x60(%rbp)
leaq -0x38(%rbp), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x40f80
cltq
addq %r13, %rax
movl -0x38(%rbp), %ecx
testl %ecx, %ecx
je 0x81c95
movaps -0x60(%rbp), %xmm3
movss -0x30(%rbp), %xmm2
xorps %xmm4, %xmm4
movaps -0x50(%rbp), %xmm5
cmpl $0x1f, %ecx
ja 0x81bab
cmpl $0xd, %ecx
je 0x81ba6
cmpl $0xa, %ecx
jne 0x81bab
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 0x81c29
movl %ecx, %edx
shlq $0x2, %rdx
addq 0x8(%r14), %rdx
cmpl (%r14), %ecx
cmovgeq %r12, %rdx
movss (%rdx), %xmm0
mulss -0x34(%rbp), %xmm0
addss %xmm5, %xmm0
ucomiss -0x3c(%rbp), %xmm0
jb 0x81c29
jmp 0x81c40
ucomiss %xmm3, %xmm5
jbe 0x81bda
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 0x81c17
movq %r15, %rax
subq %r13, %rax
movzbl (%r13), %ecx
cmpl $0x20, %ecx
je 0x81c0a
cmpl $0x9, %ecx
jne 0x81c1c
incq %r13
decq %rax
jne 0x81bfb
movq %r15, %rax
jmp 0x81c27
movq %r13, %rax
jmp 0x81c27
leaq 0x1(%r13), %rax
cmpb $0xa, %cl
cmovneq %r13, %rax
xorl %ebx, %ebx
movaps %xmm0, %xmm5
movq %rax, %r13
cmpq %r15, %rax
jb 0x81ad8
jmp 0x81c40
xorps %xmm5, %xmm5
xorps %xmm3, %xmm3
movq -0x68(%rbp), %rax
testq %rax, %rax
je 0x81c4c
movq %r13, (%rax)
ucomiss %xmm3, %xmm5
jbe 0x81c55
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 0x81c7a
movaps %xmm3, %xmm0
jmp 0x81c86
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 0x81c40