// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
cvtsi2sdl 0x3f291(%rip), %xmm0 # 0x4e1dc
mulsd 0x40835(%rip), %xmm0    # 0x4f788
divsd 0x3f2ad(%rip), %xmm0    # 0x4e208
mulsd 0x40895(%rip), %xmm0    # 0x4f7f8
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movq -0x18(%rbp), %rdi
callq 0x1b370
movl %eax, -0x24(%rbp)
movl 0x40855(%rip), %eax     # 0x4f7d4
addl -0x24(%rbp), %eax
movl 0x3f254(%rip), %ecx     # 0x4e1dc
shll %ecx
cmpl %ecx, %eax
jle 0xf00b
movq 0x3f063(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
leaq 0x3270f(%rip), %rsi     # 0x416ae
movb $0x0, %al
callq 0x21b0
movq 0x3f04b(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
movl 0x4081e(%rip), %edx     # 0x4f7d4
movl -0x24(%rbp), %ecx
movl 0x3f21c(%rip), %r8d     # 0x4e1dc
shll %r8d
leaq 0x32743(%rip), %rsi     # 0x4170d
movb $0x0, %al
callq 0x21b0
movq 0x3f020(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
leaq 0x325f5(%rip), %rsi     # 0x415d7
movb $0x0, %al
callq 0x21b0
movq 0x3f008(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
leaq 0x32601(%rip), %rsi     # 0x415fb
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2290
movl -0x24(%rbp), %eax
addl 0x407c0(%rip), %eax     # 0x4f7d4
movl %eax, 0x407ba(%rip)     # 0x4f7d4
movl $0x0, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0xf1ac
movl 0x3f1a2(%rip), %edi     # 0x4e1dc
movq -0x18(%rbp), %rsi
callq 0x1ba30
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0xf06c
movq 0x40755(%rip), %rcx     # 0x4f7a8
movslq -0x1c(%rbp), %rax
imulq $0x88, %rax, %rax
addq %rax, %rcx
movb $0x1, %al
cmpl $0x0, 0x1c(%rcx)
movb %al, -0x31(%rbp)
jne 0xf09c
xorl %eax, %eax
cmpl $0x1, -0xc(%rbp)
movb %al, -0x32(%rbp)
jne 0xf096
movq 0x4072a(%rip), %rax     # 0x4f7a8
movslq -0x1c(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x20(%rax)
setne %al
movb %al, -0x32(%rbp)
movb -0x32(%rbp), %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
testb $0x1, %al
jne 0xf0a8
jmp 0xf18b
movl 0x3f12e(%rip), %edi     # 0x4e1dc
movq -0x18(%rbp), %rsi
callq 0x1ba30
movl %eax, -0x1c(%rbp)
movl -0x20(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x20(%rbp)
imull $0x64, 0x3f110(%rip), %ecx # 0x4e1dc
cmpl %ecx, %eax
jle 0xf186
movq 0x3ef1d(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
imull $0x64, 0x3f0f7(%rip), %edx # 0x4e1dc
leaq 0x3267a(%rip), %rsi     # 0x41766
movb $0x0, %al
callq 0x21b0
movq 0x3eefe(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
leaq 0x32694(%rip), %rsi     # 0x4179e
movb $0x0, %al
callq 0x21b0
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0x3f0bb(%rip), %eax     # 0x4e1dc
jge 0xf164
movq 0x3eece(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
movl -0x1c(%rbp), %edx
addl $0x1, %edx
movq 0x4066e(%rip), %rax     # 0x4f7a8
movslq -0x1c(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
leaq 0x32676(%rip), %rsi     # 0x417c8
movb $0x0, %al
callq 0x21b0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xf118
movq 0x3ee8d(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
leaq 0x37ec0(%rip), %rsi     # 0x47035
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2290
jmp 0xf046
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x1c(%rbp), %edx
movq -0x18(%rbp), %rcx
callq 0x1cf00
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xf028
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)