// File: /workspace/github_c_makefile_star2_O3/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
testq %rdi, %rdi
je 0x17da6
movq %r8, %r14
movl %ecx, %r15d
movl %edx, %ebp
movl %esi, %ebx
movq %rdi, %r12
cmpl $0x1, %ecx
sete %al
testl %esi, %esi
sete %cl
movb %cl, 0x5(%rsp)
andb %al, %cl
movb %cl, 0x7(%rsp)
movslq %edx, %r13
cmpl $0x1, %esi
sete %cl
movl %esi, %edx
movq %rdx, 0x10(%rsp)
movb %cl, 0x4(%rsp)
andb %cl, %al
movb %al, 0x6(%rsp)
movq %r13, %rax
shlq $0x7, %rax
leaq (%rax,%r13,8), %rax
movq %rax, 0x8(%rsp)
cmpl $0x1, 0x24(%r12)
jne 0x17c4a
movq $0x0, 0x1fbfa(%rip) # 0x377d0
movq (%r14), %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, (%r14)
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0xb4eb(%rip), %xmm0     # 0x23120
mulsd 0x1f963(%rip), %xmm0    # 0x375a0
movsd %xmm0, 0x1fb93(%rip)    # 0x377d8
jmp 0x17d85
movslq 0x1c(%r12), %r8
movq 0x10(%r12), %rax
movslq 0x1c(%rax), %rax
movsd 0x40(%r12), %xmm0
addsd 0x1fb69(%rip), %xmm0    # 0x377d0
movsd %xmm0, 0x1fb61(%rip)    # 0x377d0
movsd 0x1fb61(%rip), %xmm1    # 0x377d8
ucomisd %xmm0, %xmm1
jbe 0x17ca2
movq 0x1f934(%rip), %rcx     # 0x375b8
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 0x17d85
testl %r15d, %r15d
je 0x17cc7
cmpb $0x0, 0x7(%rsp)
je 0x17ce4
movq 0x1f90b(%rip), %rcx     # 0x375c0
movq 0x8(%rsp), %rdx
cmpl $0x0, 0x10(%rcx,%rdx)
jg 0x17c7d
movb $0x1, %dl
xorl %ecx, %ecx
jmp 0x17d0e
movq 0x1f8f2(%rip), %rcx     # 0x375c0
movq 0x8(%rsp), %rdx
cmpl $0x0, 0xc(%rcx,%rdx)
movb 0x4(%rsp), %cl
movb 0x5(%rsp), %dl
jg 0x17c7d
jmp 0x17d0e
movb 0x4(%rsp), %cl
movb 0x5(%rsp), %dl
cmpb $0x0, 0x6(%rsp)
je 0x17d0e
movq 0x1f8c6(%rip), %rcx     # 0x375c0
movq 0x8(%rsp), %rdx
cmpl $0x0, 0x14(%rcx,%rdx)
jg 0x17c7d
movb $0x1, %cl
xorl %edx, %edx
movq 0x1f8a3(%rip), %rsi     # 0x375b8
movq 0x10(%rsp), %rdi
movq (%rsi,%rdi,8), %rsi
movq (%rsi,%rax,8), %rdi
movl (%rdi,%r13,4), %r9d
movl $0x1, %edi
testl %r9d, %r9d
je 0x17d50
cmpl $0x1, %r9d
jne 0x17db5
movq 0x1f883(%rip), %rax     # 0x375c0
xorl %edi, %edi
movq 0x8(%rsp), %r9
cmpl $0x1, 0x4(%rax,%r9)
jne 0x17dd6
movq (%rsi,%r8,8), %rax
movl %edi, (%rax,%r13,4)
movq 0x1f861(%rip), %rax     # 0x375c0
testb %dl, %dl
je 0x17d6e
movq 0x8(%rsp), %rcx
incl 0x10(%rax,%rcx)
jmp 0x17d7b
testb %cl, %cl
movq 0x8(%rsp), %rcx
je 0x17d7b
incl 0x14(%rax,%rcx)
incl 0xc(%rax,%rcx)
incl 0x1f7fb(%rip)           # 0x37580
movq (%r12), %rdi
movl %ebx, %esi
movl %ebp, %edx
movl %r15d, %ecx
movq %r14, %r8
callq 0x17b60
movq 0x8(%r12), %r12
testq %r12, %r12
jne 0x17bc3
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1e23c(%rip), %rcx     # 0x35ff8
movq (%rcx), %rdi
leaq 0xd918(%rip), %rsi      # 0x256de
movl %ebp, %edx
movl %ebx, %ecx
movl %eax, %r8d
xorl %eax, %eax
callq 0x21c0
jmp 0x17df2
movq 0x1e21b(%rip), %rax     # 0x35ff8
movq (%rax), %rdi
leaq 0xd8a6(%rip), %rsi      # 0x2568d
movl %ebp, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x21c0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x22a0