// File: Ciaxur[P]yagb-emu/include/imgui/imgui_draw.cpp
// Function: ImFontAtlasBuildFinish(ImFontAtlas*)
void ImFontAtlasBuildFinish(ImFontAtlas* atlas)
{
    // Render into our custom data blocks
    IM_ASSERT(atlas->TexPixelsAlpha8 != NULL);
    ImFontAtlasBuildRenderDefaultTexData(atlas);
    ImFontAtlasBuildRenderLinesTexData(atlas);

    // Register custom rectangle glyphs
    for (int i = 0; i < atlas->CustomRects.Size; i++)
    {
        const ImFontAtlasCustomRect* r = &atlas->CustomRects[i];
        if (r->Font == NULL || r->GlyphID == 0)
            continue;

        // Will ignore ImFontConfig settings: GlyphMinAdvanceX, GlyphMinAdvanceY, GlyphExtraSpacing, PixelSnapH
        IM_ASSERT(r->Font->ContainerAtlas == atlas);
        ImVec2 uv0, uv1;
        atlas->CalcCustomRectUV(r, &uv0, &uv1);
        r->Font->AddGlyph(NULL, (ImWchar)r->GlyphID, r->GlyphOffset.x, r->GlyphOffset.y, r->GlyphOffset.x + r->Width, r->GlyphOffset.y + r->Height, uv0.x, uv0.y, uv1.x, uv1.y, r->GlyphAdvanceX);
    }

    // Build all fonts lookup tables
    for (int i = 0; i < atlas->Fonts.Size; i++)
        if (atlas->Fonts[i]->DirtyLookupTables)
            atlas->Fonts[i]->BuildLookupTable();

    // Ellipsis character is required for rendering elided text. We prefer using U+2026 (horizontal ellipsis).
    // However some old fonts may contain ellipsis at U+0085. Here we auto-detect most suitable ellipsis character.
    // FIXME: Also note that 0x2026 is currently seldom included in our font ranges. Because of this we are more likely to use three individual dots.
    for (int i = 0; i < atlas->Fonts.size(); i++)
    {
        ImFont* font = atlas->Fonts[i];
        if (font->EllipsisChar != (ImWchar)-1)
            continue;
        const ImWchar ellipsis_variants[] = { (ImWchar)0x2026, (ImWchar)0x0085 };
        for (int j = 0; j < IM_ARRAYSIZE(ellipsis_variants); j++)
            if (font->FindGlyphNoFallback(ellipsis_variants[j]) != NULL) // Verify glyph exists
            {
                font->EllipsisChar = ellipsis_variants[j];
                break;
            }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x11ac89
jmp 0x11aca8
leaq 0x7009c(%rip), %rdi     # 0x18ad2c
leaq 0x6f4df(%rip), %rsi     # 0x18a176
movl $0x9df, %edx            # imm = 0x9DF
leaq 0x700aa(%rip), %rcx     # 0x18ad4d
callq 0xd180
movq -0x8(%rbp), %rdi
callq 0x11b0f0
movq -0x8(%rbp), %rdi
callq 0x11b350
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x50(%rcx), %eax
jge 0x11ade9
movq -0x8(%rbp), %rdi
addq $0x50, %rdi
movl -0xc(%rbp), %esi
callq 0x128410
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x11acfa
movq -0x18(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x11acff
jmp 0x11addb
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x40(%rax), %rax
cmpq -0x8(%rbp), %rax
jne 0x11ad13
jmp 0x11ad32
leaq 0x7005e(%rip), %rdi     # 0x18ad78
leaq 0x6f455(%rip), %rsi     # 0x18a176
movl $0x9eb, %edx            # imm = 0x9EB
leaq 0x70020(%rip), %rcx     # 0x18ad4d
callq 0xd180
leaq -0x20(%rbp), %rdi
callq 0xe7de0
leaq -0x28(%rbp), %rdi
callq 0xe7de0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x20(%rbp), %rdx
leaq -0x28(%rbp), %rcx
callq 0x117290
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
movss 0x10(%rcx), %xmm0
movq -0x18(%rbp), %rcx
movss 0x14(%rcx), %xmm1
movq -0x18(%rbp), %rcx
movss 0x10(%rcx), %xmm2
movq -0x18(%rbp), %rcx
movzwl (%rcx), %ecx
cvtsi2ss %ecx, %xmm3
addss %xmm3, %xmm2
movq -0x18(%rbp), %rcx
movss 0x14(%rcx), %xmm3
movq -0x18(%rbp), %rcx
movzwl 0x2(%rcx), %ecx
cvtsi2ss %ecx, %xmm4
addss %xmm4, %xmm3
movss -0x20(%rbp), %xmm4
movss -0x1c(%rbp), %xmm5
movss -0x28(%rbp), %xmm6
movss -0x24(%rbp), %xmm7
movq -0x18(%rbp), %rcx
movss 0xc(%rcx), %xmm8
xorl %ecx, %ecx
movl %ecx, %esi
movzwl %ax, %edx
movss %xmm8, (%rsp)
callq 0x11a9a0
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x11acc1
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x40(%rcx), %eax
jge 0x11ae3a
movq -0x8(%rbp), %rdi
addq $0x40, %rdi
movl -0x2c(%rbp), %esi
callq 0xede60
movq (%rax), %rax
testb $0x1, 0x56(%rax)
je 0x11ae2d
movq -0x8(%rbp), %rdi
addq $0x40, %rdi
movl -0x2c(%rbp), %esi
callq 0xede60
movq (%rax), %rdi
callq 0x11b5d0
jmp 0x11ae2f
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x11adf0
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
addq $0x40, %rdi
callq 0x128490
movl %eax, %ecx
movl -0x44(%rbp), %eax
cmpl %ecx, %eax
jge 0x11aee7
movq -0x8(%rbp), %rdi
addq $0x40, %rdi
movl -0x30(%rbp), %esi
callq 0xede60
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movzwl 0x54(%rax), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x11ae89
jmp 0x11aed9
movl 0x68bc5(%rip), %eax     # 0x183a54
movl %eax, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
cmpl $0x2, -0x40(%rbp)
jge 0x11aed7
movq -0x38(%rbp), %rdi
movslq -0x40(%rbp), %rax
movzwl -0x3c(%rbp,%rax,2), %esi
callq 0x11b920
cmpq $0x0, %rax
je 0x11aeca
movslq -0x40(%rbp), %rax
movw -0x3c(%rbp,%rax,2), %cx
movq -0x38(%rbp), %rax
movw %cx, 0x54(%rax)
jmp 0x11aed7
jmp 0x11aecc
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x11ae99
jmp 0x11aed9
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x11ae41
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)