// File: /workspace/github_c_makefile_star2_O0/odknt[P]st/x.c
// Function: xselectfont
FT_UInt
xselectfont(Rune rune, int frcflags, MatchFont **ret)
{
	FT_UInt glyphidx;
	Font *font = &dc.font;
	FcFontSet *fonts, *fcsets[] = { NULL };
	FcCharSet *fccharset;
	FcPattern *fcpattern;
	FcResult fcres;
	FT_Face face;
	FcChar8 *path;
	int i, f;

	/* Lookup character index with default font. */
	glyphidx = FT_Get_Char_Index(font->match.face, rune);
	if (glyphidx) {
		*ret = &font->match;
		return glyphidx;
	}

	/* Fallback on font cache, search the font cache for match. */
	for (f = 0; f < frclen; f++) {
		glyphidx = FT_Get_Char_Index(frc[f].font.face, rune);
		/* Everything correct. */
		if (glyphidx && frc[f].flags == frcflags)
			break;
		/* We got a default font for a not found glyph. */
		if (!glyphidx && frc[f].flags == frcflags
				&& frc[f].unicodep == rune) {
			break;
		}
	}

	/* Nothing was found. Use fontconfig to find matching font. */
	if (f >= frclen) {
		if (!font->set)
			font->set = FcFontSort(0, font->pattern, 1, 0, &fcres);
		fcsets[0] = font->set;

		/*
		 * Nothing was found in the cache. Now use
		 * some dozen of Fontconfig calls to get the
		 * font for one single character.
		 *
		 * cairo and fontconfig are design failures.
		 */
		fcpattern = FcPatternDuplicate(font->pattern);
		fccharset = FcCharSetCreate();

		FcCharSetAddChar(fccharset, rune);
		FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
		FcPatternAddBool(fcpattern, FC_SCALABLE, 1);
		FcPatternAddBool(fcpattern, FC_COLOR, 1);

		FcConfigSubstitute(0, fcpattern, FcMatchPattern);
		FcDefaultSubstitute(fcpattern);

		fonts = FcFontSort(NULL, fcpattern, 1, NULL, &fcres);
		FcPatternDestroy(fcpattern);
		FcCharSetDestroy(fccharset);
		if (!fonts) {
			*ret = &font->match;
			return glyphidx;
		}

		/* Allocate memory for the new cache entry. */
		if (frclen >= frccap) {
			frccap += 16;
			frc = xrealloc(frc, frccap * sizeof(Fontcache));
		}

		/* veirfy matched font */
		for (i = 0; i < fonts->nfont; i++) {
			fcpattern = fonts->fonts[i];
			FcPatternGetString(fcpattern, FC_FILE, 0, &path);
			if (FT_New_Face(ftlib, (const char *)path, 0, &face))
				die("FT_New_Face failed seeking fallback font: %s\n", path);
			if ((glyphidx = FT_Get_Char_Index(face, rune))) {
				fcpattern = FcPatternDuplicate(fcpattern);
				break;
			}
			FT_Done_Face(face);
			face = NULL;
		}
		FcFontSetDestroy(fonts);
		if (!face) {
			*ret = &font->match;
			return 0;
		}

		frc[frclen].font.face = face;
		frc[frclen].font.cairo = cairo_ft_font_face_create_for_ft_face(
		                         frc[frclen].font.face, FT_LOAD_COLOR);
		frc[frclen].font.pattern = fcpattern;
		frc[frclen].flags = frcflags;
		frc[frclen].unicodep = rune;

		f = frclen;
		frclen++;
	}
	*ret = &frc[f].font;
	return glyphidx;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
leaq 0x1428f(%rip), %rax     # 0x22458
addq $0x10, %rax
movq %rax, -0x28(%rbp)
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x60b0
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rdi
movl -0x8(%rbp), %eax
movl %eax, %esi
callq 0x6890
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0xe216
movq -0x28(%rbp), %rcx
addq $0x20, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xe5d3
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
cmpl 0x14472(%rip), %eax     # 0x22698
jge 0xe2bc
movq 0x1446d(%rip), %rax     # 0x226a0
movslq -0x68(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movl -0x8(%rbp), %eax
movl %eax, %esi
callq 0x6890
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0xe270
movq 0x14445(%rip), %rax     # 0x226a0
movslq -0x68(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0xe270
jmp 0xe2bc
cmpl $0x0, -0x1c(%rbp)
jne 0xe2ac
movq 0x14423(%rip), %rax     # 0x226a0
movslq -0x68(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0xe2ac
movq 0x14409(%rip), %rax     # 0x226a0
movslq -0x68(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
cmpl -0x8(%rbp), %eax
jne 0xe2ac
jmp 0xe2bc
jmp 0xe2ae
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0xe21d
movl -0x68(%rbp), %eax
cmpl 0x143d3(%rip), %eax     # 0x22698
jl 0xe5b4
movq -0x28(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0xe2fe
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rsi
xorl %eax, %eax
movl %eax, %ecx
movl $0x1, %edx
leaq -0x4c(%rbp), %r8
movq %rcx, %rdi
callq 0x66d0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x60e0
movq %rax, -0x48(%rbp)
callq 0x62c0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movl -0x8(%rbp), %esi
callq 0x6040
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq 0x6dba(%rip), %rsi      # 0x150f9
callq 0x6ab0
movq -0x48(%rbp), %rdi
leaq 0x6db2(%rip), %rsi      # 0x15101
movl $0x1, %edx
callq 0x6720
movq -0x48(%rbp), %rdi
leaq 0x6c66(%rip), %rsi      # 0x14fca
movl $0x1, %edx
callq 0x6720
movq -0x48(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
xorl %edx, %edx
callq 0x68e0
movq -0x48(%rbp), %rdi
callq 0x6930
movq -0x48(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
movl $0x1, %edx
leaq -0x4c(%rbp), %r8
movq %rcx, %rdi
callq 0x66d0
movq %rax, -0x30(%rbp)
movq -0x48(%rbp), %rdi
callq 0x6050
movq -0x40(%rbp), %rdi
callq 0x67b0
cmpq $0x0, -0x30(%rbp)
jne 0xe3d6
movq -0x28(%rbp), %rcx
addq $0x20, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xe5d3
movl 0x142bc(%rip), %eax     # 0x22698
cmpl 0x142c6(%rip), %eax     # 0x226a8
jl 0xe411
movl 0x142be(%rip), %eax     # 0x226a8
addl $0x10, %eax
movl %eax, 0x142b5(%rip)     # 0x226a8
movq 0x142a6(%rip), %rdi     # 0x226a0
movslq 0x142a7(%rip), %rsi     # 0x226a8
shlq $0x5, %rsi
callq 0x6cd0
movq %rax, 0x1428f(%rip)     # 0x226a0
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xe4c4
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x64(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
leaq 0x66b1(%rip), %rsi      # 0x14af7
xorl %edx, %edx
leaq -0x60(%rbp), %rcx
callq 0x64b0
movq 0x14258(%rip), %rdi     # 0x226b0
movq -0x60(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
leaq -0x58(%rbp), %rcx
callq 0x6800
cmpl $0x0, %eax
je 0xe480
movq -0x60(%rbp), %rsi
leaq 0x6c91(%rip), %rdi      # 0x1510a
movb $0x0, %al
callq 0x6c20
movq -0x58(%rbp), %rdi
movl -0x8(%rbp), %eax
movl %eax, %esi
callq 0x6890
movl %eax, -0x1c(%rbp)
cmpl $0x0, %eax
je 0xe4a5
movq -0x48(%rbp), %rdi
callq 0x60e0
movq %rax, -0x48(%rbp)
jmp 0xe4c4
movq -0x58(%rbp), %rdi
callq 0x6970
movq $0x0, -0x58(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xe418
movq -0x30(%rbp), %rdi
callq 0x6600
cmpq $0x0, -0x58(%rbp)
jne 0xe4ef
movq -0x28(%rbp), %rcx
addq $0x20, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0xe5d3
movq -0x58(%rbp), %rcx
movq 0x141a6(%rip), %rax     # 0x226a0
movslq 0x14197(%rip), %rdx     # 0x22698
shlq $0x5, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq 0x1418e(%rip), %rax     # 0x226a0
movslq 0x1417f(%rip), %rcx     # 0x22698
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movl $0x100000, %esi         # imm = 0x100000
callq 0x6100
movq %rax, %rcx
movq 0x14169(%rip), %rax     # 0x226a0
movslq 0x1415a(%rip), %rdx     # 0x22698
shlq $0x5, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x48(%rbp), %rcx
movq 0x1414c(%rip), %rax     # 0x226a0
movslq 0x1413d(%rip), %rdx     # 0x22698
shlq $0x5, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movl -0xc(%rbp), %ecx
movq 0x14130(%rip), %rax     # 0x226a0
movslq 0x14121(%rip), %rdx     # 0x22698
shlq $0x5, %rdx
addq %rdx, %rax
movl %ecx, 0x18(%rax)
movl -0x8(%rbp), %ecx
movq 0x14115(%rip), %rax     # 0x226a0
movslq 0x14106(%rip), %rdx     # 0x22698
shlq $0x5, %rdx
addq %rdx, %rax
movl %ecx, 0x1c(%rax)
movl 0x140f6(%rip), %eax     # 0x22698
movl %eax, -0x68(%rbp)
movl 0x140ed(%rip), %eax     # 0x22698
addl $0x1, %eax
movl %eax, 0x140e4(%rip)     # 0x22698
movq 0x140e5(%rip), %rcx     # 0x226a0
movslq -0x68(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)