// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: generate_result_vector(haplotype_evdience_alloc*, int)
void generate_result_vector(haplotype_evdience_alloc* hap, int pathLen)
{
    if(pathLen != hap->dp.current_snp_num)
    {
        fprintf(stderr, "error\n");
    }


    int8_t* vector = Get_Result_SNP_Vector((*hap));
    memset(vector, -1, Get_SNP_Vector_Length((*hap)));
    hap->result_stat.occ_0 = 0;
    hap->result_stat.occ_1 = 0;
    hap->result_stat.occ_2 = 0;
    hap->result_stat.score = pathLen;
    hap->result_stat.homopolymer_num = 0;
    hap->result_stat.non_homopolymer_num = 0;

    long long snpID1;
    long long j = 0;
    int flag, vectorID;
    int current_score;
    for (j = 0; j < pathLen; j++)
    {
        snpID1 = hap->dp.buffer[j];
        vectorID = hap->snp_stat.a[snpID1].id;
        vector = Get_SNP_Vector((*hap), vectorID);
        if(hap->snp_stat.a[snpID1].is_homopolymer)
        {
            hap->result_stat.homopolymer_num++;
        }
        else
        {
            hap->result_stat.non_homopolymer_num++;
        }

        if((flag = debug_add_to_result_snp_vector(hap, vector, Get_SNP_Vector_Length((*hap))))!= -1)
        {
            fprintf(stderr, "incompatible snp vector....\n");
            exit(0);
        }
    }
    hap->result_stat.overlap_num = hap->result_stat.occ_0 + hap->result_stat.occ_1;
    

    

    ///check if this is a useful snp vector
    if(hap->result_stat.overlap_num !=0 && filter_one_snp_advance_nearby(hap, hap->result_stat.occ_0 + 1, 
    hap->result_stat.occ_1, hap->result_stat.overlap_num + 1,
    hap->result_stat.homopolymer_num, hap->result_stat.non_homopolymer_num,
    hap->dp.buffer, pathLen))
    {
        current_score = calculate_score(hap->result_stat.occ_0 + 1, hap->result_stat.occ_1);
        ///first useful snp vector
        if(hap->dp.max_snp_num < pathLen)
        {
            hap->dp.max_snp_num = pathLen;
            hap->dp.max_score = current_score;
            memcpy(hap->dp.max_buffer, hap->dp.buffer, sizeof(uint32_t) * pathLen);
        }///if we have multiple single best snp vector, select the vector with max score
        else if(hap->dp.max_snp_num == pathLen)
        {
            if(current_score > hap->dp.max_score)
            {
                hap->dp.max_score = current_score;
                memcpy(hap->dp.max_buffer, hap->dp.buffer, sizeof(uint32_t) * pathLen);
            }
        }
    }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
cmpl %esi, 0x2a8(%rdi)
jne 0x50639
movq 0x1e0(%rbx), %rdi
movl 0x1c8(%rbx), %edx
movl $0xff, %esi
callq 0x20e0
movl %ebp, 0x208(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x1f4(%rbx)
movl $0x0, 0x204(%rbx)
movslq %ebp, %r14
testl %r14d, %r14d
jle 0x50570
xorl %r15d, %r15d
movq 0x290(%rbx), %rax
movl (%rax,%r15,4), %eax
movq 0x218(%rbx), %rcx
leaq (%rax,%rax,4), %rax
movl 0x1c8(%rbx), %edx
movl (%rcx,%rax,8), %esi
imull %edx, %esi
addq 0x1d0(%rbx), %rsi
xorl %edi, %edi
cmpb $0x0, 0x24(%rcx,%rax,8)
sete %dil
incl 0x200(%rbx,%rdi,4)
movq %rbx, %rdi
callq 0x4ff29
cmpl $-0x1, %eax
jne 0x506e6
incq %r15
cmpq %r15, %r14
jne 0x5050e
movl 0x1f4(%rbx), %ecx
movl 0x1f8(%rbx), %eax
jmp 0x50574
xorl %eax, %eax
xorl %ecx, %ecx
movl %eax, %esi
addl %ecx, %esi
movl %esi, 0x1f0(%rbx)
je 0x506db
incl %ecx
incl %esi
movl %ecx, %edx
subl %eax, %edx
movl %eax, %edi
cmovll %ecx, %edi
cvtsi2sd %edi, %xmm1
cvtsi2sd %esi, %xmm2
movapd %xmm1, %xmm0
divsd %xmm2, %xmm0
cmpl $0x5, %edi
jl 0x505b9
cmpl $0xa, %esi
jl 0x506db
movsd 0x1e1029(%rip), %xmm2   # 0x2315e0
jmp 0x505d3
cmpl $0xa, %esi
jl 0x506db
cmpl $0x4, %ecx
jl 0x506db
movsd 0x1e1005(%rip), %xmm2   # 0x2315d8
ucomisd %xmm0, %xmm2
ja 0x506db
movl %eax, %edi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
addl %ecx, %edi
je 0x50699
xorps %xmm0, %xmm0
cvtsi2sd %edi, %xmm0
divsd %xmm0, %xmm1
movsd 0x1e0621(%rip), %xmm2   # 0x230c20
ucomisd %xmm1, %xmm2
jb 0x50617
movsd 0x1e0f9b(%rip), %xmm2   # 0x2315a8
ucomisd %xmm1, %xmm2
ja 0x50699
movl %edx, %esi
negl %esi
cmovnsl %edx, %esi
addl %esi, %edi
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
divsd %xmm0, %xmm1
cmpl %eax, %ecx
jne 0x50643
addsd 0x1e0f99(%rip), %xmm1   # 0x2315d0
jmp 0x50691
callq 0x5b2d
jmp 0x504d0
ucomisd 0x1e0f65(%rip), %xmm1   # 0x2315b0
jae 0x50675
ucomisd 0x1e0f33(%rip), %xmm1   # 0x231588
jae 0x5067f
ucomisd 0x1e0f61(%rip), %xmm1   # 0x2315c0
jae 0x50689
ucomisd 0x1e0f17(%rip), %xmm1   # 0x231580
jb 0x50691
addsd 0x1e0f55(%rip), %xmm1   # 0x2315c8
jmp 0x50691
addsd 0x1e0f03(%rip), %xmm1   # 0x231580
jmp 0x50691
addsd 0x1e0f31(%rip), %xmm1   # 0x2315b8
jmp 0x50691
addsd 0x1e057f(%rip), %xmm1   # 0x230c10
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %esi
cmpl %ebp, 0x2a0(%rbx)
jge 0x506d1
movl %ebp, 0x2a0(%rbx)
movl %esi, 0x2a4(%rbx)
movq 0x290(%rbx), %rsi
movq 0x298(%rbx), %rdi
shlq $0x2, %r14
movq %r14, %rdx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2160
jne 0x506db
cmpl 0x2a4(%rbx), %esi
jg 0x506a7
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x5b49