// File: /workspace/github_cpp_makefile_star2_O3/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 $0xf8, %rsp
movss %xmm2, 0x14(%rsp)
movss %xmm1, 0x10(%rsp)
movss %xmm0, 0xc(%rsp)
movq %r9, 0x40(%rsp)
movq %r8, 0x48(%rsp)
movq %rcx, %r12
movq %rdx, %rbp
movq %rdx, 0x20(%rsp)
movq %rsi, %r15
movq %rdi, %r14
movl 0x148(%rsp), %r13d
movl 0x140(%rsp), %r8d
movq 0x150(%rsp), %rax
xorps %xmm0, %xmm0
leaq 0xb0(%rsp), %rbx
movaps %xmm0, (%rbx)
movaps %xmm0, 0x10(%rbx)
leaq 0x70(%rsp), %rcx
movaps %xmm0, (%rcx)
movaps %xmm0, 0x10(%rcx)
subq $0x20, %rsp
andq $0x0, 0x10(%rsp)
movq %rax, (%rsp)
xorl %edi, %edi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
movl %r13d, %r9d
callq 0x922b
subq $0x40, %rsp
movq %rbx, 0x50(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rsp)
movq 0x1b8(%rsp), %rax
movq %rax, 0x38(%rsp)
pushq $0x1
popq %rax
movl %eax, 0x30(%rsp)
movl %eax, %ecx
movq 0x1b0(%rsp), %rax
movl %eax, 0x28(%rsp)
movl %r13d, 0x20(%rsp)
movl 0x1a0(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x198(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x190(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xa0(%rsp), %r13
movq %r13, (%rsp)
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq %r12, %r8
movq 0xa8(%rsp), %rbp
movq %rbp, %r9
movss 0x6c(%rsp), %xmm0
movss 0x70(%rsp), %xmm1
movss 0x74(%rsp), %xmm2
callq 0xc30dd
addq $0x60, %rsp
movq %rax, %rbx
movq %rax, 0x38(%rsp)
subq $0x60, %rsp
leaq 0xd0(%rsp), %rax
movq %rax, 0x50(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rsp)
movq 0x1b8(%rsp), %rax
movq %rax, 0x38(%rsp)
pushq $0x1
popq %rax
movl %eax, 0x30(%rsp)
movq 0x1b0(%rsp), %rax
movl %eax, 0x28(%rsp)
movl 0x1a8(%rsp), %eax
movl %eax, 0x20(%rsp)
movl 0x1a0(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x198(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x190(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %r13, (%rsp)
pushq $0x2
popq %rcx
movq %r14, %rdi
movq %r15, 0x78(%rsp)
movq %r15, %rsi
movq 0x80(%rsp), %rdx
movq %r12, 0x88(%rsp)
movq %r12, %r8
movq %rbp, %r9
movss 0x6c(%rsp), %xmm0
movss 0x70(%rsp), %xmm1
movss 0x74(%rsp), %xmm2
callq 0xc30dd
addq $0x60, %rsp
movq %rax, %r15
movq %rax, 0x30(%rsp)
movl 0x14(%r14), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
pushq $0x1
popq %rsi
callq 0x2120
movq %rax, 0x98(%rsp)
movq %rbx, 0xa8(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xda0be
movq %rax, %r12
movq %r15, 0xa0(%rsp)
movq %r15, %rdi
movq %r14, 0x50(%rsp)
movq %r14, %rsi
callq 0xda0be
movq %rax, %r13
leaq 0x28caba(%rip), %rcx    # 0x295758
cmpl $0xfffffc00, 0x13c(%rcx) # imm = 0xFFFFFC00
jne 0x8ce7
cmpl $0x0, 0x148(%rcx)
cvtsi2sdl 0x144(%rcx), %xmm0
jne 0x8cc3
divsd 0x22d09d(%rip), %xmm0   # 0x235d60
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
mulsd 0x22d0ad(%rip), %xmm0   # 0x235d80
cvttsd2si %xmm0, %eax
movl %eax, 0x13c(%rcx)
movl $0x7fffffff, 0x140(%rcx) # imm = 0x7FFFFFFF
subq $0x8, %rsp
movq %r13, %rdi
movq %r12, %rsi
movq 0x20(%rsp), %r14
movq %r14, %rdx
movq 0x30(%rsp), %r15
movq %r15, %rcx
movq 0x140(%rsp), %r8
movq 0xa0(%rsp), %rbp
movq %rbp, %r9
pushq $0x1
callq 0xda722
popq %rcx
popq %rdx
movq %rax, %rbx
subq $0x8, %rsp
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
movq 0x140(%rsp), %r8
movq %rbp, %r9
pushq $0x2
callq 0xda722
addq $0x10, %rsp
addq %rax, %rbx
movq %r12, %rdi
callq 0xda260
movq %r13, %rdi
callq 0xda260
pushq $0x8
popq %r9
movl $0xf4240, %r8d          # imm = 0xF4240
movq 0x50(%rsp), %r13
movq %r13, %rdi
movq 0xa8(%rsp), %rsi
movq 0xa0(%rsp), %rdx
movq %rbp, %rcx
callq 0xda9b8
movq %rax, %r15
movq %rbp, %rdi
callq 0x2220
leaq 0x38(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
movq %r13, %rsi
callq 0xbb7a4
leaq 0x30(%rsp), %rdi
leaq 0x70(%rsp), %rdx
movq %r13, %rsi
callq 0xbb7a4
movq 0x28c224(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x22ef18(%rip), %rsi    # 0x237cde
leaq 0x22ef3a(%rip), %rdx    # 0x237d07
movq %rbx, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x22b0
movq 0x160(%rsp), %rcx
movq 0x168(%rsp), %r14
testq %r14, %r14
jne 0x8e04
testq %rcx, %rcx
jne 0x8e04
leaq 0x28c95d(%rip), %rax    # 0x295758
cmpb $0x0, 0x264(%rax)
jne 0x8e52
movq 0x38(%rsp), %rbx
testq %rcx, %rcx
je 0x9038
movq %rbx, (%rcx)
movq 0xc0(%rsp), %rdi
callq 0x2220
movq 0x30(%rsp), %rbx
testq %r14, %r14
je 0x908b
movq %rbx, (%r14)
movq 0x80(%rsp), %rdi
callq 0x2220
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x68(%rsp), %rax
andq $0x0, (%rax)
leaq 0x60(%rsp), %rax
andq $0x0, (%rax)
leaq 0x58(%rsp), %rax
andq $0x0, (%rax)
leaq 0xd8(%rsp), %r15
andq $0x0, 0x18(%r15)
movq 0xb0(%rsp), %r12
movq 0x70(%rsp), %rbp
leaq (%r12,%rbp), %rax
movq %rax, 0x8(%r15)
movq %rax, (%r15)
imulq $0x18, %rax, %rdi
callq 0x2280
movq %rax, %r14
movq %rax, 0x10(%r15)
movq 0xc0(%rsp), %rbx
imulq $0x18, %r12, %r12
movq %rax, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2160
addq %r14, %r12
movq 0x80(%rsp), %rsi
imulq $0x18, %rbp, %rdx
movq %r12, %rdi
callq 0x2160
movq %rbx, %rdi
callq 0x2220
movq 0x80(%rsp), %rdi
callq 0x2220
movq 0x38(%rsp), %r12
movq 0x30(%rsp), %rbx
movq 0x170(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r13, %rcx
movq 0x18(%rsp), %r13
movq %r13, %r8
movq 0x28(%rsp), %rbp
movq %rbp, %r9
movss 0xc(%rsp), %xmm0
movss 0x10(%rsp), %xmm1
movss 0x14(%rsp), %xmm2
pushq $0x0
pushq %r15
leaq 0x68(%rsp), %rax
pushq %rax
leaq 0x78(%rsp), %rax
pushq %rax
leaq 0x88(%rsp), %rax
pushq %rax
pushq 0x180(%rsp)
movl 0x178(%rsp), %eax
pushq %rax
movl 0x178(%rsp), %eax
pushq %rax
pushq 0x170(%rsp)
pushq 0x88(%rsp)
movq 0x188(%rsp), %r15
pushq %r15
pushq 0xa0(%rsp)
callq 0xe0feb
addq $0x60, %rsp
movq %r12, %rdi
callq 0xa0761
movq %rbx, %rdi
callq 0xa0761
movq %r14, %rdi
callq 0x2220
leaq 0x58(%rsp), %r12
movq (%r12), %rax
leaq 0x68(%rsp), %rcx
movq (%rcx), %rbx
movq %rax, 0x18(%rbx)
pushq $0x1
popq %r8
movq %rbx, %rdi
movq 0x50(%rsp), %r15
movq %r15, %rsi
movq %r13, %rdx
movq 0x20(%rsp), %r14
movq %r14, %rcx
movq %rbp, %r9
pushq $0x0
pushq 0x140(%rsp)
callq 0xb2ed
popq %rax
popq %rcx
movq %rbx, %rdi
callq 0xe1206
movq %rbx, %rdi
callq 0x2220
movq (%r12), %rax
leaq 0x60(%rsp), %rcx
movq (%rcx), %rbx
movq %rax, 0x18(%rbx)
pushq $0x2
popq %r8
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %rbp, %r9
pushq $0x0
pushq 0x140(%rsp)
callq 0xb2ed
popq %rax
popq %rcx
movq %rbx, %rdi
callq 0xe1206
movq %rbx, %rdi
callq 0x2220
movq (%r12), %rdi
callq 0xa0761
jmp 0x8e40
subq $0x8, %rsp
leaq 0xb8(%rsp), %rdx
pushq $0x1
popq %r9
movq %rbx, %rdi
movq %r13, %rsi
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %r8
pushq $0x0
movl 0x158(%rsp), %eax
pushq %rax
movl 0x158(%rsp), %eax
pushq %rax
pushq 0x158(%rsp)
pushq 0x50(%rsp)
callq 0xb07d
addq $0x30, %rsp
movq %rbx, %rdi
callq 0xa0761
jmp 0x8e15
subq $0x8, %rsp
leaq 0x78(%rsp), %rdx
pushq $0x2
popq %r9
movq %rbx, %rdi
movq %r13, %rsi
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %r8
pushq $0x0
movl 0x158(%rsp), %eax
pushq %rax
movl 0x158(%rsp), %eax
pushq %rax
pushq 0x158(%rsp)
pushq 0x50(%rsp)
callq 0xb07d
addq $0x30, %rsp
movq %rbx, %rdi
callq 0xa0761
jmp 0x8e33