// File: /workspace/github_cpp_makefile_star2_O2/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
movq %rsi, 0x10(%rsp)
movl 0x14(%rsi), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
xorl %edx, %edx
cmpq %rdx, %rax
je 0x9c801
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
jmp 0x9c7dd
pushq $0xc
popq %rax
xorl %ecx, %ecx
movl 0x4(%r13), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpq %rdx, %rcx
jae 0x9c829
movq 0x8(%r13), %rdx
orl $0x80000000, (%rdx,%rax) # imm = 0x80000000
incq %rcx
addq $0x18, %rax
jmp 0x9c806
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %r15d, %r15d
cmpq %rbp, %r15
je 0x9c8d7
movq 0x20(%r13), %rax
cmpl $0x0, (%rax,%r15,8)
js 0x9c8cf
movq (%rbx), %rax
movq 0x10(%rax), %r12
imulq $0x28, %r15, %rax
cmpl $0x0, 0xc(%r12,%rax)
je 0x9c8cf
addq %rax, %r12
movl 0x10(%r12), %eax
xorl %edx, %edx
xorl %ecx, %ecx
cmpq %rdx, %rax
je 0x9c88b
movq 0x18(%r12), %rsi
movq (%rsi,%rdx,8), %rsi
shrq $0x21, %rsi
movzbl (%r14,%rsi), %esi
andl $0x1, %esi
addq %rsi, %rcx
incq %rdx
jmp 0x9c869
cmpq %rax, %rcx
je 0x9c8a5
cvtsi2ss %rax, %xmm0
mulss 0xc(%rsp), %xmm0
cvttss2si %xmm0, %rax
cmpq %rax, %rcx
jl 0x9c8cf
andl $0x0, 0x10(%r12)
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movq 0x18(%r12), %rdi
callq 0x2220
andq $0x0, 0x18(%r12)
movq 0x20(%r13), %rax
orl $0x80000000, (%rax,%r15,8) # imm = 0x80000000
incq %r15
jmp 0x9c832
movq %r13, %rdi
callq 0x694eb
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x80328
movq (%rbx), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
xorl %ebp, %ebp
cmpq %r13, %rbp
je 0x9c9a9
movq (%rbx), %rax
movq 0x10(%rax), %r12
imulq $0x28, %rbp, %rax
cmpl $0x0, 0xc(%r12,%rax)
jne 0x9c926
incq %rbp
jmp 0x9c905
addq %rax, %r12
movl 0x10(%r12), %eax
xorl %ecx, %ecx
xorl %r15d, %r15d
cmpq %rcx, %rax
je 0x9c955
movq 0x18(%r12), %rdx
movq (%rdx,%rcx,8), %rdx
shrq $0x21, %rdx
movzbl (%r14,%rdx), %edx
andl $0x1, %edx
addq %rdx, %r15
incq %rcx
jmp 0x9c933
incq %rbp
movl (%r12), %eax
shrl $0x1f, %eax
leaq 0x149d25(%rip), %rcx    # 0x1e668b
movsbl (%rax,%rcx), %ecx
leaq 0x20(%rsp), %rdi
leaq 0x14cd03(%rip), %rsi    # 0x1e9679
movl %ebp, %edx
xorl %eax, %eax
callq 0x2050
movq 0x1b665a(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
movl 0x10(%r12), %ecx
leaq 0x14ccee(%rip), %rsi    # 0x1e9683
leaq 0x20(%rsp), %rdx
movq %r15, %r8
xorl %eax, %eax
callq 0x22b0
jmp 0x9c905
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq