// File: /workspace/github_c_makefile_star2_O2/michaelforney[P]wld/nouveau.c
// Function: renderer_draw_text
void
renderer_draw_text(struct wld_renderer *base,
                   struct font *font, uint32_t color,
                   int32_t x, int32_t y, const char *text,
                   uint32_t length, struct wld_extents *extents)
{
	struct nouveau_renderer *renderer = nouveau_renderer(base);
	struct nouveau_buffer *dst = renderer->target;
	uint32_t format;
	int ret;
	struct glyph *glyph;
	FT_UInt glyph_index;
	uint32_t c, count;
	int32_t origin_x = x;

	if (!ensure_space(renderer->pushbuf, 17))
		return;

	format = nvc0_format(dst->base.base.format);

	nouveau_bufctx_reset(renderer->bufctx, 0);
	nvc0_2d_use_buffer(renderer, dst, G80_2D_DST_FORMAT, format);
	nvc0_2d_inline(renderer->pushbuf, G80_2D_SIFC_BITMAP_ENABLE, 1);
	nvc0_2d(renderer->pushbuf, G80_2D_SIFC_BITMAP_FORMAT, 6,
	        G80_2D_SIFC_BITMAP_FORMAT_I1,
	        0, /* SIFC_FORMAT */
	        G80_2D_SIFC_BITMAP_LINE_PACK_MODE_ALIGN_BYTE,
	        0, color, /* SIFC_BITMAP_COLOR_BIT0, SIFC_BITMAP_COLOR_BIT1 */
	        0         /* SIFC_BITMAP_WRITE_BIT0_ENABLE */
	);
	nouveau_pushbuf_bufctx(renderer->pushbuf, renderer->bufctx);

	if (nouveau_pushbuf_validate(renderer->pushbuf) != 0)
		return;

	if (length == -1)
		length = strlen(text);

	while ((ret = FcUtf8ToUcs4((FcChar8 *)text, &c, length)) > 0 && c != '\0') {
		text += ret;
		length -= ret;
		glyph_index = FT_Get_Char_Index(font->face, c);

		if (!font_ensure_glyph(font, glyph_index))
			continue;

		glyph = font->glyphs[glyph_index];

		if (glyph->bitmap.width == 0 || glyph->bitmap.rows == 0)
			goto advance;

		count = (glyph->bitmap.pitch * glyph->bitmap.rows + 3) / 4;

		if (!ensure_space(renderer->pushbuf, 12 + count))
			return;

		nvc0_2d(renderer->pushbuf, G80_2D_SIFC_WIDTH, 10,
		        /* Use the pitch instead of width to ensure the correct
			 * alignment is used. */
		        glyph->bitmap.pitch * 8, glyph->bitmap.rows,
		        0, 1, 0, 1,
		        0, origin_x + glyph->x, 0, y + glyph->y);
		nv_add_dword(renderer->pushbuf,
		             nvc0_command(GF100_COMMAND_TYPE_NON_INCREASING,
		                          GF100_SUBCHANNEL_2D,
		                          G80_2D_SIFC_DATA, count));
		nv_add_data(renderer->pushbuf, glyph->bitmap.buffer, count);

	advance:
		origin_x += glyph->advance;
	}

	if (extents)
		extents->advance = origin_x - x;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %r14
movl %r8d, 0x20(%rsp)
movl %ecx, 0x14(%rsp)
movl %edx, %ebx
movq %rsi, %r15
movq %rdi, %r12
callq 0xc79d
movq 0x30(%r12), %r13
movq 0x18(%r12), %rdi
pushq $0x11
popq %rsi
callq 0xc021
testb %al, %al
je 0xc679
movl 0x14(%r13), %ebp
xorl %eax, %eax
cmpl $0x34325241, %ebp       # imm = 0x34325241
movq %rbx, 0x8(%rsp)
movl $0xcf, %ebx
cmovnel %eax, %ebx
movq 0x20(%r12), %rdi
xorl %esi, %esi
callq 0x9110
cmpl $0x34325258, %ebp       # imm = 0x34325258
movl $0xe6, %ecx
cmovnel %ebx, %ecx
movq %r12, %rdi
movq %r13, %rsi
movl $0x200, %edx            # imm = 0x200
callq 0xc7cb
movq 0x18(%r12), %rdi
movq 0x30(%rdi), %rax
leaq 0x4(%rax), %rcx
movq %rcx, 0x30(%rdi)
movl $0x80016200, (%rax)     # imm = 0x80016200
pushq $0x6
popq %rcx
xorl %esi, %esi
movl $0x808, %edx            # imm = 0x808
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %eax, %eax
pushq $0x0
pushq 0x10(%rsp)
pushq $0x0
pushq $0x1
callq 0xc04a
addq $0x20, %rsp
movq 0x18(%r12), %rdi
movq 0x20(%r12), %rsi
callq 0x92d0
movq 0x18(%r12), %rdi
callq 0x9460
testl %eax, %eax
jne 0xc679
movl 0x70(%rsp), %r13d
cmpl $-0x1, %r13d
jne 0xc51e
movq %r14, %rdi
callq 0x9250
movq %rax, %r13
leaq 0x24(%rsp), %rbp
movl 0x14(%rsp), %eax
movl %eax, 0x8(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
movl %r13d, %edx
callq 0x92a0
testl %eax, %eax
jle 0xc665
movl 0x24(%rsp), %esi
testl %esi, %esi
je 0xc665
movl %eax, %ecx
addq %rcx, %r14
subl %eax, %r13d
movq 0x18(%r15), %rdi
callq 0x9640
movl %eax, %ebx
movq %r15, %rdi
movl %eax, %esi
callq 0xa181
testb %al, %al
je 0xc52b
movq 0x20(%r15), %rax
movl %ebx, %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x0, 0x4(%rax)
je 0xc658
movl (%rax), %ebx
testl %ebx, %ebx
je 0xc658
movq %rax, 0x18(%rsp)
imull 0x8(%rax), %ebx
addl $0x3, %ebx
movl %ebx, %eax
shrl $0x2, %eax
movq 0x18(%r12), %rdi
movq %rax, 0x28(%rsp)
leal 0xc(%rax), %esi
callq 0xc021
testb %al, %al
je 0xc679
movq 0x18(%r12), %rdi
movq 0x18(%rsp), %rax
movl (%rax), %r9d
movl 0x8(%rax), %r8d
shll $0x3, %r8d
movswl 0x28(%rax), %r10d
addl 0x8(%rsp), %r10d
movswl 0x2a(%rax), %r11d
addl 0x20(%rsp), %r11d
xorl %esi, %esi
movl $0x838, %edx            # imm = 0x838
pushq $0xa
popq %rcx
xorl %eax, %eax
pushq %r11
pushq $0x0
pushq %r10
pushq $0x0
pushq $0x1
popq %r10
pushq %r10
pushq $0x0
pushq %r10
pushq $0x0
callq 0xc04a
addq $0x40, %rsp
movq 0x18(%r12), %rdx
movq %rdx, 0x30(%rsp)
movq 0x28(%rsp), %rax
shll $0x10, %eax
orl $0x60006218, %eax       # imm = 0x60006218
movq 0x30(%rdx), %rcx
leaq 0x4(%rcx), %rdi
movq %rdi, 0x30(%rdx)
movl %eax, (%rcx)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rsi
andl $-0x4, %ebx
movq %rbx, %rdx
callq 0x94c0
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
shll $0x2, %ecx
movq 0x30(%rsp), %rdx
addq %rcx, 0x30(%rdx)
movzwl 0x2c(%rax), %eax
addl %eax, 0x8(%rsp)
jmp 0xc52b
movq 0x78(%rsp), %rax
testq %rax, %rax
je 0xc679
movl 0x8(%rsp), %ecx
subl 0x14(%rsp), %ecx
movl %ecx, (%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq