// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movb %r9b, %al
movq 0x30(%rbp), %r9
movl 0x28(%rbp), %r9d
movl 0x20(%rbp), %r9d
movq 0x18(%rbp), %r9
movq 0x10(%rbp), %r9
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movb %al, -0x41(%rbp)
movq -0x40(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0x64, %rdi
callq 0x2270
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, 0x30(%rbp)
je 0x1244e8
movq 0x30(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x124513
movzbl -0x41(%rbp), %eax
cmpl $0x1, %eax
jne 0x1244fe
leaq 0x263e2d(%rip), %rax    # 0x388325
movq %rax, -0x78(%rbp)
jmp 0x12450b
leaq 0x263e25(%rip), %rax    # 0x38832a
movq %rax, -0x78(%rbp)
jmp 0x12450b
movq -0x78(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rdx
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rcx
leaq 0x263def(%rip), %rsi    # 0x388315
movb $0x0, %al
callq 0x2050
movq -0x50(%rbp), %rdi
leaq 0x274e9a(%rip), %rsi    # 0x3993d2
callq 0x2200
movq %rax, -0x58(%rbp)
movq 0x29fa98(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x50(%rbp), %rdx
leaq 0x262f4b(%rip), %rsi    # 0x3874a1
movb $0x0, %al
callq 0x22a0
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq 0x10(%rbp), %rcx
movq -0x30(%rbp), %r8
movl 0x20(%rbp), %r9d
movl 0x28(%rbp), %eax
xorl %r10d, %r10d
movl %eax, (%rsp)
movq $0x0, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
callq 0xed140
movq -0x20(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x90(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
movq 0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
movzbl -0x41(%rbp), %eax
cmpl $0x1, %eax
jne 0x1245e1
leaq 0x263d57(%rip), %rax    # 0x38832f
movq %rax, -0xa8(%rbp)
jmp 0x1245f1
leaq 0x263d4c(%rip), %rax    # 0x388334
movq %rax, -0xa8(%rbp)
jmp 0x1245f1
movq -0x80(%rbp), %r8
movq -0x88(%rbp), %rcx
movq -0x90(%rbp), %rdx
movq -0x98(%rbp), %rsi
movq -0xa0(%rbp), %rdi
movq -0xa8(%rbp), %r9
movq -0x58(%rbp), %rax
movq %rax, (%rsp)
callq 0xefa60
movq -0x58(%rbp), %rdi
callq 0x21a0
movq -0x50(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0xb0(%rbp)
cmpq $0x0, 0x30(%rbp)
je 0x124658
movq 0x30(%rbp), %rax
movq %rax, -0xc0(%rbp)
jmp 0x12468f
movzbl -0x41(%rbp), %eax
cmpl $0x1, %eax
jne 0x124671
leaq 0x263cbd(%rip), %rax    # 0x388325
movq %rax, -0xc8(%rbp)
jmp 0x124681
leaq 0x263cb2(%rip), %rax    # 0x38832a
movq %rax, -0xc8(%rbp)
jmp 0x124681
movq -0xc8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xb0(%rbp), %rdx
movq -0xb8(%rbp), %rdi
movq -0xc0(%rbp), %rcx
leaq 0x263c8e(%rip), %rsi    # 0x388339
movb $0x0, %al
callq 0x2050
movq -0x50(%rbp), %rdi
leaq 0x274d15(%rip), %rsi    # 0x3993d2
callq 0x2200
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq 0x18(%rbp), %rax
movq %rax, -0xd0(%rbp)
movzbl -0x41(%rbp), %eax
cmpl $0x1, %eax
jne 0x124716
leaq 0x263c22(%rip), %rax    # 0x38832f
movq %rax, -0xf8(%rbp)
jmp 0x124726
leaq 0x263c17(%rip), %rax    # 0x388334
movq %rax, -0xf8(%rbp)
jmp 0x124726
movq -0xd0(%rbp), %r8
movq -0xd8(%rbp), %rcx
movq -0xe0(%rbp), %rdx
movq -0xe8(%rbp), %rsi
movq -0xf0(%rbp), %rdi
movq -0xf8(%rbp), %r9
movq -0x58(%rbp), %rax
movq %rax, (%rsp)
callq 0xf1c10
movq -0x58(%rbp), %rdi
callq 0x21a0
leaq 0x2a008b(%rip), %rax    # 0x3c47f8
cmpl $0x0, 0x150(%rax)
je 0x124911
movq -0x50(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x100(%rbp)
cmpq $0x0, 0x30(%rbp)
je 0x1247a4
movq 0x30(%rbp), %rax
movq %rax, -0x110(%rbp)
jmp 0x1247db
movzbl -0x41(%rbp), %eax
cmpl $0x1, %eax
jne 0x1247bd
leaq 0x263b71(%rip), %rax    # 0x388325
movq %rax, -0x118(%rbp)
jmp 0x1247cd
leaq 0x263b66(%rip), %rax    # 0x38832a
movq %rax, -0x118(%rbp)
jmp 0x1247cd
movq -0x118(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x100(%rbp), %rdx
movq -0x108(%rbp), %rdi
movq -0x110(%rbp), %rcx
leaq 0x263b58(%rip), %rsi    # 0x38834f
movb $0x0, %al
callq 0x2050
movq -0x50(%rbp), %rdi
leaq 0x274bc9(%rip), %rsi    # 0x3993d2
callq 0x2200
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x140(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x130(%rbp)
movl 0x20(%rbp), %eax
movl %eax, -0x124(%rbp)
movl 0x28(%rbp), %eax
movl %eax, -0x120(%rbp)
leaq 0x29ff96(%rip), %rax    # 0x3c47f8
movl 0x150(%rax), %eax
movl %eax, -0x11c(%rbp)
movzbl -0x41(%rbp), %eax
cmpl $0x1, %eax
jne 0x124887
leaq 0x263ab1(%rip), %rax    # 0x38832f
movq %rax, -0x158(%rbp)
jmp 0x124897
leaq 0x263aa6(%rip), %rax    # 0x388334
movq %rax, -0x158(%rbp)
jmp 0x124897
movl -0x11c(%rbp), %r11d
movl -0x120(%rbp), %ebx
movl -0x124(%rbp), %r14d
movq -0x130(%rbp), %r9
movq -0x138(%rbp), %r8
movq -0x140(%rbp), %rcx
movq -0x148(%rbp), %rsi
movq -0x150(%rbp), %rdi
movq -0x158(%rbp), %r10
movq -0x58(%rbp), %rax
leaq 0x2a09f0(%rip), %rdx    # 0x3c52d0
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 -0x58(%rbp), %rdi
callq 0x21a0
movq -0x50(%rbp), %rdi
callq 0x2210
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax,%rax)