// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: update_unitig_graph(ma_ug_t*, asg_t*, ma_sub_t*, ma_hit_t_alloc*, ma_hit_t_alloc*, R_to_U*, unsigned char*, unsigned char, float, unsigned char, float)
void update_unitig_graph(ma_ug_t* ug, asg_t* read_g, ma_sub_t* coverage_cut, 
ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, R_to_U* ruIndex, uint8_t* is_r_het,
uint8_t is_final_check, float double_check_rate, uint8_t flag, float drop_rate)
{
    asg_t* nsg = ug->g;
    uint32_t v, n_vtx = nsg->n_seq, k, rId, flag_occ, non_flag_occ, hap_label_occ, n_reduce = 1;
    ma_utg_t *u;
    uint8_t* primary_flag = (uint8_t*)calloc(read_g->n_seq, sizeof(uint8_t));

    drop_semi_circle(ug, nsg, read_g, reverse_sources, ruIndex, is_r_het);

    while (n_reduce)
    {
        n_reduce = 0;
        n_vtx = nsg->n_seq;
        for (v = 0; v < n_vtx; ++v) 
        {
            if (nsg->seq[v].del) continue;
            u = &((ug)->u.a[v]);
            if(u->m == 0) continue;
            if((get_real_length(nsg, v<<1, NULL)!=0) 
                && (get_real_length(nsg, ((v<<1)^1), NULL)!=0)) continue;///check tig
            flag_occ = non_flag_occ = hap_label_occ = 0;
            for (k = 0; k < u->n; k++)
            {
                rId = u->a[k]>>33;
                if(read_g->seq[rId].c == HAP_LABLE) hap_label_occ++;
                if(R_INF.trio_flag[rId] == AMBIGU) continue;
                if(R_INF.trio_flag[rId] == DROP) continue;
                if(R_INF.trio_flag[rId] == flag) flag_occ++;
                if(R_INF.trio_flag[rId] != flag) non_flag_occ++;
            }

            ///if(is_final_check && v == 0) fprintf(stderr, "flag: %u, flag_occ: %u, non_flag_occ: %u\n", flag, flag_occ, non_flag_occ);
            
            if(is_final_check == 0 && hap_label_occ == u->n) continue;
            ///if(is_double_check && non_flag_occ < u->n*DOUBLE_CHECK_THRES) continue;
            ///if(is_double_check && non_flag_occ < u->n*double_check_rate) continue;
 
            if(is_final_check)
            {
                /**if(non_flag_occ < u->n*double_check_rate) continues**/;
            }
            else
            {
                if(u->n >= 100)
                {
                    if(non_flag_occ < u->n*double_check_rate)
                    {
                        continue;
                    }
                }
                else if(u->n >= 50)
                {
                    if(non_flag_occ < u->n*double_check_rate*0.5)
                    {
                        continue;
                    }
                }
                else
                {
                    if(non_flag_occ < u->n*double_check_rate*0.25)
                    {
                        continue;
                    }
                }
            }
            
            if(non_flag_occ > ((non_flag_occ+flag_occ)*drop_rate))
            {
                
                if(if_primary_unitig(u, read_g, coverage_cut, sources, ruIndex, primary_flag))
                {
                    continue;
                }

                if(u->m != 0)
                {
                    u->circ = u->end = u->len = u->m = u->n = u->start = 0;
                    free(u->a);
                    u->a = NULL;
                }
                asg_seq_del(nsg, v);
                n_reduce++;
            }
        }
    }

    drop_semi_circle(ug, nsg, read_g, reverse_sources, ruIndex, is_r_het);
    asg_cleanup(nsg);
    free(primary_flag);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movss %xmm1, 0x1c(%rsp)
movss %xmm0, 0x14(%rsp)
movq %r9, %rbx
movq %r8, %r15
movq %rcx, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq %rsi, %r12
movq %rdi, %rbp
movb 0xa0(%rsp), %al
movb %al, 0x7(%rsp)
movb 0x98(%rsp), %al
movb %al, 0x6(%rsp)
movq 0x90(%rsp), %r13
movq 0x18(%rdi), %r14
movl 0x14(%rsi), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
pushq $0x1
popq %rsi
callq 0x2120
movq %rax, 0x20(%rsp)
movq %rbp, 0x30(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, 0x40(%rsp)
movq %r15, %rcx
movq %rbx, 0x28(%rsp)
movq %rbx, %r8
movq %r13, 0x38(%rsp)
movq %r13, %r9
callq 0x97ac1
pushq $0x1
popq %rax
testl %eax, %eax
je 0x98bbb
movl 0x14(%r14), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %r13d, %r13d
movl $0x0, 0x18(%rsp)
movq %rdx, 0x8(%rsp)
cmpq %rdx, %r13
je 0x98bb2
movq 0x20(%r14), %rax
cmpl $0x0, (%rax,%r13,8)
js 0x98baa
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rbx
imulq $0x28, %r13, %r15
cmpl $0x0, 0xc(%rbx,%r15)
je 0x98baa
leaq (,%r13,2), %rbp
movq %r14, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0xc2e7a
testl %eax, %eax
je 0x98a59
orl $0x1, %ebp
movq %r14, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0xc2e7a
testl %eax, %eax
jne 0x98ba5
addq %r15, %rbx
movl 0x10(%rbx), %edx
leaq 0x1bb7ca(%rip), %rax    # 0x254230
movq 0x28(%rax), %rdi
xorl %r8d, %r8d
xorl %ecx, %ecx
xorl %eax, %eax
xorl %esi, %esi
cmpq %r8, %rdx
je 0x98ac8
movq 0x18(%rbx), %r9
movq (%r9,%r8,8), %r11
shrq $0x21, %r11
movq 0x20(%r12), %r10
xorl %r9d, %r9d
cmpb $0x2, 0x4(%r10,%r11,8)
sete %r10b
movzbl (%rdi,%r11), %r11d
testl %r11d, %r11d
je 0x98abd
cmpl $0x5, %r11d
je 0x98abd
xorl %ebp, %ebp
xorl %r15d, %r15d
cmpb 0x7(%rsp), %r11b
setne %bpl
sete %r15b
addl %r15d, %ecx
addl %ebp, %eax
movb %r10b, %r9b
addl %r9d, %esi
incq %r8
jmp 0x98a73
cmpb $0x0, 0x6(%rsp)
jne 0x98ad7
cmpl %edx, %esi
je 0x98ba5
movl %eax, %esi
cmpb $0x0, 0x6(%rsp)
je 0x98b51
cvtsi2ss %rsi, %xmm0
addl %ecx, %eax
cvtsi2ss %rax, %xmm1
mulss 0x1c(%rsp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x98ba5
movq %rbx, %rdi
movq %r12, %rsi
movq 0x48(%rsp), %rdx
movq 0x50(%rsp), %rcx
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %r9
callq 0x945a4
testb %al, %al
jne 0x98ba5
cmpl $0x0, 0xc(%rbx)
je 0x98b40
andl $0x0, 0x10(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq 0x18(%rbx), %rdi
callq 0x2220
andq $0x0, 0x18(%rbx)
movq %r14, %rdi
movl %r13d, %esi
callq 0x6f8da
incl 0x18(%rsp)
jmp 0x98ba5
cmpl $0x64, %edx
jb 0x98b71
cvtsi2ss %rsi, %xmm0
cvtsi2ss %rdx, %xmm1
mulss 0x14(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x98ae0
jmp 0x98ba5
cvtsi2sd %rsi, %xmm0
cvtsi2ss %edx, %xmm1
mulss 0x14(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
cmpl $0x32, %edx
jb 0x98b93
mulsd 0x14a9b7(%rip), %xmm1   # 0x1e3548
jmp 0x98b9b
mulsd 0x14a985(%rip), %xmm1   # 0x1e3520
ucomisd %xmm0, %xmm1
jbe 0x98ae0
movq 0x8(%rsp), %rdx
incq %r13
jmp 0x989f9
movl 0x18(%rsp), %eax
jmp 0x989d7
movq 0x30(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
movq 0x40(%rsp), %rcx
movq 0x28(%rsp), %r8
movq 0x38(%rsp), %r9
callq 0x97ac1
movq %r14, %rdi
callq 0x694eb
movq 0x20(%rsp), %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220