// File: /workspace/github_cpp_makefile_star2_O2/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 %rcx, -0x10(%rsp)
movq %rdi, -0x18(%rsp)
movl %esi, -0x1c(%rsp)
movl %esi, %eax
movq %rax, -0x8(%rsp)
xorl %ecx, %ecx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
xorl %ebx, %ebx
xorl %esi, %esi
xorl %eax, %eax
cmpq -0x8(%rsp), %r12
je 0xad258
cmpl $0x65, %eax
cmovael -0x1c(%rsp), %ebx
cmovael %ecx, %esi
movl %esi, -0x20(%rsp)
movq -0x18(%rsp), %rcx
movl (%rcx,%r12,4), %esi
shrl %esi
imulq $0x18, %rsi, %rsi
movq -0x10(%rsp), %rcx
leaq (%rcx,%rsi), %r14
movl 0xc(%rcx,%rsi), %r15d
cmpq $0x1, %r15
sbbl $-0x1, %ebx
movabsq $0xc, %rdi
xorl %r10d, %r10d
cmpq %r10, %r15
je 0xad234
movq (%r14), %rsi
movl (%rsi,%rdi), %r11d
movq 0x20(%r8), %r13
cmpl $0x0, (%r13,%r11,8)
movq (%r9), %rsi
js 0xad211
cmpq %r11, %rsi
jbe 0xad1fc
movq 0x8(%r9), %rcx
movl (%rcx,%r11,4), %r11d
cmpl $-0x1, %r11d
je 0xad1fc
movl %r11d, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
shrl $0x1f, %r11d
jmp 0xad201
xorl %r11d, %r11d
movl %ebp, %esi
cmpl %edx, %esi
jne 0xad22b
cmpl $-0x1, %esi
je 0xad22b
testb %r11b, %r11b
je 0xad22b
jmp 0xad23d
cmpq %r11, %rsi
jbe 0xad22b
movq 0x8(%r9), %rcx
movslq (%rcx,%r11,4), %r11
testq %r11, %r11
js 0xad22b
cmpl $0x0, (%r13,%r11,8)
jns 0xad1da
incq %r10
addq $0x28, %rdi
jmp 0xad1bf
movl %r15d, %r10d
movl -0x20(%rsp), %esi
jmp 0xad243
movl -0x20(%rsp), %esi
incl %esi
incl %eax
cmpl %r15d, %r10d
movl $0x0, %ecx
cmovnel %ecx, %eax
incq %r12
jmp 0xad174
movl %esi, %eax
cvtsi2sd %rax, %xmm0
movq 0x38(%rsp), %rax
movsd %xmm0, (%rax)
movl %ebx, %eax
cvtsi2sd %rax, %xmm0
movq 0x40(%rsp), %rax
movsd %xmm0, (%rax)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq