// File: /workspace/github_c_makefile_star2_O3/dapogon[P]cellcoal/src/cellcoal.c
// Function: SimulateSignatureISMforSite
void SimulateSignatureISMforSite (TreeNode *p, int genome, int site, int newState, long int *seed)
	{
    static double	cumBranchLength, uniform;
    int             cell, anccell, ancState;
	
    if (p != NULL)
        {
        cell = p->label;
			
        if (p->isHealthyRoot == YES)
            {
            cumBranchLength = 0;
             uniform = RandomUniform(seed) * totalTreeLength;
			//fprintf (stderr, "\nsimulating at root of position %d", site+1);
            }
        else
            {
            anccell = p->anc->label;
            ancState = data[genome][anccell][site];
            cumBranchLength += p->branchLength;
				
            if (cumBranchLength < uniform || allSites[site].numMutations > 0)/* => there will be no change; forcing ISM diploid */
                {
                data[genome][cell][site] = ancState;
 				//fprintf (stderr, "\ncopying ancstate %c", WhichNuc(ancstate));
               }
            else /* => there will be change */
                {
				data[genome][cell][site] = newState;
                if (genome == MATERNAL)
                    allSites[site].numMutationsMaternal++;
                else if (genome == PATERNAL)
                    allSites[site].numMutationsPaternal++;
                allSites[site].numMutations++;
                numMU++;
				//fprintf (stderr, "\nchange at site %d from %c to %c  (numMU = %d)", site+1, WhichNuc(ancState), WhichNuc(newState), numMU);
 				}
            }
        SimulateSignatureISMforSite (p->left, genome, site, newState, seed);
        SimulateSignatureISMforSite (p->right, genome, site, newState, seed);
		}
	}

// Assembly:
testq %rdi, %rdi
je 0x1788e
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %rbx
movl %ecx, %ebp
movl %edx, %r14d
movl %esi, %r15d
movq %rdi, %r12
movq 0x1fea1(%rip), %rax     # 0x375b8
movq %rax, 0x20(%rsp)
movl %esi, %eax
movq %rax, 0x18(%rsp)
movslq %edx, %r13
movsd 0x1fe72(%rip), %xmm0    # 0x375a0
movsd %xmm0, 0x10(%rsp)
movq %r13, %rax
shlq $0x7, %rax
leaq (%rax,%r13,8), %rax
movq %rax, 0x8(%rsp)
cmpl $0x1, 0x24(%r12)
jne 0x177c6
movq $0x0, 0x20059(%rip) # 0x377b0
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
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movq %rax, (%rbx)
divsd 0xb96a(%rip), %xmm0     # 0x23120
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x1fff4(%rip)    # 0x377b8
jmp 0x1782a
movslq 0x1c(%r12), %rax
movq 0x10(%r12), %rcx
movslq 0x1c(%rcx), %rdx
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rsi
movq (%rcx,%rsi,8), %rcx
movq (%rcx,%rdx,8), %rdx
movl (%rdx,%r13,4), %esi
movsd 0x40(%r12), %xmm0
addsd 0x1ffb7(%rip), %xmm0    # 0x377b0
movsd %xmm0, 0x1ffaf(%rip)    # 0x377b0
movsd 0x1ffaf(%rip), %xmm1    # 0x377b8
ucomisd %xmm0, %xmm1
ja 0x17822
movq 0x1fdaa(%rip), %rdx     # 0x375c0
movq 0x8(%rsp), %rdi
cmpl $0x0, 0xc(%rdx,%rdi)
jle 0x1784e
movq (%rcx,%rax,8), %rax
movl %esi, (%rax,%r13,4)
movq (%r12), %rdi
movl %r15d, %esi
movl %r14d, %edx
movl %ebp, %ecx
movq %rbx, %r8
callq 0x176eb
movq 0x8(%r12), %r12
testq %r12, %r12
jne 0x17744
jmp 0x17880
movq (%rcx,%rax,8), %rax
movl %ebp, (%rax,%r13,4)
testl %r15d, %r15d
je 0x17866
movq 0x8(%rsp), %rax
incl 0x14(%rdx,%rax)
jmp 0x1786f
movq 0x8(%rsp), %rax
incl 0x10(%rdx,%rax)
addq %rdx, %rax
addq $0xc, %rax
incl (%rax)
incl 0x1fd02(%rip)           # 0x37580
jmp 0x1782a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq