// File: /workspace/github_cpp_makefile_star2_O1/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 0xd8aa2
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 0xd8a80
testl $0x7fffffff, 0x4(%r13)  # imm = 0x7FFFFFFF
je 0xd8ad4
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 0xd8ab3
testl %ebp, %ebp
je 0xd8b93
xorl %r15d, %r15d
movq 0x20(%r13), %rax
cmpl $0x0, (%rax,%r15,8)
js 0xd8b87
movq (%rbx), %rax
movq 0x10(%rax), %rax
leaq (%r15,%r15,4), %rcx
cmpl $0x0, 0xc(%rax,%rcx,8)
je 0xd8b87
leaq (%rax,%rcx,8), %r12
movl 0x10(%r12), %eax
testq %rax, %rax
je 0xd8b38
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 0xd8b1b
jmp 0xd8b3a
xorl %ecx, %ecx
cmpq %rax, %rcx
je 0xd8b57
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
mulss 0xc(%rsp), %xmm0
cvttss2si %xmm0, %rax
cmpq %rax, %rcx
jl 0xd8b87
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%r12)
movl $0x0, (%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 0xd8adf
movq %r13, %rdi
callq 0xa02fa
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0xba760
movq (%rbx), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %r13d
andq $0x7fffffff, %r13       # imm = 0x7FFFFFFF
je 0xd8c01
movl $0xc, %ebp
xorl %r15d, %r15d
leaq 0x20(%rsp), %r12
movq (%rbx), %rax
movq 0x10(%rax), %rax
cmpl $0x0, (%rax,%rbp)
jne 0xd8be9
incq %r15
addq $0x28, %rbp
cmpq %r15, %r13
jne 0xd8bce
jmp 0xd8c01
leaq (%rax,%rbp), %rdi
addq $-0xc, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x11038
jmp 0xd8bdb
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq