// File: /workspace/github_c_makefile_star2_O2/dapogon[P]cellcoal/src/cellcoal.c
// Function: SimulateISMDNAforSite
void SimulateISMDNAforSite (TreeNode *p, int genome, int site, int doISMhaploid, long int *seed)
	{
    static double	cumBranchLength, uniform, ran;
    int             j, cell, anccell, ancstate;
	
    if (p != NULL)
        {
        cell = p->label;
			
        if (p->isHealthyRoot == YES)
            {
            cumBranchLength = 0;
            uniform = RandomUniform(seed) * totalTreeLength;
            }
        else
            {
            anccell = p->anc->label;
            ancstate = data[genome][anccell][site];
            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] = ancstate;
                }
            else /* => there will be change */
                {
                ran = RandomUniform(seed) * cumMij[ancstate][3];
                for (j=0; j<4; j++)
                    {
                    if (ran <= cumMij[ancstate][j])
                        {
                        data[genome][cell][site] = j;
                        break;
                        }
					}
                if (genome == MATERNAL)
                    allSites[site].numMutationsMaternal++;
                else if (genome == PATERNAL)
                    allSites[site].numMutationsPaternal++;
                allSites[site].numMutations++;
                numMU++;
 				}
            }
        SimulateISMDNAforSite (p->left, genome, site, doISMhaploid, seed);
        SimulateISMDNAforSite (p->right, genome, site, doISMhaploid, seed);
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %rbx
movl %edx, %r13d
movl %esi, %r14d
movq %rdi, %r12
movq 0x1d559(%rip), %rax     # 0x315b8
movq %rax, 0x28(%rsp)
movl %esi, %eax
movq %rax, 0x20(%rsp)
movslq %edx, %rsi
movl %ecx, 0xc(%rsp)
cmpl $0x1, %ecx
sete %al
testl %r14d, %r14d
sete %dl
movb %dl, 0x1(%rsp)
andb %al, %dl
movb %dl, 0x3(%rsp)
cmpl $0x1, %r14d
sete %dl
movsd 0x1d509(%rip), %xmm0    # 0x315a0
movsd %xmm0, 0x30(%rsp)
movb %dl, (%rsp)
andb %dl, %al
movb %al, 0x2(%rsp)
movq %rsi, 0x10(%rsp)
imulq $0x88, %rsi, %r15
movl %r13d, 0x8(%rsp)
movl %r14d, 0x4(%rsp)
testq %r12, %r12
je 0x14277
cmpl $0x1, 0x24(%r12)
jne 0x140f0
andq $0x0, 0x1d6eb(%rip)     # 0x317c0
movq %rbx, %rdi
callq 0x10279
mulsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x1d6dd(%rip)    # 0x317c8
jmp 0x14257
movslq 0x1c(%r12), %r14
movq 0x10(%r12), %rax
movslq 0x1c(%rax), %rax
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rcx,%rax,8), %rax
movq 0x10(%rsp), %rdx
movl (%rax,%rdx,4), %eax
movsd 0x40(%r12), %xmm0
addsd 0x1d699(%rip), %xmm0    # 0x317c0
movsd %xmm0, 0x1d691(%rip)    # 0x317c0
movsd 0x1d691(%rip), %xmm1    # 0x317c8
ucomisd %xmm0, %xmm1
jbe 0x14153
movq (%rcx,%r14,8), %rcx
movq 0x10(%rsp), %rdx
movl %eax, (%rcx,%rdx,4)
movl 0x4(%rsp), %r14d
jmp 0x14257
cmpl $0x0, 0xc(%rsp)
je 0x14176
cmpb $0x0, 0x3(%rsp)
je 0x14190
movq 0x1d458(%rip), %rdx     # 0x315c0
cmpl $0x0, 0x10(%rdx,%r15)
jg 0x1413d
movb $0x1, %dl
xorl %ebp, %ebp
jmp 0x141b4
movq 0x1d443(%rip), %rdx     # 0x315c0
cmpl $0x0, 0xc(%rdx,%r15)
movb (%rsp), %dl
movl %edx, %ebp
movb 0x1(%rsp), %dl
jg 0x1413d
jmp 0x141b4
movb (%rsp), %dl
movl %edx, %ebp
movb 0x1(%rsp), %dl
cmpb $0x0, 0x2(%rsp)
je 0x141b4
movq 0x1d419(%rip), %rdx     # 0x315c0
cmpl $0x0, 0x14(%rdx,%r15)
jg 0x1413d
movb $0x1, %bpl
xorl %edx, %edx
movl %edx, 0x1c(%rsp)
movslq %eax, %r13
movq %rbx, %rdi
callq 0x10279
shlq $0x5, %r13
leaq 0x1c3f2(%rip), %rax     # 0x305c0
mulsd 0x18(%r13,%rax), %xmm0
xorl %eax, %eax
cmpq $0x4, %rax
je 0x14219
leaq (,%rax,8), %rcx
addq %r13, %rcx
leaq 0x1c3d1(%rip), %rdx     # 0x305c0
movsd (%rdx,%rcx), %xmm1
ucomisd %xmm0, %xmm1
jae 0x141ff
incq %rax
jmp 0x141d7
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rcx,%r14,8), %rcx
movq 0x10(%rsp), %rdx
movl %eax, (%rcx,%rdx,4)
movq 0x1d3a0(%rip), %rax     # 0x315c0
cmpb $0x0, 0x1c(%rsp)
je 0x14238
incl 0x10(%rax,%r15)
movl 0x8(%rsp), %r13d
movl 0x4(%rsp), %r14d
jmp 0x1424c
testb %bpl, %bpl
movl 0x8(%rsp), %r13d
movl 0x4(%rsp), %r14d
je 0x1424c
incl 0x14(%rax,%r15)
incl 0xc(%rax,%r15)
incl 0x1d329(%rip)           # 0x31580
movq (%r12), %rdi
movl %r14d, %esi
movl %r13d, %edx
movl 0xc(%rsp), %ecx
movq %rbx, %r8
callq 0x1403e
movq 0x8(%r12), %r12
jmp 0x140bc
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq