// File: chhylp123[P]hifiasm/inter.cpp
// Function: gen_trans_adaptive_aln(ug_trans_t*, unsigned long, ha_ovec_buf_t*, kv_ul_ov_t*, char*, unsigned long, kv_u_trans_t*, double, double, double, double)
uint64_t gen_trans_adaptive_aln(ug_trans_t *s, uint64_t rid, ha_ovec_buf_t *b, kv_ul_ov_t *bl, char *seq, uint64_t len, kv_u_trans_t *fi, 
		double err_low, double err_high, double bw_low, double bw_high)
{
	uint64_t cnt = ((s->idx_n.a[rid+1]-s->idx_n.a[rid])), ol_h = 0, pass_aln = 0; 
	uint32_t high_occ = asm_opt.polyploidy + 1; overlap_region *aux_o = NULL; 
	///note: high_occ is different
	ug_map_lchain(b->abl, rid, seq, len, s->w, s->k, &(s->udb), &b->olist, &b->clist, bw_low, bw_high,
			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[rid], cnt, s->srt_a.a, s->srt_a.n, s->mini_cut, s->chain_cut, fi);
	// if(rid == 160) {
	// 	fprintf(stderr, "-1-[M::%s] utg%.6lu%c, rid::%ld, b->olist->length::%lu\n", 
	// 			__func__, rid+1, "lc"[s->ug->u.a[rid].circ], rid, b->olist.length);
	// }
	///remove candidate chains that have been calculated
	if(!fi) backward_dedup_ol(rid, bl, &(b->sp), &b->olist);
	// if(rid == 160) {
	// 	fprintf(stderr, "-2-[M::%s] utg%.6lu%c, rid::%ld, b->olist->length::%lu\n", 
	// 			__func__, rid+1, "lc"[s->ug->u.a[rid].circ], rid, b->olist.length);
	// }
	filter_by_reliable_ovlp_adv(rid, s->filter, &(b->sp), &b->olist, &(s->udb), s->sec_cutoff, 1, 1, &ol_h);
	clear_Cigar_record(&b->cigar1); clear_Round2_alignment(&b->round2); 
	if(!fi) ol_h = 0;
	
	ol_h = split_ug_lalign(ol_h, &b->olist, err_high, err_low, 
		&b->clist, &(s->udb), s->uopt, seq, len, &b->self_read, &b->ovlp_read, 
		&b->correct, &b->exz, aux_o, rid, s->k, s->chain_cut, NULL);
	
	aux_o = gen_aux_ovlp(&b->olist);///must be here

	ol_h = split_ug_lalign(ol_h, &b->olist, err_high, err_low, 
		&b->clist, &(s->udb), s->uopt, seq, len, &b->self_read, &b->ovlp_read, 
		&b->correct, &b->exz, aux_o, rid, s->k, s->chain_cut, NULL);
	
	if(fi) {///first round
		pass_aln = test_het_aln(s->ug, rid, u_trans_a((*(s->filter)), rid), u_trans_n((*(s->filter)), rid), &(b->sp), &b->olist, len);
		push_ul_ov_t(&(s->udb), u_trans_a((*(s->filter)), rid), u_trans_n((*(s->filter)), rid), rid, &(b->sp), &b->olist, len, pass_aln, err_high, bl);
		// fprintf(stderr, "-1-[M::%s] utg%.6lu%c, rid::%lu, pass_aln::%lu\n", 
		// 	__func__, rid+1, "lc"[s->ug->u.a[rid].circ], rid, pass_aln);
	} else {///second round
		push_ul_ov_t(&(s->udb), NULL, 0, rid, &(b->sp), &b->olist, len, 0, err_high, bl);
		remove_trans_ovlp_connect(s->udb.ug, rid, bl);
	}
	return pass_aln;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq 0x10(%rbp), %rax
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movq %r8, -0x50(%rbp)
movq %r9, -0x58(%rbp)
movsd %xmm0, -0x60(%rbp)
movsd %xmm1, -0x68(%rbp)
movsd %xmm2, -0x70(%rbp)
movsd %xmm3, -0x78(%rbp)
movq -0x30(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rax
movq -0x30(%rbp), %rcx
movq 0x88(%rcx), %rcx
movq -0x38(%rbp), %rdx
subq (%rcx,%rdx,8), %rax
movq %rax, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x90(%rbp)
leaq 0x10436c(%rip), %rax    # 0x3c47f8
movl 0x1bc(%rax), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
movq $0x0, -0xa0(%rbp)
movq -0x40(%rbp), %rax
movq 0xe8(%rax), %rdi
movq -0x38(%rbp), %rax
movl %eax, %esi
movq -0x50(%rbp), %rdx
movq -0x58(%rbp), %rcx
movq -0x30(%rbp), %rax
movslq 0x30(%rax), %r8
movq -0x30(%rbp), %rax
movslq 0x34(%rax), %r9
movq -0x30(%rbp), %rax
addq $0xc8, %rax
movq %rax, -0xe0(%rbp)
movq -0x40(%rbp), %rax
addq $0xa0, %rax
movq %rax, -0xd8(%rbp)
movq -0x40(%rbp), %rax
addq $0x48, %rax
movq %rax, -0xd0(%rbp)
movsd -0x70(%rbp), %xmm0
movsd -0x78(%rbp), %xmm1
movq -0x30(%rbp), %rax
movl 0x60(%rax), %eax
movl %eax, -0xc4(%rbp)
movq -0x40(%rbp), %rax
addq $0x121a0, %rax          # imm = 0x121A0
movq %rax, -0xc0(%rbp)
movq -0x40(%rbp), %rax
addq $0x12250, %rax          # imm = 0x12250
movq %rax, -0xb8(%rbp)
movq -0x30(%rbp), %rax
movl 0xa0(%rax), %r13d
movq -0x30(%rbp), %rax
movq 0x70(%rax), %r12
movq -0x30(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x38(%rbp), %r10
imulq $0x18, (%rax,%r10,8), %rax
addq %rax, %r12
movq -0x80(%rbp), %r15
movq -0x30(%rbp), %rax
movq 0x98(%rax), %r14
movq -0x30(%rbp), %rax
movl 0x90(%rax), %eax
movl %eax, %ebx
movq -0x30(%rbp), %rax
movslq 0xbc(%rax), %r11
movq -0x30(%rbp), %rax
movslq 0xc0(%rax), %r10
movq 0x10(%rbp), %rax
movq %rax, -0xa8(%rbp)
xorl %eax, %eax
leaq -0x94(%rbp), %rax
movq %rax, -0xb0(%rbp)
xorl %eax, %eax
movq -0xe0(%rbp), %rax
movsd 0xbea50(%rip), %xmm2    # 0x37f010
movq %rax, (%rsp)
movq -0xd8(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0xd0(%rbp), %rax
movq %rax, 0x10(%rsp)
movl -0xc4(%rbp), %eax
movl %eax, 0x18(%rsp)
movq -0xc0(%rbp), %rax
movl $0x1, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movq -0xb8(%rbp), %rax
movq $0x0, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq -0xb0(%rbp), %rax
movq %rax, 0x48(%rsp)
movq -0xa8(%rbp), %rax
movq $0x0, 0x50(%rsp)
movl $0x0, 0x58(%rsp)
movl $0x1, 0x60(%rsp)
movl $0x3, 0x68(%rsp)
movl %r13d, 0x70(%rsp)
movq %r12, 0x78(%rsp)
movq %r15, 0x80(%rsp)
movq %r14, 0x88(%rsp)
movq %rbx, 0x90(%rsp)
movq %r11, 0x98(%rsp)
movq %r10, 0xa0(%rsp)
movq %rax, 0xa8(%rsp)
callq 0x1b3e60
cmpq $0x0, 0x10(%rbp)
jne 0x2c06b5
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq $0x12250, %rdx          # imm = 0x12250
movq -0x40(%rbp), %rcx
addq $0xa0, %rcx
callq 0x2bfbf0
movq -0x38(%rbp), %rax
movl %eax, %edi
movq -0x30(%rbp), %rax
movq 0xf8(%rax), %rsi
movq -0x40(%rbp), %rdx
addq $0x12250, %rdx          # imm = 0x12250
movq -0x40(%rbp), %rcx
addq $0xa0, %rcx
movq -0x30(%rbp), %r8
addq $0xc8, %r8
movq -0x30(%rbp), %rax
movsd 0x48(%rax), %xmm0
movl $0x1, %r9d
leaq -0x88(%rbp), %rax
movq $0x1, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x2bcf70
movq -0x40(%rbp), %rdi
addq $0x108, %rdi            # imm = 0x108
callq 0x31d60
movq -0x40(%rbp), %rdi
addq $0x9330, %rdi           # imm = 0x9330
callq 0x31cb0
cmpq $0x0, 0x10(%rbp)
jne 0x2c0741
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0xa0, %rsi
movsd -0x68(%rbp), %xmm0
movsd -0x60(%rbp), %xmm1
movq -0x40(%rbp), %rdx
addq $0x48, %rdx
movq -0x30(%rbp), %rcx
addq $0xc8, %rcx
movq -0x30(%rbp), %rax
movq (%rax), %r8
movq -0x50(%rbp), %r9
movq -0x58(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x40(%rbp), %r13
addq $0x8, %r13
movq -0x40(%rbp), %r12
addq $0x28, %r12
movq -0x40(%rbp), %r15
addq $0x2c0, %r15            # imm = 0x2C0
movq -0x40(%rbp), %r14
addq $0x12268, %r14          # imm = 0x12268
movq -0xa0(%rbp), %rbx
movq -0x38(%rbp), %r11
movq -0x30(%rbp), %rax
movslq 0x34(%rax), %r10
movq -0x30(%rbp), %rax
movslq 0xc0(%rax), %rax
movq %rax, -0xf8(%rbp)
xorl %eax, %eax
movq -0x100(%rbp), %rax
movq %rax, (%rsp)
movq -0xf8(%rbp), %rax
movq %r13, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movq %r15, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
movq %r11, 0x30(%rsp)
movq %r10, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
callq 0x2be1b0
movq %rax, -0x88(%rbp)
movq -0x40(%rbp), %rdi
addq $0xa0, %rdi
callq 0x2b0b20
movq %rax, -0xa0(%rbp)
movq -0x88(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0xa0, %rsi
movsd -0x68(%rbp), %xmm0
movsd -0x60(%rbp), %xmm1
movq -0x40(%rbp), %rdx
addq $0x48, %rdx
movq -0x30(%rbp), %rcx
addq $0xc8, %rcx
movq -0x30(%rbp), %rax
movq (%rax), %r8
movq -0x50(%rbp), %r9
movq -0x58(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x40(%rbp), %r13
addq $0x8, %r13
movq -0x40(%rbp), %r12
addq $0x28, %r12
movq -0x40(%rbp), %r15
addq $0x2c0, %r15            # imm = 0x2C0
movq -0x40(%rbp), %r14
addq $0x12268, %r14          # imm = 0x12268
movq -0xa0(%rbp), %rbx
movq -0x38(%rbp), %r11
movq -0x30(%rbp), %rax
movslq 0x34(%rax), %r10
movq -0x30(%rbp), %rax
movslq 0xc0(%rax), %rax
movq %rax, -0xe8(%rbp)
xorl %eax, %eax
movq -0xf0(%rbp), %rax
movq %rax, (%rsp)
movq -0xe8(%rbp), %rax
movq %r13, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movq %r15, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
movq %r11, 0x30(%rsp)
movq %r10, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
callq 0x2be1b0
movq %rax, -0x88(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x2c0a43
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0xf8(%rax), %rax
movq 0x10(%rax), %rdx
movq -0x30(%rbp), %rax
movq 0xf8(%rax), %rax
movq 0x28(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
imulq $0x30, %rax, %rax
addq %rax, %rdx
movq -0x30(%rbp), %rax
movq 0xf8(%rax), %rax
movq 0x28(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movl %eax, %ecx
movq -0x40(%rbp), %r8
addq $0x12250, %r8           # imm = 0x12250
movq -0x40(%rbp), %r9
addq $0xa0, %r9
movq -0x58(%rbp), %rax
movq %rax, (%rsp)
callq 0x2be860
movl %eax, %eax
movq %rax, -0x90(%rbp)
movq -0x30(%rbp), %rdi
addq $0xc8, %rdi
movq -0x30(%rbp), %rax
movq 0xf8(%rax), %rax
movq 0x10(%rax), %rsi
movq -0x30(%rbp), %rax
movq 0xf8(%rax), %rax
movq 0x28(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
imulq $0x30, %rax, %rax
addq %rax, %rsi
movq -0x30(%rbp), %rax
movq 0xf8(%rax), %rax
movq 0x28(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movl %eax, %edx
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
addq $0x12250, %r8           # imm = 0x12250
movq -0x40(%rbp), %r9
addq $0xa0, %r9
movq -0x58(%rbp), %r11
movq -0x90(%rbp), %r10
movsd -0x68(%rbp), %xmm0
movq -0x48(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x2bf260
jmp 0x2c0aa9
movq -0x30(%rbp), %rdi
addq $0xc8, %rdi
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
addq $0x12250, %r8           # imm = 0x12250
movq -0x40(%rbp), %r9
addq $0xa0, %r9
movq -0x58(%rbp), %r10
movsd -0x68(%rbp), %xmm0
movq -0x48(%rbp), %rax
xorl %edx, %edx
movq %rdx, %rsi
movq %r10, (%rsp)
movq $0x0, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x2bf260
movq -0x30(%rbp), %rax
movq 0xc8(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x2c02d0
movq -0x90(%rbp), %rax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)