// File: /workspace/github_c_makefile_star2_O2/odknt[P]st/x.c
// Function: xloadfont
int
xloadfont(Font *f, FcPattern *pattern)
{
	FcPattern *configured = NULL;
	FcPattern *match = NULL;
	FcResult result;
	FcChar8 *path = NULL;
	double fontsize;
	cairo_text_extents_t extents;
	int wantattr, haveattr;
	double dpi;

	/*
	 * Manually configure so that we can use the configured pattern
	 * for "missing glyph" lookups.
	 */
	configured = FcPatternDuplicate(pattern);
	if (!configured)
		return 1;

	/* get dpi and set to pattern */
	dpi = (((double)DisplayHeight(xw.dpy, xw.scr) * 25.4) /
	      (double)DisplayHeightMM(xw.dpy, xw.scr));
	FcPatternAddDouble(configured, FC_DPI, dpi);

	FcConfigSubstitute(NULL, configured, FcMatchPattern);
	FcDefaultSubstitute(configured);

	match = FcFontMatch(NULL, configured, &result);
	if (!match) {
		FcPatternDestroy(configured);
		return 1;
	}

	if (FcPatternGetString(match, FC_FILE, 0, &path) == FcResultNoMatch) {
		FcPatternDestroy(configured);
		FcPatternDestroy(match);
		return 1;
	}

	if (FT_New_Face(ftlib, (const char *)path, 0, &f->match.face)) {
		FcPatternDestroy(configured);
		FcPatternDestroy(match);
		return 1;
	}

	/* initialize font data */
	f->set = NULL;
	f->pattern = configured;
	f->match.pattern = match;
	f->match.cairo = cairo_ft_font_face_create_for_ft_face(
	                 f->match.face, FT_LOAD_COLOR);

	if ((FcPatternGetInteger(pattern, FC_SLANT, 0, &wantattr) ==
	    FcResultMatch)) {
		/*
		 * Check if fontconfig was unable to find a font with
		 * the appropriate slant but gave us one anyway.
		 * Try to mitigate.
		 */
		if ((FcPatternGetInteger(f->match.pattern, FC_SLANT, 0,
		    &haveattr) != FcResultMatch) || haveattr < wantattr) {
			f->badslant = 1;
			fputs("font slant does not match\n", stderr);
		} else {
			/* synthesize to oblique font */
			cairo_ft_font_face_set_synthesize(f->match.cairo,
			                                  CAIRO_FT_SYNTHESIZE_OBLIQUE);
		}
	}

	if ((FcPatternGetInteger(pattern, FC_WEIGHT, 0, &wantattr) ==
	    FcResultMatch)) {
		if ((FcPatternGetInteger(f->match.pattern, FC_WEIGHT, 0,
		    &haveattr) != FcResultMatch) || haveattr != wantattr) {
			f->badweight = 1;
			fputs("font weight does not match\n", stderr);
		} else {
			/* synthesize to bold font */
			cairo_ft_font_face_set_synthesize(f->match.cairo,
			                                  CAIRO_FT_SYNTHESIZE_BOLD);
		}
	}

	FcPatternGetDouble(f->match.pattern, FC_PIXEL_SIZE, 0, &fontsize);
	cairo_set_font_size(xw.draw, fontsize);
	cairo_set_font_face(xw.draw, f->match.cairo);
	cairo_text_extents(xw.draw, ascii_printable, &extents);

	f->ascent = -extents.y_bearing;
	f->descent = extents.height + extents.y_bearing;
	f->lbearing = 0;
	f->rbearing = f->match.face->max_advance_width;
	f->height = extents.height;
	f->width = DIVCEIL(extents.x_advance, strlen(ascii_printable));

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x60, %rsp
movq %rsi, %r14
movq %rdi, %rbx
andq $0x0, 0x10(%rsp)
movq %rsi, %rdi
callq 0x60e0
pushq $0x1
popq %rbp
testq %rax, %rax
je 0xe0a3
movq %rax, %r15
movq 0x1080c(%rip), %rax     # 0x1e800
movq 0xe8(%rax), %rax
movslq 0x108ee(%rip), %rcx     # 0x1e8f0
shlq $0x7, %rcx
cvtsi2sdl 0x1c(%rax,%rcx), %xmm0
mulsd 0x2c64(%rip), %xmm0     # 0x10c78
cvtsi2sdl 0x24(%rax,%rcx), %xmm1
divsd %xmm1, %xmm0
leaq 0x3140(%rip), %rsi      # 0x11165
movq %r15, %rdi
callq 0x6180
xorl %edi, %edi
movq %r15, %rsi
xorl %edx, %edx
callq 0x68d0
movq %r15, %rdi
callq 0x6920
leaq 0x24(%rsp), %rdx
xorl %edi, %edi
movq %r15, %rsi
callq 0x61e0
testq %rax, %rax
je 0xe09b
movq %rax, %r12
leaq 0x27e6(%rip), %rsi      # 0x10845
leaq 0x10(%rsp), %rcx
movq %rax, %rdi
xorl %edx, %edx
callq 0x64b0
cmpl $0x1, %eax
je 0xe08e
movq 0x108a6(%rip), %rdi     # 0x1e920
movq 0x10(%rsp), %rsi
leaq 0x20(%rbx), %rcx
xorl %edx, %edx
callq 0x67f0
testl %eax, %eax
je 0xe0b2
movq %r15, %rdi
callq 0x6050
movq %r12, %rdi
jmp 0xe09e
movq %r15, %rdi
callq 0x6050
movl %ebp, %eax
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
andq $0x0, 0x38(%rbx)
movq %r15, 0x40(%rbx)
movq %r12, 0x30(%rbx)
movq 0x20(%rbx), %rdi
movl $0x100000, %esi         # imm = 0x100000
callq 0x6100
movq %rax, 0x28(%rbx)
leaq 0x3080(%rip), %rsi      # 0x11158
leaq 0xc(%rsp), %rcx
movq %r14, %rdi
xorl %edx, %edx
callq 0x66c0
testl %eax, %eax
jne 0xe124
movq 0x30(%rbx), %rdi
leaq 0x3062(%rip), %rsi      # 0x11158
leaq 0x8(%rsp), %rcx
xorl %edx, %edx
callq 0x66c0
testl %eax, %eax
jne 0xe285
movl 0x8(%rsp), %eax
cmpl 0xc(%rsp), %eax
jl 0xe285
movq 0x28(%rbx), %rdi
pushq $0x2
popq %rsi
callq 0x69c0
leaq 0x3033(%rip), %rsi      # 0x1115e
xorl %ebp, %ebp
leaq 0xc(%rsp), %rcx
movq %r14, %rdi
xorl %edx, %edx
callq 0x66c0
testl %eax, %eax
jne 0xe179
movq 0x30(%rbx), %rdi
leaq 0x3013(%rip), %rsi      # 0x1115e
leaq 0x8(%rsp), %rcx
xorl %edx, %edx
callq 0x66c0
testl %eax, %eax
jne 0xe2a7
movl 0x8(%rsp), %eax
cmpl 0xc(%rsp), %eax
jne 0xe2a7
movq 0x28(%rbx), %rdi
pushq $0x1
popq %rsi
callq 0x69c0
movq 0x30(%rbx), %rdi
leaq 0x2fca(%rip), %rsi      # 0x1114e
leaq 0x28(%rsp), %r14
xorl %edx, %edx
movq %r14, %rcx
callq 0x61c0
movq 0x106d6(%rip), %rdi     # 0x1e870
movsd (%r14), %xmm0
callq 0x64e0
movq 0x106c5(%rip), %rdi     # 0x1e870
movq 0x28(%rbx), %rsi
callq 0x6450
movq 0x106b5(%rip), %rdi     # 0x1e870
leaq 0x9f1e(%rip), %r14      # 0x180e0
leaq 0x30(%rsp), %r15
movq %r14, %rsi
movq %r15, %rdx
callq 0x6940
movsd 0x8(%r15), %xmm0
movsd 0x18(%r15), %xmm1
movapd 0x2aaa(%rip), %xmm2     # 0x10c90
xorpd %xmm0, %xmm2
addsd %xmm1, %xmm0
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
cvttpd2dq %xmm2, %xmm0
movlpd %xmm0, 0x8(%rbx)
andw $0x0, 0x18(%rbx)
movq 0x20(%rbx), %rax
movzwl 0x90(%rax), %eax
movw %ax, 0x1a(%rbx)
cvttsd2si %xmm1, %eax
movl %eax, (%rbx)
movsd 0x20(%r15), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r14, %rdi
callq 0x6410
leaq -0x1(%rax), %rcx
movq %rcx, %xmm0
movq 0x2a66(%rip), %xmm1     # 0x10ca0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x2a6a(%rip), %xmm2     # 0x10cb0
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
addsd 0x18(%rsp), %xmm3
movq %rax, %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
divsd %xmm1, %xmm3
cvttsd2si %xmm3, %eax
movl %eax, 0x4(%rbx)
jmp 0xe0a3
movl $0x1, 0x10(%rbx)
movq 0x8d5d(%rip), %rax      # 0x16ff0
movq (%rax), %rsi
leaq 0x2ecc(%rip), %rdi      # 0x11169
callq 0x65c0
jmp 0xe124
movl $0x1, 0x14(%rbx)
movq 0x8d3b(%rip), %rax      # 0x16ff0
movq (%rax), %rsi
leaq 0x2ec5(%rip), %rdi      # 0x11184
callq 0x65c0
jmp 0xe179