// File: /workspace/github_c_makefile_star2_O3/michaelforney[P]wld/font.c
// Function: wld_font_open_pattern
wld_font *
wld_font_open_pattern(struct wld_font_context *context, FcPattern *match)
{
	char *filename;
	struct font *font;
	FcResult result;
	double pixel_size, aspect;

	font = malloc(sizeof *font);

	if (!font)
		goto error0;

	font->context = context;

	result = FcPatternGetString(match, FC_FILE, 0, (FcChar8 **)&filename);

	if (result == FcResultMatch) {
		FT_Error error;

		DEBUG("Loading font file: %s\n", filename);

		error = FT_New_Face(context->library, filename, 0, &font->face);

		if (error == 0)
			goto load_face;
	}

	result = FcPatternGetFTFace(match, FC_FT_FACE, 0, &font->face);

	if (result != FcResultMatch) {
		DEBUG("Couldn't determine font filename or FreeType face\n");
		goto error1;
	}

load_face:
	result = FcPatternGetDouble(match, FC_PIXEL_SIZE, 0, &pixel_size);

	result = FcPatternGetDouble(match, FC_ASPECT, 0, &aspect);

	if (result == FcResultNoMatch)
		aspect = 1.0;

	if (font->face->face_flags & FT_FACE_FLAG_SCALABLE) {
		FT_F26Dot6 width, height;

		width = ((unsigned int)pixel_size) << 6;
		height = ((unsigned int)(pixel_size * aspect)) << 6;

		FT_Set_Char_Size(font->face, width, height, 0, 0);
	} else {
		FT_Set_Pixel_Sizes(font->face, (unsigned int)pixel_size,
		                   (unsigned int)(pixel_size * aspect));
	}

	font->base.ascent = font->face->size->metrics.ascender >> 6;
	font->base.descent = -font->face->size->metrics.descender >> 6;
	font->base.height = font->base.ascent + font->base.descent;
	font->base.max_advance = font->face->size->metrics.max_advance >> 6;

	font->glyphs = calloc(font->face->num_glyphs, sizeof(struct glyph *));

	return &font->base;

error1:
	free(font);
error0:
	return NULL;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x20, %rsp
movq %rsi, %r14
movq %rdi, %r15
movl $0x28, %edi
callq 0x9570
testq %rax, %rax
je 0xa377
movq %rax, %rbx
movq %r15, 0x10(%rax)
leaq 0x694a(%rip), %rsi      # 0x10b9d
leaq 0x18(%rsp), %rcx
movq %r14, %rdi
xorl %edx, %edx
callq 0x9690
testl %eax, %eax
je 0xa352
movq %rbx, %rcx
addq $0x18, %rcx
leaq 0x695d(%rip), %rsi      # 0x10bd5
movq %r14, %rdi
xorl %edx, %edx
callq 0x95b0
testl %eax, %eax
jne 0xa36f
leaq 0x6984(%rip), %rsi      # 0x10c15
leaq 0x10(%rsp), %rcx
movq %r14, %rdi
xorl %edx, %edx
callq 0x9090
leaq 0x6978(%rip), %rsi      # 0x10c1f
leaq 0x8(%rsp), %rcx
movq %r14, %rdi
xorl %edx, %edx
callq 0x9090
cmpl $0x1, %eax
jne 0xa2ca
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
testb $0x1, 0x10(%rdi)
movsd 0x10(%rsp), %xmm0
cvttsd2si %xmm0, %rsi
jne 0xa2f1
mulsd 0x8(%rsp), %xmm0
cvttsd2si %xmm0, %rdx
callq 0x9100
jmp 0xa30c
mulsd 0x8(%rsp), %xmm0
shll $0x6, %esi
cvttsd2si %xmm0, %rdx
shll $0x6, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x9820
movq 0x18(%rbx), %rax
movq 0xa0(%rax), %rcx
movq 0x30(%rcx), %rdx
shrq $0x6, %rdx
movl %edx, (%rbx)
xorl %esi, %esi
subq 0x38(%rcx), %rsi
shrq $0x6, %rsi
movl %esi, 0x4(%rbx)
addl %edx, %esi
movl %esi, 0x8(%rbx)
movq 0x48(%rcx), %rcx
shrq $0x6, %rcx
movl %ecx, 0xc(%rbx)
movq 0x20(%rax), %rdi
movl $0x8, %esi
callq 0x9440
movq %rax, 0x20(%rbx)
jmp 0xa379
leaq 0x18(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x997e
testb $0x1, %al
je 0xa26a
jmp 0xa28a
movq %rbx, %rdi
callq 0x99d1
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
retq