// File: /workspace/github_cpp_makefile_star2_O2/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 $0x88, %rsp
movss %xmm3, 0x34(%rsp)
movss %xmm2, 0x20(%rsp)
movss %xmm1, 0x64(%rsp)
movq %r9, %r12
movq %rcx, %r9
movss %xmm0, 0x8(%rsp)
movl %edx, (%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movq 0xf8(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x18(%rsp)
movl 0xe8(%rsp), %eax
movl %eax, 0x60(%rsp)
movl 0xe0(%rsp), %r11d
movl 0xd8(%rsp), %r10d
movq 0xd0(%rsp), %rcx
leaq 0x1b9a86(%rip), %rdx    # 0x253758
xorl %eax, %eax
cmpl $0x0, 0x134(%rdx)
movq 0xc8(%rsp), %rdx
movq %rdx, 0x70(%rsp)
setg %al
movq 0xc0(%rsp), %rdx
movq %rdx, 0x78(%rsp)
movq (%rdi), %rdi
subq $0x8, %rsp
movq %r9, 0x48(%rsp)
movq %r9, %rdx
movq %rcx, 0x18(%rsp)
movq %r8, 0x30(%rsp)
movq %r12, %r9
pushq %rax
movq %r11, 0x60(%rsp)
pushq %r11
movq %r10, 0x50(%rsp)
pushq %r10
callq 0x9a2a3
addq $0x20, %rsp
movq %rax, %r13
movq %rax, 0x80(%rsp)
movq 0xa8(%rax), %rax
testq %rax, %rax
je 0x99d4e
movq 0xa0(%r13), %rcx
movq %rcx, 0x10(%rax)
leaq 0x1b9a03(%rip), %rax    # 0x253758
movl 0x13c(%rax), %ecx
cmpl $0xfffffc00, %ecx       # imm = 0xFFFFFC00
jne 0x99da2
cmpl $0x0, 0x148(%rax)
cvtsi2sdl 0x144(%rax), %xmm0
jne 0x99d7c
divsd 0x14dee4(%rip), %xmm0   # 0x1e7c60
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
mulsd 0x14def4(%rip), %xmm0   # 0x1e7c80
cvttsd2si %xmm0, %ecx
movl %ecx, 0x13c(%rax)
movl $0x7fffffff, 0x140(%rax) # imm = 0x7FFFFFFF
jmp 0x99db2
movl 0x140(%rax), %r8d
cmpl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
jne 0x99dd3
movq 0x1b9227(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0x14f7fe(%rip), %rsi    # 0x1e95c1
leaq 0x14f7e4(%rip), %rdx    # 0x1e95ae
xorl %eax, %eax
callq 0x22b0
jmp 0x99df2
movq 0x1b9206(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0x14f799(%rip), %rsi    # 0x1e957d
leaq 0x14f7c3(%rip), %rdx    # 0x1e95ae
xorl %eax, %eax
callq 0x22b0
movq (%r14), %rsi
movq 0xa0(%r13), %r9
movq %rbx, %rdi
movq 0x28(%rsp), %r15
movq %r15, %rdx
movq 0x10(%rsp), %rbp
movq %rbp, %rcx
movq 0x68(%rsp), %r8
callq 0x8e9c7
movq (%r14), %rdi
subq $0x8, %rsp
movzbl 0x8(%rsp), %eax
movq %r15, %r8
movq %rax, %r15
movss 0x14de7d(%rip), %xmm0   # 0x1e7cb0
movq %rbx, 0x60(%rsp)
movq %rbx, %rsi
movq %r12, %rdx
movq 0x48(%rsp), %rbx
movq %rbx, %rcx
movq %rbp, %r9
movss 0x10(%rsp), %xmm1
pushq %rax
pushq $0x0
movq %r13, 0x60(%rsp)
pushq 0xa0(%r13)
callq 0x98941
addq $0x20, %rsp
movq (%r14), %rdi
movq 0x18(%rdi), %rax
movl 0x14(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
pushq $0x2
popq %rdx
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x99ea8
movq 0x20(%rax), %r8
cmpl $0x0, (%r8,%rsi,8)
js 0x99e9f
movb $0x0, 0x4(%r8,%rsi,8)
movq 0x10(%rdi), %r8
movl (%r8,%rdx,8), %r9d
movl %r9d, -0xc(%r8,%rdx,8)
incq %rsi
addq $0x5, %rdx
jmp 0x99e7c
subq $0x70, %rsp
movq 0x88(%rsp), %rax
movq %rax, 0x68(%rsp)
movq %r15, 0x70(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x60(%rsp)
movl 0xd0(%rsp), %eax
movl %eax, 0x58(%rsp)
movq 0xc0(%rsp), %rax
movl %eax, 0x50(%rsp)
movq 0xa8(%rsp), %rax
movl %eax, 0x48(%rsp)
movq 0x70(%rsp), %rax
movl %eax, 0x40(%rsp)
andl $0x0, 0x38(%rsp)
movq 0x80(%rsp), %rbp
movq %rbp, 0x8(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, (%rsp)
movq %r14, %r13
movq 0xc8(%rsp), %r14
movq %r14, %rsi
movq %r12, %rdx
movq %rbx, %rcx
movq 0x98(%rsp), %r15
movq %r15, %r8
movq 0xe8(%rsp), %r9
movss 0xd4(%rsp), %xmm0
movss 0x90(%rsp), %xmm2
movss 0xa4(%rsp), %xmm3
movss 0x78(%rsp), %xmm4
callq 0x96c8c
addq $0x68, %rsp
movss 0x14dd56(%rip), %xmm0   # 0x1e7cc4
movss 0x14dd42(%rip), %xmm1   # 0x1e7cb8
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %rbx, %rcx
movq %rbp, %r8
movq 0x8(%rsp), %r9
pushq $0x10
callq 0x99698
popq %rax
popq %rcx
movq (%r13), %rdi
movq %r14, %rsi
callq 0x997e1
movq (%r13), %rdi
subq $0x8, %rsp
movss 0x14dd01(%rip), %xmm0   # 0x1e7cb0
movq %r14, %rsi
movq %r12, %rdx
movq %rbx, %rcx
movq %r15, %r8
movq %rbp, %r9
movss 0x10(%rsp), %xmm1
pushq 0x8(%rsp)
pushq $0x0
movq 0x60(%rsp), %rax
pushq 0xa0(%rax)
movq 0x20(%rsp), %r15
callq 0x98941
addq $0x20, %rsp
movq (%r13), %rdi
movss 0x14dcd9(%rip), %xmm0   # 0x1e7cc8
movss 0x14dcd5(%rip), %xmm1   # 0x1e7ccc
movq %r14, %rsi
movq %r12, 0x20(%rsp)
movq %r12, %rdx
movq %rbx, %rcx
movq %rbp, %r9
movq 0x28(%rsp), %rbx
pushq $0x5
pushq %r15
callq 0x98bfa
popq %rax
popq %rcx
movq %r13, %rdi
movq %r14, %rsi
movq 0x18(%rsp), %rdx
callq 0x80328
leaq 0x1b9729(%rip), %rax    # 0x253758
testb $0x1, 0x1(%rax)
jne 0x9a0ee
pushq $0x1
popq %rbx
movq (%r13), %rdi
subq $0x8, %rsp
movq %r14, %rsi
movq 0x48(%rsp), %rdx
movq 0x28(%rsp), %rcx
movq 0x18(%rsp), %r8
movq 0x40(%rsp), %r9
movq 0x70(%rsp), %rbp
pushq %rbp
pushq $0x0
pushq %rbx
pushq $0x0
movq 0x78(%rsp), %r15
pushq %r15
callq 0x9a6fd
addq $0x30, %rsp
movq %r13, %rdi
movq %r14, %rsi
movq 0x18(%rsp), %r12
movq %r12, %rdx
callq 0x80328
movq (%r13), %rdi
subq $0x40, %rsp
movq %rbp, 0x30(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rsp)
movl %ebx, 0x18(%rsp)
andl $0x0, 0x10(%rsp)
movl %r15d, (%rsp)
movq 0x40(%rsp), %r15
movq 0x68(%rsp), %rbx
movl $0xa, 0x8(%rsp)
movq %r14, %rsi
movq 0x80(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq 0x50(%rsp), %r8
movq 0x78(%rsp), %r9
callq 0x9b10e
addq $0x40, %rsp
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x80328
movq (%r13), %rdi
subq $0x8, %rsp
movss 0x14dbc2(%rip), %xmm0   # 0x1e7cc0
movq %r14, %rsi
movq %r15, %rax
movq 0x28(%rsp), %r15
movq %r15, %rdx
movq 0x48(%rsp), %r12
movq %r12, %rcx
movq %rbx, %r8
movq 0x18(%rsp), %rbp
movq %rbp, %r9
movss 0x10(%rsp), %xmm1
pushq %rax
pushq $0x1
movq %rax, %rbx
movq 0x60(%rsp), %rax
pushq 0xa0(%rax)
callq 0x98941
addq $0x20, %rsp
xorl %edi, %edi
movq %r14, %rsi
callq 0x997e1
movq %r13, %rdi
movq %r14, %rsi
movq 0x18(%rsp), %rdx
callq 0x80328
subq $0x8, %rsp
movss 0x14db5f(%rip), %xmm0   # 0x1e7cc4
movss 0x14db4b(%rip), %xmm1   # 0x1e7cb8
movq %r13, 0x10(%rsp)
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
movq %rbp, %r8
movl %ebx, %r9d
pushq $0x10
callq 0x99698
popq %rax
popq %rcx
leaq 0x1b95c4(%rip), %rax    # 0x253758
cmpl $0x1, 0x134(%rax)
jne 0x9a241
movq %r15, %r13
movq 0x8(%rsp), %r15
movq (%r15), %rdi
movss 0x16c(%rax), %xmm0
leaq 0x1b959d(%rip), %rax    # 0x253758
movl 0x138(%rax), %eax
subq $0x8, %rsp
movq 0x60(%rsp), %r14
movq %r14, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq 0x30(%rsp), %r8
movq 0x18(%rsp), %rbp
movq %rbp, %r9
movss 0x3c(%rsp), %xmm1
pushq $0x0
pushq $0x0
pushq 0x60(%rsp)
pushq $0x0
pushq $0x1
pushq 0x80(%rsp)
pushq 0x70(%rsp)
pushq %rax
pushq 0x60(%rsp)
callq 0xd3406
addq $0x48, %rsp
movss 0x14dab1(%rip), %xmm0   # 0x1e7cc4
movss 0x14da9d(%rip), %xmm1   # 0x1e7cb8
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %rbp, %r8
movq 0x8(%rsp), %r9
pushq $0x10
callq 0x99698
leaq 0x1b951b(%rip), %rax    # 0x253758
addq $0x10, %rsp
movl 0x124(%rax), %ecx
testl %ecx, %ecx
movq 0x18(%rsp), %r15
movq 0x58(%rsp), %rbx
movq 0x8(%rsp), %r14
jle 0x9a26f
pushq $0x1
popq %r8
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
xorl %r9d, %r9d
callq 0x99b8b
movq (%r14), %rdi
callq 0x988cd
leaq 0x80(%rsp), %rdi
callq 0x8d243
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x80328