// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: generate_haplotypes_naive(haplotype_evdience_alloc*, overlap_region_alloc*, All_reads*, long long, int)
int generate_haplotypes_naive(haplotype_evdience_alloc* hap, overlap_region_alloc* overlap_list, All_reads* R_INF, long long rLen, 
int force_repeat)
{
    int j, i;

    
    if(hap->snp_stat.n == 0)
    {
        return 0;
    }

    ///if hap->available_snp == 1, the following codes would have bugs
    ///filter snps that are highly likly false 
    if(hap->snp_stat.n > 1)
    {
        i = 0;
        ///if a snp is very close to others, it should not be a real snp
        for (j = 0; j < (int)hap->snp_stat.n; j++)
        {
            
            if(j > 0 && j + 1 < (int)hap->snp_stat.n)
            {
                if(hap->snp_stat.a[j].site != hap->snp_stat.a[j - 1].site + 1
                    &&
                hap->snp_stat.a[j].site + 1 != hap->snp_stat.a[j + 1].site)
                {
                    hap->snp_stat.a[i] = hap->snp_stat.a[j];
                    i++;
                }

            }
            else if(j == 0)
            {
                if(hap->snp_stat.a[j].site + 1 != hap->snp_stat.a[j + 1].site)
                {
                    hap->snp_stat.a[i] = hap->snp_stat.a[j];
                    i++;
                }
            }
            else
            {
                if(hap->snp_stat.a[j].site != hap->snp_stat.a[j - 1].site + 1)
                {
                    hap->snp_stat.a[i] = hap->snp_stat.a[j];
                    i++;
                }
            }
        }
        hap->snp_stat.n = i;
    }


    long long m;
    if(hap->snp_stat.n > 0)
    {
        ///************************debug**************************///
        m = 0;
        for (i = 0; i < (int)hap->snp_stat.n; i++)
        {
            if(check_informative_site(hap, &(hap->snp_stat.a[i])))
            {
                hap->snp_stat.a[m] = hap->snp_stat.a[i];
                m++;
            }
        }
        hap->snp_stat.n = m;
        ///************************debug**************************///



        init_DP_matrix(&(hap->dp), hap->snp_stat.n);

        for (i = 0; i < (int)hap->snp_stat.n; i++)
        {
            hap->dp.max_buffer[i] = i;
        }
        hap->dp.max_snp_num = hap->snp_stat.n;
        remove_reads(hap, hap->dp.max_buffer, hap->dp.max_snp_num, overlap_list);

        return 1;

    }
    else
    {
        return 0;
    }

}

// Assembly:
movq 0x220(%rdi), %rcx
xorl %eax, %eax
testq %rcx, %rcx
je 0x51507
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
cmpq $0x1, %rcx
jne 0x51427
xorl %eax, %eax
xorl %esi, %esi
movq 0x218(%r14), %rdx
leaq (%rax,%rax,4), %r8
movl (%rdx,%r8,8), %edi
movl 0x1c8(%r14), %r9d
imulq %r9, %rdi
addq 0x1d0(%r14), %rdi
movq $0x0, 0x8(%rdx,%r8,8)
movl $0x0, 0x10(%rdx,%r8,8)
testq %r9, %r9
je 0x5133b
leaq (%rdx,%r8,8), %r8
xorl %r10d, %r10d
xorl %r11d, %r11d
xorl %ebp, %ebp
xorl %r15d, %r15d
movzbl (%rdi,%r15), %r12d
cmpl $0x2, %r12d
je 0x512eb
cmpl $0x1, %r12d
je 0x512e2
testl %r12d, %r12d
jne 0x512f1
incl %r10d
movl %r10d, 0x8(%r8)
jmp 0x512f1
incl %r11d
movl %r11d, 0xc(%r8)
jmp 0x512f1
incl %ebp
movl %ebp, 0x10(%r8)
incq %r15
cmpq %r15, %r9
jne 0x512c3
cmpl $0x2, %r10d
setb %dil
cmpl $0x2, %r11d
setb %r9b
testb %r9b, %dil
jne 0x5133b
leaq (%rsi,%rsi,4), %rcx
movq 0x20(%r8), %rdi
movq %rdi, 0x20(%rdx,%rcx,8)
movdqu (%r8), %xmm0
movdqu 0x10(%r8), %xmm1
movdqu %xmm1, 0x10(%rdx,%rcx,8)
movdqu %xmm0, (%rdx,%rcx,8)
incq %rsi
movq 0x220(%r14), %rcx
incq %rax
movslq %ecx, %rdx
cmpq %rdx, %rax
jl 0x51278
movq %rsi, 0x220(%r14)
leaq 0x250(%r14), %rdi
callq 0x86db2
movq 0x220(%r14), %rax
movq 0x298(%r14), %rsi
testl %eax, %eax
jle 0x51408
movl %eax, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leal 0x1(%rax), %ecx
andl $-0x2, %ecx
decq %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqa 0x1dff3a(%rip), %xmm1   # 0x2312d0
xorl %edx, %edx
movdqa 0x1dff40(%rip), %xmm2   # 0x2312e0
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x1e0150(%rip), %xmm4   # 0x231500
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %edi
notl %edi
testb $0x1, %dil
je 0x513e5
movl %edx, (%rsi,%rdx,4)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %edi
testb $0x1, %dil
je 0x513fb
leal 0x1(%rdx), %edi
movl %edi, 0x4(%rsi,%rdx,4)
addq $0x2, %rdx
paddq %xmm4, %xmm1
cmpq %rdx, %rcx
jne 0x513b0
movl %eax, 0x2a0(%r14)
movslq %eax, %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x508dd
movl $0x1, %eax
jmp 0x514ff
testl %ecx, %ecx
jle 0x514f0
xorl %edx, %edx
movl $0x1, %esi
xorl %eax, %eax
testq %rdx, %rdx
je 0x5146e
movslq %ecx, %r10
movq 0x218(%r14), %rcx
leaq (%rcx,%rdx), %rdi
movl -0x8(%rcx,%rdx), %r9d
movl 0x20(%rcx,%rdx), %r8d
incl %r9d
cmpq %r10, %rsi
jge 0x514cc
cmpl %r9d, %r8d
je 0x514ac
incl %r8d
cmpl 0x48(%rcx,%rdx), %r8d
jne 0x51485
jmp 0x514ac
movq 0x218(%r14), %rcx
movl 0x20(%rcx), %r8d
incl %r8d
movq %rcx, %rdi
cmpl 0x48(%rcx), %r8d
je 0x514ac
cltq
leaq (%rax,%rax,4), %r8
movq 0x20(%rdi), %r9
movq %r9, 0x20(%rcx,%r8,8)
movdqu (%rdi), %xmm0
movdqu 0x10(%rdi), %xmm1
movdqu %xmm1, 0x10(%rcx,%r8,8)
movdqu %xmm0, (%rcx,%r8,8)
incl %eax
movq 0x220(%r14), %rcx
movslq %ecx, %rdi
addq $0x28, %rdx
leaq 0x1(%rsi), %r8
cmpq %rdi, %rsi
movq %r8, %rsi
jl 0x51438
jmp 0x514d3
cmpl %r9d, %r8d
jne 0x51485
jmp 0x514ac
movslq %eax, %rcx
movq %rcx, 0x220(%r14)
testl %ecx, %ecx
je 0x514fd
testl %eax, %eax
jg 0x51274
xorl %esi, %esi
jmp 0x5134a
movq $0x0, 0x220(%r14)
jmp 0x514ff
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq