// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movq %rsi, %rbp
movq %rdi, %r14
movslq %edx, %r9
movq 0x18(%rdi), %rax
movq 0x20(%rdi), %r10
movsd 0x4944b(%rip), %xmm0    # 0x231620
divsd 0x40(%rdi), %xmm0
movq (%rax,%r9,8), %rax
movq %rax, 0x28(%rsp)
leaq 0xad56e(%rip), %rax     # 0x295758
movl 0x1bc(%rax), %eax
incl %eax
movl %eax, 0xc(%rsp)
movq 0x8(%rdi), %rdi
movq 0x10(%rdi), %rax
leaq (%rsi,%rsi,4), %rdx
movq 0x20(%rax,%rdx,8), %r8
movl (%rax,%rdx,8), %ecx
movl 0xb8(%r14), %eax
testl %eax, %eax
jne 0x1e822e
cmpl $0x0, 0xb4(%r14)
je 0x1e822e
movq 0x88(%r14), %rdx
movq $0x0, (%rdx,%rbp,8)
movq 0x28(%r14), %rdx
movq (%rdx), %rsi
movq 0x80(%rdx), %rdx
movl (%rsi,%rbp,4), %esi
incq %rdx
cmpq %rsi, %rdx
jb 0x1e8906
movq 0x18(%rdi), %rdx
movq 0x20(%rdx), %rdx
cmpl $0x0, (%rdx,%rbp,8)
js 0x1e8906
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
testl %eax, %eax
movq %r8, 0x10(%rsp)
je 0x1e8708
minsd 0x493b0(%rip), %xmm0    # 0x231628
cvttsd2si %xmm0, %rax
movq %rax, 0x60(%rsp)
movq 0x88(%r14), %rax
movq (%rax,%rbp,8), %rdx
movq 0x8(%rax,%rbp,8), %r11
subq %rdx, %r11
movq %rcx, 0x48(%rsp)
movq 0x28(%rsp), %r13
movq 0xe8(%r13), %rdi
movslq 0x30(%r14), %rax
movq %rax, 0x58(%rsp)
movq %r9, 0x70(%rsp)
movslq 0x34(%r14), %r9
leaq 0xc8(%r14), %rax
movq %rax, 0x38(%rsp)
leaq 0xa0(%r13), %r12
leaq 0x48(%r13), %rax
movq %rax, 0x40(%rsp)
movsd 0x38(%r14), %xmm0
movsd 0x50(%r14), %xmm1
movl 0x60(%r14), %eax
movq %rax, 0x20(%rsp)
leaq 0x121a0(%r13), %rax
movq %rax, 0x18(%rsp)
leaq 0x12250(%r13), %rax
movq %rax, 0x30(%rsp)
leaq (%rdx,%rdx,2), %r15
shlq $0x3, %r15
addq 0x70(%r14), %r15
movq %rbp, (%rsp)
movl 0xa0(%r14), %eax
movq %rax, 0x50(%rsp)
movl 0x90(%r14), %ebx
movslq 0xbc(%r14), %rax
movq %r10, 0x68(%rsp)
movslq 0xc0(%r14), %r10
movsd 0x49241(%rip), %xmm2    # 0x231580
movq (%rsp), %rsi
movq %r8, %rdx
movq 0x58(%rsp), %r8
movl $0x0, %ebp
pushq %rbp
pushq %r10
pushq %rax
pushq %rbx
pushq 0x98(%r14)
pushq %r11
pushq %r15
pushq 0x88(%rsp)
pushq $0x3
movl $0x1, %r10d
pushq %r10
pushq $0x0
movl $0x0, %eax
pushq %rax
leaq 0x6c(%rsp), %r11
pushq %r11
movq 0x98(%rsp), %rbx
pushq %rbx
pushq %rax
pushq 0x90(%rsp)
pushq %rax
pushq %r10
pushq 0xb0(%rsp)
movq 0xd8(%rsp), %rbp
pushq %rbp
pushq %r12
movq 0xe0(%rsp), %r15
pushq %r15
callq 0x13470d
addq $0xb0, %rsp
movq 0xf8(%r14), %rsi
movsd 0x48(%r14), %xmm0
movq (%rsp), %rdi
movq %rbx, %rdx
movq %r12, %rcx
movq %r15, %r8
xorl %r9d, %r9d
callq 0x1c3e87
leaq 0x108(%r13), %rdi
callq 0x475fb
leaq 0x9330(%r13), %rdi
callq 0x4758d
movq (%r14), %rcx
leaq 0x8(%r13), %rax
movq %rax, 0x20(%rsp)
leaq 0x28(%r13), %rbx
leaq 0x2c0(%r13), %r11
movq %r11, 0x30(%rsp)
leaq 0x12268(%r13), %rax
movq %rax, 0x18(%rsp)
movsd 0x40(%r14), %xmm0
movslq 0x34(%r14), %rax
movslq 0xc0(%r14), %r10
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq 0x10(%rsp), %r8
movq 0x48(%rsp), %r9
movl $0x0, %ebp
pushq %rbp
pushq %r10
pushq %rax
pushq 0x18(%rsp)
movq 0x80(%rsp), %rbp
pushq %rbp
xorl %eax, %eax
pushq %rax
pushq 0x48(%rsp)
pushq %r11
pushq %rbx
pushq 0x68(%rsp)
callq 0x849d9
addq $0x50, %rsp
movq %r12, %rdi
callq 0x1bce5f
movq (%r14), %rcx
movsd 0x40(%r14), %xmm0
movslq 0x34(%r14), %r10
movslq 0xc0(%r14), %r11
movq %r12, %rdi
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x10(%rsp), %r8
movq 0x48(%rsp), %r9
xorl %r15d, %r15d
pushq %r15
pushq %r11
pushq %r10
pushq 0x18(%rsp)
pushq %rbp
pushq %rax
pushq 0x48(%rsp)
pushq 0x68(%rsp)
pushq %rbx
pushq 0x68(%rsp)
callq 0x849d9
movq 0xb8(%rsp), %rdx
movq 0xc0(%rsp), %rcx
addq $0x50, %rsp
movq 0xb0(%r13), %rax
testq %rax, %rax
je 0x1e8906
imulq $0x68, %rcx, %rcx
leaq (%rdx,%rcx), %r13
addq $0x18, %r13
movq 0x8(%r13), %rbx
addq %rbx, %rax
cmpq %rax, 0x10(%r13)
movq (%rsp), %rbp
jae 0x1e8576
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
leaq 0x1(%rcx), %rax
movq %rax, 0x10(%r13)
movq (%r13), %rdi
leaq (%rax,%rax,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax), %rsi
incq %rsi
callq 0x2370
movq %rax, (%r13)
movq 0x8(%r13), %rbx
movq 0x28(%rsp), %rax
cmpq $0x0, 0xb0(%rax)
movq %rbx, %rsi
je 0x1e86dc
movq %rbx, 0x10(%rsp)
movl $0x1, %r15d
xorl %ebp, %ebp
movl $0x40000000, %ebx       # imm = 0x40000000
movq (%r13), %rax
movq 0x8(%r13), %rcx
cmpq 0x10(%r13), %rcx
jne 0x1e85c5
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r13)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%r13)
movq 0x8(%r13), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r13)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rsi
addq %rcx, %rsi
leaq (%rax,%rsi), %rdi
movq (%rsp), %rcx
movl %ecx, (%rax,%rsi)
movq (%r12), %rdx
imulq $0xa8, %rbp, %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 0x1e8694
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
leaq (%rdx,%rdx,4), %rdx
movl (%rax,%rdx,8), %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,8), %eax
andl %r10d, %eax
subl 0x14(%r8,%rcx), %eax
jmp 0x1e86a3
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 0x1c3c2d
testl %eax, %eax
jne 0x1e86b7
decq 0x8(%r13)
movl %r15d, %ebp
incl %r15d
movq 0x28(%rsp), %rax
cmpq %rbp, 0xb0(%rax)
ja 0x1e8588
movq 0x8(%r13), %rsi
movq (%rsp), %rbp
movq 0x10(%rsp), %rbx
leaq (%rbx,%rbx,8), %rax
leaq (%rax,%rax,2), %rdi
addq %rbx, %rdi
addq (%r13), %rdi
subl %ebx, %esi
movsd 0x48(%r14), %xmm0
movl %ebp, %edx
callq 0x1c389b
movl %eax, %eax
addq %rbx, %rax
movq %rax, 0x8(%r13)
jmp 0x1e8906
leaq 0xc8(%r14), %rax
movq 0x28(%rsp), %rdx
leaq 0x121a0(%rdx), %r13
cmpl $0x0, 0xb4(%r14)
leaq 0x12250(%rdx), %rsi
movq 0xe8(%rdx), %rdi
movslq 0x30(%r14), %r8
movslq 0x34(%r14), %r9
movsd 0x38(%r14), %xmm0
movsd 0x50(%r14), %xmm1
movl 0x60(%r14), %edx
movl 0xa0(%r14), %r10d
je 0x1e881c
movslq 0xbc(%r14), %r11
movslq 0xc0(%r14), %rbx
subq $0xb0, %rsp
xorl %r15d, %r15d
movq %r15, 0xa8(%rsp)
movq %rbx, 0xa0(%rsp)
movq %r11, 0x98(%rsp)
xorps %xmm2, %xmm2
movups %xmm2, 0x88(%rsp)
movups %xmm2, 0x78(%rsp)
movl %r10d, 0x70(%rsp)
movl $0x1, %r10d
movl %r10d, 0x60(%rsp)
movq %r15, 0x50(%rsp)
leaq 0xbc(%rsp), %r11
movq %r11, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq %r15, 0x38(%rsp)
movq %r13, 0x30(%rsp)
movq %r15, 0x28(%rsp)
movl %r10d, 0x20(%rsp)
movl %edx, 0x18(%rsp)
movups %xmm2, 0x8(%rsp)
movq %rax, (%rsp)
movl $0x3, 0x68(%rsp)
movl $0x0, 0x58(%rsp)
movsd 0x48d8a(%rip), %xmm2    # 0x231580
movl %ebp, %esi
movq 0xc0(%rsp), %rdx
callq 0x13470d
addq $0xb0, %rsp
movq 0x88(%r14), %rcx
movq %rax, (%rcx,%rbp,8)
jmp 0x1e8906
movq 0x88(%r14), %r11
movq (%r11,%rbp,8), %r11
leaq (%r11,%r11,2), %r11
shlq $0x3, %r11
addq 0x70(%r14), %r11
movslq 0xbc(%r14), %rbx
movslq 0xc0(%r14), %r15
subq $0xb0, %rsp
xorl %r12d, %r12d
movq %r12, 0xa8(%rsp)
movq %r15, 0xa0(%rsp)
movq %rbx, 0x98(%rsp)
movq %r12, 0x90(%rsp)
xorps %xmm2, %xmm2
movups %xmm2, 0x80(%rsp)
movq %r11, 0x78(%rsp)
movl %r10d, 0x70(%rsp)
movl $0x1, %r10d
movl %r10d, 0x60(%rsp)
movq %r12, 0x50(%rsp)
leaq 0xbc(%rsp), %r11
movq %r11, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq %r12, 0x38(%rsp)
movq %r13, 0x30(%rsp)
movq %r12, 0x28(%rsp)
movl %r10d, 0x20(%rsp)
movl %edx, 0x18(%rsp)
movups %xmm2, 0x8(%rsp)
movq %rax, (%rsp)
movl $0x3, 0x68(%rsp)
movl $0x0, 0x58(%rsp)
movsd 0x48ca5(%rip), %xmm2    # 0x231580
movl %ebp, %esi
movq 0xc0(%rsp), %rdx
callq 0x13470d
addq $0xb0, %rsp
movq 0x88(%r14), %rcx
movq 0x8(%rcx,%rbp,8), %rdx
subq (%rcx,%rbp,8), %rdx
cmpq %rdx, %rax
jne 0x1e8915
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5c972(%rip), %rdi     # 0x24528e
leaq 0x57338(%rip), %rsi     # 0x23fc5b
leaq 0x5c98d(%rip), %rcx     # 0x2452b7
movl $0x25f6, %edx           # imm = 0x25F6
callq 0x2110