// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
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 0xc4f0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x8028(%rax), %rax
movq %rax, -0x38(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x26c(%rbp)
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
movl -0x14(%rbp), %r8d
movq -0x38(%rbp), %rax
movq 0x60(%rax), %r9
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
movl $0x1, %esi
movl $0xcc, %edx
xorl %ecx, %ecx
movzwl %ax, %eax
movl %eax, (%rsp)
callq 0xcb60
cmpl $-0x1, 0x10(%rbp)
jne 0xc0c1
movq -0x28(%rbp), %rdi
callq 0x9260
movl %eax, 0x10(%rbp)
jmp 0xc0c3
movq -0x28(%rbp), %rdi
movl 0x10(%rbp), %edx
leaq -0x54(%rbp), %rsi
callq 0x92b0
movl %eax, %ecx
movl %ecx, -0x3c(%rbp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x26d(%rbp)
jle 0xc0f2
cmpl $0x0, -0x54(%rbp)
setne %al
movb %al, -0x26d(%rbp)
movb -0x26d(%rbp), %al
testb $0x1, %al
jne 0xc101
jmp 0xc317
movl -0x3c(%rbp), %ecx
movq -0x28(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x3c(%rbp), %ecx
movl 0x10(%rbp), %eax
subl %ecx, %eax
movl %eax, 0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x54(%rbp), %eax
movl %eax, %esi
callq 0x9660
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movl -0x50(%rbp), %esi
callq 0xa940
testb $0x1, %al
jne 0xc147
jmp 0xc0c3
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x50(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0xc16d
movq -0x48(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xc172
jmp 0xc2fe
leaq -0x260(%rbp), %rax
movq %rax, -0x268(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
jae 0xc1f2
movq -0x268(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rsi
movl -0x4c(%rbp), %eax
movq -0x48(%rbp), %rcx
imull 0x8(%rcx), %eax
movl %eax, %eax
addq %rax, %rsi
movq -0x48(%rbp), %rax
movl 0x4(%rax), %eax
addl $0x7, %eax
shrl $0x3, %eax
movl %eax, %eax
movl %eax, %edx
callq 0x94e0
movq -0x48(%rbp), %rax
movl 0x4(%rax), %ecx
addl $0x7, %ecx
shrl $0x3, %ecx
movq -0x268(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x268(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xc187
jmp 0xc1f4
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rsi
movl -0x26c(%rbp), %eax
movq -0x48(%rbp), %rcx
movswl 0x28(%rcx), %ecx
addl %ecx, %eax
movw %ax, -0x270(%rbp)
movl -0x1c(%rbp), %eax
movq -0x48(%rbp), %rcx
movswl 0x2a(%rcx), %ecx
addl %ecx, %eax
movw %ax, %cx
movl -0x26c(%rbp), %eax
movq -0x48(%rbp), %rdx
movswl 0x28(%rdx), %edx
addl %edx, %eax
movq -0x48(%rbp), %rdx
addl 0x4(%rdx), %eax
movw %ax, %r8w
movl -0x1c(%rbp), %eax
movq -0x48(%rbp), %rdx
movswl 0x2a(%rdx), %edx
addl %edx, %eax
movq -0x48(%rbp), %rdx
addl (%rdx), %eax
movw %ax, %r9w
movq -0x268(%rbp), %rax
leaq -0x260(%rbp), %rdx
subq %rdx, %rax
addq $0x3, %rax
movl $0x4, %r10d
cqto
idivq %r10
movw -0x270(%rbp), %dx
movw %ax, %r10w
leaq -0x260(%rbp), %rax
movswl %dx, %edx
movswl %cx, %ecx
movswl %r8w, %r8d
movswl %r9w, %r9d
movzwl %r10w, %r10d
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xcd20
movl %eax, -0x3c(%rbp)
cmpl $0x1, -0x3c(%rbp)
jne 0xc2fc
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
callq 0xe860
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
movl -0x14(%rbp), %r8d
movq -0x38(%rbp), %rax
movq 0x60(%rax), %r9
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
movl $0x1, %esi
movl $0xcc, %edx
xorl %ecx, %ecx
movzwl %ax, %eax
movl %eax, (%rsp)
callq 0xcb60
jmp 0xc1f4
jmp 0xc2fe
movq -0x48(%rbp), %rax
movzwl 0x2c(%rax), %eax
addl -0x26c(%rbp), %eax
movl %eax, -0x26c(%rbp)
jmp 0xc0c3
cmpq $0x0, 0x18(%rbp)
je 0xc32d
movl -0x26c(%rbp), %ecx
subl -0x18(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
nopw %cs:(%rax,%rax)