// File: /workspace/github_c_makefile_star2_O3/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, 0x28(%rsp)
movq 0x1eb9a(%rip), %rax     # 0x375b8
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, 0x18(%rsp)
addl $-0x7, %esi
testl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
setne %bpl
movq (%rax,%rcx,8), %rax
movl (%rax,%rdx,4), %eax
movq %rax, 0x10(%rsp)
addl $-0x7, %eax
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
setne %r15b
movsd 0x1da0c(%rip), %xmm0    # 0x36470
ucomisd 0xa694(%rip), %xmm0     # 0x23100
jne 0x18a8b
jp 0x18a8b
movsd 0x1da00(%rip), %xmm0    # 0x36478
movsd 0x1da00(%rip), %xmm1    # 0x36480
callq 0x18987
movapd %xmm0, %xmm1
jmp 0x18a93
movsd 0xa685(%rip), %xmm1     # 0x23118
andb %r15b, %bpl
cmpb $0x1, 0x1d953(%rip)     # 0x363f0
movq %r13, 0x50(%rsp)
jne 0x18b11
testb %bpl, %bpl
je 0x18bda
movsd 0x1d933(%rip), %xmm0    # 0x363e8
mulsd %xmm1, %xmm0
movsd %xmm1, 0x40(%rsp)
movsd 0x1d8b1(%rip), %xmm1    # 0x36378
movq 0xa8(%rsp), %rbp
movq %rbp, %rdi
callq 0x1a27d
movl %eax, %r13d
movsd 0xa61e(%rip), %xmm0     # 0x23100
subsd 0x40(%rsp), %xmm0
mulsd 0x1d8f8(%rip), %xmm0    # 0x363e8
movsd 0x1d880(%rip), %xmm1    # 0x36378
movq %rbp, %rdi
callq 0x1a27d
movl %eax, %ebp
movq 0x18(%rsp), %r10
movq 0x10(%rsp), %r8
jmp 0x18dac
testb %bpl, %bpl
je 0x18c3f
movsd 0x1d8c6(%rip), %xmm0    # 0x363e8
movsd %xmm1, 0x40(%rsp)
mulsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorpd %xmm1, %xmm1
movq 0xa8(%rsp), %rbp
movsd %xmm1, 0x8(%rsp)
movsd 0x30(%rsp), %xmm0
movq %rbp, %rdi
callq 0x1687f
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
incl %r13d
movsd 0xa593(%rip), %xmm0     # 0x23100
ucomisd %xmm1, %xmm0
jae 0x18b44
movsd 0xa585(%rip), %xmm0     # 0x23100
subsd 0x40(%rsp), %xmm0
mulsd 0x1d85f(%rip), %xmm0    # 0x363e8
movsd %xmm0, 0x30(%rsp)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorpd %xmm1, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x30(%rsp), %xmm0
movq %rbp, %rdi
callq 0x1687f
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
incl %r15d
movsd 0xa53e(%rip), %xmm0     # 0x23100
ucomisd %xmm1, %xmm0
jae 0x18b99
movq 0x18(%rsp), %r10
movq 0x10(%rsp), %r8
movl %r15d, %ebp
jmp 0x18dac
movq 0x10(%rsp), %r8
cmpl $0x9, %r8d
movq 0x18(%rsp), %r10
movq 0xa8(%rsp), %rdi
je 0x18bfc
cmpl $0x7, %r8d
jne 0x18cd7
cmpl $0x7, %r10d
je 0x18ce7
cmpl $0x9, %r10d
je 0x18ce7
movsd 0x1d850(%rip), %xmm0    # 0x36468
mulsd 0x1d7c8(%rip), %xmm0    # 0x363e8
movsd 0x1d750(%rip), %xmm1    # 0x36378
callq 0x1a27d
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %r10
movl %eax, %r13d
jmp 0x18daa
movq 0x10(%rsp), %r8
cmpl $0x9, %r8d
movq 0x18(%rsp), %r10
movq 0xa8(%rsp), %rbp
je 0x18c61
cmpl $0x7, %r8d
jne 0x18d2c
cmpl $0x7, %r10d
je 0x18d38
cmpl $0x9, %r10d
je 0x18d38
movsd 0x1d7eb(%rip), %xmm0    # 0x36468
mulsd 0x1d763(%rip), %xmm0    # 0x363e8
movsd %xmm0, 0x30(%rsp)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x30(%rsp), %xmm0
movq %rbp, %rdi
callq 0x1687f
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
incl %r13d
movsd 0xa436(%rip), %xmm1     # 0x23100
ucomisd %xmm0, %xmm1
jae 0x18c95
xorl %ebp, %ebp
jmp 0x18b02
cmpl $0x9, %r10d
je 0x18ce7
cmpl $0x7, %r10d
jne 0x18da7
xorl %r13d, %r13d
cmpl $0x7, %r8d
je 0x18daa
cmpl $0x9, %r8d
je 0x18daa
movsd 0x1d762(%rip), %xmm0    # 0x36468
mulsd 0x1d6da(%rip), %xmm0    # 0x363e8
movsd 0x1d662(%rip), %xmm1    # 0x36378
callq 0x1a27d
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %r10
movl %eax, %ebp
jmp 0x18dac
cmpl $0x9, %r10d
je 0x18d38
cmpl $0x7, %r10d
jne 0x18da7
xorl %r13d, %r13d
cmpl $0x7, %r8d
je 0x18daa
cmpl $0x9, %r8d
je 0x18daa
movsd 0x1d719(%rip), %xmm0    # 0x36468
mulsd 0x1d691(%rip), %xmm0    # 0x363e8
movsd %xmm0, 0x30(%rsp)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x30(%rsp), %xmm0
movq %rbp, %rdi
callq 0x1687f
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
incl %r15d
movsd 0xa364(%rip), %xmm1     # 0x23100
ucomisd %xmm0, %xmm1
jae 0x18d67
jmp 0x18bc8
xorl %r13d, %r13d
xorl %ebp, %ebp
movl %ebp, %r15d
xorpd %xmm0, %xmm0
movq 0x28(%rsp), %rax
movupd %xmm0, (%rax)
addl %r13d, %r15d
jle 0x190e8
movslq %r10d, %rax
movq %rax, 0x38(%rsp)
movslq %r8d, %rax
movq %rax, 0x48(%rsp)
movsd 0x1d673(%rip), %xmm0    # 0x36450
xorpd %xmm5, %xmm5
ucomisd %xmm5, %xmm0
xorpd %xmm6, %xmm6
movl %r15d, 0x24(%rsp)
jbe 0x18e35
movsd 0x1d660(%rip), %xmm1    # 0x36458
movq 0xa8(%rsp), %r15
movq %r15, %rdi
callq 0x18987
movsd %xmm0, 0x8(%rsp)
movsd 0x1d63a(%rip), %xmm0    # 0x36450
movsd 0x1d63a(%rip), %xmm1    # 0x36458
movq %r15, %rdi
callq 0x18987
movsd 0x8(%rsp), %xmm5
movq 0x18(%rsp), %r10
movapd %xmm0, %xmm6
movq 0xa0(%rsp), %r11
movsd 0xa2bb(%rip), %xmm0     # 0x23100
subsd %xmm5, %xmm0
leaq 0x1d480(%rip), %rax     # 0x362d0
xorl %ecx, %ecx
leaq 0x1d7e7(%rip), %rsi     # 0x36640
movq %rcx, %rdx
shlq $0x5, %rdx
addq %rsi, %rdx
addq $0x18, %rdx
movq (%rbx,%rcx,8), %rdi
xorl %r8d, %r8d
movq %rcx, %r9
movapd %xmm0, %xmm1
cmpq %r8, %rcx
je 0x18e8b
movsd (%rax,%r8,8), %xmm1
divsd (%rdx), %xmm1
mulsd %xmm5, %xmm1
movq %r8, %r9
movsd %xmm1, (%rdi,%r9,8)
incq %r8
cmpq $0x4, %r8
jne 0x18e6e
incq %rcx
addq $0x20, %rax
cmpq $0x4, %rcx
jne 0x18e59
movsd 0xa251(%rip), %xmm7     # 0x23100
subsd %xmm6, %xmm7
leaq 0x1d416(%rip), %rax     # 0x362d0
xorl %ecx, %ecx
movq %rcx, %rdx
shlq $0x5, %rdx
addq %rsi, %rdx
addq $0x18, %rdx
movq (%r11,%rcx,8), %rdi
xorl %r8d, %r8d
movq %rcx, %r9
movapd %xmm7, %xmm1
cmpq %r8, %rcx
je 0x18eee
movsd (%rax,%r8,8), %xmm1
divsd (%rdx), %xmm1
mulsd %xmm6, %xmm1
movq %r8, %r9
movsd %xmm1, (%rdi,%r9,8)
incq %r8
cmpq $0x4, %r8
jne 0x18ed1
incq %rcx
addq $0x20, %rax
cmpq $0x4, %rcx
jne 0x18ebc
movl 0x1d550(%rip), %edi     # 0x36460
movl $0xfffffff7, %r8d       # imm = 0xFFFFFFF7
movl $0xfffffff7, %r15d      # imm = 0xFFFFFFF7
cmpl $0x1, %edi
jne 0x1909a
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm5
movl %r10d, %r8d
jbe 0x18fe1
movl %r10d, %r8d
cmpl $0x7, %r10d
je 0x18fe1
movl %r10d, %r8d
cmpl $0x9, %r10d
je 0x18fe1
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
cvtsi2sd %rax, %xmm2
movq %rax, (%r8)
divsd 0xa16c(%rip), %xmm2     # 0x23120
movq 0x38(%rsp), %rax
shlq $0x5, %rax
mulsd 0x18(%rax,%rsi), %xmm2
xorl %r8d, %r8d
leaq (%rax,%r8,8), %rcx
movsd (%rsi,%rcx), %xmm3
ucomisd %xmm2, %xmm3
jae 0x18fe1
incq %r8
cmpq $0x4, %r8
jne 0x18fc6
movl %r10d, %r8d
ucomisd %xmm1, %xmm6
jbe 0x19095
movq 0x10(%rsp), %r15
cmpl $0x7, %r15d
je 0x1909a
cmpl $0x9, %r15d
je 0x1909a
movq 0xa8(%rsp), %r9
movq (%r9), %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, (%r9)
divsd 0xa0b5(%rip), %xmm1     # 0x23120
movq 0x48(%rsp), %rax
shlq $0x5, %rax
mulsd 0x18(%rax,%rsi), %xmm1
xorl %r15d, %r15d
leaq (%rax,%r15,8), %rcx
movsd (%rsi,%rcx), %xmm2
ucomisd %xmm1, %xmm2
jae 0x1909a
incq %r15
cmpq $0x4, %r15
jne 0x1907d
movq 0x10(%rsp), %r15
movsd 0x1d396(%rip), %xmm1    # 0x36438
xorpd %xmm3, %xmm3
xorpd %xmm2, %xmm2
movsd %xmm2, 0x58(%rsp)
ucomisd %xmm3, %xmm6
ja 0x190fd
ucomisd 0xa07a(%rip), %xmm5     # 0x23138
ja 0x190fd
ucomisd %xmm2, %xmm1
ja 0x190fd
movq 0x28(%rsp), %r12
movq 0x38(%rsp), %rax
addl %r13d, (%r12,%rax,4)
movq 0x50(%rsp), %r13
movq 0x10(%rsp), %r8
movl 0x24(%rsp), %r15d
jmp 0x19419
xorpd %xmm5, %xmm5
xorpd %xmm6, %xmm6
movq 0x50(%rsp), %r13
movq %rax, %r12
jmp 0x19422
cmpl $0x7, %r10d
movsd %xmm5, 0x8(%rsp)
movsd %xmm6, 0x30(%rsp)
je 0x1928b
cmpl $0x9, %r10d
je 0x1928b
cmpl $0x1, %edi
jne 0x191bc
movsd 0x9fd2(%rip), %xmm3     # 0x23100
subsd %xmm1, %xmm3
movslq %r8d, %rax
movapd %xmm5, %xmm1
mulsd %xmm3, %xmm1
movl %eax, %ecx
xorl %edx, %edx
movapd %xmm0, %xmm2
movsd %xmm3, 0x58(%rsp)
mulsd %xmm3, %xmm2
movq 0x38(%rsp), %r8
cmpq %rdx, %r10
jne 0x19173
movq (%r12,%rax,8), %rsi
movsd (%rsi,%r10,8), %xmm3
mulsd %xmm5, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, (%r14,%r10,8)
jmp 0x191b1
movq (%r12,%r8,8), %rsi
cmpq %rdx, %rcx
jne 0x19191
movsd (%rsi,%rcx,8), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm1, %xmm3
movsd %xmm3, (%r14,%rcx,8)
jmp 0x191b1
movq (%r12,%rax,8), %rdi
movsd (%rdi,%rdx,8), %xmm3
mulsd %xmm5, %xmm3
movsd (%rsi,%rdx,8), %xmm4
mulsd %xmm0, %xmm4
addsd %xmm3, %xmm4
movsd %xmm4, (%r14,%rdx,8)
incq %rdx
cmpq $0x4, %rdx
jne 0x19154
jmp 0x19209
movq 0x38(%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 0x191d5
incq %rcx
cmpq $0x4, %rcx
jne 0x191c7
xorpd %xmm0, %xmm0
movsd %xmm0, 0x58(%rsp)
xorpd %xmm2, %xmm2
xorl %ebx, %ebx
movsd %xmm7, 0x60(%rsp)
cmpq %rbx, %r10
je 0x19274
movsd (%r14,%rbx,8), %xmm0
movsd 0x9ed8(%rip), %xmm1     # 0x23100
subsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movl %r13d, %edi
movq 0xa8(%rsp), %rsi
movsd %xmm2, 0x40(%rsp)
callq 0x1766c
movsd 0x40(%rsp), %xmm2
movsd 0x60(%rsp), %xmm7
movsd 0x30(%rsp), %xmm6
movsd 0x8(%rsp), %xmm5
movq 0x18(%rsp), %r10
movq 0x28(%rsp), %rcx
addl %eax, (%rcx,%rbx,4)
subl %eax, %r13d
addsd (%r14,%rbx,8), %xmm2
incq %rbx
cmpq $0x4, %rbx
jne 0x19215
movq 0x28(%rsp), %rax
movq 0x38(%rsp), %rcx
addl %r13d, (%rax,%rcx,4)
movq 0x10(%rsp), %r8
cmpl $0x7, %r8d
je 0x19346
cmpl $0x9, %r8d
movq 0x50(%rsp), %r13
je 0x1934b
cmpl $0x1, 0x1d1b0(%rip)     # 0x36460
jne 0x1935a
movslq %r15d, %rax
movapd %xmm6, %xmm0
movsd 0x58(%rsp), %xmm3
mulsd %xmm3, %xmm0
movl %eax, %ecx
xorl %edx, %edx
mulsd %xmm7, %xmm3
movq 0x28(%rsp), %r11
movl 0x24(%rsp), %r15d
movq 0x48(%rsp), %r9
cmpq %rdx, %r8
jne 0x192fd
movq (%r12,%rax,8), %rsi
movsd (%rsi,%r8,8), %xmm1
mulsd %xmm6, %xmm1
addsd %xmm3, %xmm1
movsd %xmm1, (%r14,%r8,8)
jmp 0x1933b
movq (%r12,%r9,8), %rsi
cmpq %rdx, %rcx
jne 0x1931b
movsd (%rsi,%rcx,8), %xmm1
mulsd %xmm7, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%r14,%rcx,8)
jmp 0x1933b
movq (%r12,%rax,8), %rdi
movsd (%rdi,%rdx,8), %xmm1
mulsd %xmm6, %xmm1
movsd (%rsi,%rdx,8), %xmm2
mulsd %xmm7, %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, (%r14,%rdx,8)
incq %rdx
cmpq $0x4, %rdx
jne 0x192de
jmp 0x193af
movq 0x50(%rsp), %r13
movq 0x28(%rsp), %r12
movl 0x24(%rsp), %r15d
jmp 0x19422
movq 0x48(%rsp), %rax
movq 0xa0(%rsp), %rcx
movq (%rcx,%rax,8), %rax
xorl %ecx, %ecx
movq 0x28(%rsp), %r11
movl 0x24(%rsp), %r15d
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 0x19385
incq %rcx
cmpq $0x4, %rcx
jne 0x19377
xorpd %xmm2, %xmm2
xorl %ebx, %ebx
movq %r11, %r12
cmpq %rbx, %r8
je 0x19410
movsd (%r14,%rbx,8), %xmm0
movsd 0x9d35(%rip), %xmm1     # 0x23100
subsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movl %ebp, %edi
movq 0xa8(%rsp), %rsi
movsd %xmm2, 0x28(%rsp)
callq 0x1766c
movsd 0x28(%rsp), %xmm2
movsd 0x30(%rsp), %xmm6
movsd 0x8(%rsp), %xmm5
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %r10
addl %eax, (%r12,%rbx,4)
subl %eax, %ebp
addsd (%r14,%rbx,8), %xmm2
incq %rbx
cmpq $0x4, %rbx
jne 0x193b8
movq 0x48(%rsp), %rax
addl %ebp, (%r12,%rax,4)
movd %r8d, %xmm0
movd %r10d, %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
paddd 0x9c98(%rip), %xmm1     # 0x230d0
movl %r15d, (%r13)
movq %r12, 0x8(%r13)
pand 0x9c98(%rip), %xmm1     # 0x230e0
movl %r10d, 0x18(%r13)
pcmpeqd 0x9c5c(%rip), %xmm1     # 0x230b0
pandn 0x9c94(%rip), %xmm1     # 0x230f0
movl %r8d, 0x1c(%r13)
movq %xmm1, 0x20(%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