// File: /workspace/github_c_makefile_star2_O3/FredTheDino[P]Fog/src/engine/renderer/text.cpp
// Function: Renderer::draw_text(char const*, float, float, float, unsigned long long, float, Vec4, float, unsigned char)
void draw_text(const char *string, f32 x, f32 y, f32 size, AssetID font_id,
               f32 alignment,
               Vec4 color,
               f32 edge,
               b8 border) {
    START_PERF(TEXT);
    Asset::Font *font = Asset::fetch_font(font_id);
    ASSERT(font, "Cannot find font, the \"id\" passed in should end with _FONT");
    Vec2 offset = V2(0, 0);
    if (alignment)
        offset = V2(alignment * messure_text(string, size, font_id).x, 0.0);

    if (!font->num_kernings) {
        Asset::Font::Glyph std = font->glyphs[(u8) 'A'];
        while (*string) {
            u8 curr = *(string++);
            Asset::Font::Glyph glyph = font->glyphs[curr];
            if (glyph.w) {
                Vec2 p = {x + (glyph.x_offset) * size,
                          y + (glyph.h + glyph.y_offset) * -size};
                Vec2 uv = {glyph.x, glyph.y};
                Vec2 span = {glyph.w, glyph.h};
                push_sdf_quad(p + offset, p + offset + span * size,
                                        uv, uv + span,
                                        font->texture, color, 0.4, 0.4 + edge,
                                        border);
            }
            x += std.advance * size;
        }
    } else {
        u8 prev = '\0';
        while (*string) {
            u8 curr = *(string++);
            f32 kerning = font->find_kerning(prev, curr);
            x += kerning * size;
            Asset::Font::Glyph glyph = font->glyphs[curr];

            if (glyph.w) {
                Vec2 p = {x + (glyph.x_offset) * (size),
                          y + (glyph.h + glyph.y_offset) * (-size)};
                Vec2 uv = {glyph.x, glyph.y};
                Vec2 span = {glyph.w, glyph.h};
                push_sdf_quad(p + offset, p + offset + span * size,
                                        uv, uv + span,
                                        font->texture, color, 0.4, 0.4 + edge,
                                        border);
            }
            x += (glyph.advance + glyph.x_offset) * size;
        }
    }
    STOP_PERF(TEXT);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x90, %rsp
movl %edx, %r15d
movss %xmm6, -0x2c(%rbp)
movaps %xmm5, -0xa0(%rbp)
movaps %xmm4, -0x90(%rbp)
movss %xmm3, -0x28(%rbp)
movq %rsi, %r12
movaps %xmm2, -0x40(%rbp)
movss %xmm1, -0x30(%rbp)
movss %xmm0, -0x24(%rbp)
movq %rdi, %rbx
leaq 0x26f5d(%rip), %rsi     # 0x313cd
movl $0x3, %edi
callq 0x21db9
movq %r12, %rdi
movl $0x2, %esi
callq 0x23225
movq %rax, %r14
xorl %ecx, %ecx
testq %rax, %rax
setne %cl
leaq 0x26f00(%rip), %rdi     # 0x31399
leaq 0x26f32(%rip), %rdx     # 0x313d2
movl $0x1b, %esi
callq 0x729c
movaps -0x40(%rbp), %xmm0
xorps %xmm1, %xmm1
movss -0x28(%rbp), %xmm2
ucomiss %xmm1, %xmm2
jne 0xa4bd
jnp 0xa4da
movq %rbx, %rdi
movq %r12, %rsi
callq 0xa218
mulss -0x28(%rbp), %xmm0
xorps %xmm1, %xmm1
movss %xmm0, %xmm1            # xmm1 = xmm0[0],xmm1[1,2,3]
movaps %xmm1, -0x50(%rbp)
jmp 0xa4e1
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
cmpq $0x0, 0x18(%r14)
movss -0x24(%rbp), %xmm1
je 0xa659
movb (%rbx), %al
testb %al, %al
movaps -0x40(%rbp), %xmm0
je 0xa785
movaps 0x25b3a(%rip), %xmm2    # 0x30040
xorps %xmm0, %xmm2
movaps %xmm2, -0x70(%rbp)
movaps -0x50(%rbp), %xmm0
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movaps %xmm0, -0x60(%rbp)
xorps %xmm0, %xmm0
cvtss2sd -0x2c(%rbp), %xmm0
addsd 0x26537(%rip), %xmm0    # 0x30a60
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x2c(%rbp)
incq %rbx
movzbl %r15b, %r15d
movss %xmm1, -0x24(%rbp)
movsbl %al, %r12d
movq %r14, %rdi
xorl %esi, %esi
movl %r12d, %edx
callq 0x2dcc6
movaps -0x40(%rbp), %xmm6
movaps %xmm0, %xmm4
mulss %xmm6, %xmm4
addss -0x24(%rbp), %xmm4
movq 0x20(%r14), %rax
movzbl %r12b, %ecx
shll $0x5, %ecx
movss 0xc(%rax,%rcx), %xmm3
movss 0x14(%rax,%rcx), %xmm1
movss 0x1c(%rax,%rcx), %xmm0
ucomiss 0x25cb5(%rip), %xmm3    # 0x30238
jne 0xa58b
jnp 0xa63b
addq %rcx, %rax
movss 0x10(%rax), %xmm2
movss %xmm0, -0x80(%rbp)
movaps %xmm1, %xmm0
mulss %xmm6, %xmm0
addss %xmm4, %xmm0
movss 0x18(%rax), %xmm5
addss %xmm2, %xmm5
mulss -0x70(%rbp), %xmm5
addss -0x30(%rbp), %xmm5
addss -0x50(%rbp), %xmm0
addss -0x60(%rbp), %xmm5
movss %xmm1, -0x24(%rbp)
movaps %xmm3, %xmm1
mulss %xmm6, %xmm1
movss %xmm4, -0x28(%rbp)
movaps %xmm2, %xmm4
mulss %xmm6, %xmm4
addss %xmm0, %xmm1
addss %xmm5, %xmm4
addss 0x4(%rax), %xmm3
unpcklps %xmm4, %xmm1            # xmm1 = xmm1[0],xmm4[0],xmm1[1],xmm4[1]
addss 0x8(%rax), %xmm2
unpcklps %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
xorps %xmm4, %xmm4
cvtsi2ssl (%r14), %xmm4
movsd 0x4(%rax), %xmm2
movss -0x2c(%rbp), %xmm6
movss %xmm6, (%rsp)
unpcklps %xmm5, %xmm0            # xmm0 = xmm0[0],xmm5[0],xmm0[1],xmm5[1]
movaps -0x90(%rbp), %xmm5
movaps -0xa0(%rbp), %xmm6
movss 0x25c14(%rip), %xmm7    # 0x30234
movl %r15d, %edi
callq 0x20686
movss -0x80(%rbp), %xmm0
movss -0x28(%rbp), %xmm4
movss -0x24(%rbp), %xmm1
movaps -0x40(%rbp), %xmm6
addss %xmm0, %xmm1
mulss %xmm6, %xmm1
addss %xmm4, %xmm1
movb (%rbx), %al
incq %rbx
testb %al, %al
jne 0xa539
jmp 0xa785
movb (%rbx), %cl
testb %cl, %cl
movaps -0x40(%rbp), %xmm6
je 0xa785
movq 0x20(%r14), %rax
movaps 0x259ce(%rip), %xmm0    # 0x30040
xorps %xmm6, %xmm0
movaps %xmm0, -0x80(%rbp)
movaps -0x50(%rbp), %xmm0
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movaps %xmm0, -0x70(%rbp)
xorps %xmm0, %xmm0
cvtss2sd -0x2c(%rbp), %xmm0
addsd 0x263cb(%rip), %xmm0    # 0x30a60
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x60(%rbp)
incq %rbx
movzbl %r15b, %r15d
movss 0x83c(%rax), %xmm0
mulss %xmm6, %xmm0
movss %xmm0, -0x28(%rbp)
movq 0x20(%r14), %rax
movzbl %cl, %ecx
shll $0x5, %ecx
movss 0xc(%rax,%rcx), %xmm3
ucomiss 0x25b6b(%rip), %xmm3    # 0x30238
jne 0xa6d5
jnp 0xa773
addq %rcx, %rax
movss 0x10(%rax), %xmm2
movss 0x14(%rax), %xmm0
mulss %xmm6, %xmm0
addss %xmm1, %xmm0
movss 0x18(%rax), %xmm5
addss %xmm2, %xmm5
mulss -0x80(%rbp), %xmm5
addss -0x30(%rbp), %xmm5
addss -0x50(%rbp), %xmm0
addss -0x70(%rbp), %xmm5
movss %xmm1, -0x24(%rbp)
movaps %xmm3, %xmm1
mulss %xmm6, %xmm1
movaps %xmm2, %xmm4
mulss %xmm6, %xmm4
addss %xmm0, %xmm1
addss %xmm5, %xmm4
addss 0x4(%rax), %xmm3
unpcklps %xmm4, %xmm1            # xmm1 = xmm1[0],xmm4[0],xmm1[1],xmm4[1]
addss 0x8(%rax), %xmm2
unpcklps %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
xorps %xmm4, %xmm4
cvtsi2ssl (%r14), %xmm4
movsd 0x4(%rax), %xmm2
movss -0x60(%rbp), %xmm6
movss %xmm6, (%rsp)
unpcklps %xmm5, %xmm0            # xmm0 = xmm0[0],xmm5[0],xmm0[1],xmm5[1]
movaps -0x90(%rbp), %xmm5
movaps -0xa0(%rbp), %xmm6
movss 0x25ad2(%rip), %xmm7    # 0x30234
movl %r15d, %edi
callq 0x20686
movss -0x24(%rbp), %xmm1
movaps -0x40(%rbp), %xmm6
addss -0x28(%rbp), %xmm1
movb (%rbx), %cl
incq %rbx
testb %cl, %cl
jne 0xa6b6
movl $0x3, %edi
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x21e89