// File: chhylp123[P]hifiasm/inter.cpp
// Function: direct_ctg_trans_chain(mg_tbuf_s*, unsigned int, glchain_t*, gdpchain_t*, st_mt_t*, haplotype_evdience_alloc*, ul_idx_t const*, ug_opt_t const*, long, double, long, long, Chain_Data*, ma_ug_t*, scaf_res_t*, ma_ug_t*, scaf_res_t*, ma_ug_t*, bubble_type*, kv_u_trans_t*, asg_t const*, unsigned long, unsigned long)
uint32_t direct_ctg_trans_chain(mg_tbuf_t *b, uint32_t id, glchain_t *ll, gdpchain_t *gdp, st_mt_t *sps, haplotype_evdience_alloc *hap, const ul_idx_t *uref, const ug_opt_t *uopt,
int64_t bw, double diff_ec_ul, int64_t max_skip, int64_t ulid, Chain_Data* dp, ma_ug_t *qry, scaf_res_t *qry_sc, ma_ug_t *ref, scaf_res_t *ref_sc, ma_ug_t *gfa, bubble_type *bub, kv_u_trans_t *ta, const asg_t *rg, uint64_t soff, uint64_t is_exact)
{
	// res->bb.n = 0;
	// if(ulid != 86660) return 0;
	kv_ul_ov_t *idx = &(ll->lo), *init = &(ll->tk); ///int64_t max_idx;
	asg64_v b0, b1; uint32_t is_self = (qry?0:1); idx->n = 0;
	
	cl_trans_gen(id, qry?qry->u.a[id].len:ref->u.a[id].len, qry_sc?&(qry_sc->a[id]):&(ref_sc->a[id]), idx, uref, ref, ref_sc, gfa, bub, ta, is_self, is_exact);
	if(idx->n == 0) return 0;

	copy_asg_arr(b0, (*sps)); 
	ctg_trans_gp_chain(id, idx, uref, uopt, bw, diff_ec_ul, qry?qry->u.a[id].len:ref->u.a[id].len, dp, ref, is_self, &b0, ((is_exact)?(0.5):(0.666666)));
	copy_asg_arr((*sps), b0); 
	if(idx->n == 0) return 0;

	copy_asg_arr(b0, (*sps)); copy_asg_arr(b1, ll->srt.a); 
	filter_ctg_trans(id, qry, ref, idx, &b0, &b1, 0.5, 10000, /**0.333333**/0.85, 10000, 0.3, soff, is_self);
	copy_asg_arr((*sps), b0); copy_asg_arr(ll->srt.a, b1); 
	if(idx->n == 0) return 0;

	push_ctg_trans_res(id, idx, init);

	/**
	// gl_rg2ug_gen(rch, idx, uref, 1, 2, ulid);
	ctg_rg2ug_gen(rch, idx, uref);

	// uint32_t k;
	// fprintf(stderr, "[M::%s] rch->len::%u, rch->n::%u, idx->n::%u\n", __func__, (uint32_t)rch->len, (uint32_t)rch->n, (uint32_t)idx->n);
	// for (k = 0; k < idx->n; k++) {
	// 	fprintf(stderr, "[k->%u::utg%.6u%c(len->%u::n->%u)]\tq::[%u, %u)\t%c\tt::[%u, %u)\n", 
    //         k, (idx->a[k].tn>>1) + 1, "lc"[uref->ug->u.a[(idx->a[k].tn>>1)].circ], uref->ug->u.a[(idx->a[k].tn>>1)].len, idx->a[k].sec,
    //         idx->a[k].qs, idx->a[k].qe, "+-"[idx->a[k].rev], idx->a[k].ts, idx->a[k].te);
	// }

	// for (k = 0; k < idx->n; k++) {
	// 	fprintf(stderr, "utg%.6u%c,", (idx->a[k].tn>>1)+1, "lc"[uref->ug->u.a[(idx->a[k].tn>>1)].circ]);
	// }
	// fprintf(stderr, "\n");
	
	if(idx->n == 0) return 0;
	///generate linear chains
	gen_linear_chains_ctg(idx, init, uref, uopt, bw, diff_ec_ul, rch->len, dp);
	
	if(idx->n == 0) return 0;
	
	dump_linear_chain(uref->ug, idx, &(gdp->l), rch->len, ulid);
	if(gdp->l.n == 0) return 0;

	kv_resize(uint64_t, ll->srt.a, gdp->l.n);
	max_idx = ctg_chain_graph(b->km, uref, uref->ug, &(gdp->l), &(gdp->swap), &(gdp->dst), &(gdp->out),
        &(gdp->path), rch->len, uopt, G_CHAIN_BW, N_GCHAIN_RATE, ll->srt.a.a, sps, dp, UG_SKIP_GRAPH_N, UG_ITER_N, UG_DIS_N*100);

	//sps -> idx; (gdp->l) -> alignments
	if(max_idx >= 0) {
		max_idx = select_max_ctg_chain(b->km, uref, ulid, sps, &(gdp->l), &(ll->tk), uref->ug->g, &(gdp->dst_done), &(gdp->out), &(gdp->path), &(gdp->swap));
		if(max_idx) {
			push_ctg_res(res, &(gdp->swap));
			return 1;
		}
	}
	**/

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq 0x88(%rbp), %rax
movq 0x80(%rbp), %rax
movq 0x78(%rbp), %rax
movq 0x70(%rbp), %rax
movq 0x68(%rbp), %rax
movq 0x60(%rbp), %rax
movq 0x58(%rbp), %rax
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x28(%rbp)
movl %esi, -0x2c(%rbp)
movq %rdx, -0x38(%rbp)
movq %rcx, -0x40(%rbp)
movq %r8, -0x48(%rbp)
movq %r9, -0x50(%rbp)
movsd %xmm0, -0x58(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x68(%rbp)
movq 0x40(%rbp), %rdx
movl $0x1, %eax
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, -0x9c(%rbp)
movq -0x60(%rbp), %rax
movq $0x0, 0x8(%rax)
movl -0x2c(%rbp), %eax
movl %eax, -0xa0(%rbp)
cmpq $0x0, 0x40(%rbp)
je 0x2e3a5b
movq 0x40(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0xa4(%rbp)
jmp 0x2e3a7a
movq 0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0xa8(%rbp)
cmpq $0x0, 0x48(%rbp)
je 0x2e3aa7
movq 0x48(%rbp), %rax
movq (%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xb0(%rbp)
jmp 0x2e3abf
movq 0x58(%rbp), %rax
movq (%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xb0(%rbp)
movl -0xa8(%rbp), %esi
movl -0xa0(%rbp), %edi
movq -0xb0(%rbp), %rdx
movq -0x60(%rbp), %rcx
movq 0x10(%rbp), %r8
movq 0x50(%rbp), %r9
movq 0x58(%rbp), %r15
movq 0x60(%rbp), %r14
movq 0x68(%rbp), %rbx
movq 0x70(%rbp), %r11
movl -0x9c(%rbp), %r10d
movq 0x88(%rbp), %rax
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movl %r10d, 0x20(%rsp)
movl %eax, 0x28(%rsp)
callq 0x2e09c0
movq -0x60(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x2e3b34
movl $0x0, -0x1c(%rbp)
jmp 0x2e3e1b
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0xdc(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq 0x18(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq 0x20(%rbp), %rax
movq %rax, -0xc0(%rbp)
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
cmpq $0x0, 0x40(%rbp)
je 0x2e3bc1
movq 0x40(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0xe0(%rbp)
jmp 0x2e3be0
movq 0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0xe0(%rbp)
movl -0xe0(%rbp), %eax
movl %eax, %eax
movq %rax, -0x110(%rbp)
movq 0x38(%rbp), %rax
movq %rax, -0x108(%rbp)
movq 0x50(%rbp), %rax
movq %rax, -0x100(%rbp)
movl -0x9c(%rbp), %eax
movl %eax, -0xf4(%rbp)
movq 0x88(%rbp), %rax
movsd 0x9e650(%rip), %xmm0    # 0x382270
movsd 0xacb30(%rip), %xmm1    # 0x390758
movsd %xmm1, -0xf0(%rbp)
cmpq $0x0, %rax
movsd %xmm0, -0xe8(%rbp)
jne 0x2e3c4e
movsd -0xf0(%rbp), %xmm0
movsd %xmm0, -0xe8(%rbp)
movl -0xf4(%rbp), %r10d
movq -0x100(%rbp), %r11
movq -0x108(%rbp), %rbx
movq -0x110(%rbp), %r9
movsd -0xb8(%rbp), %xmm0
movq -0xc0(%rbp), %r8
movq -0xc8(%rbp), %rcx
movq -0xd0(%rbp), %rdx
movq -0xd8(%rbp), %rsi
movl -0xdc(%rbp), %edi
movsd -0xe8(%rbp), %xmm1
leaq -0x80(%rbp), %rax
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x2e25c0
movq -0x70(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x80(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq -0x78(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x60(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x2e3cf2
movl $0x0, -0x1c(%rbp)
jmp 0x2e3e1b
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x90(%rbp)
movl -0x2c(%rbp), %edi
movq 0x40(%rbp), %rsi
movq 0x50(%rbp), %rdx
movq -0x60(%rbp), %rcx
movq 0x80(%rbp), %r10
movl -0x9c(%rbp), %eax
leaq -0x80(%rbp), %r8
leaq -0x98(%rbp), %r9
movsd 0x9e4ff(%rip), %xmm0    # 0x382270
movsd 0xa2aef(%rip), %xmm1    # 0x386868
movsd 0x9dbc7(%rip), %xmm2    # 0x381948
movq $0x2710, (%rsp)         # imm = 0x2710
movq $0x2710, 0x8(%rsp)      # imm = 0x2710
movq %r10, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0x2e29e0
movq -0x70(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x80(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq -0x78(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x88(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x98(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x90(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x60(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x2e3e04
movl $0x0, -0x1c(%rbp)
jmp 0x2e3e1b
movl -0x2c(%rbp), %edi
movq -0x60(%rbp), %rsi
movq -0x68(%rbp), %rdx
callq 0x2e3720
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)