// File: /workspace/github_c_makefile_star2_O1/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 0xeb3a
movq %rax, %r15
movq 0xfd75(%rip), %rax      # 0x1e800
movq 0xe8(%rax), %rax
movslq 0xfe57(%rip), %rcx      # 0x1e8f0
shlq $0x7, %rcx
cvtsi2sdl 0x1c(%rax,%rcx), %xmm0
mulsd 0x21dd(%rip), %xmm0     # 0x10c88
cvtsi2sdl 0x24(%rax,%rcx), %xmm1
divsd %xmm1, %xmm0
leaq 0x26b9(%rip), %rsi      # 0x11175
movq %r15, %rdi
callq 0x6180
xorl %edi, %edi
movq %r15, %rsi
xorl %edx, %edx
callq 0x68e0
movq %r15, %rdi
callq 0x6930
leaq 0x24(%rsp), %rdx
xorl %edi, %edi
movq %r15, %rsi
callq 0x61e0
testq %rax, %rax
je 0xeb32
movq %rax, %r12
leaq 0x1d51(%rip), %rsi      # 0x10847
leaq 0x10(%rsp), %rcx
movq %rax, %rdi
xorl %edx, %edx
callq 0x64b0
cmpl $0x1, %eax
je 0xeb25
movq 0xfe0f(%rip), %rdi      # 0x1e920
movq 0x10(%rsp), %rsi
leaq 0x20(%rbx), %rcx
xorl %edx, %edx
callq 0x6800
testl %eax, %eax
je 0xeb49
movq %r15, %rdi
callq 0x6050
movq %r12, %rdi
jmp 0xeb35
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 0x25f6(%rip), %rsi      # 0x11168
leaq 0xc(%rsp), %rcx
movq %r14, %rdi
xorl %edx, %edx
callq 0x66c0
testl %eax, %eax
jne 0xebc0
movq 0x30(%rbx), %rdi
leaq 0x25d8(%rip), %rsi      # 0x11168
leaq 0x8(%rsp), %rcx
xorl %edx, %edx
callq 0x66c0
testl %eax, %eax
jne 0xed25
movl 0x8(%rsp), %eax
cmpl 0xc(%rsp), %eax
jl 0xed25
movq 0x28(%rbx), %rdi
movl $0x2, %esi
callq 0x69d0
leaq 0x25a7(%rip), %rsi      # 0x1116e
xorl %ebp, %ebp
leaq 0xc(%rsp), %rcx
movq %r14, %rdi
xorl %edx, %edx
callq 0x66c0
testl %eax, %eax
jne 0xec17
movq 0x30(%rbx), %rdi
leaq 0x2587(%rip), %rsi      # 0x1116e
leaq 0x8(%rsp), %rcx
xorl %edx, %edx
callq 0x66c0
testl %eax, %eax
jne 0xed32
movl 0x8(%rsp), %eax
cmpl 0xc(%rsp), %eax
jne 0xed32
movq 0x28(%rbx), %rdi
movl $0x1, %esi
callq 0x69d0
movq 0x30(%rbx), %rdi
leaq 0x253c(%rip), %rsi      # 0x1115e
leaq 0x28(%rsp), %r14
xorl %edx, %edx
movq %r14, %rcx
callq 0x61c0
movq 0xfc38(%rip), %rdi      # 0x1e870
movsd (%r14), %xmm0
callq 0x64e0
movq 0xfc27(%rip), %rdi      # 0x1e870
movq 0x28(%rbx), %rsi
callq 0x6450
movq 0xfc17(%rip), %rdi      # 0x1e870
leaq 0x9480(%rip), %r14      # 0x180e0
leaq 0x30(%rsp), %r15
movq %r14, %rsi
movq %r15, %rdx
callq 0x6950
movsd 0x8(%r15), %xmm0
movapd 0x2022(%rip), %xmm1     # 0x10ca0
xorpd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movl %eax, 0x8(%rbx)
movsd 0x18(%r15), %xmm1
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0xc(%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 0x1fd6(%rip), %xmm1     # 0x10cb0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x1fda(%rip), %xmm2     # 0x10cc0
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 0xeb3a
movq %rbx, %rdi
callq 0x6f23
jmp 0xebc0
movq %rbx, %rdi
callq 0x6f46
jmp 0xec17