// File: /workspace/github_cpp_makefile_star2_O3/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, %ebx
movq %r8, %r14
movq %rcx, 0x10(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %r15
movl 0xa8(%rsp), %eax
movq %rax, 0x30(%rsp)
movl 0xa0(%rsp), %eax
movq %rax, 0x40(%rsp)
movq 0x90(%rsp), %rbp
movq 0x98(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0xb0(%rsp), %r13
movq %r8, %rdi
movq %r8, 0x20(%rsp)
callq 0x2090
leaq 0x64(%rax), %rdi
callq 0x2280
movq %rax, %r12
pushq $0x1
popq %rax
cmpl %eax, %ebx
leaq 0x22c63d(%rip), %rax    # 0x23773a
leaq 0x22c63b(%rip), %rbx    # 0x23773f
cmoveq %rax, %rbx
leaq 0x22c635(%rip), %rax    # 0x237744
leaq 0x22c633(%rip), %rcx    # 0x237749
cmoveq %rax, %rcx
movq %rcx, 0x48(%rsp)
testq %r13, %r13
cmovneq %r13, %rbx
leaq 0x22c5fd(%rip), %rsi    # 0x23772a
leaq 0x23d5ae(%rip), %r13    # 0x2486e2
movq %r12, %rdi
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2050
movq %r12, %rdi
movq %r13, %rsi
callq 0x2210
movq %rax, 0x8(%rsp)
movq 0x289e85(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x22b90e(%rip), %rsi    # 0x236a73
movq %r12, %rdx
xorl %eax, %eax
callq 0x22b0
subq $0x8, %rsp
movq %r15, 0x30(%rsp)
movq %r15, %rdi
movq 0x20(%rsp), %r13
movq %r13, %rsi
movq 0x18(%rsp), %r14
movq %r14, %rdx
movq %rbp, %rcx
movq 0x40(%rsp), %r8
movq 0x48(%rsp), %r9
pushq $0x1
popq %r10
pushq %r10
pushq $0x0
pushq 0x48(%rsp)
callq 0xb67c4
addq $0x18, %rsp
leaq 0x28b07c(%rip), %rsi    # 0x296230
movq %r15, %rdi
movq %r13, %rdx
movq %r14, %rcx
movq %r12, %r14
movq %rbp, %r8
movq 0x58(%rsp), %r15
movq %r15, %r9
movq 0x10(%rsp), %r13
pushq %r13
movq 0x58(%rsp), %r12
pushq %r12
pushq $0x1
popq %rax
pushq %rax
callq 0xb7823
addq $0x20, %rsp
movq %r13, %rdi
callq 0x2190
leaq 0x22c559(%rip), %rsi    # 0x23774e
movq %r14, %rdi
movq 0x20(%rsp), %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2050
movq %r14, %rdi
leaq 0x23d4d1(%rip), %rsi    # 0x2486e2
callq 0x2210
movq %rax, %r13
subq $0x8, %rsp
movq 0x30(%rsp), %rdi
leaq 0x28b007(%rip), %rsi    # 0x296230
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq %rbp, 0x10(%rsp)
movq %rbp, %r8
movq %r15, %r9
pushq %rax
pushq %r12
pushq $0x0
callq 0xb7823
addq $0x20, %rsp
movq %r13, %rdi
callq 0x2190
leaq 0x28a4fd(%rip), %r13    # 0x295758
cmpl $0x0, 0x150(%r13)
je 0xb2d7
leaq 0x22c4f8(%rip), %rsi    # 0x237764
movq %r14, %rdi
movq 0x20(%rsp), %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2050
leaq 0x23d45d(%rip), %rsi    # 0x2486e2
movq %r14, %rdi
callq 0x2210
movq %rax, %r15
movl 0x150(%r13), %eax
leaq 0x28af92(%rip), %rdx    # 0x296230
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %r8
movq 0x38(%rsp), %r9
pushq $0x0
pushq %r15
pushq %r12
pushq %rax
pushq 0x50(%rsp)
pushq 0x68(%rsp)
callq 0xb8f0d
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