// File: /workspace/github_cpp_makefile_star2_O1/tonymugen[P]sampleSNPs/varfiles.cpp
// Function: sampFiles::BedFileI::_ld(char const*, char const*, unsigned long const&, unsigned short const&, double&, double&, double&, double&)
void BedFileI::_ld(const char *snp1, const char *snp2, const size_t &N, const unsigned short &pad, double &rSq, double &Dprime, double &dcnt1, double &dcnt2){
	// Using the Gaunt et al. (2007) formulation
	// 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
	// However, then convert everything to the most common allele frequencies to make things compatible with Gaunt et al.
	// Using the notation in that paper, too, to make things more clear

	// constants
	const char allMiss = static_cast<char>(0x55); // all genotypes missing in a byte
	const char homDerv = static_cast<char>(0x00); // homozygous derived for all bit-pair positions

	// modifiable parameters
	double D     = 0.0;
	double p1    = 0.0; // frequency of the derived allele at snp1
	double q1    = 0.0; // frequency of the derived allele at snp2
	double f11   = 0.0; // frequency of the (hom. maj. allele @1, hom. maj.allel @2) haplotype; to be estimated; D = f11 - p1*q1
	double n11   = 0.0; // # of 1,1 homozygote haplotypes
	double n12   = 0.0; // # of hom. 1, heterozygous 2 haplotypes
	double n21   = 0.0; // # of het. 1, hom. 2 haplotypes
	double n22   = 0.0; // # of het. 1, het. 2 haplotypes
	double Npres = 0.0; // # 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;

	// Data missing at either locus are ignored (i.e. I am using pairwise-complete observations)
	for (size_t ind = 0; ind < N-1; ind++) { // leave the last byte out for now since it has padding bits (in general)
		if ( (snp1[ind] == allMiss) || (snp2[ind] == allMiss) ) { // a byte with all data missing; ignore (NOTE the OR)
			continue;
		}

		// go through the byte from the end
		for (size_t inByte = 0; inByte < 4; inByte++) {
			curBitPair1 = snp1[ind] & _masks[inByte];
			curBitPair2 = snp2[ind] & _masks[inByte];

			// Test missingness
			if ( (curBitPair1 == _tests.at('M')[inByte]) || (curBitPair2 == _tests.at('M')[inByte]) ) { // 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')[inByte]){
					q1  += 0.5;
					n12 += 1.0;
				}
			} else if (curBitPair1 == _tests.at('H')[inByte]){
				p1 += 0.5;
				if (curBitPair2 == homDerv) {
					q1  += 1.0;
					n21 += 1.0;
				} else if (curBitPair2 == _tests.at('H')[inByte]){
					q1  += 0.5;
					n22 += 1.0;
				}
			} else {
				if (curBitPair2 == homDerv) {
					q1 += 1.0;
				} else if (curBitPair2 == _tests.at('H')[inByte]){
					q1 += 0.5;
				}
			}
		}
	}
	// finally, deal with the padded byte
	for (size_t inByte = 0; inByte < (4 - pad); inByte++) { // not testing for sane values of pad, since this is a protected function and I can expect sane values in correct class implementation
		curBitPair1 = snp1[N-1] & _masks[inByte];
		curBitPair2 = snp2[N-1] & _masks[inByte];

		// Test missingness
		if ( (curBitPair1 == _tests.at('M')[inByte]) || (curBitPair2 == _tests.at('M')[inByte]) ) { // 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')[inByte]){
				q1  += 0.5;
				n12 += 1.0;
			}
		} else if (curBitPair1 == _tests.at('H')[inByte]){
			p1 += 0.5;
			if (curBitPair2 == homDerv) {
				q1  += 1.0;
				n21 += 1.0;
			} else if (curBitPair2 == _tests.at('H')[inByte]){
				q1  += 0.5;
				n22 += 1.0;
			}
		} else {
			if (curBitPair2 == homDerv) {
				q1 += 1.0;
			} else if (curBitPair2 == _tests.at('H')[inByte]){
				q1 += 0.5;
			}
		}
	}

	// minor allele counts
	dcnt1 = (p1 <= Npres - p1 ? 2.0*p1 : 2.0*(Npres - p1));
	dcnt2 = (q1 <= Npres - q1 ? 2.0*q1 : 2.0*(Npres - q1));

	if (Npres <= 1.0) {
		rSq    = -9.0;
		Dprime = -9.0;
		return;
	}
	if ( (dcnt1 == 0.0) || (dcnt2 == 0.0) ) { // even if the SNPs are pre-screened for polymorphism, the alternatives may correspond to missing at the other locus
		rSq    = -9.0;
		Dprime = -9.0;
		return;
	}
	if (n22 == Npres) { // if everyone is het, cannot determine LD because we don't know the phase
		rSq    = -9.0;
		Dprime = -9.0;
		return;
	}
	// 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  = (D*D)/(p1q1*p2q2);

		if (D < -10.0*EPS) {
			double Dmax = ( p1q1 <= p2q2 ? -p1q1 : -p2q2 ); // (9) of Gaunt et al.
			Dprime      = 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      = D/Dmax;
		} else {
			Dprime = 0.0;
		}

		return;
	}

	// 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    = -9.0;
					Dprime = -9.0;

					return;

				} 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    = -9.0;
				Dprime = -9.0;

				return;
			} 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  = (D*D)/(p1q1*p2q2);

	if (D < -10.0*EPS) {
		double Dmax = ( p1q1 <= p2q2 ? -p1q1 : -p2q2 ); // (9) of Gaunt et al.
		Dprime      = 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      = D/Dmax;
	} else {
		Dprime = 0.0;
	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %r9, 0x48(%rsp)
movq %r8, 0xb0(%rsp)
movq %rdx, 0x90(%rsp)
movq %rsi, 0x70(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq %rcx, 0x60(%rsp)
cmpq $0x1, (%rcx)
movapd %xmm0, 0x80(%rsp)
movapd %xmm0, 0xa0(%rsp)
movapd %xmm0, 0xc0(%rsp)
movapd %xmm0, 0x50(%rsp)
xorpd %xmm1, %xmm1
jne 0x9938
movapd %xmm1, (%rsp)
movq 0xb0(%rsp), %rax
cmpw $0x4, (%rax)
movapd %xmm0, 0x20(%rsp)
jne 0x9bc5
movq 0x110(%rsp), %rbx
movapd 0x30(%rsp), %xmm4
movapd %xmm4, %xmm0
movapd 0x20(%rsp), %xmm3
subsd %xmm3, %xmm0
movapd %xmm3, %xmm1
cmplesd %xmm0, %xmm1
movapd %xmm1, %xmm2
andnpd %xmm0, %xmm2
andpd %xmm3, %xmm1
orpd %xmm2, %xmm1
addsd %xmm1, %xmm1
movq 0x118(%rsp), %rax
movsd %xmm1, (%rax)
movapd %xmm4, %xmm1
movapd (%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 0x120(%rsp), %rcx
movsd %xmm0, (%rcx)
movsd 0xec16(%rip), %xmm10    # 0x184e0
ucomisd %xmm4, %xmm10
jae 0x9908
movsd (%rax), %xmm2
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm2
jne 0x98e1
jnp 0x9908
ucomisd %xmm1, %xmm0
jne 0x98e9
jnp 0x9908
movapd 0x80(%rsp), %xmm1
movapd 0x30(%rsp), %xmm0
ucomisd %xmm0, %xmm1
jne 0x9e1c
jp 0x9e1c
movabsq $-0x3fde000000000000, %rax # imm = 0xC022000000000000
movq 0x48(%rsp), %rcx
movq %rax, (%rcx)
movsd 0xebce(%rip), %xmm2     # 0x184f0
movsd %xmm2, (%rbx)
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
leaq 0x169be(%rip), %rbp     # 0x20300
xorpd %xmm2, %xmm2
movapd %xmm2, 0x50(%rsp)
movapd %xmm2, 0xc0(%rsp)
movapd %xmm2, 0xa0(%rsp)
movapd %xmm2, 0x80(%rsp)
movapd %xmm2, 0x30(%rsp)
movq 0x70(%rsp), %rax
cmpb $0x55, (%rax,%r15)
je 0x9988
movq 0x90(%rsp), %rax
cmpb $0x55, (%rax,%r15)
jne 0x99a0
incq %r15
movq 0x60(%rsp), %rax
movq (%rax), %rax
decq %rax
cmpq %rax, %r15
jb 0x996d
jmp 0x9829
xorl %r14d, %r14d
movapd %xmm1, (%rsp)
movapd %xmm0, 0x20(%rsp)
movq 0x16933(%rip), %rax     # 0x202e8
movb (%rax,%r14), %r13b
movq 0x70(%rsp), %rax
movb (%rax,%r15), %r12b
andb %r13b, %r12b
movq 0x90(%rsp), %rax
movb (%rax,%r15), %bl
movb $0x4d, 0x1f(%rsp)
movq %rbp, %rdi
leaq 0x1f(%rsp), %rsi
callq 0x16d8a
movq (%rax), %rax
cmpb (%rax,%r14), %r12b
je 0x9a0a
andb %r13b, %bl
movb $0x4d, 0x1e(%rsp)
movq %rbp, %rdi
leaq 0x1e(%rsp), %rsi
callq 0x16d8a
movq (%rax), %rax
cmpb (%rax,%r14), %bl
jne 0x9a23
movapd 0x20(%rsp), %xmm0
movapd (%rsp), %xmm1
incq %r14
cmpq $0x4, %r14
jne 0x99a3
jmp 0x9988
movapd 0x30(%rsp), %xmm0
movsd 0xeaaf(%rip), %xmm1     # 0x184e0
addsd %xmm1, %xmm0
movapd %xmm0, 0x30(%rsp)
testb %r12b, %r12b
je 0x9aca
movb $0x48, 0x1c(%rsp)
movq %rbp, %rdi
leaq 0x1c(%rsp), %rsi
callq 0x16d8a
movq (%rax), %rax
cmpb (%rax,%r14), %r12b
jne 0x9b2d
movapd 0x20(%rsp), %xmm0
addsd 0xea77(%rip), %xmm0     # 0x184e8
testb %bl, %bl
je 0x9b81
movapd %xmm0, 0x20(%rsp)
movb $0x48, 0x1b(%rsp)
movq %rbp, %rdi
leaq 0x1b(%rsp), %rsi
callq 0x16d8a
movq (%rax), %rax
cmpb (%rax,%r14), %bl
jne 0x9a0a
movapd (%rsp), %xmm1
addsd 0xea3d(%rip), %xmm1     # 0x184e8
movapd 0x80(%rsp), %xmm0
addsd 0xea24(%rip), %xmm0     # 0x184e0
movapd %xmm0, 0x80(%rsp)
jmp 0x9bba
movapd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
testb %bl, %bl
je 0x9b5f
movapd %xmm0, 0x20(%rsp)
movb $0x48, 0x1d(%rsp)
movq %rbp, %rdi
leaq 0x1d(%rsp), %rsi
callq 0x16d8a
movq (%rax), %rax
cmpb (%rax,%r14), %bl
jne 0x9a0a
movapd (%rsp), %xmm1
addsd 0xe9da(%rip), %xmm1     # 0x184e8
movapd 0xc0(%rsp), %xmm0
addsd 0xe9c1(%rip), %xmm0     # 0x184e0
movapd %xmm0, 0xc0(%rsp)
jmp 0x9bba
testb %bl, %bl
je 0x9bad
movb $0x48, 0x1a(%rsp)
movq %rbp, %rdi
leaq 0x1a(%rsp), %rsi
callq 0x16d8a
movq (%rax), %rax
cmpb (%rax,%r14), %bl
jne 0x9a0a
movapd (%rsp), %xmm1
addsd 0xe98b(%rip), %xmm1     # 0x184e8
jmp 0x9bba
movapd %xmm1, %xmm3
movapd (%rsp), %xmm1
addsd %xmm3, %xmm1
movapd 0x50(%rsp), %xmm2
addsd %xmm3, %xmm2
movapd %xmm2, 0x50(%rsp)
jmp 0x9a15
movapd (%rsp), %xmm1
movsd 0xe952(%rip), %xmm3     # 0x184e0
addsd %xmm3, %xmm1
movapd 0xa0(%rsp), %xmm2
addsd %xmm3, %xmm2
movapd %xmm2, 0xa0(%rsp)
jmp 0x9a15
movapd (%rsp), %xmm1
addsd 0xe926(%rip), %xmm1     # 0x184e0
movapd 0x20(%rsp), %xmm0
jmp 0x9a15
xorl %r15d, %r15d
leaq 0x16731(%rip), %rbx     # 0x20300
leaq 0x19(%rsp), %r14
movq 0x60(%rsp), %rax
movq (%rax), %rax
movq 0x16705(%rip), %rcx     # 0x202e8
movb (%rcx,%r15), %r13b
movq 0x70(%rsp), %rcx
movb -0x1(%rcx,%rax), %r12b
andb %r13b, %r12b
movq 0x90(%rsp), %rcx
movb -0x1(%rcx,%rax), %bpl
movb $0x4d, 0x19(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x16d8a
movq (%rax), %rax
cmpb (%rax,%r15), %r12b
je 0x9c38
andb %r13b, %bpl
movb $0x4d, 0x18(%rsp)
movq %rbx, %rdi
leaq 0x18(%rsp), %rsi
callq 0x16d8a
movq (%rax), %rax
cmpb (%rax,%r15), %bpl
jne 0x9c58
incq %r15
movq 0xb0(%rsp), %rax
movzwl (%rax), %eax
movl $0x4, %ecx
subq %rax, %rcx
cmpq %rcx, %r15
jb 0x9bd4
jmp 0x9846
movapd 0x30(%rsp), %xmm0
movsd 0xe87a(%rip), %xmm1     # 0x184e0
addsd %xmm1, %xmm0
movapd %xmm0, 0x30(%rsp)
testb %r12b, %r12b
je 0x9d09
movb $0x48, 0x16(%rsp)
movq %rbx, %rdi
leaq 0x16(%rsp), %rsi
callq 0x16d8a
movq (%rax), %rax
cmpb (%rax,%r15), %r12b
jne 0x9d76
movapd 0x20(%rsp), %xmm0
addsd 0xe842(%rip), %xmm0     # 0x184e8
movapd %xmm0, 0x20(%rsp)
testb %bpl, %bpl
je 0x9dd0
movb $0x48, 0x15(%rsp)
movq %rbx, %rdi
leaq 0x15(%rsp), %rsi
callq 0x16d8a
movq (%rax), %rax
cmpb (%rax,%r15), %bpl
jne 0x9c38
movapd (%rsp), %xmm0
addsd 0xe807(%rip), %xmm0     # 0x184e8
movapd %xmm0, (%rsp)
movapd 0x80(%rsp), %xmm0
movsd 0xe7e9(%rip), %xmm1     # 0x184e0
addsd %xmm1, %xmm0
movapd %xmm0, 0x80(%rsp)
jmp 0x9c38
movapd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
movapd %xmm0, 0x20(%rsp)
testb %bpl, %bpl
je 0x9dad
movb $0x48, 0x17(%rsp)
movq %rbx, %rdi
leaq 0x17(%rsp), %rsi
callq 0x16d8a
movq (%rax), %rax
cmpb (%rax,%r15), %bpl
jne 0x9c38
movapd (%rsp), %xmm0
addsd 0xe79a(%rip), %xmm0     # 0x184e8
movapd %xmm0, (%rsp)
movapd 0xc0(%rsp), %xmm0
movsd 0xe77c(%rip), %xmm1     # 0x184e0
addsd %xmm1, %xmm0
movapd %xmm0, 0xc0(%rsp)
jmp 0x9c38
testb %bpl, %bpl
je 0x9e01
movb $0x48, 0x14(%rsp)
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0x16d8a
movq (%rax), %rax
cmpb (%rax,%r15), %bpl
jne 0x9c38
movapd (%rsp), %xmm0
addsd 0xe73d(%rip), %xmm0     # 0x184e8
jmp 0x9e12
movapd (%rsp), %xmm0
addsd %xmm1, %xmm0
movapd %xmm0, (%rsp)
movapd 0x50(%rsp), %xmm0
addsd %xmm1, %xmm0
movapd %xmm0, 0x50(%rsp)
jmp 0x9c38
movapd (%rsp), %xmm0
movsd 0xe703(%rip), %xmm1     # 0x184e0
addsd %xmm1, %xmm0
movapd %xmm0, (%rsp)
movapd 0xa0(%rsp), %xmm0
addsd %xmm1, %xmm0
movapd %xmm0, 0xa0(%rsp)
jmp 0x9c38
movapd (%rsp), %xmm0
movsd 0xe6d2(%rip), %xmm1     # 0x184e0
addsd %xmm1, %xmm0
movapd %xmm0, (%rsp)
jmp 0x9c38
movapd %xmm3, %xmm5
movapd 0x20(%rsp), %xmm3
divsd %xmm0, %xmm3
divsd %xmm0, %xmm5
movapd %xmm5, %xmm11
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
movapd 0x30(%rsp), %xmm6
movapd %xmm1, %xmm13
movapd 0xa0(%rsp), %xmm7
movapd %xmm7, %xmm1
movapd 0xc0(%rsp), %xmm9
addsd %xmm9, %xmm1
mulsd 0xe67e(%rip), %xmm1     # 0x184e8
mulsd %xmm3, %xmm11
movapd 0x50(%rsp), %xmm8
addsd %xmm8, %xmm1
movapd %xmm1, %xmm12
divsd %xmm6, %xmm12
jne 0x9f01
jp 0x9f01
subsd %xmm11, %xmm12
movapd %xmm10, %xmm0
movapd %xmm3, %xmm4
subsd %xmm3, %xmm0
subsd %xmm5, %xmm10
movapd %xmm10, %xmm1
mulsd %xmm0, %xmm1
movapd %xmm12, %xmm2
mulsd %xmm12, %xmm2
movapd %xmm11, %xmm3
mulsd %xmm1, %xmm3
divsd %xmm3, %xmm2
movq 0x48(%rsp), %rax
movsd %xmm2, (%rax)
movsd 0xe667(%rip), %xmm2     # 0x18538
ucomisd %xmm12, %xmm2
jbe 0xa105
movapd %xmm11, %xmm0
cmplesd %xmm1, %xmm0
andpd %xmm0, %xmm11
andnpd %xmm1, %xmm0
orpd %xmm11, %xmm0
xorpd 0xe5d4(%rip), %xmm0     # 0x184d0
jmp 0xa13e
movsd 0xe5f7(%rip), %xmm2     # 0x18500
movapd %xmm5, (%rsp)
movapd %xmm5, %xmm0
movapd %xmm3, 0x20(%rsp)
addsd %xmm3, %xmm0
movapd %xmm10, %xmm4
subsd %xmm0, %xmm4
addsd %xmm0, %xmm0
movapd %xmm10, %xmm5
subsd %xmm0, %xmm5
addsd %xmm8, %xmm8
addsd %xmm9, %xmm8
addsd %xmm8, %xmm7
movapd %xmm6, %xmm9
addsd %xmm6, %xmm9
movapd %xmm9, %xmm0
mulsd %xmm5, %xmm0
movapd %xmm7, %xmm3
addsd %xmm7, %xmm3
subsd %xmm3, %xmm0
subsd %xmm13, %xmm0
mulsd %xmm7, %xmm5
movapd %xmm9, %xmm3
mulsd %xmm11, %xmm3
subsd %xmm5, %xmm3
mulsd %xmm13, %xmm4
subsd %xmm4, %xmm3
mulsd %xmm11, %xmm7
addsd %xmm9, %xmm9
movapd %xmm0, %xmm4
divsd %xmm9, %xmm4
movsd 0xe56d(%rip), %xmm5     # 0x18508
movapd %xmm4, %xmm8
divsd %xmm5, %xmm8
mulsd %xmm4, %xmm4
divsd 0xe55f(%rip), %xmm4     # 0x18510
mulsd %xmm9, %xmm5
movapd %xmm9, %xmm10
mulsd %xmm8, %xmm10
addsd %xmm0, %xmm10
mulsd %xmm8, %xmm10
addsd %xmm3, %xmm10
divsd %xmm5, %xmm3
addsd %xmm4, %xmm3
movsd 0xe539(%rip), %xmm0     # 0x18518
mulsd %xmm9, %xmm0
mulsd %xmm9, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm0
movapd %xmm8, 0x70(%rsp)
mulsd %xmm8, %xmm10
subsd %xmm7, %xmm10
movapd %xmm10, %xmm4
mulsd %xmm10, %xmm4
subsd %xmm0, %xmm4
ucomisd %xmm2, %xmm4
movapd %xmm11, 0x90(%rsp)
jbe 0xa14d
xorps %xmm0, %xmm0
sqrtsd %xmm4, %xmm0
xorpd %xmm1, %xmm1
movapd %xmm4, 0xb0(%rsp)
ucomisd %xmm1, %xmm4
movsd %xmm0, 0x50(%rsp)
movapd %xmm10, 0x60(%rsp)
jae 0xa072
movapd 0xb0(%rsp), %xmm0
movsd %xmm9, 0x30(%rsp)
callq 0x4220
movapd 0x60(%rsp), %xmm10
movsd 0x30(%rsp), %xmm9
subsd %xmm10, %xmm0
addsd %xmm9, %xmm9
movsd %xmm9, 0x30(%rsp)
divsd %xmm9, %xmm0
callq 0x4070
movapd 0x70(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, 0x70(%rsp)
movapd 0xb0(%rsp), %xmm0
ucomisd 0xe49a(%rip), %xmm0     # 0x18548
movsd 0x50(%rsp), %xmm1
jae 0xa0bf
callq 0x4220
movapd %xmm0, %xmm1
movapd 0x60(%rsp), %xmm0
addsd %xmm1, %xmm0
xorpd 0xe3ff(%rip), %xmm0     # 0x184d0
divsd 0x30(%rsp), %xmm0
callq 0x4070
movapd 0x70(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
movapd (%rsp), %xmm3
movsd 0xe3e9(%rip), %xmm5     # 0x184e0
movapd 0x90(%rsp), %xmm6
jmp 0xa55c
xorpd %xmm2, %xmm2
ucomisd 0xe42e(%rip), %xmm12    # 0x18540
jbe 0x9922
movapd %xmm5, %xmm6
movapd %xmm4, %xmm1
mulsd %xmm10, %xmm1
mulsd %xmm0, %xmm6
movapd %xmm1, %xmm0
cmplesd %xmm6, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm6, %xmm0
orpd %xmm1, %xmm0
divsd %xmm0, %xmm12
movapd %xmm12, %xmm2
jmp 0x9922
mulsd 0xe392(%rip), %xmm13    # 0x184e8
addsd %xmm1, %xmm13
addsd 0xe394(%rip), %xmm12    # 0x184f8
divsd %xmm6, %xmm13
addsd %xmm2, %xmm13
movsd 0xe382(%rip), %xmm1     # 0x184f8
ucomisd %xmm4, %xmm1
movapd %xmm13, 0x80(%rsp)
movapd %xmm12, 0xb0(%rsp)
jbe 0xa1b6
movsd %xmm3, 0x50(%rsp)
xorpd 0xe331(%rip), %xmm10    # 0x184d0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xa276
sqrtsd %xmm0, %xmm0
jmp 0xa289
addsd %xmm9, %xmm9
divsd %xmm9, %xmm10
movapd %xmm10, %xmm0
callq 0x4070
movapd 0x80(%rsp), %xmm3
movapd 0x70(%rsp), %xmm4
movapd %xmm4, %xmm1
addsd %xmm0, %xmm1
addsd %xmm0, %xmm0
subsd %xmm0, %xmm4
movapd 0xb0(%rsp), %xmm5
ucomisd %xmm1, %xmm5
movapd %xmm3, %xmm0
cmpltpd %xmm4, %xmm0
movapd %xmm4, %xmm2
cmpltpd %xmm5, %xmm2
orpd %xmm0, %xmm2
movd %xmm2, %ecx
ja 0xa235
ucomisd %xmm3, %xmm1
ja 0xa235
movb $0x1, %al
testb $0x1, %cl
movapd 0x90(%rsp), %xmm6
je 0xa418
movapd %xmm1, %xmm4
jmp 0xa44d
movb $0x1, %al
testb $0x1, %cl
movapd (%rsp), %xmm3
movsd 0xe299(%rip), %xmm5     # 0x184e0
movapd 0x90(%rsp), %xmm6
je 0xa45a
movabsq $-0x3fde000000000000, %rax # imm = 0xC022000000000000
movq 0x48(%rsp), %rcx
movq %rax, (%rcx)
movq %rax, (%rbx)
xorpd %xmm4, %xmm4
xorl %eax, %eax
jmp 0xa45a
movapd %xmm10, 0x60(%rsp)
callq 0x4220
movapd 0x60(%rsp), %xmm10
divsd %xmm0, %xmm10
movapd %xmm10, %xmm0
callq 0x4280
divsd 0xe280(%rip), %xmm0     # 0x18520
movsd %xmm0, 0x30(%rsp)
movsd 0x50(%rsp), %xmm0
ucomisd 0xe294(%rip), %xmm0     # 0x18548
jb 0xa2bc
sqrtsd %xmm0, %xmm0
jmp 0xa2c1
callq 0x4220
addsd %xmm0, %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x30(%rsp), %xmm0
callq 0x4520
mulsd 0x60(%rsp), %xmm0
addsd 0x70(%rsp), %xmm0
movapd %xmm0, 0x50(%rsp)
movsd 0xe238(%rip), %xmm0     # 0x18528
addsd 0x30(%rsp), %xmm0
callq 0x4520
mulsd 0x60(%rsp), %xmm0
addsd 0x70(%rsp), %xmm0
movapd %xmm0, 0xa0(%rsp)
movsd 0x30(%rsp), %xmm0
addsd 0xe212(%rip), %xmm0     # 0x18530
callq 0x4520
movapd 0xa0(%rsp), %xmm8
movapd 0x50(%rsp), %xmm7
mulsd 0x60(%rsp), %xmm0
addsd 0x70(%rsp), %xmm0
movapd 0xb0(%rsp), %xmm4
ucomisd %xmm7, %xmm4
movapd 0x80(%rsp), %xmm3
movapd %xmm3, %xmm1
cmpltpd %xmm8, %xmm1
movapd %xmm8, %xmm2
cmpltpd %xmm4, %xmm2
orpd %xmm1, %xmm2
movd %xmm2, %eax
movapd %xmm3, %xmm1
cmpltpd %xmm0, %xmm1
movapd %xmm0, %xmm2
cmpltpd %xmm4, %xmm2
orpd %xmm1, %xmm2
movd %xmm2, %ecx
ja 0xa3c0
ucomisd %xmm3, %xmm7
ja 0xa3c0
testb $0x1, %al
movsd 0xe143(%rip), %xmm5     # 0x184e0
movapd 0x90(%rsp), %xmm6
je 0xa463
movb $0x1, %al
testb $0x1, %cl
je 0xa51a
movapd %xmm7, %xmm0
jmp 0xa54f
testb $0x1, %al
movapd (%rsp), %xmm3
movsd 0xe111(%rip), %xmm5     # 0x184e0
movapd 0x90(%rsp), %xmm6
movb $0x1, %al
je 0xa405
testb $0x1, %cl
je 0xa554
movabsq $-0x3fde000000000000, %rax # imm = 0xC022000000000000
movq 0x48(%rsp), %rcx
movq %rax, (%rcx)
movq %rax, (%rbx)
xorpd %xmm0, %xmm0
xorl %eax, %eax
jmp 0xa554
testb $0x1, %cl
je 0xa4d8
movapd %xmm8, %xmm0
jmp 0xa554
movapd %xmm1, %xmm0
subsd %xmm6, %xmm0
movapd 0xe098(%rip), %xmm2     # 0x184c0
andpd %xmm2, %xmm0
movapd %xmm4, %xmm3
subsd %xmm6, %xmm3
andpd %xmm2, %xmm3
cmplesd %xmm3, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm4, %xmm0
orpd %xmm1, %xmm0
movapd %xmm0, %xmm4
movapd (%rsp), %xmm3
movsd 0xe086(%rip), %xmm5     # 0x184e0
movapd %xmm4, %xmm0
jmp 0xa554
movapd %xmm8, %xmm1
subsd %xmm6, %xmm1
movapd 0xe04c(%rip), %xmm2     # 0x184c0
andpd %xmm2, %xmm1
movapd %xmm7, %xmm3
subsd %xmm6, %xmm3
andpd %xmm2, %xmm3
cmplesd %xmm3, %xmm1
movapd %xmm1, %xmm3
andpd %xmm8, %xmm3
andnpd %xmm7, %xmm1
orpd %xmm3, %xmm1
movb $0x1, %al
testb $0x1, %cl
jne 0xa54b
movapd %xmm1, %xmm3
subsd %xmm6, %xmm3
andpd %xmm2, %xmm3
movapd %xmm0, %xmm4
subsd %xmm6, %xmm4
andpd %xmm2, %xmm4
cmplesd %xmm4, %xmm3
movapd %xmm3, %xmm2
andpd %xmm1, %xmm2
andnpd %xmm0, %xmm3
orpd %xmm2, %xmm3
movapd %xmm3, %xmm0
jmp 0xa54f
movapd %xmm8, %xmm1
subsd %xmm6, %xmm1
movapd 0xdfd7(%rip), %xmm2     # 0x184c0
andpd %xmm2, %xmm1
movapd %xmm0, %xmm3
subsd %xmm6, %xmm3
andpd %xmm2, %xmm3
cmplesd %xmm3, %xmm1
movapd (%rsp), %xmm3
movapd %xmm1, %xmm2
andpd %xmm8, %xmm2
andnpd %xmm0, %xmm1
orpd %xmm2, %xmm1
movapd %xmm1, %xmm0
jmp 0xa554
movapd %xmm7, %xmm1
subsd %xmm6, %xmm1
movapd 0xdf96(%rip), %xmm2     # 0x184c0
andpd %xmm2, %xmm1
movapd %xmm0, %xmm3
subsd %xmm6, %xmm3
andpd %xmm2, %xmm3
cmplesd %xmm3, %xmm1
andpd %xmm1, %xmm7
andnpd %xmm0, %xmm1
orpd %xmm7, %xmm1
movapd %xmm1, %xmm0
movapd (%rsp), %xmm3
testb %al, %al
je 0x9926
subsd %xmm6, %xmm0
movapd %xmm5, %xmm1
subsd 0x20(%rsp), %xmm1
subsd %xmm3, %xmm5
movapd %xmm5, %xmm2
mulsd %xmm1, %xmm2
movapd %xmm0, %xmm3
mulsd %xmm0, %xmm3
movapd %xmm6, %xmm4
mulsd %xmm2, %xmm4
divsd %xmm4, %xmm3
movq 0x48(%rsp), %rax
movsd %xmm3, (%rax)
movsd 0xdf9d(%rip), %xmm3     # 0x18538
ucomisd %xmm0, %xmm3
jbe 0xa5c0
movapd %xmm6, %xmm1
cmplesd %xmm2, %xmm1
andpd %xmm1, %xmm6
andnpd %xmm2, %xmm1
orpd %xmm6, %xmm1
xorpd 0xdf12(%rip), %xmm1     # 0x184d0
jmp 0xa5fa
xorpd %xmm2, %xmm2
ucomisd 0xdf74(%rip), %xmm0     # 0x18540
jbe 0x9922
movapd 0x20(%rsp), %xmm2
mulsd %xmm5, %xmm2
movapd (%rsp), %xmm3
mulsd %xmm1, %xmm3
movapd %xmm2, %xmm1
cmplesd %xmm3, %xmm1
andpd %xmm1, %xmm2
andnpd %xmm3, %xmm1
orpd %xmm2, %xmm1
divsd %xmm1, %xmm0
movapd %xmm0, %xmm2
jmp 0x9922
nop