// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Trio.cpp
// Function: yak_ch_restore_core(yak_ch_t*, char const*, int, ...)
static yak_ch_t *yak_ch_restore_core(yak_ch_t *ch0, const char *fn, int mode, ...)
{
	va_list ap;
	FILE *fp;
	uint32_t t[3], f_tmp = 0;
	char magic[4];
	int i, j, absent, min_cnt = 0, mid_cnt = 0, mode_err = 0;
	uint64_t mask = (1ULL<<YAK_COUNTER_BITS) - 1, n_ins = 0, n_new = 0;
	yak_ch_t *ch;

	va_start(ap, mode);
	if (mode == YAK_LOAD_ALL) { // do nothing
	} else if (mode == YAK_LOAD_TRIOBIN1 || mode == YAK_LOAD_TRIOBIN2) {
		assert(YAK_COUNTER_BITS >= 4);
		min_cnt = va_arg(ap, int);
		mid_cnt = va_arg(ap, int);
		if (ch0 == 0 && mode == YAK_LOAD_TRIOBIN2)
			mode_err = 1;
	} else mode_err = 1;
	va_end(ap);
	if (mode_err) return 0;

	if ((fp = fopen(fn, "rb")) == 0) return 0;
	if (fread(magic, 1, 4, fp) != 4) return 0;
	if (strncmp(magic, YAK_MAGIC, 4) != 0) {
		fprintf(stderr, "ERROR: wrong file magic.\n");
		fclose(fp);
		return 0;
	}
	f_tmp += fread(t, 4, 3, fp);
	if (t[2] != YAK_COUNTER_BITS) {
		fprintf(stderr, "ERROR: saved counter bits: %d; compile-time counter bits: %d\n", t[2], YAK_COUNTER_BITS);
		fclose(fp);
		return 0;
	}
	///t[0] = k; t[1] = pre, t[2] = YAK_COUNTER_BITS;
	ch = ch0 == 0? yak_ch_init(t[0], t[1]) : ch0;
	assert((int)t[0] == ch->k && (int)t[1] == ch->pre);
	for (i = 0; i < 1<<ch->pre; ++i) {
		yak_ht_t *h = ch->h[i].h;
		f_tmp += fread(t, 4, 2, fp);
		///t[0] = kh_capacity(h), t[1] = kh_size(h);
		if (ch0 == 0) yak_ht_resize(h, t[0]);
		for (j = 0; j < (int)t[1]; ++j) {
			uint64_t key;
			f_tmp += fread(&key, 8, 1, fp);
			if (mode == YAK_LOAD_ALL) {
				++n_ins;
				yak_ht_put(h, key, &absent);
				if (absent) ++n_new;
			} else if (mode == YAK_LOAD_TRIOBIN1 || mode == YAK_LOAD_TRIOBIN2) {
				int cnt = key & mask, x, shift = mode == YAK_LOAD_TRIOBIN1? 0 : 2;
				//1. filter singleton k-mer; 2. label non-repeat and repeat
				if (cnt >= mid_cnt) x = 2<<shift;
				else if (cnt >= min_cnt) x = 1<<shift;
				else x = -1;
				if (x >= 0) {
					khint_t k;
					///no need cnt at all
					key = (key & ~mask) | x;
					++n_ins;
					k = yak_ht_put(h, key, &absent);
					if (absent) ++n_new;
					else kh_key(h, k) = kh_key(h, k) | x;
				}
			}
		}
	}
	fclose(fp);
	///fprintf(stderr, "[M::%s] inserted %ld k-mers, of which %ld are new\n", __func__, (long)n_ins, (long)n_new);
	return ch;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movl %edx, %ebp
leaq 0x70(%rsp), %rdx
movq %rcx, 0x18(%rdx)
movq %r8, 0x20(%rdx)
movq %r9, 0x28(%rdx)
testb %al, %al
je 0x1082e7
movaps %xmm0, 0xa0(%rsp)
movaps %xmm1, 0xb0(%rsp)
movaps %xmm2, 0xc0(%rsp)
movaps %xmm3, 0xd0(%rsp)
movaps %xmm4, 0xe0(%rsp)
movaps %xmm5, 0xf0(%rsp)
movaps %xmm6, 0x100(%rsp)
movaps %xmm7, 0x110(%rsp)
movabsq $0x3000000018, %rax     # imm = 0x3000000018
movq %rax, 0x30(%rsp)
leaq 0x160(%rsp), %rax
movq %rax, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
movl %ebp, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x1086bc
movq %rdi, %r12
movl 0x30(%rsp), %ecx
cmpq $0x29, %rcx
jae 0x10834d
movq 0x40(%rsp), %rdx
movq %rcx, %rax
addq $0x8, %rax
movl %eax, 0x30(%rsp)
movl (%rdx,%rcx), %edx
movl %edx, 0x10(%rsp)
cmpl $0x20, %ecx
ja 0x108361
addq 0x40(%rsp), %rax
addl $0x10, %ecx
movl %ecx, 0x30(%rsp)
jmp 0x10836f
movq 0x38(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x38(%rsp)
movl (%rax), %eax
movl %eax, 0x10(%rsp)
movq 0x38(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x38(%rsp)
cmpl $0x3, %ebp
sete %cl
testq %r12, %r12
sete %dl
testb %cl, %dl
jne 0x1086bc
movl (%rax), %eax
movl %eax, 0x58(%rsp)
leaq 0x128125(%rip), %rax    # 0x2304b5
movq %rsi, %rdi
movq %rax, %rsi
callq 0x2210
testq %rax, %rax
je 0x1086bc
movq %rax, %r14
leaq 0x5c(%rsp), %rdi
movl $0x1, %esi
movl $0x4, %edx
movq %rax, %rcx
callq 0x22f0
cmpq $0x4, %rax
jne 0x1086bc
cmpl $0x24b4159, 0x5c(%rsp)  # imm = 0x24B4159
jne 0x1086b4
leaq 0x14(%rsp), %r15
movl $0x4, %esi
movl $0x3, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x22f0
movl 0x8(%r15), %edx
cmpl $0xa, %edx
jne 0x1086d4
testq %r12, %r12
je 0x10840f
movl 0x14(%rsp), %r13d
movq %r12, %r15
jmp 0x1084b7
movl 0x14(%rsp), %r13d
movl 0x18(%rsp), %r15d
cmpl $0xa, %r15d
jge 0x108427
xorl %r15d, %r15d
jmp 0x1084b7
movq %r14, 0x28(%rsp)
movl $0x1, %edi
movl $0x20, %esi
callq 0x2120
movq %rax, %rbx
movl %r13d, 0xc(%rsp)
movl %r13d, (%rax)
movl %r15d, 0x4(%rax)
movl $0x1, %r14d
movl %r15d, %ecx
movl %r15d, 0x50(%rsp)
movl $0x1, %r15d
shll %cl, %r15d
movslq %r15d, %rdi
movl $0x8, %esi
callq 0x2120
movq %rbx, 0x20(%rsp)
movq %rax, 0x18(%rbx)
cmpl $0x1f, 0x50(%rsp)
je 0x1084a8
movq %rax, %r13
cmpl $0x2, %r15d
cmovgel %r15d, %r14d
xorl %r15d, %r15d
movl $0x1, %edi
movl $0x18, %esi
callq 0x2120
movq %rax, (%r13,%r15,8)
incq %r15
cmpq %r15, %r14
jne 0x10848c
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %r15
movl 0xc(%rsp), %r13d
cmpl (%r15), %r13d
jne 0x1086f6
movl 0x18(%rsp), %eax
cmpl 0x4(%r15), %eax
jne 0x1086f6
cmpl $0x1f, %eax
je 0x1086aa
cmpl $0x2, %ebp
setne %cl
addb %cl, %cl
movl $0x2, %eax
shll %cl, %eax
movl %eax, 0x28(%rsp)
movl $0x1, %eax
shll %cl, %eax
movl %eax, 0xc(%rsp)
xorl %ecx, %ecx
movq %r12, 0x60(%rsp)
movq %r15, 0x20(%rsp)
movq 0x18(%r15), %rax
movq %rcx, 0x50(%rsp)
movq (%rax,%rcx,8), %rbp
movl $0x4, %esi
movl $0x2, %edx
leaq 0x14(%rsp), %rdi
movq %r14, %rcx
callq 0x22f0
testq %r12, %r12
jne 0x108536
movl 0x14(%rsp), %esi
movq %rbp, %rdi
callq 0x108d57
movl 0x18(%rsp), %r12d
testl %r12d, %r12d
jle 0x108682
xorl %ebx, %ebx
movl $0x8, %esi
movl $0x1, %edx
leaq 0x68(%rsp), %rdi
movq %r14, %r15
movq %r14, %rcx
callq 0x22f0
movq 0x68(%rsp), %r14
movl %r14d, %eax
andl $0x3ff, %eax            # imm = 0x3FF
cmpl 0x10(%rsp), %eax
movl 0xc(%rsp), %r13d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmovll %ecx, %r13d
cmpl 0x58(%rsp), %eax
cmovgel 0x28(%rsp), %r13d
testl %r13d, %r13d
js 0x108674
cmpq $0x0, 0x10(%rbp)
je 0x1085a5
movb (%rbp), %cl
movl $0x1, %esi
shll %cl, %esi
jmp 0x1085a7
xorl %esi, %esi
movl %esi, %eax
shrl %eax
movl %esi, %ecx
shrl $0x2, %ecx
addl %eax, %ecx
cmpl %ecx, 0x4(%rbp)
jae 0x1085bc
movl (%rbp), %ecx
jmp 0x1085d8
incl %esi
movq %rbp, %rdi
callq 0x108d57
testl %eax, %eax
js 0x108674
movl (%rbp), %ecx
movl $0x1, %esi
shll %cl, %esi
andq $-0x400, %r14           # imm = 0xFC00
movl %r13d, %edx
orq %rdx, %r14
movq %r14, %rax
shrq $0xa, %rax
imull $0x9e3779b9, %eax, %eax # imm = 0x9E3779B9
negb %cl
shrl %cl, %eax
decl %esi
movq 0x8(%rbp), %rdi
movl %eax, %ecx
movl %ecx, %r8d
shrl $0x5, %r8d
movl (%rdi,%r8,4), %r10d
movl $0x1, %r9d
shll %cl, %r9d
btl %ecx, %r10d
jae 0x10864f
movq 0x10(%rbp), %r11
movl %ecx, %r13d
movq (%r11,%r13,8), %r11
xorq %r14, %r11
cmpq $0x400, %r11            # imm = 0x400
jb 0x10864f
incl %ecx
andl %esi, %ecx
cmpl %eax, %ecx
jne 0x1085fe
movl %eax, %r8d
shrl $0x5, %r8d
movl $0x1, %r9d
movl %eax, %ecx
shll %cl, %r9d
movl (%rdi,%r8,4), %r10d
jmp 0x108651
movl %ecx, %eax
movl %eax, %eax
testl %r10d, %r9d
je 0x108662
movq 0x10(%rbp), %rcx
orq %rdx, (%rcx,%rax,8)
jmp 0x108674
movq 0x10(%rbp), %rcx
movq %r14, (%rcx,%rax,8)
orl %r10d, %r9d
movl %r9d, (%rdi,%r8,4)
incl 0x4(%rbp)
incl %ebx
cmpl %r12d, %ebx
movq %r15, %r14
jne 0x108546
movq 0x20(%rsp), %r15
movb 0x4(%r15), %cl
movl $0x1, %eax
shll %cl, %eax
movq 0x50(%rsp), %rcx
incq %rcx
cltq
cmpq %rax, %rcx
movq 0x60(%rsp), %r12
jl 0x108501
movq %r14, %rdi
callq 0x2190
jmp 0x1086bf
movq %r14, %rdi
callq 0x12020
xorl %r15d, %r15d
movq %r15, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18c905(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x130ef5(%rip), %rsi    # 0x2395da
xorl %r15d, %r15d
movl $0xa, %ecx
xorl %eax, %eax
callq 0x22b0
jmp 0x1086aa
leaq 0x130f1b(%rip), %rdi    # 0x239618
leaq 0x130cdd(%rip), %rsi    # 0x2393e1
leaq 0x130f38(%rip), %rcx    # 0x239643
movl $0x67, %edx
callq 0x2110