// File: /workspace/github_cpp_makefile_star2_O2/Ciaxur[P]yagb-emu/include/imgui/imgui_draw.cpp
// Function: ImFont::BuildLookupTable()
void ImFont::BuildLookupTable()
{
    int max_codepoint = 0;
    for (int i = 0; i != Glyphs.Size; i++)
        max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint);

    // Build lookup table
    IM_ASSERT(Glyphs.Size < 0xFFFF); // -1 is reserved
    IndexAdvanceX.clear();
    IndexLookup.clear();
    DirtyLookupTables = false;
    memset(Used4kPagesMap, 0, sizeof(Used4kPagesMap));
    GrowIndex(max_codepoint + 1);
    for (int i = 0; i < Glyphs.Size; i++)
    {
        int codepoint = (int)Glyphs[i].Codepoint;
        IndexAdvanceX[codepoint] = Glyphs[i].AdvanceX;
        IndexLookup[codepoint] = (ImWchar)i;

        // Mark 4K page as used
        const int page_n = codepoint / 4096;
        Used4kPagesMap[page_n >> 3] |= 1 << (page_n & 7);
    }

    // Create a glyph to handle TAB
    // FIXME: Needs proper TAB handling but it needs to be contextualized (or we could arbitrary say that each string starts at "column 0" ?)
    if (FindGlyph((ImWchar)' '))
    {
        if (Glyphs.back().Codepoint != '\t')   // So we can call this function multiple times (FIXME: Flaky)
            Glyphs.resize(Glyphs.Size + 1);
        ImFontGlyph& tab_glyph = Glyphs.back();
        tab_glyph = *FindGlyph((ImWchar)' ');
        tab_glyph.Codepoint = '\t';
        tab_glyph.AdvanceX *= IM_TABSIZE;
        IndexAdvanceX[(int)tab_glyph.Codepoint] = (float)tab_glyph.AdvanceX;
        IndexLookup[(int)tab_glyph.Codepoint] = (ImWchar)(Glyphs.Size - 1);
    }

    // Mark special glyphs as not visible (note that AddGlyph already mark as non-visible glyphs with zero-size polygons)
    SetGlyphVisible((ImWchar)' ', false);
    SetGlyphVisible((ImWchar)'\t', false);

    // Setup fall-backs
    FallbackGlyph = FindGlyphNoFallback(FallbackChar);
    FallbackAdvanceX = FallbackGlyph ? FallbackGlyph->AdvanceX : 0.0f;
    for (int i = 0; i < max_codepoint + 1; i++)
        if (IndexAdvanceX[i] < 0.0f)
            IndexAdvanceX[i] = FallbackAdvanceX;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
leaq 0x28(%rdi), %r12
xorl %r14d, %r14d
movl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %r13d, %r13d
cmpl (%r12), %r14d
je 0x6accc
movq %r12, %rdi
movl %r14d, %esi
callq 0x6fc3a
movl (%rax), %eax
andl %r15d, %eax
cmpl %eax, %r13d
cmovlel %eax, %r13d
incl %r14d
jmp 0x6acaa
cmpl $0xffff, %r14d          # imm = 0xFFFF
jae 0x6aed3
movq %rbx, %rdi
callq 0x4a220
leaq 0x18(%rbx), %rdi
movq %rdi, -0x38(%rbp)
callq 0x4c100
movb $0x0, 0x56(%rbx)
andw $0x0, 0x68(%rbx)
incl %r13d
movq %rbx, %rdi
movl %r13d, -0x30(%rbp)
movl %r13d, %esi
callq 0x6b1f2
xorl %r13d, %r13d
cmpl (%r12), %r13d
jge 0x6ad81
movq %r12, %rdi
movl %r13d, %esi
callq 0x6fc3a
movl (%rax), %r14d
movl %r14d, %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movq %r12, %rdi
movl %r13d, %esi
callq 0x6fc3a
movss 0x4(%rax), %xmm0
movss %xmm0, -0x2c(%rbp)
movq %rbx, %rdi
movl %r15d, %esi
callq 0x4ad98
movss -0x2c(%rbp), %xmm0
movss %xmm0, (%rax)
movq -0x38(%rbp), %rdi
movl %r15d, %esi
callq 0x5f790
movw %r13w, (%rax)
shrl $0xc, %r14d
andb $0x7, %r14b
pushq $0x1
popq %rax
movl %r14d, %ecx
shll %cl, %eax
shrl $0xf, %r15d
orb %al, 0x68(%rbx,%r15)
incl %r13d
jmp 0x6ad0c
pushq $0x20
popq %rsi
movq %rbx, %rdi
callq 0x6b25a
testq %rax, %rax
je 0x6ae46
movq %r12, %rdi
callq 0x6fc70
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movl (%rax), %eax
andl %r13d, %eax
cmpl $0x9, %eax
je 0x6adbb
movl (%r12), %esi
incl %esi
movq %r12, %rdi
callq 0x6fcac
movq %r12, %rdi
callq 0x6fc70
movq %rax, %r12
pushq $0x20
popq %rsi
movq %rbx, %rdi
callq 0x6b25a
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm0, (%r12)
movups %xmm1, 0x10(%r12)
movq 0x20(%rax), %rax
movq %rax, 0x20(%r12)
movl $0x80000000, %eax       # imm = 0x80000000
andl (%r12), %eax
orl $0x9, %eax
movl %eax, (%r12)
movss 0x4(%r12), %xmm0
mulss 0x31a85(%rip), %xmm0    # 0x9c890
movss %xmm0, -0x2c(%rbp)
movss %xmm0, 0x4(%r12)
pushq $0x9
popq %rsi
movq %rbx, %rdi
callq 0x4ad98
movss -0x2c(%rbp), %xmm0
movss %xmm0, (%rax)
movl 0x28(%rbx), %r14d
decl %r14d
andl (%r12), %r13d
movq -0x38(%rbp), %rdi
movl %r13d, %esi
callq 0x5f790
movw %r14w, (%rax)
pushq $0x20
popq %rsi
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %edx, %edx
callq 0x6b28e
pushq $0x9
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x6b28e
movzwl 0x52(%rbx), %esi
movq %rbx, %rdi
callq 0x6aef2
movq %rax, 0x38(%rbx)
xorps %xmm0, %xmm0
testq %rax, %rax
je 0x6ae80
movss 0x4(%rax), %xmm0
movss %xmm0, 0x10(%rbx)
movl -0x30(%rbp), %r14d
cmpl %r15d, %r14d
je 0x6aec4
movq %rbx, %rdi
movl %r15d, %esi
callq 0x4ad98
xorps %xmm0, %xmm0
ucomiss (%rax), %xmm0
jbe 0x6aebf
movss 0x10(%rbx), %xmm0
movss %xmm0, -0x2c(%rbp)
movq %rbx, %rdi
movl %r15d, %esi
callq 0x4ad98
movss -0x2c(%rbp), %xmm0
movss %xmm0, (%rax)
incl %r15d
jmp 0x6ae89
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4a118(%rip), %rdi     # 0xb4ff2
leaq 0x495f5(%rip), %rsi     # 0xb44d6
leaq 0x4a11f(%rip), %rcx     # 0xb5007
movl $0xb57, %edx            # imm = 0xB57
callq 0xc140