// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/./Correct.h
// Function: InsertSNPVector(haplotype_evdience_alloc*, haplotype_evdience*, long long, char, UC_Read*)
inline void InsertSNPVector(haplotype_evdience_alloc* h, haplotype_evdience* sub_list, long long sub_length, char misBase, 
UC_Read* g_read)
{
    if(sub_length <= 0)
        return;
    long long i = 0; SnpStats *p = NULL;
    kv_pushp(SnpStats, h->snp_stat, &p);
    
    // h->snp_stat[h->available_snp].id = h->available_snp;
    // h->snp_stat[h->available_snp].occ_0 = 0;
    // h->snp_stat[h->available_snp].occ_1 = 0;
    // h->snp_stat[h->available_snp].occ_2 = 0;
    // h->snp_stat[h->available_snp].overlap_num = 0;
    // h->snp_stat[h->available_snp].site = sub_list[0].site;
    // h->snp_stat[h->available_snp].is_homopolymer = 
    // if_is_homopolymer_strict(h->snp_stat[h->available_snp].site, g_read->seq, g_read->length);
    // int8_t* vector = Get_SNP_Vector((*h), h->available_snp);

    p->id = h->snp_stat.n-1;
    p->occ_0 = 0;
    p->occ_1 = 0;
    p->occ_2 = 0;
    p->overlap_num = 0;
    p->site = sub_list[0].site;
    p->is_homopolymer = if_is_homopolymer_strict(p->site, g_read->seq, g_read->length);
    int8_t* vector = Get_SNP_Vector((*h), p->id);
    for (i = 0; i < sub_length; i++)
    {
        if(sub_list[i].type == 0)
        {
            vector[sub_list[i].overlapID] = 0;
            // h->snp_stat[h->available_snp].occ_0++;
            h->snp_stat.a[p->id].occ_0++;
        }
        else if(sub_list[i].type == 1 && sub_list[i].misBase == misBase)
        {
            vector[sub_list[i].overlapID] = 1;
            // h->snp_stat[h->available_snp].occ_1++;
            h->snp_stat.a[p->id].occ_1++;
        }
        else
        {
            vector[sub_list[i].overlapID] = 2;
            // h->snp_stat[h->available_snp].occ_2++;
            h->snp_stat.a[p->id].occ_2++;
        }
        // h->snp_stat[h->available_snp].overlap_num++;
        h->snp_stat.a[p->id].overlap_num++;
    }


    // int new_occ_0 = h->snp_stat[h->available_snp].occ_0 + 1;
    // int new_occ_1 = h->snp_stat[h->available_snp].occ_1;
    int new_occ_0 = h->snp_stat.a[p->id].occ_0 + 1;
    int new_occ_1 = h->snp_stat.a[p->id].occ_1;

    if(filter_snp(new_occ_0, new_occ_1, new_occ_0 + new_occ_1) == 0) ///Fix-attention:definitely wrong
    {
        // h->snp_stat[h->available_snp].score = -1;
        h->snp_stat.a[p->id].score = -1;
    }
    else
    {
        h->core_snp++;


        double consensus = new_occ_0 + new_occ_1 - abs(new_occ_0 - new_occ_1);

        consensus = consensus /((double)(new_occ_0 + new_occ_1));

        ///50% vs 50%///Fix-attention:definitely wrong
        if(new_occ_0 == new_occ_1)
        {
            consensus = consensus + 0.25;
        }
        else if(consensus >= 0.8)
        {
            consensus = consensus + 0.2;
        }
        else if(consensus >= 0.6)
        {
            consensus = consensus + 0.15;
        }
        else if(consensus >= 0.4)
        {
            consensus = consensus + 0.1;
        }
        else if(consensus >= 0.2)
        {
            consensus = consensus + 0.05;
        }
        

        consensus= consensus*((double)(new_occ_0 + new_occ_1));

        // h->snp_stat[h->available_snp].score = consensus;
        h->snp_stat.a[p->id].score = consensus;
    }


    
    // h->available_snp++;
}

