// File: /workspace/github_cpp_makefile_star2_O3/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 $0xa8, %rsp
movss %xmm2, 0x5c(%rsp)
movss %xmm1, 0x58(%rsp)
movss %xmm0, 0x54(%rsp)
movq %r9, %r13
movq %r8, %r14
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, 0x70(%rsp)
movl $0x1, %edi
movl $0x30, %esi
callq 0x2120
movq %rax, 0x78(%rsp)
xorps %xmm0, %xmm0
leaq 0x88(%rsp), %rbp
movups %xmm0, 0x8(%rbp)
movq %r14, 0x60(%rsp)
movq %r14, %rdi
movq %rbx, %r14
movq %r13, %rbx
movq %r12, %rsi
movq %r15, %rdx
callq 0xdaeaa
leaq 0x80(%rsp), %r12
movq %rax, (%r12)
movq %rax, %rdi
callq 0xc8eab
movq %rax, 0x68(%rsp)
movq %r14, %rdi
callq 0xc8dad
movq %rax, %r15
xorl %eax, %eax
leaq 0x48(%rsp), %rcx
movq %rax, (%rcx)
movq %rax, (%rbp)
movq 0x118(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq %rbp, 0x20(%rsp)
movl 0x110(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x108(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0xf8(%rsp), %xmm0
movups %xmm0, (%rsp)
movl $0x0, 0x40(%rsp)
movl $0x1, 0x38(%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq 0xe0(%rsp), %rdx
movq 0xe8(%rsp), %rcx
movq %r13, %r8
movq 0xf0(%rsp), %r9
movss 0x54(%rsp), %xmm1
movss 0x58(%rsp), %xmm2
movss 0x5c(%rsp), %xmm3
callq 0xc906a
movq (%r12), %rdi
callq 0xa0761
movq %r15, %rdi
movq 0x70(%rsp), %r15
callq 0xa0494
movq 0x10(%rbp), %rdi
callq 0x2220
testq %r15, %r15
je 0xdf8fa
movq 0x48(%rsp), %rax
movq 0xa8(%rax), %rax
movq 0x138(%rax), %rdx
movq (%r15), %rcx
leaq (%rcx,%rdx), %rsi
cmpq %rsi, 0x140(%rax)
jae 0xdf8a0
decq %rsi
movq %rsi, %rcx
shrq %rcx
orq %rsi, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x8, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x10, %rcx
orq %rdx, %rcx
incq %rcx
movq %rcx, 0x140(%rax)
movq 0x148(%rax), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq 0x48(%rsp), %rcx
movq 0xa8(%rcx), %rcx
movq %rax, 0x148(%rcx)
movq 0x138(%rcx), %rdx
movq (%r15), %rcx
jmp 0xdf8a7
movq 0x148(%rax), %rax
leaq (%rdx,%rdx,2), %rdi
shlq $0x4, %rdi
addq %rax, %rdi
movq 0x10(%r15), %rsi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rdx
callq 0x2160
movq (%r15), %rax
movq 0x48(%rsp), %rcx
movq 0xa8(%rcx), %rdi
addq %rax, 0x138(%rdi)
addq $0x138, %rdi            # imm = 0x138
movsd 0x151ca0(%rip), %xmm0   # 0x231588
movl $0x1, %ecx
movq 0x60(%rsp), %rsi
movq %r14, %rdx
callq 0xc559a
movq 0x48(%rsp), %rax
movl $0x138, %r13d           # imm = 0x138
movq 0xa8(%rax), %rdi
addq %r13, %rdi
leaq 0x1b5e42(%rip), %r15    # 0x295758
movzbl 0x24d(%r15), %esi
movzbl 0x24c(%r15), %edx
movzbl 0x24b(%r15), %ecx
movzbl 0x24a(%r15), %r8d
callq 0xc3997
cmpb $0x0, 0x24a(%r15)
je 0xdf9b6
movq 0x120(%rsp), %r15
movl 0x110(%rsp), %eax
movl %eax, (%rsp)
movl $0x0, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x68(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq 0xe0(%rsp), %rcx
xorl %r8d, %r8d
movl 0x108(%rsp), %r9d
callq 0xb67c4
movq 0x48(%rsp), %rax
movq 0xa8(%rax), %rcx
addq %r13, %rcx
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %r8d, %r8d
callq 0x1eb3ec
movq %r12, %rdi
callq 0xa0761
leaq 0x48(%rsp), %r15
movq (%r15), %rax
addq 0xa8(%rax), %r13
movsd 0x151bbb(%rip), %xmm0   # 0x231588
movq %r13, %rdi
movq 0x60(%rsp), %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0xc559a
movq (%r15), %rax
movq 0xa8(%rax), %rax
movups 0x138(%rax), %xmm0
movq 0x78(%rsp), %rbx
movups %xmm0, (%rbx)
movq 0x148(%rax), %rcx
movq %rcx, 0x10(%rbx)
movups 0x150(%rax), %xmm0
movups %xmm0, 0x18(%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 %r15, %rdi
callq 0xc9bdb
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq