// File: /workspace/github_c_makefile_star2_O2/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 $0x18, %rsp
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, 0x10(%rsp)
cvtsi2sdl 0x1e8fe(%rip), %xmm0 # 0x301a8
mulsd 0x1fcee(%rip), %xmm0    # 0x315a0
divsd 0x1e91e(%rip), %xmm0    # 0x301d8
mulsd 0x1fd4e(%rip), %xmm0    # 0x31610
movq %rdx, %rdi
callq 0x13e90
movl %eax, %r15d
movl 0x1fd19(%rip), %eax     # 0x315ec
addl %r15d, %eax
movl 0x1e8cc(%rip), %ecx     # 0x301a8
addl %ecx, %ecx
cmpl %ecx, %eax
jg 0x11a3c
movl %eax, 0x1fd00(%rip)     # 0x315ec
xorl %r12d, %r12d
testl %r15d, %r15d
movl %r15d, %eax
cmovlel %r12d, %eax
movl %eax, 0x8(%rsp)
xorl %eax, %eax
movl %r15d, 0x4(%rsp)
cmpl 0x8(%rsp), %eax
je 0x11a2d
movl %eax, (%rsp)
movl 0x1e890(%rip), %r15d    # 0x301a8
movl %r15d, %edi
movq %r14, %rsi
callq 0x14020
movl %eax, %r13d
imull $0x64, %r15d, %ebx
movl %r12d, 0xc(%rsp)
movslq %eax, %rcx
cmpl $0x1, %ebp
je 0x11952
testl %ebp, %ebp
jne 0x11986
movq 0x1fc7e(%rip), %rdx     # 0x315c0
imulq $0x88, %rcx, %rcx
cmpl $0x0, 0x1c(%rdx,%rcx)
jne 0x11967
jmp 0x11981
movq 0x1fc67(%rip), %rdx     # 0x315c0
imulq $0x88, %rcx, %rcx
cmpl $0x0, 0x20(%rdx,%rcx)
je 0x11981
movl %r15d, %edi
movq %r14, %rsi
callq 0x14020
leal 0x1(%r12), %ecx
cmpl %ebx, %r12d
movl %ecx, %r12d
jle 0x1192f
jmp 0x119a7
movl %eax, %r13d
jmp 0x1198b
movl 0xc(%rsp), %r12d
movq 0x10(%rsp), %rdi
movl %ebp, %esi
movl %r13d, %edx
movq %r14, %rcx
callq 0x14d4d
movl (%rsp), %eax
incl %eax
jmp 0x11904
movq 0x1e64a(%rip), %r15     # 0x2fff8
movq (%r15), %rdi
leaq 0xff31(%rip), %rsi      # 0x218e9
movl %ebx, %edx
xorl %eax, %eax
callq 0x21c0
movq (%r15), %rdi
leaq 0xff56(%rip), %rsi      # 0x21921
movl 0x4(%rsp), %edx
movl (%rsp), %ecx
xorl %eax, %eax
callq 0x21c0
pushq $0x18
popq %r12
leaq 0xff67(%rip), %rbx      # 0x2194b
xorl %r14d, %r14d
movslq 0x1e7ba(%rip), %rax     # 0x301a8
movq (%r15), %rsi
cmpq %rax, %r14
jge 0x11a1d
incq %r14
movq 0x1fbc0(%rip), %rax     # 0x315c0
movl (%rax,%r12), %ecx
movq %rsi, %rdi
movq %rbx, %rsi
movl %r14d, %edx
xorl %eax, %eax
callq 0x21c0
addq $0x88, %r12
jmp 0x119e7
pushq $0xa
popq %rdi
callq 0x2180
pushq $-0x1
popq %rdi
callq 0x22a0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1e5b5(%rip), %r14     # 0x2fff8
movq (%r14), %rcx
leaq 0xfde4(%rip), %rdi      # 0x21831
pushq $0x5e
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x22b0
movq (%r14), %rdi
movl 0x1fb88(%rip), %edx     # 0x315ec
movl 0x1e73d(%rip), %r8d     # 0x301a8
addl %r8d, %r8d
leaq 0xfe1b(%rip), %rsi      # 0x21890
movl %r15d, %ecx
xorl %eax, %eax
callq 0x21c0
movq (%r14), %rcx
leaq 0xfcd1(%rip), %rdi      # 0x2175a
pushq $0x23
popq %rsi
movq %rbx, %rdx
callq 0x22b0
movq (%r14), %rcx
leaq 0xfce0(%rip), %rdi      # 0x2177e
pushq $0x3f
popq %rsi
movq %rbx, %rdx
callq 0x22b0
jmp 0x11a25