// File: /workspace/github_cpp_makefile_star2_O1/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, 0x2c(%rsp)
movss %xmm2, 0x5c(%rsp)
movss %xmm1, 0x58(%rsp)
movq %r9, %r12
movss %xmm0, 0x4(%rsp)
movl %edx, 0x8(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movq 0xf8(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x20(%rsp)
movl 0xe8(%rsp), %ebp
movl 0xe0(%rsp), %r11d
movl 0xd8(%rsp), %r10d
movq 0xd0(%rsp), %r9
leaq 0x1b4b04(%rip), %r13    # 0x28a758
xorl %eax, %eax
cmpl $0x0, 0x134(%r13)
movq 0xc8(%rsp), %rdx
movq %rdx, 0x68(%rsp)
setg %al
movq 0xc0(%rsp), %r15
movq (%rdi), %rdi
subq $0x8, %rsp
movq %rcx, 0x68(%rsp)
movq %rcx, %rdx
movq %r9, 0x18(%rsp)
movq %r9, %rcx
movq %r8, 0x40(%rsp)
movq %r12, %r9
pushq %rax
movq %r11, 0x58(%rsp)
pushq %r11
movq %r10, 0x48(%rsp)
pushq %r10
callq 0xd621b
addq $0x20, %rsp
movq %rax, 0x80(%rsp)
movq %rax, 0x18(%rsp)
movq 0xa8(%rax), %rax
testq %rax, %rax
je 0xd5cd6
movq 0x18(%rsp), %rcx
movq 0xa0(%rcx), %rcx
movq %rcx, 0x10(%rax)
cmpl $0xfffffc00, 0x13c(%r13) # imm = 0xFFFFFC00
jne 0xd5d24
cmpl $0x0, 0x148(%r13)
cvtsi2sdl 0x144(%r13), %xmm0
jne 0xd5cfe
divsd 0x153e6a(%rip), %xmm0   # 0x229b68
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
mulsd 0x153e7a(%rip), %xmm0   # 0x229b88
cvttsd2si %xmm0, %eax
movl %eax, 0x13c(%r13)
movl $0x7fffffff, 0x140(%r13) # imm = 0x7FFFFFFF
movl 0x13c(%r13), %ecx
movl 0x140(%r13), %r8d
movq 0x1b42a7(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
cmpl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq %r15, 0x70(%rsp)
movl %ebp, 0x54(%rsp)
jne 0xd5d65
leaq 0x15577c(%rip), %rsi    # 0x22b4d1
leaq 0x155762(%rip), %rdx    # 0x22b4be
xorl %eax, %eax
callq 0x22b0
jmp 0xd5d7a
leaq 0x155721(%rip), %rsi    # 0x22b48d
leaq 0x15574b(%rip), %rdx    # 0x22b4be
xorl %eax, %eax
callq 0x22b0
movq (%r14), %rsi
movq 0x18(%rsp), %r13
movq 0xa0(%r13), %r9
movq %rbx, %rdi
movq 0x38(%rsp), %r15
movq %r15, %rdx
movq 0x10(%rsp), %rbp
movq %rbp, %rcx
movq 0x40(%rsp), %r8
callq 0xc9692
movq (%r14), %rdi
subq $0x8, %rsp
movzbl 0x10(%rsp), %eax
movss 0x153dfe(%rip), %xmm0   # 0x229bb8
movq %rbx, %rsi
movq %r12, 0x80(%rsp)
movq %r12, %rdx
movq 0x68(%rsp), %rcx
movq %r15, %r8
movq %rbp, %r9
movq %rax, %r15
movss 0xc(%rsp), %xmm1
pushq %rax
pushq $0x0
pushq 0xa0(%r13)
callq 0xd407f
addq $0x20, %rsp
movq (%r14), %rdi
movq 0x18(%rdi), %rax
movl 0x14(%rax), %ecx
andq $0x7fffffff, %rcx       # imm = 0x7FFFFFFF
movl 0x54(%rsp), %r9d
je 0xd5e3d
movq 0x20(%rax), %rax
addq $0x4, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rcx
xorl %edx, %edx
cmpl $0x0, -0x4(%rax)
js 0xd5e30
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 0xd5e19
subq $0x70, %rsp
movq 0x90(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x60(%rsp)
movl %r9d, 0x58(%rsp)
movq 0xb8(%rsp), %rax
movl %eax, 0x50(%rsp)
movq 0xa0(%rsp), %rax
movl %eax, 0x48(%rsp)
movl %r15d, 0x40(%rsp)
xorl %eax, %eax
movl %eax, 0x38(%rsp)
movq %r15, 0x78(%rsp)
movq 0x80(%rsp), %rbp
movq %rbp, 0x8(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rsi
movq 0xe8(%rsp), %r13
movq %r13, %rdx
movq 0xd0(%rsp), %r15
movq %r15, %rcx
movq 0xe0(%rsp), %r9
movq 0xa8(%rsp), %r12
movq %r12, %r8
movss 0xc8(%rsp), %xmm0
movss 0xcc(%rsp), %xmm2
movss 0x9c(%rsp), %xmm3
movss 0x74(%rsp), %xmm4
callq 0xd1f6f
addq $0x68, %rsp
movss 0x153ccd(%rip), %xmm0   # 0x229bcc
movss 0x153cb9(%rip), %xmm1   # 0x229bc0
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %rbp, %r8
movq 0x10(%rsp), %r9
pushq $0x10
callq 0xd52c2
addq $0x10, %rsp
movq (%r14), %rdi
movq %rbx, %rsi
callq 0xd54fc
movq (%r14), %rdi
subq $0x8, %rsp
movss 0x153c78(%rip), %xmm0   # 0x229bb8
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %r12, %r8
movq %rbp, %r9
movss 0xc(%rsp), %xmm1
pushq 0x10(%rsp)
xorl %eax, %eax
pushq %rax
movq 0x30(%rsp), %rax
pushq 0xa0(%rax)
callq 0xd407f
addq $0x20, %rsp
movq (%r14), %rdi
movss 0x153c55(%rip), %xmm0   # 0x229bd0
movss 0x153c51(%rip), %xmm1   # 0x229bd4
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %rbp, %r9
movq 0x8(%rsp), %rbp
pushq $0x5
pushq %rbp
callq 0xd44a8
addq $0x10, %rsp
movq %r14, %rdi
movq %rbx, %rsi
movq 0x20(%rsp), %rdx
callq 0xba760
leaq 0x1b47a1(%rip), %rax    # 0x28a758
testb $0x1, 0x1(%rax)
jne 0xd6073
movq (%r14), %rdi
subq $0x8, %rsp
movl $0x1, %r10d
movq %rbx, %rsi
movq %r15, %rdx
movq %r13, %rcx
movq 0x18(%rsp), %r8
movq 0x38(%rsp), %r9
pushq 0x48(%rsp)
pushq $0x0
pushq %r10
xorl %eax, %eax
pushq %rax
movq 0x70(%rsp), %rbp
pushq %rbp
callq 0xd674d
addq $0x30, %rsp
movq %r14, %rdi
movq %rbx, %rsi
movq 0x20(%rsp), %r12
movq %r12, %rdx
callq 0xba760
movq (%r14), %rdi
subq $0x40, %rsp
movq 0x80(%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 0x48(%rsp), %rbp
movl $0xa, 0x8(%rsp)
movq %rbx, %rsi
movq %r15, %rdx
movq %r13, %rcx
movq 0x50(%rsp), %r8
movq 0x70(%rsp), %r9
callq 0xd7438
addq $0x40, %rsp
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0xba760
movq (%r14), %rdi
subq $0x8, %rsp
movss 0x153b46(%rip), %xmm0   # 0x229bc8
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq 0x40(%rsp), %r8
movq 0x18(%rsp), %r9
movss 0xc(%rsp), %xmm1
pushq %rbp
pushq $0x1
movq 0x30(%rsp), %rax
pushq 0xa0(%rax)
callq 0xd407f
addq $0x20, %rsp
movl 0x14(%rbx), %eax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
je 0xd60dd
movq 0x20(%rbx), %rcx
xorl %edx, %edx
cmpl $0x0, (%rcx,%rdx,8)
js 0xd60d5
cmpb $0x2, 0x4(%rcx,%rdx,8)
jne 0xd60d5
movb $0x0, 0x4(%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0xd60c3
movq %r14, %rdi
movq %rbx, %rsi
movq 0x20(%rsp), %rdx
callq 0xba760
subq $0x8, %rsp
movss 0x153ad3(%rip), %xmm0   # 0x229bcc
movss 0x153abf(%rip), %xmm1   # 0x229bc0
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq 0x18(%rsp), %r8
movl %ebp, %r9d
pushq $0x10
callq 0xd52c2
addq $0x10, %rsp
leaq 0x1b4631(%rip), %r12    # 0x28a758
cmpl $0x1, 0x134(%r12)
jne 0xd61bf
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 0x40(%rsp), %r8
movq 0x18(%rsp), %rbp
movq %rbp, %r9
movss 0x34(%rsp), %xmm1
pushq %r10
pushq %r10
pushq 0x30(%rsp)
pushq %r10
pushq $0x1
pushq 0x78(%rsp)
pushq 0x68(%rsp)
pushq %rax
pushq 0x68(%rsp)
callq 0x12fee
addq $0x48, %rsp
movss 0x153a34(%rip), %xmm0   # 0x229bcc
movss 0x153a20(%rip), %xmm1   # 0x229bc0
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %rbp, %r8
movq 0x10(%rsp), %r9
pushq $0x10
callq 0xd52c2
addq $0x10, %rsp
movl 0x124(%r12), %ecx
testl %ecx, %ecx
movq 0x20(%rsp), %r15
jle 0xd61e7
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0xd5a1b
movq (%r14), %rdi
callq 0xd4004
leaq 0x80(%rsp), %rdi
callq 0xc8943
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 0xba760