// File: /workspace/github_cpp_makefile_star2_O1/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 0x876aa
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %r12
movl %ecx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movq %rdx, (%rsp)
movq 0x228(%rdi), %rax
cmpq %rax, 0x220(%rdi)
jne 0x873d6
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmovneq %rcx, %rax
movq %rax, 0x228(%rbx)
movq 0x218(%rbx), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq %rax, 0x218(%rbx)
movq 0x218(%rbx), %rdx
movq 0x220(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x220(%rbx)
leaq (%rax,%rax,4), %rsi
movl %eax, (%rdx,%rsi,8)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%rdx,%rsi,8)
movl (%r14), %edi
movl %edi, 0x20(%rdx,%rsi,8)
movq (%r12), %r8
cmpq $0x4, %rdi
movl $0x3, %r10d
cmovgeq %rdi, %r10
movq 0x8(%r12), %rcx
addq $-0x3, %r10
leaq 0x3(%rdi), %r9
leaq -0x1(%rcx), %r11
cmpq %rcx, %r9
cmovlq %r9, %r11
cmpq %rdi, %r11
jle 0x87465
xorl %ecx, %ecx
movq %rdi, %r12
xorl %r13d, %r13d
movb 0x1(%r8,%r12), %r9b
testb %r13b, %r13b
je 0x87453
cmpb %r13b, %r9b
jne 0x8746c
incq %rcx
movl %r13d, %r9d
jmp 0x8745b
movl $0x1, %ecx
movl %r9d, %r13d
incq %r12
cmpq %r12, %r11
jne 0x8743c
jmp 0x8746f
xorl %r9d, %r9d
xorl %ecx, %ecx
jmp 0x8746f
movl %r13d, %r9d
cmpq %rdi, %r10
jge 0x874a7
xorl %r11d, %r11d
movq %rdi, %r13
xorl %r12d, %r12d
movb -0x1(%r8,%r13), %r15b
testb %r12b, %r12b
je 0x87494
cmpb %r12b, %r15b
jne 0x874af
incq %r11
movl %r12d, %r15d
jmp 0x8749d
movl $0x1, %r11d
movl %r15d, %r12d
decq %r13
cmpq %r10, %r13
jg 0x8747d
jmp 0x874b2
xorl %r15d, %r15d
xorl %r11d, %r11d
jmp 0x874b2
movl %r12d, %r15d
leaq (%rdx,%rsi,8), %rdx
movb (%r8,%rdi), %sil
xorl %edi, %edi
cmpb %sil, %r9b
setne %r8b
sete %dil
cmpb %sil, %r15b
sete %r10b
addq %rdi, %rcx
movb $0x1, %dil
cmpq $0x2, %rcx
jg 0x87505
andb %r10b, %r8b
movzbl %r8b, %r8d
addq %r8, %r11
cmpq $0x2, %r11
jg 0x87505
xorb %r9b, %sil
xorb %r9b, %r15b
orb %sil, %r15b
sete %sil
addq %rcx, %r11
cmpq $0x3, %r11
setge %dil
andb %sil, %dil
movb %dil, 0x24(%rdx)
imull 0x1c8(%rbx), %eax
addq 0x1d0(%rbx), %rax
movq (%rsp), %rsi
cmpq $0x2, %rsi
movl $0x1, %ecx
cmovgeq %rsi, %rcx
addq $0x4, %r14
movzbl 0x8(%r14), %esi
cmpl $0x1, %esi
je 0x87558
testl %esi, %esi
jne 0x8757c
movl (%r14), %esi
movb $0x0, (%rax,%rsi)
movq 0x218(%rbx), %rsi
movl (%rdx), %edi
leaq (%rdi,%rdi,4), %rdi
leaq (%rsi,%rdi,8), %rsi
addq $0x8, %rsi
jmp 0x87598
cmpb %bpl, 0x10(%r14)
jne 0x8757c
movl (%r14), %esi
movb $0x1, (%rax,%rsi)
movq 0x218(%rbx), %rsi
movl (%rdx), %edi
leaq (%rdi,%rdi,4), %rdi
leaq (%rsi,%rdi,8), %rsi
addq $0xc, %rsi
jmp 0x87598
movl (%r14), %esi
movb $0x2, (%rax,%rsi)
movq 0x218(%rbx), %rsi
movl (%rdx), %edi
leaq (%rdi,%rdi,4), %rdi
leaq (%rsi,%rdi,8), %rsi
addq $0x10, %rsi
incl (%rsi)
movq 0x218(%rbx), %rsi
movl (%rdx), %edi
leaq (%rdi,%rdi,4), %rdi
incl 0x4(%rsi,%rdi,8)
addq $0x18, %r14
decq %rcx
jne 0x8752c
movq 0x218(%rbx), %rax
movl (%rdx), %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 0x19d5ea(%rip), %xmm2   # 0x224be0
ucomisd %xmm1, %xmm2
jb 0x87614
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movsd 0x19de9e(%rip), %xmm2   # 0x2254a8
ucomisd %xmm1, %xmm2
ja 0x87697
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 0x87640
addsd 0x19de92(%rip), %xmm1   # 0x2254d0
jmp 0x8768e
ucomisd 0x19de68(%rip), %xmm1   # 0x2254b0
jae 0x87672
ucomisd 0x19de36(%rip), %xmm1   # 0x225488
jae 0x8767c
ucomisd 0x19de64(%rip), %xmm1   # 0x2254c0
jae 0x87686
ucomisd 0x19de1a(%rip), %xmm1   # 0x225480
jb 0x8768e
addsd 0x19de58(%rip), %xmm1   # 0x2254c8
jmp 0x8768e
addsd 0x19de06(%rip), %xmm1   # 0x225480
jmp 0x8768e
addsd 0x19de34(%rip), %xmm1   # 0x2254b8
jmp 0x8768e
addsd 0x19d542(%rip), %xmm1   # 0x224bd0
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