// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/./Correct.h
// Function: count_nearby_snps(haplotype_evdience_alloc*, unsigned int*, int, int*, int*)
inline void count_nearby_snps(haplotype_evdience_alloc* hap, uint32_t* SNPs, int SNPsLen, int* nearsnp, int* non_nearsnps)
{
    long long i, current_id, large_id, small_id;
    long long distance = 10;

    

    if(SNPsLen == 1)
    {
        (*non_nearsnps) = 1;
        (*nearsnp) = 0;
        return;
    }

    if(SNPsLen == 0)
    {
        (*nearsnp) = 0;
        (*non_nearsnps) = 0;
        return;
    }

    (*nearsnp) = 0;
    (*non_nearsnps) = 0;

    for (i = 0; i < SNPsLen; i++)
    {
        if(i > 0 && i < SNPsLen - 1)
        {
            current_id= SNPs[i];

            ///since SNPs[i - 1].site is larger than SNPs[i]
            large_id = SNPs[i - 1];
            small_id = SNPs[i + 1];
            

            if(hap->snp_stat.a[large_id].site - hap->snp_stat.a[current_id].site < distance
              ||
              hap->snp_stat.a[current_id].site - hap->snp_stat.a[small_id].site < distance)
            {
                (*nearsnp)++;
            }
            else
            {
                (*non_nearsnps)++;
            }

            if(hap->snp_stat.a[current_id].site > hap->snp_stat.a[large_id].site || 
               hap->snp_stat.a[current_id].site < hap->snp_stat.a[small_id].site)
            {
                fprintf(stderr, "error\n");
            }
        }
        else if(i == 0)
        {
            current_id= SNPs[i];
            small_id = SNPs[i + 1];
            if(hap->snp_stat.a[current_id].site - hap->snp_stat.a[small_id].site < distance)
            {
                (*nearsnp)++;
            }
            else
            {
                (*non_nearsnps)++;
            }

            if(hap->snp_stat.a[current_id].site < hap->snp_stat.a[small_id].site)
            {
                fprintf(stderr, "error\n");
            }
        }
        else
        {
            large_id = SNPs[i - 1];
            current_id= SNPs[i];
            if(hap->snp_stat.a[large_id].site - hap->snp_stat.a[current_id].site < distance)
            {
                (*nearsnp)++;
            }
            else
            {
                (*non_nearsnps)++;
            }

            if(hap->snp_stat.a[current_id].site > hap->snp_stat.a[large_id].site)
            {
                fprintf(stderr, "error\n");
            }
            
        }
        
    }

    if((*nearsnp) + (*non_nearsnps) != SNPsLen)
    {
        fprintf(stderr, "(*nearsnp): %d, (*non_nearsnps): %d, SNPsLen: %d\n", (*nearsnp), (*non_nearsnps), SNPsLen);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %r10
movq %rcx, %r14
testl %edx, %edx
je 0x86c2c
movl %edx, %r8d
cmpl $0x1, %edx
jne 0x86c39
movl $0x1, (%r10)
movl $0x0, (%r14)
jmp 0x86d7d
xorl %eax, %eax
movl %eax, (%r14)
movl %eax, (%r10)
jmp 0x86d7d
xorl %ecx, %ecx
movl %ecx, (%r14)
movl %ecx, (%r10)
testl %r8d, %r8d
jle 0x86d72
movq %rsi, %r12
movq %rdi, %r13
movslq %r8d, %rbp
movq %r8, 0x8(%rsp)
leal -0x1(%r8), %ebx
xorl %r15d, %r15d
movq %r10, 0x10(%rsp)
testq %r15, %r15
je 0x86ce2
cmpq %rbx, %r15
jae 0x86d27
movl -0x4(%r12,%r15,4), %edx
movl (%r12,%r15,4), %edi
movl 0x4(%r12,%r15,4), %eax
movq 0x218(%r13), %rcx
leaq (%rdx,%rdx,4), %rsi
movl 0x20(%rcx,%rsi,8), %r9d
leaq (%rdi,%rdi,4), %rdx
movl 0x20(%rcx,%rdx,8), %r8d
subl %r8d, %r9d
movq %r14, %rdi
cmpl $0xa, %r9d
jb 0x86cba
leaq (%rax,%rax,4), %rdi
subl 0x20(%rcx,%rdi,8), %r8d
movq %r14, %rdi
cmpl $0xa, %r8d
jb 0x86cba
movq %r10, %rdi
leaq (%rcx,%rsi,8), %rsi
addq $0x20, %rsi
incl (%rdi)
leaq (%rcx,%rdx,8), %rdx
addq $0x20, %rdx
movl (%rdx), %edx
cmpl (%rsi), %edx
ja 0x86d5e
leaq (%rax,%rax,4), %rax
cmpl 0x20(%rcx,%rax,8), %edx
jae 0x86d19
jmp 0x86d5e
movl (%r12), %ecx
movl 0x4(%r12), %edx
movq 0x218(%r13), %rax
leaq (%rcx,%rcx,4), %rcx
movl 0x20(%rax,%rcx,8), %edi
leaq (%rdx,%rdx,4), %rdx
subl 0x20(%rax,%rdx,8), %edi
movq %r14, %rsi
cmpl $0xa, %edi
jb 0x86d0d
movq %r10, %rsi
incl (%rsi)
movl 0x20(%rax,%rcx,8), %ecx
cmpl 0x20(%rax,%rdx,8), %ecx
jb 0x86d5e
incq %r15
cmpq %r15, %rbp
jne 0x86c64
jmp 0x86d6a
movl -0x4(%r12,%r15,4), %ecx
movl (%r12,%r15,4), %edx
movq 0x218(%r13), %rax
leaq (%rcx,%rcx,4), %rcx
movl 0x20(%rax,%rcx,8), %edi
leaq (%rdx,%rdx,4), %rdx
subl 0x20(%rax,%rdx,8), %edi
movq %r14, %rsi
cmpl $0xa, %edi
jb 0x86d52
movq %r10, %rsi
incl (%rsi)
movl 0x20(%rax,%rdx,8), %edx
cmpl 0x20(%rax,%rcx,8), %edx
jbe 0x86d19
callq 0x5b6d
movq 0x10(%rsp), %r10
jmp 0x86d19
movl (%r10), %ecx
movq 0x8(%rsp), %r8
movl (%r14), %edx
leal (%rcx,%rdx), %eax
cmpl %r8d, %eax
jne 0x86d8c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20e24d(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x1aeb04(%rip), %rsi    # 0x2358a1
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22b0