// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movq %rsi, %r15
movq %rdi, %r14
divss %xmm0, %xmm1
leaq 0x10(%rdi), %rax
movq %rax, -0x50(%rbp)
movb $0x1, %r12b
xorps %xmm3, %xmm3
movq $0x0, -0x48(%rbp)
xorps %xmm4, %xmm4
xorps %xmm5, %xmm5
movq %rsi, %r13
movss %xmm1, -0x30(%rbp)
cmpq %rbx, %r13
jae 0x8358a
movsbl (%r13), %ecx
movl %ecx, -0x2c(%rbp)
movl $0x1, %eax
testl %ecx, %ecx
jns 0x83494
leaq -0x2c(%rbp), %rdi
movq %r13, %rsi
movq %rbx, %rdx
movss %xmm3, -0x3c(%rbp)
movss %xmm4, -0x38(%rbp)
movss %xmm5, -0x34(%rbp)
callq 0x41855
movss -0x34(%rbp), %xmm5
movss -0x38(%rbp), %xmm4
movss -0x3c(%rbp), %xmm3
movss -0x30(%rbp), %xmm1
cltq
movl -0x2c(%rbp), %edx
movb $0x1, %cl
testq %rdx, %rdx
je 0x8356d
addq %r13, %rax
cmpl $0x1f, %edx
ja 0x834b9
cmpq $0xa, %rdx
je 0x83506
cmpl $0xd, %edx
je 0x83572
leaq (,%rdx,4), %rsi
addq 0x8(%r14), %rsi
cmpl (%r14), %edx
cmovgeq -0x50(%rbp), %rsi
movss (%rsi), %xmm0
cmpq $0x9, %rdx
je 0x834e4
cmpl $0x20, %edx
je 0x834e4
cmpl $0x3000, %edx           # imm = 0x3000
jne 0x83516
testb $0x1, %r12b
je 0x834ee
addss %xmm5, %xmm3
xorps %xmm2, %xmm2
jne 0x834f6
movaps %xmm5, %xmm2
cmovneq %r13, %r15
addss %xmm0, %xmm2
xorl %r12d, %r12d
movaps %xmm2, %xmm5
jmp 0x8354f
movb $0x1, %r12b
xorps %xmm3, %xmm3
xorl %ecx, %ecx
xorps %xmm4, %xmm4
xorps %xmm5, %xmm5
jmp 0x83574
addss %xmm0, %xmm4
testb $0x1, %r12b
je 0x83525
movq %rax, %r15
jmp 0x83537
addss %xmm4, %xmm5
addss %xmm5, %xmm3
xorps %xmm4, %xmm4
xorps %xmm5, %xmm5
movq %r15, -0x48(%rbp)
cmpl $0x3f, %edx
ja 0x83581
movabsq $-0x77ffaffe00000000, %rsi # imm = 0x8800500200000000
btq %rdx, %rsi
jae 0x83581
xorl %r12d, %r12d
movaps %xmm3, %xmm0
addss %xmm4, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x83572
movq -0x48(%rbp), %rax
testq %rax, %rax
cmoveq %r15, %rax
ucomiss %xmm4, %xmm1
cmovaq %rax, %r13
movq %r13, %rax
jmp 0x83574
xorl %ecx, %ecx
movq %rax, %r13
testb %cl, %cl
je 0x83446
jmp 0x8358d
cmpl $0x22, %edx
setne %r12b
jmp 0x8354f
movq %r13, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq