// File: /workspace/github_c_makefile_star2_O0/dapogon[P]cellcoal/src/cellcoal.c
// Function: SimulateDeletionforSite
void SimulateDeletionforSite (TreeNode *p, int genome, int site, long int *seed)
    {
    static double	cumDeletionBranchLength, uniform;
    int             cell, anccell;
		
	if (p != NULL)
        {
        cell = p->label;
			
        if (p->isHealthyRoot == YES)
            {
            cumDeletionBranchLength = 0;
//            uniform = RandomUniform(seed) * allSites[site].deletionBranchSum;
             uniform = RandomUniform(seed) * totalTreeLength / mutationRate * deletionRate;;
           }
        else
            {
            anccell = p->anc->label;
            cumDeletionBranchLength += p->branchLength / mutationRate * deletionRate;
				
             if ((cumDeletionBranchLength < uniform) || /* => there will be no change at this branch */
                ((genome == MATERNAL) && (allSites[site].numDeletionsMaternal > 0)) ||
                ((genome == PATERNAL) && (allSites[site].numDeletionsPaternal > 0)))
                {
                data[genome][cell][site] = data[genome][anccell][site];
                }
			else /* => there will be a deletion */
                {
                if (data[genome][anccell][site] != DELETION)  /* checking all this might be excessive */
                    data[genome][cell][site] = DELETION;
                else if (data[genome][anccell][site] == DELETION)
                    {
                    fprintf (stderr, "\n\n ERROR: site %d in genome %d of cell %d cannot be deleted twice under the ISM model\n", site, genome, cell);
                    exit(-1);
                    }
                else
                    {
                    fprintf (stderr, "\n\n ERROR: site %d in genome %d of cell %d has an unknow state %d under the ISM model\n", site, genome, anccell, data[genome][anccell][site]);
                    exit(-1);
                    }
					
                if (genome == MATERNAL)
                    allSites[site].numDeletionsMaternal++;
                else if (genome == PATERNAL)
                    allSites[site].numDeletionsPaternal++;
                allSites[site].numDeletions++;
                numDEL++;
                }
            }
            SimulateDeletionforSite (p->left, genome, site, seed);
            SimulateDeletionforSite (p->right, genome, site, seed);
        }
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x1d1ce
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x1, 0x24(%rax)
jne 0x1cf6e
xorps %xmm0, %xmm0
movsd %xmm0, 0x33330(%rip)    # 0x50270
movq -0x18(%rbp), %rdi
callq 0xa500
mulsd 0x32837(%rip), %xmm0    # 0x4f788
divsd 0x312af(%rip), %xmm0    # 0x4e208
mulsd 0x32897(%rip), %xmm0    # 0x4f7f8
movsd %xmm0, 0x3330f(%rip)    # 0x50278
jmp 0x1d1a1
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movsd 0x40(%rax), %xmm0
divsd 0x3127b(%rip), %xmm0    # 0x4e208
movsd 0x32863(%rip), %xmm2    # 0x4f7f8
movsd 0x332d3(%rip), %xmm1    # 0x50270
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x332c3(%rip)    # 0x50270
movsd 0x332bb(%rip), %xmm1    # 0x50270
movsd 0x332bb(%rip), %xmm0    # 0x50278
ucomisd %xmm1, %xmm0
ja 0x1d005
cmpl $0x0, -0xc(%rbp)
jne 0x1cfe4
movq 0x327d8(%rip), %rax     # 0x4f7a8
movslq -0x10(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x1c(%rax)
jg 0x1d005
cmpl $0x1, -0xc(%rbp)
jne 0x1d046
movq 0x327b7(%rip), %rax     # 0x4f7a8
movslq -0x10(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x20(%rax)
jle 0x1d046
movq 0x32794(%rip), %rax     # 0x4f7a0
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x32776(%rip), %rax     # 0x4f7a0
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x1d19f
movq 0x32753(%rip), %rax     # 0x4f7a0
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
cmpl $0x7, (%rax,%rcx,4)
je 0x1d08e
movq 0x32732(%rip), %rax     # 0x4f7a0
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movl $0x7, (%rax,%rcx,4)
jmp 0x1d126
movq 0x3270b(%rip), %rax     # 0x4f7a0
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
cmpl $0x7, (%rax,%rcx,4)
jne 0x1d0db
movq 0x30f42(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
movl -0x10(%rbp), %edx
movl -0xc(%rbp), %ecx
movl -0x1c(%rbp), %r8d
leaq 0x24718(%rip), %rsi     # 0x417e2
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2290
movq 0x30f16(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
movl -0x10(%rbp), %edx
movl -0xc(%rbp), %ecx
movl -0x20(%rbp), %r8d
movq 0x326aa(%rip), %rax     # 0x4f7a0
movslq -0xc(%rbp), %rsi
movq (%rax,%rsi,8), %rax
movslq -0x20(%rbp), %rsi
movq (%rax,%rsi,8), %rax
movslq -0x10(%rbp), %rsi
movl (%rax,%rsi,4), %r9d
leaq 0x24724(%rip), %rsi     # 0x41839
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2290
cmpl $0x0, -0xc(%rbp)
jne 0x1d14c
movq 0x32675(%rip), %rax     # 0x4f7a8
movslq -0x10(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1c(%rax)
jmp 0x1d172
cmpl $0x1, -0xc(%rbp)
jne 0x1d170
movq 0x3264f(%rip), %rax     # 0x4f7a8
movslq -0x10(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
jmp 0x1d172
movq 0x3262f(%rip), %rax     # 0x4f7a8
movslq -0x10(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x18(%rax)
movl 0x325ca(%rip), %eax     # 0x4f760
addl $0x1, %eax
movl %eax, 0x325c1(%rip)     # 0x4f760
jmp 0x1d1a1
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movq -0x18(%rbp), %rcx
callq 0x1cf00
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movq -0x18(%rbp), %rcx
callq 0x1cf00
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)