// File: /workspace/github_c_makefile_star2_O1/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
movl %esi, %eax
movq %rax, (%rsp)
movslq %edx, %r12
movq %r12, %rax
shlq $0x7, %rax
leaq (%rax,%r12,8), %rdx
movq %rdx, %r13
testq %r15, %r15
je 0x185cc
cmpl $0x1, 0x24(%r15)
jne 0x184ca
movq $0x0, 0x2bbea(%rip) # 0x44030
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 0x1bb83(%rip), %xmm0    # 0x34028
mulsd 0x2b0f3(%rip), %xmm0    # 0x435a0
divsd 0x29d23(%rip), %xmm0    # 0x421d8
mulsd 0x2b153(%rip), %xmm0    # 0x43610
movsd %xmm0, 0x2bb73(%rip)    # 0x44038
jmp 0x185b1
movslq 0x1c(%r15), %r8
movq 0x10(%r15), %rax
movslq 0x1c(%rax), %rax
movsd 0x40(%r15), %xmm0
divsd 0x29cf4(%rip), %xmm0    # 0x421d8
mulsd 0x2b124(%rip), %xmm0    # 0x43610
addsd 0x2bb3c(%rip), %xmm0    # 0x44030
movsd %xmm0, 0x2bb34(%rip)    # 0x44030
movsd 0x2bb34(%rip), %xmm1    # 0x44038
ucomisd %xmm0, %xmm1
jbe 0x1852e
movq 0x2b0a7(%rip), %rcx     # 0x435b8
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 0x185b1
testl %ebx, %ebx
je 0x18581
cmpl $0x1, %ebx
jne 0x18545
movq 0x2b082(%rip), %rcx     # 0x435c0
cmpl $0x0, 0x20(%rcx,%rdx)
jg 0x1850a
movq 0x2b06c(%rip), %rcx     # 0x435b8
movq (%rsp), %rsi
movq (%rcx,%rsi,8), %rcx
movq (%rcx,%rax,8), %rax
cmpl $0x7, (%rax,%r12,4)
je 0x185db
movq (%rcx,%r8,8), %rax
movl $0x7, (%rax,%r12,4)
testl %ebx, %ebx
je 0x18595
cmpl $0x1, %ebx
jne 0x185a0
movq 0x2b045(%rip), %rax     # 0x435c0
incl 0x20(%rax,%rdx)
jmp 0x185a0
movq 0x2b038(%rip), %rcx     # 0x435c0
cmpl $0x0, 0x1c(%rcx,%rdx)
jg 0x1850a
jmp 0x18532
movq 0x2b024(%rip), %rax     # 0x435c0
incl 0x1c(%rax,%rdx)
movq 0x2b019(%rip), %rax     # 0x435c0
incl 0x18(%rax,%rdx)
incl 0x2afcb(%rip)           # 0x4357c
movq (%r15), %rdi
movl %ebx, %esi
movl %ebp, %edx
movq %r14, %rcx
callq 0x183fb
movq 0x8(%r15), %r15
movq %r13, %rdx
jmp 0x18427
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x29a16(%rip), %rax     # 0x41ff8
movq (%rax), %rdi
leaq 0x1e34f(%rip), %rsi     # 0x3693b
movl %ebp, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x21c0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x22a0