// File: /workspace/github_c_makefile_star2_O3/michaelforney[P]wld/intel.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 intel_renderer *renderer = intel_renderer(base);
	struct intel_buffer *dst = renderer->target;
	int ret;
	struct glyph *glyph;
	uint32_t row;
	FT_UInt glyph_index;
	uint32_t c;
	uint8_t immediate[512];
	uint8_t *byte;
	int32_t origin_x = x;

	xy_setup_blt(&renderer->batch, true, BLT_RASTER_OPERATION_SRC,
	             0, color, dst->bo, dst->base.base.pitch);

	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;

		byte = immediate;

		/* XY_TEXT_IMMEDIATE requires a pitch with no extra bytes */
		for (row = 0; row < glyph->bitmap.rows; ++row) {
			memcpy(byte, glyph->bitmap.buffer + (row * glyph->bitmap.pitch),
			       (glyph->bitmap.width + 7) / 8);
			byte += (glyph->bitmap.width + 7) / 8;
		}

	retry:
		ret = xy_text_immediate_blt(&renderer->batch, dst->bo,
		                            origin_x + glyph->x, y + glyph->y,
		                            origin_x + glyph->x + glyph->bitmap.width,
		                            y + glyph->y + glyph->bitmap.rows,
		                            (byte - immediate + 3) / 4,
		                            (uint32_t *)immediate);

		if (ret == INTEL_BATCH_NO_SPACE) {
			intel_batch_flush(&renderer->batch);
			xy_setup_blt(&renderer->batch, true, BLT_RASTER_OPERATION_SRC,
			             0, color, dst->bo, dst->base.base.pitch);
			goto retry;
		}

	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 $0x268, %rsp            # imm = 0x268
