// File: donfreiday[P]gb/./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);

    IndexXAdvance.clear();
    IndexXAdvance.resize(max_codepoint + 1);
    IndexLookup.clear();
    IndexLookup.resize(max_codepoint + 1);
    for (int i = 0; i < max_codepoint + 1; i++)
    {
        IndexXAdvance[i] = -1.0f;
        IndexLookup[i] = -1;
    }
    for (int i = 0; i < Glyphs.Size; i++)
    {
        int codepoint = (int)Glyphs[i].Codepoint;
        IndexXAdvance[codepoint] = Glyphs[i].XAdvance;
        IndexLookup[codepoint] = i;
    }

    // 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((unsigned short)' '))
    {
        if (Glyphs.back().Codepoint != '\t')   // So we can call this function multiple times
            Glyphs.resize(Glyphs.Size + 1);
        ImFont::Glyph& tab_glyph = Glyphs.back();
        tab_glyph = *FindGlyph((unsigned short)' ');
        tab_glyph.Codepoint = '\t';
        tab_glyph.XAdvance *= 4;
        IndexXAdvance[(int)tab_glyph.Codepoint] = (float)tab_glyph.XAdvance;
        IndexLookup[(int)tab_glyph.Codepoint] = (int)(Glyphs.Size-1);
    }

    FallbackGlyph = NULL;
    FallbackGlyph = FindGlyph(FallbackChar);
    FallbackXAdvance = FallbackGlyph ? FallbackGlyph->XAdvance : 0.0f;
    for (int i = 0; i < max_codepoint + 1; i++)
        if (IndexXAdvance[i] < 0.0f)
            IndexXAdvance[i] = FallbackXAdvance;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movq -0x38(%rbp), %rcx
movl -0x10(%rbp), %eax
cmpl 0x38(%rcx), %eax
je 0x4566d
movq -0x38(%rbp), %rdi
movl -0xc(%rbp), %eax
movl %eax, -0x3c(%rbp)
addq $0x38, %rdi
movl -0x10(%rbp), %esi
callq 0x4cc40
movl -0x3c(%rbp), %edi
movzwl (%rax), %esi
callq 0x44a10
movl %eax, -0xc(%rbp)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x45632
movq -0x38(%rbp), %rdi
addq $0x58, %rdi
callq 0x4cbf0
movq -0x38(%rbp), %rdi
addq $0x58, %rdi
movl -0xc(%rbp), %esi
addl $0x1, %esi
callq 0x2f430
movq -0x38(%rbp), %rdi
addq $0x68, %rdi
callq 0x3cb00
movq -0x38(%rbp), %rdi
addq $0x68, %rdi
movl -0xc(%rbp), %esi
addl $0x1, %esi
callq 0x4cca0
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x456fe
movq -0x38(%rbp), %rdi
addq $0x58, %rdi
movl -0x14(%rbp), %esi
callq 0x30290
movq -0x38(%rbp), %rdi
movss 0x1599f(%rip), %xmm0    # 0x5b07c
movss %xmm0, (%rax)
addq $0x68, %rdi
movl -0x14(%rbp), %esi
callq 0x3caa0
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x456b4
movl $0x0, -0x18(%rbp)
movq -0x38(%rbp), %rcx
movl -0x18(%rbp), %eax
cmpl 0x38(%rcx), %eax
jge 0x45780
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x18(%rbp), %esi
callq 0x4cc40
movq -0x38(%rbp), %rdi
movzwl (%rax), %eax
movl %eax, -0x1c(%rbp)
addq $0x38, %rdi
movl -0x18(%rbp), %esi
callq 0x4cc40
movq -0x38(%rbp), %rdi
movss 0x4(%rax), %xmm0
movss %xmm0, -0x44(%rbp)
addq $0x58, %rdi
movl -0x1c(%rbp), %esi
callq 0x30290
movss -0x44(%rbp), %xmm0
movq -0x38(%rbp), %rdi
movss %xmm0, (%rax)
movl -0x18(%rbp), %eax
movl %eax, -0x40(%rbp)
addq $0x68, %rdi
movl -0x1c(%rbp), %esi
callq 0x3caa0
movl -0x40(%rbp), %ecx
movl %ecx, (%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x45705
movq -0x38(%rbp), %rdi
movl $0x20, %esi
callq 0x45380
cmpq $0x0, %rax
je 0x4585f
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
callq 0x4ca20
movzwl (%rax), %eax
cmpl $0x9, %eax
je 0x457c3
movq -0x38(%rbp), %rax
movq %rax, %rdi
addq $0x38, %rdi
movl 0x38(%rax), %esi
addl $0x1, %esi
callq 0x4c9d0
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
callq 0x4ca20
movq -0x38(%rbp), %rdi
movq %rax, -0x28(%rbp)
movl $0x20, %esi
callq 0x45380
movq %rax, %rsi
movq -0x28(%rbp), %rdi
movl $0x28, %edx
callq 0x7080
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rax
movw $0x9, (%rax)
movq -0x28(%rbp), %rax
movss 0x1584c(%rip), %xmm0    # 0x5b058
mulss 0x4(%rax), %xmm0
movss %xmm0, 0x4(%rax)
movq -0x28(%rbp), %rax
movss 0x4(%rax), %xmm0
movss %xmm0, -0x4c(%rbp)
addq $0x58, %rdi
movq -0x28(%rbp), %rax
movzwl (%rax), %esi
callq 0x30290
movss -0x4c(%rbp), %xmm0
movq -0x38(%rbp), %rdi
movss %xmm0, (%rax)
movl 0x38(%rdi), %eax
subl $0x1, %eax
movl %eax, -0x48(%rbp)
addq $0x68, %rdi
movq -0x28(%rbp), %rax
movzwl (%rax), %esi
callq 0x3caa0
movl -0x48(%rbp), %ecx
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x48(%rax)
movq %rax, %rdi
movzwl 0x10(%rax), %esi
callq 0x45380
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x48(%rax)
cmpq $0x0, 0x48(%rax)
je 0x4589d
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movss 0x4(%rax), %xmm0
movss %xmm0, -0x50(%rbp)
jmp 0x458a7
xorps %xmm0, %xmm0
movss %xmm0, -0x50(%rbp)
jmp 0x458a7
movq -0x38(%rbp), %rax
movss -0x50(%rbp), %xmm0
movss %xmm0, 0x50(%rax)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x45911
movq -0x38(%rbp), %rdi
addq $0x58, %rdi
movl -0x2c(%rbp), %esi
callq 0x30290
xorps %xmm0, %xmm0
ucomiss (%rax), %xmm0
jbe 0x45904
movq -0x38(%rbp), %rdi
movss 0x50(%rdi), %xmm0
movss %xmm0, -0x54(%rbp)
addq $0x58, %rdi
movl -0x2c(%rbp), %esi
callq 0x30290
movss -0x54(%rbp), %xmm0
movss %xmm0, (%rax)
jmp 0x45906
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x458bc
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)