// File: /workspace/github_cpp_makefile_star2_O1/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 0xd2f0d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl 0x14(%r15), %r12d
andq $0x7fffffff, %r12       # imm = 0x7FFFFFFF
je 0xd4467
xorl %r14d, %r14d
movl $0x0, 0x14(%rsp)
movq %r12, 0x38(%rsp)
movq 0x20(%r15), %rax
cmpl $0x0, (%rax,%r14,8)
js 0xd4450
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
leaq (%r14,%r14,4), %rcx
cmpl $0x0, 0xc(%rax,%rcx,8)
je 0xd4450
leaq (%r14,%r14), %r11
movq 0x28(%r15), %rdx
movq %r14, %rsi
shlq $0x4, %rsi
movq (%rdx,%rsi), %rsi
movq %rsi, %rdi
andq %rbx, %rdi
je 0xd4211
movq 0x8(%r15), %r8
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%r8,%rsi,8), %rsi
addq $0xc, %rsi
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
movl (%rsi,%r8), %r10d
notl %r10d
shrl $0x1f, %r10d
addl %r10d, %r9d
addq $0x18, %r8
cmpq %r8, %rdi
jne 0xd41a7
testl %r9d, %r9d
je 0xd4211
movq 0x8(%rdx,%r11,8), %rdx
movq %rdx, %rsi
andq %rbx, %rsi
je 0xd4211
movq 0x8(%r15), %rdi
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rdi,%rdx,8), %rdx
addq $0xc, %rdx
shlq $0x3, %rsi
leaq (%rsi,%rsi,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 0xd41f1
testl %r8d, %r8d
jne 0xd4450
movq %r11, 0x70(%rsp)
leaq (%rax,%rcx,8), %rax
movl 0x10(%rax), %edx
testq %rdx, %rdx
movq %rax, 0x68(%rsp)
je 0xd4293
movq 0x18(%rax), %rdi
movq 0x18(%rsp), %rax
movq 0x20(%rax), %r8
leaq 0x1b6ff5(%rip), %rax    # 0x28b230
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 0xd4283
cmpl $0x5, %ebx
je 0xd4283
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 0xd4248
jmp 0xd4299
xorl %eax, %eax
xorl %ecx, %ecx
xorl %esi, %esi
cmpb $0x0, 0xe(%rsp)
jne 0xd42b3
cmpl %edx, %esi
jne 0xd42b3
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x38(%rsp), %r12
jmp 0xd4450
cmpb $0x0, 0xe(%rsp)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x38(%rsp), %r12
movq 0x70(%rsp), %r13
movq 0x68(%rsp), %rbp
je 0xd43ee
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 0xd4450
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %r9
callq 0xced5a
testb %al, %al
jne 0xd4450
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%rbp)
movl $0x0, (%rbp)
movq 0x18(%rbp), %rdi
callq 0x2220
movq $0x0, 0x18(%rbp)
movq 0x20(%r15), %rax
orl $0x80000000, (%rax,%r14,8) # imm = 0x80000000
xorl %eax, %eax
leaq (%rax,%r13), %rcx
movq 0x28(%r15), %rdx
movq (%rdx,%rcx,8), %rsi
movq %rsi, %rdx
andq %rbx, %rdx
je 0xd43d8
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 0xd43d0
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 0xd43c7
orb $-0x80, 0x3(%r9,%r10)
addq $0x18, %r10
cmpq %r10, %r8
jne 0xd43b3
incq %rdi
cmpq %rdx, %rdi
jne 0xd4371
leaq 0x1(%rax), %rcx
testq %rax, %rax
movq %rcx, %rax
je 0xd434b
incl 0x14(%rsp)
jmp 0xd4450
movl %ecx, %esi
cmpl $0x64, %edx
jb 0xd4416
xorps %xmm0, %xmm0
cvtsi2ss %rsi, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %rdx, %xmm1
mulss 0x10(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0xd42d2
jmp 0xd4450
xorps %xmm0, %xmm0
cvtsi2sd %rsi, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %edx, %xmm1
mulss 0x10(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
cmpl $0x32, %edx
jb 0xd443e
mulsd 0x1510b4(%rip), %xmm1   # 0x2254f0
jmp 0xd4446
mulsd 0x15108a(%rip), %xmm1   # 0x2254d0
ucomisd %xmm0, %xmm1
jbe 0xd42d2
incq %r14
cmpq %r12, %r14
jne 0xd413f
cmpl $0x0, 0x14(%rsp)
jne 0xd411e
movq 0x40(%rsp), %rdi
movq %r15, %rsi
movq 0x18(%rsp), %rdx
movq 0x50(%rsp), %rcx
movq 0x30(%rsp), %r8
movq 0x48(%rsp), %r9
callq 0xd2f0d
movq %r15, %rdi
callq 0xa02fa
movq 0x28(%rsp), %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220