// File: Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: ImGui::TextEx(char const*, char const*, int)
void ImGui::TextEx(const char* text, const char* text_end, ImGuiTextFlags flags)
{
    ImGuiWindow* window = GetCurrentWindow();
    if (window->SkipItems)
        return;

    ImGuiContext& g = *GImGui;
    IM_ASSERT(text != NULL);
    const char* text_begin = text;
    if (text_end == NULL)
        text_end = text + strlen(text); // FIXME-OPT

    const ImVec2 text_pos(window->DC.CursorPos.x, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset);
    const float wrap_pos_x = window->DC.TextWrapPos;
    const bool wrap_enabled = (wrap_pos_x >= 0.0f);
    if (text_end - text > 2000 && !wrap_enabled)
    {
        // Long text!
        // Perform manual coarse clipping to optimize for long multi-line text
        // - From this point we will only compute the width of lines that are visible. Optimization only available when word-wrapping is disabled.
        // - We also don't vertically center the text within the line full height, which is unlikely to matter because we are likely the biggest and only item on the line.
        // - We use memchr(), pay attention that well optimized versions of those str/mem functions are much faster than a casually written loop.
        const char* line = text;
        const float line_height = GetTextLineHeight();
        ImVec2 text_size(0, 0);

        // Lines to skip (can't skip when logging text)
        ImVec2 pos = text_pos;
        if (!g.LogEnabled)
        {
            int lines_skippable = (int)((window->ClipRect.Min.y - text_pos.y) / line_height);
            if (lines_skippable > 0)
            {
                int lines_skipped = 0;
                while (line < text_end && lines_skipped < lines_skippable)
                {
                    const char* line_end = (const char*)memchr(line, '\n', text_end - line);
                    if (!line_end)
                        line_end = text_end;
                    if ((flags & ImGuiTextFlags_NoWidthForLargeClippedText) == 0)
                        text_size.x = ImMax(text_size.x, CalcTextSize(line, line_end).x);
                    line = line_end + 1;
                    lines_skipped++;
                }
                pos.y += lines_skipped * line_height;
            }
        }

        // Lines to render
        if (line < text_end)
        {
            ImRect line_rect(pos, pos + ImVec2(FLT_MAX, line_height));
            while (line < text_end)
            {
                if (IsClippedEx(line_rect, 0, false))
                    break;

                const char* line_end = (const char*)memchr(line, '\n', text_end - line);
                if (!line_end)
                    line_end = text_end;
                text_size.x = ImMax(text_size.x, CalcTextSize(line, line_end).x);
                RenderText(pos, line, line_end, false);
                line = line_end + 1;
                line_rect.Min.y += line_height;
                line_rect.Max.y += line_height;
                pos.y += line_height;
            }

            // Count remaining lines
            int lines_skipped = 0;
            while (line < text_end)
            {
                const char* line_end = (const char*)memchr(line, '\n', text_end - line);
                if (!line_end)
                    line_end = text_end;
                if ((flags & ImGuiTextFlags_NoWidthForLargeClippedText) == 0)
                    text_size.x = ImMax(text_size.x, CalcTextSize(line, line_end).x);
                line = line_end + 1;
                lines_skipped++;
            }
            pos.y += lines_skipped * line_height;
        }
        text_size.y = (pos - text_pos).y;

        ImRect bb(text_pos, text_pos + text_size);
        ItemSize(text_size, 0.0f);
        ItemAdd(bb, 0);
    }
    else
    {
        const float wrap_width = wrap_enabled ? CalcWrapWidthForPos(window->DC.CursorPos, wrap_pos_x) : 0.0f;
        const ImVec2 text_size = CalcTextSize(text_begin, text_end, false, wrap_width);

        ImRect bb(text_pos, text_pos + text_size);
        ItemSize(text_size, 0.0f);
        if (!ItemAdd(bb, 0))
            return;

        // Render (we don't hide text after ## in this end-user function)
        RenderTextWrapped(bb.Min, text_begin, text_end, wrap_width);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
callq 0xeb270
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
testb $0x1, 0x93(%rax)
je 0x138a61
jmp 0x13903d
leaq 0xda4d8(%rip), %rax     # 0x212f40
movq (%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x138a78
jmp 0x138a97
leaq 0x52140(%rip), %rdi     # 0x18abbf
leaq 0x5595a(%rip), %rsi     # 0x18e3e0
movl $0x9b, %edx
leaq 0x5596e(%rip), %rcx     # 0x18e400
callq 0xd180
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x138acb
movq -0x8(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x8(%rbp), %rdi
callq 0xd410
movq %rax, %rcx
movq -0x120(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movq -0x20(%rbp), %rax
movss 0xd8(%rax), %xmm0
movq -0x20(%rbp), %rax
movss 0xdc(%rax), %xmm1
movq -0x20(%rbp), %rax
addss 0x110(%rax), %xmm1
leaq -0x38(%rbp), %rdi
callq 0xbf4c0
movq -0x20(%rbp), %rax
movss 0x1d4(%rax), %xmm0
movss %xmm0, -0x3c(%rbp)
movss -0x3c(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
setae %al
andb $0x1, %al
movb %al, -0x3d(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
subq %rcx, %rax
cmpq $0x7d0, %rax            # imm = 0x7D0
jle 0x138f5b
testb $0x1, -0x3d(%rbp)
jne 0x138f5b
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
callq 0xdd000
movss %xmm0, -0x4c(%rbp)
leaq -0x54(%rbp), %rdi
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0xbf4c0
movq -0x38(%rbp), %rax
movq %rax, -0x5c(%rbp)
movq -0x28(%rbp), %rax
testb $0x1, 0x3138(%rax)
jne 0x138c87
movq -0x20(%rbp), %rax
movss 0x25c(%rax), %xmm0
subss -0x34(%rbp), %xmm0
divss -0x4c(%rbp), %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x60(%rbp)
cmpl $0x0, -0x60(%rbp)
jle 0x138c85
movl $0x0, -0x64(%rbp)
movq -0x48(%rbp), %rcx
xorl %eax, %eax
cmpq -0x10(%rbp), %rcx
movb %al, -0x121(%rbp)
jae 0x138bc6
movl -0x64(%rbp), %eax
cmpl -0x60(%rbp), %eax
setl %al
movb %al, -0x121(%rbp)
movb -0x121(%rbp), %al
testb $0x1, %al
jne 0x138bd5
jmp 0x138c69
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x48(%rbp), %rax
subq %rax, %rdx
movl $0xa, %esi
callq 0xd490
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x138c01
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x14(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x138c4f
movss -0x54(%rbp), %xmm0
movss %xmm0, -0x128(%rbp)
movq -0x48(%rbp), %rdi
movq -0x70(%rbp), %rsi
xorl %edx, %edx
movss 0x39355(%rip), %xmm0    # 0x171f80
callq 0xc87e0
movaps %xmm0, %xmm1
movss -0x128(%rbp), %xmm0
movlpd %xmm1, -0x78(%rbp)
movss -0x78(%rbp), %xmm1
callq 0x139050
movss %xmm0, -0x54(%rbp)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x138ba5
cvtsi2ssl -0x64(%rbp), %xmm0
movss -0x4c(%rbp), %xmm2
movss -0x58(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x58(%rbp)
jmp 0x138c87
movq -0x48(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x138ee0
movss -0x4c(%rbp), %xmm1
leaq -0x98(%rbp), %rdi
movq %rdi, -0x130(%rbp)
movss 0x39304(%rip), %xmm0    # 0x171fb4
callq 0xbf4c0
movq -0x130(%rbp), %rsi
leaq -0x5c(%rbp), %rdi
callq 0x139090
movlpd %xmm0, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0xe8660
movq -0x48(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x138dfa
leaq -0x88(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xca6e0
testb $0x1, %al
jne 0x138d08
jmp 0x138d0d
jmp 0x138dfa
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x48(%rbp), %rax
subq %rax, %rdx
movl $0xa, %esi
callq 0xd490
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
jne 0x138d42
movq -0x10(%rbp), %rax
movq %rax, -0xa0(%rbp)
movss -0x54(%rbp), %xmm0
movss %xmm0, -0x134(%rbp)
movq -0x48(%rbp), %rdi
movq -0xa0(%rbp), %rsi
xorl %edx, %edx
movss 0x3921c(%rip), %xmm0    # 0x171f80
callq 0xc87e0
movaps %xmm0, %xmm1
movss -0x134(%rbp), %xmm0
movlpd %xmm1, -0xa8(%rbp)
movss -0xa8(%rbp), %xmm1
callq 0x139050
movss %xmm0, -0x54(%rbp)
movq -0x5c(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x48(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movsd -0xb0(%rbp), %xmm0
xorl %edx, %edx
callq 0xc8120
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movss -0x4c(%rbp), %xmm0
addss -0x84(%rbp), %xmm0
movss %xmm0, -0x84(%rbp)
movss -0x4c(%rbp), %xmm0
addss -0x7c(%rbp), %xmm0
movss %xmm0, -0x7c(%rbp)
movss -0x4c(%rbp), %xmm0
addss -0x58(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
jmp 0x138ce4
movl $0x0, -0xb4(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x138ec1
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x48(%rbp), %rax
subq %rax, %rdx
movl $0xa, %esi
callq 0xd490
movq %rax, -0xc0(%rbp)
cmpq $0x0, -0xc0(%rbp)
jne 0x138e47
movq -0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
movl -0x14(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x138e9e
movss -0x54(%rbp), %xmm0
movss %xmm0, -0x138(%rbp)
movq -0x48(%rbp), %rdi
movq -0xc0(%rbp), %rsi
xorl %edx, %edx
movss 0x3910c(%rip), %xmm0    # 0x171f80
callq 0xc87e0
movaps %xmm0, %xmm1
movss -0x138(%rbp), %xmm0
movlpd %xmm1, -0xc8(%rbp)
movss -0xc8(%rbp), %xmm1
callq 0x139050
movss %xmm0, -0x54(%rbp)
movq -0xc0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x138e04
cvtsi2ssl -0xb4(%rbp), %xmm0
movss -0x4c(%rbp), %xmm2
movss -0x58(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x58(%rbp)
leaq -0x5c(%rbp), %rdi
leaq -0x38(%rbp), %rsi
movq %rsi, -0x140(%rbp)
callq 0x1390e0
movq -0x140(%rbp), %rdi
movlpd %xmm0, -0xd0(%rbp)
movss -0xcc(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
leaq -0x54(%rbp), %rsi
callq 0x139090
movlpd %xmm0, -0xe8(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
callq 0xe8660
leaq -0x54(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0xd6030
leaq -0xe0(%rbp), %rdi
xorl %esi, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0xd6250
jmp 0x13903d
testb $0x1, -0x3d(%rbp)
je 0x138f80
movq -0x20(%rbp), %rdi
addq $0xd8, %rdi
movss -0x3c(%rbp), %xmm0
callq 0xca980
movss %xmm0, -0x144(%rbp)
jmp 0x138f8d
xorps %xmm0, %xmm0
movss %xmm0, -0x144(%rbp)
jmp 0x138f8d
movss -0x144(%rbp), %xmm0
movss %xmm0, -0xec(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movss -0xec(%rbp), %xmm0
xorl %edx, %edx
callq 0xc87e0
movlpd %xmm0, -0xf4(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0xf4(%rbp), %rsi
callq 0x139090
movlpd %xmm0, -0x10c(%rbp)
leaq -0x104(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x10c(%rbp), %rdx
callq 0xe8660
leaq -0xf4(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0xd6030
leaq -0x104(%rbp), %rdi
xorl %esi, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0xd6250
testb $0x1, %al
jne 0x139012
jmp 0x13903d
movq -0x104(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movss -0xec(%rbp), %xmm1
movsd -0x118(%rbp), %xmm0
callq 0xc8450
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopw %cs:(%rax,%rax)