// File: /workspace/github_cpp_makefile_star2_O3/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:
movq %rsi, %rax
cmpq %rdx, %rsi
jae 0x81a66
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %rbx
movq %rdi, %r14
divss %xmm0, %xmm1
leaq 0x10(%rdi), %rcx
movq %rcx, -0x50(%rbp)
xorps %xmm5, %xmm5
movb $0x1, %r13b
movq $0x0, -0x48(%rbp)
movq %rax, %r15
xorps %xmm3, %xmm3
xorps %xmm4, %xmm4
movss %xmm1, -0x30(%rbp)
movq %rax, %r12
movsbl (%rax), %ecx
movl %ecx, -0x2c(%rbp)
testl %ecx, %ecx
js 0x81939
leaq 0x1(%r12), %rax
jmp 0x81973
leaq -0x2c(%rbp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
movss %xmm3, -0x3c(%rbp)
movss %xmm4, -0x38(%rbp)
movss %xmm5, -0x34(%rbp)
callq 0x40f80
movss -0x34(%rbp), %xmm5
movss -0x38(%rbp), %xmm4
movss -0x3c(%rbp), %xmm3
movss -0x30(%rbp), %xmm1
cltq
addq %r12, %rax
movl -0x2c(%rbp), %ecx
testl %ecx, %ecx
je 0x81a55
cmpl $0x1f, %ecx
ja 0x8198e
cmpl $0xa, %ecx
je 0x819dc
cmpl $0xd, %ecx
je 0x81a2f
movl %ecx, %edx
leaq (,%rdx,4), %rsi
addq 0x8(%r14), %rsi
cmpl (%r14), %ecx
cmovgeq -0x50(%rbp), %rsi
movss (%rsi), %xmm0
cmpl $0x9, %ecx
je 0x819ba
cmpl $0x3000, %ecx           # imm = 0x3000
je 0x819ba
cmpl $0x20, %ecx
jne 0x819ea
testb $0x1, %r13b
je 0x819c4
addss %xmm5, %xmm4
xorps %xmm2, %xmm2
jne 0x819cc
movaps %xmm5, %xmm2
cmovneq %r12, %r15
addss %xmm0, %xmm2
xorl %r13d, %r13d
movaps %xmm2, %xmm5
jmp 0x81a23
movb $0x1, %r13b
xorps %xmm4, %xmm4
xorps %xmm3, %xmm3
xorps %xmm5, %xmm5
jmp 0x81a2f
addss %xmm0, %xmm3
testb $0x1, %r13b
je 0x819f9
movq %rax, %r15
jmp 0x81a0b
addss %xmm3, %xmm5
addss %xmm5, %xmm4
xorps %xmm3, %xmm3
xorps %xmm5, %xmm5
movq %r15, -0x48(%rbp)
cmpl $0x3f, %ecx
ja 0x81a3a
movabsq $-0x77ffaffe00000000, %rsi # imm = 0x8800500200000000
btq %rdx, %rsi
jae 0x81a3a
xorl %r13d, %r13d
movaps %xmm4, %xmm0
addss %xmm3, %xmm0
ucomiss %xmm1, %xmm0
ja 0x81a43
cmpq %rbx, %rax
jb 0x81925
jmp 0x81a58
cmpl $0x22, %ecx
setne %r13b
jmp 0x81a23
movq -0x48(%rbp), %rax
testq %rax, %rax
cmovneq %rax, %r15
ucomiss %xmm3, %xmm1
cmovaq %r15, %r12
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop