// File: /workspace/github_c_makefile_star2_O1/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 0x2d99f(%rip), %xmm0 # 0x421a8
mulsd 0x2ed8f(%rip), %xmm0    # 0x435a0
divsd 0x2d9bf(%rip), %xmm0    # 0x421d8
mulsd 0x2edd7(%rip), %xmm0    # 0x435f8
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 0x1f799(%rip), %xmm1    # 0x34008
ucomisd %xmm0, %xmm1
jae 0x14837
movl 0x2ed75(%rip), %eax     # 0x435f0
subl %r15d, %eax
movl 0x2d924(%rip), %ecx     # 0x421a8
addl %ecx, %ecx
negl %r15d
cmpl %ecx, %eax
jg 0x14a3e
negl %r14d
movl %eax, 0x2ed56(%rip)     # 0x435f0
js 0x14a1f
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 0x2d8a2(%rip), %r15d    # 0x421a8
movq %rax, (%rbx)
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x1f70f(%rip), %xmm0    # 0x34028
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
movsd %xmm1, 0x8(%rsp)
mulsd %xmm1, %xmm0
callq 0x2270
movq 0x2ec89(%rip), %r12     # 0x435c0
imull $0x64, %r15d, %r13d
movl 0x4(%rsp), %eax
movl %eax, %r15d
cvttsd2si %xmm0, %edx
movslq %edx, %rax
cmpl $0x1, %ebp
je 0x14972
testl %ebp, %ebp
jne 0x149fc
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rcx
cmpl $0x0, 0x28(%r12,%rcx)
jne 0x14985
cmpl $0x1, %ebp
jne 0x149f7
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rax
cmpl $0x0, 0x2c(%r12,%rax)
je 0x149f7
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 0x1f64e(%rip), %xmm0    # 0x34028
mulsd 0x8(%rsp), %xmm0
callq 0x2270
leal 0x1(%r15), %eax
cmpl %r13d, %r15d
movl %eax, %r15d
jle 0x14942
jmp 0x14a2e
movl %r15d, 0x4(%rsp)
movq 0x20(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rcx
callq 0x18211
movl 0x18(%rsp), %eax
incl %eax
movl 0x14(%rsp), %r15d
cmpl %eax, %r15d
jne 0x148b9
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 0x520b
movl %r15d, %edi
callq 0x52a1