// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xb0, %rsp
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movq %r9, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0xfaf0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x38(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x11, %esi
callq 0xef60
testb $0x1, %al
jne 0xf612
jmp 0xf8b0
movq -0x38(%rbp), %rax
movl 0x14(%rax), %edi
callq 0xfb40
movl %eax, -0x3c(%rbp)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdi
xorl %esi, %esi
callq 0x9120
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x3c(%rbp), %eax
movl $0x200, %edx            # imm = 0x200
movzwl %ax, %ecx
callq 0xfb80
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x3, %esi
movl $0x800, %edx            # imm = 0x800
movl $0x1, %ecx
callq 0xf090
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x14(%rbp), %eax
movl $0x3, %esi
movl $0x808, %edx            # imm = 0x808
movl $0x6, %ecx
xorl %r9d, %r9d
movl %r9d, %r8d
movl $0x1, (%rsp)
movl $0x0, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movl $0x0, 0x18(%rsp)
movb $0x0, %al
callq 0xefc0
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x92e0
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x9480
cmpl $0x0, %eax
je 0xf6d2
jmp 0xf8b0
cmpl $-0x1, 0x10(%rbp)
jne 0xf6e4
movq -0x28(%rbp), %rdi
callq 0x9260
movl %eax, 0x10(%rbp)
jmp 0xf6e6
movq -0x28(%rbp), %rdi
movl 0x10(%rbp), %edx
leaq -0x50(%rbp), %rsi
callq 0x92b0
movl %eax, %ecx
movl %ecx, -0x40(%rbp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x59(%rbp)
jle 0xf70f
cmpl $0x0, -0x50(%rbp)
setne %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0xf71b
jmp 0xf89d
movl -0x40(%rbp), %ecx
movq -0x28(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x40(%rbp), %ecx
movl 0x10(%rbp), %eax
subl %ecx, %eax
movl %eax, 0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x50(%rbp), %eax
movl %eax, %esi
callq 0x9660
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0xa940
testb $0x1, %al
jne 0xf75e
jmp 0xf6e6
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0xf784
movq -0x48(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xf789
jmp 0xf88a
movq -0x48(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x48(%rbp), %rcx
imull (%rcx), %eax
addl $0x3, %eax
shrl $0x2, %eax
movl %eax, -0x54(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x54(%rbp), %esi
addl $0xc, %esi
callq 0xef60
testb $0x1, %al
jne 0xf7bc
jmp 0xf8b0
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x48(%rbp), %rax
movl 0x8(%rax), %r8d
shll $0x3, %r8d
movq -0x48(%rbp), %rax
movl (%rax), %r9d
movl -0x58(%rbp), %r10d
movq -0x48(%rbp), %rax
movswl 0x28(%rax), %eax
addl %eax, %r10d
movl -0x1c(%rbp), %eax
movq -0x48(%rbp), %rcx
movswl 0x2a(%rcx), %ecx
addl %ecx, %eax
movl $0x3, %esi
movl $0x838, %edx            # imm = 0x838
movl $0xa, %ecx
xorl %r11d, %r11d
movl $0x0, (%rsp)
movl $0x1, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
movl $0x1, 0x18(%rsp)
movl $0x0, 0x20(%rsp)
movl %r10d, 0x28(%rsp)
movl $0x0, 0x30(%rsp)
movl %eax, 0x38(%rsp)
movb $0x0, %al
callq 0xefc0
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x68(%rbp)
movl -0x54(%rbp), %eax
movl $0x3, %esi
movl $0x860, %edx            # imm = 0x860
movl %esi, %edi
movzwl %ax, %ecx
callq 0xf120
movq -0x68(%rbp), %rdi
movl %eax, %esi
callq 0xf0f0
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rsi
movl -0x54(%rbp), %edx
callq 0xfcf0
movq -0x48(%rbp), %rax
movzwl 0x2c(%rax), %eax
addl -0x58(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0xf6e6
cmpq $0x0, 0x18(%rbp)
je 0xf8b0
movl -0x58(%rbp), %ecx
subl -0x18(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)