// File: /workspace/github_cpp_makefile_star2_O2/Ciaxur[P]yagb-emu/include/imgui/imgui_draw.cpp
// Function: ImFont::CalcWordWrapPositionA(float, char const*, char const*, float) const
const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const
{
    // Simple word-wrapping for English, not full-featured. Please submit failing cases!
    // FIXME: Much possible improvements (don't cut things like "word !", "word!!!" but cut within "word,,,,", more sensible support for punctuations, support for Unicode punctuations, etc.)

    // For references, possible wrap point marked with ^
    //  "aaa bbb, ccc,ddd. eee   fff. ggg!"
    //      ^    ^    ^   ^   ^__    ^    ^

    // List of hardcoded separators: .,;!?'"

    // Skip extra blanks after a line returns (that includes not counting them in width computation)
    // e.g. "Hello    world" --> "Hello" "World"

    // Cut words that cannot possibly fit within one line.
    // e.g.: "The tropical fish" with ~5 characters worth of width --> "The tr" "opical" "fish"

    float line_width = 0.0f;
    float word_width = 0.0f;
    float blank_width = 0.0f;
    wrap_width /= scale; // We work with unscaled widths to avoid scaling every characters

    const char* word_end = text;
    const char* prev_word_end = NULL;
    bool inside_word = true;

    const char* s = text;
    while (s < text_end)
    {
        unsigned int c = (unsigned int)*s;
        const char* next_s;
        if (c < 0x80)
            next_s = s + 1;
        else
            next_s = s + ImTextCharFromUtf8(&c, s, text_end);
        if (c == 0)
            break;

        if (c < 32)
        {
            if (c == '\n')
            {
                line_width = word_width = blank_width = 0.0f;
                inside_word = true;
                s = next_s;
                continue;
            }
            if (c == '\r')
            {
                s = next_s;
                continue;
            }
        }

        const float char_width = ((int)c < IndexAdvanceX.Size ? IndexAdvanceX.Data[c] : FallbackAdvanceX);
        if (ImCharIsBlankW(c))
        {
            if (inside_word)
            {
                line_width += blank_width;
                blank_width = 0.0f;
                word_end = s;
            }
            blank_width += char_width;
            inside_word = false;
        }
        else
        {
            word_width += char_width;
            if (inside_word)
            {
                word_end = next_s;
            }
            else
            {
                prev_word_end = word_end;
                line_width += word_width + blank_width;
                word_width = blank_width = 0.0f;
            }

            // Allow wrapping after punctuation.
            inside_word = (c != '.' && c != ',' && c != ';' && c != '!' && c != '?' && c != '\"');
        }

        // We ignore blank width at the end of the line (they can be skipped)
        if (line_width + word_width > wrap_width)
        {
            // Words that cannot possibly fit within an entire line will be cut anywhere.
            if (word_width < wrap_width)
                s = prev_word_end ? prev_word_end : word_end;
            break;
        }

        s = next_s;
    }

    return s;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
divss %xmm0, %xmm1
movss %xmm1, -0x2c(%rbp)
leaq 0x10(%rdi), %rax
movq %rax, -0x50(%rbp)
movb $0x1, %r12b
xorps %xmm2, %xmm2
movq $0x0, -0x48(%rbp)
xorps %xmm3, %xmm3
xorps %xmm4, %xmm4
movq %rsi, %r13
cmpq %r14, %r13
jae 0x6b557
movsbl (%r13), %ecx
movl %ecx, -0x30(%rbp)
testl %ecx, %ecx
js 0x6b43d
leaq 0x1(%r13), %rax
jmp 0x6b472
leaq -0x30(%rbp), %rdi
movq %r13, %rsi
movq %r14, %rdx
movss %xmm2, -0x3c(%rbp)
movss %xmm3, -0x38(%rbp)
movss %xmm4, -0x34(%rbp)
callq 0x33a81
movss -0x34(%rbp), %xmm4
movss -0x38(%rbp), %xmm3
movss -0x3c(%rbp), %xmm2
cltq
addq %r13, %rax
movl -0x30(%rbp), %ecx
testl %ecx, %ecx
je 0x6b557
cmpl $0x1f, %ecx
ja 0x6b48d
cmpl $0xa, %ecx
je 0x6b4db
cmpl $0xd, %ecx
je 0x6b52f
movl %ecx, %edx
leaq (,%rdx,4), %rsi
addq 0x8(%r15), %rsi
cmpl (%r15), %ecx
cmovgeq -0x50(%rbp), %rsi
movss (%rsi), %xmm0
cmpl $0x9, %ecx
je 0x6b4b9
cmpl $0x3000, %ecx           # imm = 0x3000
je 0x6b4b9
cmpl $0x20, %ecx
jne 0x6b4e9
testb $0x1, %r12b
je 0x6b4c3
addss %xmm4, %xmm2
xorps %xmm1, %xmm1
jne 0x6b4cb
movaps %xmm4, %xmm1
cmovneq %r13, %rbx
addss %xmm0, %xmm1
xorl %r12d, %r12d
movaps %xmm1, %xmm4
jmp 0x6b522
movb $0x1, %r12b
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
xorps %xmm4, %xmm4
jmp 0x6b52f
addss %xmm0, %xmm3
testb $0x1, %r12b
je 0x6b4f8
movq %rax, %rbx
jmp 0x6b50a
addss %xmm3, %xmm4
addss %xmm4, %xmm2
xorps %xmm3, %xmm3
xorps %xmm4, %xmm4
movq %rbx, -0x48(%rbp)
cmpl $0x3f, %ecx
ja 0x6b537
movabsq $-0x77ffaffe00000000, %rsi # imm = 0x8800500200000000
btq %rdx, %rsi
jae 0x6b537
xorl %r12d, %r12d
movaps %xmm2, %xmm0
addss %xmm3, %xmm0
ucomiss -0x2c(%rbp), %xmm0
ja 0x6b540
movq %rax, %r13
jmp 0x6b422
cmpl $0x22, %ecx
setne %r12b
jmp 0x6b522
movq -0x48(%rbp), %rax
testq %rax, %rax
cmovneq %rax, %rbx
movss -0x2c(%rbp), %xmm0
ucomiss %xmm3, %xmm0
cmovaq %rbx, %r13
movq %r13, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop