// File: /workspace/github_c_makefile_star2_O1/dapogon[P]cellcoal/src/cellcoal.c
// Function: SiteReadCounts
void SiteReadCounts (CellSiteStr *c, int i, int j, double *probs, double **ngsEij, double **ampEijmat, double **ampEijpat, long int *seed)
	{
	int		k, l, m;
	int		read, template;
	int		numMaternalReads, numPaternalReads;
	int		numReads;
	int		*readCount;
	int		maternalAllele, paternalAllele;
	int		thereIsMaternalAllele, thereIsPaternalAllele;
	double  maternalSiteAmplificationError, paternalSiteAmplificationError;
	int		ampErrorMaternalAllele, ampErrorPaternalAllele, goodTemplate, badTemplate;
	int		readsLeft, badReads;
	double	cumProb;
	double	uniform, goodTemplateProb, badTemplateProb, noSeqError;
	double 	allelicImbalance;
	
	readCount = c->readCount;
	
	thereIsMaternalAllele = YES;
	thereIsPaternalAllele = YES;
	
	maternalAllele = data[MATERNAL][i][j];
	if (maternalAllele == ADO || maternalAllele == DELETION)
		thereIsMaternalAllele = NO;
	
	paternalAllele = data[PATERNAL][i][j];
	if (paternalAllele == ADO || paternalAllele == DELETION)
		thereIsPaternalAllele = NO;
	
	/* initialize some variables */
	noSeqError = 0;
	badTemplateProb = 0;
	goodTemplateProb = 0;
	ampErrorMaternalAllele = -9;
	ampErrorPaternalAllele = -9;
	badTemplate = -9;
	goodTemplate = -9;
	maternalSiteAmplificationError = 0;
	paternalSiteAmplificationError = 0;
	
	/* sample maternal allelic imbalance for this genotype */
	if (doAllelicImbalance == YES)
		allelicImbalance = RandomBetaMeanVar(meanAllelicImbalance, varAllelicImbalance, seed);
	else
		allelicImbalance = 0.5;

	/* number of reads will follow a Poisson or a Negative Binomial distribution (overdispersed coverage) around mean coverage, and are randomly assigned to maternal/paternal chromosome */
	numMaternalReads = 0;
	numPaternalReads = 0;
	
	if (rateVarCoverage == YES) /* Negative Binomial */
		{
		if (thereIsMaternalAllele == YES && thereIsPaternalAllele == YES) /* both alleles are present */
			{
			numMaternalReads = RandomNegativeBinomial(allelicImbalance*coverage, alphaCoverage, seed);
			numPaternalReads = RandomNegativeBinomial((1.0-allelicImbalance)*coverage, alphaCoverage, seed);
			}
		else if (thereIsMaternalAllele == YES && thereIsPaternalAllele == NO)  /* only maternal allele */
			{
			numMaternalReads = RandomNegativeBinomial(haploidCoverageReduction*coverage, alphaCoverage, seed);
			numPaternalReads = 0;
			}
		else if (thereIsMaternalAllele == NO && thereIsPaternalAllele == YES)  /* only paternal allele */
			{
			numMaternalReads = 0;
			numPaternalReads = RandomNegativeBinomial(haploidCoverageReduction*coverage, alphaCoverage, seed);
			}
		else /* no allele is present (locus dropout/deletion) */
			{
			numMaternalReads = 0;
			numPaternalReads = 0;
			}
		}
	else /* Poisson distributed */
		{
		if (thereIsMaternalAllele == YES && thereIsPaternalAllele == YES) /* both alleles are present */
			{
			numMaternalReads = RandomPoisson(allelicImbalance*coverage, seed);
			numPaternalReads = RandomPoisson((1.0-allelicImbalance)*coverage, seed);
			}
		else if (thereIsMaternalAllele == YES && thereIsPaternalAllele == NO)  /* only maternal allele */
			{
			numMaternalReads = RandomPoisson(haploidCoverageReduction*coverage, seed);
			numPaternalReads = 0;
			}
		else if (thereIsMaternalAllele == NO && thereIsPaternalAllele == YES)  /* only paternal allele */
			{
			numMaternalReads = 0;
			numPaternalReads = RandomPoisson(haploidCoverageReduction*coverage, seed);
			}
		else /* no allele is present (locus dropout/deletion) */
			{
			numMaternalReads = 0;
			numPaternalReads = 0;
			}
		}
	
	numReads = numMaternalReads + numPaternalReads;
	
	/* read count simulation */
	readCount[A] = readCount[C] = readCount[G] = readCount[T] = 0;

	if (numReads > 0)
		{
		/* choose amplification error for this site. In this case we will have a proportion of alternative templates depending on whether the error occurred early or late in the amplification (we use a Beta distribution to modelize this proportion) */
		if (meanAmplificationError > 0)
			{
			maternalSiteAmplificationError = RandomBetaMeanVar(meanAmplificationError, varAmplificationError, seed);
			paternalSiteAmplificationError = RandomBetaMeanVar(meanAmplificationError, varAmplificationError, seed);
			}
		
		/* initialize ampEijmat */
		for (k=0; k<4; k++)
			for (l=0; l<4; l++)
				{
				if (k == l)
					ampEijmat[k][l] = 1.0 - maternalSiteAmplificationError;
				else
					ampEijmat[k][l] = Eij[k][l]/cumEij[k][3] * maternalSiteAmplificationError;
				}
		
		/* initialize ampEijpat */
		for (k=0; k<4; k++)
			for (l=0; l<4; l++)
				{
				if (k == l)
					ampEijpat[k][l] = 1.0 - paternalSiteAmplificationError;
				else
					ampEijpat[k][l] = Eij[k][l]/cumEij[k][3] * paternalSiteAmplificationError;
				}
		
		if (simulateOnlyTwoTemplates == YES)
			{
			/* choose base for wrong maternal template */
			ampErrorMaternalAllele = maternalAllele;
			if (maternalSiteAmplificationError > 0 && thereIsMaternalAllele == YES )
				{
				uniform = RandomUniform(seed) * cumEij[maternalAllele][3];
				for (m=0; m<4; m++)
					if (uniform <= cumEij[maternalAllele][m])
						{
						ampErrorMaternalAllele = m;
						break;
						}
				}
			/* choose base for wrong paternal template */
			ampErrorPaternalAllele = paternalAllele;
			if (paternalSiteAmplificationError > 0 && thereIsPaternalAllele == YES )
				{
				uniform = RandomUniform(seed) * cumEij[paternalAllele][3];
				for (m=0; m<4; m++)
					if (uniform <= cumEij[paternalAllele][m])
						{
						ampErrorPaternalAllele = m;
						break;
						}
				}
			}
		
		/* probabilities for the different types of reads  */
		if (sequencingError > 0 || maternalSiteAmplificationError > 0 || paternalSiteAmplificationError > 0)
			{
			if (thereIsMaternalAllele == YES)
				{
				if (simulateOnlyTwoTemplates == YES)
					{
					/* probabilities for maternal reads  (assuming a chosen template )*/
					noSeqError = 1.0 - sequencingError;
					badTemplateProb = maternalSiteAmplificationError;
					goodTemplateProb = 1.0 - maternalSiteAmplificationError;
					badTemplate = ampErrorMaternalAllele;
					goodTemplate = maternalAllele;
					for (read=0; read<4; read++)
						{
						if (read == maternalAllele)
							probs[read] = goodTemplateProb * noSeqError + badTemplateProb * ngsEij[badTemplate][read];
						else if (read == ampErrorMaternalAllele)
							probs[read] = goodTemplateProb * ngsEij[goodTemplate][read] + badTemplateProb * noSeqError;
						else
							probs[read] = goodTemplateProb * ngsEij[goodTemplate][read] + badTemplateProb * ngsEij[badTemplate][read];
						}
					}
				else
					{
					/* probabilities for maternal reads integrating over all potential templates) */
					for (read=0; read<4; read++)
						{
						probs[read] = 0;
						for (template=0; template<4; template++)
							probs[read] += ampEijmat[maternalAllele][template] * ngsEij[template][read];
						}
					}
				
				cumProb = 0;
				readsLeft = numMaternalReads;
				/* multinomial assignment of reads */
				for (read=0; read<4; read++)
					{
					if (read != maternalAllele)
						{
						badReads = RandomBinomial (probs[read] / (1 - cumProb), readsLeft, seed);
						readsLeft -= badReads;
						readCount[read] += badReads;
						cumProb += probs[read];
						}
					}
				readCount[maternalAllele] += readsLeft; /* good reads */
				}
			
			if (thereIsPaternalAllele == YES)
				{
				if (simulateOnlyTwoTemplates == YES)
					{
					/* probabilities for paternal reads  (assuming a chosen template )*/
					badTemplateProb = paternalSiteAmplificationError;
					goodTemplateProb = 1.0 - paternalSiteAmplificationError;
					badTemplate = ampErrorPaternalAllele;
					goodTemplate = paternalAllele;
					
					for (read=0; read<4; read++)
						{
						if (read == paternalAllele)
							probs[read] = goodTemplateProb * noSeqError + badTemplateProb * ngsEij[badTemplate][read];
						else if (read == ampErrorPaternalAllele)
							probs[read] = goodTemplateProb * ngsEij[goodTemplate][read] + badTemplateProb * noSeqError;
						else
							probs[read] = goodTemplateProb * ngsEij[goodTemplate][read] + badTemplateProb * ngsEij[badTemplate][read];
						}
					}
				else
					{
					/* probabilities for paternal reads  (integrating over all potential templates) */
					for (read=0; read<4; read++)
						{
						probs[read] = 0;
						for (template=0; template<4; template++)
							probs[read] += ampEijpat[paternalAllele][template] * ngsEij[template][read];
						}
					}
				
				cumProb = 0;
				readsLeft = numPaternalReads;
				/* multinomial assignment of reads */
				for (read=0; read<4; read++)
					{
					if (read != paternalAllele)
						{
						badReads = RandomBinomial (probs[read] / (1 - cumProb), readsLeft, seed);
						readsLeft -= badReads;
						readCount[read] += badReads;
						cumProb += probs[read];
						}
					}
				readCount[paternalAllele] += readsLeft; // good reads
				}
			}
		else /* no sequencing or amplification error */
			{
			readCount[maternalAllele] += numMaternalReads;
			readCount[paternalAllele] += numPaternalReads;
			}
		} // numReads > 0
	
	c->numReads = numReads;
	c->readCount = readCount;
	c->maternalAllele = maternalAllele;
	c->paternalAllele = paternalAllele;
	c->thereIsMaternalAllele = thereIsMaternalAllele;
	c->thereIsPaternalAllele = thereIsPaternalAllele;
	c->maternalSiteAmplificationError = maternalSiteAmplificationError;
	c->paternalSiteAmplificationError = paternalSiteAmplificationError;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, %rbx
movq %r8, %r12
movq %rcx, %r14
movq %rdi, %r13
movq 0xa8(%rsp), %rdi
movq 0x8(%r13), %rax
movq %rax, 0x18(%rsp)
movq 0x2af20(%rip), %rax     # 0x435b8
movslq %esi, %rcx
movq (%rax), %rsi
movq 0x8(%rax), %rax
movq (%rsi,%rcx,8), %rsi
movslq %edx, %rdx
movl (%rsi,%rdx,4), %esi
movq %rsi, 0x20(%rsp)
addl $-0x7, %esi
movl %esi, 0x64(%rsp)
testl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
setne %bpl
movq (%rax,%rcx,8), %rax
movl (%rax,%rdx,4), %ecx
movq %rcx, 0x10(%rsp)
leal -0x7(%rcx), %eax
movl %eax, 0x60(%rsp)
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
setne %r15b
movsd 0x29d8a(%rip), %xmm0    # 0x42470
ucomisd 0x1b91a(%rip), %xmm0    # 0x34008
jne 0x1870d
jp 0x1870d
movsd 0x29d7e(%rip), %xmm0    # 0x42478
movsd 0x29d7e(%rip), %xmm1    # 0x42480
callq 0x18601
movapd %xmm0, %xmm1
jmp 0x18715
movsd 0x1b90b(%rip), %xmm1    # 0x34020
andb %r15b, %bpl
cmpb $0x1, 0x29cd1(%rip)     # 0x423f0
movq %r13, 0x50(%rsp)
jne 0x18796
testb %bpl, %bpl
movq 0x18(%rsp), %r15
je 0x18864
movsd 0x29cac(%rip), %xmm0    # 0x423e8
mulsd %xmm1, %xmm0
movsd %xmm1, 0x30(%rsp)
movsd 0x29c2a(%rip), %xmm1    # 0x42378
movq 0xa8(%rsp), %rbp
movq %rbp, %rdi
callq 0x19f6a
movl %eax, %r13d
movsd 0x1b89f(%rip), %xmm0    # 0x34008
subsd 0x30(%rsp), %xmm0
mulsd 0x29c71(%rip), %xmm0    # 0x423e8
movsd 0x29bf9(%rip), %xmm1    # 0x42378
movq %rbp, %rdi
callq 0x19f6a
movq %r15, %r11
movl %eax, %ebp
movq 0x20(%rsp), %r9
jmp 0x18a40
testb %bpl, %bpl
movq 0x18(%rsp), %r11
je 0x188c2
movsd 0x29c3c(%rip), %xmm0    # 0x423e8
movsd %xmm1, 0x30(%rsp)
mulsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorpd %xmm1, %xmm1
movq 0xa8(%rsp), %rbp
movsd %xmm1, 0x8(%rsp)
movsd 0x28(%rsp), %xmm0
movq %rbp, %rdi
callq 0x165c5
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
incl %r13d
movsd 0x1b811(%rip), %xmm0    # 0x34008
ucomisd %xmm1, %xmm0
jae 0x187ce
movsd 0x1b803(%rip), %xmm0    # 0x34008
subsd 0x30(%rsp), %xmm0
mulsd 0x29bd5(%rip), %xmm0    # 0x423e8
movsd %xmm0, 0x28(%rsp)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorpd %xmm1, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x28(%rsp), %xmm0
movq %rbp, %rdi
callq 0x165c5
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
incl %r15d
movsd 0x1b7bc(%rip), %xmm0    # 0x34008
ucomisd %xmm1, %xmm0
jae 0x18823
movq 0x20(%rsp), %r9
movl %r15d, %ebp
movq 0x18(%rsp), %r11
jmp 0x18a40
movq 0x10(%rsp), %rax
cmpl $0x9, %eax
movq 0x20(%rsp), %r9
movq 0xa8(%rsp), %rdi
je 0x18884
cmpl $0x7, %eax
jne 0x18960
cmpl $0x7, %r9d
je 0x18970
cmpl $0x9, %r9d
je 0x18970
movsd 0x29bc8(%rip), %xmm0    # 0x42468
mulsd 0x29b40(%rip), %xmm0    # 0x423e8
movsd 0x29ac8(%rip), %xmm1    # 0x42378
callq 0x19f6a
movq 0x20(%rsp), %r9
movl %eax, %r13d
jmp 0x18a34
movq 0x10(%rsp), %rax
cmpl $0x9, %eax
movq 0x20(%rsp), %r9
movq 0xa8(%rsp), %rbp
je 0x188e2
cmpl $0x7, %eax
jne 0x189b3
cmpl $0x7, %r9d
je 0x189bf
cmpl $0x9, %r9d
je 0x189bf
movq %r11, %r15
movsd 0x29b67(%rip), %xmm0    # 0x42468
mulsd 0x29adf(%rip), %xmm0    # 0x423e8
movsd %xmm0, 0x28(%rsp)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x28(%rsp), %xmm0
movq %rbp, %rdi
callq 0x165c5
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
incl %r13d
movsd 0x1b6ba(%rip), %xmm1    # 0x34008
ucomisd %xmm0, %xmm1
jae 0x18919
xorl %ebp, %ebp
movq 0x20(%rsp), %r9
jmp 0x18a36
cmpl $0x9, %r9d
je 0x18970
cmpl $0x7, %r9d
jne 0x18a31
xorl %r13d, %r13d
movq 0x10(%rsp), %rax
cmpl $0x7, %eax
je 0x18a34
cmpl $0x9, %eax
je 0x18a34
movsd 0x29ad6(%rip), %xmm0    # 0x42468
mulsd 0x29a4e(%rip), %xmm0    # 0x423e8
movsd 0x299d6(%rip), %xmm1    # 0x42378
callq 0x19f6a
movq 0x20(%rsp), %r9
movl %eax, %ebp
jmp 0x18a36
cmpl $0x9, %r9d
je 0x189bf
cmpl $0x7, %r9d
jne 0x18a3b
xorl %r13d, %r13d
movq 0x10(%rsp), %rax
cmpl $0x7, %eax
je 0x18a3e
cmpl $0x9, %eax
je 0x18a3e
movsd 0x29a8f(%rip), %xmm0    # 0x42468
mulsd 0x29a07(%rip), %xmm0    # 0x423e8
movsd %xmm0, 0x28(%rsp)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x28(%rsp), %xmm0
movq %rbp, %rdi
callq 0x165c5
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
incl %r15d
movsd 0x1b5e2(%rip), %xmm1    # 0x34008
ucomisd %xmm0, %xmm1
jae 0x189f1
jmp 0x18852
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %r15, %r11
jmp 0x18a40
xorl %r13d, %r13d
xorl %ebp, %ebp
movl %ebp, %ecx
xorpd %xmm0, %xmm0
movupd %xmm0, (%r11)
addl %r13d, %ecx
jle 0x18d6a
movslq %r9d, %rax
movq %rax, 0x40(%rsp)
movslq 0x10(%rsp), %rax
movq %rax, 0x48(%rsp)
movsd 0x299e2(%rip), %xmm0    # 0x42450
xorpd %xmm5, %xmm5
ucomisd %xmm5, %xmm0
xorpd %xmm6, %xmm6
movl %ecx, 0x3c(%rsp)
jbe 0x18ac5
movsd 0x299d0(%rip), %xmm1    # 0x42458
movq 0xa8(%rsp), %r15
movq %r15, %rdi
callq 0x18601
movsd %xmm0, 0x8(%rsp)
movsd 0x299aa(%rip), %xmm0    # 0x42450
movsd 0x299aa(%rip), %xmm1    # 0x42458
movq %r15, %rdi
callq 0x18601
movsd 0x8(%rsp), %xmm5
movq 0x20(%rsp), %r9
movapd %xmm0, %xmm6
movq 0xa0(%rsp), %r10
movsd 0x1b533(%rip), %xmm0    # 0x34008
subsd %xmm5, %xmm0
leaq 0x297f0(%rip), %rax     # 0x422d0
xorl %ecx, %ecx
leaq 0x29b57(%rip), %rsi     # 0x42640
movq %rcx, %rdx
shlq $0x5, %rdx
addq %rsi, %rdx
addq $0x18, %rdx
movq (%rbx,%rcx,8), %rdi
xorl %r8d, %r8d
movapd %xmm0, %xmm1
cmpq %r8, %rcx
je 0x18b15
movsd (%rax,%r8,8), %xmm1
divsd (%rdx), %xmm1
mulsd %xmm5, %xmm1
movsd %xmm1, (%rdi,%r8,8)
incq %r8
cmpq $0x4, %r8
jne 0x18afe
incq %rcx
addq $0x20, %rax
cmpq $0x4, %rcx
jne 0x18ae9
movsd 0x1b4cf(%rip), %xmm0    # 0x34008
subsd %xmm6, %xmm0
leaq 0x2978c(%rip), %rax     # 0x422d0
xorl %ecx, %ecx
movq %rcx, %rdx
shlq $0x5, %rdx
addq %rsi, %rdx
addq $0x18, %rdx
movq (%r10,%rcx,8), %rdi
xorl %r8d, %r8d
movapd %xmm0, %xmm1
cmpq %r8, %rcx
je 0x18b72
movsd (%rax,%r8,8), %xmm1
divsd (%rdx), %xmm1
mulsd %xmm6, %xmm1
movsd %xmm1, (%rdi,%r8,8)
incq %r8
cmpq $0x4, %r8
jne 0x18b5b
incq %rcx
addq $0x20, %rax
cmpq $0x4, %rcx
jne 0x18b46
movl 0x298cc(%rip), %edi     # 0x42460
movl $0xfffffff7, %r8d       # imm = 0xFFFFFFF7
movl $0xfffffff7, %r15d      # imm = 0xFFFFFFF7
cmpl $0x1, %edi
jne 0x18d21
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm5
movl %r9d, %r8d
jbe 0x18c68
movl %r9d, %r8d
cmpl $0x7, %r9d
je 0x18c68
movl %r9d, %r8d
cmpl $0x9, %r9d
je 0x18c68
movq 0xa8(%rsp), %r8
movq (%r8), %rcx
movabsq $0x41a705af1fe3fb79, %rdx # imm = 0x41A705AF1FE3FB79
movq %rcx, %rax
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), %rax
cmovgq %rdx, %rax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
movq %rax, (%r8)
divsd 0x1b3ed(%rip), %xmm1    # 0x34028
movq 0x40(%rsp), %rax
shlq $0x5, %rax
mulsd 0x18(%rax,%rsi), %xmm1
xorl %r8d, %r8d
leaq (%rax,%r8,8), %rcx
movsd (%rsi,%rcx), %xmm2
ucomisd %xmm1, %xmm2
jae 0x18c68
incq %r8
cmpq $0x4, %r8
jne 0x18c4d
movl %r9d, %r8d
ucomisd %xmm0, %xmm6
jbe 0x18d1c
movq 0x10(%rsp), %r15
cmpl $0x7, %r15d
je 0x18d21
cmpl $0x9, %r15d
je 0x18d21
movq 0xa8(%rsp), %r10
movq (%r10), %rcx
movabsq $0x41a705af1fe3fb79, %rdx # imm = 0x41A705AF1FE3FB79
movq %rcx, %rax
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), %rax
cmovgq %rdx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movq %rax, (%r10)
divsd 0x1b336(%rip), %xmm0    # 0x34028
movq 0x48(%rsp), %rax
shlq $0x5, %rax
mulsd 0x18(%rax,%rsi), %xmm0
xorl %r15d, %r15d
leaq (%rax,%r15,8), %rcx
movsd (%rsi,%rcx), %xmm1
ucomisd %xmm0, %xmm1
jae 0x18d21
incq %r15
cmpq $0x4, %r15
jne 0x18d04
movq 0x10(%rsp), %r15
movsd 0x2970f(%rip), %xmm0    # 0x42438
xorpd %xmm2, %xmm2
xorpd %xmm1, %xmm1
movsd %xmm1, 0x58(%rsp)
ucomisd %xmm2, %xmm6
ja 0x18d83
ucomisd 0x1b2fb(%rip), %xmm5    # 0x34040
ja 0x18d83
ucomisd %xmm1, %xmm0
ja 0x18d83
movq 0x18(%rsp), %r11
movq 0x40(%rsp), %rax
addl %r13d, (%r11,%rax,4)
movq 0x50(%rsp), %r13
movq 0x10(%rsp), %r12
jmp 0x190bc
xorpd %xmm5, %xmm5
xorpd %xmm6, %xmm6
movq 0x50(%rsp), %r13
movq 0x10(%rsp), %r12
movl %ecx, %edx
jmp 0x190c9
cmpl $0x7, %r9d
movsd %xmm5, 0x8(%rsp)
movsd %xmm6, 0x28(%rsp)
je 0x18f16
cmpl $0x9, %r9d
je 0x18f16
cmpl $0x1, %edi
jne 0x18e53
movsd 0x1b254(%rip), %xmm1    # 0x34008
movapd %xmm1, %xmm3
subsd %xmm0, %xmm3
movapd %xmm1, %xmm0
subsd %xmm5, %xmm0
movslq %r8d, %rax
movapd %xmm5, %xmm1
mulsd %xmm3, %xmm1
movl %eax, %ecx
leaq (,%r9,8), %rdx
shlq $0x3, %rcx
xorl %esi, %esi
movapd %xmm0, %xmm2
movsd %xmm3, 0x58(%rsp)
mulsd %xmm3, %xmm2
movq 0x40(%rsp), %r10
cmpq %rsi, %rdx
jne 0x18e0a
movq (%r12,%rax,8), %rdi
movsd (%rdi,%rsi), %xmm3
mulsd %xmm5, %xmm3
addsd %xmm2, %xmm3
jmp 0x18e41
cmpq %rsi, %rcx
jne 0x18e22
movq (%r12,%r10,8), %rdi
movsd (%rdi,%rsi), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm1, %xmm3
jmp 0x18e41
movq (%r12,%r10,8), %rdi
movq (%r12,%rax,8), %r8
movsd (%r8,%rsi), %xmm4
mulsd %xmm5, %xmm4
movsd (%rdi,%rsi), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm4, %xmm3
movsd %xmm3, (%r14,%rsi)
addq $0x8, %rsi
cmpq $0x20, %rsi
jne 0x18df2
jmp 0x18ea0
movq 0x40(%rsp), %rax
movq (%rbx,%rax,8), %rax
xorl %ecx, %ecx
movq $0x0, (%r14,%rcx,8)
xorpd %xmm0, %xmm0
xorl %edx, %edx
movsd (%rax,%rdx,8), %xmm1
movq (%r12,%rdx,8), %rsi
mulsd (%rsi,%rcx,8), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, (%r14,%rcx,8)
incq %rdx
cmpq $0x4, %rdx
jne 0x18e6c
incq %rcx
cmpq $0x4, %rcx
jne 0x18e5e
xorpd %xmm0, %xmm0
movsd %xmm0, 0x58(%rsp)
xorpd %xmm2, %xmm2
xorl %ebx, %ebx
cmpq %rbx, %r9
je 0x18eff
movsd (%r14,%rbx,8), %xmm0
movsd 0x1b14f(%rip), %xmm1    # 0x34008
subsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movl %r13d, %edi
movq 0xa8(%rsp), %rsi
movsd %xmm2, 0x30(%rsp)
callq 0x17391
movsd 0x30(%rsp), %xmm2
movsd 0x28(%rsp), %xmm6
movsd 0x8(%rsp), %xmm5
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %rcx
addl %eax, (%rcx,%rbx,4)
subl %eax, %r13d
addsd (%r14,%rbx,8), %xmm2
incq %rbx
cmpq $0x4, %rbx
jne 0x18ea6
movq 0x18(%rsp), %rax
movq 0x40(%rsp), %rcx
addl %r13d, (%rax,%rcx,4)
movq 0x10(%rsp), %rax
cmpl $0x7, %eax
je 0x18f39
cmpl $0x9, %eax
movq 0x50(%rsp), %r13
jne 0x18f4b
movq 0x18(%rsp), %r11
movq 0x10(%rsp), %r12
jmp 0x190c5
movq 0x50(%rsp), %r13
movq 0x18(%rsp), %r11
movq %rax, %r12
jmp 0x190c5
cmpl $0x1, 0x2950e(%rip)     # 0x42460
jne 0x18ff9
movsd 0x1b0a8(%rip), %xmm0    # 0x34008
subsd %xmm6, %xmm0
movslq %r15d, %rax
movapd %xmm6, %xmm1
movsd 0x58(%rsp), %xmm4
mulsd %xmm4, %xmm1
movl %eax, %ecx
movq 0x10(%rsp), %rdx
leaq (,%rdx,8), %rdx
shlq $0x3, %rcx
xorl %esi, %esi
mulsd %xmm0, %xmm4
movq 0x18(%rsp), %r11
movq 0x48(%rsp), %r10
cmpq %rsi, %rdx
jne 0x18fb0
movq (%r12,%rax,8), %rdi
movsd (%rdi,%rsi), %xmm2
mulsd %xmm6, %xmm2
addsd %xmm4, %xmm2
jmp 0x18fe7
cmpq %rsi, %rcx
jne 0x18fc8
movq (%r12,%r10,8), %rdi
movsd (%rdi,%rsi), %xmm2
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
jmp 0x18fe7
movq (%r12,%r10,8), %rdi
movq (%r12,%rax,8), %r8
movsd (%r8,%rsi), %xmm3
mulsd %xmm6, %xmm3
movsd (%rdi,%rsi), %xmm2
mulsd %xmm0, %xmm2
addsd %xmm3, %xmm2
movsd %xmm2, (%r14,%rsi)
addq $0x8, %rsi
cmpq $0x20, %rsi
jne 0x18f98
jmp 0x19049
movq 0x48(%rsp), %rax
movq 0xa0(%rsp), %rcx
movq (%rcx,%rax,8), %rax
xorl %ecx, %ecx
movq 0x18(%rsp), %r11
movq $0x0, (%r14,%rcx,8)
xorpd %xmm0, %xmm0
xorl %edx, %edx
movsd (%rax,%rdx,8), %xmm1
movq (%r12,%rdx,8), %rsi
mulsd (%rsi,%rcx,8), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, (%r14,%rcx,8)
incq %rdx
cmpq $0x4, %rdx
jne 0x1901f
incq %rcx
cmpq $0x4, %rcx
jne 0x19011
xorpd %xmm2, %xmm2
xorl %ebx, %ebx
movq 0x10(%rsp), %r12
cmpq %rbx, %r12
je 0x190b3
movsd (%r14,%rbx,8), %xmm0
movsd 0x1afa1(%rip), %xmm1    # 0x34008
subsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movl %ebp, %edi
movq 0xa8(%rsp), %rsi
movl %ebp, %r15d
movq %r11, %rbp
movsd %xmm2, 0x30(%rsp)
callq 0x17391
movsd 0x30(%rsp), %xmm2
movq %rbp, %r11
movl %r15d, %ebp
movsd 0x28(%rsp), %xmm6
movsd 0x8(%rsp), %xmm5
movq 0x20(%rsp), %r9
addl %eax, (%r11,%rbx,4)
subl %eax, %ebp
addsd (%r14,%rbx,8), %xmm2
incq %rbx
cmpq $0x4, %rbx
jne 0x19054
movq 0x48(%rsp), %rax
addl %ebp, (%r11,%rax,4)
movl 0x3c(%rsp), %edx
xorl %eax, %eax
testl $0xfffffffd, 0x60(%rsp) # imm = 0xFFFFFFFD
setne %al
xorl %ecx, %ecx
testl $0xfffffffd, 0x64(%rsp) # imm = 0xFFFFFFFD
setne %cl
movl %edx, (%r13)
movq %r11, 0x8(%r13)
movl %r9d, 0x18(%r13)
movl %r12d, 0x1c(%r13)
movl %ecx, 0x20(%r13)
movl %eax, 0x24(%r13)
movsd %xmm5, 0x28(%r13)
movsd %xmm6, 0x30(%r13)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq