// File: /workspace/github_c_makefile_star2_O3/dapogon[P]cellcoal/src/cellcoal.c
// Function: EvolveCNLOHonTree
void EvolveCNLOHonTree (TreeNode *p, int genome, long int *seed)
	{
    int		i, trials, numCNLOH, CNLOHsoFar;
    double	totalCNLOHbranchSum;

	totalCNLOHbranchSum = numSites * totalTreeLength / mutationRate * CNLOHrate;
	numCNLOH = RandomPoisson (totalCNLOHbranchSum, seed); /* the number of CNLOH events will be distributed as a Poisson with parameter totalCNLOHbranchSum */
	
     /* if the number of CNLOH events is bigger than the number of sites quit the program and warn the user about violation of ISM */
     if (numISMCNLOH + numCNLOH > (2*numSites))
        {
        fprintf (stderr, "\n\nERROR: The haploid infinite sites model (ISM) for CNLOH events has been violated. There will be");
        fprintf (stderr, "\nmore CNLOH events (%d existing + %d proposed]) than available sites under this model (%d).", numISMCNLOH, numCNLOH, 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);
        }
	
    numISMCNLOH += numCNLOH;
    trials = 0;
    CNLOHsoFar = 0;
    while (CNLOHsoFar < numCNLOH)
        {
        i = RandomUniformTo(numSites, seed);  /* choose a site at random */
        while ((genome == MATERNAL && allSites[i].numCNLOHmaternal != 0) ||
               (genome == PATERNAL && allSites[i].numCNLOHpaternal != 0))
            {
            i = RandomUniformTo(numSites, seed);
            if (trials++ > 100*numSites)
                {
                fprintf (stderr, "\n\n ERROR: after %d trials cannot find a site without CNLOH",100*numSites);
                fprintf (stderr, "\nCNLOH = %d  CNLOH so far = %d\n\n",numCNLOH, CNLOHsoFar);
                for (i=0; i<numSites; i++)
                    fprintf (stderr, "\nsite %d has %d CNLOHs",i+1, allSites[i].numCNLOH);
                 fprintf (stderr, "\n");
                 exit(-1);
                }
            }
	
		SimulateCNLOHforSite (p, genome, i, seed);
			
        CNLOHsoFar++;
			
        #ifdef MYDEBUG
            fprintf (stderr, "\nCNLOH = %d   nCNLOH so far = %d\n",numCNLOH, CNLOHsoFar);
            if (allSites[i]].numDeletions > 1)
                {
                fprintf (stderr, "\n\n ERROR: %d CNLOH in site %d",allSites[i].numCNLOH, i+1);
                exit(-1);
                }
            for (i=0; i<numSites; i++)
                fprintf (stderr, "%2d[%d] ",i+1, allSites[i].numCNLOH);
        #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 0x21705(%rip), %xmm0 # 0x361a8
mulsd 0x22af5(%rip), %xmm0    # 0x375a0
divsd 0x21725(%rip), %xmm0    # 0x361d8
mulsd 0x22b3d(%rip), %xmm0    # 0x375f8
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 0xe5fb(%rip), %xmm1     # 0x23100
ucomisd %xmm0, %xmm1
jae 0x14ad1
movl 0x22adf(%rip), %eax     # 0x375f0
subl %r15d, %eax
movl 0x2168e(%rip), %ecx     # 0x361a8
addl %ecx, %ecx
negl %r15d
cmpl %ecx, %eax
jg 0x14ce7
negl %r14d
movl %eax, 0x22ac0(%rip)     # 0x375f0
js 0x14cc8
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 0x2160f(%rip), %r14d    # 0x361a8
movq %r13, (%rbx)
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
divsd 0xe574(%rip), %xmm0     # 0x23120
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movsd %xmm1, (%rsp)
mulsd %xmm1, %xmm0
callq 0x2270
movq 0x229f7(%rip), %r12     # 0x375c0
imull $0x64, %r14d, %r14d
movl %r15d, 0x1c(%rsp)
cvttsd2si %xmm0, %edx
cmpl $0x1, %ebp
je 0x14bfe
testl %ebp, %ebp
jne 0x14c90
movslq %edx, %rax
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rax
cmpl $0x0, 0x28(%r12,%rax)
jne 0x14c18
jmp 0x14ca2
movslq %edx, %rax
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rax
cmpl $0x0, 0x2c(%r12,%rax)
je 0x14c9b
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 0xe4ac(%rip), %xmm0     # 0x23120
mulsd (%rsp), %xmm0
callq 0x2270
leal 0x1(%r15), %eax
cmpl %r14d, %r15d
movl %eax, %r15d
jle 0x14bd2
jmp 0x14cd7
xorl %esi, %esi
movl 0x1c(%rsp), %eax
movl %eax, %r15d
jmp 0x14ca4
movl $0x1, %esi
jmp 0x14ca4
xorl %esi, %esi
movq 0x20(%rsp), %rdi
movq %rbx, %rcx
callq 0x1859c
movl 0x10(%rsp), %eax
incl %eax
movl %r15d, %edx
movl 0xc(%rsp), %r15d
cmpl %eax, %r15d
jne 0x14b3f
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 0x5214
movl %r15d, %edi
callq 0x52aa