// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x143b1a
cmpl $0x64, -0x4c(%rbp)
jbe 0x1439e1
movl $0x0, -0x48(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
shrl %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0xc(%rax)
jbe 0x143a0d
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x18(%rbp), %rcx
movl -0x34(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0xc(%rcx), %eax
jae 0x143ae2
movq -0x18(%rbp), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl -0x30(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0x143a9f
movq -0x28(%rbp), %rdi
movl -0x38(%rbp), %esi
leaq -0x38(%rbp), %rdx
leaq -0x3c(%rbp), %rcx
callq 0xd3d50
cmpl $-0x1, -0x38(%rbp)
je 0x143a9b
cmpl $0x1, -0x3c(%rbp)
je 0x143a9b
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0x143a9d
jmp 0x143ad4
jmp 0x143a9f
movq -0x28(%rbp), %rdi
movl -0x38(%rbp), %esi
leaq -0x40(%rbp), %rdx
leaq -0x3c(%rbp), %rcx
callq 0xd3d50
cmpl $-0x1, -0x40(%rbp)
je 0x143ad2
cmpl $0x1, -0x3c(%rbp)
jne 0x143ad2
movl -0x40(%rbp), %eax
cmpl -0x10(%rbp), %eax
jne 0x143ad2
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x143ae2
jmp 0x143ad4
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x143a14
movl -0x30(%rbp), %eax
movq -0x18(%rbp), %rcx
movl -0x34(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0xc(%rcx), %eax
jne 0x143b03
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x143b0a
movl $0x0, -0x4c(%rbp)
jmp 0x143b0c
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1439c2
movl -0x48(%rbp), %eax
cvtsi2sd %rax, %xmm0
movq 0x10(%rbp), %rax
movsd %xmm0, (%rax)
movl -0x44(%rbp), %eax
cvtsi2sd %rax, %xmm0
movq 0x18(%rbp), %rax
movsd %xmm0, (%rax)
addq $0x50, %rsp
popq %rbp
retq