// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: Preorder_Merge(unsigned int, haplotype_evdience_alloc*, int)
void Preorder_Merge(uint32_t snpID, haplotype_evdience_alloc* hap, int is_merge) 
{ 
    int vectorID = hap->snp_stat.a[snpID].id;
    int8_t* vector = Get_SNP_Vector((*hap), vectorID);
    hap->dp.visit[snpID] = 1;
    

    if(is_merge)
    {
        if(hap->snp_stat.a[snpID].is_homopolymer)
        {
            hap->result_stat.homopolymer_num++;
        }
        else
        {
            hap->result_stat.non_homopolymer_num++;
        }
        
        hap->result_stat.score++;
        int flag;
        if((flag = debug_add_to_result_snp_vector(hap, vector, Get_SNP_Vector_Length((*hap))))!= -1)
        {
            fprintf(stderr, "incompatible snp vector....\n");
            exit(0);
        }
    }

    uint32_t* column;
    int j;

    if(hap->dp.backtrack_length[snpID] != 0)
    {
        column = Get_DP_Backtrack_Column(hap->dp, snpID);
        
        if(is_merge)
        {
            int add_ID = 0;
            for (j = 0; j < (int)hap->dp.backtrack_length[snpID]; j++)
            {
                if(hap->snp_stat.a[column[j]].is_homopolymer == 0)
                {
                    add_ID = j;
                }
            }

            for (j = 0; j < (int)hap->dp.backtrack_length[snpID]; j++)
            {
                if(j == add_ID)
                {
                    Preorder_Merge(column[j], hap, 1); 
                }
                else
                {
                    Preorder_Merge(column[j], hap, 0); 
                }
            }
        }
        else
        {
            for (j = 0; j < (int)hap->dp.backtrack_length[snpID]; j++)
            {
                Preorder_Merge(column[j], hap, 0); 
            }
        }
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rsi, %rbx
movl %edi, %r14d
movq 0x218(%rsi), %rcx
movl %edi, %r15d
leaq (%r15,%r15,4), %rax
movl (%rcx,%rax,8), %edi
movq 0x1d0(%rsi), %rsi
movl 0x1c8(%rbx), %ecx
movq 0x258(%rbx), %r8
movb $0x1, (%r8,%r15)
testl %edx, %edx
je 0x50309
imull %edi, %ecx
addq %rcx, %rsi
movq 0x218(%rbx), %rcx
xorl %edx, %edx
cmpb $0x0, 0x24(%rcx,%rax,8)
sete %dl
incl 0x200(%rbx,%rdx,4)
incl 0x208(%rbx)
movl 0x1c8(%rbx), %edx
movq %rbx, %rdi
callq 0x4ff29
cmpl $-0x1, %eax
jne 0x5035b
movq 0x278(%rbx), %rax
movl (%rax,%r15,4), %eax
testq %rax, %rax
je 0x50351
testl %eax, %eax
jle 0x50351
imull 0x250(%rbx), %r14d
shlq $0x2, %r14
addq 0x280(%rbx), %r14
movq 0x218(%rbx), %rdx
xorl %esi, %esi
xorl %ecx, %ecx
movl (%r14,%rsi,4), %edi
leaq (%rdi,%rdi,4), %rdi
cmpb $0x0, 0x24(%rdx,%rdi,8)
cmovel %esi, %ecx
incq %rsi
cmpq %rsi, %rax
jne 0x502be
testl %eax, %eax
jle 0x50351
movl %ecx, %r12d
xorl %r13d, %r13d
xorl %edx, %edx
cmpq %r13, %r12
sete %dl
movl (%r14,%r13,4), %edi
movq %rbx, %rsi
callq 0x50208
incq %r13
movq 0x278(%rbx), %rax
movslq (%rax,%r15,4), %rax
cmpq %rax, %r13
jl 0x502e0
jmp 0x50351
movq 0x278(%rbx), %rax
movl (%rax,%r15,4), %eax
testl %eax, %eax
je 0x50351
jle 0x50351
imull 0x250(%rbx), %r14d
shlq $0x2, %r14
addq 0x280(%rbx), %r14
xorl %r12d, %r12d
movl (%r14,%r12,4), %edi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x50208
incq %r12
movq 0x278(%rbx), %rax
movslq (%rax,%r15,4), %rax
cmpq %rax, %r12
jl 0x50330
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
callq 0x5b09