// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movq %rcx, %r13
movq %rdx, 0x28(%rsp)
movq %rsi, %r14
movq %rdi, %r12
leaq 0x18(%rsp), %rbp
andq $0x0, (%rbp)
xorl %esi, %esi
callq 0xb1a83
movq %rax, (%rbp)
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %r9
movaps %xmm0, (%r9)
andq $0x0, 0x10(%r9)
subq $0x8, %rsp
movq %rbp, %rdi
movq %r12, %rsi
movq %r13, %rbp
movq %r13, %rdx
movq %r15, %rcx
movl 0xa8(%rsp), %r10d
movq %r14, %r15
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
movl 0xd8(%rsp), %eax
pushq %rax
movq %r10, %r13
pushq %r10
pushq 0xd8(%rsp)
pushq 0xd8(%rsp)
callq 0xc8339
addq $0x50, %rsp
leaq 0x27c9e3(%rip), %rbx    # 0x28a758
xorl %eax, %eax
cmpl %eax, 0xd8(%rbx)
jle 0xddc4
movsd 0xe0(%rbx), %xmm0
subq $0x30, %rsp
leaq 0xd8(%rbx), %rax
movq %rax, 0x18(%rsp)
movq %r14, (%rsp)
andq $0x0, 0x20(%rsp)
leaq 0x27d488(%rip), %rdx    # 0x28b230
leaq 0x48(%rsp), %rdi
movq %r12, %rsi
movq %rbp, %r8
movq 0xc8(%rsp), %r9
callq 0xba811
addq $0x30, %rsp
cmpl $0x0, 0xdc(%rbx)
jle 0xde12
movsd 0xe0(%rbx), %xmm0
subq $0x30, %rsp
leaq 0xdc(%rbx), %rax
movq %rax, 0x20(%rsp)
movq %r14, (%rsp)
andq $0x0, 0x18(%rsp)
leaq 0x27d43a(%rip), %rdx    # 0x28b230
leaq 0x48(%rsp), %rdi
movq %r12, %rsi
movq %rbp, %r8
movq 0xc8(%rsp), %r9
callq 0xba811
addq $0x30, %rsp
movq %r12, 0x8(%rsp)
movq 0x18(%rsp), %r12
subq $0x8, %rsp
pushq $0x1
popq %rax
leaq 0x38(%rsp), %r8
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movq %r15, %r14
movq %r15, %rdx
movq %rbp, %r15
movq %rbp, %rcx
movq %r13, %r9
pushq %rax
pushq $0x0
movl 0xc0(%rsp), %eax
pushq %rax
callq 0xb5778
addq $0x20, %rsp
movq 0x27c186(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
leaq 0x21eaf8(%rip), %rdi    # 0x22c95c
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 0x21d6ae(%rip), %rsi    # 0x22b53d
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x22e55b(%rip), %rsi    # 0x23c3fe
movq %rbp, %rdi
callq 0x2210
movq %rax, %r13
subq $0x8, %rsp
leaq 0x21c9e2(%rip), %r10    # 0x22a89b
leaq 0x27d370(%rip), %rsi    # 0x28b230
movq %r12, %rdi
movq 0x10(%rsp), %rdx
movq %r14, %rcx
movq %r15, %r8
movq 0xa0(%rsp), %r9
pushq %rax
pushq %r10
pushq $0x1
popq %rax
pushq %rax
callq 0xb688e
addq $0x20, %rsp
movq %r13, %rdi
callq 0x2190
leaq 0x21d66c(%rip), %rsi    # 0x22b561
movq %rbp, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
movq %rbp, %rdi
leaq 0x22e4f2(%rip), %rsi    # 0x23c3fe
callq 0x2210
movq %rax, %r13
subq $0x8, %rsp
movq %r12, 0x18(%rsp)
movq %r12, %rdi
movq 0x10(%rsp), %r12
leaq 0x27d304(%rip), %rsi    # 0x28b230
movq %r12, %rdx
movq %r14, %rcx
movq %r15, %r8
movq 0xa0(%rsp), %r9
pushq %rax
leaq 0x21c956(%rip), %rax    # 0x22a89b
pushq %rax
pushq $0x0
callq 0xb688e
addq $0x20, %rsp
movq %r13, %rdi
leaq 0x27c7fd(%rip), %r13    # 0x28a758
callq 0x2190
cmpl $0x0, 0x150(%r13)
je 0xdfe0
leaq 0x21d606(%rip), %rsi    # 0x22b577
movq %rbp, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x22e479(%rip), %rsi    # 0x23c3fe
movq %rbp, %rdi
callq 0x2210
movq %r15, %r8
movq %rax, %r15
movl 0x150(%r13), %eax
leaq 0x27d28f(%rip), %rdx    # 0x28b230
leaq 0x30(%rsp), %r9
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rcx
pushq $0x0
pushq %r15
leaq 0x21c8df(%rip), %r10    # 0x22a89b
pushq %r10
pushq %rax
movl 0xc8(%rsp), %eax
pushq %rax
movl 0xc8(%rsp), %eax
pushq %rax
callq 0xb7f72
addq $0x30, %rsp
movq %r15, %rdi
callq 0x2190
movq %rbp, %rdi
callq 0x2220
movq 0x10(%rsp), %rdi
callq 0xa0004
movq 0x40(%rsp), %rdi
callq 0x2220
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq