// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: filter_set_kug(unsigned char*, asg_t*, unsigned char*, kvec_asg_arc_t_warp*, float, ma_ug_t**)
void filter_set_kug(uint8_t* trio_flag, asg_t *rg, uint8_t *rf, kvec_asg_arc_t_warp *r_edges, float f_rate, ma_ug_t **ug)
{
    asg_t* nsg = (*ug)->g; ma_utg_t *u = NULL;
    uint32_t k, v, n_vtx = nsg->n_seq, rn = rg->n_seq;
    int64_t flag_occ;
    for (k = 0; k < rn; k++) {
        trio_flag[k] = rf[k]>>1;
        if(trio_flag[k] != FATHER && trio_flag[k] != MOTHER) trio_flag[k] = AMBIGU;
    }

    for (k = 0; k < nsg->n_arc; k++) nsg->arc[k].del = 1;
    for (v = 0; v < n_vtx; ++v) {
        if (nsg->seq[v].del) continue;
        u = &((*ug)->u.a[v]);
        if(u->m == 0) continue;
        for (k = flag_occ = 0; k < u->n; k++) flag_occ += (rf[u->a[k]>>33]&1);
        if (flag_occ == (int64_t)u->n || flag_occ >= (int64_t)(u->n*f_rate)) {
            if(u->m != 0){
                u->circ = u->end = u->len = u->m = u->n = u->start = 0;
                free(u->a);
                u->a = NULL;
            }
            nsg->seq[v].del = 1;
        }
    }
    asg_cleanup(nsg);
    renew_utg(ug, rg, r_edges);

    char name[32];
    for (v = 0, n_vtx = (*ug)->g->n_seq; v < n_vtx; ++v) {
        u = &((*ug)->u.a[v]);
        if(u->m == 0) continue;
        for (k = flag_occ = 0; k < u->n; k++) flag_occ += (rf[u->a[k]>>33]&1);
        sprintf(name, "ptg%.6d%c", v + 1, "lc"[u->circ]);
        fprintf(stderr, "S\t%s\t*\tTN:i:%u\tUN:i:%ld\n", name, u->n, flag_occ);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, %rbx
movss %xmm0, 0xc(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdx, %r14
movq (%r8), %rax
movq 0x18(%rax), %r13
movl 0x14(%r13), %ebp
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andq %rcx, %rbp
movq %rsi, 0x10(%rsp)
movl 0x14(%rsi), %eax
andq %rcx, %rax
je 0xd9ed3
xorl %ecx, %ecx
xorl %edx, %edx
movb (%r14,%rdx), %sil
shrb %sil
leal -0x1(%rsi), %r8d
cmpb $0x2, %r8b
movzbl %sil, %esi
cmovael %ecx, %esi
movb %sil, (%rdi,%rdx)
incq %rdx
cmpq %rdx, %rax
jne 0xd9eb1
testl $0x7fffffff, 0x4(%r13)  # imm = 0x7FFFFFFF
je 0xd9f05
movl $0xc, %eax
xorl %ecx, %ecx
movq 0x8(%r13), %rdx
orl $0x80000000, (%rdx,%rax) # imm = 0x80000000
incq %rcx
movl 0x4(%r13), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
addq $0x18, %rax
cmpq %rdx, %rcx
jb 0xd9ee4
testl %ebp, %ebp
je 0xd9fc9
xorl %r15d, %r15d
movq 0x20(%r13), %rax
cmpl $0x0, (%rax,%r15,8)
js 0xd9fbd
movq (%rbx), %rax
movq 0x10(%rax), %rax
leaq (%r15,%r15,4), %rcx
cmpl $0x0, 0xc(%rax,%rcx,8)
je 0xd9fbd
leaq (%rax,%rcx,8), %r12
movl 0x10(%r12), %eax
testq %rax, %rax
je 0xd9f6c
movq 0x18(%r12), %rdx
xorl %esi, %esi
xorl %ecx, %ecx
movq (%rdx,%rsi,8), %rdi
shrq $0x21, %rdi
movzbl (%r14,%rdi), %edi
andl $0x1, %edi
addq %rdi, %rcx
incq %rsi
cmpq %rsi, %rax
jne 0xd9f4c
movq %rax, %rdx
jmp 0xd9f70
xorl %edx, %edx
xorl %ecx, %ecx
cmpq %rdx, %rcx
je 0xd9f8d
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
mulss 0xc(%rsp), %xmm0
cvttss2si %xmm0, %rax
cmpq %rax, %rcx
jl 0xd9fbd
movl $0x0, 0x10(%r12)
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movq 0x18(%r12), %rdi
callq 0x2220
movq $0x0, 0x18(%r12)
movq 0x20(%r13), %rax
orl $0x80000000, (%rax,%r15,8) # imm = 0x80000000
incq %r15
cmpq %rbp, %r15
jne 0xd9f10
movq %r13, %rdi
callq 0xa0a7d
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0xbb7a4
movq (%rbx), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %r13d
andq $0x7fffffff, %r13       # imm = 0x7FFFFFFF
je 0xda0af
xorl %ebp, %ebp
movq (%rbx), %rax
movq 0x10(%rax), %rax
leaq (,%rbp,4), %rcx
addq %rbp, %rcx
cmpl $0x0, 0xc(%rax,%rcx,8)
jne 0xda023
incq %rbp
cmpq %r13, %rbp
jne 0xd9ffd
jmp 0xda0af
leaq (%rax,%rcx,8), %r12
movl 0x10(%r12), %eax
testq %rax, %rax
jne 0xda036
xorl %r15d, %r15d
jmp 0xda05b
movq 0x18(%r12), %rcx
xorl %edx, %edx
xorl %r15d, %r15d
movq (%rcx,%rdx,8), %rsi
shrq $0x21, %rsi
movzbl (%r14,%rsi), %esi
andl $0x1, %esi
addq %rsi, %r15
incq %rdx
cmpq %rdx, %rax
jne 0xda040
incq %rbp
movl (%r12), %eax
shrl $0x1f, %eax
leaq 0x15a6cf(%rip), %rcx    # 0x23473b
movsbl (%rax,%rcx), %ecx
leaq 0x20(%rsp), %rdi
leaq 0x15d6fd(%rip), %rsi    # 0x237779
movl %ebp, %edx
xorl %eax, %eax
callq 0x2050
movq 0x1baf54(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
movl 0x10(%r12), %ecx
leaq 0x15d6e8(%rip), %rsi    # 0x237783
leaq 0x20(%rsp), %rdx
movq %r15, %r8
xorl %eax, %eax
callq 0x22b0
jmp 0xda019
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq