// File: /workspace/github_c_makefile_star2_O2/michaelforney[P]wld/pixman.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 pixman_renderer *renderer = pixman_renderer(base);
	int ret;
	uint32_t c;
	struct glyph *glyph;
	FT_UInt glyph_index;
	pixman_glyph_t *glyphs;
	uint32_t index = 0, origin_x = 0;
	pixman_color_t pixman_color = PIXMAN_COLOR(color);
	pixman_image_t *solid;

	if (length == -1)
		length = strlen(text);
	glyphs = malloc(length * sizeof(glyphs[0]));
	if (!glyphs)
		return;
	solid = pixman_image_create_solid_fill(&pixman_color);

	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];

		glyphs[index].x = origin_x;
		glyphs[index].y = 0;
		glyphs[index].glyph = pixman_glyph_cache_lookup(renderer->glyph_cache,
		                                                font, glyph);

		/* If we don't have the glyph in our cache, do some conversions to make
		 * pixman happy, and then insert it. */
		if (!glyphs[index].glyph) {
			uint8_t *src, *dst;
			uint32_t row, byte_index, bytes_per_row, pitch;
			pixman_image_t *image;
			FT_Bitmap *bitmap;

			bitmap = &glyph->bitmap;
			image = pixman_image_create_bits(PIXMAN_a1, bitmap->width, bitmap->rows, NULL, bitmap->pitch);

			if (!image)
				goto advance;

			pitch = pixman_image_get_stride(image);
			bytes_per_row = (bitmap->width + 7) / 8;
			src = bitmap->buffer;
			dst = (uint8_t *)pixman_image_get_data(image);

			for (row = 0; row < bitmap->rows; ++row) {
				/* Pixman's A1 format expects the bits in the opposite order
				 * that Freetype gives us. Sigh... */
				for (byte_index = 0; byte_index < bytes_per_row; ++byte_index)
					dst[byte_index] = reverse(src[byte_index]);

				dst += pitch;
				src += bitmap->pitch;
			}

			/* Insert the glyph into the cache. */
			pixman_glyph_cache_freeze(renderer->glyph_cache);
			glyphs[index].glyph = pixman_glyph_cache_insert(renderer->glyph_cache, font, glyph,
			                                                -glyph->x, -glyph->y, image);
			pixman_glyph_cache_thaw(renderer->glyph_cache);

			/* The glyph cache copies the contents of the glyph bitmap. */
			pixman_image_unref(image);
		}

		++index;

	advance:
		origin_x += glyph->advance;
	}

	pixman_composite_glyphs_no_mask(PIXMAN_OP_OVER, solid, renderer->target,
	                                0, 0, x, y, renderer->glyph_cache,
	                                index, glyphs);

	free(glyphs);
	pixman_image_unref(solid);

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %r15
movl %r8d, %ebp
movl %ecx, %r14d
movl %edx, %ebx
movq %rsi, %r12
movl 0x90(%rsp), %r13d
movq %rdi, 0x18(%rsp)
callq 0xd048
movl %ebx, %eax
shrl $0x10, %eax
movl $0xff, %ecx
andl %ecx, %eax
movzbl %bh, %edx
andl %ebx, %ecx
shrl $0x18, %ebx
movd %eax, %xmm0
pinsrw $0x1, %edx, %xmm0
pinsrw $0x2, %ecx, %xmm0
pinsrw $0x3, %ebx, %xmm0
pmullw 0x471a(%rip), %xmm0     # 0x114d0
movq %xmm0, 0x50(%rsp)
cmpl $-0x1, %r13d
jne 0xcdcd
movq %r15, %rdi
callq 0x9250
movq %rax, %r13
movl %r13d, %edi
shlq $0x4, %rdi
callq 0x9570
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0xd01d
movq %rbp, 0x48(%rsp)
movl %r14d, 0x24(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x90a0
movq %rax, 0x40(%rsp)
xorl %ebp, %ebp
leaq 0xc(%rsp), %rbx
movq $0x0, (%rsp)
movq %r15, %rdi
movq %rbx, %rsi
movl %r13d, %edx
callq 0x92a0
testl %eax, %eax
jle 0xcfc5
movl 0xc(%rsp), %esi
testl %esi, %esi
je 0xcfc5
movl %eax, %ecx
addq %rcx, %r15
subl %eax, %r13d
movq 0x18(%r12), %rdi
callq 0x9640
movl %eax, %r14d
movq %r12, %rdi
movl %eax, %esi
callq 0xa181
testb %al, %al
je 0xce0f
movq 0x20(%r12), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %r14
movq %rbp, %rax
movl (%rsp), %ebp
shlq $0x4, %rbp
movq 0x10(%rsp), %rbx
movq %rax, 0x38(%rsp)
movl %eax, (%rbx,%rbp)
andl $0x0, 0x4(%rbx,%rbp)
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x9530
movq %rax, 0x8(%rbx,%rbp)
movq (%rsp), %rbx
testq %rax, %rax
jne 0xcfa3
movl (%r14), %edx
movl 0x4(%r14), %esi
movl 0x8(%r14), %r8d
movl $0x1011000, %edi        # imm = 0x1011000
xorl %ecx, %ecx
callq 0x9670
testq %rax, %rax
je 0xcfbf
addq 0x10(%rsp), %rbp
movq %rbp, 0x30(%rsp)
movq %rax, %rdi
movq %rax, 0x28(%rsp)
callq 0x9510
movl %eax, 0x20(%rsp)
movl 0x4(%r14), %ebx
addl $0x7, %ebx
shrl $0x3, %ebx
movq 0x10(%r14), %rbp
movq 0x28(%rsp), %rdi
callq 0x97a0
movl 0x20(%rsp), %ecx
xorl %edx, %edx
cmpl (%r14), %edx
jae 0xcf51
xorl %esi, %esi
cmpq %rsi, %rbx
je 0xcf43
movb (%rbp,%rsi), %dil
rolb $0x4, %dil
movl %edi, %r8d
andb $0x33, %r8b
shlb $0x2, %r8b
shrb $0x2, %dil
andb $0x33, %dil
orb %r8b, %dil
movl %edi, %r8d
andb $0x55, %r8b
addb %r8b, %r8b
shrb %dil
andb $0x55, %dil
orb %r8b, %dil
movb %dil, (%rax,%rsi)
incq %rsi
jmp 0xcf02
addq %rcx, %rax
movslq 0x8(%r14), %rsi
addq %rsi, %rbp
incl %edx
jmp 0xcefb
movq 0x18(%rsp), %rbx
movq 0x18(%rbx), %rdi
callq 0x9660
movq 0x18(%rbx), %rdi
movswl 0x28(%r14), %ecx
negl %ecx
movswl 0x2a(%r14), %r8d
negl %r8d
movq %r12, %rsi
movq %r14, %rdx
movq 0x28(%rsp), %rbp
movq %rbp, %r9
callq 0x9560
movq 0x30(%rsp), %rcx
movq %rax, 0x8(%rcx)
movq 0x18(%rbx), %rdi
callq 0x9280
movq %rbp, %rdi
callq 0x93e0
movq (%rsp), %rbx
incl %ebx
movq %rbx, (%rsp)
movzwl 0x2c(%r14), %eax
movq 0x38(%rsp), %rbp
addl %eax, %ebp
leaq 0xc(%rsp), %rbx
jmp 0xce0f
movq (%rsp), %rbx
jmp 0xcfa5
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rdx
pushq $0x3
popq %rdi
movq 0x40(%rsp), %r15
movq %r15, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
movl 0x24(%rsp), %r9d
movq 0x10(%rsp), %r14
pushq %r14
pushq 0x8(%rsp)
pushq 0x18(%rax)
pushq 0x60(%rsp)
callq 0x92e0
addq $0x20, %rsp
movq %r14, %rdi
callq 0x9060
movq %r15, %rdi
callq 0x93e0
movq 0x98(%rsp), %rax
testq %rax, %rax
je 0xd01d
movl %ebp, (%rax)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq