// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: normalize_hap_overlaps_advance(hap_overlaps_list*, hap_overlaps_list*, ma_ug_t*, asg_t*, ma_hit_t_alloc*, R_to_U*)
void normalize_hap_overlaps_advance(hap_overlaps_list* all_ovlp, hap_overlaps_list* back_all_ovlp,
ma_ug_t *ug, asg_t *read_g, ma_hit_t_alloc* reverse_sources, R_to_U* ruIndex)
{
    hap_overlaps *x = NULL, *y = NULL;
    uint32_t v, i, uId, qn, tn;
    uint32_t types[4];
    
    types[X2Y] = Y2X; types[Y2X] = X2Y; types[XCY] = YCX; types[YCX] = XCY;
    int index;
    for (v = 0; v < all_ovlp->num; v++)
    {
        uId = v;
        for (i = 0; i < all_ovlp->x[uId].a.n; i++)
        {
            qn = all_ovlp->x[uId].a.a[i].xUid;
            tn = all_ovlp->x[uId].a.a[i].yUid;
            x = &(all_ovlp->x[uId].a.a[i]);
            index = get_specific_hap_overlap(&(all_ovlp->x[tn]), tn, qn);
            if(index != -1)
            {
                y = &(all_ovlp->x[tn].a.a[index]);
                if(x->rev == y->rev && types[x->type]==y->type) continue;
                ///if(x->weight >= y->weight)
                // if((calculate_bi_weight(x, ug, read_g, reverse_sources, ruIndex)) >= 
                //    (calculate_bi_weight(y, ug, read_g, reverse_sources, ruIndex)))
                if(x->score >= y->score)
                {
                    kv_push(hap_overlaps, back_all_ovlp->x[tn].a, (*y));
                    set_reverse_hap_overlap(y, x, types);
                }
                else
                {
                    kv_push(hap_overlaps, back_all_ovlp->x[qn].a, (*x));
                    set_reverse_hap_overlap(x, y, types);
                }
            }
            else
            {
                kv_pushp(hap_overlaps, all_ovlp->x[tn].a, &y);
                set_reverse_hap_overlap(y, x, types);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, (%rsp)
movaps 0x12103e(%rip), %xmm0   # 0x22d480
movaps %xmm0, 0x10(%rsp)
cmpl $0x0, 0x8(%rdi)
je 0x10c6f2
movq %rdi, %r14
xorl %edx, %edx
movq %rdi, 0x8(%rsp)
movq (%r14), %rcx
movq %rdx, 0x20(%rsp)
leaq (%rdx,%rdx,2), %rbp
cmpq $0x0, (%rcx,%rbp,8)
je 0x10c6dd
xorl %esi, %esi
xorl %r15d, %r15d
movq 0x10(%rcx,%rbp,8), %r12
shlq $0x6, %rsi
movl 0x24(%r12,%rsi), %edx
movl 0x28(%r12,%rsi), %eax
leaq (%rax,%rax,2), %rbx
leaq (%rcx,%rbx,8), %rdi
movq (%rdi), %r8
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
testq %r8, %r8
je 0x10c4ce
movq 0x10(%rdi), %r10
xorl %r13d, %r13d
xorl %r11d, %r11d
shlq $0x6, %r13
cmpl %eax, 0x24(%r10,%r13)
jne 0x10c4be
addq %r10, %r13
cmpl %edx, 0x28(%r13)
je 0x10c4cb
incl %r11d
movq %r11, %r13
cmpq %r11, %r8
ja 0x10c4aa
jmp 0x10c4ce
movl %r11d, %r9d
addq %rsi, %r12
cmpl $-0x1, %r9d
je 0x10c5c3
movq 0x10(%rcx,%rbx,8), %rcx
movslq %r9d, %rsi
shlq $0x6, %rsi
leaq (%rcx,%rsi), %r13
movb (%r12), %dil
cmpb (%rcx,%rsi), %dil
jne 0x10c50a
movzbl 0x1(%r12), %ecx
movzbl 0x1(%r13), %esi
cmpl %esi, 0x10(%rsp,%rcx,4)
je 0x10c6ca
movq 0x30(%r12), %rsi
movq (%rsp), %rcx
movq (%rcx), %rcx
cmpq 0x30(%r13), %rsi
jge 0x10c629
leaq (%rdx,%rdx,2), %rbx
movq 0x8(%rcx,%rbx,8), %rax
cmpq %rax, (%rcx,%rbx,8)
jne 0x10c572
leaq (%rcx,%rbx,8), %rdi
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %r14
movq %rsi, 0x8(%rcx,%r14)
movq 0x8(%rdi), %rsi
movq 0x10(%rdi), %rdi
shlq $0x6, %rsi
callq 0x2370
movq (%rsp), %rcx
movq (%rcx), %rcx
movq %rax, 0x10(%rcx,%r14)
movq 0x8(%rsp), %r14
movq (%rsp), %rax
movq (%rax), %rax
movq (%rax,%rbx,8), %rcx
movq 0x10(%rax,%rbx,8), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rax,%rbx,8)
shlq $0x6, %rcx
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups 0x20(%r12), %xmm2
movups 0x30(%r12), %xmm3
movups %xmm3, 0x30(%rdx,%rcx)
movups %xmm2, 0x20(%rdx,%rcx)
movups %xmm1, 0x10(%rdx,%rcx)
movups %xmm0, (%rdx,%rcx)
movq %r12, %rdi
movq %r13, %rsi
jmp 0x10c6c0
movq 0x8(%rdi), %rdx
cmpq %rdx, %r8
jne 0x10c60c
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %edx
cmoveq %rdx, %rsi
shlq $0x3, %rax
leaq (%rax,%rax,2), %r14
movq %rsi, 0x8(%rcx,%r14)
movq 0x8(%rdi), %rsi
movq 0x10(%rdi), %rdi
shlq $0x6, %rsi
callq 0x2370
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movq %rax, 0x10(%rcx,%r14)
movq 0x8(%rsp), %r14
movq (%r14), %rax
movq (%rax,%rbx,8), %rdi
leaq 0x1(%rdi), %rcx
movq %rcx, (%rax,%rbx,8)
shlq $0x6, %rdi
addq 0x10(%rax,%rbx,8), %rdi
jmp 0x10c6bd
movq 0x8(%rcx,%rbx,8), %rdx
cmpq %rdx, (%rcx,%rbx,8)
jne 0x10c677
leaq (%rcx,%rbx,8), %rdi
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %edx
cmoveq %rdx, %rsi
shlq $0x3, %rax
leaq (%rax,%rax,2), %r14
movq %rsi, 0x8(%rcx,%r14)
movq 0x8(%rdi), %rsi
movq 0x10(%rdi), %rdi
shlq $0x6, %rsi
callq 0x2370
movq (%rsp), %rcx
movq (%rcx), %rcx
movq %rax, 0x10(%rcx,%r14)
movq 0x8(%rsp), %r14
movq (%rsp), %rax
movq (%rax), %rax
movq (%rax,%rbx,8), %rcx
movq 0x10(%rax,%rbx,8), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rax,%rbx,8)
shlq $0x6, %rcx
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups 0x30(%r13), %xmm3
movups %xmm3, 0x30(%rdx,%rcx)
movups %xmm2, 0x20(%rdx,%rcx)
movups %xmm1, 0x10(%rdx,%rcx)
movups %xmm0, (%rdx,%rcx)
movq %r13, %rdi
movq %r12, %rsi
leaq 0x10(%rsp), %rdx
callq 0x10c0f4
incl %r15d
movq (%r14), %rcx
movq %r15, %rsi
cmpq %r15, (%rcx,%rbp,8)
ja 0x10c477
movq 0x20(%rsp), %rdx
incq %rdx
movl 0x8(%r14), %eax
cmpq %rax, %rdx
jb 0x10c45b
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq