// File: /workspace/github_cpp_makefile_star2_O3/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 $0x88, %rsp
movq %r9, %rbx
movq %r8, %r15
movq %rcx, %r14
movq %rdx, %r12
movl %esi, -0x7c(%rbp)
movq %rdi, %r13
testq %r8, %r8
jne 0x30377
movq %r14, %rdi
movss %xmm2, -0x34(%rbp)
movss %xmm0, -0x2c(%rbp)
movaps %xmm1, -0xa0(%rbp)
callq 0x72e0
movaps -0xa0(%rbp), %xmm1
movss -0x2c(%rbp), %xmm0
movss -0x34(%rbp), %xmm2
movq %rax, %r15
addq %r14, %r15
movaps %xmm1, %xmm3
shufps $0x55, %xmm1, %xmm3     # xmm3 = xmm3[1,1],xmm1[1,1]
cvttps2dq %xmm3, %xmm3
cvtdq2ps %xmm3, %xmm3
addss 0xc(%r13), %xmm3
movaps %xmm3, -0x60(%rbp)
ucomiss 0xc(%r12), %xmm3
ja 0x308ad
movss (%r13), %xmm4
divss %xmm4, %xmm0
mulss %xmm0, %xmm4
xorps %xmm3, %xmm3
ucomiss %xmm3, %xmm2
ja 0x303e4
movaps -0x60(%rbp), %xmm3
addss %xmm4, %xmm3
movss 0x4(%r12), %xmm5
ucomiss %xmm3, %xmm5
seta %al
cmpq %r14, %r15
seta %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x303e4
cmpb $0xa, (%r14)
je 0x303e4
incq %r14
cmpq %r15, %r14
jne 0x303d3
movq %r15, %r14
movq 0x40(%rbx), %rax
movq %rax, -0x70(%rbp)
movq 0x48(%rbx), %rax
movq %rax, -0x78(%rbp)
movl 0x38(%rbx), %eax
movq %rax, -0x68(%rbp)
cmpq %r15, %r14
jae 0x30896
cvttps2dq %xmm1, %xmm1
cvtdq2ps %xmm1, %xmm3
addss 0x8(%r13), %xmm3
xorl %ecx, %ecx
xorps %xmm5, %xmm5
movaps %xmm3, %xmm1
movss %xmm0, -0x2c(%rbp)
movss %xmm4, -0x38(%rbp)
movaps %xmm3, -0x90(%rbp)
movss %xmm2, -0x34(%rbp)
movq %r12, -0xa8(%rbp)
movq %r14, %r12
movq %rcx, -0x40(%rbp)
movss %xmm1, -0x30(%rbp)
movaps %xmm1, %xmm7
movaps -0x60(%rbp), %xmm6
ucomiss %xmm5, %xmm2
jbe 0x304ff
testq %rcx, %rcx
jne 0x304ae
movaps %xmm3, %xmm1
subss %xmm7, %xmm1
addss %xmm2, %xmm1
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movss %xmm6, -0xa0(%rbp)
movss %xmm7, -0x80(%rbp)
callq 0x352b2
movss -0x80(%rbp), %xmm7
movss -0xa0(%rbp), %xmm6
xorps %xmm5, %xmm5
movaps -0x90(%rbp), %xmm3
movss -0x38(%rbp), %xmm4
movss -0x2c(%rbp), %xmm0
movss -0x34(%rbp), %xmm2
xorl %ecx, %ecx
cmpq %r12, %rax
sete %cl
addq %rax, %rcx
cmpq %rcx, %r12
jb 0x30506
cmpq %r15, %r12
jae 0x304e5
movq %r15, %rax
subq %r12, %rax
movzbl (%r12), %ecx
cmpl $0x9, %ecx
je 0x304cd
cmpl $0x20, %ecx
jne 0x304da
incq %r12
decq %rax
jne 0x304be
movq %r15, %r12
jmp 0x304e5
xorl %eax, %eax
cmpb $0xa, %cl
sete %al
addq %rax, %r12
addss %xmm4, %xmm6
movl $0x0, %ecx
movaps %xmm3, %xmm7
cmpq %r15, %r12
jb 0x30449
jmp 0x30896
movss -0x30(%rbp), %xmm1
jmp 0x30514
movq %r12, %r14
movaps %xmm7, %xmm1
movaps %xmm6, -0x60(%rbp)
movq %rcx, -0x40(%rbp)
movsbl (%r14), %ecx
movl %ecx, -0x44(%rbp)
testl %ecx, %ecx
movq -0xa8(%rbp), %r12
movss %xmm1, -0x30(%rbp)
js 0x30530
incq %r14
jmp 0x30568
leaq -0x44(%rbp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x880a
xorps %xmm5, %xmm5
movaps -0x90(%rbp), %xmm3
movss -0x38(%rbp), %xmm4
movss -0x34(%rbp), %xmm2
movl -0x44(%rbp), %ecx
testl %ecx, %ecx
je 0x30896
cltq
addq %rax, %r14
movss -0x30(%rbp), %xmm1
cmpl $0x1f, %ecx
ja 0x305a9
cmpl $0xd, %ecx
je 0x3059b
cmpl $0xa, %ecx
jne 0x305a9
movaps -0x60(%rbp), %xmm0
addss %xmm4, %xmm0
movaps %xmm0, -0x60(%rbp)
ucomiss 0xc(%r12), %xmm0
ja 0x30896
ucomiss %xmm5, %xmm2
jbe 0x30661
movaps %xmm3, %xmm1
movss -0x2c(%rbp), %xmm0
movq -0x40(%rbp), %rcx
jmp 0x30653
movzwl %cx, %esi
movq %r13, %rdi
callq 0x34cdc
testq %rax, %rax
je 0x305e6
movss 0x4(%rax), %xmm14
movss -0x2c(%rbp), %xmm0
mulss %xmm0, %xmm14
movl -0x44(%rbp), %ecx
cmpl $0x9, %ecx
movss -0x34(%rbp), %xmm2
movss -0x30(%rbp), %xmm1
je 0x305e0
cmpl $0x20, %ecx
jne 0x305fa
movq -0x40(%rbp), %rcx
jmp 0x3063f
xorps %xmm14, %xmm14
movss -0x34(%rbp), %xmm2
movss -0x2c(%rbp), %xmm0
movq -0x40(%rbp), %rcx
jmp 0x3063a
movss 0x8(%rax), %xmm11
mulss %xmm0, %xmm11
addss %xmm1, %xmm11
movaps %xmm1, %xmm3
movss 0x8(%r12), %xmm1
ucomiss %xmm11, %xmm1
movq -0x40(%rbp), %rcx
jb 0x3063a
movss 0x10(%rax), %xmm9
mulss %xmm0, %xmm9
addss %xmm3, %xmm9
movss (%r12), %xmm13
ucomiss %xmm13, %xmm9
jae 0x306a4
movss -0x30(%rbp), %xmm1
addss %xmm14, %xmm1
movss -0x38(%rbp), %xmm4
movaps -0x90(%rbp), %xmm3
xorps %xmm5, %xmm5
cmpq %r15, %r14
jb 0x30436
jmp 0x30896
movaps %xmm4, %xmm0
addss -0x60(%rbp), %xmm0
movss 0x4(%r12), %xmm1
ucomiss %xmm0, %xmm1
movss -0x2c(%rbp), %xmm0
movq -0x40(%rbp), %rcx
jbe 0x3069f
cmpq %r15, %r14
jae 0x3069f
movq %r15, %rax
subq %r14, %rax
cmpb $0xa, (%r14)
je 0x3069f
incq %r14
decq %rax
jne 0x30689
movaps %xmm3, %xmm1
movq %r15, %r14
jmp 0x30653
movaps %xmm3, %xmm1
jmp 0x30653
movss 0xc(%rax), %xmm10
mulss %xmm0, %xmm10
movaps -0x60(%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 0x3071f
ucomiss %xmm11, %xmm13
jbe 0x30730
movaps %xmm9, %xmm8
subss %xmm13, %xmm8
movaps %xmm9, %xmm12
subss %xmm11, %xmm12
divss %xmm12, %xmm8
movss 0xcc8b(%rip), %xmm11    # 0x3d390
subss %xmm8, %xmm11
movaps %xmm6, %xmm8
subss %xmm3, %xmm8
mulss %xmm11, %xmm8
addss %xmm8, %xmm3
jmp 0x30734
movaps %xmm10, %xmm8
movaps %xmm11, %xmm13
movaps %xmm9, %xmm1
jmp 0x307ec
movaps %xmm11, %xmm13
movss 0x4(%r12), %xmm8
ucomiss %xmm10, %xmm8
jbe 0x3077b
movaps %xmm5, %xmm11
subss %xmm8, %xmm11
movaps %xmm5, %xmm12
subss %xmm10, %xmm12
divss %xmm12, %xmm11
movss 0xcc2f(%rip), %xmm10    # 0x3d390
subss %xmm11, %xmm10
movaps %xmm4, %xmm11
subss %xmm7, %xmm11
mulss %xmm10, %xmm11
addss %xmm11, %xmm7
jmp 0x3077f
movaps %xmm10, %xmm8
ucomiss %xmm1, %xmm9
jbe 0x307a7
movaps %xmm1, %xmm10
subss %xmm13, %xmm10
subss %xmm13, %xmm9
divss %xmm9, %xmm10
subss %xmm3, %xmm6
mulss %xmm10, %xmm6
addss %xmm3, %xmm6
jmp 0x307ab
movaps %xmm9, %xmm1
movss 0xc(%r12), %xmm9
ucomiss %xmm9, %xmm5
jbe 0x307de
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 0x307e2
movaps %xmm5, %xmm9
ucomiss %xmm9, %xmm8
jae 0x3063a
movq -0x78(%rbp), %rcx
movq -0x68(%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 -0x70(%rbp), %rdx
movss %xmm13, (%rdx)
movss %xmm8, 0x4(%rdx)
movl -0x7c(%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, -0x70(%rbp)
addl $0x4, %esi
movq %rsi, -0x68(%rbp)
addq $0xc, %rcx
movq %rcx, -0x78(%rbp)
jmp 0x305f4
movq -0x70(%rbp), %rax
movq %rax, 0x40(%rbx)
movq -0x68(%rbp), %rax
movl %eax, 0x38(%rbx)
movq -0x78(%rbp), %rax
movq %rax, 0x48(%rbx)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop