// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: output_hap_graph(ma_ug_t*, asg_t*, kvec_asg_arc_t_warp*, ma_sub_t*, char*, unsigned char, ma_hit_t_alloc*, R_to_U*, int, int, char*)
void output_hap_graph(ma_ug_t *ug, asg_t *sg, kvec_asg_arc_t_warp *arcs, 
ma_sub_t* coverage_cut, char* output_file_name, uint8_t flag, ma_hit_t_alloc* sources, 
R_to_U* ruIndex, int max_hang, int min_ovlp, char *f_prefix)
{
    char* gfa_name = (char*)malloc(strlen(output_file_name)+100);
    sprintf(gfa_name, "%s.%s.p_ctg.gfa", output_file_name, f_prefix?f_prefix:(flag==FATHER?"hap1":"hap2"));
    FILE* output_file = fopen(gfa_name, "w");

    fprintf(stderr, "Writing %s to disk... \n", gfa_name);
    ///debug_utg_graph(ug, sg, 0, 0);
    ///debug_untig_length(ug, tipsLen, gfa_name);
    ///print_untig_by_read(ug, "m64011_190901_095311/125831121/ccs", 2310925, "end");
    ma_ug_seq(ug, sg, coverage_cut, sources, arcs, max_hang, min_ovlp, 0, 1);
    ma_ug_print(ug, sg, coverage_cut, sources, ruIndex, (flag==FATHER?"h1tg":"h2tg"), output_file);
    fclose(output_file);

    sprintf(gfa_name, "%s.%s.p_ctg.noseq.gfa", output_file_name, f_prefix?f_prefix:(flag==FATHER?"hap1":"hap2"));
    output_file = fopen(gfa_name, "w");
    ma_ug_print_simple(ug, sg, coverage_cut, sources, ruIndex, (flag==FATHER?"h1tg":"h2tg"), output_file);
    fclose(output_file);
    if(asm_opt.bed_inconsist_rate != 0)
    {
        sprintf(gfa_name, "%s.%s.p_ctg.lowQ.bed", output_file_name, f_prefix?f_prefix:(flag==FATHER?"hap1":"hap2"));
        output_file = fopen(gfa_name, "w");
        ma_ug_print_bed(ug, sg, &R_INF, coverage_cut, sources, arcs, 
        max_hang, min_ovlp, asm_opt.bed_inconsist_rate, (flag==FATHER?"h1tg":"h2tg"), output_file, NULL);
        fclose(output_file);
    }

    free(gfa_name);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r9d, %ebp
movq %r8, %r14
movq %rcx, 0x10(%rsp)
movq %rdx, 0x40(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, 0x28(%rsp)
movl 0xa8(%rsp), %eax
movq %rax, 0x48(%rsp)
movl 0xa0(%rsp), %eax
movq %rax, 0x38(%rsp)
movq 0x90(%rsp), %r12
movq 0x98(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0xb0(%rsp), %rbx
movq %r8, %rdi
movq %r8, 0x18(%rsp)
callq 0x2090
leaq 0x64(%rax), %rdi
callq 0x2280
movq %rax, %r15
cmpl $0x1, %ebp
leaq 0x14d17c(%rip), %rax    # 0x1e963a
leaq 0x14d17a(%rip), %rbp    # 0x1e963f
cmoveq %rax, %rbp
leaq 0x14d174(%rip), %rax    # 0x1e9644
leaq 0x14d172(%rip), %rcx    # 0x1e9649
cmoveq %rax, %rcx
movq %rcx, 0x20(%rsp)
testq %rbx, %rbx
cmovneq %rbx, %rbp
leaq 0x14d13c(%rip), %rsi    # 0x1e962a
leaq 0x15e1ac(%rip), %rbx    # 0x1fa6a1
movq %r15, %rdi
movq %r14, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x2050
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2210
movq %rax, (%rsp)
movq 0x1b6ac5(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0x14c44e(%rip), %rsi    # 0x1e8973
movq %r15, %rdx
xorl %eax, %eax
callq 0x22b0
subq $0x8, %rsp
movq 0x30(%rsp), %r13
movq %r13, %rdi
movq 0x10(%rsp), %r14
movq %r14, %rsi
movq 0x18(%rsp), %rbx
movq %rbx, %rdx
movq %r12, 0x38(%rsp)
movq %r12, %rcx
movq 0x48(%rsp), %r8
movq 0x40(%rsp), %r9
pushq $0x1
pushq $0x0
pushq 0x60(%rsp)
callq 0x7b888
addq $0x18, %rsp
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %r12, %rcx
movq 0x58(%rsp), %rbx
movq %rbx, %r8
movq 0x28(%rsp), %r12
movq %r12, %r9
movq 0x8(%rsp), %r14
pushq %r14
callq 0x7cd23
popq %rax
popq %rcx
movq %r14, %rdi
callq 0x2190
leaq 0x14d0a7(%rip), %rsi    # 0x1e964e
movq %r15, %rdi
movq 0x18(%rsp), %rdx
movq %rbp, (%rsp)
movq %rbp, %rcx
xorl %eax, %eax
callq 0x2050
movq %r15, %rdi
leaq 0x15e0da(%rip), %rsi    # 0x1fa6a1
callq 0x2210
movq %rax, %rbp
subq $0x8, %rsp
movq %r13, %rdi
movq 0x10(%rsp), %rsi
movq %r15, %r14
movq 0x18(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq %rbx, %r8
movq %r12, %r9
pushq %rax
callq 0x7de8f
popq %rax
popq %rcx
movq %rbp, %rdi
callq 0x2190
leaq 0x1b7153(%rip), %rbp    # 0x253758
cmpl $0x0, 0x150(%rbp)
je 0x9c682
leaq 0x14d04f(%rip), %rsi    # 0x1e9664
movq %r14, %rdi
movq 0x18(%rsp), %rdx
movq (%rsp), %rcx
xorl %eax, %eax
callq 0x2050
leaq 0x15e072(%rip), %rsi    # 0x1fa6a1
movq %r14, %rdi
callq 0x2210
movq %rax, %r15
movl 0x150(%rbp), %eax
leaq 0x1b7be9(%rip), %rdx    # 0x254230
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rcx
movq 0x30(%rsp), %r8
movq 0x40(%rsp), %r9
pushq $0x0
pushq %r15
pushq 0x30(%rsp)
pushq %rax
pushq 0x68(%rsp)
pushq 0x60(%rsp)
callq 0x7debc
addq $0x30, %rsp
movq %r15, %rdi
callq 0x2190
movq %r14, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220