// File: /workspace/github_c_makefile_star2_O3/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
movl %edx, 0x1c(%rsp)
testq %rdi, %rdi
je 0x17b51
movq %r8, %rbx
movl %ecx, %ebp
movl %esi, %r15d
movq %rdi, %r12
movq 0x1fcfc(%rip), %rax     # 0x375b8
movq %rax, 0x30(%rsp)
movl %esi, %eax
movq %rax, 0x28(%rsp)
movslq 0x1c(%rsp), %rcx
cmpl $0x1, %ebp
sete %al
testl %esi, %esi
sete %dl
movb %dl, 0xd(%rsp)
andb %al, %dl
movb %dl, 0xf(%rsp)
cmpl $0x1, %esi
sete %dl
movsd 0x1fcb0(%rip), %xmm0    # 0x375a0
movsd %xmm0, 0x20(%rsp)
movb %dl, 0xc(%rsp)
andb %dl, %al
movb %al, 0xe(%rsp)
movq %rcx, %rax
shlq $0x7, %rax
movq %rcx, %r14
leaq (%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
leaq 0x1eca6(%rip), %r13     # 0x365c0
cmpl $0x1, 0x24(%r12)
jne 0x1799f
movq $0x0, 0x1fe93(%rip) # 0x377c0
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
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movq %rax, (%rbx)
divsd 0xb794(%rip), %xmm0     # 0x23120
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x1fe2e(%rip)    # 0x377c8
jmp 0x17b2e
movslq 0x1c(%r12), %rsi
movq 0x10(%r12), %rax
movslq 0x1c(%rax), %rax
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %rdx
movq (%rcx,%rdx,8), %rdi
movq (%rdi,%rax,8), %rax
movl (%rax,%r14,4), %eax
movsd 0x40(%r12), %xmm0
addsd 0x1fdee(%rip), %xmm0    # 0x377c0
movsd %xmm0, 0x1fde6(%rip)    # 0x377c0
movsd 0x1fde6(%rip), %xmm1    # 0x377c8
ucomisd %xmm0, %xmm1
jbe 0x179f5
movq (%rdi,%rsi,8), %rcx
movl %eax, (%rcx,%r14,4)
jmp 0x17b2e
testl %ebp, %ebp
je 0x17a1b
cmpb $0x0, 0xf(%rsp)
je 0x17a3e
movq 0x1fbb9(%rip), %rcx     # 0x375c0
movq 0x10(%rsp), %rdx
cmpl $0x0, 0x10(%rcx,%rdx)
jg 0x179e8
movb $0x1, %r9b
xorl %r8d, %r8d
jmp 0x17a6c
movq 0x1fb9e(%rip), %rcx     # 0x375c0
movq 0x10(%rsp), %rdx
cmpl $0x0, 0xc(%rcx,%rdx)
movb 0xc(%rsp), %cl
movl %ecx, %r8d
movb 0xd(%rsp), %cl
movl %ecx, %r9d
jg 0x179e8
jmp 0x17a6c
movb 0xc(%rsp), %cl
movl %ecx, %r8d
movb 0xd(%rsp), %cl
movl %ecx, %r9d
cmpb $0x0, 0xe(%rsp)
je 0x17a6c
movq 0x1fb66(%rip), %rcx     # 0x375c0
movq 0x10(%rsp), %rdx
cmpl $0x0, 0x14(%rcx,%rdx)
jg 0x179e8
movb $0x1, %r8b
xorl %r9d, %r9d
movslq %eax, %r10
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 0xb652(%rip), %xmm0     # 0x23120
shlq $0x5, %r10
mulsd 0x18(%r10,%r13), %xmm0
xorl %eax, %eax
leaq (%r10,%rax,8), %rcx
movsd (%r13,%rcx), %xmm1
ucomisd %xmm0, %xmm1
jae 0x17af7
incq %rax
cmpq $0x4, %rax
jne 0x17adb
jmp 0x17aff
movq (%rdi,%rsi,8), %rcx
movl %eax, (%rcx,%r14,4)
movq 0x1faba(%rip), %rax     # 0x375c0
testb %r9b, %r9b
je 0x17b16
movq 0x10(%rsp), %rcx
incl 0x10(%rax,%rcx)
jmp 0x17b24
testb %r8b, %r8b
movq 0x10(%rsp), %rcx
je 0x17b24
incl 0x14(%rax,%rcx)
incl 0xc(%rax,%rcx)
incl 0x1fa52(%rip)           # 0x37580
movq (%r12), %rdi
movl %r15d, %esi
movl 0x1c(%rsp), %edx
movl %ebp, %ecx
movq %rbx, %r8
callq 0x1788f
movq 0x8(%r12), %r12
testq %r12, %r12
jne 0x1791a
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq