// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %ecx, %r12d
movq %rdx, %rbx
movq %rsi, %rbp
movq %rdi, %r14
movq %rdx, %rdi
movq %rdx, 0x20(%rsp)
callq 0x2090
leaq 0x64(%rax), %rdi
callq 0x2280
movq %rax, %r13
cmpl $0x1, %r12d
leaq 0x1fe5f2(%rip), %rax    # 0x22b54a
leaq 0x1fe5f0(%rip), %rcx    # 0x22b54f
cmoveq %rax, %rcx
movq %rcx, 0x18(%rsp)
leaq 0x1fe5cb(%rip), %rsi    # 0x22b53a
leaq 0x20f488(%rip), %r15    # 0x23c3fe
leaq 0x1fe5d7(%rip), %rax    # 0x22b554
leaq 0x1fe5d5(%rip), %rdx    # 0x22b559
cmoveq %rax, %rdx
movq %rdx, 0x10(%rsp)
movq %r13, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
movq %r13, %rdi
movq %r15, %rsi
callq 0x2210
movq %rax, 0x8(%rsp)
movq 0x238(%rbp), %rdi
callq 0xc815c
leaq 0x28(%rsp), %rcx
movq %rax, (%rcx)
movq %rcx, %rdi
leaq 0x30(%rsp), %rax
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movq %rax, %r15
movq 0x20(%rbp), %rsi
movq (%r14), %r9
movq 0x8(%r14), %rcx
movq 0x10(%r14), %r8
movss 0x20(%r14), %xmm1
movss 0x38(%r14), %xmm2
movss 0x3c(%r14), %xmm3
movl 0x40(%r14), %eax
movl 0x44(%r14), %r10d
movl 0x50(%r14), %r11d
movss 0x1fcbb3(%rip), %xmm0   # 0x229bbc
movq %rdi, %rbx
movl %r12d, %edx
pushq 0x60(%r14)
pushq %r15
pushq %r11
pushq %r10
pushq %rax
pushq 0x30(%r14)
pushq 0x28(%r14)
pushq 0x18(%r14)
callq 0xd5bde
addq $0x40, %rsp
movq 0x25cfaa(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x1fd843(%rip), %rsi    # 0x22a883
movq %r13, %rdx
xorl %eax, %eax
callq 0x22b0
movq (%rbx), %rdi
movq 0x20(%rbp), %rsi
movq (%r14), %rdx
movq 0x8(%r14), %rcx
movl 0x40(%r14), %r9d
movl 0x44(%r14), %eax
subq $0x8, %rsp
movq %r15, %r8
pushq $0x1
pushq $0x0
pushq %rax
callq 0xb5778
addq $0x20, %rsp
movq (%rbx), %rdi
movq %rbx, %r15
movq 0x20(%rbp), %rsi
movq (%r14), %rdx
movq 0x8(%r14), %rcx
movq 0x30(%r14), %r8
subq $0x8, %rsp
movq 0x18(%rsp), %rbx
movq %rbx, %r9
movq 0x10(%rsp), %r12
pushq %r12
callq 0xb6f6d
popq %rax
popq %rcx
movq %r12, %rdi
callq 0x2190
leaq 0x1fe4ab(%rip), %rsi    # 0x22b55e
movq %r13, %rdi
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x2050
movq %r13, %rdi
leaq 0x20f32d(%rip), %rsi    # 0x23c3fe
callq 0x2210
movq %rax, %r12
movq (%r15), %rdi
movq 0x20(%rbp), %rsi
movq (%r14), %rdx
movq 0x8(%r14), %rcx
movq 0x30(%r14), %r8
subq $0x8, %rsp
movq %rbx, %r9
pushq %rax
callq 0xb7f45
popq %rax
popq %rcx
movq %r12, %rdi
callq 0x2190
movq %r13, %rdi
callq 0x2220
movq (%r15), %rdi
callq 0xa0004
leaq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x2220
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq