// File: /workspace/github_cpp_makefile_star2_O2/tonymugen[P]sampleSNPs/varfiles.cpp
// Function: sampFiles::BedFileI::_ld(char const*, char const*, sampFiles::PopIndex const&, std::vector<double, std::allocator<double>>&, std::vector<double, std::allocator<double>>&, std::vector<double, std::allocator<double>>&, std::vector<double, std::allocator<double>>&)
void BedFileI::_ld(const char *snp1, const char *snp2, const PopIndex &popID, vector<double> &rSq, vector<double> &Dprime, vector<double> &dcnt1, vector<double> &dcnt2){

	// The data in .bed files are strictly biallelic by definition of the format, so that makes things easier.
	// Using derived alleles because they are mostly at low frequency so the expected number of calculations is low

	// constants
	const char homDerv = static_cast<char>(0x00); // homozygous derived for all bit-pair positions

	// modifiable parameters
	double D;
	double p1;     // frequency of the derived allele at snp1
	double q1;     // frequency of the derived allele at snp2
	double f11;    // frequency of the (hom. maj. allele @1, hom. maj.allel @2) haplotype; to be estimated; D = f11 - p1*q1
	double n11;    // # of 1,1 homozygote haplotypes
	double n12;    // # of hom. 1, heterozygous 2 haplotypes
	double n21;    // # of het. 1, hom. 2 haplotypes
	double n22;    // # of het. 1, het. 2 haplotypes
	double Npres;  // # of present genotypes (present at both loci)
	double p1q1;   // p1*q1
	double p2q2;   // p2*q2
	// f11 min and max
	double f11Min;
	double f11Max;
	// re-used intermediate variables
	double opq;       // 1-2p-2q
	double smn;       // 2n11+n12+n21
	double ppq;       // p1+q1
	// qubic equation coefficients
	double a;
	double b;
	double c;
	double d;
	// decision variables
	double bda;    // b/a
	double xN;
	double deltaSq;
	double hSq;
	double gammaN;
	double Delta3;

	char curBitPair1;
	char curBitPair2;

	for (size_t iPop = 0; iPop < popID.popNumber(); iPop++) {
		// reset everything
		p1    = 0.0;
		q1    = 0.0;
		f11   = 0.0;
		n11   = 0.0;
		n12   = 0.0;
		n21   = 0.0;
		n22   = 0.0;
		Npres = 0.0;

		for (auto popIt = popID[iPop].begin(); popIt != popID[iPop].end(); ++popIt) {
			size_t byteInd    = (*popIt)/4;
			size_t bitPairInd = (*popIt) % 4; // will automatically index from the end of the byte
			curBitPair1 = snp1[byteInd] & _masks[bitPairInd];
			curBitPair2 = snp2[byteInd] & _masks[bitPairInd];

			// Test miss
			if ( (curBitPair1 == _tests.at('M')[bitPairInd]) || (curBitPair2 == _tests.at('M')[bitPairInd]) ) { // must use .at() because _tests is const
				continue;
			}
			Npres += 1.0;
			// Go through all the pairwise possibilities; adding up gametes (one per diploid)
			if (curBitPair1 == homDerv) {
				p1 += 1.0;
				if (curBitPair2 == homDerv) {
					q1  += 1.0;
					n11 += 1.0;
				} else if (curBitPair2 == _tests.at('H')[bitPairInd]){
					q1  += 0.5;
					n12 += 1.0;
				}
			} else if (curBitPair1 == _tests.at('H')[bitPairInd]){
				p1 += 0.5;
				if (curBitPair2 == homDerv) {
					q1  += 1.0;
					n21 += 1.0;
				} else if (curBitPair2 == _tests.at('H')[bitPairInd]){
					q1  += 0.5;
					n22 += 1.0;
				}
			} else {
				if (curBitPair2 == homDerv) {
					q1 += 1.0;
				} else if (curBitPair2 == _tests.at('H')[bitPairInd]){
					q1 += 0.5;
				}
			}
		}
		dcnt1[iPop]  = (p1 <= Npres - p1 ? 2.0*p1 : 2.0*(Npres - p1));
		dcnt2[iPop]  = (q1 <= Npres - q1 ? 2.0*q1 : 2.0*(Npres - q1));

		if (Npres <= 1.0) {
			rSq[iPop]    = -9.0;
			Dprime[iPop] = -9.0;
			continue;
		}
		if ( (dcnt1[iPop] == 0.0) || (dcnt2[iPop] == 0.0) ) { // even if the SNPs are pre-screened for polymorphism, the alternatives may correspond to missing at the other locus
			rSq[iPop]    = -9.0;
			Dprime[iPop] = -9.0;
			continue;
		}
		if (n22 == Npres) { // if everyone is het, cannot determine LD because we don't know the phase
			rSq[iPop]    = -9.0;
			Dprime[iPop] = -9.0;
			continue;
		}
		// Finish calculating statistics if everything is sane
		p1   = p1/Npres;
		q1   = q1/Npres;
		// intermediate values
		p1q1 = p1*q1;

		if (n22 == 0.0) { // no het/het match-ups; means I can directly enumerate haplotypes
			f11        = (n11 + 0.5*(n12 + n21))/Npres;
			D          = f11 - p1q1;
			p2q2       = (1.0-p1)*(1.0-q1);
			rSq[iPop]  = (D*D)/(p1q1*p2q2);

			if (D < -10.0*EPS) {
				double Dmax  = ( p1q1 <= p2q2 ? -p1q1 : -p2q2 ); // (9) of Gaunt et al.
				Dprime[iPop] = D/Dmax;
			} else if (D > 10.0*EPS) {
				p1q1 = p1*(1.0 - q1);
				p2q2 = (1.0 - p1)*q1;

				double Dmax  = ( p1q1 <= p2q2 ? p1q1 : p2q2 ); // (9) of Gaunt et al.
				Dprime[iPop] = D/Dmax;
			} else {
				Dprime[iPop] = 0.0;
			}

		} else {
			// There is n22, so need to estimate f11 via ML (using Gaunt et al. cubic equation); they say f11 is between major alleles, but that is not necessary. Results will be the same for minor or any other combination
			// Calculate the bracketing values for f11:
			f11Min = n11 + 0.5*(n12 + n21); // i.e., all the het/het haplotypes are crossovers
			f11Max = f11Min + 0.5*n22;      // i.e., all het/het haplotypes are in phase
			f11Min = f11Min/Npres - 100.0*EPS; // some padding to take into account round-off errors
			f11Max = f11Max/Npres + 100.0*EPS;
			// re-used auxiliary variables
			ppq = p1 + q1;
			opq = 1.0 - 2.0*ppq;
			smn = 2.0*n11 + n12 + n21;
			// coefficients
			a   = 2.0*Npres; // will need to multiply again later to make 4N; doing this to re-use the 2N
			b   = a*opq - 2.0*smn - n22;
			c   = a*p1q1 - smn*opq - n22*(1.0 - ppq);
			d   = -smn*p1q1;
			a  *= 2.0;
			// decision variables
			bda     = b/a;
			xN      = -bda/3.0;
			deltaSq = bda*bda/9.0 - c/(3.0*a);
			hSq     = 4.0*a*a*deltaSq*deltaSq*deltaSq;
			gammaN  = xN*( xN*( a*xN + b ) + c ) + d;
			Delta3  = gammaN*gammaN - hSq;

			// now decide how many roots we have
			if (Delta3 > 100.0*EPS) { // everything is cool, only one distinct root
				f11 = xN + cbrt((sqrt(Delta3) - gammaN)/(2.0*a)) + cbrt(-(sqrt(Delta3) + gammaN)/(2.0*a));
			} else if (Delta3 < -100.0*EPS){ // Three roots; worst case scenario
				double theta  = acos(-gammaN/sqrt(hSq))/3.0;
				double ddelta = 2.0*sqrt(deltaSq);
				double alpha  = xN + ddelta*cos(theta);
				double beta   = xN + ddelta*cos(2.0*PI/3.0 + theta);
				double gamma  = xN + ddelta*cos(4.0*PI/3.0 + theta);

				if ( (alpha < f11Min) || (alpha > f11Max) ) {
					if ( (beta < f11Min) || (beta > f11Max) ) {
						if ( (gamma < f11Min) || (gamma > f11Max) ) {
							rSq[iPop]    = -9.0;
							Dprime[iPop] = -9.0;
							continue;
						} else {
							f11 = gamma;
						}
					} else if ( (gamma < f11Min) || (gamma > f11Max) ) {
						f11 = beta;
					} else {
						// two plausible roots; choose the one with smallest |D|
						f11 = (fabs(beta - p1q1) <= fabs(gamma - p1q1) ? beta : gamma);
					}
				} else {
					if ( (beta < f11Min) || (beta > f11Max) ) {
						if ( (gamma < f11Min) || (gamma > f11Max) ) {
							f11 = alpha;
						} else {
							// two plausible roots; choose the one with smallest |D|
							f11 = (fabs(alpha - p1q1) <= fabs(gamma - p1q1) ? alpha : gamma);
						}
					} else if ( (gamma < f11Min) || (gamma > f11Max) ) {
						// two plausible roots; choose the one with smallest |D|
						f11 = (fabs(beta - p1q1) <= fabs(alpha - p1q1) ? beta : alpha);
					} else {
						// three plausible roots; choose the one with smallest |D|
						double minAB = (fabs(beta - p1q1) <= fabs(alpha - p1q1) ? beta : alpha);
						f11 = (fabs(minAB - p1q1) <= fabs(gamma - p1q1) ? minAB : gamma);
					}

				}
			} else { // Delta3 == 0; two different roots
				double mu    = cbrt(gammaN/(2.0*a));
				double alpha = xN + mu;
				double gamma = xN - 2.0*mu;
				if ( (alpha < f11Min) || (alpha > f11Max) ) { // f11 cannot be greater than min(p1, q1)
					if ( (gamma < f11Min) || (gamma > f11Max) ) {
						rSq[iPop]    = -9.0;
						Dprime[iPop] = -9.0;
						continue;
					} else {
						f11 = gamma;
					}
				} else {
					if ( (gamma < f11Min) || (gamma > f11Max) ) { // impossible gamma; going with alpha
						f11 = alpha;
					} else { // both doable; conservatively choose the one minimzing |D|
						f11 = (fabs(alpha - p1q1) <= fabs(gamma - p1q1) ? alpha : gamma);
					}
				}

			}

			D         = f11 - p1q1;
			p2q2      = (1.0-p1)*(1.0-q1);
			rSq[iPop] = (D*D)/(p1q1*p2q2);

			if (D < -10.0*EPS) {
				double Dmax  = ( p1q1 <= p2q2 ? -p1q1 : -p2q2 ); // (9) of Gaunt et al.
				Dprime[iPop] = D/Dmax;
			} else if (D > 10.0*EPS) {
				p1q1 = p1*(1.0 - q1);
				p2q2 = (1.0 - p1)*q1;

				double Dmax  = ( p1q1 <= p2q2 ? p1q1 : p2q2 ); // (9) of Gaunt et al.
				Dprime[iPop] = D/Dmax;
			} else {
				Dprime[iPop] = 0.0;
			}

		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %r9, 0xd0(%rsp)
movq %r8, 0x38(%rsp)
movq %rcx, 0xc8(%rsp)
movq %rdx, 0xe8(%rsp)
movq %rsi, 0xe0(%rsp)
xorl %ebx, %ebx
movsd 0xb972(%rip), %xmm5     # 0x144e0
movq 0xc8(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
subq %rcx, %rax
cqto
pushq $0x18
popq %rsi
idivq %rsi
cmpq %rax, %rbx
jae 0x972b
movq %rbx, 0xd8(%rsp)
imulq $0x18, %rbx, %rax
movq %rax, 0x90(%rsp)
movq (%rcx,%rax), %rbx
xorpd %xmm0, %xmm0
movsd %xmm0, 0x60(%rsp)
movsd %xmm0, 0xb0(%rsp)
movsd %xmm0, 0x50(%rsp)
movsd %xmm0, 0x80(%rsp)
movsd %xmm0, 0x40(%rsp)
movapd %xmm0, 0x10(%rsp)
xorpd %xmm4, %xmm4
movq 0x90(%rsp), %rax
cmpq 0x8(%rcx,%rax), %rbx
je 0x8e5b
movapd %xmm4, 0x20(%rsp)
movq (%rbx), %rbp
movq %rbp, %rax
shrq $0x2, %rax
andl $0x3, %ebp
movq 0x136e0(%rip), %rcx     # 0x1c2e8
movb (%rcx,%rbp), %r14b
movq 0xe0(%rsp), %rcx
movb (%rcx,%rax), %r13b
andb %r14b, %r13b
movq 0xe8(%rsp), %rcx
movb (%rcx,%rax), %r12b
movb $0x4d, 0xf(%rsp)
leaq 0x136cd(%rip), %r15     # 0x1c300
movq %r15, %rdi
leaq 0xf(%rsp), %rsi
callq 0x12480
movq (%rax), %rax
cmpb (%rax,%rbp), %r13b
je 0x8c67
andb %r14b, %r12b
movb $0x4d, 0xe(%rsp)
movq %r15, %rdi
leaq 0xe(%rsp), %rsi
callq 0x12480
movq (%rax), %rax
cmpb (%rax,%rbp), %r12b
jne 0x8c89
movsd 0xb871(%rip), %xmm5     # 0x144e0
movapd 0x20(%rsp), %xmm4
addq $0x8, %rbx
movq 0xc8(%rsp), %rax
movq (%rax), %rcx
jmp 0x8bdb
movsd 0xb84f(%rip), %xmm5     # 0x144e0
movsd 0x60(%rsp), %xmm0
addsd %xmm5, %xmm0
movsd %xmm0, 0x60(%rsp)
testb %r13b, %r13b
je 0x8d3c
movb $0x48, 0xc(%rsp)
movq %r15, %rdi
leaq 0xc(%rsp), %rsi
callq 0x12480
movq (%rax), %rax
cmpb (%rax,%rbp), %r13b
jne 0x8dab
movapd 0x20(%rsp), %xmm4
addsd 0xb819(%rip), %xmm4     # 0x144f0
testb %r12b, %r12b
je 0x8e11
movapd %xmm4, 0x20(%rsp)
movb $0x48, 0xb(%rsp)
movq %r15, %rdi
leaq 0xb(%rsp), %rsi
callq 0x12480
movq (%rax), %rax
cmpb (%rax,%rbp), %r12b
jne 0x8c67
movapd 0x10(%rsp), %xmm0
addsd 0xb7dd(%rip), %xmm0     # 0x144f0
movapd %xmm0, 0x10(%rsp)
movsd 0xb7bf(%rip), %xmm5     # 0x144e0
movsd 0xb0(%rsp), %xmm0
addsd %xmm5, %xmm0
movsd %xmm0, 0xb0(%rsp)
jmp 0x8c6f
movapd 0x20(%rsp), %xmm4
addsd %xmm5, %xmm4
testb %r12b, %r12b
je 0x8dec
movapd %xmm4, 0x20(%rsp)
movb $0x48, 0xd(%rsp)
movq %r15, %rdi
leaq 0xd(%rsp), %rsi
callq 0x12480
movq (%rax), %rax
cmpb (%rax,%rbp), %r12b
jne 0x8c67
movapd 0x10(%rsp), %xmm0
addsd 0xb76e(%rip), %xmm0     # 0x144f0
movapd %xmm0, 0x10(%rsp)
movsd 0xb750(%rip), %xmm5     # 0x144e0
movsd 0x80(%rsp), %xmm0
addsd %xmm5, %xmm0
movsd %xmm0, 0x80(%rsp)
jmp 0x8c6f
testb %r12b, %r12b
je 0x8e3e
movb $0x48, 0xa(%rsp)
movq %r15, %rdi
leaq 0xa(%rsp), %rsi
callq 0x12480
movq (%rax), %rax
cmpb (%rax,%rbp), %r12b
jne 0x8c67
movapd 0x10(%rsp), %xmm0
addsd 0xb70f(%rip), %xmm0     # 0x144f0
movapd %xmm0, 0x10(%rsp)
jmp 0x8c67
movapd 0x10(%rsp), %xmm0
addsd %xmm5, %xmm0
movapd %xmm0, 0x10(%rsp)
movsd 0x40(%rsp), %xmm0
addsd %xmm5, %xmm0
movsd %xmm0, 0x40(%rsp)
jmp 0x8c75
movsd 0xb6c7(%rip), %xmm5     # 0x144e0
movapd 0x10(%rsp), %xmm0
addsd %xmm5, %xmm0
movapd %xmm0, 0x10(%rsp)
movsd 0x50(%rsp), %xmm0
addsd %xmm5, %xmm0
movsd %xmm0, 0x50(%rsp)
jmp 0x8c75
movsd 0xb69a(%rip), %xmm5     # 0x144e0
movapd 0x10(%rsp), %xmm0
addsd %xmm5, %xmm0
movapd %xmm0, 0x10(%rsp)
jmp 0x8c6f
movsd 0x60(%rsp), %xmm6
movapd %xmm6, %xmm0
subsd %xmm4, %xmm0
movapd %xmm4, %xmm1
cmplesd %xmm0, %xmm1
movapd %xmm1, %xmm2
andnpd %xmm0, %xmm2
andpd %xmm4, %xmm1
orpd %xmm2, %xmm1
addsd %xmm1, %xmm1
movq 0x140(%rsp), %rax
movq (%rax), %rax
movq 0xd8(%rsp), %rbx
movsd %xmm1, (%rax,%rbx,8)
movapd %xmm6, %xmm1
movapd 0x10(%rsp), %xmm3
subsd %xmm3, %xmm1
movapd %xmm3, %xmm0
cmplesd %xmm1, %xmm0
movapd %xmm0, %xmm2
andnpd %xmm1, %xmm2
andpd %xmm3, %xmm0
orpd %xmm2, %xmm0
addsd %xmm0, %xmm0
movq 0x148(%rsp), %rcx
movq (%rcx), %rcx
movsd %xmm0, (%rcx,%rbx,8)
ucomisd %xmm6, %xmm5
jae 0x8f12
movsd (%rax,%rbx,8), %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0x8ef0
jnp 0x8f12
ucomisd %xmm2, %xmm0
jne 0x8ef8
jnp 0x8f12
movsd 0x60(%rsp), %xmm9
movsd 0xb0(%rsp), %xmm11
ucomisd %xmm9, %xmm11
jne 0x8f48
jp 0x8f48
movq 0x38(%rsp), %rax
movq (%rax), %rax
movabsq $-0x3fde000000000000, %rcx # imm = 0xC022000000000000
movq %rcx, (%rax,%rbx,8)
movsd 0xb5b8(%rip), %xmm1     # 0x144e8
movq 0xd0(%rsp), %rax
movq (%rax), %rax
movsd %xmm1, (%rax,%rbx,8)
incq %rbx
jmp 0x8b6e
divsd %xmm9, %xmm4
movapd 0x10(%rsp), %xmm2
divsd %xmm9, %xmm2
movapd %xmm2, %xmm7
mulsd %xmm4, %xmm7
ucomisd 0xb5df(%rip), %xmm11    # 0x14548
movsd 0x50(%rsp), %xmm10
movapd %xmm10, %xmm1
movsd 0x80(%rsp), %xmm12
addsd %xmm12, %xmm1
movsd 0xb564(%rip), %xmm6     # 0x144f0
mulsd %xmm6, %xmm1
movsd 0x40(%rsp), %xmm13
addsd %xmm13, %xmm1
movapd %xmm1, %xmm14
divsd %xmm9, %xmm14
movapd %xmm5, %xmm8
subsd %xmm4, %xmm8
jne 0x9026
jp 0x9026
subsd %xmm7, %xmm14
movapd %xmm5, %xmm0
movapd %xmm2, %xmm6
subsd %xmm2, %xmm0
movapd %xmm0, %xmm1
mulsd %xmm8, %xmm1
movapd %xmm14, %xmm2
mulsd %xmm14, %xmm2
movapd %xmm7, %xmm3
mulsd %xmm1, %xmm3
divsd %xmm3, %xmm2
movq 0x38(%rsp), %rax
movq (%rax), %rax
movsd %xmm2, (%rax,%rbx,8)
movsd 0xb53f(%rip), %xmm2     # 0x14538
ucomisd %xmm14, %xmm2
jbe 0x925d
movapd %xmm7, %xmm0
cmplesd %xmm1, %xmm0
andpd %xmm0, %xmm7
andnpd %xmm1, %xmm0
orpd %xmm7, %xmm0
xorpd 0xb4af(%rip), %xmm0     # 0x144d0
jmp 0x928e
movapd %xmm2, 0x10(%rsp)
movapd %xmm2, %xmm0
movapd %xmm4, 0x20(%rsp)
addsd %xmm4, %xmm0
movapd %xmm5, %xmm3
subsd %xmm0, %xmm3
addsd %xmm0, %xmm0
movapd %xmm5, %xmm4
subsd %xmm0, %xmm4
addsd %xmm13, %xmm13
addsd %xmm12, %xmm13
addsd %xmm13, %xmm10
movapd %xmm9, %xmm12
addsd %xmm9, %xmm12
movapd %xmm12, %xmm0
mulsd %xmm4, %xmm0
movapd %xmm10, %xmm2
addsd %xmm10, %xmm2
subsd %xmm2, %xmm0
subsd %xmm11, %xmm0
mulsd %xmm10, %xmm4
movapd %xmm12, %xmm2
mulsd %xmm7, %xmm2
subsd %xmm4, %xmm2
mulsd %xmm11, %xmm3
subsd %xmm3, %xmm2
addsd %xmm12, %xmm12
movapd %xmm0, %xmm3
divsd %xmm12, %xmm3
movapd %xmm3, %xmm5
movsd 0xb450(%rip), %xmm4     # 0x14508
divsd %xmm4, %xmm5
movapd %xmm12, %xmm13
mulsd %xmm5, %xmm13
addsd %xmm0, %xmm13
movapd %xmm12, %xmm0
mulsd %xmm4, %xmm0
mulsd %xmm5, %xmm13
addsd %xmm2, %xmm13
movapd %xmm2, %xmm4
divsd %xmm0, %xmm4
mulsd %xmm6, %xmm11
movsd 0xb405(%rip), %xmm2     # 0x144f8
addsd %xmm2, %xmm14
mulsd %xmm7, %xmm10
mulsd %xmm3, %xmm3
divsd 0xb407(%rip), %xmm3     # 0x14510
addsd %xmm3, %xmm4
movapd %xmm12, %xmm0
mulsd 0xb3fe(%rip), %xmm0     # 0x14518
mulsd %xmm12, %xmm0
mulsd %xmm4, %xmm0
mulsd %xmm4, %xmm0
mulsd %xmm4, %xmm0
movapd %xmm5, 0x90(%rsp)
mulsd %xmm5, %xmm13
subsd %xmm10, %xmm13
movapd %xmm13, %xmm5
mulsd %xmm13, %xmm5
subsd %xmm0, %xmm5
movsd 0xb3ac(%rip), %xmm3     # 0x14500
ucomisd %xmm3, %xmm5
movapd %xmm7, 0xa0(%rsp)
movsd %xmm8, 0x78(%rsp)
jbe 0x929d
sqrtsd %xmm5, %xmm0
movapd %xmm5, 0x50(%rsp)
ucomisd 0xb3c8(%rip), %xmm5     # 0x14548
movsd %xmm0, 0x80(%rsp)
movapd %xmm13, 0x40(%rsp)
jae 0x91b2
movapd 0x50(%rsp), %xmm0
movsd %xmm12, 0x60(%rsp)
callq 0x4230
movapd 0x40(%rsp), %xmm13
movsd 0x60(%rsp), %xmm12
subsd %xmm13, %xmm0
addsd %xmm12, %xmm12
movsd %xmm12, 0x60(%rsp)
divsd %xmm12, %xmm0
callq 0x4070
movapd %xmm0, %xmm2
movapd 0x50(%rsp), %xmm0
ucomisd 0xb369(%rip), %xmm0     # 0x14548
movsd 0x80(%rsp), %xmm1
jae 0x91ff
movsd %xmm2, 0x50(%rsp)
callq 0x4230
movsd 0x50(%rsp), %xmm2
movapd %xmm0, %xmm1
movapd 0x90(%rsp), %xmm0
addsd %xmm2, %xmm0
movapd %xmm0, 0x90(%rsp)
movapd 0x40(%rsp), %xmm0
addsd %xmm1, %xmm0
xorpd 0xb2a9(%rip), %xmm0     # 0x144d0
divsd 0x60(%rsp), %xmm0
callq 0x4070
addsd 0x90(%rsp), %xmm0
movsd 0xb29d(%rip), %xmm5     # 0x144e0
movapd 0x10(%rsp), %xmm4
movapd 0xa0(%rsp), %xmm6
movsd 0x78(%rsp), %xmm7
jmp 0x967d
xorpd %xmm1, %xmm1
ucomisd 0xb2d6(%rip), %xmm14    # 0x14540
jbe 0x8f30
mulsd %xmm0, %xmm4
mulsd %xmm8, %xmm6
movapd %xmm4, %xmm0
cmplesd %xmm6, %xmm0
andpd %xmm0, %xmm4
andnpd %xmm6, %xmm0
orpd %xmm4, %xmm0
divsd %xmm0, %xmm14
movapd %xmm14, %xmm1
jmp 0x8f30
addsd %xmm1, %xmm11
divsd %xmm9, %xmm11
addsd %xmm3, %xmm11
ucomisd %xmm5, %xmm2
movapd %xmm14, 0x50(%rsp)
movapd %xmm11, 0x60(%rsp)
jbe 0x92e0
movsd %xmm4, 0x80(%rsp)
ucomisd 0xb277(%rip), %xmm0     # 0x14548
jb 0x93cb
sqrtsd %xmm0, %xmm0
jmp 0x93de
addsd %xmm12, %xmm12
divsd %xmm12, %xmm13
movapd %xmm13, %xmm0
callq 0x4070
movapd 0x60(%rsp), %xmm4
movapd 0x90(%rsp), %xmm2
movapd %xmm2, %xmm1
addsd %xmm0, %xmm1
addsd %xmm0, %xmm0
subsd %xmm0, %xmm2
movapd %xmm2, %xmm0
movapd 0x50(%rsp), %xmm5
ucomisd %xmm1, %xmm5
movapd %xmm4, %xmm2
cmpltpd %xmm0, %xmm2
movapd %xmm0, %xmm3
cmpltpd %xmm5, %xmm3
orpd %xmm2, %xmm3
movd %xmm3, %eax
ja 0x93a1
ucomisd %xmm4, %xmm1
ja 0x93a1
testb $0x1, %al
movsd 0xb193(%rip), %xmm5     # 0x144e0
movapd 0xb16b(%rip), %xmm4     # 0x144c0
movapd 0xa0(%rsp), %xmm6
movsd 0x78(%rsp), %xmm7
jne 0x95d5
movapd %xmm1, %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
movapd %xmm6, %xmm3
unpcklpd %xmm6, %xmm3            # xmm3 = xmm3[0],xmm6[0]
subpd %xmm3, %xmm2
andpd %xmm4, %xmm2
pshufd $0xee, %xmm2, %xmm3     # xmm3 = xmm2[2,3,2,3]
cmplesd %xmm3, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
movapd %xmm2, %xmm0
jmp 0x9677
testb $0x1, %al
movsd 0xb135(%rip), %xmm5     # 0x144e0
movapd 0x10(%rsp), %xmm4
movapd 0xa0(%rsp), %xmm6
movsd 0x78(%rsp), %xmm7
jne 0x8f12
jmp 0x967d
movapd %xmm13, 0x40(%rsp)
callq 0x4230
movapd 0x40(%rsp), %xmm13
xorpd 0xb0e9(%rip), %xmm13    # 0x144d0
divsd %xmm0, %xmm13
movapd %xmm13, %xmm0
callq 0x4290
divsd 0xb122(%rip), %xmm0     # 0x14520
movsd %xmm0, 0x40(%rsp)
xorpd %xmm1, %xmm1
movsd 0x80(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x941d
sqrtsd %xmm0, %xmm0
jmp 0x9422
callq 0x4230
addsd %xmm0, %xmm0
movapd %xmm0, 0x80(%rsp)
movsd 0x40(%rsp), %xmm0
callq 0x4500
mulsd 0x80(%rsp), %xmm0
addsd 0x90(%rsp), %xmm0
movapd %xmm0, 0xb0(%rsp)
movsd 0x40(%rsp), %xmm0
addsd 0xb0c5(%rip), %xmm0     # 0x14528
callq 0x4500
movapd %xmm0, 0xf0(%rsp)
movsd 0x40(%rsp), %xmm0
addsd 0xb0b1(%rip), %xmm0     # 0x14530
callq 0x4500
movapd 0xb0(%rsp), %xmm9
movapd 0x90(%rsp), %xmm8
movapd 0x80(%rsp), %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
movapd 0xf0(%rsp), %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
mulpd %xmm1, %xmm2
unpcklpd %xmm8, %xmm8            # xmm8 = xmm8[0,0]
addpd %xmm2, %xmm8
movapd 0x50(%rsp), %xmm3
ucomisd %xmm9, %xmm3
movapd 0x60(%rsp), %xmm4
movapd %xmm4, %xmm0
cmpltpd %xmm8, %xmm0
movapd %xmm8, %xmm1
cmpltpd %xmm3, %xmm1
orpd %xmm0, %xmm1
movd %xmm1, %ecx
movapd %xmm8, %xmm0
unpckhpd %xmm8, %xmm0            # xmm0 = xmm0[1],xmm8[1]
movapd %xmm4, %xmm1
cmpltpd %xmm0, %xmm1
movapd %xmm0, %xmm2
cmpltpd %xmm3, %xmm2
orpd %xmm1, %xmm2
movd %xmm2, %eax
ja 0x9550
ucomisd %xmm4, %xmm9
ja 0x9550
testb $0x1, %cl
movsd 0xafbb(%rip), %xmm5     # 0x144e0
movapd 0xaf93(%rip), %xmm4     # 0x144c0
movapd 0xa0(%rsp), %xmm6
movsd 0x78(%rsp), %xmm7
je 0x959b
testb $0x1, %al
je 0x9614
movapd %xmm9, %xmm0
jmp 0x9677
testb $0x1, %cl
movsd 0xaf85(%rip), %xmm5     # 0x144e0
movapd 0xaf5d(%rip), %xmm3     # 0x144c0
movapd 0xa0(%rsp), %xmm6
movsd 0x78(%rsp), %xmm7
je 0x9587
testb $0x1, %al
movapd 0x10(%rsp), %xmm4
jne 0x8f12
jmp 0x967d
testb $0x1, %al
movapd 0x10(%rsp), %xmm4
je 0x95de
movapd %xmm8, %xmm0
jmp 0x967d
movapd %xmm8, %xmm1
unpcklpd %xmm9, %xmm1            # xmm1 = xmm1[0],xmm9[0]
movapd %xmm6, %xmm2
unpcklpd %xmm6, %xmm2            # xmm2 = xmm2[0],xmm6[0]
subpd %xmm2, %xmm1
andpd %xmm4, %xmm1
pshufd $0xee, %xmm1, %xmm3     # xmm3 = xmm1[2,3,2,3]
cmplesd %xmm3, %xmm1
movapd %xmm1, %xmm3
andpd %xmm8, %xmm3
andnpd %xmm9, %xmm1
orpd %xmm3, %xmm1
testb $0x1, %al
je 0x9648
movapd %xmm1, %xmm0
jmp 0x9677
movapd %xmm6, %xmm1
unpcklpd %xmm6, %xmm1            # xmm1 = xmm1[0],xmm6[0]
movapd %xmm8, %xmm2
subpd %xmm1, %xmm2
andpd %xmm3, %xmm2
pshufd $0xee, %xmm2, %xmm1     # xmm1 = xmm2[2,3,2,3]
cmplesd %xmm1, %xmm2
movapd %xmm2, %xmm1
andpd %xmm8, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
movapd %xmm2, %xmm0
jmp 0x967d
movsd %xmm9, %xmm8            # xmm8 = xmm9[0],xmm8[1]
movapd %xmm6, %xmm1
unpcklpd %xmm6, %xmm1            # xmm1 = xmm1[0],xmm6[0]
subpd %xmm1, %xmm8
andpd %xmm4, %xmm8
pshufd $0xee, %xmm8, %xmm1     # xmm1 = xmm8[2,3,2,3]
cmplesd %xmm1, %xmm8
andpd %xmm8, %xmm9
andnpd %xmm0, %xmm8
orpd %xmm9, %xmm8
jmp 0x9672
movsd %xmm1, %xmm8            # xmm8 = xmm1[0],xmm8[1]
subpd %xmm2, %xmm8
andpd %xmm4, %xmm8
pshufd $0xee, %xmm8, %xmm2     # xmm2 = xmm8[2,3,2,3]
cmplesd %xmm2, %xmm8
andpd %xmm8, %xmm1
andnpd %xmm0, %xmm8
orpd %xmm1, %xmm8
movapd %xmm8, %xmm0
movapd 0x10(%rsp), %xmm4
subsd %xmm6, %xmm0
movapd %xmm5, %xmm2
subsd %xmm4, %xmm2
movapd %xmm2, %xmm1
mulsd %xmm7, %xmm1
movapd %xmm0, %xmm3
mulsd %xmm0, %xmm3
movapd %xmm6, %xmm4
mulsd %xmm1, %xmm4
divsd %xmm4, %xmm3
movq 0x38(%rsp), %rax
movq (%rax), %rax
movsd %xmm3, (%rax,%rbx,8)
movsd 0xae7e(%rip), %xmm3     # 0x14538
ucomisd %xmm0, %xmm3
jbe 0x96e3
movapd %xmm6, %xmm2
cmplesd %xmm1, %xmm2
andpd %xmm2, %xmm6
andnpd %xmm1, %xmm2
orpd %xmm6, %xmm2
xorpd 0xadf3(%rip), %xmm2     # 0x144d0
divsd %xmm2, %xmm0
jmp 0x9722
xorpd %xmm1, %xmm1
ucomisd 0xae51(%rip), %xmm0     # 0x14540
movapd 0x20(%rsp), %xmm3
jbe 0x8f30
mulsd %xmm2, %xmm3
movapd 0x10(%rsp), %xmm2
mulsd %xmm7, %xmm2
movapd %xmm3, %xmm1
cmplesd %xmm2, %xmm1
andpd %xmm1, %xmm3
andnpd %xmm2, %xmm1
orpd %xmm3, %xmm1
divsd %xmm1, %xmm0
movapd %xmm0, %xmm1
jmp 0x8f30
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop