// File: /workspace/github_c_makefile_star2_O2/dapogon[P]cellcoal/src/cellcoal.c
// Function: SimulateISMforSite
void SimulateISMforSite (TreeNode *p, int genome, int site, int doISMhaploid, long int *seed)
    {
    static double	cumBranchLength, uniform;
    int             cell, anccell;
		
	if (p != NULL)
        {
        cell = p->label;
			
        if (p->isHealthyRoot == YES)
            {
            cumBranchLength = 0;
            uniform = RandomUniform(seed) * totalTreeLength;
            }
        else
            {
            anccell = p->anc->label;
            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] = data[genome][anccell][site];
                }
            else /* => there will be change */
                {
                if (data[genome][anccell][site] == 0)  /* checking all this might be excessive */
                    data[genome][cell][site] = 1;
				else if (data[genome][anccell][site] == 1)
                    {
					if (allSites[site].isSNP == YES) // this is a germline mutation
						data[genome][cell][site] = 0;
					else
						{
						fprintf (stderr, "\n\nERROR: site %d in genome %d of cell %d cannot mutate twice under the ISM model", site, genome, cell);
                    	exit(-1);
						}
					}
                else
                    {
                    fprintf (stderr, "\n\nERROR: site %d in genome %d of cell %d has an unknow state %d under the ISM model", site, genome, anccell, data[genome][anccell][site]);
                    exit(-1);
                    }
					
                if (genome == MATERNAL)
                    allSites[site].numMutationsMaternal++;
                else if (genome == PATERNAL)
                    allSites[site].numMutationsPaternal++;
                allSites[site].numMutations++;
                numMU++;
                }
            }
            SimulateISMforSite (p->left, genome, site, doISMhaploid, seed);
            SimulateISMforSite (p->right, genome, site, doISMhaploid, seed);
        }
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %r14
movl %ecx, %r15d
movl %esi, %ebx
movq %rdi, %r12
cmpl $0x1, %ecx
sete %al
testl %esi, %esi
sete %cl
movb %cl, 0x9(%rsp)
andb %al, %cl
movb %cl, 0xb(%rsp)
movl %edx, 0xc(%rsp)
movslq %edx, %r13
cmpl $0x1, %esi
sete %cl
movl %esi, %edx
movq %rdx, 0x10(%rsp)
movb %cl, 0x8(%rsp)
andb %cl, %al
movb %al, 0xa(%rsp)
imulq $0x88, %r13, %r10
movq %r10, %rbp
testq %r12, %r12
je 0x14451
cmpl $0x1, 0x24(%r12)
jne 0x14312
andq $0x0, 0x1d4db(%rip)     # 0x317d0
movq %r14, %rdi
callq 0x10279
mulsd 0x1d29b(%rip), %xmm0    # 0x315a0
movsd %xmm0, 0x1d4cb(%rip)    # 0x317d8
jmp 0x1442f
movslq 0x1c(%r12), %r8
movq 0x10(%r12), %rax
movslq 0x1c(%rax), %rax
movsd 0x40(%r12), %xmm0
addsd 0x1d4a1(%rip), %xmm0    # 0x317d0
movsd %xmm0, 0x1d499(%rip)    # 0x317d0
movsd 0x1d499(%rip), %xmm1    # 0x317d8
ucomisd %xmm0, %xmm1
jbe 0x1436a
movq 0x1d26c(%rip), %rcx     # 0x315b8
movq 0x10(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rcx,%rax,8), %rax
movl (%rax,%r13,4), %eax
movq (%rcx,%r8,8), %rcx
movl %eax, (%rcx,%r13,4)
jmp 0x1442f
testl %r15d, %r15d
je 0x1438b
cmpb $0x0, 0xb(%rsp)
je 0x143a4
movq 0x1d243(%rip), %rcx     # 0x315c0
cmpl $0x0, 0x10(%rcx,%r10)
jg 0x14345
movb $0x1, %dl
xorl %ecx, %ecx
jmp 0x143c6
movq 0x1d22e(%rip), %rcx     # 0x315c0
cmpl $0x0, 0xc(%rcx,%r10)
movb 0x8(%rsp), %cl
movb 0x9(%rsp), %dl
jg 0x14345
jmp 0x143c6
movb 0x8(%rsp), %cl
movb 0x9(%rsp), %dl
cmpb $0x0, 0xa(%rsp)
je 0x143c6
movq 0x1d206(%rip), %rcx     # 0x315c0
cmpl $0x0, 0x14(%rcx,%r10)
jg 0x14345
movb $0x1, %cl
xorl %edx, %edx
movq 0x1d1eb(%rip), %rsi     # 0x315b8
movq 0x10(%rsp), %rdi
movq (%rsi,%rdi,8), %rsi
movq (%rsi,%rax,8), %rdi
movl (%rdi,%r13,4), %r9d
pushq $0x1
popq %rdi
testl %r9d, %r9d
je 0x14401
cmpl $0x1, %r9d
jne 0x14460
movq 0x1d1cd(%rip), %rax     # 0x315c0
xorl %edi, %edi
cmpl $0x1, 0x4(%rax,%r10)
jne 0x14483
movq (%rsi,%r8,8), %rax
movl %edi, (%rax,%r13,4)
movq 0x1d1b0(%rip), %rax     # 0x315c0
testb %dl, %dl
je 0x1441b
incl 0x10(%rax,%r10)
jmp 0x14424
testb %cl, %cl
je 0x14424
incl 0x14(%rax,%r10)
incl 0xc(%rax,%r10)
incl 0x1d151(%rip)           # 0x31580
movq (%r12), %rdi
movl %ebx, %esi
movl 0xc(%rsp), %edx
movl %r15d, %ecx
movq %r14, %r8
callq 0x14286
movq 0x8(%r12), %r12
movq %rbp, %r10
jmp 0x142dc
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1bb91(%rip), %rcx     # 0x2fff8
movq (%rcx), %rdi
leaq 0xd1d7(%rip), %rsi      # 0x21648
movl 0xc(%rsp), %edx
movl %ebx, %ecx
movl %eax, %r8d
xorl %eax, %eax
callq 0x21c0
jmp 0x144a1
movq 0x1bb6e(%rip), %rax     # 0x2fff8
movq (%rax), %rdi
leaq 0xd163(%rip), %rsi      # 0x215f7
movl 0xc(%rsp), %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x21c0
pushq $-0x1
popq %rdi
callq 0x22a0