// File: /workspace/github_c_makefile_star2_O1/dapogon[P]cellcoal/src/cellcoal.c
// Function: EvolveDeletionsOnTree
void EvolveDeletionsOnTree (TreeNode *p, int genome, long int *seed)
	{
    int		i, trials, numDeletions, deletionsSoFar;
    double	totalDeletionBranchSum;
	
	totalDeletionBranchSum = numSites * totalTreeLength / mutationRate * deletionRate;
	numDeletions = RandomPoisson (totalDeletionBranchSum, seed); /* the number of deletions will be distributed as a Poisson with parameter totalDeletionBranchSum */
	
     /* if the number of deletions is bigger than the number of sites quit the program and warn the user about violation of ISM */
     if (numISMdeletions + numDeletions > (2*numSites))
        {
        fprintf (stderr, "\n\nERROR: The haploid infinite sites model (ISM) for deletions has been violated. There will be");
        fprintf (stderr, "\nmore deletions (%d existing + %d proposed]) than available sites under this model (%d).", numISMdeletions, numDeletions, 2*numSites);
        fprintf (stderr, "\nTry using a smaller deletion rate.");
        fprintf (stderr, "\nIf using a user tree, try introducing smaller branch lengths.\n");
        exit (-1);
        }
	
    numISMdeletions += numDeletions;
    trials = 0;
    deletionsSoFar = 0;
    while (deletionsSoFar < numDeletions)
        {
        i = RandomUniformTo(numSites, seed);  /* choose a site at random */
        while ((genome == MATERNAL && allSites[i].numDeletionsMaternal != 0) ||
               (genome == PATERNAL && allSites[i].numDeletionsPaternal != 0))
            {
            i = RandomUniformTo(numSites, seed);
            if (trials++ > 100*numSites)
                {
                fprintf (stderr, "\n\n ERROR: after %d trials cannot find an undeleted site",100*numSites);
                fprintf (stderr, "\ndeletions = %d   deletions so far = %d\n\n",numDeletions, deletionsSoFar);
                for (i=0; i<numSites; i++)
                    fprintf (stderr, "\nsite %d has %d deletions",i+1, allSites[i].numDeletions);
                 fprintf (stderr, "\n");
                 exit(-1);
                }
            }
	
		SimulateDeletionforSite (p, genome, i, seed);
			
        deletionsSoFar++;
			
        #ifdef MYDEBUG
            fprintf (stderr, "\deletions = %d   deletions so far = %d\n",numDeletions, deletionsSoFar);
            if (allSites[i]].numDeletions > 1)
                {
                fprintf (stderr, "\n\n ERROR: %d deletions in site %d",allSites[i].numDeletions, i+1);
                exit(-1);
                }
            for (i=0; i<numSites; i++)
                fprintf (stderr, "%2d[%d] ",i+1, allSites[i].numDeletions);
        #endif
			
        }
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, 0x20(%rsp)
cvtsi2sdl 0x2d742(%rip), %xmm0 # 0x421a8
mulsd 0x2eb32(%rip), %xmm0    # 0x435a0
divsd 0x2d762(%rip), %xmm0    # 0x421d8
mulsd 0x2eb92(%rip), %xmm0    # 0x43610
movsd %xmm0, 0x18(%rsp)
xorpd %xmm0, %xmm0
movl $0x1, %r15d
movl $0x2, %r14d
movsd %xmm0, 0x8(%rsp)
movsd 0x18(%rsp), %xmm0
movq %rbx, %rdi
callq 0x165c5
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
decl %r15d
decl %r14d
movsd 0x1f53c(%rip), %xmm1    # 0x34008
ucomisd %xmm0, %xmm1
jae 0x14a94
movl 0x2eb14(%rip), %eax     # 0x435ec
subl %r15d, %eax
movl 0x2d6c7(%rip), %ecx     # 0x421a8
addl %ecx, %ecx
negl %r15d
cmpl %ecx, %eax
jg 0x14c9b
negl %r14d
movl %eax, 0x2eaf5(%rip)     # 0x435ec
js 0x14c7c
xorl %eax, %eax
movabsq $0x41a705af1fe3fb79, %r14 # imm = 0x41A705AF1FE3FB79
movl $0x0, 0x4(%rsp)
movl %r15d, 0x14(%rsp)
movl %eax, 0x18(%rsp)
movq (%rbx), %rcx
movq %rcx, %rax
imulq %r14
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
movl 0x2d645(%rip), %r15d    # 0x421a8
movq %rax, (%rbx)
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x1f4b2(%rip), %xmm0    # 0x34028
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
movsd %xmm1, 0x8(%rsp)
mulsd %xmm1, %xmm0
callq 0x2270
movq 0x2ea2c(%rip), %r12     # 0x435c0
imull $0x64, %r15d, %r13d
movl 0x4(%rsp), %eax
movl %eax, %r15d
cvttsd2si %xmm0, %edx
movslq %edx, %rax
cmpl $0x1, %ebp
je 0x14bcf
testl %ebp, %ebp
jne 0x14c59
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rcx
cmpl $0x0, 0x1c(%r12,%rcx)
jne 0x14be2
cmpl $0x1, %ebp
jne 0x14c54
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rax
cmpl $0x0, 0x20(%r12,%rax)
je 0x14c54
movq (%rbx), %rcx
movq %rcx, %rax
imulq %r14
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 0x1f3f1(%rip), %xmm0    # 0x34028
mulsd 0x8(%rsp), %xmm0
callq 0x2270
leal 0x1(%r15), %eax
cmpl %r13d, %r15d
movl %eax, %r15d
jle 0x14b9f
jmp 0x14c8b
movl %r15d, 0x4(%rsp)
movq 0x20(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rcx
callq 0x183fb
movl 0x18(%rsp), %eax
incl %eax
movl 0x14(%rsp), %r15d
cmpl %eax, %r15d
jne 0x14b16
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r13d, %edi
movl 0x14(%rsp), %esi
movl 0x18(%rsp), %edx
callq 0x531b
movl %r15d, %edi
callq 0x53b1