// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/hic.cpp
// Function: clean_trans_ovlp(bubble_type*, kv_u_trans_t*, kv_u_trans_t*, asg64_v*, ma_ug_t*)
void clean_trans_ovlp(bubble_type *bub, kv_u_trans_t *des, kv_u_trans_t *src, asg64_v *srt, ma_ug_t *ug)
{
    uint64_t k, st, i, m = 0, ncut; 
    for (k = des->n = 0; k < src->n; k++) {
        if(IF_HOM(src->a[k].qn, (*bub))) continue;
        if(IF_HOM(src->a[k].tn, (*bub))) continue;
        kv_push(u_trans_t, *des, src->a[k]);
    }

    kv_resize(uint64_t, des->idx, src->idx.n); des->idx.n = src->idx.n;
    memset(des->idx.a, 0, des->idx.n*sizeof((*(des->idx.a))));
    for (st = 0, i = 1; i <= des->n; ++i) {
        if (i == des->n || des->a[i].qn != des->a[st].qn) {
            des->idx.a[des->a[st].qn] = (((uint64_t)st)<<32)|(i-st); m++;
            st = i;
        }
    }
    
    if(srt && m) {
        ncut = 0; kv_resize(uint64_t, *srt, m);
        for (k = srt->n = 0; k < des->idx.n; k++) {
            if(!((uint32_t)(des->idx.a[k]))) continue;
            m = cal_ave_ovlp(des->a+(des->idx.a[k]>>32), ((uint32_t)(des->idx.a[k])), 0.9); 
            m = ((uint64_t)-1)-m; m <<= 32; m += k;
            kv_push(uint64_t, *srt, m);
        }
        radix_sort_b64(srt->a, srt->a + srt->n);
        for (k = 0; k < srt->n; k++) {
            ncut += trans_sec_cut0(des, srt, (uint32_t)(srt->a[k]), 0.2, 256, ug);
        }

        if(ncut) {///renew idx
            for (i = k = 0; i < des->n; i++) {
                if(des->a[i].del) continue;
                des->a[k++] = des->a[i];
            }
            des->n = k;
            
            memset(des->idx.a, 0, des->idx.n*sizeof((*(des->idx.a))));
            for (st = 0, i = 1; i <= des->n; ++i) {
                if (i == des->n || des->a[i].qn != des->a[st].qn) {
                    des->idx.a[des->a[st].qn] = (((uint64_t)st)<<32)|(i-st); m++;
                    st = i;
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, (%rsp)
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %rbx
andq $0x0, (%rsi)
movq %rdi, %r13
xorl %ebp, %ebp
xorl %r14d, %r14d
cmpq (%r12), %r14
jae 0x11da57
movq (%r13), %rdx
movq 0x80(%r13), %rax
movq 0x10(%r12), %rcx
movl 0x8(%rcx,%rbp), %esi
movl (%rdx,%rsi,4), %esi
incq %rax
cmpq %rsi, %rax
jb 0x11da4b
movl 0x14(%rcx,%rbp), %esi
movl (%rdx,%rsi,4), %edx
cmpq %rdx, %rax
jb 0x11da4b
movq (%rbx), %rdx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rdx
jne 0x11da24
leaq (%rdx,%rdx), %rcx
testq %rdx, %rdx
pushq $0x2
popq %rdx
cmoveq %rdx, %rcx
movq %rcx, 0x8(%rbx)
imulq $0x30, %rcx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq 0x10(%r12), %rcx
movq (%rbx), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rbx)
imulq $0x30, %rdx, %rdx
movups (%rcx,%rbp), %xmm0
movups 0x10(%rcx,%rbp), %xmm1
movups 0x20(%rcx,%rbp), %xmm2
movups %xmm2, 0x20(%rax,%rdx)
movups %xmm1, 0x10(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
incq %r14
addq $0x30, %rbp
jmp 0x11d9b8
movq 0x18(%r12), %rdx
cmpq %rdx, 0x20(%rbx)
jae 0x11dabd
decq %rdx
movq %rdx, %rax
shrq %rax
orq %rdx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x20(%rbx)
movq 0x28(%rbx), %rdi
leaq 0x8(,%rax,8), %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x28(%rbx)
movq 0x18(%r12), %rdx
jmp 0x11dac1
movq 0x28(%rbx), %rdi
movq %rdx, 0x18(%rbx)
shlq $0x3, %rdx
xorl %r14d, %r14d
xorl %esi, %esi
callq 0x20e0
pushq $0x1
popq %rcx
pushq $0x38
popq %rdx
xorl %eax, %eax
cmpq (%rbx), %rcx
ja 0x11db23
movq 0x10(%rbx), %rdi
jne 0x11daf0
imulq $0x30, %r14, %rsi
movl 0x8(%rdi,%rsi), %esi
jmp 0x11dafd
imulq $0x30, %r14, %rsi
movl 0x8(%rdi,%rsi), %esi
cmpl %esi, (%rdi,%rdx)
je 0x11db1a
movq %rcx, %rdi
subq %r14, %rdi
shlq $0x20, %r14
orq %rdi, %r14
movq 0x28(%rbx), %rdi
movl %esi, %esi
movq %r14, (%rdi,%rsi,8)
incq %rax
movq %rcx, %r14
incq %rcx
addq $0x30, %rdx
jmp 0x11dadb
testq %r15, %r15
setne %cl
testq %rax, %rax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x11dd22
cmpq %rax, 0x8(%r15)
jae 0x11db91
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%r15)
movq 0x10(%r15), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x10(%r15)
andq $0x0, (%r15)
movabsq $-0x100000000, %r14     # imm = 0xFFFFFFFF00000000
xorl %r13d, %r13d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq 0x18(%rbx), %r13
jae 0x11dc25
movq 0x28(%rbx), %rax
movq (%rax,%r13,8), %rax
movq %rax, %rsi
andq %rbp, %rsi
je 0x11dc20
shrq $0x20, %rax
imulq $0x30, %rax, %rdi
addq 0x10(%rbx), %rdi
movsd 0xc596f(%rip), %xmm0    # 0x1e3540
callq 0x11d8dd
movq %rax, %r12
movq (%r15), %rcx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rcx
jne 0x11dc0b
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r15)
movq (%r15), %rcx
imulq %r14, %r12
addq %r13, %r12
addq %r14, %r12
leaq 0x1(%rcx), %rdx
movq %rdx, (%r15)
movq %r12, (%rax,%rcx,8)
incq %r13
jmp 0x11dba7
movq (%r15), %rax
movq 0x10(%r15), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0xf2735
xorl %r14d, %r14d
xorl %r12d, %r12d
movq (%rsp), %r13
cmpq (%r15), %r14
jae 0x11dc6f
movq 0x10(%r15), %rax
movl (%rax,%r14,8), %edx
movl $0x100, %ecx            # imm = 0x100
movq %rbx, %rdi
movq %r15, %rsi
movsd 0xc5871(%rip), %xmm0    # 0x1e34d0
movq %r13, %r8
callq 0x87ea7
addq %rax, %r12
incq %r14
jmp 0x11dc3f
testq %r12, %r12
je 0x11dd22
xorl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
cmpq (%rbx), %rdx
jae 0x11dcbe
movq 0x10(%rbx), %rsi
cmpb $0x0, 0x28(%rsi,%rax)
js 0x11dcb5
leaq (%rsi,%rax), %rdi
imulq $0x30, %rcx, %r8
incq %rcx
movups (%rdi), %xmm0
movups 0x10(%rdi), %xmm1
movups 0x20(%rdi), %xmm2
movups %xmm2, 0x20(%rsi,%r8)
movups %xmm1, 0x10(%rsi,%r8)
movups %xmm0, (%rsi,%r8)
incq %rdx
addq $0x30, %rax
jmp 0x11dc7e
movq %rcx, (%rbx)
movq 0x18(%rbx), %rdx
movq 0x28(%rbx), %rdi
shlq $0x3, %rdx
xorl %r14d, %r14d
xorl %esi, %esi
callq 0x20e0
pushq $0x1
popq %rax
pushq $0x38
popq %rcx
cmpq (%rbx), %rax
ja 0x11dd22
movq 0x10(%rbx), %rsi
jne 0x11dcf2
imulq $0x30, %r14, %rdx
movl 0x8(%rsi,%rdx), %edx
jmp 0x11dcff
imulq $0x30, %r14, %rdx
movl 0x8(%rsi,%rdx), %edx
cmpl %edx, (%rsi,%rcx)
je 0x11dd19
movq %rax, %rsi
subq %r14, %rsi
shlq $0x20, %r14
orq %rsi, %r14
movq 0x28(%rbx), %rsi
movl %edx, %edx
movq %r14, (%rsi,%rdx,8)
movq %rax, %r14
incq %rax
addq $0x30, %rcx
jmp 0x11dcdd
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq