// File: /workspace/github_cpp_makefile_star2_O2/donfreiday[P]gb/./imgui/imgui_draw.cpp
// Function: ImFont::RenderText(float, ImVec2, unsigned int, ImVec4 const&, char const*, char const*, ImDrawList*, float, bool) const
void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, ImDrawList* draw_list, float wrap_width, bool cpu_fine_clip) const
{
    if (!text_end)
        text_end = text_begin + strlen(text_begin);

    // Align to be pixel perfect
    pos.x = (float)(int)pos.x + DisplayOffset.x;
    pos.y = (float)(int)pos.y + DisplayOffset.y;
    float x = pos.x;
    float y = pos.y;
    if (y > clip_rect.w)
        return;

    const float scale = size / FontSize;
    const float line_height = FontSize * scale;
    const bool word_wrap_enabled = (wrap_width > 0.0f);
    const char* word_wrap_eol = NULL;

    ImDrawVert* vtx_write = draw_list->_VtxWritePtr;
    ImDrawIdx* idx_write = draw_list->_IdxWritePtr;
    unsigned int vtx_current_idx = draw_list->_VtxCurrentIdx;

    const char* s = text_begin;
    if (!word_wrap_enabled && y + line_height < clip_rect.y)
        while (s < text_end && *s != '\n')  // Fast-forward to next line
            s++;
    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 - (x - pos.x));
                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)
            {
                x = pos.x;
                y += line_height;
                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
        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')
            {
                x = pos.x;
                y += line_height;

                if (y > clip_rect.w)
                    break;
                if (!word_wrap_enabled && y + line_height < clip_rect.y)
                    while (s < text_end && *s != '\n')  // Fast-forward to next line
                        s++;
                continue;
            }
            if (c == '\r')
                continue;
        }

        float char_width = 0.0f;
        if (const Glyph* glyph = FindGlyph((unsigned short)c))
        {
            char_width = glyph->XAdvance * scale;

            // Clipping on Y is more likely
            if (c != ' ' && c != '\t')
            {
                // We don't do a second finer clipping test on the Y axis (TODO: do some measurement see if it is worth it, probably not)
                float y1 = (float)(y + glyph->Y0 * scale);
                float y2 = (float)(y + glyph->Y1 * scale);

                float x1 = (float)(x + glyph->X0 * scale);
                float x2 = (float)(x + glyph->X1 * scale);
                if (x1 <= clip_rect.z && x2 >= clip_rect.x)
                {
                    // Render a character
                    float u1 = glyph->U0;
                    float v1 = glyph->V0;
                    float u2 = glyph->U1;
                    float v2 = glyph->V1;

                    // CPU side clipping used to fit text in their frame when the frame is too small. Only does clipping for axis aligned quads.
                    if (cpu_fine_clip)
                    {
                        if (x1 < clip_rect.x)
                        {
                            u1 = u1 + (1.0f - (x2 - clip_rect.x) / (x2 - x1)) * (u2 - u1);
                            x1 = clip_rect.x;
                        }
                        if (y1 < clip_rect.y)
                        {
                            v1 = v1 + (1.0f - (y2 - clip_rect.y) / (y2 - y1)) * (v2 - v1);
                            y1 = clip_rect.y;
                        }
                        if (x2 > clip_rect.z)
                        {
                            u2 = u1 + ((clip_rect.z - x1) / (x2 - x1)) * (u2 - u1);
                            x2 = clip_rect.z;
                        }
                        if (y2 > clip_rect.w)
                        {
                            v2 = v1 + ((clip_rect.w - y1) / (y2 - y1)) * (v2 - v1);
                            y2 = clip_rect.w;
                        }
                        if (y1 >= y2)
                        {
                            x += char_width;
                            continue;
                        }
                    }

                    // NB: we are not calling PrimRectUV() here because non-inlined causes too much overhead in a debug build.
                    // inlined:
                    {
                        idx_write[0] = (ImDrawIdx)(vtx_current_idx); idx_write[1] = (ImDrawIdx)(vtx_current_idx+1); idx_write[2] = (ImDrawIdx)(vtx_current_idx+2);
                        idx_write[3] = (ImDrawIdx)(vtx_current_idx); idx_write[4] = (ImDrawIdx)(vtx_current_idx+2); idx_write[5] = (ImDrawIdx)(vtx_current_idx+3);
                        vtx_write[0].pos.x = x1; vtx_write[0].pos.y = y1; vtx_write[0].col = col; vtx_write[0].uv.x = u1; vtx_write[0].uv.y = v1;
                        vtx_write[1].pos.x = x2; vtx_write[1].pos.y = y1; vtx_write[1].col = col; vtx_write[1].uv.x = u2; vtx_write[1].uv.y = v1;
                        vtx_write[2].pos.x = x2; vtx_write[2].pos.y = y2; vtx_write[2].col = col; vtx_write[2].uv.x = u2; vtx_write[2].uv.y = v2;
                        vtx_write[3].pos.x = x1; vtx_write[3].pos.y = y2; vtx_write[3].col = col; vtx_write[3].uv.x = u1; vtx_write[3].uv.y = v2;
                        vtx_write += 4;
                        vtx_current_idx += 4;
                        idx_write += 6;
                    }
                }
            }
        }

        x += char_width;
    }

    draw_list->_VtxWritePtr = vtx_write;
    draw_list->_VtxCurrentIdx = vtx_current_idx;
    draw_list->_IdxWritePtr = idx_write;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, %rbx
