// File: /workspace/github_c_makefile_star2_O3/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
testq %rdi, %rdi
je 0x18952
movq %rcx, %r14
movl %edx, %ebp
movl %esi, %ebx
movq %rdi, %r15
movslq %edx, %r12
movl %esi, %r13d
movq %r12, %rax
shlq $0x7, %rax
leaq (%rax,%r12,8), %rax
movq %rax, (%rsp)
cmpl $0x1, 0x24(%r15)
jne 0x18856
movq $0x0, 0x1f85e(%rip) # 0x38030
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 0xa8ef(%rip), %xmm0     # 0x23120
mulsd 0x1ed67(%rip), %xmm0    # 0x375a0
divsd 0x1d997(%rip), %xmm0    # 0x361d8
mulsd 0x1edc7(%rip), %xmm0    # 0x37610
movsd %xmm0, 0x1f7e7(%rip)    # 0x38038
jmp 0x18936
movslq 0x1c(%r15), %r8
movq 0x10(%r15), %rax
movslq 0x1c(%rax), %rax
movsd 0x40(%r15), %xmm0
divsd 0x1d968(%rip), %xmm0    # 0x361d8
mulsd 0x1ed98(%rip), %xmm0    # 0x37610
addsd 0x1f7b0(%rip), %xmm0    # 0x38030
movsd %xmm0, 0x1f7a8(%rip)    # 0x38030
movsd 0x1f7a8(%rip), %xmm1    # 0x38038
ucomisd %xmm0, %xmm1
jbe 0x188b6
movq 0x1ed1b(%rip), %rcx     # 0x375b8
movq (%rcx,%r13,8), %rcx
movq (%rcx,%rax,8), %rax
movl (%rax,%r12,4), %eax
movq (%rcx,%r8,8), %rcx
movl %eax, (%rcx,%r12,4)
jmp 0x18936
testl %ebx, %ebx
je 0x188d5
cmpl $0x1, %ebx
jne 0x188e7
movq 0x1ecfa(%rip), %rcx     # 0x375c0
movq (%rsp), %rdx
cmpl $0x0, 0x20(%rcx,%rdx)
jg 0x18896
movb $0x1, %cl
jmp 0x188e9
movq 0x1ece4(%rip), %rcx     # 0x375c0
movq (%rsp), %rdx
cmpl $0x0, 0x1c(%rcx,%rdx)
jg 0x18896
xorl %ecx, %ecx
movq 0x1ecc8(%rip), %rdx     # 0x375b8
movq (%rdx,%r13,8), %rdx
movq (%rdx,%rax,8), %rax
cmpl $0x7, (%rax,%r12,4)
je 0x18961
movq (%rdx,%r8,8), %rax
movl $0x7, (%rax,%r12,4)
movq 0x1ecae(%rip), %rax     # 0x375c0
testl %ebx, %ebx
je 0x18924
testb %cl, %cl
movq (%rsp), %rcx
je 0x1892c
incl 0x20(%rax,%rcx)
jmp 0x1892c
movq (%rsp), %rcx
incl 0x1c(%rax,%rcx)
incl 0x18(%rax,%rcx)
incl 0x1ec46(%rip)           # 0x3757c
movq (%r15), %rdi
movl %ebx, %esi
movl %ebp, %edx
movq %r14, %rcx
callq 0x18789
movq 0x8(%r15), %r15
testq %r15, %r15
jne 0x187bc
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1d690(%rip), %rax     # 0x35ff8
movq (%rax), %rdi
leaq 0xd089(%rip), %rsi      # 0x259fb
movl %ebp, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x21c0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x22a0