// File: /workspace/github_cpp_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movq %rsi, %rbx
movl %edi, %r14d
movq 0x218(%rsi), %rcx
movl %edi, %r15d
leaq (%r15,%r15,4), %rax
movl (%rcx,%rax,8), %edx
movq 0x1d0(%rsi), %rsi
movl 0x1c8(%rbx), %ecx
movq 0x258(%rbx), %rdi
movb $0x1, (%rdi,%r15)
testl %ebp, %ebp
je 0x51114
imull %edx, %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 0x50dc1
cmpl $-0x1, %eax
jne 0x511e6
movq 0x278(%rbx), %rax
movl (%rax,%r15,4), %eax
testq %rax, %rax
je 0x511d7
imull 0x250(%rbx), %r14d
shlq $0x2, %r14
addq 0x280(%rbx), %r14
testl %ebp, %ebp
je 0x511a5
xorl %r12d, %r12d
testl %eax, %eax
jle 0x5116b
movq 0x218(%rbx), %rcx
xorl %edx, %edx
movl (%r14,%rdx,4), %esi
leaq (%rsi,%rsi,4), %rsi
cmpb $0x0, 0x24(%rcx,%rsi,8)
cmovel %edx, %r12d
incq %rdx
cmpq %rdx, %rax
jne 0x5114f
movl %r12d, %r12d
movq 0x278(%rbx), %rax
cmpl $0x0, (%rax,%r15,4)
jle 0x511d7
xorl %r13d, %r13d
xorl %edx, %edx
cmpq %r13, %r12
sete %dl
movl (%r14,%r13,4), %edi
movq %rbx, %rsi
callq 0x51098
incq %r13
movq 0x278(%rbx), %rax
movslq (%rax,%r15,4), %rax
cmpq %rax, %r13
jl 0x5117c
jmp 0x511d7
movq 0x278(%rbx), %rax
cmpl $0x0, (%rax,%r15,4)
jle 0x511d7
xorl %r12d, %r12d
movl (%r14,%r12,4), %edi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x51098
incq %r12
movq 0x278(%rbx), %rax
movslq (%rax,%r15,4), %rax
cmpq %rax, %r12
jl 0x511b6
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5a49