// File: /workspace/github_cpp_makefile_star2_O2/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 0x535b6
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq 0x218(%rdi), %r13
movq 0x220(%rdi), %rax
cmpq 0x228(%rdi), %rax
movl %ecx, 0x4(%rsp)
jne 0x533e9
leaq (%rax,%rax), %rcx
testq %rax, %rax
pushq $0x2
popq %rax
cmovneq %rcx, %rax
movq %rax, 0x228(%rbx)
imulq $0x28, %rax, %rsi
movq %r13, %rdi
movq %r8, %r12
callq 0x2370
movq %r12, %r8
movq %rax, %r13
movq %rax, 0x218(%rbx)
movq 0x220(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x220(%rbx)
imulq $0x28, %rax, %rbp
movq %r13, %r12
addq %rbp, %r12
movl %eax, (%r13,%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%r13,%rbp)
movl (%r15), %edi
movl %edi, 0x20(%r13,%rbp)
movq (%r8), %rsi
movq 0x8(%r8), %rdx
callq 0x52f6d
movb %al, 0x24(%r13,%rbp)
movl (%r13,%rbp), %ecx
movl 0x1c8(%rbx), %eax
imull %ecx, %eax
addq 0x1d0(%rbx), %rax
addq $0x4, %r15
movl 0x4(%rsp), %edi
subq $0x1, %r14
jb 0x534ce
movzbl 0x8(%r15), %ecx
cmpl $0x1, %ecx
je 0x53479
testl %ecx, %ecx
jne 0x5349e
movl (%r15), %ecx
movb $0x0, (%rax,%rcx)
movq 0x218(%rbx), %rdx
movl (%r12), %ecx
imulq $0x28, %rcx, %rsi
addq %rdx, %rsi
addq $0x8, %rsi
jmp 0x534bb
cmpb %dil, 0x10(%r15)
jne 0x5349e
movl (%r15), %ecx
movb $0x1, (%rax,%rcx)
movq 0x218(%rbx), %rdx
movl (%r12), %ecx
imulq $0x28, %rcx, %rsi
addq %rdx, %rsi
addq $0xc, %rsi
jmp 0x534bb
movl (%r15), %ecx
movb $0x2, (%rax,%rcx)
movq 0x218(%rbx), %rdx
movl (%r12), %ecx
imulq $0x28, %rcx, %rsi
addq %rdx, %rsi
addq $0x10, %rsi
incl (%rsi)
imulq $0x28, %rcx, %rsi
incl 0x4(%rdx,%rsi)
addq $0x18, %r15
jmp 0x53442
movq 0x218(%rbx), %rax
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
movl 0x8(%rax,%rcx), %esi
movl 0xc(%rax,%rcx), %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 0x18f6f4(%rip), %xmm2   # 0x1e2c00
ucomisd %xmm1, %xmm2
jb 0x53525
movsd 0x18ffde(%rip), %xmm2   # 0x1e34f8
ucomisd %xmm1, %xmm2
jbe 0x53525
pushq $-0x1
popq %rdx
jmp 0x535a4
incl 0x1c4(%rbx)
movl %r8d, %r9d
negl %r9d
cmovnsl %r8d, %r9d
addl %r9d, %edi
cvtsi2sd %edi, %xmm1
divsd %xmm0, %xmm1
cmpl %edx, %esi
jne 0x5354e
addsd 0x18ffd4(%rip), %xmm1   # 0x1e3520
jmp 0x5359c
ucomisd 0x18ffaa(%rip), %xmm1   # 0x1e3500
jae 0x53580
ucomisd 0x18ff78(%rip), %xmm1   # 0x1e34d8
jae 0x5358a
ucomisd 0x18ffa6(%rip), %xmm1   # 0x1e3510
jae 0x53594
ucomisd 0x18ff5c(%rip), %xmm1   # 0x1e34d0
jb 0x5359c
addsd 0x18ff9a(%rip), %xmm1   # 0x1e3518
jmp 0x5359c
addsd 0x18ff48(%rip), %xmm1   # 0x1e34d0
jmp 0x5359c
addsd 0x18ff76(%rip), %xmm1   # 0x1e3508
jmp 0x5359c
addsd 0x18f654(%rip), %xmm1   # 0x1e2bf0
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %edx
movl %edx, 0x1c(%rax,%rcx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq