// File: /workspace/github_cpp_makefile_star2_O1/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 0x514c5
movq 0x1e0(%rbx), %rdi
movl 0x1c8(%rbx), %edx
movl $0xff, %esi
callq 0x20e0
xorl %eax, %eax
movq %rax, 0x1f4(%rbx)
movl $0x0, 0x1fc(%rbx)
movl %ebp, 0x208(%rbx)
movq %rax, 0x200(%rbx)
movslq %ebp, %r14
testl %r14d, %r14d
jle 0x513f4
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 0x50dc1
cmpl $-0x1, %eax
jne 0x51572
incq %r15
cmpq %r15, %r14
jne 0x513a0
movl 0x1f4(%rbx), %eax
movl 0x1f8(%rbx), %ecx
movl %ecx, %esi
addl %eax, %esi
movl %esi, 0x1f0(%rbx)
je 0x51567
incl %eax
incl %esi
movl %eax, %edx
subl %ecx, %edx
movl %ecx, %edi
cmovll %eax, %edi
cvtsi2sd %edi, %xmm1
cvtsi2sd %esi, %xmm2
movapd %xmm1, %xmm0
divsd %xmm2, %xmm0
cmpl $0x5, %edi
jl 0x51445
cmpl $0xa, %esi
jl 0x51567
movsd 0x1d409d(%rip), %xmm2   # 0x2254e0
jmp 0x5145f
cmpl $0xa, %esi
jl 0x51567
cmpl $0x4, %eax
jl 0x51567
movsd 0x1d4079(%rip), %xmm2   # 0x2254d8
ucomisd %xmm0, %xmm2
ja 0x51567
movl %ecx, %edi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
addl %eax, %edi
je 0x51525
xorps %xmm0, %xmm0
cvtsi2sd %edi, %xmm0
divsd %xmm0, %xmm1
movsd 0x1d3755(%rip), %xmm2   # 0x224be0
ucomisd %xmm1, %xmm2
jb 0x514a3
movsd 0x1d400f(%rip), %xmm2   # 0x2254a8
ucomisd %xmm1, %xmm2
ja 0x51525
movl %edx, %esi
negl %esi
cmovnsl %edx, %esi
addl %esi, %edi
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
divsd %xmm0, %xmm1
cmpl %ecx, %eax
jne 0x514cf
addsd 0x1d400d(%rip), %xmm1   # 0x2254d0
jmp 0x5151d
callq 0x5a6d
jmp 0x5135e
ucomisd 0x1d3fd9(%rip), %xmm1   # 0x2254b0
jae 0x51501
ucomisd 0x1d3fa7(%rip), %xmm1   # 0x225488
jae 0x5150b
ucomisd 0x1d3fd5(%rip), %xmm1   # 0x2254c0
jae 0x51515
ucomisd 0x1d3f8b(%rip), %xmm1   # 0x225480
jb 0x5151d
addsd 0x1d3fc9(%rip), %xmm1   # 0x2254c8
jmp 0x5151d
addsd 0x1d3f77(%rip), %xmm1   # 0x225480
jmp 0x5151d
addsd 0x1d3fa5(%rip), %xmm1   # 0x2254b8
jmp 0x5151d
addsd 0x1d36b3(%rip), %xmm1   # 0x224bd0
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %esi
cmpl %ebp, 0x2a0(%rbx)
jge 0x5155d
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 0x51567
cmpl 0x2a4(%rbx), %esi
jg 0x51533
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x5a89