// File: chhylp123[P]hifiasm/Trio.cpp
// Function: tb_worker(void*, long, int)
static void tb_worker(void *_data, long k, int tid)
{
	tb_shared_t *aux = (tb_shared_t*)_data;
	UC_Read *s = &aux->bseq[tid]; 
	recover_UC_Read(s, aux->seq, k);
	tb_buf_t *b = &aux->buf[tid];
	tb_cnt_t cnt; memset(&cnt, 0, sizeof(tb_cnt_t));
	uint64_t x[4], mask;
	int i, l, shift;
	if (aux->ch->k < 32) {
		mask = (1ULL<<2*aux->ch->k) - 1;
		shift = 2 * (aux->ch->k - 1);
	} else {
		mask = (1ULL<<aux->ch->k) - 1;
		shift = aux->ch->k - 1;
	}
	if (s->length > b->max) {
		b->max = s->length;
		kroundup32(b->max);
		b->s = (uint32_t*)realloc(b->s, b->max * sizeof(uint32_t));
	}
	memset(b->s, 0, s->length * sizeof(uint32_t));
	for (i = l = 0, x[0] = x[1] = x[2] = x[3] = 0; i < s->length; ++i) {
		int flag, c = seq_nt4_table[(uint8_t)s->seq[i]];
		if (c < 4) {
			if (aux->ch->k < 32) {
				x[0] = (x[0] << 2 | c) & mask;
				x[1] = x[1] >> 2 | (uint64_t)(3 - c) << shift;
			} else {
				x[0] = (x[0] << 1 | (c&1))  & mask;
				x[1] = (x[1] << 1 | (c>>1)) & mask;
				x[2] = x[2] >> 1 | (uint64_t)(1 - (c&1))  << shift;
				x[3] = x[3] >> 1 | (uint64_t)(1 - (c>>1)) << shift;
			}
			if (++l >= aux->k) {
				int type = 0, c1, c2;
				uint64_t y;
				++cnt.nk;
				if (aux->ch->k < 32)
					y = yak_hash64(x[0] < x[1]? x[0] : x[1], mask);
				else
					y = yak_hash_long(x);
				flag = yak_ch_get(aux->ch, y);
				if (flag < 0) flag = 0;
				c1 = flag&3, c2 = flag>>2&3;
				if (c1 == 2 && c2 == 0) type = 1;
				else if (c2 == 2 && c1 == 0) type = 2;
				b->s[i] = type;
				++cnt.c[flag];
			}
		} else l = 0, x[0] = x[1] = x[2] = x[3] = 0;
	}
	for (l = 0, i = 1; i <= s->length; ++i) {
		if (i == s->length || b->s[i] != b->s[l]) {
			if (b->s[l] > 0 && i - l >= aux->k - 4)
				cnt.sc[b->s[l] - 1] += i - l;
			l = i;
		}
	}

	int *c = cnt.c;
	char type;
	type = tb_classify(cnt.sc, c, aux->k, aux->ratio_thres);
	aux->seq->trio_flag[k] = AMBIGU;
	if(type == 'p') aux->seq->trio_flag[k] = FATHER;
	if(type == 'm') aux->seq->trio_flag[k] = MOTHER;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x10(%rbp), %rdx
callq 0xa380
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
leaq -0x7c(%rbp), %rdi
xorl %esi, %esi
movl $0x4c, %edx
callq 0x2100
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
cmpl $0x20, (%rax)
jge 0x16c268
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
shll %eax
movl %eax, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
subq $0x1, %rax
movq %rax, -0xa8(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
subl $0x1, %eax
shll %eax
movl %eax, -0xb4(%rbp)
jmp 0x16c29a
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
subq $0x1, %rax
movq %rax, -0xa8(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
subl $0x1, %eax
movl %eax, -0xb4(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rcx
movslq (%rcx), %rcx
cmpq %rcx, %rax
jle 0x16c34f
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl (%rax), %ecx
sarl %ecx
movq -0x30(%rbp), %rax
orl (%rax), %ecx
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl (%rax), %ecx
sarl $0x2, %ecx
movq -0x30(%rbp), %rax
orl (%rax), %ecx
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl (%rax), %ecx
sarl $0x4, %ecx
movq -0x30(%rbp), %rax
orl (%rax), %ecx
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl (%rax), %ecx
sarl $0x8, %ecx
movq -0x30(%rbp), %rax
orl (%rax), %ecx
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl (%rax), %ecx
sarl $0x10, %ecx
movq -0x30(%rbp), %rax
orl (%rax), %ecx
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x30(%rbp), %rax
movslq (%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x2100
movl $0x0, -0xb0(%rbp)
movl $0x0, -0xac(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x90(%rbp)
movq $0x0, -0x98(%rbp)
movq $0x0, -0xa0(%rbp)
movslq -0xac(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0x16c6a1
movq -0x28(%rbp), %rax
movq (%rax), %rax
movslq -0xac(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x21e406(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rcx), %eax
movl %eax, -0xbc(%rbp)
cmpl $0x4, -0xbc(%rbp)
jge 0x16c655
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
cmpl $0x20, (%rax)
jge 0x16c455
movq -0xa0(%rbp), %rax
shlq $0x2, %rax
movslq -0xbc(%rbp), %rcx
orq %rcx, %rax
andq -0xa8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rax
shrq $0x2, %rax
movl $0x3, %ecx
subl -0xbc(%rbp), %ecx
movslq %ecx, %rdx
movl -0xb4(%rbp), %ecx
shlq %cl, %rdx
movq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x98(%rbp)
jmp 0x16c507
movq -0xa0(%rbp), %rax
shlq %rax
movl -0xbc(%rbp), %ecx
andl $0x1, %ecx
movslq %ecx, %rcx
orq %rcx, %rax
andq -0xa8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rax
shlq %rax
movl -0xbc(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
orq %rcx, %rax
andq -0xa8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rax
shrq %rax
movl -0xbc(%rbp), %edx
andl $0x1, %edx
movl $0x1, %ecx
subl %edx, %ecx
movslq %ecx, %rdx
movl -0xb4(%rbp), %ecx
shlq %cl, %rdx
movq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rax
shrq %rax
movl -0xbc(%rbp), %edx
sarl %edx
movl $0x1, %ecx
subl %edx, %ecx
movslq %ecx, %rdx
movl -0xb4(%rbp), %ecx
shlq %cl, %rdx
movq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x88(%rbp)
movl -0xb0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb0(%rbp)
movq -0x20(%rbp), %rcx
cmpl (%rcx), %eax
jl 0x16c653
movl $0x0, -0xc0(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
cmpl $0x20, (%rax)
jge 0x16c58c
movq -0xa0(%rbp), %rax
cmpq -0x98(%rbp), %rax
jae 0x16c562
movq -0xa0(%rbp), %rax
movq %rax, -0xe8(%rbp)
jmp 0x16c570
movq -0x98(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rdi
movq -0xa8(%rbp), %rsi
callq 0x16cfa0
movq %rax, -0xd0(%rbp)
jmp 0x16c59f
leaq -0xa0(%rbp), %rdi
callq 0x16d070
movq %rax, -0xd0(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0xd0(%rbp), %rsi
callq 0x16d0e0
movl %eax, -0xb8(%rbp)
cmpl $0x0, -0xb8(%rbp)
jge 0x16c5cc
movl $0x0, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
andl $0x3, %eax
movl %eax, -0xc4(%rbp)
movl -0xb8(%rbp), %eax
sarl $0x2, %eax
andl $0x3, %eax
movl %eax, -0xc8(%rbp)
cmpl $0x2, -0xc4(%rbp)
jne 0x16c60b
cmpl $0x0, -0xc8(%rbp)
jne 0x16c60b
movl $0x1, -0xc0(%rbp)
jmp 0x16c629
cmpl $0x2, -0xc8(%rbp)
jne 0x16c627
cmpl $0x0, -0xc4(%rbp)
jne 0x16c627
movl $0x2, -0xc0(%rbp)
jmp 0x16c629
movl -0xc0(%rbp), %edx
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xac(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movslq -0xb8(%rbp), %rax
movl -0x7c(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0x7c(%rbp,%rax,4)
jmp 0x16c68b
movl $0x0, -0xb0(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x90(%rbp)
movq $0x0, -0x98(%rbp)
movq $0x0, -0xa0(%rbp)
jmp 0x16c68d
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0x16c3aa
movl $0x0, -0xb0(%rbp)
movl $0x1, -0xac(%rbp)
movslq -0xac(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jg 0x16c77c
movslq -0xac(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0x16c701
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xac(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
movslq -0xb0(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
je 0x16c766
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xb0(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jbe 0x16c75a
movl -0xac(%rbp), %eax
subl -0xb0(%rbp), %eax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x4, %ecx
cmpl %ecx, %eax
jl 0x16c75a
movl -0xac(%rbp), %ecx
subl -0xb0(%rbp), %ecx
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xb0(%rbp), %rdx
movl (%rax,%rdx,4), %eax
subl $0x1, %eax
movl %eax, %eax
addl -0x3c(%rbp,%rax,4), %ecx
movl %ecx, -0x3c(%rbp,%rax,4)
movl -0xac(%rbp), %eax
movl %eax, -0xb0(%rbp)
jmp 0x16c768
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0x16c6b5
leaq -0x7c(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0x7c(%rbp), %rdi
addq $0x40, %rdi
movq -0xd8(%rbp), %rsi
movq -0x20(%rbp), %rax
movl (%rax), %edx
movq -0x20(%rbp), %rax
movsd 0x10(%rax), %xmm0
callq 0x16d1b0
movb %al, -0xd9(%rbp)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movsbl -0xd9(%rbp), %eax
cmpl $0x70, %eax
jne 0x16c7e4
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movb $0x1, (%rax,%rcx)
movsbl -0xd9(%rbp), %eax
cmpl $0x6d, %eax
jne 0x16c804
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movb $0x2, (%rax,%rcx)
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax)