// File: /workspace/github_c_makefile_star2_O1/justinmeiners[P]text2image/text2image.c
// Function: render_text
void render_text(stbtt_fontinfo* font_info,
                 unsigned char* bitmap,
                 int* w,
                 float scale,
                 const char* text,
                 size_t text_size)
                
{
    int ascent, descent, line_gap;
    stbtt_GetFontVMetrics(font_info, &ascent, &descent, &line_gap);
    
    ascent *= scale;
    descent *= scale;

    int x = 0;
    for (int i = 0; i < text_size; ++i)
    {
        if (iscntrl(text[i])) continue;

        int c_x1, c_y1, c_x2, c_y2;
        stbtt_GetCodepointBitmapBox(font_info, text[i], scale, scale, &c_x1, &c_y1, &c_x2, &c_y2);
        
        int y = ascent + c_y1;
        
        /* render character (stride and offset is important here) */
        if (bitmap)
        {
            int offset = x + (y * (*w));
            stbtt_MakeCodepointBitmap(font_info, bitmap + offset, c_x2 - c_x1, c_y2 - c_y1, *w, scale, scale, text[i]);
        }
       
        int ax;
        stbtt_GetCodepointHMetrics(font_info, text[i], &ax, 0);
        x += ax * scale;
        
        int kern = stbtt_GetCodepointKernAdvance(font_info, text[i], text[i + 1]);
        x += kern * scale;
    }

    *w = x;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, 0x28(%rsp)
testq %r8, %r8
je 0x9dd4
movq %r8, %rbx
movq %rcx, %r14
movq %rsi, %rbp
movq %rdi, %r13
movq 0x8(%rdi), %rax
movslq 0x24(%rdi), %rcx
movzwl 0x4(%rax,%rcx), %eax
rolw $0x8, %ax
cwtl
cvtsi2ss %eax, %xmm1
movss %xmm0, 0xc(%rsp)
mulss %xmm0, %xmm1
cvttss2si %xmm1, %eax
movq %rax, 0x50(%rsp)
xorl %r15d, %r15d
callq 0x1220
movq %rax, %r12
xorl %ecx, %ecx
movq %rbx, 0x60(%rsp)
movq %rbp, 0x58(%rsp)
movq %rax, 0x48(%rsp)
movq (%r12), %rax
movsbq (%r14,%r15), %rsi
testb $0x2, (%rax,%rsi,2)
jne 0x9dc6
movq %r13, %rdi
movl %ecx, 0x30(%rsp)
callq 0x356a
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
movq %r13, %rdi
movl %eax, %esi
movss 0xc(%rsp), %xmm0
movaps %xmm0, %xmm1
leaq 0x24(%rsp), %rdx
leaq 0x20(%rsp), %rcx
leaq 0x1c(%rsp), %r8
leaq 0x18(%rsp), %r9
callq 0x4e29
testq %rbp, %rbp
je 0x9d56
movl 0x20(%rsp), %eax
movq 0x50(%rsp), %rcx
addl %eax, %ecx
movq 0x28(%rsp), %rdx
movl (%rdx), %edx
movl %edx, 0x10(%rsp)
imull %edx, %ecx
addl 0x30(%rsp), %ecx
movslq %ecx, %r12
movq %r14, %rbx
movl 0x1c(%rsp), %r14d
subl 0x24(%rsp), %r14d
addq %rbp, %r12
movl 0x18(%rsp), %ebp
subl %eax, %ebp
movsbl (%rbx,%r15), %esi
movq %r13, %rdi
callq 0x356a
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
movq %r13, %rdi
movq %r12, %rsi
movq 0x48(%rsp), %r12
movl %r14d, %edx
movq %rbx, %r14
movl %ebp, %ecx
movq 0x58(%rsp), %rbp
movl 0x10(%rsp), %r8d
movq 0x60(%rsp), %rbx
movss 0xc(%rsp), %xmm0
movaps %xmm0, %xmm1
movl %eax, %r9d
callq 0x629d
movsbl (%r14,%r15), %esi
movq %r13, %rdi
callq 0x356a
movq %r13, %rdi
movl %eax, %esi
leaq 0x14(%rsp), %rdx
xorl %ecx, %ecx
callq 0x44fd
xorps %xmm1, %xmm1
cvtsi2ssl 0x14(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtsi2ssl 0x30(%rsp), %xmm0
mulss 0xc(%rsp), %xmm1
addss %xmm0, %xmm1
movaps %xmm1, 0x30(%rsp)
movsbl (%r14,%r15), %esi
movsbl 0x1(%r14,%r15), %edx
movq %r13, %rdi
callq 0x4b77
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
cvttps2dq 0x30(%rsp), %xmm1
cvtdq2ps %xmm1, %xmm1
mulss 0xc(%rsp), %xmm0
addss %xmm1, %xmm0
cvttss2si %xmm0, %ecx
incq %r15
cmpq %r15, %rbx
jne 0x9c89
jmp 0x9dd6
xorl %ecx, %ecx
movq 0x28(%rsp), %rax
movl %ecx, (%rax)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq