// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: recover_chain_nodes(buf_t*, ma_ug_t*, unsigned int, float, float, unsigned int)
void recover_chain_nodes(buf_t *in, ma_ug_t *ug, uint32_t flag, float flag_rate, float used_rate, uint32_t min_occ)
{
    ma_utg_t *u = NULL; uint32_t flag_occ, non_flag_occ, drop_occ, rid;
    uint32_t tot_flag_occ, tot_non_flag_occ, tot_drop_occ, tot_occ, i, k, z;
    tot_flag_occ = tot_non_flag_occ = tot_drop_occ = tot_occ = 0;

    for (i = 0; i < in->b.n; i++) {
        u = &(ug->u.a[in->b.a[i]>>1]);
        flag_occ = non_flag_occ = drop_occ = 0; 
        for (k = 0; k < u->n; k++) {
            rid = u->a[k]>>33;
            if(R_INF.trio_flag[rid] == AMBIGU) continue;
            else if(R_INF.trio_flag[rid] == DROP) drop_occ++;
            else if(R_INF.trio_flag[rid] == flag) flag_occ++;
            else if(R_INF.trio_flag[rid] != flag) non_flag_occ++;
        }

        if(is_useful_node(flag_occ, non_flag_occ, drop_occ, u->n, flag_rate, used_rate, min_occ)) {
            ug->g->seq[in->b.a[i]>>1].c = PRIMARY_LABLE;
        }
        tot_flag_occ += flag_occ;
        tot_non_flag_occ += non_flag_occ;
        tot_drop_occ += drop_occ;
        tot_occ += u->n;
        if(is_useful_node(tot_flag_occ, tot_non_flag_occ, tot_drop_occ, tot_occ, flag_rate, used_rate, min_occ)) {
            for (z = 0; z <= i; z++) {
                if(ug->g->seq[in->b.a[z]>>1].c == ALTER_LABLE) {
                    u = &(ug->u.a[in->b.a[z]>>1]);
                    flag_occ = non_flag_occ = drop_occ = 0; 
                    for (k = 0; k < u->n; k++) {
                        rid = u->a[k]>>33;
                        if(R_INF.trio_flag[rid] == AMBIGU) continue;
                        else if(R_INF.trio_flag[rid] == DROP) drop_occ++;
                        else if(R_INF.trio_flag[rid] == flag) flag_occ++;
                        else if(R_INF.trio_flag[rid] != flag) non_flag_occ++;
                    }
                    if(is_useful_node(flag_occ, non_flag_occ, drop_occ, u->n, flag_rate, used_rate, 0/**min_occ**/)) {
                        ug->g->seq[in->b.a[z]>>1].c = PRIMARY_LABLE;
                    }
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %ecx, -0x3c(%rsp)
movq %rsi, -0x38(%rsp)
movq 0x38(%rdi), %rax
movq %rax, -0x10(%rsp)
testq %rax, %rax
je 0xd63b4
movq -0x38(%rsp), %rax
movq 0x10(%rax), %r8
movq 0x48(%rdi), %rax
movq %rax, -0x18(%rsp)
leaq 0x1c0113(%rip), %rax    # 0x296230
movq 0x28(%rax), %r10
xorl %ecx, %ecx
movl $0x1, %ebx
movl $0x0, -0x40(%rsp)
movl $0x0, -0x44(%rsp)
movq $0x0, -0x20(%rsp)
movq $0x0, -0x28(%rsp)
movq %r8, -0x30(%rsp)
cmpl $0x1, %ebx
movl %ebx, %r13d
adcl $0x0, %r13d
movq -0x18(%rsp), %rax
movq %rcx, -0x8(%rsp)
movl (%rax,%rcx,4), %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rdi
movl 0x10(%r8,%rdi,8), %r9d
movl $0x0, %esi
movl $0x0, %ebp
movl $0x0, %eax
testq %r9, %r9
je 0xd6232
leaq (%r8,%rdi,8), %rax
movq 0x18(%rax), %r14
xorl %r8d, %r8d
xorl %esi, %esi
xorl %ebp, %ebp
xorl %eax, %eax
movq (%r14,%r8,8), %rdi
shrq $0x21, %rdi
movzbl (%r10,%rdi), %edi
testl %edi, %edi
je 0xd61be
cmpl $0x5, %edi
jne 0xd61b4
incl %esi
jmp 0xd61be
cmpl %edx, %edi
jne 0xd61bc
incl %eax
jmp 0xd61be
incl %ebp
incq %r8
cmpq %r8, %r9
jne 0xd619a
testl %eax, %eax
sete %dil
cmpl -0x3c(%rsp), %eax
setb %r8b
orb %dil, %r8b
je 0xd61e0
movq -0x30(%rsp), %r8
jmp 0xd6232
movl %eax, %edi
xorps %xmm2, %xmm2
cvtsi2ss %rdi, %xmm2
leal (%rax,%rbp), %edi
addl %esi, %edi
xorps %xmm3, %xmm3
cvtsi2ss %rdi, %xmm3
mulss %xmm0, %xmm3
ucomiss %xmm3, %xmm2
movq -0x30(%rsp), %r8
jb 0xd6232
movl %esi, %edi
xorps %xmm2, %xmm2
cvtsi2ss %rdi, %xmm2
xorps %xmm3, %xmm3
cvtsi2ss %r9, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm2, %xmm3
jb 0xd6232
movq -0x38(%rsp), %rdi
movq 0x18(%rdi), %rdi
movq 0x20(%rdi), %rdi
movb $0x0, 0x4(%rdi,%rcx,8)
addl %esi, -0x44(%rsp)
movq -0x20(%rsp), %rcx
addl %ebp, %ecx
movq %rcx, -0x20(%rsp)
addl %r9d, -0x40(%rsp)
movq -0x28(%rsp), %rcx
addl %eax, %ecx
sete %al
movq %rcx, -0x28(%rsp)
cmpl -0x3c(%rsp), %ecx
setb %cl
orb %al, %cl
jne 0xd639d
movq -0x28(%rsp), %rcx
movl %ecx, %eax
xorps %xmm2, %xmm2
cvtsi2ss %rax, %xmm2
movq -0x20(%rsp), %rax
addl %ecx, %eax
addl -0x44(%rsp), %eax
xorps %xmm3, %xmm3
cvtsi2ss %rax, %xmm3
mulss %xmm0, %xmm3
ucomiss %xmm3, %xmm2
jb 0xd639d
movl -0x44(%rsp), %eax
xorps %xmm2, %xmm2
cvtsi2ss %rax, %xmm2
movl -0x40(%rsp), %eax
xorps %xmm3, %xmm3
cvtsi2ss %rax, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm2, %xmm3
jb 0xd639d
movq -0x38(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
leaq 0x1bff63(%rip), %rcx    # 0x296230
movq 0x28(%rcx), %r9
movl %r13d, %esi
xorl %r13d, %r13d
movq -0x18(%rsp), %rcx
movl (%rcx,%r13,4), %ecx
shrl %ecx
cmpb $0x1, 0x4(%rax,%rcx,8)
jne 0xd6391
leaq (%rcx,%rcx,4), %rdi
movl 0x10(%r8,%rdi,8), %ebp
testq %rbp, %rbp
je 0xd6391
leaq (%r8,%rdi,8), %rdi
movq 0x18(%rdi), %r8
xorl %edi, %edi
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %r12d, %r12d
movq (%r8,%rdi,8), %r11
shrq $0x21, %r11
movzbl (%r9,%r11), %r11d
testl %r11d, %r11d
je 0xd633c
cmpl $0x5, %r11d
jne 0xd632f
incl %r15d
jmp 0xd633c
cmpl %edx, %r11d
jne 0xd6339
incl %r12d
jmp 0xd633c
incl %r14d
incq %rdi
cmpq %rdi, %rbp
jne 0xd6312
testl %r12d, %r12d
movq -0x30(%rsp), %r8
je 0xd6391
movl %r12d, %edi
xorps %xmm2, %xmm2
cvtsi2ss %rdi, %xmm2
addl %r12d, %r14d
addl %r15d, %r14d
xorps %xmm3, %xmm3
cvtsi2ss %r14, %xmm3
mulss %xmm0, %xmm3
ucomiss %xmm3, %xmm2
jb 0xd6391
movl %r15d, %edi
xorps %xmm2, %xmm2
cvtsi2ss %rdi, %xmm2
xorps %xmm3, %xmm3
cvtsi2ss %rbp, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm2, %xmm3
jb 0xd6391
movb $0x0, 0x4(%rax,%rcx,8)
incq %r13
cmpq %rsi, %r13
jne 0xd62d7
movq -0x8(%rsp), %rcx
incq %rcx
movl %ecx, %eax
incl %ebx
cmpq %rax, -0x10(%rsp)
ja 0xd614f
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq