// File: /workspace/github_c_makefile_star2_O3/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
movl %r8d, 0x10(%rsp)
movl %ecx, 0xc(%rsp)
leaq 0xae19(%rip), %rax      # 0x17a90
cmpq %rax, (%rdi)
jne 0xcf8f
movq %r9, %r14
movl %edx, %r13d
movq %rsi, %r15
movq %rdi, %r12
movq 0x30(%rdi), %rbx
movq 0x18(%rdi), %rdi
movq 0x38(%rdi), %rax
subq 0x30(%rdi), %rax
cmpq $0x44, %rax
jg 0xccb8
movl $0x11, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x9860
testl %eax, %eax
jne 0xcf80
movl 0x14(%rbx), %ebp
movq 0x20(%r12), %rdi
xorl %esi, %esi
callq 0x9110
cmpl $0x34325241, %ebp       # imm = 0x34325241
movl $0x80cf6080, %eax       # imm = 0x80CF6080
movl $0x80006080, %ecx       # imm = 0x80006080
cmovel %eax, %ecx
cmpl $0x34325258, %ebp       # imm = 0x34325258
movl $0x80e66080, %edx       # imm = 0x80E66080
cmovnel %ecx, %edx
movq 0x18(%r12), %rdi
movq 0x30(%rdi), %rax
leaq 0x4(%rax), %rcx
movq %rcx, 0x30(%rdi)
movl %edx, (%rax)
movq 0x68(%rbx), %rcx
cmpl $0x0, 0x30(%rcx)
je 0xcd21
movl 0x34(%rcx), %r9d
xorl %esi, %esi
movl $0x204, %edx            # imm = 0x204
movl $0x2, %ecx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0xc655
jmp 0xcd47
leaq 0x8(%rax), %rcx
movq %rcx, 0x30(%rdi)
movl $0x80016081, 0x4(%rax)  # imm = 0x80016081
movl 0x10(%rbx), %r8d
xorl %esi, %esi
movl $0x214, %edx            # imm = 0x214
movl $0x1, %ecx
xorl %eax, %eax
callq 0xc655
movq 0x18(%r12), %rdi
movl 0x8(%rbx), %r8d
movl 0xc(%rbx), %r9d
movq 0x68(%rbx), %rax
movq 0x20(%rax), %r10
xorl %ebp, %ebp
xorl %esi, %esi
movl $0x218, %edx            # imm = 0x218
movl $0x4, %ecx
xorl %eax, %eax
pushq %r10
shrq $0x20, %r10
pushq %r10
callq 0xc655
addq $0x10, %rsp
movq 0x20(%r12), %rdi
movq 0x68(%rbx), %rdx
xorl %esi, %esi
movl $0x201, %ecx            # imm = 0x201
callq 0x95c0
movq 0x18(%r12), %rdi
movq 0x30(%rdi), %rax
leaq 0x4(%rax), %rcx
movq %rcx, 0x30(%rdi)
movl $0x80016200, (%rax)     # imm = 0x80016200
xorl %esi, %esi
movl $0x808, %edx            # imm = 0x808
movl $0x6, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %eax, %eax
pushq %rbp
pushq %r13
pushq %rbp
pushq $0x1
callq 0xc655
addq $0x20, %rsp
movq 0x18(%r12), %rdi
movq 0x20(%r12), %rsi
callq 0x92d0
movq 0x18(%r12), %rdi
callq 0x9460
testl %eax, %eax
jne 0xcf80
movl 0x70(%rsp), %r13d
cmpl $-0x1, %r13d
jne 0xce03
movq %r14, %rdi
callq 0x9250
movq %rax, %r13
leaq 0x14(%rsp), %rbp
movl 0xc(%rsp), %eax
movl %eax, 0x8(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
movl %r13d, %edx
callq 0x92a0
testl %eax, %eax
jle 0xcf6c
movl 0x14(%rsp), %esi
testl %esi, %esi
je 0xcf6c
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 0xa39c
testb %al, %al
je 0xce10
movq 0x20(%r15), %rax
movl %ebx, %ecx
movq (%rax,%rcx,8), %rbx
cmpl $0x0, 0x4(%rbx)
je 0xcf5f
movl (%rbx), %r9d
testl %r9d, %r9d
je 0xcf5f
movl 0x8(%rbx), %r8d
movl %r8d, %eax
imull %r9d, %eax
addl $0x3, %eax
movq %rax, 0x28(%rsp)
shrl $0x2, %eax
movq 0x18(%r12), %rdi
movq %rax, 0x30(%rsp)
leal 0xc(%rax), %esi
movq 0x38(%rdi), %rax
subq 0x30(%rdi), %rax
sarq $0x2, %rax
cmpq %rsi, %rax
jg 0xcec4
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x9860
testl %eax, %eax
jne 0xcf80
movq 0x18(%r12), %rdi
movl (%rbx), %r9d
movl 0x8(%rbx), %r8d
shll $0x3, %r8d
movswl 0x28(%rbx), %r10d
addl 0x8(%rsp), %r10d
movswl 0x2a(%rbx), %r11d
addl 0x10(%rsp), %r11d
xorl %esi, %esi
movl $0x838, %edx            # imm = 0x838
movl $0xa, %ecx
xorl %eax, %eax
pushq %r11
xorl %r11d, %r11d
pushq %r11
pushq %r10
pushq %r11
movl $0x1, %r10d
pushq %r10
pushq %r11
pushq %r10
pushq %r11
callq 0xc655
addq $0x40, %rsp
movq 0x18(%r12), %rdx
movq %rdx, 0x20(%rsp)
movq %rbx, 0x18(%rsp)
movq 0x30(%rsp), %rbx
movl %ebx, %eax
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
movq 0x28(%rsp), %rdx
andl $-0x4, %edx
callq 0x94c0
shll $0x2, %ebx
movq 0x20(%rsp), %rax
addq %rbx, 0x30(%rax)
movq 0x18(%rsp), %rbx
movzwl 0x2c(%rbx), %eax
addl %eax, 0x8(%rsp)
jmp 0xce10
movq 0x78(%rsp), %rax
testq %rax, %rax
je 0xcf80
movl 0x8(%rsp), %ecx
subl 0xc(%rsp), %ecx
movl %ecx, (%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3e63(%rip), %rdi      # 0x10df9
leaq 0x4463(%rip), %rsi      # 0x11400
leaq 0x44df(%rip), %rcx      # 0x11483
movl $0x4b, %edx
callq 0x9380