// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movss %xmm0, -0x18(%rbp)
movss %xmm1, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x11fcc8
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl -0x4c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x11fa86
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x50(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, -0x38(%rbp)
leaq 0x2a58d6(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x11fa0c
jmp 0x11fa78
leaq 0x2a58bd(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x5, %eax
jne 0x11fa2e
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x11fa74
leaq 0x2a589b(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl -0x14(%rbp), %eax
jne 0x11fa50
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x11fa72
leaq 0x2a5879(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl -0x14(%rbp), %eax
je 0x11fa70
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x11fa72
jmp 0x11fa74
jmp 0x11fa76
jmp 0x11fa78
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x11f9cd
movl -0x2c(%rbp), %edi
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
movq -0x28(%rbp), %rax
movl 0x10(%rax), %ecx
movss -0x18(%rbp), %xmm0
movss -0x1c(%rbp), %xmm1
movl -0x20(%rbp), %r8d
callq 0x167f40
cmpl $0x0, %eax
je 0x11fad1
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl -0x4c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movb $0x0, 0x4(%rax,%rcx,8)
movl -0x2c(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x30(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x34(%rbp), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x3c(%rbp), %edi
movl -0x40(%rbp), %esi
movl -0x44(%rbp), %edx
movl -0x48(%rbp), %ecx
movss -0x18(%rbp), %xmm0
movss -0x1c(%rbp), %xmm1
movl -0x20(%rbp), %r8d
callq 0x167f40
cmpl $0x0, %eax
je 0x11fcb8
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x4c(%rbp), %eax
ja 0x11fcb6
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl -0x54(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
jne 0x11fca6
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl -0x54(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x11fc5a
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x50(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, -0x38(%rbp)
leaq 0x2a5702(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x11fbe0
jmp 0x11fc4c
leaq 0x2a56e9(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x5, %eax
jne 0x11fc02
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x11fc48
leaq 0x2a56c7(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl -0x14(%rbp), %eax
jne 0x11fc24
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x11fc46
leaq 0x2a56a5(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl -0x14(%rbp), %eax
je 0x11fc44
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x11fc46
jmp 0x11fc48
jmp 0x11fc4a
jmp 0x11fc4c
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x11fba1
movl -0x2c(%rbp), %edi
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
movq -0x28(%rbp), %rax
movl 0x10(%rax), %ecx
movss -0x18(%rbp), %xmm0
movss -0x1c(%rbp), %xmm1
xorl %r8d, %r8d
callq 0x167f40
cmpl $0x0, %eax
je 0x11fca4
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl -0x54(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movb $0x0, 0x4(%rax,%rcx,8)
jmp 0x11fca6
jmp 0x11fca8
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x11fb28
jmp 0x11fcb8
jmp 0x11fcba
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x11f97b
addq $0x60, %rsp
popq %rbp
retq
nop