// File: /workspace/github_c_makefile_star2_O1/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 $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), %rdi
movq %rdi, %r14
testq %r12, %r12
je 0x1757e
cmpl $0x1, 0x24(%r12)
jne 0x174d2
movq $0x0, 0x2c34f(%rip) # 0x437b0
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 0x1cb68(%rip), %xmm0    # 0x34028
mulsd 0x2c0d8(%rip), %xmm0    # 0x435a0
movsd %xmm0, 0x2c2e8(%rip)    # 0x437b8
jmp 0x17533
movslq 0x1c(%r12), %rax
movq 0x10(%r12), %rcx
movslq 0x1c(%rcx), %rdx
movq 0x2c0d1(%rip), %rcx     # 0x435b8
movq 0x10(%rsp), %rsi
movq (%rcx,%rsi,8), %rcx
movq (%rcx,%rdx,8), %rdx
movl (%rdx,%r13,4), %edx
movsd 0x40(%r12), %xmm0
addsd 0x2c2a9(%rip), %xmm0    # 0x437b0
movsd %xmm0, 0x2c2a1(%rip)    # 0x437b0
movsd 0x2c2a1(%rip), %xmm1    # 0x437b8
ucomisd %xmm0, %xmm1
ja 0x1752b
movq 0x2c09c(%rip), %rsi     # 0x435c0
cmpl $0x0, 0xc(%rsi,%rdi)
jle 0x17555
movq (%rcx,%rax,8), %rax
movl %edx, (%rax,%r13,4)
movq (%r12), %rdi
movl %r15d, %esi
movl 0xc(%rsp), %edx
movl %ebp, %ecx
movq %rbx, %r8
callq 0x17410
movq 0x8(%r12), %r12
movq %r14, %rdi
jmp 0x17445
movq (%rcx,%rax,8), %rax
movl %ebp, (%rax,%r13,4)
testl %r15d, %r15d
je 0x17568
incl 0x14(%rsi,%rdi)
jmp 0x1756c
incl 0x10(%rsi,%rdi)
leaq (%rsi,%rdi), %rax
addq $0xc, %rax
incl (%rax)
incl 0x2c004(%rip)           # 0x43580
jmp 0x17533
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq