// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: output_bp_trio_graph(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, bub_label_t*, long long, ug_opt_t*)
void output_bp_trio_graph(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, bub_label_t* b_mask_t,
long long gap_fuzz, ug_opt_t *opt)
{
    hic_clean(sg);

    kvec_asg_arc_t_warp new_rtg_edges;
    kv_init(new_rtg_edges.a); 
    ma_ug_t *ug = NULL;
    ug = ma_ug_gen_primary(sg, PRIMARY_LABLE);
    
    hap_cov_t *cov = NULL;
    trans_chain* t_ch = NULL;
    if((asm_opt.flag & HA_F_VERBOSE_GFA)) t_ch = load_hc_trans(output_file_name);
    
    if(!t_ch) {
        new_rtg_edges.a.n = 0;
        asg_t *copy_sg = copy_read_graph(sg);
        ma_ug_t *copy_ug = copy_untig_graph(ug);    
        ///asm_opt.purge_overlap_len = asm_opt.purge_overlap_len_hic;
        ///asm_opt.purge_simi_thres = asm_opt.purge_simi_rate_hic;
        adjust_utg_by_primary(&copy_ug, copy_sg, TRIO_THRES, sources, reverse_sources, coverage_cut, 
        tipsLen, tip_drop_ratio, stops_threshold, ruIndex, chimeric_rate, drop_ratio, 
        max_hang, min_ovlp, &new_rtg_edges, &cov, b_mask_t, 1, 0);
        
        ma_ug_destroy(copy_ug);
        asg_destroy(copy_sg);

        if((asm_opt.flag & HA_F_VERBOSE_GFA)) write_trans_chain(cov->t_ch, output_file_name);
    }

    // clean_u_trans_t_idx_filter_adv(&(cov?cov->t_ch->k_trans:t_ch->k_trans), ug, sg);
    trio_phasing_refine(ug, sg, cov?&(cov->t_ch->k_trans):&(t_ch->k_trans), opt);
    
    if(cov) destory_hap_cov_t(&cov);
    if(t_ch) destory_trans_chain(&t_ch);


    // char* gfa_name = (char*)malloc(strlen(output_file_name)+50);
    // sprintf(gfa_name, "%s.after.clean_d_utg.noseq.gfa", output_file_name);
    // FILE* output_file = fopen(gfa_name, "w");
    // ma_ug_print_simple(ug, sg, coverage_cut, sources, ruIndex, "utg", output_file);
    // fclose(output_file);
    // free(gfa_name);



    ma_ug_destroy(ug);
    kv_destroy(new_rtg_edges.a); 


    output_trio_graph_joint(sg, coverage_cut, output_file_name, sources, reverse_sources, (asm_opt.max_short_tip*2), 0.15, 3, ruIndex, 
    0.05, 0.9, max_hang, min_ovlp, gap_fuzz, b_mask_t, NULL, NULL, opt);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movss %xmm2, 0x24(%rsp)
movss %xmm1, 0x20(%rsp)
movss %xmm0, 0x1c(%rsp)
movq %r9, %rbx
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, 0x28(%rsp)
movq %rdi, %r13
callq 0xbeb19
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
andq $0x0, 0x60(%rsp)
movq %r13, %rdi
xorl %esi, %esi
callq 0xb1a83
andq $0x0, 0x10(%rsp)
andq $0x0, 0x8(%rsp)
movq %rax, %rbp
leaq 0x280722(%rip), %rax    # 0x28a758
testb $0x4, (%rax)
je 0xa048
movq %r12, %rdi
callq 0xbeaa7
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
jne 0xa13a
leaq 0x50(%rsp), %rax
andq $0x0, (%rax)
movq %r13, %rdi
callq 0xc802c
movq %rbp, %rdi
movq %rax, %rbp
movq %rdi, 0x30(%rsp)
callq 0xc815c
movq %r12, 0x38(%rsp)
leaq 0x70(%rsp), %r12
movq %rax, (%r12)
subq $0x8, %rsp
leaq 0x18(%rsp), %rax
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, 0x48(%rsp)
movq %r15, %rdx
movq %r14, 0x50(%rsp)
movq %r14, %rcx
movq 0x30(%rsp), %r8
movq %rbx, %r9
movss 0x24(%rsp), %xmm1
movss 0x28(%rsp), %xmm2
movss 0x2c(%rsp), %xmm3
pushq $0x0
pushq $0x1
pushq 0xe8(%rsp)
pushq %rax
leaq 0x78(%rsp), %rax
pushq %rax
movl 0xf8(%rsp), %eax
pushq %rax
movl 0xf8(%rsp), %eax
pushq %rax
pushq 0xf8(%rsp)
pushq 0xf8(%rsp)
callq 0xc8339
addq $0x50, %rsp
movq (%r12), %rdi
movq 0x38(%rsp), %r12
callq 0xa0004
movq %rbp, %rdi
callq 0x9fcdb
leaq 0x280646(%rip), %rax    # 0x28a758
testb $0x4, (%rax)
je 0xa12b
movq 0x10(%rsp), %rax
movq 0xa8(%rax), %rdi
movq %r12, %rsi
callq 0xbe947
movq 0x48(%rsp), %r14
movq 0x40(%rsp), %r15
movq 0x30(%rsp), %rbp
movq 0x10(%rsp), %rax
leaq 0xa8(%rax), %rcx
testq %rax, %rax
leaq 0x8(%rsp), %rax
cmovneq %rcx, %rax
movl $0x138, %edx            # imm = 0x138
addq (%rax), %rdx
movq %rbp, %rdi
movq %r13, %rsi
movq 0xe0(%rsp), %rcx
callq 0x15ccd1
cmpq $0x0, 0x10(%rsp)
je 0xa17f
leaq 0x10(%rsp), %rdi
callq 0xc8943
movq 0xd8(%rsp), %rbx
cmpq $0x0, 0x8(%rsp)
je 0xa199
leaq 0x8(%rsp), %rdi
callq 0xbe6d4
movq %rbp, %rdi
callq 0xa0004
movq 0x60(%rsp), %rdi
callq 0x2220
leaq 0x2805a6(%rip), %rax    # 0x28a758
movslq 0x11c(%rax), %r9
addq %r9, %r9
subq $0x50, %rsp
movq 0x130(%rsp), %rax
movq %rax, 0x40(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rsp)
movq 0x120(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %rbx, 0x20(%rsp)
movl 0x118(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x110(%rsp), %eax
movl %eax, 0x10(%rsp)
movq 0x108(%rsp), %rax
movq %rax, 0x8(%rsp)
movq $0x3, (%rsp)
movss 0x21f9a6(%rip), %xmm0   # 0x229bc0
movss 0x21f9a2(%rip), %xmm1   # 0x229bc4
movss 0x21f992(%rip), %xmm2   # 0x229bbc
movq %r13, %rdi
movq 0x78(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r8
callq 0x8ae6
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq