// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
movq %rcx, %rbp
movq %rdx, (%rsp)
movq %rsi, %r12
movl 0xa8(%rsp), %r15d
movq %r9, 0x28(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
xorl %r14d, %r14d
movq %rdi, 0x8(%rsp)
xorl %esi, %esi
callq 0x781bd
movq %rax, %r13
movq %rax, 0x20(%rsp)
movq 0x18(%rax), %rax
movl 0x14(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
pushq $0x2
popq %rdx
cmpq %r14, %rcx
je 0xb3df7
movq 0x20(%rax), %rsi
cmpl $0x0, (%rsi,%r14,8)
js 0xb3dee
movb $0x0, 0x4(%rsi,%r14,8)
movq 0x10(%r13), %rsi
movl (%rsi,%rdx,8), %edi
movl %edi, -0xc(%rsi,%rdx,8)
incq %r14
addq $0x5, %rdx
jmp 0xb3dcd
testq %rbx, %rbx
jne 0xb3e03
movq 0x8(%rsp), %r14
jmp 0xb3e51
subq $0x10, %rsp
andq $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
leaq 0x38(%rsp), %rsi
pushq $-0x1
popq %rdx
pushq $0x5
popq %rcx
movq %r13, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x9716c
popq %rcx
popq %rdx
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x8ea44
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x80328
movq (%rbx), %r13
movq (%rsp), %rbx
subq $0x8, %rsp
leaq 0x38(%rsp), %r8
movq %r13, %rdi
movq %r14, %rsi
movq %r12, 0x20(%rsp)
movq %r12, %rdx
movq %rbp, 0x18(%rsp)
movq %rbp, %rcx
movl 0xa8(%rsp), %eax
movq %rax, %r9
pushq $0x1
pushq $0x0
pushq %r15
callq 0x7b888
addq $0x20, %rsp
movq 0x19f14c(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x136b52(%rip), %rdi    # 0x1ea9f0
pushq $0x29
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq %rbx, %rdi
callq 0x2090
leaq 0x23(%rax), %rdi
callq 0x2280
movq %r14, %r12
movq %rbx, %r14
movq %rax, %rbx
leaq 0x136b50(%rip), %rsi    # 0x1eaa1a
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x1467c3(%rip), %rsi    # 0x1fa6a1
movq %rbx, %rdi
callq 0x2210
movq %rax, %r15
subq $0x8, %rsp
leaq 0x139d87(%rip), %r9     # 0x1edc7b
movq %r13, %rdi
movq %r12, %rsi
movq 0x20(%rsp), %rbp
movq %rbp, %rdx
movq 0x18(%rsp), %rcx
movq 0xa0(%rsp), %r8
pushq %rax
callq 0x7cd23
popq %rax
popq %rcx
movq %r15, %rdi
callq 0x2190
leaq 0x136b01(%rip), %rsi    # 0x1eaa27
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2050
movq %rbx, %rdi
leaq 0x146764(%rip), %rsi    # 0x1fa6a1
callq 0x2210
movq %rax, %r14
subq $0x8, %rsp
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
leaq 0x139d22(%rip), %r12    # 0x1edc7b
movq 0x18(%rsp), %rcx
movq 0xa0(%rsp), %r8
movq %r12, %r9
pushq %rax
callq 0x7de8f
popq %rax
popq %rcx
movq %r14, %rdi
callq 0x2190
leaq 0x19f7d8(%rip), %r15    # 0x253758
cmpl $0x0, 0x150(%r15)
je 0xb3ffe
leaq 0x136aa9(%rip), %rsi    # 0x1eaa3a
movq %rbx, %rdi
movq (%rsp), %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x1466fb(%rip), %rsi    # 0x1fa6a1
movq %rbx, %rdi
callq 0x2210
movq %rax, %r14
movl 0x150(%r15), %eax
leaq 0x1a0271(%rip), %rdx    # 0x254230
leaq 0x30(%rsp), %r9
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %r8
pushq $0x0
pushq %r14
pushq %r12
pushq %rax
movl 0xc8(%rsp), %eax
pushq %rax
movl 0xc8(%rsp), %eax
pushq %rax
callq 0x7debc
addq $0x30, %rsp
movq %r14, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x2220
movq %r13, %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