// File: /workspace/github_cpp_makefile_star2_O1/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 %rcx, %r14
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r12
movq %r9, 0x18(%rsp)
xorps %xmm0, %xmm0
andq $0x0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x10(%rsp)
xorl %esi, %esi
callq 0xb1a83
movq %rax, 0x10(%rsp)
movq 0x18(%rax), %rcx
movl 0x14(%rcx), %edx
andq $0x7fffffff, %rdx       # imm = 0x7FFFFFFF
je 0xda5a
movq 0x20(%rcx), %rcx
addq $0x4, %rcx
imulq $0x28, %rdx, %rdx
xorl %esi, %esi
cmpl $0x0, -0x4(%rcx)
js 0xda4d
movb $0x0, (%rcx)
movq 0x10(%rax), %rdi
movl 0x10(%rdi,%rsi), %r8d
movl %r8d, 0x4(%rdi,%rsi)
addq $0x8, %rcx
addq $0x28, %rsi
cmpq %rsi, %rdx
jne 0xda36
movl 0xa8(%rsp), %ebp
movl 0xa0(%rsp), %r9d
cmpq $0x0, 0x18(%rsp)
je 0xdabf
subq $0x10, %rsp
andq $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
leaq 0x28(%rsp), %rsi
pushq $-0x1
popq %rdx
pushq $0x5
popq %rcx
movq %rax, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xd23e2
popq %rcx
popq %rdx
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0xc971c
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0xba760
movl 0xa0(%rsp), %r9d
movq 0x10(%rsp), %rdi
movq %rdi, 0x8(%rsp)
subq $0x8, %rsp
pushq $0x1
popq %rax
leaq 0x38(%rsp), %r8
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
pushq %rax
pushq $0x0
pushq %rbp
callq 0xb5778
addq $0x20, %rsp
movq 0x27c4ee(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
leaq 0x21ee04(%rip), %rdi    # 0x22c900
pushq $0x29
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq %r13, %rdi
callq 0x2090
leaq 0x23(%rax), %rdi
callq 0x2280
movq %r13, %rbx
movq %rax, %rbp
leaq 0x21ee05(%rip), %rsi    # 0x22c92a
movq %rax, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x22e8c5(%rip), %rsi    # 0x23c3fe
movq %rbp, %rdi
callq 0x2210
movq %r12, %r13
movq %rax, %r12
subq $0x8, %rsp
leaq 0x221fe9(%rip), %r10    # 0x22fb3b
leaq 0x27d6d7(%rip), %rsi    # 0x28b230
movq 0x10(%rsp), %rdi
movq %r13, %rdx
movq %r15, %rcx
movq %r14, %r8
movq 0xa0(%rsp), %r9
pushq %rax
pushq %r10
pushq $0x1
popq %rax
pushq %rax
callq 0xb688e
addq $0x20, %rsp
movq %r12, %rdi
movq %r14, %r12
callq 0x2190
leaq 0x21eda6(%rip), %rsi    # 0x22c937
movq %rbp, %rdi
movq %rbx, 0x28(%rsp)
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
movq %rbp, %rdi
leaq 0x22e851(%rip), %rsi    # 0x23c3fe
callq 0x2210
movq %rax, %rbx
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
leaq 0x221f76(%rip), %rax    # 0x22fb3b
leaq 0x27d664(%rip), %rsi    # 0x28b230
movq %r13, 0x28(%rsp)
movq %r13, %rdx
movq %r15, %rcx
movq %r14, %r8
movq 0xa0(%rsp), %r9
pushq %rbx
movq %rax, %r13
pushq %rax
pushq $0x0
callq 0xb688e
addq $0x20, %rsp
movq %rbx, %rdi
callq 0x2190
leaq 0x27cb57(%rip), %r14    # 0x28a758
cmpl $0x0, 0x150(%r14)
je 0xdc7d
leaq 0x21ed38(%rip), %rsi    # 0x22c94a
movq %rbp, %rdi
movq 0x28(%rsp), %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x22e7d6(%rip), %rsi    # 0x23c3fe
movq %rbp, %rdi
callq 0x2210
movq %rax, %rbx
movl 0x150(%r14), %eax
leaq 0x27d5ef(%rip), %rdx    # 0x28b230
leaq 0x30(%rsp), %r9
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %r15, %rcx
movq %r12, %r8
pushq $0x0
pushq %rbx
pushq %r13
pushq %rax
movl 0xc8(%rsp), %eax
pushq %rax
movl 0xc8(%rsp), %eax
pushq %rax
callq 0xb7f72
addq $0x30, %rsp
movq %rbx, %rdi
callq 0x2190
movq %rbp, %rdi
callq 0x2220
movq 0x8(%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