// File: /workspace/github_c_makefile_star2_O3/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
movq $0x0, 0x10(%rsp)
movq %rsi, %rdi
callq 0x60e0
movl $0x1, %ebp
testq %rax, %rax
je 0xf19a
movq %rax, %r15
movq 0x10705(%rip), %rax     # 0x1f7f0
movq 0xe8(%rax), %rax
movslq 0x107e7(%rip), %rcx     # 0x1f8e0
shlq $0x7, %rcx
cvtsi2sdl 0x1c(%rax,%rcx), %xmm0
mulsd 0x2b9d(%rip), %xmm0     # 0x11ca8
cvtsi2sdl 0x24(%rax,%rcx), %xmm1
divsd %xmm1, %xmm0
leaq 0x3079(%rip), %rsi      # 0x12195
movq %r15, %rdi
callq 0x6180
xorl %edi, %edi
movq %r15, %rsi
xorl %edx, %edx
callq 0x68c0
movq %r15, %rdi
callq 0x6910
leaq 0x24(%rsp), %rdx
xorl %edi, %edi
movq %r15, %rsi
callq 0x61e0
testq %rax, %rax
je 0xf192
movq %rax, %r12
leaq 0x271f(%rip), %rsi      # 0x11875
leaq 0x10(%rsp), %rcx
movq %rax, %rdi
xorl %edx, %edx
callq 0x64b0
cmpl $0x1, %eax
je 0xf185
movq 0x1079f(%rip), %rdi     # 0x1f910
movq 0x10(%rsp), %rsi
leaq 0x20(%rbx), %rcx
xorl %edx, %edx
callq 0x67f0
testl %eax, %eax
je 0xf1a9
movq %r15, %rdi
callq 0x6050
movq %r12, %rdi
jmp 0xf195
movq %r15, %rdi
callq 0x6050
movl %ebp, %eax
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq $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 0x2fb6(%rip), %rsi      # 0x12188
leaq 0xc(%rsp), %rcx
movq %r14, %rdi
xorl %edx, %edx
callq 0x66c0
testl %eax, %eax
jne 0xf220
movq 0x30(%rbx), %rdi
leaq 0x2f98(%rip), %rsi      # 0x12188
leaq 0x8(%rsp), %rcx
xorl %edx, %edx
callq 0x66c0
testl %eax, %eax
jne 0xf384
movl 0x8(%rsp), %eax
cmpl 0xc(%rsp), %eax
jl 0xf384
movq 0x28(%rbx), %rdi
movl $0x2, %esi
callq 0x69b0
leaq 0x2f67(%rip), %rsi      # 0x1218e
xorl %ebp, %ebp
leaq 0xc(%rsp), %rcx
movq %r14, %rdi
xorl %edx, %edx
callq 0x66c0
testl %eax, %eax
jne 0xf277
movq 0x30(%rbx), %rdi
leaq 0x2f47(%rip), %rsi      # 0x1218e
leaq 0x8(%rsp), %rcx
xorl %edx, %edx
callq 0x66c0
testl %eax, %eax
jne 0xf391
movl 0x8(%rsp), %eax
cmpl 0xc(%rsp), %eax
jne 0xf391
movq 0x28(%rbx), %rdi
movl $0x1, %esi
callq 0x69b0
movq 0x30(%rbx), %rdi
leaq 0x2efc(%rip), %rsi      # 0x1217e
leaq 0x28(%rsp), %r14
xorl %edx, %edx
movq %r14, %rcx
callq 0x61c0
movq 0x105c8(%rip), %rdi     # 0x1f860
movsd (%r14), %xmm0
callq 0x64e0
movq 0x105b7(%rip), %rdi     # 0x1f860
movq 0x28(%rbx), %rsi
callq 0x6450
movq 0x105a7(%rip), %rdi     # 0x1f860
leaq 0x9e10(%rip), %r14      # 0x190d0
leaq 0x30(%rsp), %r15
movq %r14, %rsi
movq %r15, %rdx
callq 0x6930
movsd 0x8(%r15), %xmm0
movsd 0x18(%r15), %xmm1
movapd 0x29dc(%rip), %xmm2     # 0x11cc0
xorpd %xmm0, %xmm2
addsd %xmm1, %xmm0
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
cvttpd2dq %xmm2, %xmm0
movlpd %xmm0, 0x8(%rbx)
movw $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 0x2997(%rip), %xmm1     # 0x11cd0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x299b(%rip), %xmm2     # 0x11ce0
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 0xf19a
movq %rbx, %rdi
callq 0x6f03
jmp 0xf220
movq %rbx, %rdi
callq 0x6f26
jmp 0xf277