// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x2a8(%rcx), %eax
je 0x3eb06
movq 0x3854eb(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x343ae6(%rip), %rsi    # 0x3825e5
movb $0x0, %al
callq 0x22a0
movq -0x8(%rbp), %rax
movq 0x1e0(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x1c8(%rax), %eax
movl %eax, %edx
movl $0xff, %esi
callq 0x2100
movq -0x8(%rbp), %rax
movl $0x0, 0x1f4(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x1f8(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x1fc(%rax)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x208(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x200(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x204(%rax)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movslq -0xc(%rbp), %rcx
cmpq %rcx, %rax
jge 0x3ec85
movq -0x8(%rbp), %rax
movq 0x290(%rax), %rax
movq -0x28(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
imulq $0x28, -0x20(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x1d0(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x1c8(%rcx), %ecx
imull -0x30(%rbp), %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
imulq $0x28, -0x20(%rbp), %rcx
addq %rcx, %rax
cmpb $0x0, 0x24(%rax)
je 0x3ec21
movq -0x8(%rbp), %rax
movl 0x200(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x200(%rax)
jmp 0x3ec34
movq -0x8(%rbp), %rax
movl 0x204(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x204(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x8(%rbp), %rax
movl 0x1c8(%rax), %edx
callq 0x3e280
movl %eax, -0x2c(%rbp)
cmpl $-0x1, %eax
je 0x3ec72
movq 0x385386(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x343b4e(%rip), %rsi    # 0x3827b2
movb $0x0, %al
callq 0x22a0
xorl %edi, %edi
callq 0x2240
jmp 0x3ec74
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x3eb92
movq -0x8(%rbp), %rax
movl 0x1f4(%rax), %ecx
movq -0x8(%rbp), %rax
addl 0x1f8(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x1f0(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x1f0(%rax)
je 0x3eddb
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x1f4(%rax), %esi
addl $0x1, %esi
movq -0x8(%rbp), %rax
movl 0x1f8(%rax), %edx
movq -0x8(%rbp), %rax
movl 0x1f0(%rax), %ecx
addl $0x1, %ecx
movq -0x8(%rbp), %rax
movl 0x200(%rax), %eax
movl %eax, %r8d
movq -0x8(%rbp), %rax
movl 0x204(%rax), %eax
movl %eax, %r9d
movq -0x8(%rbp), %rax
movq 0x290(%rax), %r10
movl -0xc(%rbp), %eax
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0xa1670
cmpl $0x0, %eax
je 0x3eddb
movq -0x8(%rbp), %rax
movl 0x1f4(%rax), %edi
addl $0x1, %edi
movq -0x8(%rbp), %rax
movl 0x1f8(%rax), %esi
callq 0xa1740
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movl 0x2a0(%rax), %eax
cmpl -0xc(%rbp), %eax
jge 0x3ed87
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x2a0(%rax)
movl -0x34(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x2a4(%rax)
movq -0x8(%rbp), %rax
movq 0x298(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x290(%rax), %rsi
movslq -0xc(%rbp), %rdx
shlq $0x2, %rdx
callq 0x2180
jmp 0x3edd9
movq -0x8(%rbp), %rax
movl 0x2a0(%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0x3edd7
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x2a4(%rcx), %eax
jle 0x3edd5
movl -0x34(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x2a4(%rax)
movq -0x8(%rbp), %rax
movq 0x298(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x290(%rax), %rsi
movslq -0xc(%rbp), %rdx
shlq $0x2, %rdx
callq 0x2180
jmp 0x3edd7
jmp 0x3edd9
jmp 0x3eddb
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)