// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: output_contig_graph_primary(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*)
void output_contig_graph_primary(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)
{
    ma_ug_t *ug = NULL;
    ug = ma_ug_gen_primary(sg, PRIMARY_LABLE);

    kvec_asg_arc_t_warp new_rtg_edges;
    kv_init(new_rtg_edges.a);

    adjust_utg_by_primary(&ug, 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, NULL, b_mask_t, 0, 0);

    if(asm_opt.b_low_cov > 0)
    {
        break_ug_contig(&ug, sg, &R_INF, coverage_cut, sources, ruIndex, &new_rtg_edges, max_hang, min_ovlp, 
        &asm_opt.b_low_cov, NULL, asm_opt.m_rate);
    }
    if(asm_opt.b_high_cov > 0)
    {
        break_ug_contig(&ug, sg, &R_INF, coverage_cut, sources, ruIndex, &new_rtg_edges, max_hang, min_ovlp, 
        NULL, &asm_opt.b_high_cov, asm_opt.m_rate);
    }
    ma_ug_seq(ug, sg, coverage_cut, sources, &new_rtg_edges, max_hang, min_ovlp, 0, 1);
    
    
    fprintf(stderr, "Writing primary contig GFA to disk... \n");
    char* gfa_name = (char*)malloc(strlen(output_file_name)+35);
    sprintf(gfa_name, "%s.p_ctg.gfa", output_file_name);
    FILE* output_file = fopen(gfa_name, "w");
    ma_ug_print(ug, sg, coverage_cut, sources, ruIndex, "ptg", output_file);
    fclose(output_file);

    sprintf(gfa_name, "%s.p_ctg.noseq.gfa", output_file_name);
    output_file = fopen(gfa_name, "w");
    ma_ug_print_simple(ug, sg, coverage_cut, sources, ruIndex, "ptg", output_file);
    fclose(output_file);
    if(asm_opt.bed_inconsist_rate != 0)
    {
        sprintf(gfa_name, "%s.p_ctg.lowQ.bed", output_file_name);
        output_file = fopen(gfa_name, "w");
        ma_ug_print_bed(ug, sg, &R_INF, coverage_cut, sources, &new_rtg_edges, 
        max_hang, min_ovlp, asm_opt.bed_inconsist_rate, "ptg", output_file, NULL);
        fclose(output_file);
    }

    free(gfa_name);
    ma_ug_destroy(ug);
    kv_destroy(new_rtg_edges.a);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movss %xmm2, 0x10(%rsp)
movss %xmm1, 0x8(%rsp)
movss %xmm0, (%rsp)
movq %r9, %rbx
movq %r8, %r15
movq %rcx, %r14
movq %rdx, 0x20(%rsp)
movq %rsi, %rbp
movq %rdi, %r12
xorl %esi, %esi
callq 0xb2a6d
leaq 0x18(%rsp), %rdi
movq %rax, (%rdi)
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %r13
movaps %xmm0, (%r13)
andq $0x0, 0x10(%r13)
subq $0x8, %rsp
movq %r12, %rsi
movq %r14, %rdx
movq %r15, %rcx
movl 0xa8(%rsp), %eax
movq %rbp, %r15
movq %rbp, %r8
movq %rbx, %r9
movss 0x8(%rsp), %xmm1
movss 0x10(%rsp), %xmm2
movss 0x18(%rsp), %xmm3
pushq $0x0
pushq $0x0
pushq 0xc8(%rsp)
pushq $0x0
pushq %r13
movl 0xd8(%rsp), %r10d
pushq %r10
movq %rax, %rbp
pushq %rax
pushq 0xd8(%rsp)
pushq 0xd8(%rsp)
callq 0xc906a
addq $0x50, %rsp
leaq 0x287a7d(%rip), %rbx    # 0x295758
xorl %eax, %eax
cmpl %eax, 0xd8(%rbx)
jle 0xdd2a
movsd 0xe0(%rbx), %xmm0
subq $0x30, %rsp
leaq 0xd8(%rbx), %rax
movq %rax, 0x18(%rsp)
movq %r13, (%rsp)
andq $0x0, 0x20(%rsp)
leaq 0x288522(%rip), %rdx    # 0x296230
leaq 0x48(%rsp), %rdi
movq %r12, %rsi
movq %r14, %r8
movq 0xc8(%rsp), %r9
callq 0xbb86f
addq $0x30, %rsp
cmpl $0x0, 0xdc(%rbx)
jle 0xdd78
movsd 0xe0(%rbx), %xmm0
subq $0x30, %rsp
leaq 0xdc(%rbx), %rax
movq %rax, 0x20(%rsp)
movq %r13, (%rsp)
andq $0x0, 0x18(%rsp)
leaq 0x2884d4(%rip), %rdx    # 0x296230
leaq 0x48(%rsp), %rdi
movq %r12, %rsi
movq %r14, %r8
movq 0xc8(%rsp), %r9
callq 0xbb86f
addq $0x30, %rsp
movq 0x18(%rsp), %rbx
subq $0x8, %rsp
pushq $0x1
popq %rax
leaq 0x38(%rsp), %r8
movq %rbx, %rdi
movq %rbx, 0x18(%rsp)
movq %r12, %rsi
movq %r15, %rdx
movq %r15, 0x30(%rsp)
movq %r14, %rcx
movq %rbp, %r9
pushq %rax
pushq $0x0
movl 0xc0(%rsp), %eax
pushq %rax
callq 0xb67c4
addq $0x20, %rsp
movq 0x287223(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x22ad85(%rip), %rdi    # 0x238b4c
pushq $0x27
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x2090
leaq 0x23(%rax), %rdi
callq 0x2280
movq %rax, %rbp
leaq 0x22993b(%rip), %rsi    # 0x23772d
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x23a8dc(%rip), %rsi    # 0x2486e2
movq %rbp, %rdi
callq 0x2210
movq %rax, %r13
subq $0x8, %rsp
leaq 0x228c6f(%rip), %r10    # 0x236a8b
leaq 0x28840d(%rip), %rsi    # 0x296230
movq %rbx, %rdi
movq %r12, %rdx
movq 0x30(%rsp), %rbx
movq %rbx, %rcx
movq %r14, %r8
movq 0xa0(%rsp), %r9
pushq %rax
pushq %r10
pushq $0x1
popq %rax
pushq %rax
callq 0xb7823
addq $0x20, %rsp
movq %r13, %rdi
callq 0x2190
leaq 0x2298f6(%rip), %rsi    # 0x237751
movq %rbp, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
movq %rbp, %rdi
leaq 0x23a870(%rip), %rsi    # 0x2486e2
callq 0x2210
movq %rax, %r13
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
leaq 0x2883a6(%rip), %rsi    # 0x296230
movq %rbx, %r15
leaq 0x228bf7(%rip), %rbx    # 0x236a8b
movq %r12, 0x8(%rsp)
movq %r12, %rdx
movq %r15, %rcx
movq %r14, 0x10(%rsp)
movq %r14, %r8
movq %rdi, %r12
movq 0xa0(%rsp), %r9
pushq %rax
pushq %rbx
pushq $0x0
callq 0xb7823
addq $0x20, %rsp
movq %r13, %rdi
callq 0x2190
leaq 0x28788a(%rip), %rax    # 0x295758
cmpl $0x0, 0x150(%rax)
je 0xdf4b
movq %rax, %r13
leaq 0x229886(%rip), %rsi    # 0x237767
movq %rbp, %rdi
movq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x23a7eb(%rip), %rsi    # 0x2486e2
movq %rbp, %rdi
callq 0x2210
movq %r15, %rcx
movq %rax, %r15
movl 0x150(%r13), %eax
leaq 0x28831d(%rip), %rdx    # 0x296230
leaq 0x30(%rsp), %r9
movq %r12, %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %r8
pushq $0x0
pushq %r15
pushq %rbx
pushq %rax
movl 0xc8(%rsp), %eax
pushq %rax
movl 0xc8(%rsp), %eax
pushq %rax
callq 0xb8f0d
addq $0x30, %rsp
movq %r15, %rdi
callq 0x2190
movq %rbp, %rdi
callq 0x2220
movq %r12, %rdi
callq 0xa0761
movq 0x40(%rsp), %rdi
callq 0x2220
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq