// File: /workspace/github_cpp_makefile_star2_O3/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)
movq (%rdx), %rax
testq %rax, %rax
je 0x162b8e
movq %rdi, %r13
xorl %ebp, %ebp
xorl %r14d, %r14d
movq (%r13), %rsi
movq 0x80(%r13), %rdx
movq 0x10(%r12), %rcx
movl 0x8(%rcx,%rbp), %edi
movl (%rsi,%rdi,4), %edi
incq %rdx
cmpq %rdi, %rdx
jb 0x162b7e
movl 0x14(%rcx,%rbp), %edi
movl (%rsi,%rdi,4), %esi
cmpq %rsi, %rdx
jb 0x162b7e
movq (%rbx), %rdx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rdx
jne 0x162b4f
leaq (%rdx,%rdx), %rcx
testq %rdx, %rdx
movl $0x2, %edx
cmoveq %rdx, %rcx
movq %rcx, 0x8(%rbx)
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq 0x10(%r12), %rcx
movq (%rbx), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rbx)
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %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)
movq (%r12), %rax
incq %r14
addq $0x30, %rbp
cmpq %rax, %r14
jb 0x162ae7
movq 0x18(%r12), %rdx
cmpq %rdx, 0x20(%rbx)
jae 0x162bf4
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 0x162bf8
movq 0x28(%rbx), %rdi
movq (%rsp), %r13
movq %rdx, 0x18(%rbx)
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x20e0
movq (%rbx), %r8
testq %r8, %r8
je 0x162ebb
movq 0x10(%rbx), %rcx
leaq 0x38(%rcx), %rdx
movl $0x1, %esi
xorl %eax, %eax
xorl %edi, %edi
leaq (%rdi,%rdi,2), %r9
shlq $0x4, %r9
cmpq %r8, %rsi
jne 0x162c3c
movl 0x8(%rcx,%r9), %r9d
jmp 0x162c46
movl 0x8(%rcx,%r9), %r9d
cmpl %r9d, (%rdx)
je 0x162c67
movq %rsi, %r8
subq %rdi, %r8
shlq $0x20, %rdi
orq %r8, %rdi
movq 0x28(%rbx), %r8
movl %r9d, %r9d
movq %rdi, (%r8,%r9,8)
incq %rax
movq (%rbx), %r8
movq %rsi, %rdi
incq %rsi
addq $0x30, %rdx
cmpq %r8, %rsi
jbe 0x162c28
testq %r15, %r15
setne %cl
testq %rax, %rax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x162ebb
cmpq %rax, 0x8(%r15)
jae 0x162ce1
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)
movq $0x0, (%r15)
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x162d99
movabsq $-0x100000000, %r14     # imm = 0xFFFFFFFF00000000
xorl %r13d, %r13d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x28(%rbx), %rcx
movq (%rcx,%r13,8), %rcx
movq %rcx, %rsi
andq %rbp, %rsi
je 0x162d84
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rdi
shlq $0x4, %rdi
addq 0x10(%rbx), %rdi
movsd 0xce8c9(%rip), %xmm0    # 0x2315f8
callq 0x162a03
movq %rax, %r12
movq (%r15), %rcx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rcx
jne 0x162d6b
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
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)
movq 0x18(%rbx), %rax
incq %r13
cmpq %rax, %r13
jb 0x162d07
movq (%r15), %rax
movq (%rsp), %r13
jmp 0x162d9b
xorl %eax, %eax
movq 0x10(%r15), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x1390c9
cmpq $0x0, (%r15)
je 0x162ebb
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 0xce7ad(%rip), %xmm0    # 0x231580
movq %r13, %r8
callq 0xc4481
addq %rax, %r14
incq %r12
cmpq (%r15), %r12
jb 0x162db8
testq %r14, %r14
je 0x162ebb
movq (%rbx), %rsi
testq %rsi, %rsi
je 0x162e44
xorl %ecx, %ecx
xorl %edx, %edx
xorl %eax, %eax
movq 0x10(%rbx), %rdi
cmpb $0x0, 0x28(%rdi,%rcx)
js 0x162e36
leaq (%rdi,%rcx), %rsi
leaq (%rax,%rax,2), %r8
incq %rax
shlq $0x4, %r8
movups (%rsi), %xmm0
movups 0x10(%rsi), %xmm1
movups 0x20(%rsi), %xmm2
movups %xmm2, 0x20(%rdi,%r8)
movups %xmm1, 0x10(%rdi,%r8)
movups %xmm0, (%rdi,%r8)
movq (%rbx), %rsi
incq %rdx
addq $0x30, %rcx
cmpq %rsi, %rdx
jb 0x162dfd
jmp 0x162e46
xorl %eax, %eax
movq %rax, (%rbx)
movq 0x18(%rbx), %rdx
movq 0x28(%rbx), %rdi
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x20e0
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x162ebb
movq 0x10(%rbx), %rax
leaq 0x38(%rax), %rcx
movl $0x1, %edx
xorl %esi, %esi
leaq (%rsi,%rsi,2), %r8
shlq $0x4, %r8
cmpq %rdi, %rdx
jne 0x162e87
movl 0x8(%rax,%r8), %r8d
jmp 0x162e91
movl 0x8(%rax,%r8), %r8d
cmpl %r8d, (%rcx)
je 0x162eaf
movq %rdx, %rdi
subq %rsi, %rdi
shlq $0x20, %rsi
orq %rdi, %rsi
movq 0x28(%rbx), %rdi
movl %r8d, %r8d
movq %rsi, (%rdi,%r8,8)
movq (%rbx), %rdi
movq %rdx, %rsi
incq %rdx
addq $0x30, %rcx
cmpq %rdi, %rdx
jbe 0x162e73
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq