// File: /workspace/github_c_makefile_star2_O1/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 0x26d18(%rip), %rsi     # 0x313dd
movl $0x3, %edi
callq 0x22084
movq %r12, %rdi
movl $0x2, %esi
callq 0x234d6
movq %rax, %r14
xorl %ecx, %ecx
testq %rax, %rax
setne %cl
leaq 0x26cbb(%rip), %rdi     # 0x313a9
leaq 0x26ced(%rip), %rdx     # 0x313e2
movl $0x1b, %esi
callq 0x722f
movaps -0x40(%rbp), %xmm0
xorps %xmm1, %xmm1
movss -0x28(%rbp), %xmm2
ucomiss %xmm1, %xmm2
jne 0xa712
jnp 0xa72f
movq %rbx, %rdi
movq %r12, %rsi
callq 0xa46d
mulss -0x28(%rbp), %xmm0
xorps %xmm1, %xmm1
movss %xmm0, %xmm1            # xmm1 = xmm0[0],xmm1[1,2,3]
movaps %xmm1, -0x50(%rbp)
jmp 0xa736
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
cmpq $0x0, 0x18(%r14)
movss -0x24(%rbp), %xmm1
je 0xa8ae
movb (%rbx), %al
testb %al, %al
movaps -0x40(%rbp), %xmm0
je 0xa9da
movaps 0x258e5(%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 0x262f2(%rip), %xmm0    # 0x30a70
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 0x2e42e
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 0x25a60(%rip), %xmm3    # 0x30238
jne 0xa7e0
jnp 0xa890
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 0x259bf(%rip), %xmm7    # 0x30234
movl %r15d, %edi
callq 0x2095d
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 0xa78e
jmp 0xa9da
movb (%rbx), %cl
testb %cl, %cl
movaps -0x40(%rbp), %xmm6
je 0xa9da
movq 0x20(%r14), %rax
movaps 0x25779(%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 0x26186(%rip), %xmm0    # 0x30a70
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 0x25916(%rip), %xmm3    # 0x30238
jne 0xa92a
jnp 0xa9c8
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 0x2587d(%rip), %xmm7    # 0x30234
movl %r15d, %edi
callq 0x2095d
movss -0x24(%rbp), %xmm1
movaps -0x40(%rbp), %xmm6
addss -0x28(%rbp), %xmm1
movb (%rbx), %cl
incq %rbx
testb %cl, %cl
jne 0xa90b
movl $0x3, %edi
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x22154