// Assembly:
testq %rdx, %rdx
jle 0x86bf8
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %r12
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq 0x218(%rdi), %rax
movq 0x220(%rdi), %r10
cmpq 0x228(%rdi), %r10
movl %ecx, 0x4(%rsp)
jne 0x86948
leaq (%r10,%r10), %rdx
testq %r10, %r10
movl $0x2, %ecx
cmovneq %rdx, %rcx
movq %rcx, 0x228(%rbx)
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x218(%rbx)
movq 0x220(%rbx), %r10
leaq 0x1(%r10), %rdx
movq %rdx, 0x220(%rbx)
leaq (%r10,%r10,4), %rsi
movl %r10d, (%rax,%rsi,8)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%rax,%rsi,8)
movl (%r15), %edi
movl %edi, 0x20(%rax,%rsi,8)
movq (%r12), %r8
cmpq $0x4, %rdi
movl $0x3, %ecx
cmovaeq %rdi, %rcx
movq 0x8(%r12), %rdx
addq $-0x3, %rcx
leaq 0x3(%rdi), %r9
leaq -0x1(%rdx), %r11
cmpq %rdx, %r9
cmovlq %r9, %r11
cmpq %rdi, %r11
jle 0x869c9
xorl %edx, %edx
movq %rdi, %r12
xorl %r13d, %r13d
movb 0x1(%r8,%r12), %r9b
testb %r13b, %r13b
je 0x869b7
cmpb %r13b, %r9b
jne 0x869d0
incq %rdx
movl %r13d, %r9d
jmp 0x869bf
movl $0x1, %edx
movl %r9d, %r13d
incq %r12
cmpq %r12, %r11
jne 0x869a0
jmp 0x869d3
xorl %r9d, %r9d
xorl %edx, %edx
jmp 0x869d3
movl %r13d, %r9d
cmpq %rdi, %rcx
jge 0x86a0b
xorl %r11d, %r11d
movq %rdi, %r13
xorl %r12d, %r12d
movb -0x1(%r8,%r13), %bpl
testb %r12b, %r12b
je 0x869f8
cmpb %r12b, %bpl
jne 0x86a12
incq %r11
movl %r12d, %ebp
jmp 0x86a01
movl $0x1, %r11d
movl %ebp, %r12d
decq %r13
cmpq %rcx, %r13
jg 0x869e1
jmp 0x86a15
xorl %ebp, %ebp
xorl %r11d, %r11d
jmp 0x86a15
movl %r12d, %ebp
leaq (%rax,%rsi,8), %rsi
movb (%r8,%rdi), %al
xorl %edi, %edi
cmpb %al, %r9b
setne %r8b
sete %dil
cmpb %al, %bpl
sete %cl
addq %rdi, %rdx
movb $0x1, %dil
cmpq $0x2, %rdx
jg 0x86a6c
andb %cl, %r8b
movzbl %r8b, %r8d
addq %r8, %r11
cmpq $0x2, %r11
movl 0x4(%rsp), %ecx
jg 0x86a70
xorb %r9b, %al
xorb %r9b, %bpl
orb %al, %bpl
sete %al
addq %rdx, %r11
cmpq $0x3, %r11
setge %dil
andb %al, %dil
jmp 0x86a70
movl 0x4(%rsp), %ecx
movb %dil, 0x24(%rsi)
imull 0x1c8(%rbx), %r10d
addq 0x1d0(%rbx), %r10
addq $0x4, %r15
movzbl 0x8(%r15), %eax
cmpl $0x1, %eax
je 0x86ab4
testl %eax, %eax
jne 0x86ad9
movl (%r15), %eax
movb $0x0, (%r10,%rax)
movq 0x218(%rbx), %rax
movl (%rsi), %edx
leaq (%rdx,%rdx,4), %rdi
leaq (%rax,%rdi,8), %rdi
addq $0x8, %rdi
jmp 0x86af6
cmpb %cl, 0x10(%r15)
jne 0x86ad9
movl (%r15), %eax
movb $0x1, (%r10,%rax)
movq 0x218(%rbx), %rax
movl (%rsi), %edx
leaq (%rdx,%rdx,4), %rdi
leaq (%rax,%rdi,8), %rdi
addq $0xc, %rdi
jmp 0x86af6
movl (%r15), %eax
movb $0x2, (%r10,%rax)
movq 0x218(%rbx), %rax
movl (%rsi), %edx
leaq (%rdx,%rdx,4), %rdi
leaq (%rax,%rdi,8), %rdi
addq $0x10, %rdi
incl (%rdi)
leaq (%rdx,%rdx,4), %rdi
incl 0x4(%rax,%rdi,8)
addq $0x18, %r15
decq %r14
jne 0x86a87
movl %edx, %ecx
leaq (%rcx,%rcx,4), %rcx
movl 0x8(%rax,%rcx,8), %esi
movl 0xc(%rax,%rcx,8), %edx
leal (%rsi,%rdx), %edi
incl %edi
incl %esi
movl %esi, %r8d
subl %edx, %r8d
movl %edx, %r9d
cmovll %esi, %r9d
cvtsi2sd %r9d, %xmm1
cvtsi2sd %edi, %xmm0
divsd %xmm0, %xmm1
movsd 0x1aa0dc(%rip), %xmm2   # 0x230c20
ucomisd %xmm1, %xmm2
jb 0x86b62
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movsd 0x1aaa50(%rip), %xmm2   # 0x2315a8
ucomisd %xmm1, %xmm2
ja 0x86be5
incl 0x1c4(%rbx)
movl %r8d, %r9d
negl %r9d
cmovnsl %r8d, %r9d
addl %r9d, %edi
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
divsd %xmm0, %xmm1
cmpl %edx, %esi
jne 0x86b8e
addsd 0x1aaa44(%rip), %xmm1   # 0x2315d0
jmp 0x86bdc
ucomisd 0x1aaa1a(%rip), %xmm1   # 0x2315b0
jae 0x86bc0
ucomisd 0x1aa9e8(%rip), %xmm1   # 0x231588
jae 0x86bca
ucomisd 0x1aaa16(%rip), %xmm1   # 0x2315c0
jae 0x86bd4
ucomisd 0x1aa9cc(%rip), %xmm1   # 0x231580
jb 0x86bdc
addsd 0x1aaa0a(%rip), %xmm1   # 0x2315c8
jmp 0x86bdc
addsd 0x1aa9b8(%rip), %xmm1   # 0x231580
jmp 0x86bdc
addsd 0x1aa9e6(%rip), %xmm1   # 0x2315b8
jmp 0x86bdc
addsd 0x1aa034(%rip), %xmm1   # 0x230c10
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %r9d
movl %r9d, 0x1c(%rax,%rcx,8)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq