// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: normalize_hap_overlaps(hap_overlaps_list*, hap_overlaps_list*)
void normalize_hap_overlaps(hap_overlaps_list* all_ovlp, hap_overlaps_list* back_all_ovlp)
{
    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)
                {
                    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 $0x38, %rsp
movq %rsi, (%rsp)
movq %rdi, 0x8(%rsp)
movaps 0x11de60(%rip), %xmm0   # 0x1eb570
leaq 0x10(%rsp), %rax
movaps %xmm0, (%rax)
xorl %ecx, %ecx
movq 0x8(%rsp), %rax
movl 0x8(%rax), %eax
cmpq %rax, %rcx
jae 0xcd942
xorl %r15d, %r15d
movq %rcx, 0x28(%rsp)
imulq $0x18, %rcx, %rcx
movq %rcx, 0x30(%rsp)
movl %r15d, %r15d
movq 0x8(%rsp), %rax
movq (%rax), %rbx
cmpq %r15, (%rbx,%rcx)
jbe 0xcd935
leaq (%rbx,%rcx), %rax
movq 0x10(%rax), %rax
movq %r15, %rcx
shlq $0x6, %rcx
leaq (%rax,%rcx), %r12
movl 0x24(%rax,%rcx), %ebp
movl 0x28(%rax,%rcx), %esi
imulq $0x18, %rsi, %r14
leaq (%rbx,%r14), %r13
movq %r13, %rdi
movl %ebp, %edx
callq 0xcd675
cmpl $-0x1, %eax
je 0xcd853
movq 0x10(%rbx,%r14), %rcx
cltq
shlq $0x6, %rax
leaq (%rcx,%rax), %r13
movb (%r12), %dl
cmpb (%rcx,%rax), %dl
jne 0xcd7b4
movzbl 0x1(%r12), %eax
movzbl 0x1(%r13), %ecx
cmpl %ecx, 0x10(%rsp,%rax,4)
je 0xcd928
movl 0x2c(%r12), %eax
movq (%rsp), %rcx
movq (%rcx), %rcx
cmpl 0x2c(%r13), %eax
jae 0xcd8a1
imulq $0x18, %rbp, %rbx
movq (%rcx,%rbx), %rax
cmpq 0x8(%rcx,%rbx), %rax
jne 0xcd80d
leaq (%rax,%rax), %rsi
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rsi
leaq (%rcx,%rbx), %rax
movq %rsi, 0x8(%rcx,%rbx)
movq 0x10(%rax), %rdi
shlq $0x6, %rsi
callq 0x2370
movq (%rsp), %rcx
movq (%rcx), %rcx
movq %rax, 0x10(%rcx,%rbx)
movq (%rcx,%rbx), %rax
movq 0x10(%rcx,%rbx), %rdx
leaq 0x1(%rax), %rsi
movq %rsi, (%rcx,%rbx)
shlq $0x6, %rax
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups 0x20(%r12), %xmm2
movups 0x30(%r12), %xmm3
movups %xmm3, 0x30(%rdx,%rax)
movups %xmm2, 0x20(%rdx,%rax)
movups %xmm1, 0x10(%rdx,%rax)
movups %xmm0, (%rdx,%rax)
movq %r12, %rdi
movq %r13, %rsi
jmp 0xcd91e
movq (%r13), %rdi
cmpq 0x8(%r13), %rdi
jne 0xcd88e
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx,%r14)
movq 0x10(%r13), %rdi
shlq $0x6, %rsi
callq 0x2370
movq 0x8(%rsp), %rcx
movq (%rcx), %rbx
movq %rax, 0x10(%rbx,%r14)
movq (%rbx,%r14), %rdi
leaq 0x1(%rdi), %rax
movq %rax, (%rbx,%r14)
shlq $0x6, %rdi
addq 0x10(%rbx,%r14), %rdi
jmp 0xcd91b
movq (%rcx,%r14), %rax
cmpq 0x8(%rcx,%r14), %rax
jne 0xcd8e0
leaq (%rax,%rax), %rsi
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rsi
leaq (%rcx,%r14), %rax
movq %rsi, 0x8(%rcx,%r14)
movq 0x10(%rax), %rdi
shlq $0x6, %rsi
callq 0x2370
movq (%rsp), %rcx
movq (%rcx), %rcx
movq %rax, 0x10(%rcx,%r14)
movq (%rcx,%r14), %rax
movq 0x10(%rcx,%r14), %rdx
leaq 0x1(%rax), %rsi
movq %rsi, (%rcx,%r14)
shlq $0x6, %rax
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups 0x30(%r13), %xmm3
movups %xmm3, 0x30(%rdx,%rax)
movups %xmm2, 0x20(%rdx,%rax)
movups %xmm1, 0x10(%rdx,%rax)
movups %xmm0, (%rdx,%rax)
movq %r13, %rdi
movq %r12, %rsi
leaq 0x10(%rsp), %rdx
callq 0xcd6a4
incl %r15d
movq 0x30(%rsp), %rcx
jmp 0xcd73c
movq 0x28(%rsp), %rcx
incq %rcx
jmp 0xcd71a
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq