// File: /workspace/github_cpp_makefile_star2_O1/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, %r10
movq 0x18(%rdi), %rax
movq 0x20(%rdi), %r9
movsd 0x47daa(%rip), %xmm0    # 0x225520
divsd 0x40(%rdi), %xmm0
movq (%rax,%r10,8), %rax
movq %rax, 0x28(%rsp)
leaq 0xacfcd(%rip), %rax     # 0x28a758
movl 0x1bc(%rax), %eax
incl %eax
movl %eax, 0x14(%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 0x1dd7cf
cmpl $0x0, 0xb4(%r14)
je 0x1dd7cf
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 0x1dde98
movq 0x18(%rdi), %rdx
movq 0x20(%rdx), %rdx
cmpl $0x0, (%rdx,%rbp,8)
js 0x1dde98
movq %r8, 0x8(%rsp)
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
testl %eax, %eax
je 0x1ddc9a
minsd 0x47d0f(%rip), %xmm0    # 0x225528
cvttsd2si %xmm0, %rax
movq %rax, 0x68(%rsp)
movq 0x88(%r14), %rax
movq (%rax,%rbp,8), %rdx
movq 0x8(%rax,%rbp,8), %r11
subq %rdx, %r11
movq %rcx, 0x58(%rsp)
movq 0x28(%rsp), %r13
movq 0xe8(%r13), %rdi
movslq 0x30(%r14), %r8
movq %r9, 0x70(%rsp)
movslq 0x34(%r14), %r9
leaq 0xc8(%r14), %rax
movq %rax, 0x48(%rsp)
leaq 0xa0(%r13), %r12
leaq 0x48(%r13), %rax
movq %rax, 0x50(%rsp)
movsd 0x38(%r14), %xmm0
movsd 0x50(%r14), %xmm1
movl 0x60(%r14), %eax
movq %rax, 0x20(%rsp)
leaq 0x121a0(%r13), %rax
movq %rax, 0x40(%rsp)
leaq 0x12250(%r13), %rax
movq %rax, 0x30(%rsp)
movq %rbp, 0x18(%rsp)
leaq (%rdx,%rdx,2), %rbp
shlq $0x3, %rbp
addq 0x70(%r14), %rbp
movl 0xa0(%r14), %eax
movq %rax, 0x38(%rsp)
movl 0x90(%r14), %r15d
movq %r10, 0x60(%rsp)
movslq 0xbc(%r14), %r10
movslq 0xc0(%r14), %rbx
movsd 0x47ba4(%rip), %xmm2    # 0x225480
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %rdx
movl $0x0, %eax
pushq %rax
pushq %rbx
pushq %r10
pushq %r15
pushq 0x98(%r14)
pushq %r11
pushq %rbp
pushq 0x70(%rsp)
pushq $0x3
movl $0x1, %r10d
pushq %r10
pushq $0x0
movl $0x0, %eax
pushq %rax
leaq 0x74(%rsp), %r11
pushq %r11
movq 0x98(%rsp), %r15
pushq %r15
pushq %rax
pushq 0xb8(%rsp)
pushq %rax
pushq %r10
pushq 0xb0(%rsp)
movq 0xe8(%rsp), %rbp
pushq %rbp
pushq %r12
movq 0xf0(%rsp), %rbx
pushq %rbx
callq 0x12e4fe
addq $0xb0, %rsp
movq 0xf8(%r14), %rsi
movsd 0x48(%r14), %xmm0
movq 0x18(%rsp), %rdi
movq %r15, %rdx
movq %r12, %rcx
movq %rbx, %r8
xorl %r9d, %r9d
callq 0x1ba084
leaq 0x108(%r13), %rdi
callq 0x48007
leaq 0x9330(%r13), %rdi
callq 0x47f99
movq (%r14), %rcx
leaq 0x8(%r13), %rax
movq %rax, 0x20(%rsp)
leaq 0x28(%r13), %r11
movq %r11, 0x38(%rsp)
leaq 0x2c0(%r13), %r15
movq %r15, 0x40(%rsp)
leaq 0x12268(%r13), %rax
movq %rax, 0x30(%rsp)
movsd 0x40(%r14), %xmm0
movslq 0x34(%r14), %rax
movslq 0xc0(%r14), %r10
movq %r12, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq 0x8(%rsp), %r8
movq 0x58(%rsp), %r9
movl $0x0, %ebp
pushq %rbp
pushq %r10
pushq %rax
pushq 0x30(%rsp)
movq 0x88(%rsp), %rbp
pushq %rbp
xorl %eax, %eax
pushq %rax
movq 0x60(%rsp), %rbx
pushq %rbx
pushq %r15
pushq %r11
pushq 0x68(%rsp)
callq 0x852da
addq $0x50, %rsp
movq %r12, %rdi
callq 0x1b3684
movq (%r14), %rcx
movsd 0x40(%r14), %xmm0
movslq 0x34(%r14), %r10
movslq 0xc0(%r14), %r11
movq %r12, %rdi
movq 0x50(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq 0x8(%rsp), %r8
movq 0x58(%rsp), %r9
xorl %r15d, %r15d
pushq %r15
pushq %r11
pushq %r10
pushq 0x30(%rsp)
pushq %rbp
pushq %rax
pushq %rbx
pushq 0x78(%rsp)
pushq 0x78(%rsp)
pushq 0x68(%rsp)
callq 0x852da
movq 0xb0(%rsp), %rcx
movq 0xc0(%rsp), %rdx
addq $0x50, %rsp
movq 0xb0(%r13), %rax
testq %rax, %rax
je 0x1dde98
imulq $0x68, %rcx, %rcx
leaq (%rdx,%rcx), %r15
addq $0x18, %r15
addq 0x8(%r15), %rax
cmpq %rax, 0x10(%r15)
jae 0x1ddaf4
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(%r15)
movq (%r15), %rdi
leaq (%rax,%rax,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax), %rsi
incq %rsi
callq 0x2370
movq %rax, (%r15)
movq 0x8(%r15), %rax
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rax
cmpq $0x0, 0xb0(%rax)
je 0x1ddc63
movl $0x1, %r13d
xorl %ebp, %ebp
movl $0x40000000, %ebx       # imm = 0x40000000
movq 0x10(%r15), %rax
cmpq %rax, 0x8(%r15)
jne 0x1ddb51
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%r15)
movq (%r15), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq %rax, (%r15)
movq (%r15), %rcx
movq 0x8(%r15), %rax
leaq 0x1(%rax), %rdx
movq %rdx, 0x8(%r15)
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rsi
addq %rax, %rsi
leaq (%rcx,%rsi), %rdi
movq 0x18(%rsp), %rax
movl %eax, (%rcx,%rsi)
movq (%r12), %rdx
imulq $0xa8, %rbp, %rax
movl 0x10(%rdx,%rax), %edx
movl %edx, 0xc(%rcx,%rsi)
movl 0x18(%rcx,%rsi), %r8d
orl %ebx, %r8d
movl %r8d, 0x18(%rcx,%rsi)
movq (%r12), %r9
movl 0x30(%r9,%rax), %r9d
movl $0x3fffffff, %r10d      # imm = 0x3FFFFFFF
andl %r10d, %r9d
andl $0xc0000000, %r8d       # imm = 0xC0000000
orl %r9d, %r8d
movl %r8d, 0x18(%rcx,%rsi)
movq (%r12), %r8
movl 0x1c(%r8,%rax), %r10d
shll $0x1f, %r10d
orl %r10d, %r9d
orl %ebx, %r9d
movl %r9d, 0x18(%rcx,%rsi)
movq (%r12), %r8
movl 0x4(%r8,%rax), %r9d
movl %r9d, 0x4(%rcx,%rsi)
movl 0x8(%r8,%rax), %r9d
incl %r9d
movl %r9d, 0x8(%rcx,%rsi)
testl %r10d, %r10d
je 0x1ddc28
movq 0x48(%rsp), %rcx
movq (%rcx), %rcx
movq 0x10(%rcx), %rcx
leaq (%rdx,%rdx,4), %rdx
movl (%rcx,%rdx,8), %esi
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
andl %r10d, %esi
movl 0x18(%r8,%rax), %r9d
notl %r9d
addl %esi, %r9d
movl %r9d, 0x10(%rdi)
movl (%rcx,%rdx,8), %ecx
andl %r10d, %ecx
subl 0x14(%r8,%rax), %ecx
jmp 0x1ddc37
movl 0x14(%r8,%rax), %ecx
movl %ecx, 0x10(%rdi)
movl 0x18(%r8,%rax), %ecx
incl %ecx
movl %ecx, 0x14(%rdi)
movq 0x8(%r14), %rsi
callq 0x1b9e17
testl %eax, %eax
jne 0x1ddc4b
decq 0x8(%r15)
movl %r13d, %ebp
incl %r13d
movq 0x28(%rsp), %rax
cmpq %rbp, 0xb0(%rax)
ja 0x1ddb1d
movq 0x8(%rsp), %rbx
leaq (%rbx,%rbx,8), %rax
leaq (%rax,%rax,2), %rdi
addq %rbx, %rdi
addq (%r15), %rdi
movl 0x8(%r15), %esi
subl %ebx, %esi
movsd 0x48(%r14), %xmm0
movq 0x18(%rsp), %rdx
callq 0x1b9b23
movl %eax, %eax
addq %rbx, %rax
movq %rax, 0x8(%r15)
jmp 0x1dde98
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 0x1dddae
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 0xc4(%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 0x476f8(%rip), %xmm2    # 0x225480
movl %ebp, %esi
movq 0xb8(%rsp), %rdx
callq 0x12e4fe
addq $0xb0, %rsp
movq 0x88(%r14), %rcx
movq %rax, (%rcx,%rbp,8)
jmp 0x1dde98
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 0xc4(%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 0x47613(%rip), %xmm2    # 0x225480
movl %ebp, %esi
movq 0xb8(%rsp), %rdx
callq 0x12e4fe
addq $0xb0, %rsp
movq 0x88(%r14), %rcx
movq 0x8(%rcx,%rbp,8), %rdx
subq (%rcx,%rbp,8), %rdx
cmpq %rdx, %rax
jne 0x1ddea7
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5b110(%rip), %rdi     # 0x238fbe
leaq 0x55ad6(%rip), %rsi     # 0x23398b
leaq 0x5b12b(%rip), %rcx     # 0x238fe7
movl $0x25f6, %edx           # imm = 0x25F6
callq 0x2110