// File: donfreiday[P]gb/./imgui/imgui_draw.cpp
// Function: ImDrawList::AddText(ImFont const*, float, ImVec2 const&, unsigned int, char const*, char const*, float, ImVec4 const*)
void ImDrawList::AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end, float wrap_width, const ImVec4* cpu_fine_clip_rect)
{
    if ((col >> 24) == 0)
        return;

    if (text_end == NULL)
        text_end = text_begin + strlen(text_begin);
    if (text_begin == text_end)
        return;

    IM_ASSERT(font->ContainerAtlas->TexID == _TextureIdStack.back());  // Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font.

    // reserve vertices for worse case (over-reserving is useful and easily amortized)
    const int char_count = (int)(text_end - text_begin);
    const int vtx_count_max = char_count * 4;
    const int idx_count_max = char_count * 6;
    const int vtx_begin = VtxBuffer.Size;
    const int idx_begin = IdxBuffer.Size;
    PrimReserve(idx_count_max, vtx_count_max);

    ImVec4 clip_rect = _ClipRectStack.back();
    if (cpu_fine_clip_rect)
    {
        clip_rect.x = ImMax(clip_rect.x, cpu_fine_clip_rect->x);
        clip_rect.y = ImMax(clip_rect.y, cpu_fine_clip_rect->y);
        clip_rect.z = ImMin(clip_rect.z, cpu_fine_clip_rect->z);
        clip_rect.w = ImMin(clip_rect.w, cpu_fine_clip_rect->w);
    }
    font->RenderText(font_size, pos, col, clip_rect, text_begin, text_end, this, wrap_width, cpu_fine_clip_rect != NULL);

    // give back unused vertices
    // FIXME-OPT: clean this up
    VtxBuffer.resize((int)(_VtxWritePtr - VtxBuffer.Data));
    IdxBuffer.resize((int)(_IdxWritePtr - IdxBuffer.Data));
    int vtx_unused = vtx_count_max - (VtxBuffer.Size - vtx_begin);
    int idx_unused = idx_count_max - (IdxBuffer.Size - idx_begin);
    CmdBuffer.back().ElemCount -= idx_unused;
    _VtxWritePtr -= vtx_unused;
    _IdxWritePtr -= idx_unused;
    _VtxCurrentIdx = (ImDrawIdx)VtxBuffer.Size;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movss %xmm0, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movss %xmm1, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x24(%rbp), %eax
shrl $0x18, %eax
cmpl $0x0, %eax
jne 0x40ad8
jmp 0x40d26
cmpq $0x0, -0x38(%rbp)
jne 0x40afe
movq -0x30(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x30(%rbp), %rdi
callq 0x7330
movq %rax, %rcx
movq -0x80(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jne 0x40b0d
jmp 0x40d26
movq -0x78(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rax
movq %rax, -0x88(%rbp)
addq $0x60, %rdi
callq 0x4c250
movq %rax, %rcx
movq -0x88(%rbp), %rax
cmpq (%rcx), %rax
jne 0x40b3d
jmp 0x40b5c
leaq 0x23aa8(%rip), %rdi     # 0x645ec
leaq 0x239ab(%rip), %rsi     # 0x644f6
movl $0x343, %edx            # imm = 0x343
leaq 0x23acb(%rip), %rcx     # 0x64622
callq 0x7160
movq -0x78(%rbp), %rdi
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
shll $0x2, %eax
movl %eax, -0x44(%rbp)
imull $0x6, -0x40(%rbp), %eax
movl %eax, -0x48(%rbp)
movl 0x20(%rdi), %eax
movl %eax, -0x4c(%rbp)
movl 0x10(%rdi), %eax
movl %eax, -0x50(%rbp)
movl -0x48(%rbp), %esi
movl -0x44(%rbp), %edx
callq 0x3d830
movq -0x78(%rbp), %rdi
addq $0x50, %rdi
callq 0x314a0
movq (%rax), %rcx
movq %rcx, -0x60(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x40c17
movss -0x60(%rbp), %xmm0
movq 0x10(%rbp), %rax
movss (%rax), %xmm1
callq 0x40d30
movss %xmm0, -0x60(%rbp)
movss -0x5c(%rbp), %xmm0
movq 0x10(%rbp), %rax
movss 0x4(%rax), %xmm1
callq 0x40d30
movss %xmm0, -0x5c(%rbp)
movss -0x58(%rbp), %xmm0
movq 0x10(%rbp), %rax
movss 0x8(%rax), %xmm1
callq 0x40480
movss %xmm0, -0x58(%rbp)
movss -0x54(%rbp), %xmm0
movq 0x10(%rbp), %rax
movss 0xc(%rax), %xmm1
callq 0x40480
movss %xmm0, -0x54(%rbp)
movq -0x78(%rbp), %r9
movq -0x10(%rbp), %rdi
movss -0x14(%rbp), %xmm0
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movl -0x24(%rbp), %esi
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movss -0x3c(%rbp), %xmm2
movq 0x10(%rbp), %rax
testq %rax, %rax
setne %al
movsd -0x68(%rbp), %xmm1
movzbl %al, %edx
andl $0x1, %edx
movq %rsp, %rax
movl %edx, (%rax)
leaq -0x60(%rbp), %rdx
callq 0x40d70
movq -0x78(%rbp), %rcx
movq %rcx, %rdi
addq $0x20, %rdi
movq 0x40(%rcx), %rax
movq 0x28(%rcx), %rcx
subq %rcx, %rax
movl $0x14, %ecx
cqto
idivq %rcx
movl %eax, %esi
callq 0x4bef0
movq -0x78(%rbp), %rcx
movq %rcx, %rdi
addq $0x10, %rdi
movq 0x48(%rcx), %rax
movq 0x18(%rcx), %rcx
subq %rcx, %rax
sarq %rax
movl %eax, %esi
callq 0x2ff70
movq -0x78(%rbp), %rdi
movl -0x44(%rbp), %eax
movl 0x20(%rdi), %ecx
subl -0x4c(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x6c(%rbp)
movl -0x48(%rbp), %eax
movl 0x10(%rdi), %ecx
subl -0x50(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x8c(%rbp)
callq 0x31000
movl -0x8c(%rbp), %esi
movq %rax, %rcx
movq -0x78(%rbp), %rax
movl (%rcx), %edx
subl %esi, %edx
movl %edx, (%rcx)
movl -0x6c(%rbp), %edx
movq 0x40(%rax), %rcx
movslq %edx, %rsi
xorl %edx, %edx
subq %rsi, %rdx
imulq $0x14, %rdx, %rdx
addq %rdx, %rcx
movq %rcx, 0x40(%rax)
movl -0x70(%rbp), %edx
movq 0x48(%rax), %rcx
movslq %edx, %rsi
xorl %edx, %edx
subq %rsi, %rdx
shlq %rdx
addq %rdx, %rcx
movq %rcx, 0x48(%rax)
movl 0x20(%rax), %ecx
movzwl %cx, %ecx
movl %ecx, 0x38(%rax)
addq $0xa0, %rsp
popq %rbp
retq
nop