// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movss %xmm2, 0x24(%rsp)
movss %xmm1, 0x20(%rsp)
movss %xmm0, 0x1c(%rsp)
movq %r9, %rbx
movq %r8, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, %r15
movq %rsi, 0x28(%rsp)
movq %rdi, %r13
movq 0xd0(%rsp), %r12
callq 0x84414
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
movq %r13, %rdi
xorl %esi, %esi
callq 0x781bd
andq $0x0, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
movq %rax, %rbp
leaq 0x1c1b58(%rip), %rax    # 0x253758
testb $0x4, (%rax)
je 0x91c20
movq %r15, %rdi
callq 0x84211
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x91c20
xorl %ebx, %ebx
xorl %eax, %eax
jmp 0x91cf1
leaq 0x40(%rsp), %rax
andq $0x0, (%rax)
movq %r13, %rdi
callq 0x8c8a9
movq %rax, %r14
movq %rbp, %rdi
callq 0x8c99a
leaq 0x60(%rsp), %r12
movq %rax, (%r12)
subq $0x8, %rsp
leaq 0x10(%rsp), %rax
movq %r12, %rdi
movq %r14, %rsi
movq 0x38(%rsp), %rdx
movq 0x40(%rsp), %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 0xd8(%rsp)
pushq %rax
leaq 0x68(%rsp), %rax
pushq %rax
movl 0xe8(%rsp), %eax
pushq %rax
movl 0xe8(%rsp), %eax
pushq %rax
pushq 0xe8(%rsp)
pushq 0xe8(%rsp)
callq 0x8cb4c
addq $0x50, %rsp
movq (%r12), %rdi
callq 0x6921d
movq %r14, %rdi
callq 0x68f68
leaq 0x1c1a8f(%rip), %rax    # 0x253758
testb $0x4, (%rax)
je 0x91ce2
movq 0x8(%rsp), %rax
movq 0xa8(%rax), %rdi
movq %r15, %rsi
callq 0x840ba
movb $0x1, %bl
movq 0x8(%rsp), %rax
movq 0xd0(%rsp), %r12
leaq 0xa8(%rax), %rcx
testq %rax, %rax
leaq 0x10(%rsp), %rax
cmovneq %rcx, %rax
movl $0x138, %edx            # imm = 0x138
addq (%rax), %rdx
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rcx
callq 0x11e572
cmpq $0x0, 0x8(%rsp)
je 0x91d2c
leaq 0x8(%rsp), %rdi
callq 0x8d243
movq 0xc8(%rsp), %r14
testb %bl, %bl
jne 0x91d42
leaq 0x10(%rsp), %rdi
callq 0x83bb0
movq %rbp, %rdi
callq 0x6921d
movq 0x50(%rsp), %rdi
callq 0x2220
leaq 0x1c19fd(%rip), %rax    # 0x253758
movslq 0x11c(%rax), %r9
addq %r9, %r9
subq $0x50, %rsp
movq %r12, 0x40(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %r14, 0x20(%rsp)
movl 0x108(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x100(%rsp), %eax
movl %eax, 0x10(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x8(%rsp)
movq $0x3, (%rsp)
movss 0x155efd(%rip), %xmm0   # 0x1e7cb8
movss 0x155ef9(%rip), %xmm1   # 0x1e7cbc
movss 0x155ee9(%rip), %xmm2   # 0x1e7cb4
movq %r13, %rdi
movq 0x78(%rsp), %rsi
movq %r15, %rdx
movq 0x80(%rsp), %rcx
movq 0x88(%rsp), %r8
callq 0x8d2bd
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq