// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: output_trio_graph_joint(asg_t*, ma_sub_t*, char*, ma_hit_t_alloc*, ma_hit_t_alloc*, long long, float, long long, R_to_U*, float, float, int, int, long long, bub_label_t*, ma_ug_t**, ma_ug_t**, ug_opt_t*)
void output_trio_graph_joint(asg_t *sg, ma_sub_t* coverage_cut, char* output_file_name, 
ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, 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, long long gap_fuzz, bub_label_t* b_mask_t, ma_ug_t **rhu0, ma_ug_t **rhu1, ug_opt_t *opt)
{
    ma_ug_t *hu0 = NULL, *hu1 = NULL; kvec_asg_arc_t_warp arcs0, arcs1; 
    memset(&arcs0, 0, sizeof(arcs0)); memset(&arcs1, 0, sizeof(arcs1));

    reduce_hamming_error_adv(NULL, sg, sources, coverage_cut, max_hang, min_ovlp, gap_fuzz, ruIndex, NULL);
    
    hu0 = output_trio_unitig_graph(sg, coverage_cut, output_file_name, FATHER, sources, 
        reverse_sources, tipsLen, tip_drop_ratio, stops_threshold, ruIndex, chimeric_rate, 
        drop_ratio, max_hang, min_ovlp, gap_fuzz, 1, b_mask_t, NULL, NULL, &arcs0);
    
    hu1 = output_trio_unitig_graph(sg, coverage_cut, output_file_name, MOTHER, sources, 
        reverse_sources, tipsLen, tip_drop_ratio, stops_threshold, ruIndex, chimeric_rate, 
        drop_ratio, max_hang, min_ovlp, gap_fuzz, 1, b_mask_t, NULL, NULL, &arcs1);

    dedup_idx_t *hidx0 = NULL, *hidx1 = NULL; uint8_t *ff; CALLOC(ff, sg->n_seq);
    hidx0 = gen_dedup_idx_t(hu0, sg); hidx1 = gen_dedup_idx_t(hu1, sg);
    update_recover_atg_cov();

    uint64_t dedup_base = 0, miss_base = 0, s;
    s = dedup_exact_ug(hidx1, hidx0, coverage_cut, sources, ruIndex, ff, FATHER); dedup_base += s;
    s = dedup_exact_ug(hidx0, hidx1, coverage_cut, sources, ruIndex, ff, MOTHER); dedup_base += s;
    destroy_dedup_idx_t(hidx0); destroy_dedup_idx_t(hidx1); 

    s = append_miss_nid(sg, hu0, hu1, ff, PHASE_MISS_LEN, PHASE_MISS_N); miss_base += s;
    // s = append_miss_nid(sg, hu0, hu1, ff, PHASE_MISS_SLEN, PHASE_MISS_SN); miss_base += s;
    free(ff);

    renew_utg((&hu0), sg, &arcs0); renew_utg((&hu1), sg, &arcs1);
    fprintf(stderr, "[M::%s] dedup_base::%lu, miss_base::%lu\n", __func__, dedup_base, miss_base);

    if((asm_opt.self_scaf) && (!rhu0) && (!rhu1)) {
        kvect_sec_t *sc0 = NULL, *sc1 = NULL; ma_ug_t *mug = NULL;  /**kv_u_trans_t *rs_trans = NULL;**/ kvec_asg_arc_t_warp ma; memset(&ma, 0, sizeof(ma));
        merge_kvec_asg_arc_t_warp(&arcs0, &arcs1, &ma); kv_destroy(arcs0.a); kv_destroy(arcs1.a);
        gen_self_scaf(opt, hu0, hu1, sg, coverage_cut, sources, reverse_sources, ruIndex, tipsLen, tip_drop_ratio, stops_threshold, chimeric_rate, drop_ratio, max_hang, min_ovlp, b_mask_t, &sc0, &sc1, &mug, &ma, /**&rs_trans**/NULL);
        ma_ug_destroy(hu0); ma_ug_destroy(hu1); kv_destroy(ma.a);

        ///output scaf trans
        /**kv_destroy((*rs_trans)); kv_destroy(rs_trans->idx); free(rs_trans);**/

        sc0->ctg = mug;
        output_hap_sc_graph(sc0, sg, /**&arcs0,**/ coverage_cut, output_file_name, FATHER, sources, ruIndex, /**max_hang, min_ovlp,**/ NULL); 
        destory_kvect_sec_t(sc0); free(sc0); 

        sc1->ctg = mug;
        output_hap_sc_graph(sc1, sg, /**&arcs1,**/ coverage_cut, output_file_name, MOTHER, sources, ruIndex, /**max_hang, min_ovlp,**/ NULL);
        destory_kvect_sec_t(sc1); free(sc1); 

        ma_ug_destroy(mug);
    } else {
        if(!rhu0) {
            output_hap_graph(hu0, sg, &arcs0, coverage_cut, output_file_name, FATHER, sources, ruIndex, max_hang, min_ovlp, NULL);
            ma_ug_destroy(hu0); 
        } else {
            (*rhu0) = hu0;
        }    
        kv_destroy(arcs0.a); 

        
        if(!rhu1) {
            output_hap_graph(hu1, sg, &arcs1, coverage_cut, output_file_name, MOTHER, sources, ruIndex, max_hang, min_ovlp, NULL);
            ma_ug_destroy(hu1); 
        } else {
            (*rhu1) = hu1; // ma_ug_destroy(hu1); 
        }
        kv_destroy(arcs1.a);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movss %xmm2, 0x14(%rsp)
movss %xmm1, 0x10(%rsp)
movss %xmm0, 0xc(%rsp)
movq %r9, %rbx
movq %r8, 0x48(%rsp)
movq %rcx, %r15
movq %rdx, %r12
movq %rdx, 0x18(%rsp)
movq %rsi, %rbp
movq %rdi, %r14
movl 0x138(%rsp), %r13d
movl 0x130(%rsp), %r8d
xorps %xmm0, %xmm0
leaq 0xa0(%rsp), %rax
movaps %xmm0, (%rax)
movaps %xmm0, 0x10(%rax)
leaq 0x80(%rsp), %rax
movaps %xmm0, (%rax)
movaps %xmm0, 0x10(%rax)
movq 0x140(%rsp), %rax
subq $0x20, %rsp
andq $0x0, 0x10(%rsp)
movq %rax, (%rsp)
xorl %edi, %edi
movq %r14, %rsi
movq %r14, 0x60(%rsp)
movq %rcx, %rdx
movq %rbp, %rcx
movl %r13d, %r9d
callq 0x8f127
subq $0x40, %rsp
leaq 0x100(%rsp), %rax
movq %rax, 0x50(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rsp)
movq 0x1a8(%rsp), %rax
movq %rax, 0x38(%rsp)
pushq $0x1
popq %rax
movl %eax, 0x30(%rsp)
movq %rax, %rcx
movq 0x1a0(%rsp), %rax
movl %eax, 0x28(%rsp)
movl %r13d, 0x20(%rsp)
movl 0x190(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x188(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x180(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rbx, (%rsp)
movq %r14, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, 0x80(%rsp)
movq %r15, %r8
movq 0xa8(%rsp), %r13
movq %r13, %r9
movss 0x6c(%rsp), %xmm0
movss 0x70(%rsp), %xmm1
movss 0x74(%rsp), %xmm2
callq 0x86cbc
addq $0x60, %rsp
movq %rax, %r12
leaq 0x38(%rsp), %rcx
movq %rax, (%rcx)
movq %rax, 0x70(%rsp)
subq $0x60, %rsp
leaq 0xe0(%rsp), %rax
movq %rax, 0x50(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rsp)
movq 0x1a8(%rsp), %rax
movq %rax, 0x38(%rsp)
pushq $0x1
popq %rax
movl %eax, 0x30(%rsp)
movq 0x1a0(%rsp), %rax
movl %eax, 0x28(%rsp)
movl 0x198(%rsp), %eax
movl %eax, 0x20(%rsp)
movl 0x190(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x188(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x180(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rbx, 0xc0(%rsp)
movq %rbx, (%rsp)
pushq $0x2
popq %rcx
movq %r14, %rdi
movq %rbp, %rsi
movq 0x78(%rsp), %rdx
movq %r15, %r8
movq %r13, %r9
movss 0x6c(%rsp), %xmm0
movss 0x70(%rsp), %xmm1
movss 0x74(%rsp), %xmm2
callq 0x86cbc
addq $0x60, %rsp
movq %rax, %r15
leaq 0x30(%rsp), %rcx
movq %rax, (%rcx)
movq %rax, 0x68(%rsp)
movl 0x14(%r14), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
pushq $0x1
popq %rsi
callq 0x2120
movq %rax, %rbx
movq %r12, %rdi
movq %r14, %rsi
callq 0x9cd2f
movq %rax, %r12
movq %r15, %rdi
movq %r14, %rsi
callq 0x9cd2f
movq %rax, %r13
callq 0x9cee6
subq $0x8, %rsp
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %r15
movq %rbp, %rdx
movq 0x28(%rsp), %rbp
movq %rbp, %rcx
movq 0x130(%rsp), %r8
movq %rbx, %r9
pushq $0x1
popq %rax
pushq %rax
callq 0x9d276
popq %rcx
popq %rdx
movq %rax, %r14
subq $0x8, %rsp
movq %r12, %rdi
movq %r13, %rsi
movq %r15, 0x30(%rsp)
movq %r15, %rdx
movq %rbp, %rcx
movq 0x130(%rsp), %r8
movq %rbx, %r9
pushq $0x2
callq 0x9d276
addq $0x10, %rsp
movq %r14, %r15
addq %rax, %r15
movq %r12, %rdi
callq 0x9cec1
movq %r13, %rdi
movq 0x40(%rsp), %r13
callq 0x9cec1
pushq $0x8
popq %r9
movl $0xf4240, %r8d          # imm = 0xF4240
movq %r13, %rdi
movq 0x70(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq %rbx, %rcx
callq 0x9d4fa
movq %rax, %r14
movq %rbx, %rdi
callq 0x2220
leaq 0x38(%rsp), %rdi
movq %r13, %rsi
leaq 0xa0(%rsp), %rdx
callq 0x80328
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
leaq 0x80(%rsp), %rdx
callq 0x80328
movq 0x1c5a18(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0x15c60c(%rip), %rsi    # 0x1e9bde
leaq 0x15c62e(%rip), %rdx    # 0x1e9c07
movq %r15, %rcx
movq %r14, %r8
movq 0x158(%rsp), %r14
xorl %eax, %eax
callq 0x22b0
movq 0x150(%rsp), %rcx
testq %r14, %r14
jne 0x8d7c4
testq %rcx, %rcx
jne 0x8d7c4
leaq 0x1c6149(%rip), %rax    # 0x253758
cmpb $0x0, 0x264(%rax)
je 0x8d7c4
movq 0x160(%rsp), %r12
leaq 0x58(%rsp), %rax
andq $0x0, (%rax)
leaq 0x50(%rsp), %rax
andq $0x0, (%rax)
leaq 0x78(%rsp), %rbp
andq $0x0, (%rbp)
xorps %xmm0, %xmm0
leaq 0xc0(%rsp), %r14
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
leaq 0xa0(%rsp), %rbx
leaq 0x80(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0xa3872
movq 0x10(%rbx), %rdi
callq 0x2220
movq 0x10(%r15), %rdi
callq 0x2220
movq 0x38(%rsp), %r15
movq 0x30(%rsp), %rbx
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r13, %rcx
movq 0x28(%rsp), %r13
movq %r13, %r8
movq 0x20(%rsp), %r12
movq %r12, %r9
movss 0xc(%rsp), %xmm0
movss 0x10(%rsp), %xmm1
movss 0x14(%rsp), %xmm2
pushq $0x0
pushq %r14
pushq %rbp
leaq 0x68(%rsp), %rax
pushq %rax
leaq 0x78(%rsp), %rax
pushq %rax
pushq 0x170(%rsp)
movl 0x168(%rsp), %eax
pushq %rax
movl 0x168(%rsp), %eax
pushq %rax
pushq 0x160(%rsp)
pushq 0xa8(%rsp)
movq 0x178(%rsp), %rbp
pushq %rbp
pushq 0xa0(%rsp)
callq 0xa3623
addq $0x60, %rsp
movq %r15, %rdi
callq 0x6921d
movq %rbx, %rdi
callq 0x6921d
movq 0x10(%r14), %rdi
callq 0x2220
leaq 0x78(%rsp), %r15
movq (%r15), %rax
leaq 0x58(%rsp), %rcx
movq (%rcx), %rbx
movq %rax, 0x18(%rbx)
pushq $0x1
popq %r8
movq %rbx, %rdi
movq 0x40(%rsp), %rbp
movq %rbp, %rsi
movq %r13, %rdx
movq 0x18(%rsp), %r14
movq %r14, %rcx
movq %r12, %r9
pushq $0x0
pushq 0x130(%rsp)
callq 0x9c698
popq %rax
popq %rcx
movq %rbx, %rdi
callq 0xa383e
movq %rbx, %rdi
callq 0x2220
movq (%r15), %rax
leaq 0x50(%rsp), %rcx
movq (%rcx), %rbx
movq %rax, 0x18(%rbx)
pushq $0x2
popq %r8
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %r12, %r9
pushq $0x0
pushq 0x130(%rsp)
callq 0x9c698
popq %rax
popq %rcx
movq %rbx, %rdi
callq 0xa383e
movq %rbx, %rdi
callq 0x2220
movq (%r15), %rdi
callq 0x6921d
jmp 0x8d898
movq 0x38(%rsp), %rbx
testq %rcx, %rcx
je 0x8d7d3
movq %rbx, (%rcx)
jmp 0x8d821
subq $0x8, %rsp
leaq 0xa8(%rsp), %rdx
pushq $0x1
popq %r9
movq %rbx, %rdi
movq %r13, %rsi
movq 0x30(%rsp), %rcx
movq 0x20(%rsp), %r8
pushq $0x0
movl 0x148(%rsp), %eax
pushq %rax
movl 0x148(%rsp), %eax
pushq %rax
pushq 0x148(%rsp)
pushq 0x48(%rsp)
callq 0x9c43e
addq $0x30, %rsp
movq %rbx, %rdi
callq 0x6921d
movq 0xb0(%rsp), %rdi
callq 0x2220
movq 0x30(%rsp), %rbx
testq %r14, %r14
je 0x8d83d
movq %rbx, (%r14)
jmp 0x8d88b
subq $0x8, %rsp
leaq 0x88(%rsp), %rdx
pushq $0x2
popq %r9
movq %rbx, %rdi
movq %r13, %rsi
movq 0x30(%rsp), %rcx
movq 0x20(%rsp), %r8
pushq $0x0
movl 0x148(%rsp), %eax
pushq %rax
movl 0x148(%rsp), %eax
pushq %rax
pushq 0x148(%rsp)
pushq 0x48(%rsp)
callq 0x9c43e
addq $0x30, %rsp
movq %rbx, %rdi
callq 0x6921d
movq 0x90(%rsp), %rdi
callq 0x2220
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq