// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rdi, 0x48(%rsp)
leaq 0x70(%rsp), %rdx
movq %rcx, 0x18(%rdx)
movq %r8, 0x20(%rdx)
movq %r9, 0x28(%rdx)
testb %al, %al
je 0x103b1c
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, %ecx
andl $-0x2, %ecx
xorl %eax, %eax
movl $0x0, 0xc(%rsp)
movl $0x0, 0x10(%rsp)
movl %ecx, 0x58(%rsp)
cmpl $0x2, %ecx
jne 0x103bcc
movl 0x30(%rsp), %ecx
cmpq $0x28, %rcx
ja 0x103b78
movq %rcx, %rax
addq 0x40(%rsp), %rax
addl $0x8, %ecx
movl %ecx, 0x30(%rsp)
jmp 0x103b86
movq 0x38(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x38(%rsp)
movl (%rax), %eax
movl %eax, 0x10(%rsp)
movl 0x30(%rsp), %ecx
cmpq $0x28, %rcx
ja 0x103ba7
movq %rcx, %rax
addq 0x40(%rsp), %rax
addl $0x8, %ecx
movl %ecx, 0x30(%rsp)
jmp 0x103bb5
movq 0x38(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x38(%rsp)
cmpl $0x3, %ebp
setne %cl
movl (%rax), %eax
movl %eax, 0xc(%rsp)
cmpq $0x0, 0x48(%rsp)
setne %al
orb %cl, %al
testb %al, %al
je 0x103c65
leaq 0x1208ca(%rip), %rax    # 0x2244a5
movq %rsi, %rdi
movq %rax, %rsi
callq 0x2210
testq %rax, %rax
je 0x103c65
movq %rax, %rbx
leaq 0x5c(%rsp), %rdi
movl $0x1, %esi
movl $0x4, %edx
movq %rax, %rcx
callq 0x22f0
cmpq $0x4, %rax
jne 0x103c65
cmpl $0x24b4159, 0x5c(%rsp)  # imm = 0x24B4159
jne 0x103f18
leaq 0x14(%rsp), %r12
movl $0x4, %esi
movl $0x3, %edx
movq %r12, %rdi
movq %rbx, %rcx
callq 0x22f0
movl 0x8(%r12), %edx
cmpl $0xa, %edx
jne 0x103f22
movq 0x48(%rsp), %rax
movq %rax, %r14
testq %rax, %rax
jne 0x103cff
movl 0x18(%rsp), %r12d
cmpl $0xa, %r12d
jge 0x103c7d
xorl %r14d, %r14d
jmp 0x103cff
xorl %r14d, %r14d
movq %r14, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, 0x28(%rsp)
movl 0x14(%rsp), %ebx
movl $0x1, %edi
movl $0x20, %esi
callq 0x2120
movq %rax, %r15
movl %ebx, (%rax)
movl %r12d, 0x4(%rax)
movl $0x1, %ebx
movl $0x1, %r14d
movl %r12d, %ecx
shll %cl, %r14d
movslq %r14d, %rdi
movl $0x8, %esi
callq 0x2120
movq %r15, 0x20(%rsp)
movq %rax, 0x18(%r15)
cmpl $0x1f, %r12d
je 0x103cf5
movq %rax, %r13
cmpl $0x2, %r14d
cmovgel %r14d, %ebx
xorl %r14d, %r14d
movl $0x1, %edi
movl $0x18, %esi
callq 0x2120
movq %rax, (%r13,%r14,8)
incq %r14
cmpq %r14, %rbx
jne 0x103cd9
movq 0x28(%rsp), %rbx
movq 0x20(%rsp), %r14
movl 0x14(%rsp), %eax
cmpl (%r14), %eax
jne 0x103f44
movl 0x18(%rsp), %eax
cmpl 0x4(%r14), %eax
jne 0x103f44
cmpl $0x1f, 0x4(%r14)
je 0x103f0b
cmpl $0x2, %ebp
setne %cl
addb %cl, %cl
movl $0x2, %eax
shll %cl, %eax
movl %eax, 0x54(%rsp)
movl $0x1, %eax
shll %cl, %eax
movl %eax, 0x50(%rsp)
xorl %ecx, %ecx
movq %r14, 0x20(%rsp)
movq 0x18(%r14), %rax
movq %rcx, 0x68(%rsp)
movq (%rax,%rcx,8), %rbp
movl $0x4, %esi
movl $0x2, %edx
leaq 0x14(%rsp), %rdi
movq %rbx, %rcx
callq 0x22f0
cmpq $0x0, 0x48(%rsp)
jne 0x103d82
movl 0x14(%rsp), %esi
movq %rbp, %rdi
callq 0x1045cf
movl 0x18(%rsp), %eax
movl %eax, 0x28(%rsp)
testl %eax, %eax
jle 0x103ee8
xorl %r13d, %r13d
movl $0x8, %esi
movl $0x1, %edx
leaq 0x60(%rsp), %rdi
movq %rbx, %r15
movq %rbx, %rcx
callq 0x22f0
cmpl $0x2, 0x58(%rsp)
jne 0x103ed7
movq 0x60(%rsp), %r14
movl %r14d, %ecx
andl $0x3ff, %ecx            # imm = 0x3FF
cmpl 0x10(%rsp), %ecx
movl 0x50(%rsp), %eax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmovll %edx, %eax
cmpl 0xc(%rsp), %ecx
cmovgel 0x54(%rsp), %eax
testl %eax, %eax
js 0x103ed7
andq $-0x400, %r14           # imm = 0xFC00
movl %eax, %ebx
orq %rbx, %r14
movq %r14, 0x60(%rsp)
cmpq $0x0, 0x10(%rbp)
je 0x103e0f
movb (%rbp), %cl
movl $0x1, %r12d
shll %cl, %r12d
jmp 0x103e12
xorl %r12d, %r12d
movl %r12d, %eax
shrl %eax
movl %r12d, %ecx
shrl $0x2, %ecx
addl %eax, %ecx
cmpl %ecx, 0x4(%rbp)
jb 0x103e45
leal 0x1(%r12), %esi
movq %rbp, %rdi
callq 0x1045cf
testl %eax, %eax
js 0x103ec6
movb (%rbp), %cl
movl $0x1, %r12d
shll %cl, %r12d
movq %r14, %rax
shrq $0xa, %rax
imull $0x9e3779b9, %eax, %edx # imm = 0x9E3779B9
movb (%rbp), %al
xorl %ecx, %ecx
subb %al, %cl
shrl %cl, %edx
movl %r12d, %ecx
decl %ecx
movq 0x8(%rbp), %rax
movl %edx, %r12d
movl %r12d, %esi
shrl $0x5, %esi
movl (%rax,%rsi,4), %esi
btl %r12d, %esi
jae 0x103e98
movq 0x10(%rbp), %rsi
movl %r12d, %edi
movq (%rsi,%rdi,8), %rsi
xorq %r14, %rsi
cmpq $0x400, %rsi            # imm = 0x400
jb 0x103e98
incl %r12d
andl %ecx, %r12d
cmpl %edx, %r12d
jne 0x103e67
movl %r12d, %edx
movl $0x1, %esi
movl %r12d, %ecx
shll %cl, %esi
shrl $0x5, %edx
movl (%rax,%rdx,4), %edi
movb $0x1, %cl
btl %r12d, %edi
jb 0x103ec8
movq 0x10(%rbp), %rcx
movl %r12d, %r8d
movq %r14, (%rcx,%r8,8)
orl %edi, %esi
movl %esi, (%rax,%rdx,4)
incl 0x4(%rbp)
xorl %ecx, %ecx
testb %cl, %cl
je 0x103ed7
movq 0x10(%rbp), %rax
movl %r12d, %ecx
orq %rbx, (%rax,%rcx,8)
incl %r13d
cmpl 0x28(%rsp), %r13d
movq %r15, %rbx
jne 0x103d95
movq 0x20(%rsp), %r14
movb 0x4(%r14), %cl
movl $0x1, %eax
shll %cl, %eax
movq 0x68(%rsp), %rcx
incq %rcx
cltq
cmpq %rax, %rcx
jl 0x103d4a
movq %rbx, %rdi
callq 0x2190
jmp 0x103c68
callq 0x126ed
xorl %r14d, %r14d
jmp 0x103f0b
movq 0x1860b7(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x12949a(%rip), %rsi    # 0x22d3cd
xorl %r14d, %r14d
movl $0xa, %ecx
xorl %eax, %eax
callq 0x22b0
jmp 0x103f0b
leaq 0x1294c0(%rip), %rdi    # 0x22d40b
leaq 0x129282(%rip), %rsi    # 0x22d1d4
leaq 0x1294dd(%rip), %rcx    # 0x22d436
movl $0x67, %edx
callq 0x2110