// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: worker_for_trans_ovlp(void*, long, int)
static void worker_for_trans_ovlp(void *data, long i, int tid) // callback for kt_for()
{
    ug_trans_t *s = (ug_trans_t*)data;
    ha_ovec_buf_t *b = s->hab[tid];
	kv_ul_ov_t *bl = &(s->ll[tid].tk);
    int64_t winLen = MIN((((double)THRESHOLD_MAX_SIZE)/s->diff_ec_ul), WINDOW);
	uint32_t high_occ = asm_opt.polyploidy + 1, k; uint64_t cnt, bn;
	overlap_region *aux_o = NULL; ul_ov_t *p;
	char *seq = s->ug->u.a[i].s; 
	int64_t len = s->ug->u.a[i].len;
	if((!s->is_ovlp) && (s->is_cnt)) s->idx_n.a[i] = 0;
	if(IF_HOM(i, (*(s->bub))) || s->ug->g->seq[i].del) return;

	// asprintf(&as, "\n[M::%s] rid::%ld, len::%lu, name::%.*s\n", __func__, s->id+i, s->len[i], (int32_t)UL_INF.nid.a[s->id+i].n, UL_INF.nid.a[s->id+i].a);
    // push_vlog(&(overall_zdbg->a[s->id+i]), as); free(as); as = NULL;

	if(!s->is_ovlp) {
		if(s->is_cnt) {
			s->idx_n.a[i] = ug_map_lchain(b->abl, i, seq, len, s->w, s->k, &(s->udb), NULL, NULL, s->bw_thres, s->bw_thres_double,
            	s->max_n_chain, 1, NULL, &(b->tmp_region), NULL, &(b->sp), &high_occ, NULL, 0, 1, 0.2, 3, s->is_HPC, NULL, 0, NULL, 0, s->mini_cut, s->chain_cut, NULL);
			// fprintf(stderr, "-1-[M::%s] rid::%ld, is_ovlp::%d, is_cnt::%d, len::%d, str::%u, s->idx_n.a[i]::%lu\n", 
			// 	__func__, i, s->is_ovlp, s->is_cnt, len, !!seq, s->idx_n.a[i]);
		} else {
			cnt = ug_map_lchain(b->abl, i, seq, len, s->w, s->k, &(s->udb), NULL, NULL, s->bw_thres, s->bw_thres_double,
				s->max_n_chain, 1, NULL, &(b->tmp_region), NULL, &(b->sp), &high_occ, NULL, 0, 1, 0.2, 3, s->is_HPC, s->idx_a.a + s->idx_n.a[i], 0, NULL, 0, s->mini_cut, s->chain_cut, NULL);
			assert(cnt == ((s->idx_n.a[i+1]-s->idx_n.a[i])));
			// if(i == 1576 || i == 2879) {
			// 	fprintf(stderr, "-2-[M::%s] rid::%ld, is_ovlp::%d, is_cnt::%d, len::%ld, str::%u, cnt::%lu\n", 
			// 	__func__, i, s->is_ovlp, s->is_cnt, len, !!seq, cnt);
			// }
		}
		return;
	} else {
		cnt = ((s->idx_n.a[i+1]-s->idx_n.a[i]));
		// fprintf(stderr, "\n-0-[M::%s] utg%.6u%c, rid::%ld, is_ovlp::%d, is_cnt::%d, len::%ld, str::%u, cnt::%lu, diff::%f\n", 
		// 		__func__, (uint32_t)i+1, "lc"[s->ug->u.a[i].circ], i, s->is_ovlp, s->is_cnt, len, (uint32_t)(!!seq), cnt, s->diff_ec_ul);
		///note: high_occ is different
		ug_map_lchain(b->abl, i, seq, len, s->w, s->k, &(s->udb), &b->olist, &b->clist, s->bw_thres, s->bw_thres_double,
				s->max_n_chain, 1, NULL, &(b->tmp_region), NULL, &(b->sp), &high_occ, NULL, 0, 1, 0.2, 3, s->is_HPC, s->idx_a.a + s->idx_n.a[i], cnt, s->srt_a.a, s->srt_a.n, s->mini_cut, s->chain_cut, NULL);
	}
	
	filter_by_reliable_ovlp(i, s->filter, &(b->sp), &b->olist, &(s->udb), s->sec_cutoff, 0);
	// fprintf(stderr, "-0-[M::%s] rid::%ld, is_ovlp::%d, is_cnt::%d, len::%ld, str::%u\n", 
	// __func__, i, s->is_ovlp, s->is_cnt, len, !!seq);
	clear_Cigar_record(&b->cigar1); clear_Round2_alignment(&b->round2);
	
	ug_lalign(&b->olist, &b->clist, &(s->udb), s->uopt, seq, len, &b->self_read, &b->ovlp_read,
                        &b->correct, &b->exz, aux_o, s->diff_ec_ul, winLen, i, s->k, s->chain_cut, NULL);
	
	aux_o = gen_aux_ovlp(&b->olist);///must be here

	ug_lalign(&b->olist, &b->clist, &(s->udb), s->uopt, seq, len, &b->self_read, &b->ovlp_read,
						&b->correct, &b->exz, aux_o, s->diff_ec_ul, winLen, i, s->k, s->chain_cut, NULL);
	if(b->olist.length > 0) {
		cnt = bl->n + b->olist.length; kv_resize(ul_ov_t, (*bl), cnt);
		for (k = 0, bn = bl->n; k < b->olist.length; k++) {
			// if(b->olist.list[k].non_homopolymer_errors == 0) continue;///exact match is not trans
			kv_pushp(ul_ov_t, (*bl), &p);
			p->qn = i; p->tn = b->olist.list[k].y_id; p->el = 1; 
			p->sec = b->olist.list[k].non_homopolymer_errors; 
			p->rev = b->olist.list[k].y_pos_strand;
			p->qs = b->olist.list[k].x_pos_s; p->qe = b->olist.list[k].x_pos_e+1;
			// p->ts = b->olist.list[k].y_pos_s; p->te = b->olist.list[k].y_pos_e+1;
			if(p->rev) {
				p->ts = s->udb.ug->u.a[p->tn].len - (b->olist.list[k].y_pos_e+1); 
				p->te = s->udb.ug->u.a[p->tn].len - b->olist.list[k].y_pos_s;
			} else {
				p->ts = b->olist.list[k].y_pos_s; 
				p->te = b->olist.list[k].y_pos_e+1;
			}
			// if(i == 5) 
			// {
			// 	fprintf(stderr, "***utg%.6u%c\t%u\t%u\t%u\t%c\tutg%.6u%c\t%u\t%u\t%u\ti::%ld\n", 
			// 		p->qn+1, "lc"[s->ug->u.a[p->qn].circ], s->ug->u.a[p->qn].len, p->qs, p->qe, "+-"[p->rev],
			// 		p->tn+1, "lc"[s->ug->u.a[p->tn].circ], s->ug->u.a[p->tn].len, p->ts, p->te, i);
			// }
			if(!trans_ovlp_connect(p, s->ug)) {
				bl->n--;
			} 
			// else {
			// 	if(i == 5) 
			// 	{
			// 		fprintf(stderr, ">>>utg%.6u%c\t%u\t%u\t%u\t%c\tutg%.6u%c\t%u\t%u\t%u\ti::%ld\n", 
			// 			p->qn+1, "lc"[s->ug->u.a[p->qn].circ], s->ug->u.a[p->qn].len, p->qs, p->qe, "+-"[p->rev],
			// 			p->tn+1, "lc"[s->ug->u.a[p->tn].circ], s->ug->u.a[p->tn].len, p->ts, p->te, i);
			// 	}
			// }
		}
		cnt = filter_sec_trans_ovlp(bl->a+bn, bl->n-bn, i, s->sec_cutoff) + bn;
		bl->n = cnt;
	}


	// fprintf(stderr, "[M::%s] rid:%ld, dd:%u\n", __func__, s->id+i, UL_INF.a[s->id+i].dd);
    // int64_t mem[6], mem_hab[6];
    // if(get_utepdat_t_mem_tid(s, tid, mem, mem_hab)>((int64_t)5*(int64_t)1073741824)) {
    //     fprintf(stderr, "[M::%s::tid->%d::rid->%ld] buffer[0]: %.3fGB(%.3fGB::%.3fGB::%.3fGB::%.3fGB::%.3fGB), buffer[1]: %.3fGB, buffer[2]: %.3fGB, buffer[3]: %.3fGB, buffer[4]: %.3fGB, buffer[5]: %.3fGB\n", 
    //             __func__, tid, i, mem[0]/1073741824.0, 
	// 			mem_hab[0]/1073741824.0, mem_hab[1]/1073741824.0, mem_hab[2]/1073741824.0, 
	// 			mem_hab[3]/1073741824.0, mem_hab[4]/1073741824.0,
	// 			mem[1]/1073741824.0, mem[2]/1073741824.0,
    //             mem[3]/1073741824.0, mem[4]/1073741824.0, mem[5]/1073741824.0);
    // }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r15
movq %rdi, %r14
movslq %edx, %r10
movq 0x18(%rdi), %rax
movq 0x20(%rdi), %r9
movsd 0x45fe8(%rip), %xmm0    # 0x1e3570
divsd 0x40(%rdi), %xmm0
movq (%rax,%r10,8), %rbp
leaq 0xb61c0(%rip), %rax     # 0x253758
movl 0x1bc(%rax), %eax
incl %eax
movl %eax, 0xc(%rsp)
movq 0x8(%rdi), %rdi
movq 0x10(%rdi), %rax
imulq $0x28, %rsi, %rdx
movq 0x20(%rax,%rdx), %r8
movl (%rax,%rdx), %ecx
movl 0xb8(%r14), %eax
testl %eax, %eax
jne 0x19d5d9
cmpl $0x0, 0xb4(%r14)
je 0x19d5d9
movq 0x88(%r14), %rdx
andq $0x0, (%rdx,%r15,8)
movq 0x28(%r14), %rdx
movq (%rdx), %rsi
movq 0x80(%rdx), %rdx
movl (%rsi,%r15,4), %esi
incq %rdx
cmpq %rsi, %rdx
jb 0x19dc35
movq 0x18(%rdi), %rdx
movq 0x20(%rdx), %rdx
cmpl $0x0, (%rdx,%r15,8)
js 0x19dc35
movq %r8, (%rsp)
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
testl %eax, %eax
je 0x19da45
minsd 0x45f54(%rip), %xmm0    # 0x1e3578
cvttsd2si %xmm0, %rax
movq %rax, 0x58(%rsp)
movq 0x88(%r14), %rax
movq (%rax,%r15,8), %rdx
movq 0x8(%rax,%r15,8), %rbx
subq %rdx, %rbx
movq 0xe8(%rbp), %rdi
movslq 0x30(%r14), %r8
movq %r9, 0x60(%rsp)
movslq 0x34(%r14), %r9
leaq 0xc8(%r14), %rax
movq %rax, 0x30(%rsp)
movq %rcx, 0x40(%rsp)
leaq 0xa0(%rbp), %r12
leaq 0x48(%rbp), %rax
movq %rax, 0x38(%rsp)
movsd 0x38(%r14), %xmm0
movsd 0x50(%r14), %xmm1
movl 0x60(%r14), %eax
movq %rax, 0x28(%rsp)
leaq 0x121a0(%rbp), %rax
movq %rax, 0x20(%rsp)
leaq 0x12250(%rbp), %r13
movq %r15, 0x10(%rsp)
imulq $0x18, %rdx, %r15
addq 0x70(%r14), %r15
movl 0xa0(%r14), %eax
movq %rax, 0x18(%rsp)
movl 0x90(%r14), %eax
movq %r10, 0x50(%rsp)
movslq 0xbc(%r14), %r10
movslq 0xc0(%r14), %r11
movsd 0x45df7(%rip), %xmm2    # 0x1e34d0
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
pushq $0x0
pushq %r11
pushq %r10
pushq %rax
pushq 0x98(%r14)
pushq %rbx
pushq %r15
pushq 0x50(%rsp)
pushq $0x3
pushq $0x1
popq %rax
pushq %rax
pushq $0x0
pushq $0x0
leaq 0x6c(%rsp), %r10
pushq %r10
pushq %r13
pushq $0x0
pushq 0x98(%rsp)
pushq $0x0
pushq %rax
pushq 0xb8(%rsp)
movq 0xd0(%rsp), %rbx
pushq %rbx
pushq %r12
movq 0xd8(%rsp), %r15
pushq %r15
callq 0xedfe4
addq $0xb0, %rsp
movq 0xf8(%r14), %rsi
movsd 0x48(%r14), %xmm0
movq 0x10(%rsp), %rdi
movq %r13, %rdx
movq %r12, %rcx
movq %r15, %r8
xorl %r9d, %r9d
callq 0x178a69
leaq 0x108(%rbp), %rdi
callq 0x1b25d
leaq 0x9330(%rbp), %rdi
callq 0x1b1e8
movq (%r14), %rcx
leaq 0x8(%rbp), %r11
leaq 0x28(%rbp), %rax
movq %rax, 0x28(%rsp)
leaq 0x2c0(%rbp), %r13
movq %r13, 0x20(%rsp)
leaq 0x12268(%rbp), %rdx
movq %rdx, 0x18(%rsp)
movsd 0x40(%r14), %xmm0
movslq 0x34(%r14), %rdx
movq %rdx, 0x48(%rsp)
movslq 0xc0(%r14), %r10
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq (%rsp), %r8
movq 0x40(%rsp), %r9
pushq $0x0
pushq %r10
pushq 0x58(%rsp)
pushq 0x28(%rsp)
movq 0x78(%rsp), %rbx
pushq %rbx
pushq $0x0
movq 0x48(%rsp), %r15
pushq %r15
pushq %r13
pushq %rax
pushq %r11
movq %r11, %r13
callq 0x5128a
addq $0x50, %rsp
movq %r12, %rdi
callq 0x172830
movq (%r14), %rcx
movsd 0x40(%r14), %xmm0
movslq 0x34(%r14), %r10
movslq 0xc0(%r14), %r11
movq %r12, %rdi
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq (%rsp), %r8
movq 0x40(%rsp), %r9
pushq $0x0
pushq %r11
pushq %r10
pushq 0x28(%rsp)
pushq %rbx
pushq %rax
pushq %r15
pushq 0x58(%rsp)
pushq 0x68(%rsp)
pushq %r13
callq 0x5128a
movq 0xa0(%rsp), %rcx
movq 0xb0(%rsp), %rdx
addq $0x50, %rsp
movq 0xb0(%rbp), %rax
testq %rax, %rax
je 0x19dc35
imulq $0x68, %rcx, %rcx
leaq (%rdx,%rcx), %r13
addq $0x18, %r13
movq 0x8(%r13), %rcx
addq %rcx, %rax
cmpq %rax, 0x10(%r13)
jae 0x19d8d1
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
incq %rcx
movq %rcx, 0x10(%r13)
movq (%r13), %rdi
imulq $0x1c, %rcx, %rsi
callq 0x2370
movq %rax, (%r13)
movq 0x8(%r13), %rcx
movq %rcx, (%rsp)
xorl %r15d, %r15d
movl $0x40000000, %ebx       # imm = 0x40000000
movl %r15d, %r15d
cmpq %r15, 0xb0(%rbp)
jbe 0x19da15
movq (%r13), %rax
movq 0x8(%r13), %rcx
cmpq 0x10(%r13), %rcx
jne 0x19d921
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r13)
imulq $0x1c, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%r13)
movq 0x8(%r13), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r13)
imulq $0x1c, %rcx, %rsi
leaq (%rax,%rsi), %rdi
movq 0x10(%rsp), %rcx
movl %ecx, (%rax,%rsi)
movq (%r12), %rdx
imulq $0xa8, %r15, %rcx
movl 0x10(%rdx,%rcx), %edx
movl %edx, 0xc(%rax,%rsi)
movl 0x18(%rax,%rsi), %r8d
orl %ebx, %r8d
movl %r8d, 0x18(%rax,%rsi)
movq (%r12), %r9
movl 0x30(%r9,%rcx), %r9d
movl $0x3fffffff, %r10d      # imm = 0x3FFFFFFF
andl %r10d, %r9d
andl $0xc0000000, %r8d       # imm = 0xC0000000
orl %r9d, %r8d
movl %r8d, 0x18(%rax,%rsi)
movq (%r12), %r8
movl 0x1c(%r8,%rcx), %r10d
shll $0x1f, %r10d
orl %r10d, %r9d
orl %ebx, %r9d
movl %r9d, 0x18(%rax,%rsi)
movq (%r12), %r8
movl 0x4(%r8,%rcx), %r9d
movl %r9d, 0x4(%rax,%rsi)
movl 0x8(%r8,%rcx), %r9d
incl %r9d
movl %r9d, 0x8(%rax,%rsi)
testl %r10d, %r10d
je 0x19d9ea
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
imulq $0x28, %rdx, %rdx
movl (%rax,%rdx), %esi
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
andl %r10d, %esi
movl 0x18(%r8,%rcx), %r9d
notl %r9d
addl %esi, %r9d
movl %r9d, 0x10(%rdi)
movl (%rax,%rdx), %eax
andl %r10d, %eax
subl 0x14(%r8,%rcx), %eax
jmp 0x19d9f9
movl 0x14(%r8,%rcx), %eax
movl %eax, 0x10(%rdi)
movl 0x18(%r8,%rcx), %eax
incl %eax
movl %eax, 0x14(%rdi)
movq 0x8(%r14), %rsi
callq 0x178842
testl %eax, %eax
jne 0x19da0d
decq 0x8(%r13)
incl %r15d
jmp 0x19d8dd
movq (%rsp), %rbx
imulq $0x1c, %rbx, %rdi
addq (%r13), %rdi
movl 0x8(%r13), %esi
subl %ebx, %esi
movsd 0x48(%r14), %xmm0
movq 0x10(%rsp), %rdx
callq 0x1785f1
movl %eax, %eax
addq %rbx, %rax
movq %rax, 0x8(%r13)
jmp 0x19dc35
leaq 0xc8(%r14), %rax
leaq 0x121a0(%rbp), %r13
cmpl $0x0, 0xb4(%r14)
leaq 0x12250(%rbp), %rdx
movq 0xe8(%rbp), %rdi
movslq 0x30(%r14), %r8
movslq 0x34(%r14), %r9
movsd 0x38(%r14), %xmm0
movsd 0x50(%r14), %xmm1
movl 0x60(%r14), %esi
movl 0xa0(%r14), %r10d
je 0x19db51
movslq 0xbc(%r14), %r11
movslq 0xc0(%r14), %rbx
subq $0xb0, %rsp
movq %rbx, 0xa0(%rsp)
movq %r11, 0x98(%rsp)
xorps %xmm2, %xmm2
movups %xmm2, 0x88(%rsp)
movups %xmm2, 0x78(%rsp)
movl %r10d, 0x70(%rsp)
pushq $0x1
popq %r10
movl %r10d, 0x60(%rsp)
leaq 0xbc(%rsp), %r11
movq %r11, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %r13, 0x30(%rsp)
movl %r10d, 0x20(%rsp)
movl %esi, 0x18(%rsp)
movups %xmm2, 0x8(%rsp)
andq $0x0, 0xa8(%rsp)
andl $0x0, 0x58(%rsp)
andq $0x0, 0x50(%rsp)
andq $0x0, 0x38(%rsp)
andq $0x0, 0x28(%rsp)
movq %rax, (%rsp)
movl $0x3, 0x68(%rsp)
movsd 0x459a6(%rip), %xmm2    # 0x1e34d0
movl %r15d, %esi
movq 0xb0(%rsp), %rdx
callq 0xedfe4
addq $0xb0, %rsp
movq 0x88(%r14), %rcx
movq %rax, (%rcx,%r15,8)
jmp 0x19dc35
movq 0x88(%r14), %r11
imulq $0x18, (%r11,%r15,8), %r11
addq 0x70(%r14), %r11
movslq 0xbc(%r14), %rbx
movq %r15, %r12
movslq 0xc0(%r14), %r15
subq $0xb0, %rsp
movq %r15, 0xa0(%rsp)
movq %rbx, 0x98(%rsp)
xorps %xmm2, %xmm2
movups %xmm2, 0x80(%rsp)
movq %r11, 0x78(%rsp)
movl %r10d, 0x70(%rsp)
pushq $0x1
popq %r10
movl %r10d, 0x60(%rsp)
leaq 0xbc(%rsp), %r11
movq %r11, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %r13, 0x30(%rsp)
movl %r10d, 0x20(%rsp)
movl %esi, 0x18(%rsp)
movups %xmm2, 0x8(%rsp)
andq $0x0, 0xa8(%rsp)
andq $0x0, 0x90(%rsp)
andl $0x0, 0x58(%rsp)
andq $0x0, 0x50(%rsp)
andq $0x0, 0x38(%rsp)
andq $0x0, 0x28(%rsp)
movq %rax, (%rsp)
movl $0x3, 0x68(%rsp)
movsd 0x458c7(%rip), %xmm2    # 0x1e34d0
movl %r12d, %esi
movq 0xb0(%rsp), %rdx
callq 0xedfe4
addq $0xb0, %rsp
movq 0x88(%r14), %rcx
movq 0x8(%rcx,%r12,8), %rdx
subq (%rcx,%r12,8), %rdx
cmpq %rdx, %rax
jne 0x19dc44
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5950b(%rip), %rdi     # 0x1f7156
leaq 0x53ed1(%rip), %rsi     # 0x1f1b23
leaq 0x59526(%rip), %rcx     # 0x1f717f
movl $0x25f6, %edx           # imm = 0x25F6
callq 0x2110