// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movss %xmm1, 0x24(%rsp)
movss %xmm0, 0x10(%rsp)
movq %r9, %rbx
movq %r8, %r14
movq %rcx, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
movq %rsi, %r12
movq %rdi, %rbp
movb 0xc0(%rsp), %al
movb %al, 0xf(%rsp)
movb 0xb8(%rsp), %al
movb %al, 0xe(%rsp)
movq 0xb0(%rsp), %r13
movq 0x18(%rdi), %r15
movl 0x14(%rsi), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl $0x1, %esi
callq 0x2120
movq %rax, 0x28(%rsp)
movq %rbp, 0x40(%rsp)
movq %rbp, %rdi
movq %r15, %rsi
movq %r12, 0x18(%rsp)
movq %r12, %rdx
movq %r14, 0x50(%rsp)
movq %r14, %rcx
movq %rbx, 0x30(%rsp)
movq %rbx, %r8
movq %r13, 0x48(%rsp)
movq %r13, %r9
callq 0xd4320
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl 0x14(%r15), %r12d
andq $0x7fffffff, %r12       # imm = 0x7FFFFFFF
je 0xd5825
xorl %r14d, %r14d
movl $0x0, 0x14(%rsp)
movq %r12, 0x38(%rsp)
movq 0x20(%r15), %rax
cmpl $0x0, (%rax,%r14,8)
js 0xd580e
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
leaq (%r14,%r14,4), %rcx
cmpl $0x0, 0xc(%rax,%rcx,8)
je 0xd580e
leaq (%r14,%r14), %r13
movq 0x28(%r15), %rdx
movq %r14, %rsi
shlq $0x4, %rsi
movq (%rdx,%rsi), %rdi
movq %rdi, %r8
andq %rbx, %r8
je 0xd55cc
movq 0x8(%r15), %rsi
shrq $0x20, %rdi
leaq (%rdi,%rdi,2), %rdi
leaq (%rsi,%rdi,8), %rdi
addq $0xc, %rdi
shlq $0x3, %r8
leaq (%r8,%r8,2), %r8
xorl %r9d, %r9d
xorl %r10d, %r10d
movl (%rdi,%r9), %r11d
notl %r11d
shrl $0x1f, %r11d
addl %r11d, %r10d
addq $0x18, %r9
cmpq %r9, %r8
jne 0xd5566
testl %r10d, %r10d
je 0xd55cc
movq 0x8(%rdx,%r13,8), %rdx
movq %rdx, %rdi
andq %rbx, %rdi
je 0xd55cc
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rsi,%rdx,8), %rdx
addq $0xc, %rdx
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
movl (%rdx,%rdi), %r9d
notl %r9d
shrl $0x1f, %r9d
addl %r9d, %r8d
addq $0x18, %rdi
cmpq %rdi, %rsi
jne 0xd55ac
testl %r8d, %r8d
jne 0xd580e
movq %r13, 0x70(%rsp)
leaq (%rax,%rcx,8), %rax
movl 0x10(%rax), %edx
testq %rdx, %rdx
movq %rax, 0x68(%rsp)
je 0xd564e
movq 0x18(%rax), %rdi
movq 0x18(%rsp), %rax
movq 0x20(%rax), %r8
leaq 0x1c0c3a(%rip), %rax    # 0x296230
movq 0x28(%rax), %r9
xorl %r10d, %r10d
xorl %esi, %esi
xorl %ecx, %ecx
xorl %eax, %eax
movq (%rdi,%r10,8), %rbx
shrq $0x21, %rbx
xorl %r11d, %r11d
cmpb $0x2, 0x4(%r8,%rbx,8)
sete %bpl
movzbl (%r9,%rbx), %ebx
testl %ebx, %ebx
je 0xd563e
cmpl $0x5, %ebx
je 0xd563e
xorl %r13d, %r13d
xorl %r12d, %r12d
cmpb 0xf(%rsp), %bl
setne %r13b
sete %r12b
addl %r12d, %eax
addl %r13d, %ecx
movb %bpl, %r11b
addl %r11d, %esi
incq %r10
cmpq %r10, %rdx
jne 0xd5603
jmp 0xd5654
xorl %eax, %eax
xorl %ecx, %ecx
xorl %esi, %esi
cmpb $0x0, 0xe(%rsp)
jne 0xd566e
cmpl %edx, %esi
jne 0xd566e
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x38(%rsp), %r12
jmp 0xd580e
cmpb $0x0, 0xe(%rsp)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x38(%rsp), %r12
movq 0x70(%rsp), %r13
movq 0x68(%rsp), %rbp
je 0xd57ac
movl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2ss %rdx, %xmm0
addl %ecx, %eax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
mulss 0x24(%rsp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0xd580e
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %r9
callq 0xcffc4
testb %al, %al
jne 0xd580e
movl $0x0, 0x10(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, (%rbp)
movq 0x18(%rbp), %rdi
callq 0x2220
movq $0x0, 0x18(%rbp)
movq 0x20(%r15), %rax
orl $0x80000000, (%rax,%r14,8) # imm = 0x80000000
movb $0x1, %al
xorl %ecx, %ecx
orq %r13, %rcx
movq 0x28(%r15), %rdx
movq (%rdx,%rcx,8), %rsi
movq %rsi, %rdx
andq %rbx, %rdx
je 0xd5794
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
shlq $0x3, %rsi
addq 0x8(%r15), %rsi
xorl %edi, %edi
leaq (%rdi,%rdi,2), %r8
orb $-0x80, 0xf(%rsi,%r8,8)
movl 0x8(%rsi,%r8,8), %r8d
xorq $0x1, %r8
movq 0x28(%r15), %r9
movq (%r9,%r8,8), %r9
movq %r9, %r8
andq %rbx, %r8
je 0xd578c
movq 0x8(%r15), %r10
shrq $0x20, %r9
shlq $0x3, %r8
leaq (%r8,%r8,2), %r8
leaq (%r9,%r9,2), %r9
leaq (%r10,%r9,8), %r9
addq $0xc, %r9
xorl %r10d, %r10d
movl -0x4(%r9,%r10), %r11d
xorl %ecx, %r11d
cmpl $0x1, %r11d
jne 0xd5783
orb $-0x80, 0x3(%r9,%r10)
addq $0x18, %r10
cmpq %r10, %r8
jne 0xd576f
incq %rdi
cmpq %rdx, %rdi
jne 0xd572d
movl $0x1, %ecx
testb $0x1, %al
movl $0x0, %eax
jne 0xd5708
incl 0x14(%rsp)
jmp 0xd580e
movl %ecx, %esi
cmpl $0x64, %edx
jb 0xd57d4
xorps %xmm0, %xmm0
cvtsi2ss %rsi, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %rdx, %xmm1
mulss 0x10(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0xd568d
jmp 0xd580e
xorps %xmm0, %xmm0
cvtsi2sd %rsi, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %edx, %xmm1
mulss 0x10(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
cmpl $0x32, %edx
jb 0xd57fc
mulsd 0x15bdf6(%rip), %xmm1   # 0x2315f0
jmp 0xd5804
mulsd 0x15bdcc(%rip), %xmm1   # 0x2315d0
ucomisd %xmm0, %xmm1
jbe 0xd568d
incq %r14
cmpq %r12, %r14
jne 0xd54fe
cmpl $0x0, 0x14(%rsp)
jne 0xd54dd
movq 0x40(%rsp), %rdi
movq %r15, %rsi
movq 0x18(%rsp), %rdx
movq 0x50(%rsp), %rcx
movq 0x30(%rsp), %r8
movq 0x48(%rsp), %r9
callq 0xd4320
movq %r15, %rdi
callq 0xa0a7d
movq 0x28(%rsp), %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220