// File: tplinderoth[P]introDist/introDist.cpp
// Function: comp2DistIndAvg(std::basic_fstream<char, std::char_traits<char>>&, std::basic_fstream<char, std::char_traits<char>>&, unsigned int, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, double const*)
int comp2DistIndAvg (std::fstream &freqfile, std::fstream &genofile, unsigned int window, unsigned int step, std::string* genofname, const double* distance) {

	/*
	 * this calculates the difference in the genetic distance between individual i and population2 in a region and
	 * the genome-wide average distance between individual i and population2
	 *
	 * D = d_R(i, P2) - d_G(i, P2)
	 * subscript G denotes average over the genome
	 * subscript R denotes average across region
	 *
	 * at site s:
	 * expected distance between individual i and population 2: E[d(i, P2)] = |g_i - E[g_p2]|/2
	 *
	 * d_G(i, P2) = 1/N_G * sum_from=1_to=N_G |g_i - E[g_p2]|/2, where N_G is total number of sites analyzed
	 *
	 * d_R(i, P2) = 1/N_R * sum_from=1_to=N_R |g_i - E[g_p2]|/2, where N_R is the number of sites in the window
	 *
	 * assumes individual i is from population 1
	 *
	 */

	std::vector<sitedist> dist;
	dist.resize(window);
	std::vector<sitedist>::iterator distiter = dist.begin();
	unsigned int lastidx = window-1;
	unsigned int nsites = 0;
	unsigned int dr_nsites = 0;
	double windD = 0.0;
	unsigned int i = 0;
	unsigned int n = window-step;
	double dg = 0.0;
	unsigned int dg_nsites = 0;

	std::stringstream ss;

	std::string(fline);
	std::string(fchr);
	unsigned int fpos;
	double p1f;
	double p2f;

	std::string(gline);
	std::string(gchr);
	unsigned int gpos;
	int geno;

	getline(freqfile, fline);
	getline(genofile, gline);

	// estimate number of lines of input files to set up vector to hold distances
	ss.str(gline);
	ss >> gchr;
	unsigned int nlines = ceil(filesize(genofname->c_str())/(gchr.size()+2*sizeof(int)-1));
	std::vector<WindowInfo> windist;
	windist.reserve(nlines/step + 10);

	// calculate windows
	while (!fline.empty()) {

		// parse frequency file lines
		ss.str(std::string());
		ss.clear();
		ss.str(fline);
		ss >> fchr >> fpos >> p1f >> p2f;

		// parse genotype file lines
		ss.str(std::string());
		ss.clear();
		ss.str(gline);
		ss >> gchr >> gpos >> geno;

		// ensure that files are synched
		if (gchr.compare(fchr) != 0 || gpos != fpos) {
			std::cerr << "Positions in input files differ\n";
			return -1;
		}

		distiter->first = gpos;
		if (geno < 0) {
			// missing data
			distiter->second = -3.0;
		} else {
			// update window information
			distiter->second = expectIndPopDist(geno, p2f);
			// update genome-wide distance
			dg += distiter->second;
			++dg_nsites;
		}
		++distiter;
		++nsites;

		if (distiter == dist.end()) {

			// calculate window value
			windD = 0.0;
			dr_nsites = 0;
			for (distiter = dist.begin(); distiter != dist.end(); ++distiter) {
				if (distiter->second < -2.0) continue;
				windD += distiter->second;
				++dr_nsites;
			}
			if (dr_nsites > 0) {
				windD /= (double)dr_nsites;
			} else {
				std::cerr << "Warning: window " << gchr << " " << dist[0].first << "," << dist[lastidx].first << " has no sites with data\n";
			}
			windist.push_back(makeWinInfo(dist[0].first, dist[lastidx].first, dr_nsites, windD));

			// prepare vector for new values
			for (i = 0; i < n; ++i) {
				dist[i].first = dist[step+i].first;
				dist[i].second = dist[step+i].second;
			}

			nsites = n;
			distiter = dist.begin() + n;
		}

		getline(freqfile, fline);
		getline(genofile, gline);
	}

	// calculate last window
	if (nsites > n && nsites < window) {
		unsigned int lastwinidx = nsites-1;
		dr_nsites = 0;
		windD = 0.0;
		for (i=0; i < lastwinidx; ++i) {
			if (dist[i].second < -2.0) continue;
			windD += dist[i].second;
			++dr_nsites;
		}
		if (dr_nsites > 0) {
			windD /= (double)dr_nsites;
		} else {
			std::cerr << "Warning: window " << gchr << " " << dist[0].first << "," << dist[lastwinidx].first << " has no sites with data\n";
		}
		windist.push_back(makeWinInfo(dist[0].first, dist[lastwinidx].first, dr_nsites, windD));
	}

	// calculate and print distance statistic
	if (dg_nsites > 0) {
		dg /= (double)dg_nsites;
	} else {
		std::cerr << "There were no sites with complete data, cannot calculate distance statistic\n";
		return 0; // use better exception handling here
	}
	std::cerr << "\nCalculated genome-wide, average distance between individual and population2: " << dg << "\n";

	if (distance) {
		// use provided distance
		dg = *distance;
		std::cerr << "\nUsing distance: " << dg <<  "\n";
	}
	std::cerr << "\n";

	unsigned int midpoint = 0;
	double Dstat = 0.0;
	for (std::vector<WindowInfo>::iterator winditer = windist.begin(); winditer != windist.end(); ++winditer) {
		Dstat = winditer->d - dg;
		midpoint = (winditer->start + winditer->stop)/2;
		std::cout << gchr << "\t" << winditer->start << "\t" << winditer->stop << "\t" << midpoint << "\t" << Dstat << "\t" << winditer->nsites << "\n";
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x550, %rsp            # imm = 0x550
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
leaq -0x48(%rbp), %rdi
movq %rdi, -0x3b8(%rbp)
callq 0x9240
movq -0x3b8(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x9260
jmp 0x7ed4
leaq -0x48(%rbp), %rdi
callq 0x92f0
movq %rax, -0x60(%rbp)
movl -0x1c(%rbp), %eax
decl %eax
movl %eax, -0x64(%rbp)
movl $0x0, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movq $0x0, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movl -0x1c(%rbp), %eax
movl -0x20(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movl $0x0, -0x8c(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x31f0
jmp 0x7f34
leaq -0x238(%rbp), %rdi
movq %rdi, -0x3c0(%rbp)
callq 0x33d0
leaq -0x258(%rbp), %rdi
callq 0x33d0
leaq -0x290(%rbp), %rdi
callq 0x33d0
leaq -0x2b0(%rbp), %rdi
callq 0x33d0
movq -0x3c0(%rbp), %rsi
movq -0x10(%rbp), %rdi
callq 0x30b0
jmp 0x7f7d
movq -0x18(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x30b0
jmp 0x7f8f
leaq -0x218(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x3340
jmp 0x7fa4
leaq -0x218(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
callq 0x33a0
jmp 0x7fb9
movq -0x28(%rbp), %rdi
callq 0x3140
movq %rax, %rdi
callq 0xd000
movq %rdx, -0x3d0(%rbp)
movq %rax, -0x3c8(%rbp)
jmp 0x7fda
movq -0x3d0(%rbp), %rax
movq -0x3c8(%rbp), %rcx
movq %rcx, -0x2d0(%rbp)
movq %rax, -0x2c8(%rbp)
leaq -0x2d0(%rbp), %rdi
callq 0x9320
movq %rax, -0x3d8(%rbp)
jmp 0x800b
leaq -0x2b0(%rbp), %rdi
callq 0x31e0
movq %rax, %rcx
movq -0x3d8(%rbp), %rax
addq $0x7, %rcx
xorl %edx, %edx
movl %edx, -0x3e4(%rbp)
divq %rcx
movq %rax, %xmm0
movaps 0x7014(%rip), %xmm1     # 0xf050
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x7018(%rip), %xmm1     # 0xf060
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
callq 0x3090
cvttsd2si %xmm0, %rax
movl %eax, -0x2bc(%rbp)
leaq -0x2e8(%rbp), %rdi
movq %rdi, -0x3e0(%rbp)
callq 0x9340
movl -0x3e4(%rbp), %edx
movq -0x3e0(%rbp), %rdi
movl -0x2bc(%rbp), %eax
movl -0x20(%rbp), %ecx
divl %ecx
addl $0xa, %eax
movl %eax, %esi
callq 0x9360
jmp 0x809e
jmp 0x80a0
leaq -0x238(%rbp), %rdi
callq 0x3470
xorb $-0x1, %al
testb $0x1, %al
jne 0x80b7
jmp 0x86b1
leaq -0x308(%rbp), %rdi
movq %rdi, -0x3f0(%rbp)
callq 0x33d0
movq -0x3f0(%rbp), %rsi
leaq -0x218(%rbp), %rdi
callq 0x3340
jmp 0x80df
leaq -0x308(%rbp), %rdi
callq 0x31b0
movq -0x218(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x218(%rbp,%rax), %rdi
xorl %esi, %esi
callq 0x3480
jmp 0x8107
leaq -0x218(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x3340
jmp 0x811c
leaq -0x218(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x33a0
movq %rax, -0x3f8(%rbp)
jmp 0x8138
movq -0x3f8(%rbp), %rdi
leaq -0x25c(%rbp), %rsi
callq 0x3060
movq %rax, -0x400(%rbp)
jmp 0x8154
movq -0x400(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x3250
movq %rax, -0x408(%rbp)
jmp 0x8170
movq -0x408(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x3250
jmp 0x8185
leaq -0x328(%rbp), %rdi
movq %rdi, -0x410(%rbp)
callq 0x33d0
movq -0x410(%rbp), %rsi
leaq -0x218(%rbp), %rdi
callq 0x3340
jmp 0x81ad
leaq -0x328(%rbp), %rdi
callq 0x31b0
movq -0x218(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x218(%rbp,%rax), %rdi
xorl %esi, %esi
callq 0x3480
jmp 0x81d5
leaq -0x218(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x3340
jmp 0x81ea
leaq -0x218(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
callq 0x33a0
movq %rax, -0x418(%rbp)
jmp 0x8206
movq -0x418(%rbp), %rdi
leaq -0x2b4(%rbp), %rsi
callq 0x3060
movq %rax, -0x420(%rbp)
jmp 0x8222
movq -0x420(%rbp), %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x31a0
jmp 0x8237
leaq -0x2b0(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x3040
movl %eax, -0x424(%rbp)
jmp 0x8252
movl -0x424(%rbp), %eax
cmpl $0x0, %eax
jne 0x826f
movl -0x2b4(%rbp), %eax
cmpl -0x25c(%rbp), %eax
je 0x8307
movq 0xcd7a(%rip), %rdi      # 0x14ff0
leaq 0x7114(%rip), %rsi      # 0xf391
callq 0x32c0
jmp 0x8284
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x32c(%rbp)
jmp 0x8bfb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x8ca0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x8c64
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x8c58
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x308(%rbp), %rdi
callq 0x31b0
jmp 0x8c58
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x328(%rbp), %rdi
callq 0x31b0
jmp 0x8c58
movl -0x2b4(%rbp), %eax
movl %eax, -0x428(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x9460
movl -0x428(%rbp), %ecx
movl %ecx, (%rax)
cmpl $0x0, -0x2b8(%rbp)
jge 0x8345
leaq -0x60(%rbp), %rdi
callq 0x9460
movsd 0x6cea(%rip), %xmm0     # 0xf028
movsd %xmm0, 0x8(%rax)
jmp 0x83a7
cvtsi2sdl -0x2b8(%rbp), %xmm0
movsd -0x270(%rbp), %xmm1
callq 0x63d0
movsd %xmm0, -0x430(%rbp)
jmp 0x8364
leaq -0x60(%rbp), %rdi
callq 0x9460
movsd -0x430(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
leaq -0x60(%rbp), %rdi
callq 0x9460
movsd 0x8(%rax), %xmm0
addsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x9480
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x94e0
movq %rax, -0x338(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x338(%rbp), %rsi
callq 0x94a0
testb $0x1, %al
jne 0x83e2
jmp 0x8688
xorps %xmm0, %xmm0
movsd %xmm0, -0x78(%rbp)
movl $0x0, -0x6c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x92f0
movq %rax, -0x340(%rbp)
movq -0x340(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x94e0
movq %rax, -0x348(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x348(%rbp), %rsi
callq 0x9510
testb $0x1, %al
jne 0x8432
jmp 0x8478
leaq -0x60(%rbp), %rdi
callq 0x9460
movsd 0x6bdd(%rip), %xmm0     # 0xf020
ucomisd 0x8(%rax), %xmm0
jbe 0x844c
jmp 0x846d
leaq -0x60(%rbp), %rdi
callq 0x9460
movsd 0x8(%rax), %xmm0
addsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x9480
jmp 0x840c
cmpl $0x0, -0x6c(%rbp)
jbe 0x8499
movl -0x6c(%rbp), %eax
cvtsi2sd %rax, %xmm1
movsd -0x78(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
jmp 0x8569
movq 0xcb50(%rip), %rdi      # 0x14ff0
leaq 0x6fe4(%rip), %rsi      # 0xf48b
callq 0x32c0
movq %rax, -0x438(%rbp)
jmp 0x84b5
movq -0x438(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
callq 0x3280
movq %rax, -0x440(%rbp)
jmp 0x84d1
movq -0x440(%rbp), %rdi
leaq 0x7752(%rip), %rsi      # 0xfc31
callq 0x32c0
movq %rax, -0x448(%rbp)
jmp 0x84ed
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x9550
movq -0x448(%rbp), %rdi
movl (%rax), %esi
callq 0x33b0
movq %rax, -0x450(%rbp)
jmp 0x8511
movq -0x450(%rbp), %rdi
leaq 0x6f7d(%rip), %rsi      # 0xf49c
callq 0x32c0
movq %rax, -0x458(%rbp)
jmp 0x852d
movl -0x64(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x9550
movq -0x458(%rbp), %rdi
movl (%rax), %esi
callq 0x33b0
movq %rax, -0x460(%rbp)
jmp 0x8552
movq -0x460(%rbp), %rdi
leaq 0x6f3e(%rip), %rsi      # 0xf49e
callq 0x32c0
jmp 0x8567
jmp 0x8569
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
movq %rdi, -0x470(%rbp)
callq 0x9550
movq -0x470(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x464(%rbp)
movl -0x64(%rbp), %eax
movl %eax, %esi
callq 0x9550
movl -0x464(%rbp), %esi
movl (%rax), %edx
movl -0x6c(%rbp), %ecx
movsd -0x78(%rbp), %xmm0
leaq -0x360(%rbp), %rdi
callq 0x8cc0
jmp 0x85b4
leaq -0x2e8(%rbp), %rdi
leaq -0x360(%rbp), %rsi
callq 0x9570
jmp 0x85c9
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x80(%rbp), %eax
jae 0x864f
movl -0x20(%rbp), %eax
addl -0x7c(%rbp), %eax
movl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x9550
movl (%rax), %eax
movl %eax, -0x47c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x9550
movl -0x47c(%rbp), %ecx
movl %ecx, (%rax)
movl -0x20(%rbp), %eax
addl -0x7c(%rbp), %eax
movl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x9550
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x478(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x9550
movsd -0x478(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x85d0
movl -0x80(%rbp), %eax
movl %eax, -0x68(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x92f0
movq %rax, -0x370(%rbp)
movl -0x80(%rbp), %eax
movl %eax, %esi
leaq -0x370(%rbp), %rdi
callq 0x95a0
movq %rax, -0x368(%rbp)
movq -0x368(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x30b0
jmp 0x869a
movq -0x18(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x30b0
jmp 0x86ac
jmp 0x80a0
movl -0x68(%rbp), %eax
cmpl -0x80(%rbp), %eax
jbe 0x889f
movl -0x68(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x889f
movl -0x68(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x374(%rbp)
movl $0x0, -0x6c(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x374(%rbp), %eax
jae 0x8746
movl -0x7c(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x9550
movsd 0x6914(%rip), %xmm0     # 0xf020
ucomisd 0x8(%rax), %xmm0
jbe 0x8715
jmp 0x873b
movl -0x7c(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x9550
movsd 0x8(%rax), %xmm0
addsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x86eb
cmpl $0x0, -0x6c(%rbp)
jbe 0x8767
movl -0x6c(%rbp), %eax
cvtsi2sd %rax, %xmm1
movsd -0x78(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
jmp 0x883a
movq 0xc882(%rip), %rdi      # 0x14ff0
leaq 0x6d16(%rip), %rsi      # 0xf48b
callq 0x32c0
movq %rax, -0x488(%rbp)
jmp 0x8783
movq -0x488(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
callq 0x3280
movq %rax, -0x490(%rbp)
jmp 0x879f
movq -0x490(%rbp), %rdi
leaq 0x7484(%rip), %rsi      # 0xfc31
callq 0x32c0
movq %rax, -0x498(%rbp)
jmp 0x87bb
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x9550
movq -0x498(%rbp), %rdi
movl (%rax), %esi
callq 0x33b0
movq %rax, -0x4a0(%rbp)
jmp 0x87df
movq -0x4a0(%rbp), %rdi
leaq 0x6caf(%rip), %rsi      # 0xf49c
callq 0x32c0
movq %rax, -0x4a8(%rbp)
jmp 0x87fb
movl -0x374(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x9550
movq -0x4a8(%rbp), %rdi
movl (%rax), %esi
callq 0x33b0
movq %rax, -0x4b0(%rbp)
jmp 0x8823
movq -0x4b0(%rbp), %rdi
leaq 0x6c6d(%rip), %rsi      # 0xf49e
callq 0x32c0
jmp 0x8838
jmp 0x883a
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
movq %rdi, -0x4c0(%rbp)
callq 0x9550
movq -0x4c0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x4b4(%rbp)
movl -0x374(%rbp), %eax
movl %eax, %esi
callq 0x9550
movl -0x4b4(%rbp), %esi
movl (%rax), %edx
movl -0x6c(%rbp), %ecx
movsd -0x78(%rbp), %xmm0
leaq -0x390(%rbp), %rdi
callq 0x8cc0
jmp 0x8888
leaq -0x2e8(%rbp), %rdi
leaq -0x390(%rbp), %rsi
callq 0x9570
jmp 0x889d
jmp 0x889f
cmpl $0x0, -0x8c(%rbp)
jbe 0x88c9
movl -0x8c(%rbp), %eax
cvtsi2sd %rax, %xmm1
movsd -0x88(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
jmp 0x88f4
movq 0xc720(%rip), %rdi      # 0x14ff0
leaq 0x6be0(%rip), %rsi      # 0xf4b7
callq 0x32c0
jmp 0x88de
movl $0x0, -0x4(%rbp)
movl $0x1, -0x32c(%rbp)
jmp 0x8bfb
movq 0xc6f5(%rip), %rdi      # 0x14ff0
leaq 0x6c47(%rip), %rsi      # 0xf549
callq 0x32c0
movq %rax, -0x4c8(%rbp)
jmp 0x8910
movq -0x4c8(%rbp), %rdi
movsd -0x88(%rbp), %xmm0
callq 0x3530
movq %rax, -0x4d0(%rbp)
jmp 0x892d
movq -0x4d0(%rbp), %rdi
leaq 0x72b1(%rip), %rsi      # 0xfbec
callq 0x32c0
jmp 0x8942
cmpq $0x0, -0x30(%rbp)
je 0x89a9
movq -0x30(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x88(%rbp)
movq 0xc690(%rip), %rdi      # 0x14ff0
leaq 0x6bd0(%rip), %rsi      # 0xf537
callq 0x32c0
movq %rax, -0x4d8(%rbp)
jmp 0x8975
movq -0x4d8(%rbp), %rdi
movsd -0x88(%rbp), %xmm0
callq 0x3530
movq %rax, -0x4e0(%rbp)
jmp 0x8992
movq -0x4e0(%rbp), %rdi
leaq 0x724c(%rip), %rsi      # 0xfbec
callq 0x32c0
jmp 0x89a7
jmp 0x89a9
movq 0xc640(%rip), %rdi      # 0x14ff0
leaq 0x7235(%rip), %rsi      # 0xfbec
callq 0x32c0
jmp 0x89be
movl $0x0, -0x394(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x3a0(%rbp)
leaq -0x2e8(%rbp), %rdi
callq 0x95e0
movq %rax, -0x3a8(%rbp)
leaq -0x2e8(%rbp), %rdi
callq 0x9650
movq %rax, -0x3b0(%rbp)
leaq -0x3a8(%rbp), %rdi
leaq -0x3b0(%rbp), %rsi
callq 0x9610
testb $0x1, %al
jne 0x8a15
jmp 0x8bea
leaq -0x3a8(%rbp), %rdi
movq %rdi, -0x4f8(%rbp)
callq 0x9680
movq -0x4f8(%rbp), %rdi
movsd 0x10(%rax), %xmm0
movsd -0x88(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x3a0(%rbp)
callq 0x9680
movq -0x4f8(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x4ec(%rbp)
callq 0x9680
movq %rax, %rcx
movl -0x4ec(%rbp), %eax
movl 0x4(%rcx), %ecx
addl %ecx, %eax
shrl %eax
movl %eax, -0x394(%rbp)
movq 0xc54a(%rip), %rdi      # 0x14fc8
leaq -0x2b0(%rbp), %rsi
callq 0x3280
movq %rax, -0x4e8(%rbp)
jmp 0x8a93
movq -0x4e8(%rbp), %rdi
leaq 0x6882(%rip), %rsi      # 0xf323
callq 0x32c0
movq %rax, -0x500(%rbp)
jmp 0x8aaf
leaq -0x3a8(%rbp), %rdi
callq 0x9680
movq -0x500(%rbp), %rdi
movl (%rax), %esi
callq 0x33b0
movq %rax, -0x508(%rbp)
jmp 0x8ad2
movq -0x508(%rbp), %rdi
leaq 0x6843(%rip), %rsi      # 0xf323
callq 0x32c0
movq %rax, -0x510(%rbp)
jmp 0x8aee
leaq -0x3a8(%rbp), %rdi
callq 0x9680
movq -0x510(%rbp), %rdi
movl 0x4(%rax), %esi
callq 0x33b0
movq %rax, -0x518(%rbp)
jmp 0x8b12
movq -0x518(%rbp), %rdi
leaq 0x6803(%rip), %rsi      # 0xf323
callq 0x32c0
movq %rax, -0x520(%rbp)
jmp 0x8b2e
movq -0x520(%rbp), %rdi
movl -0x394(%rbp), %esi
callq 0x33b0
movq %rax, -0x528(%rbp)
jmp 0x8b49
movq -0x528(%rbp), %rdi
leaq 0x67cc(%rip), %rsi      # 0xf323
callq 0x32c0
movq %rax, -0x530(%rbp)
jmp 0x8b65
movq -0x530(%rbp), %rdi
movsd -0x3a0(%rbp), %xmm0
callq 0x3530
movq %rax, -0x538(%rbp)
jmp 0x8b82
movq -0x538(%rbp), %rdi
leaq 0x6793(%rip), %rsi      # 0xf323
callq 0x32c0
movq %rax, -0x540(%rbp)
jmp 0x8b9e
leaq -0x3a8(%rbp), %rdi
callq 0x9680
movq -0x540(%rbp), %rdi
movl 0x8(%rax), %esi
callq 0x33b0
movq %rax, -0x548(%rbp)
jmp 0x8bc2
movq -0x548(%rbp), %rdi
leaq 0x701c(%rip), %rsi      # 0xfbec
callq 0x32c0
jmp 0x8bd7
jmp 0x8bd9
leaq -0x3a8(%rbp), %rdi
callq 0x96a0
jmp 0x89e6
movl $0x0, -0x4(%rbp)
movl $0x1, -0x32c(%rbp)
leaq -0x2e8(%rbp), %rdi
callq 0x96c0
leaq -0x2b0(%rbp), %rdi
callq 0x31b0
leaq -0x290(%rbp), %rdi
callq 0x31b0
leaq -0x258(%rbp), %rdi
callq 0x31b0
leaq -0x238(%rbp), %rdi
callq 0x31b0
leaq -0x218(%rbp), %rdi
callq 0x3210
leaq -0x48(%rbp), %rdi
callq 0x9720
movl -0x4(%rbp), %eax
addq $0x550, %rsp            # imm = 0x550
popq %rbp
retq
leaq -0x2e8(%rbp), %rdi
callq 0x96c0
leaq -0x2b0(%rbp), %rdi
callq 0x31b0
leaq -0x290(%rbp), %rdi
callq 0x31b0
leaq -0x258(%rbp), %rdi
callq 0x31b0
leaq -0x238(%rbp), %rdi
callq 0x31b0
leaq -0x218(%rbp), %rdi
callq 0x3210
leaq -0x48(%rbp), %rdi
callq 0x9720
movq -0x50(%rbp), %rdi
callq 0x34c0
nopw %cs:(%rax,%rax)