// File: /workspace/github_c_makefile_star2_O0/dapogon[P]cellcoal/src/cellcoal.c
// Function: AllelicDropout
void AllelicDropout (long int *seed)
	{
	int i,j;
	double alleleADOrateMean = 0.0, alleleADOrateCell = 0.0, alleleADOrateSite = 0.0;
	double **alleleADOrate;

	/* allocate space for the ADO rates */
	alleleADOrate = (double**) calloc (numCells+1, sizeof(double**));
	if (!alleleADOrate)
		{
		fprintf (stderr, "Could not allocate the alleleADOrate structure\n");
		exit (-1);
		}
	for (i=0; i<numCells+1; i++)
		{
		alleleADOrate[i] = (double*) calloc (numSites, sizeof(double*));
		if (!alleleADOrate[i])
			{
			fprintf (stderr, "Could not allocate the alleleADOrate[i] structure\n");
			exit (-1);
			}
		}

	// fixed ADO rate
	if (doADOcell == NO && doADOsite == NO)
		{
		alleleADOrateMean = 1.0 - sqrt (1.0 - fixedADOrate);
		for (i=0; i<numCells+1; i++)
			for (j=0; j<numSites; j++)
				alleleADOrate[i][j] = alleleADOrateMean;
		}
	else // variable ADO rates
		{
		for (i=0; i<numCells+1; i++)
			{
			if (doADOcell == YES)
				alleleADOrateCell = RandomBetaMeanVar(meanADOcell, varADOcell, seed);
			else
				alleleADOrateCell = 0;
			}
		for (j=0; j<numSites; j++)
			{
			if (doADOsite == YES)
				alleleADOrateSite = RandomBetaMeanVar(meanADOsite, varADOsite, seed);
			else
				alleleADOrateSite = 0;
			}
		for (i=0; i<numCells+1; i++)
			{
			for (j=0; j<numSites; j++)
				{
				alleleADOrate[i][j] = alleleADOrateCell + alleleADOrateSite - (alleleADOrateCell * alleleADOrateSite);
				alleleADOrate[i][j] = 1.0 - sqrt (1.0 - alleleADOrate[i][j]); // at the allele level
				}
			}
		}
	

/*	for (i=0; i<numCells+1; i++)
		for (j=0; j<numSites; j++)
			fprintf (stderr, "\ncell %d  site %d  alleleADOrate[i][j] = %6.4f", i+1, j+1, alleleADOrate[i][j]);
*/
	
	for (i=0; i<numCells+1; i++)
		{
		for (j=0; j<numSites; j++)
			{
			if (data[MATERNAL][i][j] != DELETION)
				{
				if (RandomUniform(seed) < alleleADOrate[i][j])
					{
					data[MATERNAL][i][j] = ADO;
					allSites[j].hasADO = YES;
					}
				}
			if (data[PATERNAL][i][j] != DELETION)
				{
				if (RandomUniform(seed) < alleleADOrate[i][j])
					{
					data[PATERNAL][i][j] = ADO;
					allSites[j].hasADO = YES;
					}
				}
			}
		}
	
	// free allele ADO rates
	for (i=0; i<numCells+1; i++)
		free(alleleADOrate[i]);
	free(alleleADOrate);
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x20(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
movl 0x3e0ea(%rip), %eax     # 0x4e1d4
addl $0x1, %eax
movslq %eax, %rdi
movl $0x8, %esi
callq 0x2190
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x10127
movq 0x3deec(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
leaq 0x31779(%rip), %rsi     # 0x4188f
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2290
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl 0x3e09d(%rip), %ecx     # 0x4e1d4
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1019c
movslq 0x3e097(%rip), %rdi     # 0x4e1dc
movl $0x8, %esi
callq 0x2190
movq %rax, %rdx
movq -0x30(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movslq -0xc(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x1018f
movq 0x3de84(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
leaq 0x31741(%rip), %rsi     # 0x418bf
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2290
jmp 0x10191
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x1012e
movsd 0x3e2a4(%rip), %xmm0    # 0x4e448
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x1025b
jp 0x1025b
movsd 0x3e291(%rip), %xmm0    # 0x4e450
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x1025b
jp 0x1025b
movsd 0x2ee46(%rip), %xmm0    # 0x3f020
subsd 0x3e256(%rip), %xmm0    # 0x4e438
callq 0x22a0
movaps %xmm0, %xmm1
movsd 0x2ee2e(%rip), %xmm0    # 0x3f020
subsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl 0x3dfc9(%rip), %ecx     # 0x4e1d4
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x10256
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl 0x3dfba(%rip), %eax     # 0x4e1dc
jge 0x10249
movsd -0x18(%rbp), %xmm0
movq -0x30(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x10219
jmp 0x1024b
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x10202
jmp 0x103fd
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl 0x3df69(%rip), %ecx     # 0x4e1d4
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x102bf
movsd 0x3e1ce(%rip), %xmm0    # 0x4e448
movsd 0x2ed9e(%rip), %xmm1    # 0x3f020
ucomisd %xmm1, %xmm0
jne 0x102aa
jp 0x102aa
movsd 0x3e1c6(%rip), %xmm0    # 0x4e458
movsd 0x3e1c6(%rip), %xmm1    # 0x4e460
movq -0x8(%rbp), %rdi
callq 0x1d1e0
movsd %xmm0, -0x20(%rbp)
jmp 0x102b2
xorps %xmm0, %xmm0
movsd %xmm0, -0x20(%rbp)
jmp 0x102b4
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x10262
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl 0x3df0d(%rip), %eax     # 0x4e1dc
jge 0x1031e
movsd 0x3e177(%rip), %xmm0    # 0x4e450
movsd 0x2ed3f(%rip), %xmm1    # 0x3f020
ucomisd %xmm1, %xmm0
jne 0x10309
jp 0x10309
movsd 0x3e177(%rip), %xmm0    # 0x4e468
movsd 0x3e177(%rip), %xmm1    # 0x4e470
movq -0x8(%rbp), %rdi
callq 0x1d1e0
movsd %xmm0, -0x28(%rbp)
jmp 0x10311
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
jmp 0x10313
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x102c6
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl 0x3dea6(%rip), %ecx     # 0x4e1d4
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x103fb
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl 0x3de93(%rip), %eax     # 0x4e1dc
jge 0x103eb
movsd -0x20(%rbp), %xmm1
addsd -0x28(%rbp), %xmm1
movsd -0x20(%rbp), %xmm0
movsd -0x28(%rbp), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x30(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movsd 0x2ec71(%rip), %xmm0    # 0x3f020
subsd (%rax,%rcx,8), %xmm0
callq 0x22a0
movaps %xmm0, %xmm1
movsd 0x2ec5c(%rip), %xmm0    # 0x3f020
subsd %xmm1, %xmm0
movq -0x30(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x10340
jmp 0x103ed
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x10325
jmp 0x103fd
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl 0x3ddc7(%rip), %ecx     # 0x4e1d4
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1054c
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl 0x3ddb4(%rip), %eax     # 0x4e1dc
jge 0x1053c
movq 0x3f36b(%rip), %rax     # 0x4f7a0
movq (%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
cmpl $0x7, (%rax,%rcx,4)
je 0x104ac
movq -0x8(%rbp), %rdi
callq 0xa500
movaps %xmm0, %xmm1
movq -0x30(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x104aa
movq 0x3f328(%rip), %rax     # 0x4f7a0
movq (%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movl $0x9, (%rax,%rcx,4)
movq 0x3f313(%rip), %rax     # 0x4f7a8
movslq -0x10(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
movl $0x1, 0x30(%rax)
jmp 0x104ac
movq 0x3f2ed(%rip), %rax     # 0x4f7a0
movq 0x8(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
cmpl $0x7, (%rax,%rcx,4)
je 0x1052c
movq -0x8(%rbp), %rdi
callq 0xa500
movaps %xmm0, %xmm1
movq -0x30(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1052a
movq 0x3f2a9(%rip), %rax     # 0x4f7a0
movq 0x8(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movl $0x9, (%rax,%rcx,4)
movq 0x3f293(%rip), %rax     # 0x4f7a8
movslq -0x10(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
movl $0x1, 0x30(%rax)
jmp 0x1052c
jmp 0x1052e
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x1041f
jmp 0x1053e
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x10404
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl 0x3dc78(%rip), %ecx     # 0x4e1d4
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1057f
movq -0x30(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2030
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x10553
movq -0x30(%rbp), %rdi
callq 0x2030
addq $0x30, %rsp
popq %rbp
retq
nop