// File: /workspace/github_c_makefile_star2_O2/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 $0x18, %rsp
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, 0x10(%rsp)
cvtsi2sdl 0x1eb1b(%rip), %xmm0 # 0x301a8
mulsd 0x1ff0b(%rip), %xmm0    # 0x315a0
divsd 0x1eb3b(%rip), %xmm0    # 0x301d8
mulsd 0x1ff53(%rip), %xmm0    # 0x315f8
movq %rdx, %rdi
callq 0x13e90
movl %eax, %r15d
movl 0x1ff3a(%rip), %eax     # 0x315f0
addl %r15d, %eax
movl 0x1eae9(%rip), %ebx     # 0x301a8
leal (%rbx,%rbx), %ecx
cmpl %ecx, %eax
jg 0x11818
movl %eax, 0x1ff20(%rip)     # 0x315f0
imull $0x64, %ebx, %r13d
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 0x11809
movl %eax, (%rsp)
movl %ebx, %edi
movq %r14, %rsi
callq 0x14020
movl %eax, %r15d
movl %r12d, 0xc(%rsp)
movslq %eax, %rcx
cmpl $0x1, %ebp
je 0x1172e
testl %ebp, %ebp
jne 0x11761
movq 0x1fea2(%rip), %rdx     # 0x315c0
imulq $0x88, %rcx, %rcx
cmpl $0x0, 0x28(%rdx,%rcx)
jne 0x11743
jmp 0x1175c
movq 0x1fe8b(%rip), %rdx     # 0x315c0
imulq $0x88, %rcx, %rcx
cmpl $0x0, 0x2c(%rdx,%rcx)
je 0x1175c
movl %ebx, %edi
movq %r14, %rsi
callq 0x14020
leal 0x1(%r12), %ecx
cmpl %r13d, %r12d
movl %ecx, %r12d
jle 0x1170b
jmp 0x11782
movl %eax, %r15d
jmp 0x11766
movl 0xc(%rsp), %r12d
movq 0x10(%rsp), %rdi
movl %ebp, %esi
movl %r15d, %edx
movq %r14, %rcx
callq 0x14bc6
movl (%rsp), %eax
incl %eax
jmp 0x116ec
movq 0x1e86f(%rip), %r15     # 0x2fff8
movq (%r15), %rdi
leaq 0x1002b(%rip), %rsi     # 0x217be
movl %r13d, %edx
xorl %eax, %eax
callq 0x21c0
movq (%r15), %rdi
leaq 0x10052(%rip), %rsi     # 0x217f9
movl 0x4(%rsp), %edx
movl (%rsp), %ecx
xorl %eax, %eax
callq 0x21c0
pushq $0x24
popq %r12
leaq 0x1005a(%rip), %rbx     # 0x2181a
xorl %r14d, %r14d
movslq 0x1e9de(%rip), %rax     # 0x301a8
movq (%r15), %rsi
cmpq %rax, %r14
jge 0x117f9
incq %r14
movq 0x1fde4(%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 0x117c3
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 0x1e7d9(%rip), %r14     # 0x2fff8
movq (%r14), %rcx
leaq 0xfe73(%rip), %rdi      # 0x2169c
pushq $0x61
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x22b0
movq (%r14), %rdi
movl 0x1fdb0(%rip), %edx     # 0x315f0
movl 0x1e961(%rip), %r8d     # 0x301a8
addl %r8d, %r8d
leaq 0xfead(%rip), %rsi      # 0x216fe
movl %r15d, %ecx
xorl %eax, %eax
callq 0x21c0
movq (%r14), %rcx
leaq 0xfef5(%rip), %rdi      # 0x2175a
pushq $0x23
popq %rsi
movq %rbx, %rdx
callq 0x22b0
movq (%r14), %rcx
leaq 0xff04(%rip), %rdi      # 0x2177e
pushq $0x3f
popq %rsi
movq %rbx, %rdx
callq 0x22b0
jmp 0x11801