// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/include/imgui/imgui_draw.cpp
// Function: ImFont::RenderText(ImDrawList*, float, ImVec2, unsigned int, ImVec4 const&, char const*, char const*, float, bool) const
void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width, bool cpu_fine_clip) const
{
    if (!text_end)
        text_end = text_begin + strlen(text_begin); // ImGui:: functions generally already provides a valid text_end, so this is merely to handle direct calls.

    // Align to be pixel perfect
    pos.x = IM_FLOOR(pos.x);
    pos.y = IM_FLOOR(pos.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;

    // Fast-forward to first visible line
    const char* s = text_begin;
    if (y + line_height < clip_rect.y && !word_wrap_enabled)
        while (y + line_height < clip_rect.y && s < text_end)
        {
            s = (const char*)memchr(s, '\n', text_end - s);
            s = s ? s + 1 : text_end;
            y += line_height;
        }

    // For large text, scan for the last visible line in order to avoid over-reserving in the call to PrimReserve()
    // Note that very large horizontal line will still be affected by the issue (e.g. a one megabyte string buffer without a newline will likely crash atm)
    if (text_end - s > 10000 && !word_wrap_enabled)
    {
        const char* s_end = s;
        float y_end = y;
        while (y_end < clip_rect.w && s_end < text_end)
        {
            s_end = (const char*)memchr(s_end, '\n', text_end - s_end);
            s_end = s_end ? s_end + 1 : text_end;
            y_end += line_height;
        }
        text_end = s_end;
    }
    if (s == text_end)
        return;

    // Reserve vertices for remaining worse case (over-reserving is useful and easily amortized)
    const int vtx_count_max = (int)(text_end - s) * 4;
    const int idx_count_max = (int)(text_end - s) * 6;
    const int idx_expected_size = draw_list->IdxBuffer.Size + idx_count_max;
    draw_list->PrimReserve(idx_count_max, vtx_count_max);

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

    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 (ImCharIsBlankA(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) // Malformed UTF-8?
                break;
        }

        if (c < 32)
        {
            if (c == '\n')
            {
                x = pos.x;
                y += line_height;
                if (y > clip_rect.w)
                    break; // break out of main loop
                continue;
            }
            if (c == '\r')
                continue;
        }

        const ImFontGlyph* glyph = FindGlyph((ImWchar)c);
        if (glyph == NULL)
            continue;

        float char_width = glyph->AdvanceX * scale;
        if (glyph->Visible)
        {
            // We don't do a second finer clipping test on the Y axis as we've already skipped anything before clip_rect.y and exit once we pass clip_rect.w
            float x1 = x + glyph->X0 * scale;
            float x2 = x + glyph->X1 * scale;
            float y1 = y + glyph->Y0 * scale;
            float y2 = y + glyph->Y1 * 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;
                    }
                }

                // We are NOT calling PrimRectUV() here because non-inlined causes too much overhead in a debug builds. Inlined here:
                {
                    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;
    }

    // Give back unused vertices (clipped ones, blanks) ~ this is essentially a PrimUnreserve() action.
    draw_list->VtxBuffer.Size = (int)(vtx_write - draw_list->VtxBuffer.Data); // Same as calling shrink()
    draw_list->IdxBuffer.Size = (int)(idx_write - draw_list->IdxBuffer.Data);
    draw_list->CmdBuffer[draw_list->CmdBuffer.Size - 1].ElemCount -= (idx_expected_size - draw_list->IdxBuffer.Size);
    draw_list->_VtxWritePtr = vtx_write;
    draw_list->_IdxWritePtr = idx_write;
    draw_list->_VtxCurrentIdx = vtx_current_idx;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r9, %r15
movq %r8, %r13
movq %rcx, %r14
movl %edx, -0x94(%rbp)
movq %rsi, %rbx
movq %rdi, %r12
testq %r9, %r9
movaps %xmm2, -0xb0(%rbp)
jne 0x797fa
movq %r13, %rdi
movss %xmm0, -0x2c(%rbp)
movaps %xmm1, -0x50(%rbp)
callq 0xc350
movaps -0x50(%rbp), %xmm1
movss -0x2c(%rbp), %xmm0
movaps -0xb0(%rbp), %xmm2
movq %rax, %r15
addq %r13, %r15
movaps %xmm1, %xmm3
shufps $0x55, %xmm1, %xmm3     # xmm3 = xmm3[1,1],xmm1[1,1]
cvttps2dq %xmm3, %xmm3
cvtdq2ps %xmm3, %xmm3
movq %r14, -0x58(%rbp)
movss 0xc(%r14), %xmm4
movss %xmm4, -0x30(%rbp)
ucomiss %xmm4, %xmm3
ja 0x79e3e
movaps %xmm1, -0x50(%rbp)
movss 0x14(%r12), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x2c(%rbp)
mulss %xmm0, %xmm1
movaps %xmm3, %xmm0
movss %xmm1, -0x34(%rbp)
addss %xmm1, %xmm0
movq -0x58(%rbp), %rax
movss 0x4(%rax), %xmm4
xorps %xmm1, %xmm1
cmpltps %xmm2, %xmm1
movaps %xmm0, %xmm2
movaps %xmm4, -0xc0(%rbp)
cmpnltps %xmm4, %xmm2
orps %xmm1, %xmm2
movd %xmm2, %eax
cmpq %r13, %r15
setbe %cl
orb %al, %cl
testb $0x1, %cl
jne 0x798b6
movaps %xmm0, -0x70(%rbp)
movq %r15, %rdx
subq %r13, %rdx
movq %r13, %rdi
movl $0xa, %esi
callq 0xc3c0
movaps -0x70(%rbp), %xmm3
leaq 0x1(%rax), %r13
testq %rax, %rax
cmoveq %r15, %r13
movss -0x34(%rbp), %xmm0
addss %xmm3, %xmm0
movaps -0xc0(%rbp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x798b6
cmpq %r15, %r13
jb 0x79876
movaps -0xb0(%rbp), %xmm0
ucomiss 0x3bf80(%rip), %xmm0    # 0xb5844
ja 0x7993e
movq %r15, %rax
subq %r13, %rax
cmpq $0x2711, %rax           # imm = 0x2711
movaps -0x50(%rbp), %xmm0
jl 0x79939
movss -0x30(%rbp), %xmm1
movq %r13, %r14
ucomiss %xmm3, %xmm1
jbe 0x79945
cmpq %r15, %r13
jae 0x79945
movaps %xmm3, -0x70(%rbp)
movq %r13, %r14
movss %xmm3, -0xc0(%rbp)
movq %r15, %rdx
subq %r14, %rdx
movq %r14, %rdi
movl $0xa, %esi
callq 0xc3c0
movss -0xc0(%rbp), %xmm3
leaq 0x1(%rax), %r14
testq %rax, %rax
cmoveq %r15, %r14
addss -0x34(%rbp), %xmm3
movss -0x30(%rbp), %xmm0
ucomiss %xmm3, %xmm0
jbe 0x79933
cmpq %r15, %r14
jb 0x798f1
movaps -0x70(%rbp), %xmm3
jmp 0x79941
movq %r15, %r14
jmp 0x79945
movq %r15, %r14
movaps -0x50(%rbp), %xmm0
cmpq %r14, %r13
je 0x79e3e
movaps %xmm3, -0x70(%rbp)
cvttps2dq %xmm0, %xmm0
cvtdq2ps %xmm0, %xmm0
movaps %xmm0, -0xe0(%rbp)
movl %r14d, %eax
subl %r13d, %eax
leal (,%rax,4), %edx
addl %eax, %eax
leal (%rax,%rax,2), %esi
movl 0x10(%rbx), %eax
movl %eax, -0x90(%rbp)
movq %rbx, %rdi
movl %esi, -0x8c(%rbp)
callq 0x75e52
movaps -0xe0(%rbp), %xmm14
movaps -0xb0(%rbp), %xmm13
movq 0x48(%rbx), %rax
movq %rax, -0x88(%rbp)
movq 0x50(%rbx), %rax
movq %rax, -0x80(%rbp)
movl 0x34(%rbx), %eax
movq %rax, -0x78(%rbp)
movq $0x0, -0xc8(%rbp)
xorps %xmm15, %xmm15
movaps %xmm14, %xmm11
cmpq %r14, %r13
jae 0x79de1
movaps %xmm11, %xmm2
movaps -0x70(%rbp), %xmm0
movq -0xc8(%rbp), %rcx
movq %r13, %r15
movss %xmm11, -0x50(%rbp)
ucomiss %xmm15, %xmm13
jbe 0x79ab9
testq %rcx, %rcx
jne 0x79a55
movaps %xmm14, %xmm1
subss %xmm2, %xmm1
addss %xmm13, %xmm1
movq %r12, %rdi
movss %xmm0, -0xc0(%rbp)
movss -0x2c(%rbp), %xmm0
movq %r15, %rsi
movq %r14, %rdx
movss %xmm2, -0x30(%rbp)
callq 0x818da
movss -0x30(%rbp), %xmm2
movss -0xc0(%rbp), %xmm0
movss -0x50(%rbp), %xmm11
xorps %xmm15, %xmm15
movaps -0xe0(%rbp), %xmm14
movaps -0xb0(%rbp), %xmm13
xorl %ecx, %ecx
cmpq %r15, %rax
sete %cl
addq %rax, %rcx
cmpq %rcx, %r15
jb 0x79aa7
cmpq %r14, %r15
jae 0x79a8b
movq %r14, %rax
subq %r15, %rax
movzbl (%r15), %ecx
cmpl $0x20, %ecx
je 0x79a73
cmpl $0x9, %ecx
jne 0x79a80
incq %r15
decq %rax
jne 0x79a65
movq %r14, %r15
jmp 0x79a8b
leaq 0x1(%r15), %rax
cmpb $0xa, %cl
cmoveq %rax, %r15
addss -0x34(%rbp), %xmm0
movaps %xmm14, %xmm2
movl $0x0, %ecx
cmpq %r14, %r15
jb 0x799e7
jmp 0x79de1
movaps %xmm2, %xmm11
movaps %xmm0, -0x70(%rbp)
movq %r15, %r13
movq %rcx, -0xc8(%rbp)
movsbl (%r13), %ecx
movl %ecx, -0x5c(%rbp)
testl %ecx, %ecx
js 0x79aca
incq %r13
jmp 0x79b09
movss %xmm11, -0x50(%rbp)
leaq -0x5c(%rbp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x40f80
movl -0x5c(%rbp), %ecx
testl %ecx, %ecx
je 0x79de1
cltq
addq %rax, %r13
movaps -0xb0(%rbp), %xmm13
movaps -0xe0(%rbp), %xmm14
xorps %xmm15, %xmm15
movss -0x50(%rbp), %xmm11
cmpl $0x1f, %ecx
ja 0x79b40
cmpl $0xa, %ecx
jne 0x79b37
movaps -0x70(%rbp), %xmm0
addss -0x34(%rbp), %xmm0
movq -0x58(%rbp), %rax
movaps %xmm0, -0x70(%rbp)
ucomiss 0xc(%rax), %xmm0
movaps %xmm14, %xmm11
jbe 0x799c6
jmp 0x79de1
cmpl $0xd, %ecx
je 0x799c6
movzwl %cx, %eax
cmpl 0x18(%r12), %eax
jae 0x79b5d
movq 0x20(%r12), %rcx
movl %eax, %eax
movzwl (%rcx,%rax,2), %eax
cmpq $0xffff, %rax           # imm = 0xFFFF
jne 0x79b64
movq 0x38(%r12), %rax
jmp 0x79b70
leaq (%rax,%rax,4), %rax
shll $0x3, %eax
addq 0x30(%r12), %rax
movss -0x2c(%rbp), %xmm3
testq %rax, %rax
je 0x799c6
movss 0x4(%rax), %xmm0
mulss %xmm3, %xmm0
cmpl $0x0, (%rax)
jns 0x79dd7
movss 0x8(%rax), %xmm8
mulss %xmm3, %xmm8
addss %xmm11, %xmm8
movq -0x58(%rbp), %rcx
movss 0x8(%rcx), %xmm1
ucomiss %xmm8, %xmm1
jb 0x79dd7
movss 0x10(%rax), %xmm9
mulss %xmm3, %xmm9
addss %xmm11, %xmm9
movss (%rcx), %xmm2
ucomiss %xmm2, %xmm9
jb 0x79dd7
movss 0xc(%rax), %xmm10
mulss %xmm3, %xmm10
movaps -0x70(%rbp), %xmm4
addss %xmm4, %xmm10
movss 0x14(%rax), %xmm5
mulss %xmm3, %xmm5
addss %xmm4, %xmm5
movss 0x18(%rax), %xmm3
movss 0x1c(%rax), %xmm7
movss 0x20(%rax), %xmm6
movss 0x24(%rax), %xmm4
cmpb $0x0, 0x10(%rbp)
je 0x79c52
ucomiss %xmm8, %xmm2
movss %xmm11, -0x50(%rbp)
jbe 0x79c63
movaps %xmm9, %xmm11
subss %xmm2, %xmm11
movaps %xmm9, %xmm12
subss %xmm8, %xmm12
divss %xmm12, %xmm11
movss 0x3b3ac(%rip), %xmm8    # 0xb4fe4
subss %xmm11, %xmm8
movaps %xmm6, %xmm11
subss %xmm3, %xmm11
mulss %xmm8, %xmm11
addss %xmm11, %xmm3
jmp 0x79c67
movaps %xmm8, %xmm2
movaps %xmm9, %xmm1
movaps %xmm10, %xmm8
jmp 0x79d2b
movaps %xmm8, %xmm2
movq -0x58(%rbp), %rax
movss 0x4(%rax), %xmm8
ucomiss %xmm10, %xmm8
jbe 0x79cb1
movaps %xmm5, %xmm11
subss %xmm8, %xmm11
movaps %xmm5, %xmm12
subss %xmm10, %xmm12
divss %xmm12, %xmm11
movss 0x3b34d(%rip), %xmm10   # 0xb4fe4
subss %xmm11, %xmm10
movaps %xmm4, %xmm11
subss %xmm7, %xmm11
mulss %xmm10, %xmm11
addss %xmm11, %xmm7
jmp 0x79cb5
movaps %xmm10, %xmm8
movss -0x50(%rbp), %xmm11
ucomiss %xmm1, %xmm9
jbe 0x79ce3
movaps %xmm1, %xmm10
subss %xmm2, %xmm10
subss %xmm2, %xmm9
divss %xmm9, %xmm10
subss %xmm3, %xmm6
mulss %xmm10, %xmm6
addss %xmm3, %xmm6
jmp 0x79ce7
movaps %xmm9, %xmm1
movq -0x58(%rbp), %rax
movss 0xc(%rax), %xmm9
ucomiss %xmm9, %xmm5
jbe 0x79d1d
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 0x79d21
movaps %xmm5, %xmm9
ucomiss %xmm9, %xmm8
jae 0x79dd7
movq -0x80(%rbp), %rdx
movq -0x78(%rbp), %rsi
movw %si, (%rdx)
leal 0x1(%rsi), %eax
movw %ax, 0x2(%rdx)
leal 0x2(%rsi), %eax
movw %ax, 0x4(%rdx)
movw %si, 0x6(%rdx)
movw %ax, 0x8(%rdx)
leal 0x3(%rsi), %eax
movw %ax, 0xa(%rdx)
movq -0x88(%rbp), %rcx
movss %xmm2, (%rcx)
movss %xmm8, 0x4(%rcx)
movl -0x94(%rbp), %eax
movl %eax, 0x10(%rcx)
movss %xmm3, 0x8(%rcx)
movss %xmm7, 0xc(%rcx)
movss %xmm1, 0x14(%rcx)
movss %xmm8, 0x18(%rcx)
movl %eax, 0x24(%rcx)
movss %xmm6, 0x1c(%rcx)
movss %xmm7, 0x20(%rcx)
movss %xmm1, 0x28(%rcx)
movss %xmm5, 0x2c(%rcx)
movl %eax, 0x38(%rcx)
movss %xmm6, 0x30(%rcx)
movss %xmm4, 0x34(%rcx)
movss %xmm2, 0x3c(%rcx)
movss %xmm5, 0x40(%rcx)
movl %eax, 0x4c(%rcx)
movss %xmm3, 0x44(%rcx)
movss %xmm4, 0x48(%rcx)
addq $0x50, %rcx
movq %rcx, -0x88(%rbp)
addl $0x4, %esi
movq %rsi, -0x78(%rbp)
addq $0xc, %rdx
movq %rdx, -0x80(%rbp)
addss %xmm0, %xmm11
jmp 0x799c6
movq -0x88(%rbp), %rsi
movq %rsi, %rax
subq 0x28(%rbx), %rax
shrq $0x2, %rax
imull $0xcccccccd, %eax, %eax # imm = 0xCCCCCCCD
movl %eax, 0x20(%rbx)
movq -0x80(%rbp), %rdi
movq %rdi, %rax
subq 0x18(%rbx), %rax
shrq %rax
movl %eax, 0x10(%rbx)
movslq (%rbx), %rcx
testq %rcx, %rcx
jle 0x79e50
movl -0x90(%rbp), %edx
addl -0x8c(%rbp), %edx
subl %edx, %eax
movq 0x8(%rbx), %rdx
imulq $0x38, %rcx, %rcx
addl %eax, -0x18(%rdx,%rcx)
movq %rsi, 0x48(%rbx)
movq %rdi, 0x50(%rbx)
movq -0x78(%rbp), %rax
movl %eax, 0x34(%rbx)
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3f821(%rip), %rdi     # 0xb9678
leaq 0x3f82d(%rip), %rsi     # 0xb968b
leaq 0x54cf6(%rip), %rcx     # 0xceb5b
movl $0x65c, %edx            # imm = 0x65C
callq 0xc140
nop