// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: output_unitig_graph(asg_t*, ma_sub_t*, char*, ma_hit_t_alloc*, R_to_U*, int, int)
void output_unitig_graph(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(sg);
    ma_ug_seq(ug, sg, coverage_cut, sources, &new_rtg_edges, max_hang, min_ovlp, 0, 1);

    fprintf(stderr, "Writing raw unitig GFA to disk... \n");
    char* gfa_name = (char*)malloc(strlen(output_file_name)+25);
    sprintf(gfa_name, "%s.r_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.r_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.r_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);
    }

    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
callq 0xe5910
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 0x2c88ca(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x28bd2b(%rip), %rsi    # 0x38744b
movb $0x0, %al
callq 0x22a0
movq -0x30(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0x19, %rdi
callq 0x2270
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x28bd20(%rip), %rsi    # 0x38746f
movb $0x0, %al
callq 0x2050
movq -0x78(%rbp), %rdi
leaq 0x29dc71(%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 0x29121f(%rip), %r9     # 0x38c9a8
movq %rax, (%rsp)
callq 0xefa60
movq -0x80(%rbp), %rdi
callq 0x21a0
movq -0x78(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x28bcd2(%rip), %rsi    # 0x38747c
movb $0x0, %al
callq 0x2050
movq -0x78(%rbp), %rdi
leaq 0x29dc16(%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 0x2911c4(%rip), %r9     # 0x38c9a8
movq %rax, (%rsp)
callq 0xf1c10
movq -0x80(%rbp), %rdi
callq 0x21a0
leaq 0x2c8ffb(%rip), %rax    # 0x3c47f8
cmpl $0x0, 0x150(%rax)
je 0xfb8a0
movq -0x78(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x28bc76(%rip), %rsi    # 0x38748f
movb $0x0, %al
callq 0x2050
movq -0x78(%rbp), %rdi
leaq 0x29dba7(%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 0x2c8fa6(%rip), %rax    # 0x3c47f8
movl 0x150(%rax), %r11d
movq -0x80(%rbp), %rax
leaq 0x2c9a6c(%rip), %rdx    # 0x3c52d0
leaq -0x68(%rbp), %r9
leaq 0x291139(%rip), %r10    # 0x38c9a8
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
nopl (%rax)