// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %rax
movq %rdi, %rbx
movslq %edx, %r14
movq %r14, %r15
shlq $0x5, %r15
movq 0x28(%rdi), %r12
movq 0x30(%rdi), %rsi
leaq (%r12,%r15), %r13
movq %r13, %rdi
movq %rax, 0x8(%rsp)
movq %rax, %rdx
callq 0x715e
movq 0x20(%rbx), %rax
shlq $0x4, %r14
xorpd %xmm0, %xmm0
movupd %xmm0, 0xbc(%rsp)
movapd %xmm0, 0xb0(%rsp)
movapd %xmm0, 0xa0(%rsp)
movapd %xmm0, 0x90(%rsp)
movapd %xmm0, 0x80(%rsp)
movq %rbx, 0x10(%rsp)
movq 0x18(%rbx), %rcx
movl (%rcx), %edx
leal -0x1(%rdx), %ecx
cmpl $0x20, %edx
leal -0x2(%rdx,%rdx), %ebx
cmovgel %ecx, %ebx
leal (%rdx,%rdx), %ecx
cmovgel %edx, %ecx
pushq $-0x1
popq %r8
shlq %cl, %r8
leaq (%rax,%r14), %rbp
movq 0x8(%r12,%r15), %rdx
movslq (%rax,%r14), %rax
cmpq %rax, %rdx
jle 0xc6081
decl %edx
movl %edx, %eax
sarl %eax
orl %edx, %eax
movl %eax, %ecx
sarl $0x2, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x8, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x10, %eax
orl %ecx, %eax
leal 0x1(%rax), %ecx
movl %ecx, (%rbp)
movq 0x8(%rbp), %rdi
cltq
leaq 0x4(,%rax,4), %rsi
movq %r8, %r14
callq 0x2370
movq %r14, %r8
movq %rax, %rdi
movq %rax, 0x8(%rbp)
movq 0x8(%r13), %rdx
jmp 0xc6085
movq 0x8(%rbp), %rdi
movq %rbp, %r15
notq %r8
movq %r8, 0x30(%rsp)
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x20e0
movq 0x30(%rsp), %r9
xorpd %xmm0, %xmm0
movapd %xmm0, 0x50(%rsp)
movq 0x8(%r13), %rax
testq %rax, %rax
movl $0x0, %r10d
movq %rax, 0x60(%rsp)
cmovgq %rax, %r10
movl %ebx, %eax
movq %rax, 0x38(%rsp)
leaq 0x125a32(%rip), %rdi    # 0x1ebb00
xorl %r14d, %r14d
xorl %ebx, %ebx
xorl %ebp, %ebp
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq %r13, %r8
xorl %r13d, %r13d
movq %r8, 0x78(%rsp)
movq %r15, 0x68(%rsp)
movq %r10, 0x70(%rsp)
cmpq %r10, %r14
je 0xc6388
movq (%r8), %rax
movzbl (%rax,%r14), %eax
movzbl (%rdi,%rax), %edx
cmpl $0x3, %edx
ja 0xc6148
movq 0x10(%rsp), %rax
movq 0x18(%rax), %r12
movl (%r12), %eax
cmpl $0x1f, %eax
jg 0xc6172
movl %edx, %ecx
leaq (%rcx,%rbx,4), %rbx
shrq $0x2, %rbp
pushq $0x3
popq %rsi
subq %rdx, %rsi
movq 0x38(%rsp), %rcx
shlq %cl, %rsi
orq %rsi, %rbp
jmp 0xc61d0
movapd %xmm0, 0x50(%rsp)
movapd %xmm0, 0x40(%rsp)
xorl %ebx, %ebx
xorl %ebp, %ebp
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
xorl %r13d, %r13d
jmp 0xc636a
movl %edx, %esi
andl $0x1, %esi
leaq (%rsi,%rbx,2), %rbx
addq %rbp, %rbp
shrl %edx
movq %rdx, %rdi
orq %rbp, %rdi
andq %r9, %rdi
movq 0x20(%rsp), %r11
shrq %r11
xorl $0x1, %esi
movq 0x38(%rsp), %rcx
shlq %cl, %rsi
orq %rsi, %r11
movq %r11, 0x20(%rsp)
movq %r11, 0x50(%rsp)
pushq $0x1
popq %rsi
subl %edx, %esi
shlq %cl, %rsi
movq 0x18(%rsp), %rdx
shrq %rdx
orq %rsi, %rdx
movq %rdx, 0x18(%rsp)
movq %rdx, 0x58(%rsp)
movq %rdi, %rbp
leaq 0x125930(%rip), %rdi    # 0x1ebb00
andq %r9, %rbx
movq %rbx, 0x40(%rsp)
movq %rbp, 0x48(%rsp)
incl %r13d
movq 0x10(%rsp), %rcx
cmpl (%rcx), %r13d
jl 0xc636a
incl 0xc8(%rsp)
cmpl $0x1f, %eax
movl %r13d, 0x2c(%rsp)
jg 0xc6256
cmpq %rbp, %rbx
movq %rbp, %rax
cmovbq %rbx, %rax
movq %rax, %rcx
notq %rcx
shlq $0x15, %rax
addq %rcx, %rax
andq %r9, %rax
movq %rax, %rcx
shrq $0x18, %rcx
xorq %rax, %rcx
imulq $0x109, %rcx, %rax      # imm = 0x109
andq %r9, %rax
movq %rax, %rcx
shrq $0xe, %rcx
xorq %rax, %rcx
imulq $0x15, %rcx, %rcx
andq %r9, %rcx
movq %rcx, %rax
shrq $0x1c, %rax
xorq %rcx, %rax
movl $0x80000001, %ecx       # imm = 0x80000001
imulq %rcx, %rax
andq %r9, %rax
jmp 0xc6289
xorl %r15d, %r15d
cmpq 0x18(%rsp), %rbp
setae %r15b
shll $0x4, %r15d
movq 0x40(%rsp,%r15), %rdi
callq 0xc671a
movq %rax, %r13
movq 0x48(%rsp,%r15), %rdi
movq 0x68(%rsp), %r15
callq 0xc671a
xorpd %xmm0, %xmm0
addq %r13, %rax
movb 0x4(%r12), %cl
pushq $-0x1
popq %rdi
movl %edi, %edx
shll %cl, %edx
notl %edx
movq 0x18(%r12), %rsi
andl %eax, %edx
shrq %cl, %rax
movq (%rsi,%rdx,8), %r8
movq 0x10(%r8), %rdx
movl %edi, %ecx
testq %rdx, %rdx
je 0xc630a
movb (%r8), %cl
pushq $0x1
popq %rsi
shll %cl, %esi
movq %rax, %rdi
imull $0x9e3779b9, %eax, %eax # imm = 0x9E3779B9
negb %cl
shrl %cl, %eax
shlq $0xa, %rdi
leal -0x1(%rsi), %ecx
movq 0x8(%r8), %r9
movl %eax, %r8d
movl %r8d, %r10d
shrl $0x5, %r10d
movl (%r9,%r10,4), %r10d
btl %r8d, %r10d
jae 0xc6305
movl %r8d, %r10d
movq (%rdx,%r10,8), %r10
movq %r10, %r11
xorq %rdi, %r11
cmpq $0x400, %r11            # imm = 0x400
jb 0xc6372
incl %r8d
andl %ecx, %r8d
cmpl %eax, %r8d
jne 0xc62d3
pushq $-0x1
popq %rax
movl %eax, %ecx
testl %ecx, %ecx
movl $0x0, %eax
cmovlel %eax, %ecx
movl %ecx, %eax
andl $0x3, %eax
movl %ecx, %edx
shrl $0x2, %edx
andl $0x3, %edx
movl %eax, %esi
xorl $0x2, %esi
movl %edx, %edi
xorl $0x2, %edi
xorl %r8d, %r8d
orl %eax, %edi
sete %r8b
addl %r8d, %r8d
orl %edx, %esi
pushq $0x1
popq %rax
cmovel %eax, %r8d
movq 0x8(%r15), %rax
movl %r8d, (%rax,%r14,4)
incl 0x80(%rsp,%rcx,4)
movq 0x78(%rsp), %r8
movq 0x30(%rsp), %r9
movq 0x70(%rsp), %r10
leaq 0x12579b(%rip), %rdi    # 0x1ebb00
movl 0x2c(%rsp), %r13d
incq %r14
jmp 0xc60fc
pushq $-0x1
popq %rax
movl %eax, %ecx
cmpl %esi, %r8d
je 0xc630a
andl $0x3ff, %r10d           # imm = 0x3FF
movl %r10d, %ecx
jmp 0xc630a
negq %r10
xorl %ecx, %ecx
pushq $0x1
popq %rax
movq 0x60(%rsp), %r8
leaq (%r10,%rax), %rdx
cmpq $0x1, %rdx
je 0xc63e9
movq 0x8(%r15), %rsi
movslq %ecx, %rdx
cmpq %rax, %r8
jne 0xc63b0
movl (%rsi,%rdx,4), %edx
jmp 0xc63b8
movl (%rsi,%rdx,4), %edx
cmpl %edx, (%rsi,%rax,4)
je 0xc63e4
testl %edx, %edx
je 0xc63e2
movl %eax, %esi
subl %ecx, %esi
movq 0x10(%rsp), %rdi
movl (%rdi), %edi
addl $-0x4, %edi
cmpl %edi, %esi
jl 0xc63e2
decl %edx
movl 0xc0(%rsp,%rdx,4), %esi
subl %ecx, %esi
addl %eax, %esi
movl %esi, 0xc0(%rsp,%rdx,4)
movl %eax, %ecx
incq %rax
jmp 0xc6395
movq 0x10(%rsp), %rax
movl (%rax), %eax
movl 0xc0(%rsp), %edx
movl 0xc4(%rsp), %esi
movl %edx, %ecx
orl %esi, %ecx
jne 0xc645f
movl 0x88(%rsp), %edx
movl 0xa0(%rsp), %esi
cmpl %esi, %edx
je 0xc64f4
cvtsi2sd %esi, %xmm0
leal (%rsi,%rax), %ecx
addl $-0x4, %ecx
cvtsi2sd %edx, %xmm1
cmpl %ecx, %edx
jge 0xc64fd
addl $-0x4, %eax
addl %edx, %eax
cmpl %eax, %esi
jl 0xc64f4
movb $0x2, %cl
cmpl $0x2, %edx
jl 0xc651a
mulsd 0x11d0c8(%rip), %xmm0   # 0x1e3518
ucomisd %xmm1, %xmm0
jbe 0xc64f4
jmp 0xc651a
cmpl %eax, %edx
setg %cl
cmpl %eax, %esi
setg %dil
testb %dil, %cl
jne 0xc64f4
movq 0x10(%rsp), %rcx
movsd 0x10(%rcx), %xmm0
cvtsi2sd %esi, %xmm1
leal (%rsi,%rax), %ecx
addl $-0x4, %ecx
cvtsi2sd %edx, %xmm2
cmpl %ecx, %edx
jl 0xc64bf
movsd 0x11d081(%rip), %xmm3   # 0x1e3518
mulsd %xmm2, %xmm3
ucomisd %xmm1, %xmm3
jb 0xc64bf
cvtsi2sdl 0x88(%rsp), %xmm3
cvtsi2sdl 0xa0(%rsp), %xmm4
mulsd %xmm0, %xmm3
movb $0x1, %cl
ucomisd %xmm4, %xmm3
ja 0xc651a
addl $-0x4, %eax
addl %eax, %edx
cmpl %edx, %esi
jl 0xc64f4
mulsd 0x11d048(%rip), %xmm1   # 0x1e3518
ucomisd %xmm2, %xmm1
jb 0xc64f4
cvtsi2sdl 0xa0(%rsp), %xmm1
cvtsi2sdl 0x88(%rsp), %xmm2
mulsd %xmm1, %xmm0
movb $0x2, %cl
ucomisd %xmm2, %xmm0
ja 0xc651a
xorl %ecx, %ecx
movq 0x8(%rsp), %rdx
jmp 0xc6530
movb $0x1, %cl
cmpl $0x2, %esi
jl 0xc651a
movsd 0x11d00c(%rip), %xmm2   # 0x1e3518
mulsd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
jbe 0xc6430
movq 0x10(%rsp), %rax
movq 0x30(%rax), %rax
movq 0x28(%rax), %rax
movq 0x8(%rsp), %rdx
movb $0x0, (%rax,%rdx)
movq 0x10(%rsp), %rax
movq 0x30(%rax), %rax
movq 0x28(%rax), %rax
movb %cl, (%rax,%rdx)
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq