// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x28, %edi
callq 0x9590
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xa6ca
jmp 0xa8fd
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rdi
leaq 0xa4c9(%rip), %rsi      # 0x14baa
xorl %edx, %edx
leaq -0x20(%rbp), %rcx
callq 0x96b0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0xa741
movq 0x118f4(%rip), %rax     # 0x1bff0
movq (%rax), %rdi
movq -0x20(%rbp), %rcx
leaq 0xa4a5(%rip), %rsi      # 0x14baf
leaq 0xa4bb(%rip), %rdx      # 0x14bcc
movb $0x0, %al
callq 0x94a0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rcx
addq $0x18, %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x9320
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0xa73f
jmp 0xa78a
jmp 0xa741
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rcx
addq $0x18, %rcx
leaq 0xa48e(%rip), %rsi      # 0x14be2
xorl %edx, %edx
callq 0x95d0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0xa788
movq 0x11885(%rip), %rax     # 0x1bff0
movq (%rax), %rdi
leaq 0xa474(%rip), %rsi      # 0x14be9
leaq 0xa450(%rip), %rdx      # 0x14bcc
movb $0x0, %al
callq 0x94a0
jmp 0xa8f4
jmp 0xa78a
movq -0x18(%rbp), %rdi
leaq 0xa48d(%rip), %rsi      # 0x14c22
xorl %edx, %edx
leaq -0x38(%rbp), %rcx
callq 0x9090
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rdi
leaq 0xa47e(%rip), %rsi      # 0x14c2c
xorl %edx, %edx
leaq -0x40(%rbp), %rcx
callq 0x9090
movl %eax, -0x2c(%rbp)
cmpl $0x1, -0x2c(%rbp)
jne 0xa7cf
movsd 0xa35e(%rip), %xmm0     # 0x14b28
movsd %xmm0, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0xa82b
cvttsd2si -0x38(%rbp), %rax
shll $0x6, %eax
movq %rax, -0x50(%rbp)
movsd -0x38(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
shll $0x6, %eax
movl %eax, %eax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdx
xorl %r8d, %r8d
movl %r8d, %ecx
callq 0x9840
jmp 0xa854
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
movsd -0x38(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movl %eax, %esi
movsd -0x40(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, %edx
callq 0x9110
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq 0xa0(%rax), %rax
movq 0x30(%rax), %rax
sarq $0x6, %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq 0xa0(%rax), %rcx
xorl %eax, %eax
subq 0x38(%rcx), %rax
sarq $0x6, %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rax
movl (%rax), %ecx
movq -0x28(%rbp), %rax
addl 0x4(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq 0xa0(%rax), %rax
movq 0x48(%rax), %rax
sarq $0x6, %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rdi
movl $0x8, %esi
callq 0x9460
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xa905
movq -0x28(%rbp), %rdi
callq 0x9060
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nop