movl %r8d, 0x2c(%rsp)
leaq 0xc650(%rip), %rax      # 0x179f0
cmpq %rax, (%rdi)
jne 0xb665
movq %r9, %r14
movl %ecx, %r15d
movl %edx, %r12d
movq %rsi, %r13
movl 0x2a0(%rsp), %ebx
movq 0x8028(%rdi), %rax
movq %rdi, 0x20(%rsp)
addq $0x10, %rdi
movq 0x60(%rax), %rdx
movq %rax, 0x50(%rsp)
movzwl 0x10(%rax), %ecx
movq %rdi, 0x38(%rsp)
movl %r12d, %esi
callq 0xb88f
cmpl $-0x1, %ebx
jne 0xb3f6
movq %r14, %rdi
callq 0x9250
movq %rax, %rbx
movl %r15d, 0xc(%rsp)
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
movl %ebx, %edx
callq 0x92a0
testl %eax, %eax
jle 0xb63d
movl 0x30(%rsp), %esi
testl %esi, %esi
je 0xb63d
movl %eax, %ecx
addq %rcx, %r14
subl %eax, %ebx
movq 0x18(%r13), %rdi
callq 0x9640
movl %eax, %ebp
movq %r13, %rdi
movl %eax, %esi
callq 0xa39c
testb %al, %al
je 0xb3fb
movq 0x20(%r13), %rax
movl %ebp, %ecx
movq (%rax,%rcx,8), %rax
movl 0x4(%rax), %ebp
testl %ebp, %ebp
je 0xb630
cmpl $0x0, (%rax)
je 0xb630
movq %r13, 0x48(%rsp)
movl %r12d, 0x14(%rsp)
movl %r15d, 0x28(%rsp)
xorl %r13d, %r13d
leaq 0x60(%rsp), %r15
movq %rax, 0x18(%rsp)
movq %r15, %r12
movl 0x8(%rax), %esi
imull %r13d, %esi
addq 0x10(%rax), %rsi
addl $0x7, %ebp
shrl $0x3, %ebp
movq %r15, %rdi
movq %rbp, %rdx
callq 0x94c0
movq 0x18(%rsp), %rax
movl (%rax), %esi
movl 0x4(%rax), %ebp
leal 0x7(%rbp), %r15d
shrl $0x3, %r15d
addq %r12, %r15
incl %r13d
cmpl %esi, %r13d
jb 0xb478
leaq 0x60(%rsp), %rax
subq %rax, %r15
leaq 0x3(%r15), %rax
addq $0x6, %r15
testq %rax, %rax
cmovnsq %rax, %r15
sarq $0x2, %r15
leal 0x1(%r15), %eax
andl $0xfe, %eax
movq %rax, 0x40(%rsp)
leal 0x3(%rax), %edx
movl $0x1ffe, %eax           # imm = 0x1FFE
movq 0x20(%rsp), %rcx
subl 0x8020(%rcx), %eax
movl %edx, 0x10(%rsp)
cmpl %edx, %eax
movq 0x50(%rsp), %r13
movq 0x38(%rsp), %r12
jae 0xb54d
movq %r12, %rdi
callq 0xc1bc
movq 0x60(%r13), %rdx
movzwl 0x10(%r13), %ecx
movq %r12, %rdi
movl 0x14(%rsp), %esi
callq 0xb88f
movl $0x1ffe, %eax           # imm = 0x1FFE
movq 0x20(%rsp), %rcx
subl 0x8020(%rcx), %eax
cmpl 0x10(%rsp), %eax
jb 0xb502
movq 0x60(%r13), %rdi
movq 0x18(%rsp), %rdx
movzwl 0x28(%rdx), %eax
movzwl 0x2a(%rdx), %ecx
movl (%rdx), %esi
movl 0x4(%rdx), %ebp
jmp 0xb55e
movq 0x60(%r13), %rdi
movq 0x18(%rsp), %rcx
movzwl 0x28(%rcx), %eax
movzwl 0x2a(%rcx), %ecx
movzwl %cx, %r13d
addl 0x2c(%rsp), %r13d
addl %r13d, %esi
movl %esi, 0x10(%rsp)
movzwl %ax, %r12d
addl 0xc(%rsp), %r12d
addl %r12d, %ebp
leaq 0x34(%rsp), %rsi
leaq 0x5c(%rsp), %rdx
callq 0x9350
xorl %edx, %edx
cmpl $0x0, 0x34(%rsp)
setne %dl
shll $0xb, %edx
addl 0x40(%rsp), %edx
orl $0x4c410001, %edx       # imm = 0x4C410001
shll $0x10, %r13d
movswl %r12w, %ecx
orl %r13d, %ecx
movl 0x10(%rsp), %eax
shll $0x10, %eax
movswl %bp, %r8d
orl %eax, %r8d
movq 0x38(%rsp), %rdi
movl $0x3, %esi
xorl %eax, %eax
callq 0xb7d5
testw %r15w, %r15w
movq 0x48(%rsp), %r13
movq 0x20(%rsp), %r8
je 0xb621
movzwl %r15w, %eax
xorl %ecx, %ecx
movl 0x60(%rsp,%rcx,4), %edx
movl 0x8020(%r8), %esi
leal 0x1(%rsi), %edi
movl %edi, 0x8020(%r8)
movl %edx, 0x20(%r8,%rsi,4)
incq %rcx
cmpl %ecx, %eax
jne 0xb5e0
testb $0x1, %r15b
je 0xb621
movl 0x8020(%r8), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x8020(%r8)
movl $0x0, 0x20(%r8,%rax,4)
movl 0x28(%rsp), %r15d
movl 0x14(%rsp), %r12d
movq 0x18(%rsp), %rax
movzwl 0x2c(%rax), %eax
addl %eax, 0xc(%rsp)
jmp 0xb3fb
movq 0x2a8(%rsp), %rax
testq %rax, %rax
je 0xb653
movl 0xc(%rsp), %ecx
subl %r15d, %ecx
movl %ecx, (%rax)
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x578d(%rip), %rdi      # 0x10df9
leaq 0x570d(%rip), %rsi      # 0x10d80
leaq 0x57a2(%rip), %rcx      # 0x10e1c
movl $0x39, %edx
callq 0x9380