movq %r8, %r13
movq %rcx, %r14
movq %rdx, %r12
movl %esi, -0x6c(%rbp)
movq %rdi, %r15
testq %r8, %r8
movss %xmm2, -0x38(%rbp)
jne 0x29fa0
movq %r14, %rdi
movss %xmm0, -0x30(%rbp)
movaps %xmm1, -0x90(%rbp)
callq 0x7300
movaps -0x90(%rbp), %xmm1
movss -0x30(%rbp), %xmm0
movss -0x38(%rbp), %xmm2
movq %rax, %r13
addq %r14, %r13
movaps %xmm1, %xmm3
shufps $0x55, %xmm1, %xmm3     # xmm3 = xmm3[1,1],xmm1[1,1]
cvttps2dq %xmm3, %xmm3
cvtdq2ps %xmm3, %xmm3
addss 0xc(%r15), %xmm3
movaps %xmm3, -0x50(%rbp)
ucomiss 0xc(%r12), %xmm3
ja 0x2a4b8
cvttps2dq %xmm1, %xmm1
cvtdq2ps %xmm1, %xmm4
movss (%r15), %xmm5
divss %xmm5, %xmm0
mulss %xmm0, %xmm5
xorps %xmm6, %xmm6
ucomiss %xmm6, %xmm2
ja 0x2a004
movaps -0x50(%rbp), %xmm3
addss %xmm5, %xmm3
movss 0x4(%r12), %xmm1
ucomiss %xmm3, %xmm1
jbe 0x2a004
cmpq %r13, %r14
jae 0x2a004
cmpb $0xa, (%r14)
je 0x2a004
incq %r14
jmp 0x29ff4
movq %r12, -0xa0(%rbp)
addss 0x8(%r15), %xmm4
movq 0x40(%rbx), %rax
movq %rax, -0x60(%rbp)
movq 0x48(%rbx), %rax
movq %rax, -0x68(%rbp)
movq %rbx, -0x98(%rbp)
movl 0x38(%rbx), %eax
movq %rax, -0x58(%rbp)
xorl %edi, %edi
movaps %xmm4, %xmm3
movss %xmm0, -0x30(%rbp)
movaps %xmm4, -0x80(%rbp)
movss %xmm5, -0x34(%rbp)
movaps -0x50(%rbp), %xmm1
movss %xmm3, -0x2c(%rbp)
movq %rdi, %rbx
movq %rdi, %rcx
movq %r14, %r12
cmpq %r13, %r12
jae 0x2a49a
ucomiss %xmm6, %xmm2
jbe 0x2a104
testq %rcx, %rcx
jne 0x2a0bf
movss %xmm1, -0x90(%rbp)
movaps %xmm4, %xmm1
subss %xmm3, %xmm1
addss %xmm2, %xmm1
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movss %xmm3, -0x70(%rbp)
callq 0x2e5d2
movss -0x70(%rbp), %xmm3
movss -0x90(%rbp), %xmm1
xorps %xmm6, %xmm6
movss -0x34(%rbp), %xmm5
movaps -0x80(%rbp), %xmm4
movss -0x30(%rbp), %xmm0
movss -0x38(%rbp), %xmm2
xorl %ecx, %ecx
cmpq %r12, %rax
sete %cl
addq %rax, %rcx
cmpq %rcx, %r12
jb 0x2a0f5
addss %xmm5, %xmm1
cmpq %r13, %r12
jae 0x2a0eb
movzbl (%r12), %eax
cmpl $0x9, %eax
je 0x2a0dc
cmpl $0x20, %eax
jne 0x2a0e1
incq %r12
jmp 0x2a0c8
xorl %ecx, %ecx
cmpb $0xa, %al
sete %cl
addq %rcx, %r12
movaps %xmm4, %xmm3
xorl %ecx, %ecx
jmp 0x2a054
movaps %xmm1, -0x50(%rbp)
movss %xmm3, -0x2c(%rbp)
movq %r12, %r14
movq %rcx, %rbx
movsbl (%r14), %ecx
movl %ecx, -0x3c(%rbp)
testl %ecx, %ecx
movq -0xa0(%rbp), %r12
js 0x2a11b
incq %r14
jmp 0x2a14b
leaq -0x3c(%rbp), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x851f
xorps %xmm6, %xmm6
movss -0x34(%rbp), %xmm5
movaps -0x80(%rbp), %xmm4
movss -0x38(%rbp), %xmm2
movl -0x3c(%rbp), %ecx
testl %ecx, %ecx
je 0x2a49a
cltq
addq %rax, %r14
cmpl $0x1f, %ecx
ja 0x2a18a
cmpl $0xd, %ecx
je 0x2a180
cmpl $0xa, %ecx
jne 0x2a18a
movaps -0x50(%rbp), %xmm0
addss %xmm5, %xmm0
movaps %xmm0, -0x50(%rbp)
ucomiss 0xc(%r12), %xmm0
ja 0x2a49a
ucomiss %xmm6, %xmm2
jbe 0x2a24f
movss %xmm4, -0x2c(%rbp)
movss -0x30(%rbp), %xmm0
jmp 0x2a242
movzwl %cx, %esi
movq %r15, %rdi
callq 0x2e20c
testq %rax, %rax
je 0x2a219
movss 0x4(%rax), %xmm14
movss -0x30(%rbp), %xmm0
mulss %xmm0, %xmm14
movl -0x3c(%rbp), %ecx
cmpl $0x9, %ecx
movss -0x38(%rbp), %xmm2
movss -0x2c(%rbp), %xmm3
je 0x2a22c
cmpl $0x20, %ecx
je 0x2a22c
movss 0x8(%rax), %xmm11
mulss %xmm0, %xmm11
addss %xmm3, %xmm11
movss 0x8(%r12), %xmm1
ucomiss %xmm11, %xmm1
jb 0x2a1fe
movss 0x10(%rax), %xmm9
mulss %xmm0, %xmm9
addss %xmm3, %xmm9
movss (%r12), %xmm13
ucomiss %xmm13, %xmm9
jae 0x2a289
movq %rbx, %rdi
addss %xmm14, %xmm3
movss %xmm3, -0x2c(%rbp)
movaps -0x80(%rbp), %xmm4
movss -0x34(%rbp), %xmm5
xorps %xmm6, %xmm6
jmp 0x2a245
xorps %xmm14, %xmm14
movss -0x38(%rbp), %xmm2
movss -0x30(%rbp), %xmm0
movss -0x2c(%rbp), %xmm3
addss %xmm14, %xmm3
movss %xmm3, -0x2c(%rbp)
movaps -0x80(%rbp), %xmm4
movss -0x34(%rbp), %xmm5
xorps %xmm6, %xmm6
movq %rbx, %rdi
movss -0x2c(%rbp), %xmm3
jmp 0x2a042
movaps %xmm5, %xmm0
addss -0x50(%rbp), %xmm0
movss 0x4(%r12), %xmm1
ucomiss %xmm0, %xmm1
movss -0x30(%rbp), %xmm0
jbe 0x2a27b
movq %rbx, %rdi
cmpq %r13, %r14
jae 0x2a282
cmpb $0xa, (%r14)
je 0x2a282
incq %r14
jmp 0x2a26b
movss %xmm4, -0x2c(%rbp)
jmp 0x2a242
movss %xmm4, -0x2c(%rbp)
jmp 0x2a245
movss 0xc(%rax), %xmm10
mulss %xmm0, %xmm10
movaps -0x50(%rbp), %xmm3
addss %xmm3, %xmm10
movss 0x14(%rax), %xmm5
mulss %xmm0, %xmm5
addss %xmm3, %xmm5
movss 0x18(%rax), %xmm3
movss 0x1c(%rax), %xmm7
movss 0x20(%rax), %xmm6
movss 0x24(%rax), %xmm4
cmpb $0x0, 0x10(%rbp)
je 0x2a304
ucomiss %xmm11, %xmm13
jbe 0x2a318
movaps %xmm9, %xmm8
subss %xmm13, %xmm8
movaps %xmm9, %xmm12
subss %xmm11, %xmm12
divss %xmm12, %xmm8
movss 0xc0a6(%rip), %xmm11    # 0x36390
subss %xmm8, %xmm11
movaps %xmm6, %xmm8
subss %xmm3, %xmm8
mulss %xmm11, %xmm8
addss %xmm8, %xmm3
jmp 0x2a31c
movaps %xmm10, %xmm8
movaps %xmm11, %xmm13
movaps %xmm9, %xmm1
movq %rbx, %rdi
jmp 0x2a3d7
movaps %xmm11, %xmm13
movss 0x4(%r12), %xmm8
ucomiss %xmm10, %xmm8
jbe 0x2a363
movaps %xmm5, %xmm11
subss %xmm8, %xmm11
movaps %xmm5, %xmm12
subss %xmm10, %xmm12
divss %xmm12, %xmm11
movss 0xc047(%rip), %xmm10    # 0x36390
subss %xmm11, %xmm10
movaps %xmm4, %xmm11
subss %xmm7, %xmm11
mulss %xmm10, %xmm11
addss %xmm11, %xmm7
jmp 0x2a367
movaps %xmm10, %xmm8
ucomiss %xmm1, %xmm9
jbe 0x2a38f
movaps %xmm1, %xmm10
subss %xmm13, %xmm10
subss %xmm13, %xmm9
divss %xmm9, %xmm10
subss %xmm3, %xmm6
mulss %xmm10, %xmm6
addss %xmm3, %xmm6
jmp 0x2a393
movaps %xmm9, %xmm1
movss 0xc(%r12), %xmm9
ucomiss %xmm9, %xmm5
jbe 0x2a3c6
movaps %xmm9, %xmm10
subss %xmm8, %xmm10
subss %xmm8, %xmm5
divss %xmm5, %xmm10
subss %xmm7, %xmm4
mulss %xmm10, %xmm4
addss %xmm7, %xmm4
movaps %xmm9, %xmm5
jmp 0x2a3ca
movaps %xmm5, %xmm9
movq %rbx, %rdi
ucomiss %xmm9, %xmm8
jae 0x2a486
movq -0x68(%rbp), %rcx
movq -0x58(%rbp), %rsi
movw %si, (%rcx)
leal 0x1(%rsi), %eax
movw %ax, 0x2(%rcx)
leal 0x2(%rsi), %eax
movw %ax, 0x4(%rcx)
movw %si, 0x6(%rcx)
movw %ax, 0x8(%rcx)
leal 0x3(%rsi), %eax
movw %ax, 0xa(%rcx)
movq -0x60(%rbp), %rdx
movss %xmm13, (%rdx)
movss %xmm8, 0x4(%rdx)
movl -0x6c(%rbp), %eax
movl %eax, 0x10(%rdx)
movss %xmm3, 0x8(%rdx)
movss %xmm7, 0xc(%rdx)
movss %xmm1, 0x14(%rdx)
movss %xmm8, 0x18(%rdx)
movl %eax, 0x24(%rdx)
movss %xmm6, 0x1c(%rdx)
movss %xmm7, 0x20(%rdx)
movss %xmm1, 0x28(%rdx)
movss %xmm5, 0x2c(%rdx)
movl %eax, 0x38(%rdx)
movss %xmm6, 0x30(%rdx)
movss %xmm4, 0x34(%rdx)
movss %xmm13, 0x3c(%rdx)
movss %xmm5, 0x40(%rdx)
movl %eax, 0x4c(%rdx)
movss %xmm3, 0x44(%rdx)
movss %xmm4, 0x48(%rdx)
addq $0x50, %rdx
movq %rdx, -0x60(%rbp)
addl $0x4, %esi
movq %rsi, -0x58(%rbp)
addq $0xc, %rcx
movq %rcx, -0x68(%rbp)
movss -0x2c(%rbp), %xmm3
jmp 0x2a201
movss -0x2c(%rbp), %xmm1
addss %xmm14, %xmm1
movss %xmm1, -0x2c(%rbp)
jmp 0x2a20b
movq -0x60(%rbp), %rax
movq -0x98(%rbp), %rcx
movq %rax, 0x40(%rcx)
movq -0x58(%rbp), %rax
movl %eax, 0x38(%rcx)
movq -0x68(%rbp), %rax
movq %rax, 0x48(%rcx)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop