// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xc0, %rsp
movq 0x30(%rbp), %rax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x28(%rbp)
movq %rsi, -0x30(%rbp)
movq %rdx, -0x38(%rbp)
movq %rcx, -0x40(%rbp)
movq %r8, -0x48(%rbp)
movq %r9, -0x50(%rbp)
movss %xmm0, -0x54(%rbp)
movss %xmm1, -0x58(%rbp)
movss %xmm2, -0x5c(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0xe7ae0
movq %rax, -0x68(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x28(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x50(%rbp), %r9
movss -0x54(%rbp), %xmm1
movq 0x10(%rbp), %r15
movq 0x18(%rbp), %r14
movss -0x58(%rbp), %xmm2
movss -0x5c(%rbp), %xmm3
movl 0x20(%rbp), %ebx
movl 0x28(%rbp), %r11d
movq 0x30(%rbp), %rax
leaq -0x68(%rbp), %rdi
movss 0x23750d(%rip), %xmm0   # 0x38689c
leaq -0x88(%rbp), %r10
xorl %r12d, %r12d
xorl %r12d, %r12d
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movl %ebx, 0x10(%rsp)
movl %r11d, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movl $0x0, 0x38(%rsp)
movl $0x0, 0x40(%rsp)
callq 0x10bde0
leaq 0x27541b(%rip), %rax    # 0x3c47f8
cmpl $0x0, 0xd8(%rax)
jle 0x14f450
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %r8
movq 0x18(%rbp), %r9
movl 0x20(%rbp), %r11d
movl 0x28(%rbp), %r10d
leaq 0x2753f3(%rip), %rax    # 0x3c47f8
movsd 0xe0(%rax), %xmm0
leaq -0x68(%rbp), %rdi
leaq 0x275eb8(%rip), %rdx    # 0x3c52d0
leaq -0x88(%rbp), %rbx
leaq 0x2753d2(%rip), %rax    # 0x3c47f8
addq $0xd8, %rax
xorl %r14d, %r14d
movq %rbx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
callq 0xf6220
leaq 0x2753a1(%rip), %rax    # 0x3c47f8
cmpl $0x0, 0xdc(%rax)
jle 0x14f4c9
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %r8
movq 0x18(%rbp), %r9
movl 0x20(%rbp), %r11d
movl 0x28(%rbp), %r10d
leaq 0x275379(%rip), %rax    # 0x3c47f8
movsd 0xe0(%rax), %xmm0
leaq -0x68(%rbp), %rdi
leaq 0x275e3e(%rip), %rdx    # 0x3c52d0
leaq -0x88(%rbp), %rbx
xorl %eax, %eax
leaq 0x275356(%rip), %rax    # 0x3c47f8
addq $0xdc, %rax
movq %rbx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0xf6220
movq -0x68(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x40(%rbp), %rcx
movl 0x20(%rbp), %r9d
movl 0x28(%rbp), %eax
leaq -0x88(%rbp), %r8
xorl %r10d, %r10d
movl %eax, (%rsp)
movq $0x0, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
callq 0xed140
movq 0x274ad6(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x23a263(%rip), %rsi    # 0x389777
movb $0x0, %al
callq 0x22a0
movq -0x38(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0x23, %rdi
callq 0x2270
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x238dcf(%rip), %rsi    # 0x388318
movb $0x0, %al
callq 0x2050
movq -0x90(%rbp), %rdi
leaq 0x249e74(%rip), %rsi    # 0x3993d2
callq 0x2200
movq %rax, -0x98(%rbp)
movq -0x68(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq 0x18(%rbp), %r8
movq -0x98(%rbp), %rax
leaq 0x237f2d(%rip), %r9     # 0x3874b9
movq %rax, (%rsp)
callq 0xefa60
movq -0x98(%rbp), %rdi
callq 0x21a0
movq -0x90(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x238d89(%rip), %rsi    # 0x38833c
movb $0x0, %al
callq 0x2050
movq -0x90(%rbp), %rdi
leaq 0x249e0a(%rip), %rsi    # 0x3993d2
callq 0x2200
movq %rax, -0x98(%rbp)
movq -0x68(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq 0x18(%rbp), %r8
movq -0x98(%rbp), %rax
leaq 0x237ec3(%rip), %r9     # 0x3874b9
movq %rax, (%rsp)
callq 0xf1c10
movq -0x98(%rbp), %rdi
callq 0x21a0
leaq 0x2751e6(%rip), %rax    # 0x3c47f8
cmpl $0x0, 0x150(%rax)
je 0x14f6c7
movq -0x90(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x238d21(%rip), %rsi    # 0x388352
movb $0x0, %al
callq 0x2050
movq -0x90(%rbp), %rdi
leaq 0x249d8c(%rip), %rsi    # 0x3993d2
callq 0x2200
movq %rax, -0x98(%rbp)
movq -0x68(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %r8
movl 0x20(%rbp), %r14d
movl 0x28(%rbp), %ebx
leaq 0x275188(%rip), %rax    # 0x3c47f8
movl 0x150(%rax), %r11d
movq -0x98(%rbp), %rax
leaq 0x275c4b(%rip), %rdx    # 0x3c52d0
leaq -0x88(%rbp), %r9
leaq 0x237e26(%rip), %r10    # 0x3874b9
xorl %r15d, %r15d
movl %r14d, (%rsp)
movl %ebx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
callq 0xf1c80
movq -0x98(%rbp), %rdi
callq 0x21a0
movq -0x90(%rbp), %rdi
callq 0x2210
movq -0x68(%rbp), %rdi
callq 0xcd6f0
movq -0x78(%rbp), %rdi
callq 0x2210
addq $0xc0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)