// File: /workspace/github_c_makefile_star2_O3/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 0x21499(%rip), %xmm0 # 0x361a8
mulsd 0x22889(%rip), %xmm0    # 0x375a0
divsd 0x214b9(%rip), %xmm0    # 0x361d8
mulsd 0x228e9(%rip), %xmm0    # 0x37610
movsd %xmm0, 0x10(%rsp)
xorpd %xmm0, %xmm0
movl $0x1, %r15d
movl $0x2, %r14d
movsd %xmm0, (%rsp)
movsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x1687f
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movsd (%rsp), %xmm0
decl %r15d
decl %r14d
movsd 0xe38f(%rip), %xmm1     # 0x23100
ucomisd %xmm0, %xmm1
jae 0x14d3d
movl 0x2286f(%rip), %eax     # 0x375ec
subl %r15d, %eax
movl 0x21422(%rip), %ecx     # 0x361a8
addl %ecx, %ecx
negl %r15d
cmpl %ecx, %eax
jg 0x14f53
negl %r14d
movl %eax, 0x22850(%rip)     # 0x375ec
js 0x14f34
xorl %eax, %eax
xorl %edx, %edx
movl %r15d, 0xc(%rsp)
movl %eax, 0x10(%rsp)
movq (%rbx), %rcx
movq %rcx, %rax
movl %edx, %r15d
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), %r13
cmovgq %rdx, %r13
movl 0x213a3(%rip), %r14d    # 0x361a8
movq %r13, (%rbx)
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
divsd 0xe308(%rip), %xmm0     # 0x23120
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movsd %xmm1, (%rsp)
mulsd %xmm1, %xmm0
callq 0x2270
movq 0x2278b(%rip), %r12     # 0x375c0
imull $0x64, %r14d, %r14d
movl %r15d, 0x1c(%rsp)
cvttsd2si %xmm0, %edx
cmpl $0x1, %ebp
je 0x14e6a
testl %ebp, %ebp
jne 0x14efc
movslq %edx, %rax
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rax
cmpl $0x0, 0x1c(%r12,%rax)
jne 0x14e84
jmp 0x14f0e
movslq %edx, %rax
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rax
cmpl $0x0, 0x20(%r12,%rax)
je 0x14f07
movq %r13, %rax
movabsq $0x41a705af1fe3fb79, %rcx # imm = 0x41A705AF1FE3FB79
imulq %rcx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0xf, %rdx
addq %rax, %rdx
imulq $0x1f31d, %rdx, %rax    # imm = 0x1F31D
subq %rax, %r13
imulq $0x41a7, %r13, %rax     # imm = 0x41A7
imulq $-0xb14, %rdx, %rcx     # imm = 0xF4EC
leaq (%rcx,%rax), %rdx
testq %rdx, %rdx
leaq 0x7fffffff(%rcx,%rax), %r13
cmovgq %rdx, %r13
movq %r13, (%rbx)
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
divsd 0xe240(%rip), %xmm0     # 0x23120
mulsd (%rsp), %xmm0
callq 0x2270
leal 0x1(%r15), %eax
cmpl %r14d, %r15d
movl %eax, %r15d
jle 0x14e3e
jmp 0x14f43
xorl %esi, %esi
movl 0x1c(%rsp), %eax
movl %eax, %r15d
jmp 0x14f10
movl $0x1, %esi
jmp 0x14f10
xorl %esi, %esi
movq 0x20(%rsp), %rdi
movq %rbx, %rcx
callq 0x18789
movl 0x10(%rsp), %eax
incl %eax
movl %r15d, %edx
movl 0xc(%rsp), %r15d
cmpl %eax, %r15d
jne 0x14dab
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r14d, %edi
movl 0xc(%rsp), %esi
movl 0x10(%rsp), %edx
callq 0x5324
movl %r15d, %edi
callq 0x53ba