// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: output_bp_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_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;
    asg_t *copy_sg = copy_read_graph(sg);
    ma_ug_t *copy_ug = copy_untig_graph(ug);
    /*******************************for debug************************************/
    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, 1);
    // adjust_utg_advance(copy_sg, copy_ug, reverse_sources, ruIndex, b_mask_t);
    // get_utg_ovlp(&copy_ug, copy_sg, sources, reverse_sources, coverage_cut, 
    // ruIndex, max_hang, min_ovlp, &new_rtg_edges, b_mask_t, NULL);
    // exit(1);
    /*******************************for debug************************************/
    print_utg(&copy_ug, copy_sg, coverage_cut, output_file_name, sources, ruIndex, max_hang, 
    min_ovlp, &new_rtg_edges);
    ma_ug_destroy(copy_ug);
    asg_destroy(copy_sg);

    clean_u_trans_t_idx(&(cov->t_ch->k_trans), ug, sg);
    // print_untig_by_read(copy_ug, "m64011_190830_220126/88867583/ccs", 603738, NULL, NULL, "sb");
    
    ///debug_gfa_space(ug, cov);

    set_trio_flag_by_cov(ug, sg, cov);
    // print_r_het(cov, R_INF.trio_flag, "out-1");
    // print_debug_gfa(ug, sg, coverage_cut, output_file_name, sources, ruIndex);
    // exit(1);

    destory_hap_cov_t(&cov);
    ma_ug_destroy(ug);
    kv_destroy(new_rtg_edges.a);

    // reduce_hamming_error_adv(NULL, sg, sources, coverage_cut, max_hang, min_ovlp, gap_fuzz, opt->ruIndex, NULL);
    
    // output_trio_unitig_graph(sg, coverage_cut, output_file_name, FATHER, sources, reverse_sources, (asm_opt.max_short_tip*2), 0.15, 3, ruIndex, 
    // 0.05, 0.9, max_hang, min_ovlp, gap_fuzz, 0, b_mask_t, NULL, NULL, NULL);
    // output_trio_unitig_graph(sg, coverage_cut, output_file_name, MOTHER, sources, reverse_sources, (asm_opt.max_short_tip*2), 0.15, 3, ruIndex, 
    // 0.05, 0.9, max_hang, min_ovlp, gap_fuzz, 0, b_mask_t, NULL, NULL, NULL);
    
    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 $0x88, %rsp
movss %xmm2, 0x14(%rsp)
movss %xmm1, 0x10(%rsp)
movss %xmm0, 0xc(%rsp)
movq %r9, 0x30(%rsp)
movq %r8, %rbx
movq %r8, 0x50(%rsp)
movq %rcx, %rbp
movq %rcx, 0x28(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, %r12
movq %rdi, %r15
movq %rdi, 0x48(%rsp)
callq 0xbeb19
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq %r15, %rdi
xorl %esi, %esi
callq 0xb1a83
movq %rax, %r13
movq %rax, 0x40(%rsp)
leaq 0x58(%rsp), %r14
andq $0x0, (%r14)
movq %r15, %rdi
callq 0xc802c
movq %rax, %r15
movq %r13, %rdi
callq 0xc815c
leaq 0x20(%rsp), %rdi
movq %rax, (%rdi)
subq $0x8, %rsp
pushq $0x1
popq %rax
movq %r15, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
movq %r12, 0x40(%rsp)
movq %r12, %r8
movq 0x38(%rsp), %r9
movss 0x14(%rsp), %xmm1
movss 0x18(%rsp), %xmm2
movss 0x1c(%rsp), %xmm3
pushq %rax
pushq %rax
pushq 0xf8(%rsp)
pushq %r14
leaq 0x88(%rsp), %r13
pushq %r13
movl 0x108(%rsp), %ebp
pushq %rbp
movl 0x108(%rsp), %r14d
pushq %r14
movq 0x108(%rsp), %rbx
pushq %rbx
pushq 0x108(%rsp)
callq 0xc8339
addq $0x48, %rsp
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
movq 0x20(%rsp), %rcx
movq 0x30(%rsp), %r12
movq %r12, %r8
movq %rbx, %r9
pushq %r13
movq %r13, %rbx
pushq %rbp
pushq %r14
callq 0x7e72
addq $0x20, %rsp
leaq 0x20(%rsp), %rax
movq (%rax), %rdi
callq 0xa0004
movq %r15, %rdi
callq 0x9fcdb
leaq 0x58(%rsp), %rbp
movq (%rbp), %rax
movl $0x138, %edi            # imm = 0x138
addq 0xa8(%rax), %rdi
movq 0x40(%rsp), %r13
movq %r13, %rsi
movq 0x48(%rsp), %r15
movq %r15, %rdx
callq 0xcbfbf
movq (%rbp), %rdx
movq %r13, %rdi
movq %r15, %rsi
callq 0xc9ee2
movq %rbp, %rdi
callq 0xc8943
movq %r13, %rdi
callq 0xa0004
movq 0x10(%rbx), %rdi
callq 0x2220
leaq 0x280835(%rip), %rax    # 0x28a758
movslq 0x11c(%rax), %r9
addq %r9, %r9
subq $0x50, %rsp
movq 0x140(%rsp), %rax
movq %rax, 0x40(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rsp)
movq 0x130(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x138(%rsp), %rax
movq %rax, 0x20(%rsp)
movl 0x128(%rsp), %eax
movl %eax, 0x18(%rsp)
movl %r14d, 0x10(%rsp)
movq 0x118(%rsp), %rax
movq %rax, 0x8(%rsp)
movq $0x3, (%rsp)
movss 0x21fc33(%rip), %xmm0   # 0x229bc0
movss 0x21fc2f(%rip), %xmm1   # 0x229bc4
movss 0x21fc1f(%rip), %xmm2   # 0x229bbc
movq %r15, %rdi
movq 0x88(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq %r12, %rcx
movq 0xa0(%rsp), %r8
callq 0x8ae6
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq