// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %rsp
movss %xmm2, -0x3c(%rbp)
movq %r9, %r14
movq %r8, %r15
movq %rcx, %r13
movl %edx, -0x94(%rbp)
movq %rsi, %rbx
movq %rdi, %r12
testq %r9, %r9
jne 0x7b03a
movq %r15, %rdi
movss %xmm0, -0x30(%rbp)
movaps %xmm1, -0x70(%rbp)
callq 0xc350
movaps -0x70(%rbp), %xmm1
movss -0x30(%rbp), %xmm0
movq %rax, %r14
addq %r15, %r14
movaps %xmm1, %xmm2
shufps $0x55, %xmm1, %xmm2     # xmm2 = xmm2[1,1],xmm1[1,1]
cvttps2dq %xmm2, %xmm2
cvtdq2ps %xmm2, %xmm2
movq %r13, -0x50(%rbp)
movss 0xc(%r13), %xmm3
movaps %xmm2, -0x60(%rbp)
movss %xmm3, -0x40(%rbp)
ucomiss %xmm3, %xmm2
ja 0x7b6a1
movss 0x14(%r12), %xmm2
divss %xmm2, %xmm0
movss %xmm0, -0x30(%rbp)
mulss %xmm0, %xmm2
xorps %xmm3, %xmm3
movss -0x3c(%rbp), %xmm0
ucomiss %xmm3, %xmm0
movss %xmm2, -0x34(%rbp)
movaps %xmm1, -0x70(%rbp)
ja 0x7b0f4
movaps -0x60(%rbp), %xmm0
addss %xmm2, %xmm0
movq -0x50(%rbp), %rax
movss 0x4(%rax), %xmm2
movss %xmm2, -0x38(%rbp)
ucomiss %xmm0, %xmm2
jbe 0x7b0f4
seta %al
cmpq %r15, %r14
seta %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x7b0f4
movaps %xmm0, -0x60(%rbp)
movq %r14, %rdx
subq %r15, %rdx
movq %r15, %rdi
movl $0xa, %esi
callq 0xc3c0
leaq 0x1(%rax), %r15
testq %rax, %rax
cmoveq %r14, %r15
movss -0x34(%rbp), %xmm0
addss -0x60(%rbp), %xmm0
movss -0x38(%rbp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x7b0f4
cmpq %r14, %r15
jb 0x7b0b9
movss -0x3c(%rbp), %xmm0
ucomiss 0x3c744(%rip), %xmm0    # 0xb7844
ja 0x7b16b
movq %r14, %rax
subq %r15, %rax
cmpq $0x2711, %rax           # imm = 0x2711
jl 0x7b16b
movss -0x40(%rbp), %xmm0
ucomiss -0x60(%rbp), %xmm0
movq %r15, %r13
jbe 0x7b16e
movq %r15, %r13
cmpq %r14, %r15
jae 0x7b16e
movaps -0x60(%rbp), %xmm1
movq %r15, %r13
movss %xmm1, -0x38(%rbp)
movq %r14, %rdx
subq %r13, %rdx
movq %r13, %rdi
movl $0xa, %esi
callq 0xc3c0
movss -0x38(%rbp), %xmm1
leaq 0x1(%rax), %r13
testq %rax, %rax
cmoveq %r14, %r13
addss -0x34(%rbp), %xmm1
movss -0x40(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x7b16e
cmpq %r14, %r13
jb 0x7b12d
jmp 0x7b16e
movq %r14, %r13
cmpq %r13, %r15
movaps -0x70(%rbp), %xmm0
je 0x7b6a1
cvttps2dq %xmm0, %xmm0
cvtdq2ps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
movl %r13d, %eax
subl %r15d, %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 0x77438
movaps -0x70(%rbp), %xmm15
movss -0x30(%rbp), %xmm0
movq 0x48(%rbx), %rax
movq %rax, -0x88(%rbp)
movq 0x50(%rbx), %rax
movq %rax, -0x80(%rbp)
movl 0x34(%rbx), %eax
movq %rax, -0x78(%rbp)
xorl %r14d, %r14d
xorps %xmm11, %xmm11
movaps %xmm15, %xmm2
movss -0x34(%rbp), %xmm14
cmpq %r13, %r15
jae 0x7b644
movss %xmm2, -0x2c(%rbp)
movaps %xmm2, %xmm3
movaps -0x60(%rbp), %xmm1
movq %r14, -0xa0(%rbp)
movq %r14, %rcx
movq %r15, %r14
movss -0x3c(%rbp), %xmm2
ucomiss %xmm11, %xmm2
jbe 0x7b2be
testq %rcx, %rcx
jne 0x7b26c
movss %xmm1, -0x38(%rbp)
movaps %xmm15, %xmm1
subss %xmm3, %xmm1
addss %xmm2, %xmm1
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
movss %xmm3, -0x40(%rbp)
callq 0x83404
movss -0x40(%rbp), %xmm3
movss -0x38(%rbp), %xmm1
xorps %xmm11, %xmm11
movaps -0x70(%rbp), %xmm15
movss -0x34(%rbp), %xmm14
movss -0x30(%rbp), %xmm0
movss -0x3c(%rbp), %xmm2
xorl %ecx, %ecx
cmpq %r14, %rax
sete %cl
addq %rax, %rcx
cmpq %rcx, %r14
jb 0x7b2cc
cmpq %r13, %r14
jae 0x7b2a2
movq %r14, %rcx
movzbl (%r14), %eax
cmpl $0x20, %eax
sete %dl
leal -0x9(%rax), %esi
cmpb $0x2, %sil
setb %sil
orb %dl, %sil
movzbl %sil, %r14d
addq %rcx, %r14
cmpl $0x20, %eax
je 0x7b271
cmpl $0x9, %eax
je 0x7b271
addss %xmm14, %xmm1
movaps %xmm15, %xmm3
movl $0x0, %ecx
cmpq %r13, %r14
jb 0x7b20b
jmp 0x7b644
movq -0xa0(%rbp), %r14
movss -0x2c(%rbp), %xmm2
jmp 0x7b2d9
movaps %xmm3, %xmm2
movaps %xmm1, -0x60(%rbp)
movq %r14, %r15
movq %rcx, %r14
movsbl (%r15), %eax
movl %eax, -0x44(%rbp)
testl %eax, %eax
js 0x7b2ec
incq %r15
movq %r15, %rax
jmp 0x7b328
movss %xmm2, -0x2c(%rbp)
leaq -0x44(%rbp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x41855
cltq
addq %r15, %rax
cmpl $0x0, -0x44(%rbp)
je 0x7b470
movss -0x30(%rbp), %xmm0
movss -0x34(%rbp), %xmm14
movaps -0x70(%rbp), %xmm15
xorps %xmm11, %xmm11
movss -0x2c(%rbp), %xmm2
movl -0x44(%rbp), %ecx
cmpq $0x1f, %rcx
ja 0x7b361
cmpq $0xd, %rcx
je 0x7b627
cmpl $0xa, %ecx
jne 0x7b361
movaps -0x60(%rbp), %xmm1
addss %xmm14, %xmm1
movq -0x50(%rbp), %rcx
movaps %xmm1, -0x60(%rbp)
ucomiss 0xc(%rcx), %xmm1
seta %cl
movaps %xmm15, %xmm2
jmp 0x7b629
movzwl %cx, %ecx
cmpl 0x18(%r12), %ecx
jae 0x7b37d
movq 0x20(%r12), %rdx
movzwl (%rdx,%rcx,2), %ecx
cmpq $0xffff, %rcx           # imm = 0xFFFF
jne 0x7b384
movq 0x38(%r12), %rdx
jmp 0x7b390
leaq (%rcx,%rcx,4), %rdx
shll $0x3, %edx
addq 0x30(%r12), %rdx
testq %rdx, %rdx
je 0x7b627
movss 0x4(%rdx), %xmm13
mulss %xmm0, %xmm13
cmpl $0x0, (%rdx)
jns 0x7b622
movss 0x8(%rdx), %xmm8
mulss %xmm0, %xmm8
addss %xmm2, %xmm8
movq -0x50(%rbp), %rsi
movss 0x8(%rsi), %xmm1
movb $0x1, %cl
ucomiss %xmm8, %xmm1
jb 0x7b61e
movss 0x10(%rdx), %xmm9
mulss %xmm0, %xmm9
movss %xmm2, -0x2c(%rbp)
addss %xmm2, %xmm9
movss (%rsi), %xmm2
ucomiss %xmm2, %xmm9
jb 0x7b619
movss 0xc(%rdx), %xmm10
mulss %xmm0, %xmm10
movaps -0x60(%rbp), %xmm3
addss %xmm3, %xmm10
movss 0x14(%rdx), %xmm5
mulss %xmm0, %xmm5
addss %xmm3, %xmm5
movss 0x18(%rdx), %xmm3
movss 0x1c(%rdx), %xmm7
movss 0x20(%rdx), %xmm6
movss 0x24(%rdx), %xmm4
cmpb $0x0, 0x10(%rbp)
je 0x7b490
ucomiss %xmm8, %xmm2
jbe 0x7b4a1
movaps %xmm9, %xmm11
subss %xmm2, %xmm11
movaps %xmm9, %xmm12
subss %xmm8, %xmm12
divss %xmm12, %xmm11
movss 0x3bb8e(%rip), %xmm8    # 0xb6fe4
subss %xmm11, %xmm8
movaps %xmm6, %xmm11
subss %xmm3, %xmm11
mulss %xmm8, %xmm11
addss %xmm11, %xmm3
jmp 0x7b4a5
movb $0x1, %cl
movss -0x30(%rbp), %xmm0
movss -0x34(%rbp), %xmm14
movaps -0x70(%rbp), %xmm15
xorps %xmm11, %xmm11
movss -0x2c(%rbp), %xmm2
jmp 0x7b629
movaps %xmm8, %xmm2
movaps %xmm9, %xmm1
movaps %xmm10, %xmm8
jmp 0x7b567
movaps %xmm8, %xmm2
movq -0x50(%rbp), %rdx
movss 0x4(%rdx), %xmm8
ucomiss %xmm10, %xmm8
jbe 0x7b4ef
movaps %xmm5, %xmm11
subss %xmm8, %xmm11
movaps %xmm5, %xmm12
subss %xmm10, %xmm12
divss %xmm12, %xmm11
movss 0x3bb0f(%rip), %xmm10   # 0xb6fe4
subss %xmm11, %xmm10
movaps %xmm4, %xmm11
subss %xmm7, %xmm11
mulss %xmm10, %xmm11
addss %xmm11, %xmm7
jmp 0x7b4f3
movaps %xmm10, %xmm8
xorps %xmm11, %xmm11
ucomiss %xmm1, %xmm9
jbe 0x7b51f
movaps %xmm1, %xmm10
subss %xmm2, %xmm10
subss %xmm2, %xmm9
divss %xmm9, %xmm10
subss %xmm3, %xmm6
mulss %xmm10, %xmm6
addss %xmm3, %xmm6
jmp 0x7b523
movaps %xmm9, %xmm1
movq -0x50(%rbp), %rdx
movss 0xc(%rdx), %xmm9
ucomiss %xmm9, %xmm5
jbe 0x7b559
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 0x7b55d
movaps %xmm5, %xmm9
ucomiss %xmm9, %xmm8
jae 0x7b636
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %r8
movw %r8w, (%rdi)
leal 0x1(%r8), %edx
movw %dx, 0x2(%rdi)
leal 0x2(%r8), %edx
movw %dx, 0x4(%rdi)
movw %r8w, 0x6(%rdi)
movw %dx, 0x8(%rdi)
leal 0x3(%r8), %edx
movw %dx, 0xa(%rdi)
movq -0x88(%rbp), %rsi
movss %xmm2, (%rsi)
movss %xmm8, 0x4(%rsi)
movl -0x94(%rbp), %edx
movl %edx, 0x10(%rsi)
movss %xmm3, 0x8(%rsi)
movss %xmm7, 0xc(%rsi)
movss %xmm1, 0x14(%rsi)
movss %xmm8, 0x18(%rsi)
movl %edx, 0x24(%rsi)
movss %xmm6, 0x1c(%rsi)
movss %xmm7, 0x20(%rsi)
movss %xmm1, 0x28(%rsi)
movss %xmm5, 0x2c(%rsi)
movl %edx, 0x38(%rsi)
movss %xmm6, 0x30(%rsi)
movss %xmm4, 0x34(%rsi)
movss %xmm2, 0x3c(%rsi)
movss %xmm5, 0x40(%rsi)
movl %edx, 0x4c(%rsi)
movss %xmm3, 0x44(%rsi)
movss %xmm4, 0x48(%rsi)
addq $0x50, %rsi
movq %rsi, -0x88(%rbp)
addl $0x4, %r8d
movq %r8, -0x78(%rbp)
addq $0xc, %rdi
movq %rdi, -0x80(%rbp)
movss -0x2c(%rbp), %xmm2
testb %cl, %cl
je 0x7b627
addss %xmm13, %xmm2
xorl %ecx, %ecx
movq %rax, %r15
testb %cl, %cl
je 0x7b1e4
jmp 0x7b644
movss -0x2c(%rbp), %xmm2
addss %xmm13, %xmm2
xorl %ecx, %ecx
jmp 0x7b61e
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 0x7b6b0
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 $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3ffc1(%rip), %rdi     # 0xbb678
leaq 0x3ffcd(%rip), %rsi     # 0xbb68b
leaq 0x554fa(%rip), %rcx     # 0xd0bbf
movl $0x65c, %edx            # imm = 0x65C
callq 0xc140
nop