// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq %r8, -0x20(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x1c10f
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x1, 0x24(%rax)
jne 0x1be51
xorps %xmm0, %xmm0
movsd %xmm0, 0x33bcd(%rip)    # 0x4fa00
movq -0x20(%rbp), %rdi
callq 0xa500
mulsd 0x33944(%rip), %xmm0    # 0x4f788
movsd %xmm0, 0x33bbc(%rip)    # 0x4fa08
jmp 0x1c0dc
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movsd 0x40(%rax), %xmm0
addsd 0x33b90(%rip), %xmm0    # 0x4fa00
movsd %xmm0, 0x33b88(%rip)    # 0x4fa00
movsd 0x33b80(%rip), %xmm1    # 0x4fa00
movsd 0x33b80(%rip), %xmm0    # 0x4fa08
ucomisd %xmm1, %xmm0
ja 0x1befd
cmpl $0x0, -0x14(%rbp)
jne 0x1beaf
movq 0x3390d(%rip), %rax     # 0x4f7a8
movslq -0x10(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0xc(%rax)
jg 0x1befd
cmpl $0x1, -0x14(%rbp)
jne 0x1bed6
cmpl $0x0, -0xc(%rbp)
jne 0x1bed6
movq 0x338e6(%rip), %rax     # 0x4f7a8
movslq -0x10(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x10(%rax)
jg 0x1befd
cmpl $0x1, -0x14(%rbp)
jne 0x1bf3e
cmpl $0x1, -0xc(%rbp)
jne 0x1bf3e
movq 0x338bf(%rip), %rax     # 0x4f7a8
movslq -0x10(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x14(%rax)
jle 0x1bf3e
movq 0x3389c(%rip), %rax     # 0x4f7a0
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x3387e(%rip), %rax     # 0x4f7a0
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x1c0da
movq 0x3385b(%rip), %rax     # 0x4f7a0
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x1bf86
movq 0x3383a(%rip), %rax     # 0x4f7a0
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
jmp 0x1c061
movq 0x33813(%rip), %rax     # 0x4f7a0
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
cmpl $0x1, (%rax,%rcx,4)
jne 0x1c014
movq 0x337fa(%rip), %rax     # 0x4f7a8
movslq -0x10(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0x1bfe6
movq 0x337d7(%rip), %rax     # 0x4f7a0
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
jmp 0x1c012
movq 0x3200b(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
movl -0x10(%rbp), %edx
movl -0xc(%rbp), %ecx
movl -0x24(%rbp), %r8d
leaq 0x25473(%rip), %rsi     # 0x41474
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2290
jmp 0x1c05f
movq 0x31fdd(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
movl -0x10(%rbp), %edx
movl -0xc(%rbp), %ecx
movl -0x28(%rbp), %r8d
movq 0x33771(%rip), %rax     # 0x4f7a0
movslq -0xc(%rbp), %rsi
movq (%rax,%rsi,8), %rax
movslq -0x28(%rbp), %rsi
movq (%rax,%rsi,8), %rax
movslq -0x10(%rbp), %rsi
movl (%rax,%rsi,4), %r9d
leaq 0x25477(%rip), %rsi     # 0x414c5
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2290
jmp 0x1c061
cmpl $0x0, -0xc(%rbp)
jne 0x1c087
movq 0x3373a(%rip), %rax     # 0x4f7a8
movslq -0x10(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
jmp 0x1c0ad
cmpl $0x1, -0xc(%rbp)
jne 0x1c0ab
movq 0x33714(%rip), %rax     # 0x4f7a8
movslq -0x10(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
jmp 0x1c0ad
movq 0x336f4(%rip), %rax     # 0x4f7a8
movslq -0x10(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
movl 0x33693(%rip), %eax     # 0x4f764
addl $0x1, %eax
movl %eax, 0x3368a(%rip)     # 0x4f764
jmp 0x1c0dc
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movl -0x14(%rbp), %ecx
movq -0x20(%rbp), %r8
callq 0x1bdf0
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movl -0x14(%rbp), %ecx
movq -0x20(%rbp), %r8
callq 0x1bdf0
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)