// File: /workspace/github_cpp_makefile_star2_O2/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, 0x8(%rsp)
movss %xmm1, 0x10(%rsp)
movss %xmm0, 0x24(%rsp)
movq %r9, %rbx
movq %r8, %r13
movq %rcx, %rbp
movq %rdx, 0x28(%rsp)
movq %rsi, %r14
movq %rdi, %r12
xorl %esi, %esi
callq 0x781bd
leaq 0x18(%rsp), %rdi
movq %rax, (%rdi)
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %r9
movaps %xmm0, (%r9)
andq $0x0, 0x10(%r9)
subq $0x8, %rsp
movq %r12, %rsi
movq %rbp, %r15
movq %rbp, %rdx
movq %r13, %rcx
movl 0xb0(%rsp), %ebp
movq %r14, %r13
movq %r14, %r8
movq %r9, %r14
movq %rbx, %r9
movss 0x2c(%rsp), %xmm1
movss 0x18(%rsp), %xmm2
movss 0x10(%rsp), %xmm3
pushq $0x0
pushq $0x0
pushq 0xc8(%rsp)
pushq $0x0
pushq %r14
pushq %rbp
movl 0xd8(%rsp), %eax
pushq %rax
pushq 0xd8(%rsp)
pushq 0xd8(%rsp)
callq 0x8cb4c
addq $0x50, %rsp
leaq 0x19f672(%rip), %rbx    # 0x253758
xorl %eax, %eax
cmpl %eax, 0xd8(%rbx)
jle 0xb4135
movsd 0xe0(%rbx), %xmm0
subq $0x30, %rsp
leaq 0xd8(%rbx), %rax
movq %rax, 0x18(%rsp)
movq %r14, (%rsp)
andq $0x0, 0x20(%rsp)
leaq 0x1a0117(%rip), %rdx    # 0x254230
leaq 0x48(%rsp), %rdi
movq %r12, %rsi
movq %r15, %r8
movq 0xc8(%rsp), %r9
callq 0x80454
addq $0x30, %rsp
cmpl $0x0, 0xdc(%rbx)
jle 0xb4183
movsd 0xe0(%rbx), %xmm0
subq $0x30, %rsp
leaq 0xdc(%rbx), %rax
movq %rax, 0x20(%rsp)
movq %r14, (%rsp)
andq $0x0, 0x18(%rsp)
leaq 0x1a00c9(%rip), %rdx    # 0x254230
leaq 0x48(%rsp), %rdi
movq %r12, %rsi
movq %r15, %r8
movq 0xc8(%rsp), %r9
callq 0x80454
addq $0x30, %rsp
movq %r12, 0x8(%rsp)
movq 0x18(%rsp), %r12
subq $0x8, %rsp
leaq 0x38(%rsp), %r8
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movq %r13, %r14
movq %r13, %rdx
movq %r15, %r13
movq %r15, %rcx
movl 0xa8(%rsp), %r9d
pushq $0x1
pushq $0x0
pushq %rbp
callq 0x7b888
addq $0x20, %rsp
movq 0x19ee19(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x13687b(%rip), %rdi    # 0x1eaa4c
pushq $0x27
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x2090
leaq 0x23(%rax), %rdi
callq 0x2280
movq %rax, %rbp
leaq 0x135431(%rip), %rsi    # 0x1e962d
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x146491(%rip), %rsi    # 0x1fa6a1
movq %rbp, %rdi
callq 0x2210
movq %rax, %r15
subq $0x8, %rsp
leaq 0x134765(%rip), %r9     # 0x1e898b
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
movq %r13, %rcx
movq 0xa0(%rsp), %r8
pushq %rax
callq 0x7cd23
popq %rax
popq %rcx
movq %r15, %rdi
callq 0x2190
leaq 0x1353fe(%rip), %rsi    # 0x1e9651
movq %rbp, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
movq %rbp, %rdi
leaq 0x146437(%rip), %rsi    # 0x1fa6a1
callq 0x2210
movq %rax, %r15
subq $0x8, %rsp
movq %r12, 0x18(%rsp)
movq %r12, %rdi
movq 0x10(%rsp), %r12
movq %r12, %rsi
movq %r14, %rdx
movq %r13, %rcx
movq 0xa0(%rsp), %r8
leaq 0x1346f0(%rip), %r9     # 0x1e898b
pushq %rax
callq 0x7de8f
popq %rax
popq %rcx
movq %r15, %rdi
callq 0x2190
leaq 0x19f4a6(%rip), %rax    # 0x253758
cmpl $0x0, 0x150(%rax)
je 0xb4337
leaq 0x1353a5(%rip), %rsi    # 0x1e9667
movq %rbp, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x1463cb(%rip), %rsi    # 0x1fa6a1
movq %rbp, %rdi
callq 0x2210
movq %rax, %r15
leaq 0x19f470(%rip), %rax    # 0x253758
movl 0x150(%rax), %eax
leaq 0x19ff3b(%rip), %rdx    # 0x254230
leaq 0x30(%rsp), %r9
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rcx
movq %r13, %r8
pushq $0x0
pushq %r15
leaq 0x134678(%rip), %r10    # 0x1e898b
pushq %r10
pushq %rax
movl 0xc8(%rsp), %eax
pushq %rax
movl 0xc8(%rsp), %eax
pushq %rax
callq 0x7debc
addq $0x30, %rsp
movq %r15, %rdi
callq 0x2190
movq %rbp, %rdi
callq 0x2220
movq 0x10(%rsp), %rdi
callq 0x6921d
movq 0x40(%rsp), %rdi
callq 0x2220
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq