// File: /workspace/github_c_makefile_star2_O0/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
subq $0x1e0, %rsp            # imm = 0x1E0
movb %dl, %al
movlpd %xmm4, -0x10(%rbp)
movlpd %xmm5, -0x8(%rbp)
movq %rdi, -0x18(%rbp)
movss %xmm0, -0x1c(%rbp)
movss %xmm1, -0x20(%rbp)
movss %xmm2, -0x24(%rbp)
movq %rsi, -0x30(%rbp)
movss %xmm3, -0x34(%rbp)
movss %xmm6, -0x38(%rbp)
movb %al, -0x39(%rbp)
leaq 0x368ab(%rip), %rsi     # 0x4639d
movl $0x3, %edi
callq 0x2e590
movq -0x30(%rbp), %rdi
callq 0x2e570
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
testq %rax, %rax
setne %al
movzbl %al, %ecx
leaq 0x3684c(%rip), %rdi     # 0x46369
leaq 0x3687e(%rip), %rdx     # 0x463a2
movl $0x1b, %esi
callq 0xb210
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0xbc10
movlpd %xmm0, -0x50(%rbp)
movss -0x34(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0xfb4f
jp 0xfb4f
jmp 0xfb9c
movss -0x34(%rbp), %xmm0
movss %xmm0, -0x1c4(%rbp)
movq -0x18(%rbp), %rdi
movss -0x24(%rbp), %xmm0
movq -0x30(%rbp), %rsi
callq 0xf7f0
movaps %xmm0, %xmm1
movss -0x1c4(%rbp), %xmm0
movlpd %xmm1, -0x60(%rbp)
movss -0x60(%rbp), %xmm1
mulss %xmm1, %xmm0
xorps %xmm1, %xmm1
callq 0xbc10
movlpd %xmm0, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0xfe40
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x820(%rax), %rcx
movq %rcx, -0x80(%rbp)
movq 0x828(%rax), %rcx
movq %rcx, -0x78(%rbp)
movq 0x830(%rax), %rcx
movq %rcx, -0x70(%rbp)
movq 0x838(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
cmpb $0x0, (%rax)
je 0xfe3b
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movb (%rax), %al
movb %al, -0x81(%rbp)
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movzbl -0x81(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0xa4(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x9c(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x94(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x8c(%rbp)
movss -0x98(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0xfc5b
jp 0xfc5b
jmp 0xfe1a
movss -0x1c(%rbp), %xmm1
movss -0x90(%rbp), %xmm0
movss -0x24(%rbp), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0xac(%rbp)
movss -0x20(%rbp), %xmm0
movss -0x94(%rbp), %xmm1
movss -0x8c(%rbp), %xmm2
addss %xmm2, %xmm1
movss -0x24(%rbp), %xmm2
mulss %xmm2, %xmm1
subss %xmm1, %xmm0
movss %xmm0, -0xa8(%rbp)
movss -0xa0(%rbp), %xmm0
movss %xmm0, -0xb4(%rbp)
movss -0x9c(%rbp), %xmm0
movss %xmm0, -0xb0(%rbp)
movss -0x98(%rbp), %xmm0
movss %xmm0, -0xbc(%rbp)
movss -0x94(%rbp), %xmm0
movss %xmm0, -0xb8(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0xd0(%rbp)
movsd -0xd0(%rbp), %xmm0
leaq -0xac(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x40dc0
movq -0x1d0(%rbp), %rdi
movlpd %xmm0, -0xc4(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0xe8(%rbp)
movsd -0xe8(%rbp), %xmm0
callq 0x40dc0
movlpd %xmm0, -0xe0(%rbp)
movss -0x24(%rbp), %xmm0
leaq -0xbc(%rbp), %rdi
callq 0x5810
movlpd %xmm0, -0xf0(%rbp)
movsd -0xf0(%rbp), %xmm0
leaq -0xe0(%rbp), %rdi
callq 0x40dc0
movlpd %xmm0, -0xd8(%rbp)
movq -0xb4(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xbc(%rbp), %rax
movq %rax, -0x108(%rbp)
movsd -0x108(%rbp), %xmm0
leaq -0xb4(%rbp), %rdi
callq 0x40dc0
movlpd %xmm0, -0x100(%rbp)
movq -0x48(%rbp), %rax
movl (%rax), %edi
movups -0x10(%rbp), %xmm0
movaps %xmm0, -0x120(%rbp)
movss -0x38(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x35c71(%rip), %xmm1    # 0x45a40
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm7
movb -0x39(%rbp), %al
movsd -0xc4(%rbp), %xmm0
movsd -0xd8(%rbp), %xmm1
movsd -0xf8(%rbp), %xmm2
movsd -0x100(%rbp), %xmm3
movsd -0x120(%rbp), %xmm4
movsd -0x118(%rbp), %xmm5
movzbl %al, %esi
movss 0x35407(%rip), %xmm6    # 0x4521c
callq 0x2e350
movss -0x64(%rbp), %xmm0
movss -0x24(%rbp), %xmm2
movss -0x1c(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x1c(%rbp)
jmp 0xfbdf
jmp 0x100f0
movb $0x0, -0x121(%rbp)
movq -0x18(%rbp), %rax
cmpb $0x0, (%rax)
je 0x100ee
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movb (%rax), %al
movb %al, -0x122(%rbp)
movq -0x48(%rbp), %rdi
movb -0x121(%rbp), %al
movsbl %al, %esi
movsbl -0x122(%rbp), %edx
callq 0x42110
movss %xmm0, -0x128(%rbp)
movss -0x128(%rbp), %xmm0
movss -0x24(%rbp), %xmm2
movss -0x1c(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x1c(%rbp)
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movzbl -0x122(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x148(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x140(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x138(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x130(%rbp)
movss -0x13c(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0xff03
jp 0xff03
jmp 0x100c2
movss -0x1c(%rbp), %xmm1
movss -0x134(%rbp), %xmm0
movss -0x24(%rbp), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x150(%rbp)
movss -0x20(%rbp), %xmm0
movss -0x138(%rbp), %xmm1
movss -0x130(%rbp), %xmm2
addss %xmm2, %xmm1
movss -0x24(%rbp), %xmm2
mulss %xmm2, %xmm1
subss %xmm1, %xmm0
movss %xmm0, -0x14c(%rbp)
movss -0x144(%rbp), %xmm0
movss %xmm0, -0x158(%rbp)
movss -0x140(%rbp), %xmm0
movss %xmm0, -0x154(%rbp)
movss -0x13c(%rbp), %xmm0
movss %xmm0, -0x160(%rbp)
movss -0x138(%rbp), %xmm0
movss %xmm0, -0x15c(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x170(%rbp)
movsd -0x170(%rbp), %xmm0
leaq -0x150(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x40dc0
movq -0x1d8(%rbp), %rdi
movlpd %xmm0, -0x168(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x188(%rbp)
movsd -0x188(%rbp), %xmm0
callq 0x40dc0
movlpd %xmm0, -0x180(%rbp)
movss -0x24(%rbp), %xmm0
leaq -0x160(%rbp), %rdi
callq 0x5810
movlpd %xmm0, -0x190(%rbp)
movsd -0x190(%rbp), %xmm0
leaq -0x180(%rbp), %rdi
callq 0x40dc0
movlpd %xmm0, -0x178(%rbp)
movq -0x158(%rbp), %rax
movq %rax, -0x198(%rbp)
movq -0x160(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movsd -0x1a8(%rbp), %xmm0
leaq -0x158(%rbp), %rdi
callq 0x40dc0
movlpd %xmm0, -0x1a0(%rbp)
movq -0x48(%rbp), %rax
movl (%rax), %edi
movups -0x10(%rbp), %xmm0
movaps %xmm0, -0x1c0(%rbp)
movss -0x38(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x359c9(%rip), %xmm1    # 0x45a40
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm7
movb -0x39(%rbp), %al
movsd -0x168(%rbp), %xmm0
movsd -0x178(%rbp), %xmm1
movsd -0x198(%rbp), %xmm2
movsd -0x1a0(%rbp), %xmm3
movsd -0x1c0(%rbp), %xmm4
movsd -0x1b8(%rbp), %xmm5
movzbl %al, %esi
movss 0x3515f(%rip), %xmm6    # 0x4521c
callq 0x2e350
movss -0x12c(%rbp), %xmm0
addss -0x134(%rbp), %xmm0
movss -0x24(%rbp), %xmm2
movss -0x1c(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x1c(%rbp)
jmp 0xfe47
jmp 0x100f0
movl $0x3, %edi
callq 0x2e670
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
nopw %cs:(%rax,%rax)