// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movq %r8, -0x50(%rbp)
movq %r9, -0x58(%rbp)
movss %xmm0, -0x5c(%rbp)
movss %xmm1, -0x60(%rbp)
movss %xmm2, -0x64(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
leaq -0x98(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2100
leaq -0xb8(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2100
movq -0x30(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl 0x20(%rbp), %r8d
movl 0x28(%rbp), %r9d
movq 0x30(%rbp), %r10
movq 0x18(%rbp), %rax
xorl %edi, %edi
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
callq 0x10f400
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %r8
movq -0x50(%rbp), %r9
movq -0x58(%rbp), %r13
movss -0x5c(%rbp), %xmm0
movq 0x10(%rbp), %r12
movq 0x18(%rbp), %r15
movss -0x60(%rbp), %xmm1
movss -0x64(%rbp), %xmm2
movl 0x20(%rbp), %r14d
movl 0x28(%rbp), %ebx
movq 0x30(%rbp), %rax
movl %eax, %r11d
movq 0x38(%rbp), %r10
movl $0x1, %ecx
xorl %eax, %eax
leaq -0x98(%rbp), %rax
movq %r13, (%rsp)
movq %r12, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movl %r14d, 0x18(%rsp)
movl %ebx, 0x20(%rsp)
movl %r11d, 0x28(%rsp)
movl $0x1, 0x30(%rsp)
movq %r10, 0x38(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
movq %rax, 0x50(%rsp)
callq 0x100cf0
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %r8
movq -0x50(%rbp), %r9
movq -0x58(%rbp), %r13
movss -0x5c(%rbp), %xmm0
movq 0x10(%rbp), %r12
movq 0x18(%rbp), %r15
movss -0x60(%rbp), %xmm1
movss -0x64(%rbp), %xmm2
movl 0x20(%rbp), %r14d
movl 0x28(%rbp), %ebx
movq 0x30(%rbp), %rax
movl %eax, %r11d
movq 0x38(%rbp), %r10
movl $0x2, %ecx
xorl %eax, %eax
leaq -0xb8(%rbp), %rax
movq %r13, (%rsp)
movq %r12, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movl %r14d, 0x18(%rsp)
movl %ebx, 0x20(%rsp)
movl %r11d, 0x28(%rsp)
movl $0x1, 0x30(%rsp)
movq %r10, 0x38(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
movq %rax, 0x50(%rsp)
callq 0x100cf0
movq %rax, -0x78(%rbp)
movq $0x0, -0xc0(%rbp)
movq $0x0, -0xc8(%rbp)
movq -0x30(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x2140
movq %rax, -0xd0(%rbp)
movq -0x70(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x125270
movq %rax, -0xc0(%rbp)
movq -0x78(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x125270
movq %rax, -0xc8(%rbp)
callq 0x125680
movq $0x0, -0xd8(%rbp)
movq $0x0, -0xe0(%rbp)
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq 0x18(%rbp), %r8
movq -0xd0(%rbp), %r9
movl $0x1, (%rsp)
callq 0x125ec0
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rax
addq -0xd8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xc0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq 0x18(%rbp), %r8
movq -0xd0(%rbp), %r9
movl $0x2, (%rsp)
callq 0x125ec0
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rax
addq -0xd8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x125640
movq -0xc8(%rbp), %rdi
callq 0x125640
movq -0x30(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq -0xd0(%rbp), %rcx
movl $0xf4240, %r8d          # imm = 0xF4240
movl $0x8, %r9d
callq 0x1262b0
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rax
addq -0xe0(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xd0(%rbp), %rdi
callq 0x2210
movq -0x30(%rbp), %rsi
leaq -0x70(%rbp), %rdi
leaq -0x98(%rbp), %rdx
callq 0xf6030
movq -0x30(%rbp), %rsi
leaq -0x78(%rbp), %rdi
leaq -0xb8(%rbp), %rdx
callq 0xf6030
movq 0x2b7229(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0xd8(%rbp), %rcx
movq -0xe0(%rbp), %r8
leaq 0x27bafa(%rip), %rsi    # 0x3888c9
leaq 0x27bb1c(%rip), %rdx    # 0x3888f2
movb $0x0, %al
callq 0x22a0
leaq 0x2b7a14(%rip), %rax    # 0x3c47f8
cmpb $0x0, 0x264(%rax)
je 0x10d039
cmpq $0x0, 0x40(%rbp)
jne 0x10d039
cmpq $0x0, 0x48(%rbp)
jne 0x10d039
movq $0x0, -0xf0(%rbp)
movq $0x0, -0xf8(%rbp)
movq $0x0, -0x100(%rbp)
leaq -0x120(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2100
leaq -0x98(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
leaq -0x120(%rbp), %rdx
callq 0x1324d0
movq -0x88(%rbp), %rdi
callq 0x2210
movq -0xa8(%rbp), %rdi
callq 0x2210
movq 0x50(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x48(%rbp), %r9
movq -0x50(%rbp), %rax
movq %rax, -0x140(%rbp)
movq 0x18(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x130(%rbp)
movss -0x5c(%rbp), %xmm0
movq 0x10(%rbp), %r13
movss -0x60(%rbp), %xmm1
movss -0x64(%rbp), %xmm2
movl 0x20(%rbp), %r12d
movl 0x28(%rbp), %r15d
movq 0x38(%rbp), %r14
leaq -0xf0(%rbp), %rbx
leaq -0xf8(%rbp), %r11
leaq -0x100(%rbp), %r10
leaq -0x120(%rbp), %rax
movq %rax, -0x128(%rbp)
xorl %eax, %eax
movq -0x140(%rbp), %rax
movq %rax, (%rsp)
movq -0x138(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0x130(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0x128(%rbp), %rax
movq %r13, 0x18(%rsp)
movl %r12d, 0x20(%rsp)
movl %r15d, 0x28(%rsp)
movq %r14, 0x30(%rsp)
movq %rbx, 0x38(%rsp)
movq %r11, 0x40(%rsp)
movq %r10, 0x48(%rsp)
movq %rax, 0x50(%rsp)
movq $0x0, 0x58(%rsp)
callq 0x132270
movq -0x70(%rbp), %rdi
callq 0xcd6f0
movq -0x78(%rbp), %rdi
callq 0xcd6f0
movq -0x110(%rbp), %rdi
callq 0x2210
movq -0x100(%rbp), %rcx
movq -0xf0(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0xf0(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r9
movq 0x18(%rbp), %rax
movl $0x1, %r8d
xorl %r10d, %r10d
movq %rax, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0x124930
movq -0xf0(%rbp), %rdi
callq 0x132470
movq -0xf0(%rbp), %rdi
callq 0x2210
movq -0x100(%rbp), %rcx
movq -0xf8(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0xf8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r9
movq 0x18(%rbp), %rax
movl $0x2, %r8d
xorl %r10d, %r10d
movq %rax, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0x124930
movq -0xf8(%rbp), %rdi
callq 0x132470
movq -0xf8(%rbp), %rdi
callq 0x2210
movq -0x100(%rbp), %rdi
callq 0xcd6f0
jmp 0x10d129
cmpq $0x0, 0x40(%rbp)
jne 0x10d09a
movq -0x70(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
movq -0x48(%rbp), %rbx
movq 0x18(%rbp), %r11
movl 0x20(%rbp), %r10d
movl 0x28(%rbp), %eax
leaq -0x98(%rbp), %rdx
movl $0x1, %r9d
xorl %r14d, %r14d
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
callq 0x124470
movq -0x70(%rbp), %rdi
callq 0xcd6f0
jmp 0x10d0a5
movq -0x70(%rbp), %rcx
movq 0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x88(%rbp), %rdi
callq 0x2210
cmpq $0x0, 0x48(%rbp)
jne 0x10d112
movq -0x78(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
movq -0x48(%rbp), %rbx
movq 0x18(%rbp), %r11
movl 0x20(%rbp), %r10d
movl 0x28(%rbp), %eax
leaq -0xb8(%rbp), %rdx
movl $0x2, %r9d
xorl %r14d, %r14d
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
callq 0x124470
movq -0x78(%rbp), %rdi
callq 0xcd6f0
jmp 0x10d11d
movq -0x78(%rbp), %rcx
movq 0x48(%rbp), %rax
movq %rcx, (%rax)
movq -0xa8(%rbp), %rdi
callq 0x2210
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax,%rax)