// File: /workspace/github_c_makefile_star2_O2/dapogon[P]cellcoal/src/cellcoal.c
// Function: SimulateDeletionforSite
void SimulateDeletionforSite (TreeNode *p, int genome, int site, long int *seed)
    {
    static double	cumDeletionBranchLength, uniform;
    int             cell, anccell;
		
	if (p != NULL)
        {
        cell = p->label;
			
        if (p->isHealthyRoot == YES)
            {
            cumDeletionBranchLength = 0;
//            uniform = RandomUniform(seed) * allSites[site].deletionBranchSum;
             uniform = RandomUniform(seed) * totalTreeLength / mutationRate * deletionRate;;
           }
        else
            {
            anccell = p->anc->label;
            cumDeletionBranchLength += p->branchLength / mutationRate * deletionRate;
				
             if ((cumDeletionBranchLength < uniform) || /* => there will be no change at this branch */
                ((genome == MATERNAL) && (allSites[site].numDeletionsMaternal > 0)) ||
                ((genome == PATERNAL) && (allSites[site].numDeletionsPaternal > 0)))
                {
                data[genome][cell][site] = data[genome][anccell][site];
                }
			else /* => there will be a deletion */
                {
                if (data[genome][anccell][site] != DELETION)  /* checking all this might be excessive */
                    data[genome][cell][site] = DELETION;
                else if (data[genome][anccell][site] == DELETION)
                    {
                    fprintf (stderr, "\n\n ERROR: site %d in genome %d of cell %d cannot be deleted twice under the ISM model\n", site, genome, cell);
                    exit(-1);
                    }
                else
                    {
                    fprintf (stderr, "\n\n ERROR: site %d in genome %d of cell %d has an unknow state %d under the ISM model\n", site, genome, anccell, data[genome][anccell][site]);
                    exit(-1);
                    }
					
                if (genome == MATERNAL)
                    allSites[site].numDeletionsMaternal++;
                else if (genome == PATERNAL)
                    allSites[site].numDeletionsPaternal++;
                allSites[site].numDeletions++;
                numDEL++;
                }
            }
            SimulateDeletionforSite (p->left, genome, site, seed);
            SimulateDeletionforSite (p->right, genome, site, seed);
        }
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movl %edx, %ebp
movl %esi, %ebx
movq %rdi, %r15
movslq %edx, %r12
movl %esi, %eax
movq %rax, (%rsp)
imulq $0x88, %r12, %rsi
movq %rsi, %r13
testq %r15, %r15
je 0x14eaa
cmpl $0x1, 0x24(%r15)
jne 0x14dba
andq $0x0, 0x1d2a3(%rip)     # 0x32030
movq %r14, %rdi
callq 0x10279
mulsd 0x1c803(%rip), %xmm0    # 0x315a0
divsd 0x1b433(%rip), %xmm0    # 0x301d8
mulsd 0x1c863(%rip), %xmm0    # 0x31610
movsd %xmm0, 0x1d283(%rip)    # 0x32038
jmp 0x14e8f
movslq 0x1c(%r15), %r8
movq 0x10(%r15), %rax
movslq 0x1c(%rax), %rax
movsd 0x40(%r15), %xmm0
divsd 0x1b404(%rip), %xmm0    # 0x301d8
mulsd 0x1c834(%rip), %xmm0    # 0x31610
addsd 0x1d24c(%rip), %xmm0    # 0x32030
movsd %xmm0, 0x1d244(%rip)    # 0x32030
movsd 0x1d244(%rip), %xmm1    # 0x32038
ucomisd %xmm0, %xmm1
jbe 0x14e1b
movq 0x1c7b7(%rip), %rcx     # 0x315b8
movq (%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rcx,%rax,8), %rax
movl (%rax,%r12,4), %eax
movq (%rcx,%r8,8), %rcx
movl %eax, (%rcx,%r12,4)
jmp 0x14e8f
testl %ebx, %ebx
je 0x14e36
cmpl $0x1, %ebx
jne 0x14e44
movq 0x1c795(%rip), %rcx     # 0x315c0
cmpl $0x0, 0x20(%rcx,%rsi)
jg 0x14dfa
movb $0x1, %cl
jmp 0x14e46
movq 0x1c783(%rip), %rcx     # 0x315c0
cmpl $0x0, 0x1c(%rcx,%rsi)
jg 0x14dfa
xorl %ecx, %ecx
movq 0x1c76b(%rip), %rdx     # 0x315b8
movq (%rsp), %rdi
movq (%rdx,%rdi,8), %rdx
movq (%rdx,%rax,8), %rax
cmpl $0x7, (%rax,%r12,4)
je 0x14eb9
movq (%rdx,%r8,8), %rax
movl $0x7, (%rax,%r12,4)
movq 0x1c74d(%rip), %rax     # 0x315c0
testl %ebx, %ebx
je 0x14e81
testb %cl, %cl
je 0x14e85
incl 0x20(%rax,%rsi)
jmp 0x14e85
incl 0x1c(%rax,%rsi)
incl 0x18(%rax,%rsi)
incl 0x1c6ed(%rip)           # 0x3157c
movq (%r15), %rdi
movl %ebx, %esi
movl %ebp, %edx
movq %r14, %rcx
callq 0x14d4d
movq 0x8(%r15), %r15
movq %r13, %rsi
jmp 0x14d75
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1b138(%rip), %rax     # 0x2fff8
movq (%rax), %rdi
leaq 0xca9b(%rip), %rsi      # 0x21965
movl %ebp, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x21c0
pushq $-0x1
popq %rdi
callq 0x22a0