// File: /workspace/github_cpp_makefile_star2_O1/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
movq $0x0, (%rsi)
cmpq $0x0, (%rdx)
je 0x15c0f2
movq %rdi, %r13
xorl %ebp, %ebp
xorl %r14d, %r14d
movq (%r13), %rcx
movq 0x80(%r13), %rax
movq 0x10(%r12), %rdx
movl 0x8(%rdx,%rbp), %esi
movl (%rcx,%rsi,4), %esi
incq %rax
cmpq %rsi, %rax
jb 0x15c0e1
movl 0x14(%rdx,%rbp), %edx
movl (%rcx,%rdx,4), %ecx
cmpq %rcx, %rax
jb 0x15c0e1
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x15c0aa
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movq 0x10(%r12), %rax
movq (%rbx), %rcx
movq 0x10(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movups (%rax,%rbp), %xmm0
movups 0x10(%rax,%rbp), %xmm1
movups 0x20(%rax,%rbp), %xmm2
movups %xmm2, 0x20(%rdx,%rcx)
movups %xmm1, 0x10(%rdx,%rcx)
movups %xmm0, (%rdx,%rcx)
incq %r14
addq $0x30, %rbp
cmpq (%r12), %r14
jb 0x15c04d
movq 0x18(%r12), %rax
cmpq %rax, 0x20(%rbx)
jae 0x15c14e
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, 0x20(%rbx)
movq 0x28(%rbx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x28(%rbx)
movq 0x18(%r12), %rdx
movq %rdx, 0x18(%rbx)
movq 0x28(%rbx), %rdi
shlq $0x3, %rdx
xorl %r12d, %r12d
xorl %esi, %esi
callq 0x20e0
movq (%rbx), %rsi
testq %rsi, %rsi
je 0x15c1d5
movl $0x1, %eax
movl $0x38, %ecx
xorl %r12d, %r12d
xorl %edx, %edx
cmpq %rsi, %rax
je 0x15c19b
movq 0x10(%rbx), %rsi
movl (%rsi,%rcx), %edi
leaq (%rdx,%rdx,2), %r8
shlq $0x4, %r8
cmpl 0x8(%rsi,%r8), %edi
je 0x15c1c6
movq %rax, %rsi
subq %rdx, %rsi
leaq (%rdx,%rdx,2), %rdi
shlq $0x20, %rdx
orq %rdx, %rsi
movq 0x10(%rbx), %rdx
movq 0x28(%rbx), %r8
shlq $0x4, %rdi
movl 0x8(%rdx,%rdi), %edx
movq %rsi, (%r8,%rdx,8)
incq %r12
movq %rax, %rdx
incq %rax
movq (%rbx), %rsi
addq $0x30, %rcx
cmpq %rsi, %rax
jbe 0x15c180
testq %r15, %r15
setne %al
testq %r12, %r12
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x15c417
cmpq %r12, 0x8(%r15)
jae 0x15c243
decq %r12
movq %r12, %rax
shrq %rax
orq %r12, %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, 0x8(%r15)
movq 0x10(%r15), %rdi
leaq 0x8(,%rax,8), %rsi
callq 0x2370
movq %rax, 0x10(%r15)
movq $0x0, (%r15)
cmpq $0x0, 0x18(%rbx)
je 0x15c2ee
movabsq $-0x100000000, %r14     # imm = 0xFFFFFFFF00000000
xorl %r13d, %r13d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x28(%rbx), %rax
movq (%rax,%r13,8), %rax
movq %rax, %rsi
andq %rbp, %rsi
je 0x15c2e1
shrq $0x20, %rax
leaq (%rax,%rax,2), %rdi
shlq $0x4, %rdi
addq 0x10(%rbx), %rdi
movsd 0xc9269(%rip), %xmm0    # 0x2254f8
callq 0x15bf6b
movq %rax, %r12
movq 0x8(%r15), %rax
cmpq %rax, (%r15)
jne 0x15c2c5
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r15)
movq 0x10(%r15), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%r15)
imulq %r14, %r12
addq %r13, %r12
addq %r14, %r12
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r15)
movq %r12, (%rcx,%rax,8)
incq %r13
cmpq 0x18(%rbx), %r13
jb 0x15c267
movq (%r15), %rax
movq 0x10(%r15), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x132eff
cmpq $0x0, (%r15)
movq (%rsp), %r13
je 0x15c417
xorl %r14d, %r14d
xorl %r12d, %r12d
movq 0x10(%r15), %rax
movl (%rax,%r12,8), %edx
movl $0x100, %ecx            # imm = 0x100
movq %rbx, %rdi
movq %r15, %rsi
movsd 0xc9153(%rip), %xmm0    # 0x225480
movq %r13, %r8
callq 0xc358d
addq %rax, %r14
incq %r12
cmpq (%r15), %r12
jb 0x15c312
testq %r14, %r14
je 0x15c417
cmpq $0x0, (%rbx)
je 0x15c399
xorl %ecx, %ecx
xorl %edx, %edx
xorl %eax, %eax
movq 0x10(%rbx), %rsi
cmpb $0x0, 0x28(%rsi,%rcx)
js 0x15c38b
leaq (%rsi,%rcx), %rdi
leaq (%rax,%rax,2), %r8
incq %rax
shlq $0x4, %r8
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, %rcx
cmpq (%rbx), %rdx
jb 0x15c355
jmp 0x15c39b
xorl %eax, %eax
movq %rax, (%rbx)
movq 0x18(%rbx), %rdx
movq 0x28(%rbx), %rdi
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x20e0
movq (%rbx), %rsi
testq %rsi, %rsi
je 0x15c417
movl $0x1, %eax
movl $0x38, %ecx
xorl %edx, %edx
cmpq %rsi, %rax
je 0x15c3e0
movq 0x10(%rbx), %rsi
movl (%rsi,%rcx), %edi
leaq (%rdx,%rdx,2), %r8
shlq $0x4, %r8
cmpl 0x8(%rsi,%r8), %edi
je 0x15c408
movq %rax, %rsi
subq %rdx, %rsi
leaq (%rdx,%rdx,2), %rdi
shlq $0x20, %rdx
orq %rdx, %rsi
movq 0x10(%rbx), %rdx
movq 0x28(%rbx), %r8
shlq $0x4, %rdi
movl 0x8(%rdx,%rdi), %edx
movq %rsi, (%r8,%rdx,8)
movq %rax, %rdx
incq %rax
movq (%rbx), %rsi
addq $0x30, %rcx
cmpq %rsi, %rax
jbe 0x15c3c5
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq