// File: /workspace/github_c_makefile_star2_O1/dapogon[P]cellcoal/src/cellcoal.c
// Function: SimulateISMDNAforSite
void SimulateISMDNAforSite (TreeNode *p, int genome, int site, int doISMhaploid, long int *seed)
	{
    static double	cumBranchLength, uniform, ran;
    int             j, cell, anccell, ancstate;
	
    if (p != NULL)
        {
        cell = p->label;
			
        if (p->isHealthyRoot == YES)
            {
            cumBranchLength = 0;
            uniform = RandomUniform(seed) * totalTreeLength;
            }
        else
            {
            anccell = p->anc->label;
            ancstate = data[genome][anccell][site];
            cumBranchLength += p->branchLength;
				
            if ((cumBranchLength < uniform) || /* => there will be no change */
                ((doISMhaploid == NO)  && (allSites[site].numMutations > 0))  ||
                ((doISMhaploid == YES) && (genome == MATERNAL) && (allSites[site].numMutationsMaternal > 0)) ||
                ((doISMhaploid == YES) && (genome == PATERNAL) && (allSites[site].numMutationsPaternal > 0)))
                {
                data[genome][cell][site] = ancstate;
                }
            else /* => there will be change */
                {
                ran = RandomUniform(seed) * cumMij[ancstate][3];
                for (j=0; j<4; j++)
                    {
                    if (ran <= cumMij[ancstate][j])
                        {
                        data[genome][cell][site] = j;
                        break;
                        }
					}
                if (genome == MATERNAL)
                    allSites[site].numMutationsMaternal++;
                else if (genome == PATERNAL)
                    allSites[site].numMutationsPaternal++;
                allSites[site].numMutations++;
                numMU++;
 				}
            }
        SimulateISMDNAforSite (p->left, genome, site, doISMhaploid, seed);
        SimulateISMDNAforSite (p->right, genome, site, doISMhaploid, seed);
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %rbx
movl %ecx, %ebp
movl %esi, %r15d
movq %rdi, %r12
movl %esi, %eax
movq %rax, 0x10(%rsp)
movl %edx, 0xc(%rsp)
movslq %edx, %r13
movq %r13, %rax
shlq $0x7, %rax
leaq (%rax,%r13,8), %r9
movl %ecx, %eax
xorl $0x1, %eax
movl %eax, 0x4(%rsp)
movl %esi, %eax
xorl $0x1, %eax
movl %eax, 0x8(%rsp)
movq %r9, %r14
testq %r12, %r12
je 0x17802
cmpl $0x1, 0x24(%r12)
jne 0x17661
movq $0x0, 0x2c1d0(%rip) # 0x437c0
movq (%rbx), %rcx
movq %rcx, %rax
movabsq $0x41a705af1fe3fb79, %rdx # imm = 0x41A705AF1FE3FB79
imulq %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0xf, %rdx
addq %rax, %rdx
imulq $0x1f31d, %rdx, %rax    # imm = 0x1F31D
subq %rax, %rcx
imulq $0x41a7, %rcx, %rax     # imm = 0x41A7
imulq $-0xb14, %rdx, %rcx     # imm = 0xF4EC
leaq (%rcx,%rax), %rdx
testq %rdx, %rdx
leaq 0x7fffffff(%rcx,%rax), %rax
cmovgq %rdx, %rax
movq %rax, (%rbx)
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x1c9d9(%rip), %xmm0    # 0x34028
mulsd 0x2bf49(%rip), %xmm0    # 0x435a0
movsd %xmm0, 0x2c169(%rip)    # 0x437c8
jmp 0x176b4
movslq 0x1c(%r12), %rsi
movq 0x10(%r12), %rax
movslq 0x1c(%rax), %rax
movq 0x2bf42(%rip), %rcx     # 0x435b8
movq 0x10(%rsp), %rdx
movq (%rcx,%rdx,8), %rdi
movq (%rdi,%rax,8), %rax
movl (%rax,%r13,4), %eax
movsd 0x40(%r12), %xmm0
addsd 0x2c12a(%rip), %xmm0    # 0x437c0
movsd %xmm0, 0x2c122(%rip)    # 0x437c0
movsd 0x2c122(%rip), %xmm1    # 0x437c8
ucomisd %xmm0, %xmm1
jbe 0x176d6
movq (%rdi,%rsi,8), %rcx
movl %eax, (%rcx,%r13,4)
movq (%r12), %rdi
movl %r15d, %esi
movl 0xc(%rsp), %edx
movl %ebp, %ecx
movq %rbx, %r8
callq 0x1758d
movq 0x8(%r12), %r12
movq %r14, %r9
jmp 0x175d4
testl %ebp, %ebp
je 0x177a6
movl %r15d, %ecx
orl 0x4(%rsp), %ecx
jne 0x176f6
movq 0x2bed2(%rip), %rcx     # 0x435c0
cmpl $0x0, 0x10(%rcx,%r9)
jg 0x176ac
movl 0x8(%rsp), %ecx
orl 0x4(%rsp), %ecx
jne 0x1770f
movq 0x2beb9(%rip), %rcx     # 0x435c0
cmpl $0x0, 0x14(%rcx,%r9)
jg 0x176ac
movslq %eax, %r8
movq (%rbx), %rcx
movq %rcx, %rax
movabsq $0x41a705af1fe3fb79, %rdx # imm = 0x41A705AF1FE3FB79
imulq %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0xf, %rdx
addq %rax, %rdx
imulq $0x1f31d, %rdx, %rax    # imm = 0x1F31D
subq %rax, %rcx
imulq $0x41a7, %rcx, %rax     # imm = 0x41A7
imulq $-0xb14, %rdx, %rcx     # imm = 0xF4EC
leaq (%rcx,%rax), %rdx
testq %rdx, %rdx
leaq 0x7fffffff(%rcx,%rax), %rax
cmovgq %rdx, %rax
movq %rax, (%rbx)
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x1c8b7(%rip), %xmm0    # 0x34028
shlq $0x5, %r8
leaq 0x2ae44(%rip), %rax     # 0x425c0
mulsd 0x18(%r8,%rax), %xmm0
xorl %eax, %eax
leaq (%r8,%rax,8), %rcx
leaq 0x2ae30(%rip), %rdx     # 0x425c0
movsd (%rdx,%rcx), %xmm1
ucomisd %xmm0, %xmm1
jae 0x177be
incq %rax
cmpq $0x4, %rax
jne 0x17785
jmp 0x177c6
movq 0x2be13(%rip), %rcx     # 0x435c0
cmpl $0x0, 0xc(%rcx,%r9)
jg 0x176ac
jmp 0x176de
movq (%rdi,%rsi,8), %rcx
movl %eax, (%rcx,%r13,4)
testl %r15d, %r15d
je 0x177df
cmpl $0x1, %r15d
jne 0x177eb
movq 0x2bde8(%rip), %rax     # 0x435c0
incl 0x14(%rax,%r9)
jmp 0x177eb
movq 0x2bdda(%rip), %rax     # 0x435c0
incl 0x10(%rax,%r9)
movq 0x2bdce(%rip), %rax     # 0x435c0
incl 0xc(%rax,%r9)
incl 0x2bd83(%rip)           # 0x43580
jmp 0x176b4
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq