// File: /workspace/github_cpp_makefile_star2_O2/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, %r12
movq %rsi, %rbp
movq %rdi, 0x70(%rsp)
pushq $0x1
popq %rdi
pushq $0x30
popq %rsi
callq 0x2120
movq %rax, 0x78(%rsp)
xorps %xmm0, %xmm0
leaq 0x88(%rsp), %r15
movups %xmm0, 0x8(%r15)
movq %r14, 0x60(%rsp)
movq %r14, %rdi
movq %rbx, %r14
movq %r13, %rbx
movq %rbp, %rsi
movq %r12, %rdx
callq 0x9db6f
leaq 0x80(%rsp), %r12
movq %rax, (%r12)
movq %rax, %rdi
callq 0x8c99a
movq %rax, 0x68(%rsp)
movq %r14, %rdi
callq 0x8c8a9
leaq 0x48(%rsp), %rcx
andq $0x0, (%rcx)
movq %rax, %rbp
andq $0x0, (%r15)
movq 0x118(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq %r15, 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)
andl $0x0, 0x40(%rsp)
movl $0x1, 0x38(%rsp)
movq %r12, %rdi
movq %rbp, %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 0x8cb4c
movq (%r12), %rdi
callq 0x6921d
movq %rbp, %rdi
callq 0x68f68
movq 0x10(%r15), %rdi
movq 0x70(%rsp), %r15
callq 0x2220
testq %r15, %r15
je 0xa208c
movq 0x48(%rsp), %rax
movq 0xa8(%rax), %rax
movq 0x138(%rax), %rdx
movq (%r15), %rcx
leaq (%rcx,%rdx), %rsi
cmpq %rsi, 0x140(%rax)
jae 0xa203c
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
imulq $0x30, %rcx, %rsi
callq 0x2370
movq 0x48(%rsp), %rcx
movq 0xa8(%rcx), %rcx
movq %rax, 0x148(%rcx)
movq 0x138(%rcx), %rdx
movq (%r15), %rcx
jmp 0xa2043
movq 0x148(%rax), %rax
imulq $0x30, %rdx, %rdi
addq %rax, %rdi
movq 0x10(%r15), %rsi
imulq $0x30, %rcx, %rdx
callq 0x2160
movq (%r15), %rax
movq 0x48(%rsp), %rcx
movq 0xa8(%rcx), %rdi
addq %rax, 0x138(%rdi)
addq $0x138, %rdi            # imm = 0x138
movsd 0x14145c(%rip), %xmm0   # 0x1e34d8
pushq $0x1
popq %rcx
movq 0x60(%rsp), %rsi
movq %r14, %rdx
callq 0x8922a
movq 0x48(%rsp), %rax
movl $0x138, %r13d           # imm = 0x138
movq 0xa8(%rax), %rdi
addq %r13, %rdi
leaq 0x1b16b0(%rip), %r15    # 0x253758
movzbl 0x24d(%r15), %esi
movzbl 0x24c(%r15), %edx
movzbl 0x24b(%r15), %ecx
movzbl 0x24a(%r15), %r8d
callq 0x874f8
cmpb $0x0, 0x24a(%r15)
je 0xa2142
movq 0x120(%rsp), %r12
andl $0x0, 0x10(%rsp)
andq $0x0, 0x8(%rsp)
movl 0x110(%rsp), %eax
movl %eax, (%rsp)
movq 0x68(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq 0xe0(%rsp), %rcx
xorl %r8d, %r8d
movl 0x108(%rsp), %r9d
callq 0x7b888
movq 0x48(%rsp), %rax
movq 0xa8(%rax), %rcx
addq %r13, %rcx
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
xorl %r8d, %r8d
callq 0x1a028d
movq %r15, %rdi
callq 0x6921d
leaq 0x48(%rsp), %r12
movq (%r12), %rax
addq 0xa8(%rax), %r13
movsd 0x14137e(%rip), %xmm0   # 0x1e34d8
movq %r13, %rdi
movq 0x60(%rsp), %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x8922a
movq (%r12), %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 %r12, %rdi
callq 0x8d243
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq