// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movss %xmm0, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x50(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x50(%rbp), %eax
jae 0x124b79
movq -0x18(%rbp), %rax
movl -0x44(%rbp), %ecx
movzbl (%rax,%rcx), %eax
sarl %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movl -0x44(%rbp), %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movl -0x44(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x1, %eax
je 0x124b6c
movq -0x8(%rbp), %rax
movl -0x44(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x2, %eax
je 0x124b6c
movq -0x8(%rbp), %rax
movl -0x44(%rbp), %ecx
movb $0x0, (%rax,%rcx)
jmp 0x124b6e
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x124b20
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x38(%rbp), %rcx
movl 0x4(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x124bc3
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x44(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x124b80
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jae 0x124d38
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x124bf1
jmp 0x124d2a
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movl -0x48(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x124c19
jmp 0x124d2a
movq $0x0, -0x58(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x124c67
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x44(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movzbl (%rax,%rcx), %eax
andl $0x1, %eax
cltq
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x124c28
movq -0x58(%rbp), %rax
movq -0x40(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
je 0x124c9a
movq -0x58(%rbp), %rax
movq -0x40(%rbp), %rcx
movl 0x10(%rcx), %ecx
cvtsi2ss %rcx, %xmm0
mulss -0x24(%rbp), %xmm0
cvttss2si %xmm0, %rcx
cmpq %rcx, %rax
jl 0x124d28
movq -0x40(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x124d0b
movq -0x40(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x40(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x40(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x40(%rbp), %rax
movl (%rax), %ecx
andl $0x80000000, %ecx       # imm = 0x80000000
orl $0x0, %ecx
movl %ecx, (%rax)
movq -0x40(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x40(%rbp), %rax
movl (%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, (%rax)
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x2210
movq -0x40(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orl $0x80000000, %edx       # imm = 0x80000000
movl %edx, (%rax,%rcx,8)
jmp 0x124d2a
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x124bca
movq -0x38(%rbp), %rdi
callq 0xcdd10
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0xf6030
movl $0x0, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x4c(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jae 0x124e56
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movl -0x48(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x124da3
jmp 0x124e48
movq $0x0, -0x58(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x124df1
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x44(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movzbl (%rax,%rcx), %eax
andl $0x1, %eax
cltq
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x124db2
leaq -0x80(%rbp), %rdi
movl -0x48(%rbp), %edx
addl $0x1, %edx
movq -0x40(%rbp), %rax
movl (%rax), %eax
shrl $0x1f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x2604f4(%rip), %rax    # 0x385303
movsbl (%rax,%rcx), %ecx
leaq 0x26354a(%rip), %rsi    # 0x388364
movb $0x0, %al
callq 0x2050
movq 0x29f1b8(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq -0x80(%rbp), %rdx
movq -0x40(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x58(%rbp), %r8
leaq 0x26352d(%rip), %rsi    # 0x38836e
movb $0x0, %al
callq 0x22a0
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x124d6f
addq $0x80, %rsp
popq %rbp
retq
nop