// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: output_contig_graph_primary_pre(asg_t*, ma_sub_t*, char*, ma_hit_t_alloc*, ma_hit_t_alloc*, unsigned long, long long, R_to_U*, int, int, ug_opt_t const*)
void output_contig_graph_primary_pre(asg_t *sg, ma_sub_t* coverage_cut, char* output_file_name, 
ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, uint64_t bubble_dist, long long tipsLen, 
R_to_U* ruIndex, int max_hang, int min_ovlp, const ug_opt_t *uopt)
{
    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);

    asg_t* nsg = ug->g;
    uint32_t n_vtx = nsg->n_seq, v;
    for (v = 0; v < n_vtx; ++v) 
    {
        if(nsg->seq[v].del) continue;
        nsg->seq[v].c = PRIMARY_LABLE;
        EvaluateLen(ug->u, v) = ug->u.a[v].n;
    }

    if(bubble_dist > 0)
    {
        asg_pop_bubble_primary_trio(ug, &bubble_dist, (uint32_t)-1, DROP, NULL, NULL, 0, NULL);
        delete_useless_nodes(&ug);
        renew_utg(&ug, sg, &new_rtg_edges);
    }
    
    // reset_untig_hap_label(ug, 7, FATHER, R_INF.trio_flag);
    // reset_untig_hap_label(ug, 35, FATHER, R_INF.trio_flag);

    // reset_untig_hap_label(ug, 713, FATHER, R_INF.trio_flag);
    // reset_untig_hap_label(ug, 273, FATHER, R_INF.trio_flag);
    // reset_untig_hap_label(ug, 822, FATHER, R_INF.trio_flag);

    ma_ug_seq(ug, sg, coverage_cut, sources, &new_rtg_edges, max_hang, min_ovlp, 0, 1);

    fprintf(stderr, "Writing processed unitig GFA to disk... \n");
    char* gfa_name = (char*)malloc(strlen(output_file_name)+35);
    sprintf(gfa_name, "%s.p_utg.gfa", output_file_name);
    FILE* output_file = fopen(gfa_name, "w");
    ma_ug_print(ug, sg, coverage_cut, sources, ruIndex, "utg", output_file);
    fclose(output_file);
    
    sprintf(gfa_name, "%s.p_utg.noseq.gfa", output_file_name);
    output_file = fopen(gfa_name, "w");
    ma_ug_print_simple(ug, sg, coverage_cut, sources, ruIndex, "utg", output_file);
    fclose(output_file);
    if(asm_opt.bed_inconsist_rate != 0)
    {
        sprintf(gfa_name, "%s.p_utg.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, "utg", output_file, NULL);
        fclose(output_file);
    }

    ///for debug
    // graph_ovlp_binning(ug, sg, uopt);
    // gen_hpc_re_t(ug);

    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
movq %r9, %rbp
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r13
movq %r9, 0x28(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
xorl %esi, %esi
callq 0xb2a6d
movq %rax, %r15
movq %rax, 0x20(%rsp)
movq 0x18(%rax), %rax
movl 0x14(%rax), %ecx
andq $0x7fffffff, %rcx       # imm = 0x7FFFFFFF
je 0xd9bb
movq 0x20(%rax), %rax
addq $0x4, %rax
imulq $0x28, %rcx, %rcx
xorl %edx, %edx
cmpl $0x0, -0x4(%rax)
js 0xd9ae
movb $0x0, (%rax)
movq 0x10(%r15), %rsi
movl 0x10(%rsi,%rdx), %edi
movl %edi, 0x4(%rsi,%rdx)
addq $0x8, %rax
addq $0x28, %rdx
cmpq %rdx, %rcx
jne 0xd999
movl 0xa8(%rsp), %r10d
movl 0xa0(%rsp), %eax
testq %rbp, %rbp
je 0xda2b
subq $0x10, %rsp
andq $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
leaq 0x38(%rsp), %rsi
pushq $-0x1
popq %rdx
pushq $0x5
popq %rcx
movq %r15, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
movq %r10, %r15
callq 0xd3845
popq %rcx
popq %rdx
movq %rbx, %rbp
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0xca9ea
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq 0xbb7a4
movq %r15, %r10
movl 0xa0(%rsp), %eax
movq (%rbx), %r15
movq %rbp, %rbx
subq $0x8, %rsp
pushq $0x1
popq %r11
leaq 0x38(%rsp), %r8
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r14, %rcx
movq %rax, %r9
pushq %r11
pushq $0x0
pushq %r10
callq 0xb67c4
addq $0x20, %rsp
movq 0x287583(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x22b089(%rip), %rdi    # 0x238af0
pushq $0x29
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq %rbx, %rdi
callq 0x2090
leaq 0x23(%rax), %rdi
callq 0x2280
movq %rax, %rbp
leaq 0x22b08d(%rip), %rsi    # 0x238b1a
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x23ac41(%rip), %rsi    # 0x2486e2
movq %rbp, %rdi
callq 0x2210
movq %r12, %rcx
movq %r13, %r12
movq %rax, %r13
subq $0x8, %rsp
leaq 0x22e2ce(%rip), %r10    # 0x23bd8b
movq %rcx, 0x10(%rsp)
leaq 0x288767(%rip), %rsi    # 0x296230
movq %r15, %rdi
movq %r12, %rdx
movq 0x10(%rsp), %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
movq %r14, %r13
callq 0x2190
leaq 0x22b026(%rip), %rsi    # 0x238b27
movq %rbp, %rdi
movq %rbx, 0x10(%rsp)
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
movq %rbp, %rdi
leaq 0x23abc5(%rip), %rsi    # 0x2486e2
callq 0x2210
movq %rax, %rbx
subq $0x8, %rsp
movq %r15, %rdi
leaq 0x2886fd(%rip), %rsi    # 0x296230
movq 0x10(%rsp), %r14
movq %r12, 0x20(%rsp)
movq %r12, %rdx
movq %r14, %rcx
movq %r13, %r8
movq 0xa0(%rsp), %r9
pushq %rax
leaq 0x22e235(%rip), %rax    # 0x23bd8b
pushq %rax
pushq $0x0
callq 0xb7823
addq $0x20, %rsp
movq %rbx, %rdi
callq 0x2190
leaq 0x287be7(%rip), %r12    # 0x295758
cmpl $0x0, 0x150(%r12)
je 0xdbf4
leaq 0x22afb7(%rip), %rsi    # 0x238b3a
movq %rbp, %rdi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x23ab49(%rip), %rsi    # 0x2486e2
movq %rbp, %rdi
callq 0x2210
movq %rax, %rbx
movl 0x150(%r12), %eax
leaq 0x28867d(%rip), %rdx    # 0x296230
leaq 0x30(%rsp), %r9
movq %r15, %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rcx
movq %r13, %r8
pushq $0x0
pushq %rbx
leaq 0x22e1bb(%rip), %r10    # 0x23bd8b
pushq %r10
pushq %rax
movl 0xc8(%rsp), %eax
pushq %rax
movl 0xc8(%rsp), %eax
pushq %rax
callq 0xb8f0d
addq $0x30, %rsp
movq %rbx, %rdi
callq 0x2190
movq %rbp, %rdi
callq 0x2220
movq %r15, %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