// File: /workspace/github_c_makefile_star2_O1/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
movl %esi, %eax
movq %rax, 0x10(%rsp)
movl %edx, 0x4(%rsp)
movslq %edx, %r13
movq %r13, %rax
shlq $0x7, %rax
leaq (%rax,%r13,8), %rsi
movl %ecx, %eax
xorl $0x1, %eax
movl %eax, 0x8(%rsp)
movl %ebx, %eax
xorl $0x1, %eax
movl %eax, 0xc(%rsp)
movq %rsi, %rbp
testq %r12, %r12
je 0x17a23
cmpl $0x1, 0x24(%r12)
jne 0x178e5
movq $0x0, 0x2bf5c(%rip) # 0x437d0
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 0x1c755(%rip), %xmm0    # 0x34028
mulsd 0x2bcc5(%rip), %xmm0    # 0x435a0
movsd %xmm0, 0x2bef5(%rip)    # 0x437d8
jmp 0x17938
movslq 0x1c(%r12), %r8
movq 0x10(%r12), %rax
movslq 0x1c(%rax), %rax
movsd 0x40(%r12), %xmm0
addsd 0x2bece(%rip), %xmm0    # 0x437d0
movsd %xmm0, 0x2bec6(%rip)    # 0x437d0
movsd 0x2bec6(%rip), %xmm1    # 0x437d8
ucomisd %xmm0, %xmm1
jbe 0x1795a
movq 0x2bc99(%rip), %rcx     # 0x435b8
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)
movq (%r12), %rdi
movl %ebx, %esi
movl 0x4(%rsp), %edx
movl %r15d, %ecx
movq %r14, %r8
callq 0x17811
movq 0x8(%r12), %r12
movq %rbp, %rsi
jmp 0x17858
testl %r15d, %r15d
je 0x179eb
movl %ebx, %ecx
orl 0x8(%rsp), %ecx
jne 0x17979
movq 0x2bc4e(%rip), %rcx     # 0x435c0
cmpl $0x0, 0x10(%rcx,%rsi)
jg 0x17918
movl 0xc(%rsp), %ecx
orl 0x8(%rsp), %ecx
jne 0x17991
movq 0x2bc36(%rip), %rcx     # 0x435c0
cmpl $0x0, 0x14(%rcx,%rsi)
jg 0x17918
movq 0x2bc20(%rip), %rcx     # 0x435b8
movq 0x10(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rcx,%rax,8), %rdx
movl (%rdx,%r13,4), %r9d
movl $0x1, %edx
testl %r9d, %r9d
je 0x179cd
cmpl $0x1, %r9d
jne 0x17a32
movq 0x2bc00(%rip), %rax     # 0x435c0
xorl %edx, %edx
cmpl $0x1, 0x4(%rax,%rsi)
jne 0x17a55
movq (%rcx,%r8,8), %rax
movl %edx, (%rax,%r13,4)
testl %ebx, %ebx
je 0x17a02
cmpl $0x1, %ebx
jne 0x17a0d
movq 0x2bbdb(%rip), %rax     # 0x435c0
incl 0x14(%rax,%rsi)
jmp 0x17a0d
movq 0x2bbce(%rip), %rcx     # 0x435c0
cmpl $0x0, 0xc(%rcx,%rsi)
jg 0x17918
jmp 0x17963
movq 0x2bbb7(%rip), %rax     # 0x435c0
incl 0x10(%rax,%rsi)
movq 0x2bbac(%rip), %rax     # 0x435c0
incl 0xc(%rax,%rsi)
incl 0x2bb62(%rip)           # 0x43580
jmp 0x17938
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2a5bf(%rip), %rcx     # 0x41ff8
movq (%rcx), %rdi
leaq 0x1ebdb(%rip), %rsi     # 0x3661e
movl 0x4(%rsp), %edx
movl %ebx, %ecx
movl %eax, %r8d
xorl %eax, %eax
callq 0x21c0
jmp 0x17a73
movq 0x2a59c(%rip), %rax     # 0x41ff8
movq (%rax), %rdi
leaq 0x1eb67(%rip), %rsi     # 0x365cd
movl 0x4(%rsp), %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x21c0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x22a0