// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: gen_deep_ref_trans(kv_u_trans_t*, scaf_res_t*, scaf_res_t*, asg_t*, ma_ug_t*, ma_sub_t*, ma_hit_t_alloc*, ma_hit_t_alloc*, long long, float, long long, R_to_U*, float, float, int, int, bub_label_t*, ug_opt_t*)
kv_u_trans_t *gen_deep_ref_trans(kv_u_trans_t *in, scaf_res_t *cp0, scaf_res_t *cp1, asg_t *sg, ma_ug_t *ref, ma_sub_t* cover, ma_hit_t_alloc* src, ma_hit_t_alloc* rev,
long long tipsLen, float tip_drop_ratio, long long stops_threshold, R_to_U* ruIndex, float chimeric_rate, float drop_ratio, int max_hang, int min_ovlp, bub_label_t* b_mask_t, ug_opt_t *opt)
{
    kvec_asg_arc_t_warp ne; kv_init(ne.a); kv_u_trans_t *p = NULL; CALLOC(p, 1);
    ma_ug_t *cref = gen_clean_ug(ref, cp0, cp1); ma_ug_t *ccref = copy_untig_graph(cref);
    asg_t *csg = copy_read_graph(sg); hap_cov_t *cov = NULL; ne.a.n = 0; 
    // print_debug_gfa(sg, cref, cover, "cl.sb.utg", src, ruIndex, opt->max_hang, opt->min_ovlp, 0, 0, 0);
    
    adjust_utg_by_primary(&cref, csg, TRIO_THRES, src, rev, cover, tipsLen, tip_drop_ratio, stops_threshold, ruIndex, chimeric_rate, drop_ratio, max_hang, min_ovlp, &ne, &cov, b_mask_t, 1, 0);

    ma_ug_destroy(cref); asg_destroy(csg); kv_destroy(ne.a);
    if(in) {
        kv_resize(u_trans_t, cov->t_ch->k_trans, cov->t_ch->k_trans.n + in->n);
        memcpy(cov->t_ch->k_trans.a + cov->t_ch->k_trans.n, in->a, (in->n*sizeof((*(in->a)))));
        cov->t_ch->k_trans.n += in->n;
        clean_u_trans_t_idx_filter_adv(&(cov->t_ch->k_trans), ref, sg, 0.6, 1);///select best overlap for each pair of contigs
    }

    filter_u_trans(&(cov->t_ch->k_trans), asm_opt.is_bub_trans, asm_opt.is_topo_trans, asm_opt.is_read_trans, asm_opt.is_base_trans);
    if(asm_opt.is_base_trans) {
        ma_ug_seq(ccref, sg, cover, src, NULL, max_hang, min_ovlp, NULL, 0);///polish
        trans_base_infer(ccref, sg, opt, &(cov->t_ch->k_trans), NULL);
        ma_ug_destroy(ccref);
    } 
    clean_u_trans_t_idx_filter_adv(&(cov->t_ch->k_trans), ref, sg, 0.6, 0);

    p->n = cov->t_ch->k_trans.n; p->m = cov->t_ch->k_trans.m; p->a = cov->t_ch->k_trans.a; 
    p->idx.n = cov->t_ch->k_trans.idx.n; p->idx.m = cov->t_ch->k_trans.idx.m; p->idx.a = cov->t_ch->k_trans.idx.a;  
    cov->t_ch->k_trans.n = cov->t_ch->k_trans.m = 0; cov->t_ch->k_trans.a = NULL;
    cov->t_ch->k_trans.idx.n = cov->t_ch->k_trans.idx.m = 0; cov->t_ch->k_trans.idx.a = NULL;
    destory_hap_cov_t(&cov);
    return p;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movss %xmm2, 0x5c(%rsp)
movss %xmm1, 0x58(%rsp)
movss %xmm0, 0x54(%rsp)
movq %r9, %r13
movq %r8, %rbx
movq %rcx, 0x70(%rsp)
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, 0x78(%rsp)
movl $0x1, %edi
movl $0x30, %esi
callq 0x2120
movq %rax, 0x80(%rsp)
xorps %xmm0, %xmm0
leaq 0x90(%rsp), %r15
movaps %xmm0, (%r15)
xorl %r14d, %r14d
movq %r14, 0x10(%r15)
movq %rbx, 0x60(%rsp)
movq %rbx, %rdi
movq %r13, %rbx
movq %rbp, %rsi
movq %r12, %rdx
callq 0xd9a77
leaq 0x88(%rsp), %r12
movq %rax, (%r12)
movq %rax, %rdi
callq 0xc815c
movq %rax, 0x68(%rsp)
movq 0x70(%rsp), %r13
movq %r13, %rdi
callq 0xc802c
movq %rax, %rbp
leaq 0x48(%rsp), %rax
movq %r14, (%rax)
movq %r14, (%r15)
movq 0x78(%rsp), %r14
movq 0x128(%rsp), %rcx
movq %rcx, 0x30(%rsp)
movq %rax, 0x28(%rsp)
movq %r15, 0x20(%rsp)
movl 0x120(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x118(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0x108(%rsp), %xmm0
movups %xmm0, (%rsp)
movl $0x0, 0x40(%rsp)
movl $0x1, 0x38(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
movq 0xf0(%rsp), %rdx
movq 0xf8(%rsp), %rcx
movq %rbx, %r8
movq 0x100(%rsp), %r9
movss 0x54(%rsp), %xmm1
movss 0x58(%rsp), %xmm2
movss 0x5c(%rsp), %xmm3
callq 0xc8339
movq (%r12), %rdi
callq 0xa0004
movq %rbp, %rdi
callq 0x9fcdb
movq 0x10(%r15), %rdi
movq %r13, %r15
callq 0x2220
testq %r14, %r14
je 0xde563
movq 0x48(%rsp), %rax
movq 0xa8(%rax), %rax
movq (%r14), %rcx
addq 0x138(%rax), %rcx
cmpq %rcx, 0x140(%rax)
jae 0xde4f6
decq %rcx
movq %rcx, %rdx
shrq %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x2, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x4, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x8, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x10, %rdx
orq %rcx, %rdx
incq %rdx
movq %rdx, 0x140(%rax)
movq 0x148(%rax), %rdi
shlq $0x4, %rdx
leaq (%rdx,%rdx,2), %rsi
callq 0x2370
movq 0x48(%rsp), %rcx
movq 0xa8(%rcx), %rcx
movq %rax, 0x148(%rcx)
movq 0x48(%rsp), %rax
movq 0xa8(%rax), %rax
movq 0x138(%rax), %rcx
leaq (%rcx,%rcx,2), %rdi
shlq $0x4, %rdi
addq 0x148(%rax), %rdi
movq (%r14), %rax
movq 0x10(%r14), %rsi
shlq $0x4, %rax
leaq (%rax,%rax,2), %rdx
callq 0x2160
movq (%r14), %rax
movq 0x48(%rsp), %rcx
movq 0xa8(%rcx), %rdi
addq %rax, 0x138(%rdi)
addq $0x138, %rdi            # imm = 0x138
movsd 0x146f37(%rip), %xmm0   # 0x225488
movl $0x1, %ecx
movq 0x60(%rsp), %rsi
movq %r15, %rdx
callq 0xc476d
movq 0x48(%rsp), %rax
movl $0x138, %r13d           # imm = 0x138
movq 0xa8(%rax), %rdi
addq %r13, %rdi
leaq 0x1ac1d9(%rip), %r14    # 0x28a758
movzbl 0x24d(%r14), %esi
movzbl 0x24c(%r14), %edx
movzbl 0x24b(%r14), %ecx
movzbl 0x24a(%r14), %r8d
callq 0xc2a5f
cmpb $0x0, 0x24a(%r14)
je 0xde61f
movq 0x130(%rsp), %r12
movl 0x120(%rsp), %eax
movl %eax, (%rsp)
movl $0x0, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x68(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq 0xf0(%rsp), %rcx
xorl %r8d, %r8d
movl 0x118(%rsp), %r9d
callq 0xb5778
movq 0x48(%rsp), %rax
movq 0xa8(%rax), %rcx
addq %r13, %rcx
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %r8d, %r8d
callq 0x1e0907
movq %r14, %rdi
callq 0xa0004
leaq 0x48(%rsp), %r12
movq (%r12), %rax
addq 0xa8(%rax), %r13
movsd 0x146e51(%rip), %xmm0   # 0x225488
movq %r13, %rdi
movq 0x60(%rsp), %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xc476d
movq (%r12), %rax
movq 0xa8(%rax), %rax
movq 0x138(%rax), %rcx
movq 0x80(%rsp), %rbx
movq %rcx, (%rbx)
movq 0x140(%rax), %rcx
movq %rcx, 0x8(%rbx)
movq 0x148(%rax), %rcx
movq %rcx, 0x10(%rbx)
movq 0x150(%rax), %rcx
movq %rcx, 0x18(%rbx)
movq 0x158(%rax), %rcx
movq %rcx, 0x20(%rbx)
movq 0x160(%rax), %rcx
movq %rcx, 0x28(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x158(%rax)
movups %xmm0, 0x148(%rax)
movups %xmm0, 0x138(%rax)
movq %r12, %rdi
callq 0xc8943
movq %rbx, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq