// File: /workspace/github_cpp_makefile_star2_O1/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, 0x40(%rsp)
movq %r8, 0x48(%rsp)
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbp
movq %rdi, 0x80(%rsp)
leaq 0x30(%rsp), %rax
andq $0x0, (%rax)
leaq 0x28(%rsp), %rax
andq $0x0, (%rax)
movl 0x138(%rsp), %r15d
movl 0x130(%rsp), %ebx
xorps %xmm0, %xmm0
leaq 0xa0(%rsp), %rax
movaps %xmm0, (%rax)
movaps %xmm0, 0x10(%rax)
leaq 0x60(%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 %rbp, %rsi
movq %rcx, %rdx
movq %r14, %rcx
movl %ebx, %r8d
movl %r15d, %r9d
callq 0x927f
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 %r15d, 0x20(%rsp)
movl %ebx, 0x18(%rsp)
movq 0x188(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x180(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, (%rsp)
movq %rbp, %rdi
movq %r14, %rsi
movq %r14, 0x80(%rsp)
movq %r12, %rdx
movq %r12, %rbx
movq %r13, %r8
movq %r13, 0x78(%rsp)
movq 0xa8(%rsp), %r15
movq %r15, %r9
movss 0x6c(%rsp), %xmm0
movss 0x70(%rsp), %xmm1
movss 0x74(%rsp), %xmm2
callq 0xc21cc
addq $0x60, %rsp
movq %rax, %r12
leaq 0x30(%rsp), %rax
movq %r12, (%rax)
movq %r12, 0x90(%rsp)
subq $0x60, %rsp
leaq 0xc0(%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 0xa0(%rsp), %rax
movq %rax, (%rsp)
pushq $0x2
popq %rcx
movq %rbp, %rdi
movq %r14, %rsi
movq %rbx, 0x98(%rsp)
movq %rbx, %rdx
movq %r13, %r8
movq %r15, %r9
movss 0x6c(%rsp), %xmm0
movss 0x70(%rsp), %xmm1
movss 0x74(%rsp), %xmm2
callq 0xc21cc
addq $0x60, %rsp
movq %rax, %r14
leaq 0x28(%rsp), %rax
movq %r14, (%rax)
movq %r14, 0x88(%rsp)
movl 0x14(%rbp), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
pushq $0x1
popq %rsi
callq 0x2120
movq %rax, %rbx
movq %r12, %rdi
movq %rbp, %rsi
callq 0xd8c10
movq %rax, %r15
movq %r14, %rdi
movq %rbp, %rsi
callq 0xd8c10
movq %rax, %r12
callq 0xd8de5
subq $0x8, %rsp
movq %r12, %rdi
movq %r15, %rsi
movq 0x28(%rsp), %r13
movq %r13, %rdx
movq 0x20(%rsp), %r14
movq %r14, %rcx
movq 0x130(%rsp), %r8
movq %rbx, %r9
pushq $0x1
popq %rax
pushq %rax
callq 0xd9295
popq %rcx
popq %rdx
movq %rax, %rbp
subq $0x8, %rsp
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq 0x130(%rsp), %r8
movq %rbx, %r9
pushq $0x2
callq 0xd9295
addq $0x10, %rsp
movq %rbp, %r13
addq %rax, %r13
movq %r15, %rdi
movq 0x80(%rsp), %rbp
callq 0xd8dc0
movq %r12, %rdi
callq 0xd8dc0
pushq $0x8
popq %r9
movl $0xf4240, %r8d          # imm = 0xF4240
movq %rbp, %rdi
movq 0x90(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq %rbx, %rcx
callq 0xd9540
movq %rax, %r14
movq %rbx, %rdi
callq 0x2220
leaq 0x30(%rsp), %rdi
movq %rbp, %rsi
leaq 0xa0(%rsp), %rdx
callq 0xba760
leaq 0x28(%rsp), %rdi
movq %rbp, %rsi
leaq 0x60(%rsp), %rdx
callq 0xba760
movq 0x2811c7(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x222ccb(%rip), %rsi    # 0x22baee
leaq 0x222ced(%rip), %rdx    # 0x22bb17
movq %r13, %rcx
movq %r14, %r8
movq 0x158(%rsp), %r14
xorl %eax, %eax
callq 0x22b0
movq 0x150(%rsp), %rcx
testq %r14, %r14
jne 0x8e61
testq %rcx, %rcx
jne 0x8e61
leaq 0x281900(%rip), %rax    # 0x28a758
cmpb $0x0, 0x264(%rax)
jne 0x8eac
movq 0x30(%rsp), %rbx
testq %rcx, %rcx
je 0x908c
movq %rbx, (%rcx)
movq 0xb0(%rsp), %rdi
callq 0x2220
movq 0x28(%rsp), %rbx
testq %r14, %r14
je 0x90df
movq %rbx, (%r14)
movq 0x70(%rsp), %rdi
callq 0x2220
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x58(%rsp), %rax
andq $0x0, (%rax)
leaq 0x50(%rsp), %rax
andq $0x0, (%rax)
leaq 0x98(%rsp), %rax
andq $0x0, (%rax)
xorps %xmm0, %xmm0
leaq 0xc0(%rsp), %rbx
movaps %xmm0, (%rbx)
movaps %xmm0, 0x10(%rbx)
movq 0xa0(%rsp), %r12
movq 0x60(%rsp), %r13
leaq (%r12,%r13), %rax
movq %rax, 0x8(%rbx)
movq %rax, (%rbx)
imulq $0x18, %rax, %rdi
callq 0x2280
movq %rax, %r14
movq %rax, 0x10(%rbx)
movq 0xb0(%rsp), %r15
imulq $0x18, %r12, %r12
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2160
addq %r14, %r12
movq 0x70(%rsp), %rsi
imulq $0x18, %r13, %rdx
movq %r12, %rdi
callq 0x2160
movq %r15, %rdi
callq 0x2220
movq 0x70(%rsp), %rdi
callq 0x2220
movq 0x30(%rsp), %r15
movq 0x28(%rsp), %r13
movq 0x160(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rbp, %rcx
movq 0x20(%rsp), %r12
movq %r12, %r8
movq 0x18(%rsp), %r9
movss 0xc(%rsp), %xmm0
movss 0x10(%rsp), %xmm1
movss 0x14(%rsp), %xmm2
pushq $0x0
pushq %rbx
leaq 0xa8(%rsp), %rbx
pushq %rbx
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 0x88(%rsp)
movq 0x178(%rsp), %rax
pushq %rax
pushq 0xa0(%rsp)
callq 0xdfc91
addq $0x60, %rsp
movq %r15, %rdi
callq 0xa0004
movq %r13, %rdi
callq 0xa0004
movq %r14, %rdi
callq 0x2220
movq (%rbx), %rax
movq %rbx, %r13
leaq 0x58(%rsp), %rcx
movq (%rcx), %rbx
movq %rax, 0x18(%rbx)
pushq $0x1
popq %r8
movq %rbx, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq 0x38(%rsp), %r14
movq %r14, %rcx
movq 0x18(%rsp), %r15
movq %r15, %r9
pushq $0x0
pushq 0x130(%rsp)
callq 0xb361
popq %rax
popq %rcx
movq %rbx, %rdi
callq 0xdfeac
movq %rbx, %rdi
callq 0x2220
movq (%r13), %rax
leaq 0x50(%rsp), %rcx
movq (%rcx), %rbx
movq %rax, 0x18(%rbx)
pushq $0x2
popq %r8
movq %rbx, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r14, %rcx
movq %r15, %r9
pushq $0x0
pushq 0x130(%rsp)
callq 0xb361
popq %rax
popq %rcx
movq %rbx, %rdi
callq 0xdfeac
movq %rbx, %rdi
callq 0x2220
movq (%r13), %rdi
callq 0xa0004
jmp 0x8e9a
subq $0x8, %rsp
leaq 0xa8(%rsp), %rdx
pushq $0x1
popq %r9
movq %rbx, %rdi
movq %rbp, %rsi
movq 0x28(%rsp), %rcx
movq 0x40(%rsp), %r8
pushq $0x0
movl 0x148(%rsp), %eax
pushq %rax
movl 0x148(%rsp), %eax
pushq %rax
pushq 0x148(%rsp)
pushq 0x40(%rsp)
callq 0xb0f1
addq $0x30, %rsp
movq %rbx, %rdi
callq 0xa0004
jmp 0x8e72
subq $0x8, %rsp
leaq 0x68(%rsp), %rdx
pushq $0x2
popq %r9
movq %rbx, %rdi
movq %rbp, %rsi
movq 0x28(%rsp), %rcx
movq 0x40(%rsp), %r8
pushq $0x0
movl 0x148(%rsp), %eax
pushq %rax
movl 0x148(%rsp), %eax
pushq %rax
pushq 0x148(%rsp)
pushq 0x40(%rsp)
callq 0xb0f1
addq $0x30, %rsp
movq %rbx, %rdi
callq 0xa0004
jmp 0x8e90