// File: /workspace/github_c_makefile_star2_O1/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 $0x278, %rsp            # imm = 0x278
movl %r8d, 0x2c(%rsp)
leaq 0xc648(%rip), %rax      # 0x179f0
cmpq %rax, (%rdi)
jne 0xb666
movq %r9, %r14
movl %ecx, %ebx
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %r13
movl 0x2b0(%rsp), %r15d
movq 0x8028(%rdi), %rax
addq $0x10, %rdi
movq 0x60(%rax), %rdx
movq %rax, 0x40(%rsp)
movzwl 0x10(%rax), %ecx
movq %rdi, 0x48(%rsp)
movl %ebp, %esi
callq 0xb890
movq %r15, 0x18(%rsp)
cmpl $-0x1, %r15d
jne 0xb402
movq %r14, %rdi
callq 0x9250
movq %rax, 0x18(%rsp)
movl %ebx, 0x24(%rsp)
movl %ebx, 0x4(%rsp)
movq 0x18(%rsp), %rbx
movq %r14, %rdi
leaq 0x38(%rsp), %rsi
movl %ebx, %edx
callq 0x92a0
testl %eax, %eax
jle 0xb63d
movl 0x38(%rsp), %esi
testl %esi, %esi
je 0xb63d
movl %eax, %ecx
addq %rcx, %r14
subl %eax, %ebx
movq 0x18(%r12), %rdi
callq 0x9640
movl %eax, %r15d
movq %r12, %rdi
movl %eax, %esi
callq 0xa3b4
testb %al, %al
je 0xb40f
movq %rbx, 0x18(%rsp)
movq %r14, 0x58(%rsp)
movq %r12, 0x50(%rsp)
movq 0x20(%r12), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
cmpl $0x0, 0x4(%rax)
je 0xb621
movq 0x8(%rsp), %rax
cmpl $0x0, (%rax)
je 0xb621
movq 0x8(%rsp), %rax
cmpl $0x0, (%rax)
leaq 0x70(%rsp), %r14
movq %r14, %r15
je 0xb4db
xorl %ebx, %ebx
movq %r14, %r12
movl 0x8(%rax), %esi
imull %ebx, %esi
addq 0x10(%rax), %rsi
movl 0x4(%rax), %edx
addl $0x7, %edx
shrl $0x3, %edx
movq %r12, %rdi
callq 0x94c0
movq 0x8(%rsp), %rax
movl 0x4(%rax), %r15d
addl $0x7, %r15d
shrl $0x3, %r15d
addq %r12, %r15
incl %ebx
movq %r15, %r12
cmpl (%rax), %ebx
jb 0xb4a3
subq %r14, %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, 0x60(%rsp)
addl $0x3, %eax
movl %eax, 0x14(%rsp)
movzwl %r15w, %r12d
movq 0x40(%rsp), %rbx
movl %ebp, 0x28(%rsp)
movl $0x1ffe, %eax           # imm = 0x1FFE
subl 0x8020(%r13), %eax
cmpl 0x14(%rsp), %eax
jb 0xb5fd
movl %eax, 0x34(%rsp)
movq 0x60(%rbx), %rdi
movq 0x8(%rsp), %rax
movzwl 0x28(%rax), %ebx
movzwl 0x2a(%rax), %ebp
addl 0x2c(%rsp), %ebp
movl (%rax), %r14d
addl %ebp, %r14d
addl 0x4(%rsp), %ebx
movl 0x4(%rax), %eax
addl %ebx, %eax
movl %eax, 0x30(%rsp)
leaq 0x3c(%rsp), %rsi
leaq 0x6c(%rsp), %rdx
callq 0x9350
xorl %edx, %edx
cmpl $0x0, 0x3c(%rsp)
setne %dl
shll $0xb, %edx
addl 0x60(%rsp), %edx
orl $0x4c410001, %edx       # imm = 0x4C410001
shll $0x10, %ebp
movswl %bx, %ecx
orl %ebp, %ecx
shll $0x10, %r14d
movswl 0x30(%rsp), %r8d
orl %r14d, %r8d
movq 0x48(%rsp), %rdi
movl $0x3, %esi
xorl %eax, %eax
callq 0xb7d6
testq %r12, %r12
je 0xb5ca
xorl %eax, %eax
movl 0x70(%rsp,%rax,4), %ecx
movl 0x8020(%r13), %edx
leal 0x1(%rdx), %esi
movl %esi, 0x8020(%r13)
movl %ecx, 0x20(%r13,%rdx,4)
incq %rax
cmpl %eax, %r12d
jne 0xb5a8
testb $0x1, %r15b
movl 0x28(%rsp), %ebp
je 0xb5ee
movl 0x8020(%r13), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x8020(%r13)
movl $0x0, 0x20(%r13,%rax,4)
movl 0x34(%rsp), %eax
cmpl 0x14(%rsp), %eax
movq 0x40(%rsp), %rbx
jae 0xb621
movq 0x48(%rsp), %r14
movq %r14, %rdi
callq 0xc1c4
movq 0x60(%rbx), %rdx
movzwl 0x10(%rbx), %ecx
movq %r14, %rdi
movl %ebp, %esi
callq 0xb890
jmp 0xb513
movq 0x8(%rsp), %rax
movzwl 0x2c(%rax), %eax
addl %eax, 0x4(%rsp)
movq 0x58(%rsp), %r14
movq 0x50(%rsp), %r12
jmp 0xb40a
movq 0x2b8(%rsp), %rax
testq %rax, %rax
je 0xb654
movl 0x4(%rsp), %ecx
subl 0x24(%rsp), %ecx
movl %ecx, (%rax)
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x578c(%rip), %rdi      # 0x10df9
leaq 0x570c(%rip), %rsi      # 0x10d80
leaq 0x57a1(%rip), %rcx      # 0x10e1c
movl $0x39, %edx
callq 0x9380