// File: /workspace/github_cpp_makefile_star2_O1/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 0x2203d9(%rip), %rax    # 0x22b54a
leaq 0x2203d7(%rip), %rbx    # 0x22b54f
cmoveq %rax, %rbx
leaq 0x2203d1(%rip), %rax    # 0x22b554
leaq 0x2203cf(%rip), %rcx    # 0x22b559
cmoveq %rax, %rcx
movq %rcx, 0x48(%rsp)
testq %r13, %r13
cmovneq %r13, %rbx
leaq 0x220399(%rip), %rsi    # 0x22b53a
leaq 0x231256(%rip), %r13    # 0x23c3fe
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 0x27ee11(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x21f6aa(%rip), %rsi    # 0x22a883
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 0xb5778
addq $0x18, %rsp
leaq 0x280008(%rip), %rsi    # 0x28b230
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 0xb688e
addq $0x20, %rsp
movq %r13, %rdi
callq 0x2190
leaq 0x2202f5(%rip), %rsi    # 0x22b55e
movq %r14, %rdi
movq 0x20(%rsp), %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2050
movq %r14, %rdi
leaq 0x231179(%rip), %rsi    # 0x23c3fe
callq 0x2210
movq %rax, %r13
subq $0x8, %rsp
movq 0x30(%rsp), %rdi
leaq 0x27ff93(%rip), %rsi    # 0x28b230
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 0xb688e
addq $0x20, %rsp
movq %r13, %rdi
callq 0x2190
leaq 0x27f489(%rip), %r13    # 0x28a758
cmpl $0x0, 0x150(%r13)
je 0xb34b
leaq 0x220294(%rip), %rsi    # 0x22b574
movq %r14, %rdi
movq 0x20(%rsp), %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2050
leaq 0x231105(%rip), %rsi    # 0x23c3fe
movq %r14, %rdi
callq 0x2210
movq %rax, %r15
movl 0x150(%r13), %eax
leaq 0x27ff1e(%rip), %rdx    # 0x28b230
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 0xb7f72
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