// File: /workspace/github_c_makefile_star2_O2/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 $0x80, %rsp
movl %edx, %r15d
movss %xmm6, -0x40(%rbp)
movaps %xmm5, -0xa0(%rbp)
movaps %xmm4, -0x90(%rbp)
movss %xmm3, -0x28(%rbp)
movq %rsi, %r12
movaps %xmm2, -0x50(%rbp)
movss %xmm1, -0x2c(%rbp)
movss %xmm0, -0x24(%rbp)
movq %rdi, %rbx
leaq 0x23137(%rip), %rsi     # 0x2c3a5
pushq $0x3
popq %rdi
callq 0x202dd
movq %r12, %rdi
callq 0x202ce
movq %rax, %r14
xorl %ecx, %ecx
testq %rax, %rax
setne %cl
leaq 0x230e1(%rip), %rdi     # 0x2c371
leaq 0x23113(%rip), %rdx     # 0x2c3aa
pushq $0x1b
popq %rsi
callq 0x6903
movaps -0x50(%rbp), %xmm0
xorps %xmm1, %xmm1
movss -0x28(%rbp), %xmm2
ucomiss %xmm1, %xmm2
jne 0x92b2
jnp 0x92cf
movq %rbx, %rdi
movq %r12, %rsi
callq 0x905c
mulss -0x28(%rbp), %xmm0
xorps %xmm1, %xmm1
movss %xmm0, %xmm1            # xmm1 = xmm0[0],xmm1[1,2,3]
movaps %xmm1, -0x60(%rbp)
jmp 0x92d6
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
cmpq $0x0, 0x18(%r14)
movss -0x24(%rbp), %xmm1
je 0x9431
movaps 0x21d53(%rip), %xmm0    # 0x2b040
xorps -0x50(%rbp), %xmm0
movaps %xmm0, -0x70(%rbp)
movaps -0x60(%rbp), %xmm2
cvtss2sd -0x40(%rbp), %xmm0
addsd 0x22732(%rip), %xmm0    # 0x2ba38
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
movaps %xmm2, -0x40(%rbp)
movzbl %r15b, %r15d
movzbl (%rbx), %r12d
testq %r12, %r12
je 0x9547
movsbl %r12b, %edx
movq %r14, %rdi
xorl %esi, %esi
movss %xmm1, -0x24(%rbp)
callq 0x29a5c
movaps -0x50(%rbp), %xmm6
movaps %xmm0, %xmm4
mulss %xmm6, %xmm4
addss -0x24(%rbp), %xmm4
movq 0x20(%r14), %rax
shll $0x5, %r12d
movss 0xc(%rax,%r12), %xmm3
movss 0x14(%rax,%r12), %xmm1
movss 0x1c(%rax,%r12), %xmm0
ucomiss 0x21ebd(%rip), %xmm3    # 0x2b22c
jne 0x9377
jnp 0x941d
addq %r12, %rax
movss 0x10(%rax), %xmm2
movss %xmm0, -0x80(%rbp)
movaps %xmm1, %xmm0
mulss %xmm6, %xmm0
addss %xmm4, %xmm0
movss %xmm4, -0x28(%rbp)
movss 0x18(%rax), %xmm4
addss %xmm2, %xmm4
mulss -0x70(%rbp), %xmm4
addss -0x2c(%rbp), %xmm4
addss -0x60(%rbp), %xmm0
addss -0x40(%rbp), %xmm4
movss %xmm1, -0x24(%rbp)
movaps %xmm3, %xmm1
mulss %xmm6, %xmm1
movaps %xmm2, %xmm5
mulss %xmm6, %xmm5
addss %xmm0, %xmm1
addss %xmm4, %xmm5
unpcklps %xmm5, %xmm1            # xmm1 = xmm1[0],xmm5[0],xmm1[1],xmm5[1]
addss 0x4(%rax), %xmm3
addss 0x8(%rax), %xmm2
unpcklps %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
movl (%r14), %edi
unpcklps %xmm4, %xmm0            # xmm0 = xmm0[0],xmm4[0],xmm0[1],xmm4[1]
movsd 0x4(%rax), %xmm2
movaps -0x90(%rbp), %xmm4
movaps -0xa0(%rbp), %xmm5
movss 0x21e3b(%rip), %xmm6    # 0x2b238
movss -0x30(%rbp), %xmm7
movl %r15d, %esi
callq 0x20213
movss -0x80(%rbp), %xmm0
movss -0x28(%rbp), %xmm4
movss -0x24(%rbp), %xmm1
movaps -0x50(%rbp), %xmm6
incq %rbx
addss %xmm0, %xmm1
mulss %xmm6, %xmm1
addss %xmm4, %xmm1
jmp 0x931b
movq 0x20(%r14), %rax
movaps 0x21c04(%rip), %xmm0    # 0x2b040
movaps -0x50(%rbp), %xmm6
xorps %xmm6, %xmm0
movaps %xmm0, -0x80(%rbp)
movaps -0x60(%rbp), %xmm2
cvtss2sd -0x40(%rbp), %xmm0
addsd 0x225e0(%rip), %xmm0    # 0x2ba38
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
movaps %xmm2, -0x70(%rbp)
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x40(%rbp)
movzbl %r15b, %r15d
movss 0x83c(%rax), %xmm0
mulss %xmm6, %xmm0
movss %xmm0, -0x28(%rbp)
movzbl (%rbx), %ecx
testq %rcx, %rcx
je 0x9547
movq 0x20(%r14), %rax
shll $0x5, %ecx
movss 0xc(%rax,%rcx), %xmm3
ucomiss 0x21d8e(%rip), %xmm3    # 0x2b22c
jne 0x94a6
jnp 0x953a
addq %rcx, %rax
movss 0x10(%rax), %xmm2
movss 0x14(%rax), %xmm0
mulss %xmm6, %xmm0
addss %xmm1, %xmm0
movss 0x18(%rax), %xmm4
addss %xmm2, %xmm4
mulss -0x80(%rbp), %xmm4
addss -0x2c(%rbp), %xmm4
addss -0x60(%rbp), %xmm0
addss -0x70(%rbp), %xmm4
movss %xmm1, -0x24(%rbp)
movaps %xmm3, %xmm1
mulss %xmm6, %xmm1
movaps %xmm2, %xmm5
mulss %xmm6, %xmm5
addss %xmm0, %xmm1
addss %xmm4, %xmm5
unpcklps %xmm5, %xmm1            # xmm1 = xmm1[0],xmm5[0],xmm1[1],xmm5[1]
addss 0x4(%rax), %xmm3
addss 0x8(%rax), %xmm2
unpcklps %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
movl (%r14), %edi
unpcklps %xmm4, %xmm0            # xmm0 = xmm0[0],xmm4[0],xmm0[1],xmm4[1]
movsd 0x4(%rax), %xmm2
movaps -0x90(%rbp), %xmm4
movaps -0xa0(%rbp), %xmm5
movss 0x21d14(%rip), %xmm6    # 0x2b238
movss -0x40(%rbp), %xmm7
movl %r15d, %esi
callq 0x20213
movss -0x24(%rbp), %xmm1
movaps -0x50(%rbp), %xmm6
incq %rbx
addss -0x28(%rbp), %xmm1
jmp 0x947e
pushq $0x3
popq %rdi
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x20365