// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: get_hap_similarity(unsigned int*, unsigned int, unsigned int, ma_hit_t_alloc*, asg_t*, R_to_U*, double*, double*)
void get_hap_similarity(uint32_t* list, uint32_t Len, uint32_t target_uId, 
ma_hit_t_alloc* reverse_sources, asg_t *read_g, R_to_U* ruIndex, 
double* Match, double* Total)
{
    #define CUTOFF_THRES 100
    uint32_t i, j, qn, tn, is_Unitig, uId, min_count = 0, max_count = 0, cutoff = 0;;
    for (i = 0; i < Len; i++)
    {
        if(cutoff > CUTOFF_THRES)
        {
            max_count = 0;
            min_count = Len;
        }
        qn = list[i]>>1;
        if(reverse_sources[qn].length > 0) min_count++;
        for (j = 0; j < reverse_sources[qn].length; j++)
        {
            tn = Get_tn(reverse_sources[qn].buffer[j]);
            if(read_g->seq[tn].del == 1)
            {
                get_R_to_U(ruIndex, tn, &tn, &is_Unitig);
                if(tn == (uint32_t)-1 || is_Unitig == 1 || read_g->seq[tn].del == 1) continue;
            }


            get_R_to_U(ruIndex, tn, &uId, &is_Unitig);
            if(uId!=(uint32_t)-1 && is_Unitig == 1 && uId == target_uId)
            {
                max_count++;
                break;
            }
        }

        //means no match
        if(j == reverse_sources[qn].length)
        {
            cutoff++;
        }
        else
        {
            cutoff = 0;
        }
    }

    (*Match) = max_count;
    (*Total) = min_count;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %r8, -0x18(%rsp)
movq %rdi, -0x8(%rsp)
movq 0x40(%rsp), %rax
movq 0x38(%rsp), %rdi
testl %esi, %esi
je 0xea782
movl %esi, %eax
movq %rax, -0x10(%rsp)
xorl %r8d, %r8d
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %ebp, %ebp
movq %rcx, -0x20(%rsp)
movl %esi, -0x24(%rsp)
cmpl $0x65, %r12d
cmovael %esi, %ebp
cmovael %r8d, %r15d
movq -0x8(%rsp), %rax
movl (%rax,%r14,4), %eax
shrl %eax
leaq (%rax,%rax,2), %rdi
movl 0xc(%rcx,%rdi,8), %ebx
xorl %eax, %eax
testq %rbx, %rbx
setne %r10b
je 0xea731
movb %r10b, -0x25(%rsp)
leaq (%rcx,%rdi,8), %rdi
movq (%rdi), %r8
movq -0x18(%rsp), %rsi
movq 0x20(%rsi), %r11
addq $0xc, %r8
xorl %r13d, %r13d
movl (%r8), %r10d
cmpl $0x0, (%r11,%r10,8)
movl %r10d, %edi
js 0xea6dd
movl %edi, %r10d
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
cmpq %r10, (%r9)
jbe 0xea6ca
movq 0x8(%r9), %rsi
movl (%rsi,%r10,4), %r10d
cmpl $-0x1, %r10d
je 0xea6ca
movl %r10d, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
shrl $0x1f, %r10d
jmp 0xea6cd
xorl %r10d, %r10d
cmpl %edx, %edi
jne 0xea71c
cmpl $-0x1, %edi
je 0xea71c
testb %r10b, %r10b
je 0xea71c
jmp 0xea736
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
cmpq %r10, (%r9)
jbe 0xea704
movq 0x8(%r9), %rsi
movl (%rsi,%r10,4), %r10d
cmpl $-0x1, %r10d
je 0xea704
movl %r10d, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
shrl $0x1f, %r10d
jmp 0xea707
xorl %r10d, %r10d
cmpl $-0x1, %edi
sete %sil
orb %r10b, %sil
jne 0xea71c
movl %edi, %esi
cmpl $0x0, (%r11,%rsi,8)
jns 0xea6a0
incq %r13
addq $0x28, %r8
cmpq %r13, %rbx
jne 0xea693
movl %ebx, %r13d
jmp 0xea739
xorl %r13d, %r13d
jmp 0xea74a
incl %r15d
movq -0x20(%rsp), %rcx
movl -0x24(%rsp), %esi
xorl %r8d, %r8d
movb -0x25(%rsp), %r10b
movb %r10b, %al
addl %eax, %ebp
incl %r12d
cmpl %ebx, %r13d
cmovnel %r8d, %r12d
incq %r14
cmpq -0x10(%rsp), %r14
jne 0xea64a
movl %r15d, %eax
cvtsi2sd %rax, %xmm1
movl %ebp, %eax
cvtsi2sd %rax, %xmm0
movq 0x40(%rsp), %rax
movq 0x38(%rsp), %rdi
jmp 0xea78a
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movsd %xmm1, (%rdi)
movsd %xmm0, (%rax)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq