// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %rbx
movl %ecx, %ebp
movl %esi, %r15d
movq %rdi, %r12
movq 0x1d6ad(%rip), %rax     # 0x315b8
movq %rax, 0x20(%rsp)
movl %esi, %eax
movq %rax, 0x18(%rsp)
movl %edx, 0xc(%rsp)
movslq %edx, %r13
movsd 0x1d67a(%rip), %xmm0    # 0x315a0
movsd %xmm0, 0x10(%rsp)
imulq $0x88, %r13, %rdi
movq %rdi, %r14
testq %r12, %r12
je 0x14011
cmpl $0x1, 0x24(%r12)
jne 0x13f67
andq $0x0, 0x1d861(%rip)     # 0x317b0
movq %rbx, %rdi
callq 0x10279
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x1d853(%rip)    # 0x317b8
jmp 0x13fc6
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 0x1d816(%rip), %xmm0    # 0x317b0
movsd %xmm0, 0x1d80e(%rip)    # 0x317b0
movsd 0x1d80e(%rip), %xmm1    # 0x317b8
ucomisd %xmm0, %xmm1
ja 0x13fbe
movq 0x1d609(%rip), %rdx     # 0x315c0
cmpl $0x0, 0xc(%rdx,%rdi)
jle 0x13fe8
movq (%rcx,%rax,8), %rax
movl %esi, (%rax,%r13,4)
movq (%r12), %rdi
movl %r15d, %esi
movl 0xc(%rsp), %edx
movl %ebp, %ecx
movq %rbx, %r8
callq 0x13eeb
movq 0x8(%r12), %r12
movq %r14, %rdi
jmp 0x13f36
movq (%rcx,%rax,8), %rax
movl %ebp, (%rax,%r13,4)
testl %r15d, %r15d
je 0x13ffb
incl 0x14(%rdx,%rdi)
jmp 0x13fff
incl 0x10(%rdx,%rdi)
leaq (%rdx,%rdi), %rax
addq $0xc, %rax
incl (%rax)
incl 0x1d571(%rip)           # 0x31580
jmp 0x13fc6
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq