// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: get_pair_hap_similarity_by_base(ma_utg_t*, asg_t*, unsigned int, ma_hit_t_alloc*, R_to_U*, long long, long long, double*, double*)
void get_pair_hap_similarity_by_base(ma_utg_t *xReads, asg_t *read_g, uint32_t target_uId, 
ma_hit_t_alloc* reverse_sources, R_to_U* ruIndex, long long xBegPos, long long xEndPos, 
double* Match, double* Total)
{
    uint32_t i, j, qn, tn, is_Unitig, uId, min_count = 0, max_count = 0;
    long long offset, r_beg, r_end, ovlp;
    
    for (i = 0, offset = 0; i < xReads->n; i++)
    {
        qn = xReads->a[i]>>33;
        r_beg = offset; r_end = offset + (long long)(read_g->seq[qn].len) - 1;
        offset += (uint32_t)xReads->a[i];
        
        ovlp = (long long)(MIN(r_end, xEndPos)) - (long long)(MAX(r_beg, xBegPos)) + 1;
        if(ovlp <= 0) continue;

        if(reverse_sources[qn].length > 0) min_count++;
        if(reverse_sources[qn].length == 0) continue;
        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;
            }
        }
    }

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, 0x40(%rsp)
movl %edx, 0x18(%rsp)
movq 0x90(%rsp), %rax
movq 0x88(%rsp), %rdx
cmpl $0x0, 0x10(%rdi)
je 0x1064b4
movq %rsi, %r12
movq 0x80(%rsp), %r8
xorl %ebx, %ebx
xorl %r10d, %r10d
xorl %r13d, %r13d
movl $0x0, 0x10(%rsp)
movq %r9, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq %rdi, 0x20(%rsp)
movq 0x18(%rdi), %rax
movq (%rax,%rbx,8), %r11
movq %r11, %rax
shrq $0x21, %rax
movq 0x20(%r12), %rdx
movl (%rdx,%rax,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leaq (%rdx,%r13), %rsi
decq %rsi
cmpq %r8, %rsi
cmovgeq %r8, %rsi
cmpq %r9, %r13
movq %r9, %rdx
cmovgq %r13, %rdx
cmpq %rdx, %rsi
jl 0x10647c
leaq (%rax,%rax,2), %rax
movl 0xc(%rcx,%rax,8), %esi
xorl %edx, %edx
testl %esi, %esi
setne %dl
addl %edx, %r10d
testl %esi, %esi
je 0x10647c
leaq (%rcx,%rax,8), %rbp
cmpl $0x0, 0xc(%rbp)
je 0x10647c
movq %r11, 0x38(%rsp)
movl %r10d, 0x14(%rsp)
movl $0xc, %r15d
xorl %r14d, %r14d
movq (%rbp), %rax
movl (%rax,%r15), %esi
movl %esi, 0xc(%rsp)
movq 0x20(%r12), %rax
cmpl $0x0, (%rax,%rsi,8)
js 0x10640e
movl 0xc(%rsp), %esi
movq 0x40(%rsp), %rdi
leaq 0x1c(%rsp), %rdx
leaq 0x8(%rsp), %rcx
callq 0xa306f
movl 0x1c(%rsp), %eax
cmpl 0x18(%rsp), %eax
jne 0x106442
cmpl $-0x1, %eax
je 0x106442
cmpl $0x1, 0x8(%rsp)
jne 0x106442
jmp 0x106457
movq 0x40(%rsp), %rdi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
callq 0xa306f
movl 0xc(%rsp), %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
je 0x106442
cmpl $0x1, 0x8(%rsp)
je 0x106442
movq 0x20(%r12), %rcx
cmpl $0x0, (%rcx,%rax,8)
jns 0x1063de
incq %r14
movl 0xc(%rbp), %eax
addq $0x28, %r15
cmpq %rax, %r14
jb 0x1063c7
jmp 0x10645b
incl 0x10(%rsp)
movq 0x30(%rsp), %r9
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rdi
movq 0x80(%rsp), %r8
movl 0x14(%rsp), %r10d
movq 0x38(%rsp), %r11
movl %r11d, %eax
addq %rax, %r13
incq %rbx
movl 0x10(%rdi), %eax
cmpq %rax, %rbx
jb 0x10634e
movl 0x10(%rsp), %eax
cvtsi2sd %rax, %xmm0
movl %r10d, %eax
cvtsi2sd %rax, %xmm1
movq 0x90(%rsp), %rax
movq 0x88(%rsp), %rdx
jmp 0x1064bc
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movsd %xmm0, (%rdx)
movsd %xmm1, (%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq