// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: output_trio_unitig_graph_ul(ug_opt_t*, ul_resolve_t*, char*, unsigned char)
ma_ug_t* output_trio_unitig_graph_ul(ug_opt_t *uopt, ul_resolve_t *uidx, char* ou, uint8_t flag)
{
    char* gfa_name; MALLOC(gfa_name, strlen(ou)+100);
    sprintf(gfa_name, "%s.%s.p_ctg.gfa", ou, (flag==FATHER?"hap1":"hap2"));
    FILE* output_file = fopen(gfa_name, "w");

    ma_ug_t *ug = copy_untig_graph(uidx->uovl.hybrid_ug); 
    kvec_asg_arc_t_warp ne; kv_init(ne.a);

    adjust_utg_by_trio(&ug, uidx->sg, flag, TRIO_THRES, uopt->sources, uopt->reverse_sources, 
    uopt->coverage_cut, uopt->tipsLen, uopt->tip_drop_ratio, uopt->stops_threshold, uopt->ruIndex, 
    uopt->chimeric_rate, uopt->drop_ratio, uopt->max_hang, uopt->min_ovlp, uopt->gap_fuzz, &ne, uopt->b_mask_t);    

    // if(asm_opt.b_low_cov > 0) {
    //     break_ug_contig(&ug, uidx->sg, &R_INF, uopt->coverage_cut, uopt->sources, uopt->ruIndex, &ne, 
    //     uopt->max_hang, uopt->min_ovlp, &asm_opt.b_low_cov, NULL, asm_opt.m_rate);
    // }

    // if(asm_opt.b_high_cov > 0)
    // {
    //     break_ug_contig(&ug, uidx->sg, &R_INF, uopt->coverage_cut, uopt->sources, uopt->ruIndex, &ne, 
    //     uopt->max_hang, uopt->min_ovlp, NULL, &asm_opt.b_high_cov, asm_opt.m_rate);
    // }

    fprintf(stderr, "Writing %s to disk... \n", gfa_name);
    ma_ug_seq(ug, uidx->sg, uopt->coverage_cut, uopt->sources, &ne, uopt->max_hang, uopt->min_ovlp, 0, 1);
    
    ma_ug_print(ug, uidx->sg, uopt->coverage_cut, uopt->sources, uopt->ruIndex, (flag==FATHER?"h1tg":"h2tg"), output_file);
    fclose(output_file);

    sprintf(gfa_name, "%s.%s.p_ctg.noseq.gfa", ou, (flag==FATHER?"hap1":"hap2"));
    output_file = fopen(gfa_name, "w");
    ma_ug_print_simple(ug, uidx->sg, uopt->coverage_cut, uopt->sources, uopt->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, &new_rtg_edges, 
    //     max_hang, min_ovlp, asm_opt.bed_inconsist_rate, (flag==FATHER?"h1tg":"h2tg"), output_file, NULL);
    //     fclose(output_file);
    // }

    free(gfa_name);
    ma_ug_destroy(ug);
    kv_destroy(ne.a);
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movb %cl, %al
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movb %al, -0x41(%rbp)
movq -0x40(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0x64, %rdi
shlq $0x0, %rdi
callq 0x2270
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x88(%rbp)
movzbl -0x41(%rbp), %eax
cmpl $0x1, %eax
jne 0x3754a1
leaq 0x12e8d(%rip), %rax     # 0x388325
movq %rax, -0x98(%rbp)
jmp 0x3754b1
leaq 0x12e82(%rip), %rax     # 0x38832a
movq %rax, -0x98(%rbp)
jmp 0x3754b1
movq -0x88(%rbp), %rdx
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %rcx
leaq 0x12e48(%rip), %rsi     # 0x388315
movb $0x0, %al
callq 0x2050
movq -0x50(%rbp), %rdi
leaq 0x23ef3(%rip), %rsi     # 0x3993d2
callq 0x2200
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movq 0x238(%rax), %rdi
callq 0x10ba70
movq %rax, -0x60(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rsi
movb -0x41(%rbp), %dl
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %r8
movq -0x30(%rbp), %rax
movq (%rax), %r9
movq -0x30(%rbp), %rax
movq 0x18(%rax), %r13
movq -0x30(%rbp), %rax
movss 0x20(%rax), %xmm1
movq -0x30(%rbp), %rax
movq 0x28(%rax), %r12
movq -0x30(%rbp), %rax
movq 0x30(%rax), %r15
movq -0x30(%rbp), %rax
movss 0x38(%rax), %xmm2
movq -0x30(%rbp), %rax
movss 0x3c(%rax), %xmm3
movq -0x30(%rbp), %rax
movl 0x40(%rax), %r14d
movq -0x30(%rbp), %rax
movl 0x44(%rax), %ebx
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rax
movl %eax, %r11d
movq -0x30(%rbp), %rax
movq 0x60(%rax), %rax
leaq -0x60(%rbp), %rdi
movss 0x11305(%rip), %xmm0    # 0x38689c
leaq -0x80(%rbp), %r10
movzbl %dl, %edx
movq %r13, (%rsp)
movq %r12, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movl %r14d, 0x18(%rsp)
movl %ebx, 0x20(%rsp)
movl %r11d, 0x28(%rsp)
movq %r10, 0x30(%rsp)
movq %rax, 0x38(%rsp)
callq 0x120950
movq 0x4ea10(%rip), %rax     # 0x3c3fe0
movq (%rax), %rdi
movq -0x50(%rbp), %rdx
leaq 0x11ec3(%rip), %rsi     # 0x3874a1
movb $0x0, %al
callq 0x22a0
movq -0x60(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x30(%rbp), %rax
movq (%rax), %rdx
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x30(%rbp), %rax
movl 0x40(%rax), %r9d
movq -0x30(%rbp), %rax
movl 0x44(%rax), %eax
leaq -0x80(%rbp), %r8
xorl %r10d, %r10d
movl %eax, (%rsp)
movq $0x0, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
callq 0xed140
movq -0x60(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0xa0(%rbp)
movzbl -0x41(%rbp), %eax
cmpl $0x1, %eax
jne 0x37568e
leaq 0x12caa(%rip), %rax     # 0x38832f
movq %rax, -0xc8(%rbp)
jmp 0x37569e
leaq 0x12c9f(%rip), %rax     # 0x388334
movq %rax, -0xc8(%rbp)
jmp 0x37569e
movq -0xa0(%rbp), %r8
movq -0xa8(%rbp), %rcx
movq -0xb0(%rbp), %rdx
movq -0xb8(%rbp), %rsi
movq -0xc0(%rbp), %rdi
movq -0xc8(%rbp), %r9
movq -0x58(%rbp), %rax
movq %rax, (%rsp)
callq 0xefa60
movq -0x58(%rbp), %rdi
callq 0x21a0
movq -0x50(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0xd0(%rbp)
movzbl -0x41(%rbp), %eax
cmpl $0x1, %eax
jne 0x37570d
leaq 0x12c21(%rip), %rax     # 0x388325
movq %rax, -0xe0(%rbp)
jmp 0x37571d
leaq 0x12c16(%rip), %rax     # 0x38832a
movq %rax, -0xe0(%rbp)
jmp 0x37571d
movq -0xd0(%rbp), %rdx
movq -0xd8(%rbp), %rdi
movq -0xe0(%rbp), %rcx
leaq 0x12c00(%rip), %rsi     # 0x388339
movb $0x0, %al
callq 0x2050
movq -0x50(%rbp), %rdi
leaq 0x23c87(%rip), %rsi     # 0x3993d2
callq 0x2200
movq %rax, -0x58(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x100(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xf8(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xf0(%rbp)
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0xe8(%rbp)
movzbl -0x41(%rbp), %eax
cmpl $0x1, %eax
jne 0x3757b3
leaq 0x12b85(%rip), %rax     # 0x38832f
movq %rax, -0x110(%rbp)
jmp 0x3757c3
leaq 0x12b7a(%rip), %rax     # 0x388334
movq %rax, -0x110(%rbp)
jmp 0x3757c3
movq -0xe8(%rbp), %r8
movq -0xf0(%rbp), %rcx
movq -0xf8(%rbp), %rdx
movq -0x100(%rbp), %rsi
movq -0x108(%rbp), %rdi
movq -0x110(%rbp), %r9
movq -0x58(%rbp), %rax
movq %rax, (%rsp)
callq 0xf1c10
movq -0x58(%rbp), %rdi
callq 0x21a0
movq -0x50(%rbp), %rdi
callq 0x2210
movq -0x60(%rbp), %rdi
callq 0xcd6f0
movq -0x70(%rbp), %rdi
callq 0x2210
xorl %eax, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)