// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: output_contig_graph_alternative(asg_t*, ma_sub_t*, char*, ma_hit_t_alloc*, R_to_U*, int, int)
void output_contig_graph_alternative(asg_t *sg, ma_sub_t* coverage_cut, char* output_file_name,
ma_hit_t_alloc* sources, R_to_U* ruIndex, int max_hang, int min_ovlp)
{
    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, ALTER_LABLE);

    // 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);
    // }

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

    fprintf(stderr, "Writing alternate contig GFA to disk... \n");
    char* gfa_name = (char*)malloc(strlen(output_file_name)+35);
    sprintf(gfa_name, "%s.a_ctg.gfa", output_file_name);
    FILE* output_file = fopen(gfa_name, "w");
    ma_ug_print(ug, sg, coverage_cut, sources, ruIndex, "atg", output_file);
    fclose(output_file);
    
    sprintf(gfa_name, "%s.a_ctg.noseq.gfa", output_file_name);
    output_file = fopen(gfa_name, "w");
    ma_ug_print_simple(ug, sg, coverage_cut, sources, ruIndex, "atg", output_file);
    fclose(output_file);
    if(asm_opt.bed_inconsist_rate != 0)
    {
        sprintf(gfa_name, "%s.a_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, "atg", 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 %rbx
subq $0x98, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movl %r9d, -0x44(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0xe7ae0
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl -0x44(%rbp), %r9d
movl 0x10(%rbp), %eax
leaq -0x68(%rbp), %r8
xorl %r10d, %r10d
movl %eax, (%rsp)
movq $0x0, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
callq 0xed140
movq 0x2b7835(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x27cfea(%rip), %rsi    # 0x38979f
movb $0x0, %al
callq 0x22a0
movq -0x30(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0x23, %rdi
callq 0x2270
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x27cfe5(%rip), %rsi    # 0x3897c9
movb $0x0, %al
callq 0x2050
movq -0x78(%rbp), %rdi
leaq 0x28cbdc(%rip), %rsi    # 0x3993d2
callq 0x2200
movq %rax, -0x80(%rbp)
movq -0x70(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
movq -0x80(%rbp), %rax
leaq 0x27cfb8(%rip), %r9     # 0x3897d6
movq %rax, (%rsp)
callq 0xefa60
movq -0x80(%rbp), %rdi
callq 0x21a0
movq -0x78(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x27cf9b(%rip), %rsi    # 0x3897da
movb $0x0, %al
callq 0x2050
movq -0x78(%rbp), %rdi
leaq 0x28cb81(%rip), %rsi    # 0x3993d2
callq 0x2200
movq %rax, -0x80(%rbp)
movq -0x70(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
movq -0x80(%rbp), %rax
leaq 0x27cf5d(%rip), %r9     # 0x3897d6
movq %rax, (%rsp)
callq 0xf1c10
movq -0x80(%rbp), %rdi
callq 0x21a0
leaq 0x2b7f66(%rip), %rax    # 0x3c47f8
cmpl $0x0, 0x150(%rax)
je 0x10c935
movq -0x78(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x27cf3f(%rip), %rsi    # 0x3897ed
movb $0x0, %al
callq 0x2050
movq -0x78(%rbp), %rdi
leaq 0x28cb12(%rip), %rsi    # 0x3993d2
callq 0x2200
movq %rax, -0x80(%rbp)
movq -0x70(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %r8
movl -0x44(%rbp), %r14d
movl 0x10(%rbp), %ebx
leaq 0x2b7f11(%rip), %rax    # 0x3c47f8
movl 0x150(%rax), %r11d
movq -0x80(%rbp), %rax
leaq 0x2b89d7(%rip), %rdx    # 0x3c52d0
leaq -0x68(%rbp), %r9
leaq 0x27ced2(%rip), %r10    # 0x3897d6
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 -0x80(%rbp), %rdi
callq 0x21a0
movq -0x78(%rbp), %rdi
callq 0x2210
movq -0x70(%rbp), %rdi
callq 0xcd6f0
movq -0x58(%rbp), %rdi
callq 0x2210
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop