// File: /workspace/github_cpp_makefile_star2_O3/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 $0xf8, %rsp
movq %r9, 0xc0(%rsp)
movq %r8, 0x48(%rsp)
movq %rdx, 0xd8(%rsp)
movq %rsi, 0xd0(%rsp)
movq (%rcx), %rax
movq %rcx, 0x98(%rsp)
cmpq %rax, 0x8(%rcx)
je 0xb23c
xorl %ebx, %ebx
movq %rbx, 0xc8(%rsp)
leaq (%rbx,%rbx,2), %rbx
movq (%rax,%rbx,8), %r14
xorpd %xmm0, %xmm0
movapd %xmm0, 0x70(%rsp)
movapd %xmm0, 0x80(%rsp)
xorpd %xmm1, %xmm1
xorpd %xmm11, %xmm11
xorpd %xmm10, %xmm10
xorpd %xmm3, %xmm3
xorpd %xmm6, %xmm6
cmpq 0x8(%rax,%rbx,8), %r14
je 0xa96e
movapd %xmm0, 0x80(%rsp)
movapd %xmm0, 0x70(%rsp)
movapd %xmm11, 0x60(%rsp)
movapd %xmm10, 0x30(%rsp)
movapd %xmm1, 0x50(%rsp)
movapd %xmm3, 0x10(%rsp)
movapd %xmm6, 0x20(%rsp)
movq (%r14), %rbp
movq %rbp, %rax
shrq $0x2, %rax
andl $0x3, %ebp
movq 0x15c44(%rip), %rcx     # 0x202e8
movb (%rcx,%rbp), %r15b
movq 0xd0(%rsp), %rcx
movb (%rcx,%rax), %r13b
andb %r15b, %r13b
movq 0xd8(%rsp), %rcx
movb (%rcx,%rax), %r12b
movb $0x4d, 0xf(%rsp)
leaq 0x15c31(%rip), %rdi     # 0x20300
leaq 0xf(%rsp), %rsi
callq 0x16bf6
testq %rax, %rax
je 0xb24e
movq 0x10(%rax), %rax
cmpb (%rax,%rbp), %r13b
jne 0xa711
movapd 0x20(%rsp), %xmm6
movapd 0x10(%rsp), %xmm3
movapd 0x50(%rsp), %xmm1
movapd 0x30(%rsp), %xmm10
movapd 0x60(%rsp), %xmm11
jmp 0xa930
movb $0x4d, 0xe(%rsp)
leaq 0x15be3(%rip), %rdi     # 0x20300
leaq 0xe(%rsp), %rsi
callq 0x16bf6
testq %rax, %rax
je 0xb24e
andb %r15b, %r12b
movq 0x10(%rax), %rax
cmpb (%rax,%rbp), %r12b
movapd 0x60(%rsp), %xmm11
jne 0xa762
movapd 0x20(%rsp), %xmm6
movapd 0x10(%rsp), %xmm3
movapd 0x50(%rsp), %xmm1
movapd 0x30(%rsp), %xmm10
jmp 0xa930
movsd 0xdd76(%rip), %xmm0     # 0x184e0
movapd 0x70(%rsp), %xmm1
addsd %xmm0, %xmm1
testb %r13b, %r13b
movapd %xmm1, 0x70(%rsp)
je 0xa847
movb $0x48, 0xc(%rsp)
leaq 0x15b71(%rip), %rdi     # 0x20300
leaq 0xc(%rsp), %rsi
callq 0x16bf6
testq %rax, %rax
je 0xb24e
movq 0x10(%rax), %rax
cmpb (%rax,%rbp), %r13b
movsd 0xdd36(%rip), %xmm0     # 0x184e8
movapd 0x20(%rsp), %xmm6
movapd 0x10(%rsp), %xmm3
movapd 0x50(%rsp), %xmm1
jne 0xa8b8
addsd %xmm0, %xmm6
testb %r12b, %r12b
je 0xa94c
movapd %xmm6, 0x20(%rsp)
movb $0x48, 0xb(%rsp)
leaq 0x15b17(%rip), %rdi     # 0x20300
leaq 0xb(%rsp), %rsi
callq 0x16bf6
testq %rax, %rax
je 0xb24e
movq 0x10(%rax), %rax
cmpb (%rax,%rbp), %r12b
movapd 0x10(%rsp), %xmm3
movapd 0x30(%rsp), %xmm10
movapd 0x60(%rsp), %xmm11
jne 0xa83c
addsd 0xdcc6(%rip), %xmm3     # 0x184e8
movapd 0x80(%rsp), %xmm0
addsd 0xdcad(%rip), %xmm0     # 0x184e0
movapd %xmm0, 0x80(%rsp)
movapd 0x20(%rsp), %xmm6
jmp 0xa92a
movapd 0x20(%rsp), %xmm6
addsd %xmm0, %xmm6
testb %r12b, %r12b
je 0xa914
movapd %xmm6, 0x20(%rsp)
movb $0x48, 0xd(%rsp)
leaq 0x15a94(%rip), %rdi     # 0x20300
leaq 0xd(%rsp), %rsi
callq 0x16bf6
testq %rax, %rax
je 0xb24e
movq 0x10(%rax), %rax
cmpb (%rax,%rbp), %r12b
movapd 0x10(%rsp), %xmm3
movapd 0x50(%rsp), %xmm1
movapd 0x60(%rsp), %xmm11
jne 0xa8ad
addsd 0xdc44(%rip), %xmm3     # 0x184e8
addsd 0xdc33(%rip), %xmm11    # 0x184e0
movapd 0x20(%rsp), %xmm6
jmp 0xa756
testb %r12b, %r12b
je 0xa961
movb $0x48, 0xa(%rsp)
leaq 0x15a33(%rip), %rdi     # 0x20300
leaq 0xa(%rsp), %rsi
callq 0x16bf6
testq %rax, %rax
je 0xb24e
movq 0x10(%rax), %rax
cmpb (%rax,%rbp), %r12b
movapd 0x10(%rsp), %xmm3
movapd 0x50(%rsp), %xmm1
movapd 0x30(%rsp), %xmm10
movapd 0x60(%rsp), %xmm11
jne 0xa90c
addsd 0xdbdc(%rip), %xmm3     # 0x184e8
movapd 0x20(%rsp), %xmm6
jmp 0xa930
movapd 0x10(%rsp), %xmm3
addsd %xmm0, %xmm3
movapd 0x30(%rsp), %xmm10
addsd %xmm0, %xmm10
movapd 0x50(%rsp), %xmm1
addq $0x8, %r14
movq 0x98(%rsp), %rax
movq (%rax), %rax
cmpq 0x8(%rax,%rbx,8), %r14
jne 0xa670
jmp 0xa96e
movsd 0xdb8c(%rip), %xmm0     # 0x184e0
addsd %xmm0, %xmm3
addsd %xmm0, %xmm1
jmp 0xa6fe
addsd 0xdb77(%rip), %xmm3     # 0x184e0
jmp 0xa6fe
movapd %xmm1, %xmm7
movapd 0x70(%rsp), %xmm4
movapd %xmm4, %xmm0
subsd %xmm6, %xmm0
movapd %xmm6, %xmm1
cmplesd %xmm0, %xmm1
movapd %xmm1, %xmm2
andnpd %xmm0, %xmm2
andpd %xmm6, %xmm1
orpd %xmm2, %xmm1
addsd %xmm1, %xmm1
movq 0x130(%rsp), %rax
movq (%rax), %rax
movq 0xc8(%rsp), %rbx
movsd %xmm1, (%rax,%rbx,8)
movapd %xmm4, %xmm1
subsd %xmm3, %xmm1
movapd %xmm3, %xmm0
cmplesd %xmm1, %xmm0
movapd %xmm0, %xmm2
andnpd %xmm1, %xmm2
movapd %xmm3, %xmm5
andpd %xmm3, %xmm0
movapd %xmm4, %xmm3
orpd %xmm2, %xmm0
addsd %xmm0, %xmm0
movq 0x138(%rsp), %rcx
movq (%rcx), %rcx
movsd %xmm0, (%rcx,%rbx,8)
movsd 0xdae6(%rip), %xmm4     # 0x184e0
ucomisd %xmm3, %xmm4
jae 0xaa30
movsd (%rax,%rbx,8), %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
xorpd %xmm1, %xmm1
jne 0xaa15
jnp 0xaa30
ucomisd %xmm1, %xmm0
jne 0xaa1d
jnp 0xaa30
movapd 0x80(%rsp), %xmm9
ucomisd %xmm3, %xmm9
jne 0xaa93
jp 0xaa93
movq 0x48(%rsp), %rax
movq (%rax), %rax
movabsq $-0x3fde000000000000, %rcx # imm = 0xC022000000000000
movq %rcx, (%rax,%rbx,8)
movsd 0xdaa2(%rip), %xmm2     # 0x184f0
movq 0xc0(%rsp), %rax
movq (%rax), %rax
movsd %xmm2, (%rax,%rbx,8)
incq %rbx
movq 0x98(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
cmpq %rcx, %rbx
jb 0xa61d
jmp 0xb23c
divsd %xmm3, %xmm6
divsd %xmm3, %xmm5
movapd %xmm5, %xmm8
mulsd %xmm6, %xmm8
ucomisd %xmm1, %xmm9
movapd %xmm7, %xmm1
addsd %xmm11, %xmm1
movsd 0xda2d(%rip), %xmm0     # 0x184e8
mulsd %xmm0, %xmm1
addsd %xmm10, %xmm1
jne 0xab4a
jp 0xab4a
divsd %xmm3, %xmm1
subsd %xmm8, %xmm1
movapd %xmm4, %xmm0
subsd %xmm6, %xmm0
movapd %xmm4, %xmm3
movapd %xmm5, %xmm7
subsd %xmm5, %xmm3
movapd %xmm3, %xmm2
mulsd %xmm0, %xmm2
movapd %xmm1, %xmm4
mulsd %xmm1, %xmm4
movapd %xmm8, %xmm5
mulsd %xmm2, %xmm5
divsd %xmm5, %xmm4
movq 0x48(%rsp), %rax
movq (%rax), %rax
movsd %xmm4, (%rax,%rbx,8)
movsd 0xda1d(%rip), %xmm4     # 0x18538
ucomisd %xmm1, %xmm4
jbe 0xad88
movapd %xmm8, %xmm0
cmplesd %xmm2, %xmm0
andpd %xmm0, %xmm8
andnpd %xmm2, %xmm0
orpd %xmm8, %xmm0
xorpd 0xd98b(%rip), %xmm0     # 0x184d0
jmp 0xadb7
movapd %xmm9, %xmm12
mulsd %xmm0, %xmm12
movapd %xmm5, 0x10(%rsp)
movapd %xmm5, %xmm0
addsd %xmm6, %xmm0
movapd %xmm3, %xmm5
movapd %xmm4, %xmm3
subsd %xmm0, %xmm3
addsd %xmm0, %xmm0
subsd %xmm0, %xmm4
addsd %xmm10, %xmm10
addsd %xmm11, %xmm10
addsd %xmm10, %xmm7
movapd %xmm5, %xmm10
addsd %xmm5, %xmm10
movapd %xmm10, %xmm0
mulsd %xmm4, %xmm0
movapd %xmm7, %xmm2
addsd %xmm7, %xmm2
subsd %xmm2, %xmm0
subsd %xmm9, %xmm0
mulsd %xmm7, %xmm4
movapd %xmm10, %xmm2
mulsd %xmm8, %xmm2
subsd %xmm4, %xmm2
mulsd %xmm9, %xmm3
subsd %xmm3, %xmm2
addsd %xmm10, %xmm10
movapd %xmm0, %xmm3
divsd %xmm10, %xmm3
movapd %xmm3, %xmm9
movsd 0xd929(%rip), %xmm4     # 0x18508
divsd %xmm4, %xmm9
movapd %xmm10, %xmm11
mulsd %xmm9, %xmm11
addsd %xmm0, %xmm11
movapd %xmm10, %xmm0
mulsd %xmm4, %xmm0
mulsd %xmm9, %xmm11
addsd %xmm2, %xmm11
movapd %xmm2, %xmm13
divsd %xmm0, %xmm13
movapd %xmm1, %xmm4
divsd %xmm5, %xmm4
movsd 0xd8d8(%rip), %xmm2     # 0x184f8
addsd %xmm2, %xmm4
mulsd %xmm8, %xmm7
mulsd %xmm3, %xmm3
divsd 0xd8db(%rip), %xmm3     # 0x18510
addsd %xmm3, %xmm13
movapd %xmm10, %xmm0
mulsd 0xd8d1(%rip), %xmm0     # 0x18518
mulsd %xmm10, %xmm0
mulsd %xmm13, %xmm0
mulsd %xmm13, %xmm0
mulsd %xmm13, %xmm0
mulsd %xmm9, %xmm11
subsd %xmm7, %xmm11
movapd %xmm11, %xmm7
mulsd %xmm11, %xmm7
subsd %xmm0, %xmm7
movsd 0xd885(%rip), %xmm3     # 0x18500
ucomisd %xmm3, %xmm7
movapd %xmm6, 0x20(%rsp)
movapd %xmm8, 0x50(%rsp)
movapd %xmm9, 0x60(%rsp)
jbe 0xadc4
xorps %xmm0, %xmm0
sqrtsd %xmm7, %xmm0
movapd %xmm7, 0x70(%rsp)
ucomisd 0xd89a(%rip), %xmm7     # 0x18548
movsd %xmm0, 0xa0(%rsp)
movapd %xmm11, 0x80(%rsp)
jae 0xace6
movapd 0x70(%rsp), %xmm0
movsd %xmm10, 0x30(%rsp)
callq 0x4220
movapd 0x80(%rsp), %xmm11
movsd 0x30(%rsp), %xmm10
subsd %xmm11, %xmm0
addsd %xmm10, %xmm10
movsd %xmm10, 0x30(%rsp)
divsd %xmm10, %xmm0
callq 0x4070
movapd %xmm0, %xmm2
movapd 0x70(%rsp), %xmm0
ucomisd 0xd835(%rip), %xmm0     # 0x18548
movsd 0xa0(%rsp), %xmm1
jae 0xad33
movsd %xmm2, 0x70(%rsp)
callq 0x4220
movsd 0x70(%rsp), %xmm2
movapd %xmm0, %xmm1
movapd 0x60(%rsp), %xmm0
addsd %xmm2, %xmm0
movapd %xmm0, 0x60(%rsp)
movapd 0x80(%rsp), %xmm0
addsd %xmm1, %xmm0
xorpd 0xd778(%rip), %xmm0     # 0x184d0
divsd 0x30(%rsp), %xmm0
callq 0x4070
addsd 0x60(%rsp), %xmm0
movsd 0xd76f(%rip), %xmm3     # 0x184e0
movapd 0x20(%rsp), %xmm6
movapd 0x10(%rsp), %xmm4
movapd 0x50(%rsp), %xmm7
jmp 0xb194
xorpd %xmm2, %xmm2
ucomisd 0xd7ac(%rip), %xmm1     # 0x18540
jbe 0xaa4e
mulsd %xmm3, %xmm6
mulsd %xmm0, %xmm7
movapd %xmm6, %xmm0
cmplesd %xmm7, %xmm0
andpd %xmm0, %xmm6
andnpd %xmm7, %xmm0
orpd %xmm6, %xmm0
divsd %xmm0, %xmm1
movapd %xmm1, %xmm2
jmp 0xaa4e
addsd %xmm1, %xmm12
divsd %xmm5, %xmm12
addsd %xmm3, %xmm12
ucomisd %xmm7, %xmm2
movapd %xmm12, 0x30(%rsp)
movapd %xmm4, 0xa0(%rsp)
jbe 0xae0a
movsd %xmm13, 0xb0(%rsp)
ucomisd 0xd74d(%rip), %xmm0     # 0x18548
jb 0xaeb7
sqrtsd %xmm0, %xmm0
jmp 0xaed0
addsd %xmm10, %xmm10
divsd %xmm10, %xmm11
movapd %xmm11, %xmm0
callq 0x4070
movapd 0x30(%rsp), %xmm4
movapd 0x60(%rsp), %xmm2
movapd %xmm2, %xmm1
addsd %xmm0, %xmm1
addsd %xmm0, %xmm0
subsd %xmm0, %xmm2
movapd %xmm2, %xmm0
movapd 0xa0(%rsp), %xmm5
ucomisd %xmm1, %xmm5
movapd %xmm4, %xmm2
cmpltpd %xmm0, %xmm2
movapd %xmm0, %xmm3
cmpltpd %xmm5, %xmm3
orpd %xmm2, %xmm3
movd %xmm3, %eax
ja 0xae90
ucomisd %xmm4, %xmm1
ja 0xae90
testb $0x1, %al
movapd 0x20(%rsp), %xmm6
movapd 0x10(%rsp), %xmm4
movapd 0x50(%rsp), %xmm7
je 0xb080
movapd %xmm1, %xmm0
jmp 0xb123
testb $0x1, %al
movsd 0xd646(%rip), %xmm3     # 0x184e0
movapd 0x20(%rsp), %xmm6
movapd 0x10(%rsp), %xmm4
movapd 0x50(%rsp), %xmm7
jne 0xaa30
jmp 0xb194
movapd %xmm11, 0x80(%rsp)
callq 0x4220
movapd 0x80(%rsp), %xmm11
xorpd 0xd5f7(%rip), %xmm11    # 0x184d0
divsd %xmm0, %xmm11
movapd %xmm11, %xmm0
callq 0x4280
movapd %xmm0, %xmm2
divsd 0xd62c(%rip), %xmm2     # 0x18520
xorpd %xmm1, %xmm1
movsd 0xb0(%rsp), %xmm0
ucomisd %xmm1, %xmm0
movsd %xmm2, 0x70(%rsp)
jb 0xaf13
sqrtsd %xmm0, %xmm0
jmp 0xaf1e
callq 0x4220
movsd 0x70(%rsp), %xmm2
addsd %xmm0, %xmm0
movapd %xmm0, 0x80(%rsp)
movapd %xmm2, %xmm0
callq 0x4520
mulsd 0x80(%rsp), %xmm0
addsd 0x60(%rsp), %xmm0
movapd %xmm0, 0xb0(%rsp)
movsd 0x70(%rsp), %xmm0
addsd 0xd5ce(%rip), %xmm0     # 0x18528
callq 0x4520
movapd %xmm0, 0xe0(%rsp)
movsd 0x70(%rsp), %xmm0
addsd 0xd5ba(%rip), %xmm0     # 0x18530
callq 0x4520
movapd 0xb0(%rsp), %xmm8
movapd 0x60(%rsp), %xmm5
movapd 0x80(%rsp), %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
movapd 0xe0(%rsp), %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
mulpd %xmm1, %xmm2
unpcklpd %xmm5, %xmm5            # xmm5 = xmm5[0,0]
addpd %xmm2, %xmm5
movapd 0xa0(%rsp), %xmm4
ucomisd %xmm8, %xmm4
movapd 0x30(%rsp), %xmm3
movapd %xmm3, %xmm0
cmpltpd %xmm5, %xmm0
movapd %xmm5, %xmm1
cmpltpd %xmm4, %xmm1
orpd %xmm0, %xmm1
movd %xmm1, %ecx
movapd %xmm5, %xmm0
unpckhpd %xmm5, %xmm0            # xmm0 = xmm0[1],xmm5[1]
movapd %xmm3, %xmm1
cmpltpd %xmm0, %xmm1
movapd %xmm0, %xmm2
cmpltpd %xmm4, %xmm2
orpd %xmm1, %xmm2
movd %xmm2, %eax
ja 0xb041
ucomisd %xmm3, %xmm8
ja 0xb041
testb $0x1, %cl
movapd 0xd4ab(%rip), %xmm4     # 0x184c0
movapd 0x20(%rsp), %xmm6
movapd 0x50(%rsp), %xmm7
je 0xb0ac
testb $0x1, %al
movsd 0xd4af(%rip), %xmm3     # 0x184e0
je 0xb12d
movapd %xmm8, %xmm0
jmp 0xb18e
testb $0x1, %cl
movsd 0xd494(%rip), %xmm3     # 0x184e0
movapd 0x20(%rsp), %xmm6
movapd 0x50(%rsp), %xmm7
je 0xb06d
testb $0x1, %al
movapd 0x10(%rsp), %xmm4
jne 0xaa30
jmp 0xb194
testb $0x1, %al
movapd 0x10(%rsp), %xmm4
je 0xb0ed
movapd %xmm5, %xmm0
jmp 0xb194
movapd %xmm1, %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
movapd %xmm7, %xmm3
unpcklpd %xmm7, %xmm3            # xmm3 = xmm3[0],xmm7[0]
subpd %xmm3, %xmm2
andpd 0xd424(%rip), %xmm2     # 0x184c0
pshufd $0xee, %xmm2, %xmm3     # xmm3 = xmm2[2,3,2,3]
cmplesd %xmm3, %xmm2
andpd %xmm2, %xmm1
jmp 0xb117
movapd %xmm5, %xmm1
unpcklpd %xmm8, %xmm1            # xmm1 = xmm1[0],xmm8[0]
movapd %xmm7, %xmm2
unpcklpd %xmm7, %xmm2            # xmm2 = xmm2[0],xmm7[0]
subpd %xmm2, %xmm1
andpd %xmm4, %xmm1
pshufd $0xee, %xmm1, %xmm3     # xmm3 = xmm1[2,3,2,3]
cmplesd %xmm3, %xmm1
movapd %xmm1, %xmm3
andpd %xmm5, %xmm3
andnpd %xmm8, %xmm1
orpd %xmm3, %xmm1
testb $0x1, %al
je 0xb160
movapd %xmm1, %xmm0
jmp 0xb186
movapd %xmm7, %xmm1
unpcklpd %xmm7, %xmm1            # xmm1 = xmm1[0],xmm7[0]
movapd %xmm5, %xmm2
subpd %xmm1, %xmm2
andpd 0xd3bb(%rip), %xmm2     # 0x184c0
pshufd $0xee, %xmm2, %xmm1     # xmm1 = xmm2[2,3,2,3]
cmplesd %xmm1, %xmm2
movapd %xmm2, %xmm1
andpd %xmm5, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
movapd %xmm2, %xmm0
movsd 0xd3b5(%rip), %xmm3     # 0x184e0
jmp 0xb194
movsd %xmm8, %xmm5            # xmm5 = xmm8[0],xmm5[1]
movapd %xmm7, %xmm1
unpcklpd %xmm7, %xmm1            # xmm1 = xmm1[0],xmm7[0]
subpd %xmm1, %xmm5
andpd %xmm4, %xmm5
pshufd $0xee, %xmm5, %xmm1     # xmm1 = xmm5[2,3,2,3]
cmplesd %xmm1, %xmm5
andpd %xmm5, %xmm8
andnpd %xmm0, %xmm5
orpd %xmm8, %xmm5
movapd %xmm5, %xmm0
jmp 0xb18e
movsd %xmm1, %xmm5            # xmm5 = xmm1[0],xmm5[1]
subpd %xmm2, %xmm5
andpd %xmm4, %xmm5
pshufd $0xee, %xmm5, %xmm2     # xmm2 = xmm5[2,3,2,3]
cmplesd %xmm2, %xmm5
andpd %xmm5, %xmm1
andnpd %xmm0, %xmm5
orpd %xmm1, %xmm5
movapd %xmm5, %xmm0
movsd 0xd352(%rip), %xmm3     # 0x184e0
movapd 0x10(%rsp), %xmm4
subsd %xmm7, %xmm0
movapd %xmm3, %xmm1
subsd %xmm6, %xmm1
subsd %xmm4, %xmm3
movapd %xmm3, %xmm2
mulsd %xmm1, %xmm2
movapd %xmm0, %xmm4
mulsd %xmm0, %xmm4
movapd %xmm7, %xmm5
mulsd %xmm2, %xmm5
divsd %xmm5, %xmm4
movq 0x48(%rsp), %rax
movq (%rax), %rax
movsd %xmm4, (%rax,%rbx,8)
movsd 0xd363(%rip), %xmm4     # 0x18538
ucomisd %xmm0, %xmm4
jbe 0xb1fa
movapd %xmm7, %xmm1
cmplesd %xmm2, %xmm1
andpd %xmm1, %xmm7
andnpd %xmm2, %xmm1
orpd %xmm7, %xmm1
xorpd 0xd2d8(%rip), %xmm1     # 0x184d0
jmp 0xb22f
xorpd %xmm2, %xmm2
ucomisd 0xd33a(%rip), %xmm0     # 0x18540
jbe 0xaa4e
mulsd %xmm3, %xmm6
movapd 0x10(%rsp), %xmm2
mulsd %xmm1, %xmm2
movapd %xmm6, %xmm1
cmplesd %xmm2, %xmm1
andpd %xmm1, %xmm6
andnpd %xmm2, %xmm1
orpd %xmm6, %xmm1
divsd %xmm1, %xmm0
movapd %xmm0, %xmm2
jmp 0xaa4e
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xdcc3(%rip), %rdi      # 0x18f18
callq 0x43e0