// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq $0xa, -0x50(%rbp)
cmpl $0x1, -0x14(%rbp)
jne 0xa18f2
movq -0x28(%rbp), %rax
movl $0x1, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
jmp 0xa1c4f
cmpl $0x0, -0x14(%rbp)
jne 0xa1911
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
jmp 0xa1c4f
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movslq -0x14(%rbp), %rcx
cmpq %rcx, %rax
jge 0xa1c16
cmpq $0x0, -0x30(%rbp)
jle 0xa1a8a
movq -0x30(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0xa1a8a
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
movl (%rax,%rcx,4), %eax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %eax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
imulq $0x28, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x218(%rcx), %rcx
imulq $0x28, -0x38(%rbp), %rdx
addq %rdx, %rcx
subl 0x20(%rcx), %eax
movl %eax, %eax
cmpq -0x50(%rbp), %rax
jl 0xa19f9
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x218(%rcx), %rcx
imulq $0x28, -0x48(%rbp), %rdx
addq %rdx, %rcx
subl 0x20(%rcx), %eax
movl %eax, %eax
cmpq -0x50(%rbp), %rax
jge 0xa1a06
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0xa1a11
movq -0x28(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x218(%rcx), %rcx
imulq $0x28, -0x40(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x20(%rcx), %eax
ja 0xa1a6d
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x218(%rcx), %rcx
imulq $0x28, -0x48(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x20(%rcx), %eax
jae 0xa1a85
movq 0x32256c(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x2e0b67(%rip), %rsi    # 0x3825e5
movb $0x0, %al
callq 0x22a0
jmp 0xa1c03
cmpq $0x0, -0x30(%rbp)
jne 0xa1b4b
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %eax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x218(%rcx), %rcx
imulq $0x28, -0x48(%rbp), %rdx
addq %rdx, %rcx
subl 0x20(%rcx), %eax
movl %eax, %eax
cmpq -0x50(%rbp), %rax
jge 0xa1af5
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0xa1b00
movq -0x28(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x218(%rcx), %rcx
imulq $0x28, -0x48(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x20(%rcx), %eax
jae 0xa1b46
movq 0x3224ab(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x2e0aa6(%rip), %rsi    # 0x3825e5
movb $0x0, %al
callq 0x22a0
jmp 0xa1c01
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
movl (%rax,%rcx,4), %eax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
imulq $0x28, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x218(%rcx), %rcx
imulq $0x28, -0x38(%rbp), %rdx
addq %rdx, %rcx
subl 0x20(%rcx), %eax
movl %eax, %eax
cmpq -0x50(%rbp), %rax
jge 0xa1bae
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0xa1bb9
movq -0x28(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x218(%rcx), %rcx
imulq $0x28, -0x40(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x20(%rcx), %eax
jbe 0xa1bff
movq 0x3223f2(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x2e09ed(%rip), %rsi    # 0x3825e5
movb $0x0, %al
callq 0x22a0
jmp 0xa1c01
jmp 0xa1c03
jmp 0xa1c05
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xa192d
movq -0x20(%rbp), %rax
movl (%rax), %eax
movq -0x28(%rbp), %rcx
addl (%rcx), %eax
cmpl -0x14(%rbp), %eax
je 0xa1c4f
movq 0x3223b2(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movl (%rax), %edx
movq -0x28(%rbp), %rax
movl (%rax), %ecx
movl -0x14(%rbp), %r8d
leaq 0x2e4821(%rip), %rsi    # 0x386469
movb $0x0, %al
callq 0x22a0
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop