// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: adjust_utg_by_trio(ma_ug_t**, asg_t*, unsigned char, float, ma_hit_t_alloc*, ma_hit_t_alloc*, ma_sub_t*, long long, float, long long, R_to_U*, float, float, int, int, int, kvec_asg_arc_t_warp*, bub_label_t*)
void adjust_utg_by_trio(ma_ug_t **ug, asg_t* read_g, uint8_t flag, float drop_rate,
ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, ma_sub_t* coverage_cut, 
long long tipsLen, float tip_drop_ratio, long long stops_threshold, 
R_to_U* ruIndex, float chimeric_rate, float drop_ratio, int max_hang, int min_ovlp, int gap_fuzz,
kvec_asg_arc_t_warp* new_rtg_edges, bub_label_t* b_mask_t)
{
    asg_t* nsg = (*ug)->g;
    uint32_t v, n_vtx = nsg->n_seq;    
    hap_cov_t *cov = init_hap_cov_t(*ug, read_g, sources, ruIndex, reverse_sources, 
                                                    coverage_cut, max_hang, min_ovlp, asm_opt.purge_level_trio>0?1:0);
    if(cov->t_ch) cov->t_ch->ir_het = cov->is_r_het;

    if(asm_opt.recover_atg_cov_min == -1024)
    {
        asm_opt.recover_atg_cov_max = (asm_opt.hom_global_coverage_set?
            (asm_opt.hom_global_coverage):(((double)asm_opt.hom_global_coverage)/((double)HOM_PEAK_RATE)));         
        asm_opt.recover_atg_cov_min = asm_opt.recover_atg_cov_max * 0.85;
        asm_opt.recover_atg_cov_max = INT32_MAX;
    }
    if(asm_opt.recover_atg_cov_max != INT32_MAX)
    {
        fprintf(stderr, "[M::%s] primary contig coverage range: [%d, %d]\n", 
        __func__, asm_opt.recover_atg_cov_min, asm_opt.recover_atg_cov_max);
    }
    else
    {
        fprintf(stderr, "[M::%s] primary contig coverage range: [%d, infinity]\n", 
        __func__, asm_opt.recover_atg_cov_min);
    }

    // fprintf(stderr, "[M::%s] 0\n", __func__); dbg_asys_gfa((*ug)->g);
    adjust_utg_advance(read_g, (*ug), reverse_sources, ruIndex, b_mask_t, cov->is_r_het);
    // fprintf(stderr, "[M::%s] 1\n", __func__); dbg_asys_gfa((*ug)->g);

    ///primary_flag = get_utg_attributes(*ug, read_g, coverage_cut, sources, ruIndex);
    update_unitig_graph((*ug), read_g, coverage_cut, sources, reverse_sources, ruIndex, cov->is_r_het, 0, 
    DOUBLE_CHECK_THRES, flag, drop_rate);
    // fprintf(stderr, "[M::%s] 2\n", __func__); dbg_asys_gfa((*ug)->g);

    nsg = (*ug)->g;
    n_vtx = nsg->n_seq;
    for (v = 0; v < n_vtx; ++v) 
    {
        if(nsg->seq[v].del) continue;
        nsg->seq[v].c = PRIMARY_LABLE;
        EvaluateLen((*ug)->u, v) = (*ug)->u.a[v].n;
    }
    // fprintf(stderr, "[M::%s] 3\n", __func__);
    clean_trio_untig_graph(*ug, read_g, coverage_cut, sources, reverse_sources, tipsLen, 
    tip_drop_ratio, stops_threshold, ruIndex, NULL, NULL, 0, 0, 0, chimeric_rate, 0, 0, drop_ratio, flag, drop_rate, max_hang, min_ovlp, gap_fuzz, cov, new_rtg_edges);
    // fprintf(stderr, "[M::%s] 4\n", __func__);
    
    ///delete_useless_nodes(ug);
    delete_useless_trio_nodes(ug, read_g, coverage_cut, sources, ruIndex, flag, 0.8, 0.15, 16);
    // fprintf(stderr, "[M::%s] 5\n", __func__);

    update_hap_label(*ug, read_g);
    // fprintf(stderr, "[M::%s] 6\n", __func__);

    update_unitig_graph((*ug), read_g, coverage_cut, sources, reverse_sources, ruIndex, cov->is_r_het, 0, 
    DOUBLE_CHECK_THRES, flag, drop_rate);
    // fprintf(stderr, "[M::%s] 7\n", __func__);

    force_trio_clean((*ug), read_g, coverage_cut, sources, reverse_sources, ruIndex, flag, 0.55, 0.01, 5);
    // fprintf(stderr, "[M::%s] 8\n", __func__);
    ///if(flag == MOTHER) print_debug_gfa(read_g, *ug, coverage_cut, "debug_trio_1", sources, ruIndex, asm_opt.max_hang_Len, asm_opt.min_overlap_Len);

    renew_utg(ug, read_g, new_rtg_edges);
    // fprintf(stderr, "[M::%s] 9\n", __func__);

    if (!(asm_opt.flag & HA_F_BAN_POST_JOIN))
    {
        rescue_missing_overlaps_aggressive(*ug, read_g, sources, coverage_cut, ruIndex, max_hang,
        min_ovlp, 0, 1, NULL, b_mask_t);
        // fprintf(stderr, "[M::%s] 10\n", __func__);

        renew_utg(ug, read_g, new_rtg_edges);
        // fprintf(stderr, "[M::%s] 11\n", __func__);

        rescue_contained_reads_aggressive(*ug, read_g, sources, coverage_cut, ruIndex, max_hang, 
        min_ovlp, 10, 0, 1, NULL, NULL, b_mask_t);
        // fprintf(stderr, "[M::%s] 12\n", __func__);

        renew_utg(ug, read_g, new_rtg_edges);
        // fprintf(stderr, "[M::%s] 13\n", __func__);
    }

    ///if(flag == MOTHER) print_untig_by_read(*ug, "m64043_200627_000137/124716590/ccs", 2789716, NULL, NULL, "beg");
    
    
    update_unitig_graph((*ug), read_g, coverage_cut, sources, reverse_sources, ruIndex, cov->is_r_het, 1, 
    FINAL_DOUBLE_CHECK_THRES, flag, drop_rate);
    // fprintf(stderr, "[M::%s] 14\n", __func__);

    update_hap_label(NULL, read_g);
    // fprintf(stderr, "[M::%s] 15\n", __func__);

    renew_utg(ug, read_g, new_rtg_edges);
    // fprintf(stderr, "[M::%s] 16\n", __func__);

    ///delete_useless_nodes(ug);
    delete_useless_trio_nodes(ug, read_g, coverage_cut, sources, ruIndex, flag, 0.8, 0.15, 16);
    // fprintf(stderr, "[M::%s] 17\n", __func__);


    if(asm_opt.purge_level_trio == 1)
    {
		purge_dups(*ug, read_g, coverage_cut, sources, reverse_sources, ruIndex, new_rtg_edges, 
        asm_opt.purge_simi_thres, asm_opt.purge_overlap_len, max_hang, min_ovlp, drop_ratio, 1, 0, 
        cov, 0, 0);
		///delete_useless_nodes(ug);
        delete_useless_trio_nodes(ug, read_g, coverage_cut, sources, ruIndex, flag, 0.8, 0.15, 16);
	}
    // fprintf(stderr, "[M::%s] 18\n", __func__);

    if(asm_opt.max_contig_tip > 0) {
        discard_small_ctg(ug, read_g, new_rtg_edges, asm_opt.max_contig_tip, 1, 0);
    }    

    // fprintf(stderr, "[M::%s] 19\n", __func__);
    set_drop_trio_flag(*ug);
    destory_hap_cov_t(&cov);
    // fprintf(stderr, "[M::%s] 20\n", __func__);
    // purge_dump(*ug);
    renew_utg(ug, read_g, new_rtg_edges);
    // fprintf(stderr, "[M::%s] 21\n", __func__);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movss %xmm3, 0x34(%rsp)
movss %xmm2, 0x64(%rsp)
movss %xmm1, 0x60(%rsp)
movq %r9, %r12
movss %xmm0, 0xc(%rsp)
movl %edx, 0x10(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movq 0x108(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x100(%rsp), %r15
movl 0xf8(%rsp), %ebp
movl 0xf0(%rsp), %r11d
movl 0xe8(%rsp), %r10d
movq 0xe0(%rsp), %r9
leaq 0x1be81f(%rip), %rdx    # 0x295758
xorl %eax, %eax
cmpl $0x0, 0x134(%rdx)
movq 0xd8(%rsp), %rdx
movq %rdx, 0x70(%rsp)
setg %al
movq 0xd0(%rsp), %r13
movq (%rdi), %rdi
subq $0x8, %rsp
movq %rcx, 0x70(%rsp)
movq %rcx, %rdx
movq %r9, 0x20(%rsp)
movq %r9, %rcx
movq %r8, 0x48(%rsp)
movq %r12, %r9
pushq %rax
movq %r11, 0x60(%rsp)
pushq %r11
movq %r10, 0x50(%rsp)
pushq %r10
callq 0xd74eb
addq $0x20, %rsp
movq %rax, 0x88(%rsp)
movq %rax, 0x20(%rsp)
movq 0xa8(%rax), %rax
testq %rax, %rax
je 0xd6fba
movq 0x20(%rsp), %rcx
movq 0xa0(%rcx), %rcx
movq %rcx, 0x10(%rax)
leaq 0x1be797(%rip), %rax    # 0x295758
movl 0x13c(%rax), %ecx
cmpl $0xfffffc00, %ecx       # imm = 0xFFFFFC00
movq %r15, 0x28(%rsp)
movq %r13, 0x78(%rsp)
movl %ebp, 0x5c(%rsp)
jne 0xd6ff2
leaq 0x94(%rsp), %r15
movq %r15, %rdi
callq 0x10ea0
movl (%r15), %ecx
jmp 0xd7002
movl 0x140(%rax), %r8d
cmpl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
jne 0xd7023
movq 0x1bdfd7(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x1606ae(%rip), %rsi    # 0x2376c1
leaq 0x160694(%rip), %rdx    # 0x2376ae
xorl %eax, %eax
callq 0x22b0
jmp 0xd7042
movq 0x1bdfb6(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x160649(%rip), %rsi    # 0x23767d
leaq 0x160673(%rip), %rdx    # 0x2376ae
xorl %eax, %eax
callq 0x22b0
movq (%r14), %rsi
movq 0x20(%rsp), %r13
movq 0xa0(%r13), %r9
movq %rbx, %rdi
movq 0x40(%rsp), %r15
movq %r15, %rdx
movq 0x18(%rsp), %rbp
movq %rbp, %rcx
movq 0x48(%rsp), %r8
callq 0xca960
movq (%r14), %rdi
subq $0x8, %rsp
movzbl 0x18(%rsp), %eax
movss 0x15ed2e(%rip), %xmm0   # 0x235db0
movq %rbx, %rsi
movq %r12, 0x88(%rsp)
movq %r12, %rdx
movq 0x70(%rsp), %rcx
movq %r15, %r8
movq %rbp, %r9
movq %rax, %r15
movss 0x14(%rsp), %xmm1
pushq %rax
pushq $0x0
pushq 0xa0(%r13)
callq 0xd543e
addq $0x20, %rsp
movq (%r14), %rdi
movq 0x18(%rdi), %rax
movl 0x14(%rax), %ecx
andq $0x7fffffff, %rcx       # imm = 0x7FFFFFFF
movl 0x5c(%rsp), %r9d
je 0xd7105
movq 0x20(%rax), %rax
addq $0x4, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rcx
xorl %edx, %edx
cmpl $0x0, -0x4(%rax)
js 0xd70f8
movb $0x0, (%rax)
movq 0x10(%rdi), %rsi
movl 0x10(%rsi,%rdx), %r8d
movl %r8d, 0x4(%rsi,%rdx)
addq $0x8, %rax
addq $0x28, %rdx
cmpq %rdx, %rcx
jne 0xd70e1
subq $0x70, %rsp
movq 0x98(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x60(%rsp)
movl %r9d, 0x58(%rsp)
movq 0xc0(%rsp), %rax
movl %eax, 0x50(%rsp)
movq 0xa8(%rsp), %rax
movl %eax, 0x48(%rsp)
movl %r15d, 0x40(%rsp)
xorl %eax, %eax
movl %eax, 0x38(%rsp)
movq %r15, 0x80(%rsp)
movq 0x88(%rsp), %rbp
movq %rbp, 0x8(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rsi
movq 0xf0(%rsp), %r13
movq %r13, %rdx
movq 0xd8(%rsp), %r15
movq %r15, %rcx
movq 0xe8(%rsp), %r9
movq 0xb0(%rsp), %r12
movq %r12, %r8
movss 0xd0(%rsp), %xmm0
movss 0xd4(%rsp), %xmm2
movss 0xa4(%rsp), %xmm3
movss 0x7c(%rsp), %xmm4
callq 0xd33d8
addq $0x68, %rsp
movss 0x15ebfa(%rip), %xmm0   # 0x235dc4
movss 0x15ebe6(%rip), %xmm1   # 0x235db8
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %rbp, %r8
movq 0x18(%rsp), %r9
pushq $0x10
callq 0xd6604
addq $0x10, %rsp
movq (%r14), %rdi
movq %rbx, %rsi
callq 0xd6842
movq (%r14), %rdi
subq $0x8, %rsp
movss 0x15eba5(%rip), %xmm0   # 0x235db0
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %r12, %r8
movq %rbp, %r9
movss 0x14(%rsp), %xmm1
pushq 0x18(%rsp)
xorl %eax, %eax
pushq %rax
movq 0x38(%rsp), %rax
pushq 0xa0(%rax)
callq 0xd543e
addq $0x20, %rsp
movq (%r14), %rdi
movss 0x15eb82(%rip), %xmm0   # 0x235dc8
movss 0x15eb7e(%rip), %xmm1   # 0x235dcc
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %rbp, %r9
movq 0x10(%rsp), %rbp
pushq $0x5
pushq %rbp
callq 0xd5866
addq $0x10, %rsp
movq %r14, %rdi
movq %rbx, %rsi
movq 0x28(%rsp), %rdx
callq 0xbb7a4
leaq 0x1be4d6(%rip), %r12    # 0x295758
testb $0x1, 0x1(%r12)
jne 0xd7347
movq (%r14), %rdi
subq $0x8, %rsp
movl $0x1, %r10d
movq %rbx, %rsi
movq %r15, %rdx
movq %r13, %rcx
movq 0x20(%rsp), %r8
movq 0x40(%rsp), %r9
pushq 0x50(%rsp)
pushq $0x0
pushq %r10
xorl %eax, %eax
pushq %rax
movq 0x78(%rsp), %rbp
pushq %rbp
callq 0xd7993
addq $0x30, %rsp
movq %r14, %rdi
movq %rbx, %rsi
movq 0x28(%rsp), %r12
movq %r12, %rdx
callq 0xbb7a4
movq (%r14), %rdi
subq $0x40, %rsp
movq 0x88(%rsp), %rax
movq %rax, 0x30(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rsp)
movl $0x1, %eax
movl %eax, 0x18(%rsp)
xorl %eax, %eax
movl %eax, 0x10(%rsp)
movl %ebp, (%rsp)
movq 0x50(%rsp), %rbp
movl $0xa, 0x8(%rsp)
movq %rbx, %rsi
movq %r15, %rdx
movq %r13, %rcx
movq 0x58(%rsp), %r8
movq 0x78(%rsp), %r9
callq 0xd8787
addq $0x40, %rsp
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
leaq 0x1be416(%rip), %r12    # 0x295758
callq 0xbb7a4
movq (%r14), %rdi
subq $0x8, %rsp
movss 0x15ea6a(%rip), %xmm0   # 0x235dc0
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq 0x48(%rsp), %r8
movq 0x20(%rsp), %r9
movss 0x14(%rsp), %xmm1
pushq %rbp
pushq $0x1
movq 0x38(%rsp), %rax
pushq 0xa0(%rax)
callq 0xd543e
addq $0x20, %rsp
movl 0x14(%rbx), %eax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
je 0xd73b1
movq 0x20(%rbx), %rcx
xorl %edx, %edx
cmpl $0x0, (%rcx,%rdx,8)
js 0xd73a9
cmpb $0x2, 0x4(%rcx,%rdx,8)
jne 0xd73a9
movb $0x0, 0x4(%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0xd7397
movq %r14, %rdi
movq %rbx, %rsi
movq 0x28(%rsp), %rdx
callq 0xbb7a4
subq $0x8, %rsp
movss 0x15e9f7(%rip), %xmm0   # 0x235dc4
movss 0x15e9e3(%rip), %xmm1   # 0x235db8
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq 0x20(%rsp), %r8
movl %ebp, %r9d
pushq $0x10
callq 0xd6604
addq $0x10, %rsp
cmpl $0x1, 0x134(%r12)
jne 0xd748f
movq (%r14), %rdi
movss 0x16c(%r12), %xmm0
movl 0x138(%r12), %eax
subq $0x8, %rsp
xorl %r10d, %r10d
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq 0x48(%rsp), %r8
movq 0x20(%rsp), %rbp
movq %rbp, %r9
movss 0x3c(%rsp), %xmm1
pushq %r10
pushq %r10
pushq 0x38(%rsp)
pushq %r10
pushq $0x1
pushq 0x80(%rsp)
pushq 0x70(%rsp)
pushq %rax
pushq 0x70(%rsp)
callq 0x12943
addq $0x48, %rsp
movss 0x15e95c(%rip), %xmm0   # 0x235dc4
movss 0x15e948(%rip), %xmm1   # 0x235db8
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %rbp, %r8
movq 0x18(%rsp), %r9
pushq $0x10
callq 0xd6604
addq $0x10, %rsp
movl 0x124(%r12), %ecx
testl %ecx, %ecx
movq 0x28(%rsp), %r15
jle 0xd74b7
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0xd6d0f
movq (%r14), %rdi
callq 0xd53b8
leaq 0x88(%rsp), %rdi
callq 0xc9bdb
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xbb7a4