// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rsi, -0x40(%rsp)
movq 0x38(%rdi), %rax
movq %rax, -0x10(%rsp)
testq %rax, %rax
je 0xd505d
movq -0x40(%rsp), %rax
movq 0x10(%rax), %r15
movq 0x48(%rdi), %rax
movq %rax, -0x18(%rsp)
leaq 0x1b647c(%rip), %rax    # 0x28b230
movq 0x28(%rax), %r10
xorl %esi, %esi
movl $0x1, %ebx
movl $0x0, -0x44(%rsp)
movl $0x0, -0x48(%rsp)
movq $0x0, -0x30(%rsp)
movq $0x0, -0x38(%rsp)
movl %ecx, -0x24(%rsp)
movq %r15, -0x20(%rsp)
cmpl $0x1, %ebx
movl %ebx, %r13d
adcl $0x0, %r13d
movq -0x18(%rsp), %rax
movq %rsi, -0x8(%rsp)
movl (%rax,%rsi,4), %esi
shrl %esi
leaq (%rsi,%rsi,4), %rdi
movl 0x10(%r15,%rdi,8), %eax
movl $0x0, %r9d
movl $0x0, %r11d
movl $0x0, %ebp
testq %rax, %rax
je 0xd4e63
leaq (%r15,%rdi,8), %rdi
movq 0x18(%rdi), %r14
xorl %r8d, %r8d
xorl %ebp, %ebp
xorl %r11d, %r11d
xorl %r9d, %r9d
movq (%r14,%r8,8), %rdi
shrq $0x21, %rdi
movzbl (%r10,%rdi), %edi
testl %edi, %edi
je 0xd4e5b
cmpl $0x5, %edi
jne 0xd4e4f
incl %ebp
jmp 0xd4e5b
cmpl %edx, %edi
jne 0xd4e58
incl %r9d
jmp 0xd4e5b
incl %r11d
incq %r8
cmpq %r8, %rax
jne 0xd4e35
testl %r9d, %r9d
sete %dil
cmpl %ecx, %r9d
setb %r8b
orb %dil, %r8b
jne 0xd4ec5
movl %r9d, %edi
xorps %xmm2, %xmm2
cvtsi2ss %rdi, %xmm2
leal (%r11,%r9), %edi
addl %ebp, %edi
xorps %xmm3, %xmm3
cvtsi2ss %rdi, %xmm3
mulss %xmm0, %xmm3
ucomiss %xmm3, %xmm2
jb 0xd4ec5
movl %ebp, %edi
xorps %xmm2, %xmm2
cvtsi2ss %rdi, %xmm2
xorps %xmm3, %xmm3
cvtsi2ss %rax, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm2, %xmm3
jb 0xd4ec5
movq -0x40(%rsp), %rdi
movq 0x18(%rdi), %rdi
movq 0x20(%rdi), %rdi
movb $0x0, 0x4(%rdi,%rsi,8)
movq -0x30(%rsp), %rsi
addl %r11d, %esi
movq %rsi, -0x30(%rsp)
addl %ebp, -0x48(%rsp)
addl %eax, -0x44(%rsp)
movq -0x38(%rsp), %rsi
addl %r9d, %esi
sete %al
movq %rsi, -0x38(%rsp)
cmpl %ecx, %esi
setb %cl
orb %al, %cl
jne 0xd503d
movq -0x38(%rsp), %rcx
movl %ecx, %eax
xorps %xmm2, %xmm2
cvtsi2ss %rax, %xmm2
movq -0x30(%rsp), %rax
addl %ecx, %eax
addl -0x48(%rsp), %eax
xorps %xmm3, %xmm3
cvtsi2ss %rax, %xmm3
mulss %xmm0, %xmm3
ucomiss %xmm3, %xmm2
jb 0xd503d
movl -0x48(%rsp), %eax
xorps %xmm2, %xmm2
cvtsi2ss %rax, %xmm2
movl -0x44(%rsp), %eax
xorps %xmm3, %xmm3
cvtsi2ss %rax, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm2, %xmm3
jb 0xd503d
movq -0x40(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %r9
leaq 0x1b62d1(%rip), %rax    # 0x28b230
movq 0x28(%rax), %rax
movl %r13d, %r13d
xorl %esi, %esi
movq -0x18(%rsp), %rcx
movl (%rcx,%rsi,4), %ebp
shrl %ebp
cmpb $0x1, 0x4(%r9,%rbp,8)
jne 0xd5031
leaq (,%rbp,4), %rdi
addq %rbp, %rdi
movq -0x20(%rsp), %r8
movl 0x10(%r8,%rdi,8), %ecx
testq %rcx, %rcx
je 0xd4fdf
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 (%rax,%r11), %r11d
testl %r11d, %r11d
je 0xd4fd5
cmpl $0x5, %r11d
jne 0xd4fc8
incl %r15d
jmp 0xd4fd5
cmpl %edx, %r11d
jne 0xd4fd2
incl %r12d
jmp 0xd4fd5
incl %r14d
incq %rdi
cmpq %rdi, %rcx
jne 0xd4fab
jmp 0xd4fe8
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %r15d, %r15d
testl %r12d, %r12d
je 0xd5031
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 0xd5031
movl %r15d, %edi
xorps %xmm2, %xmm2
cvtsi2ss %rdi, %xmm2
xorps %xmm3, %xmm3
cvtsi2ss %rcx, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm2, %xmm3
jb 0xd5031
movb $0x0, 0x4(%r9,%rbp,8)
incq %rsi
cmpq %r13, %rsi
jne 0xd4f68
movq -0x8(%rsp), %rsi
incq %rsi
movl %esi, %eax
incl %ebx
cmpq %rax, -0x10(%rsp)
movl -0x24(%rsp), %ecx
movq -0x20(%rsp), %r15
ja 0xd4dea
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq