// File: tplinderoth[P]introDist/introDist.cpp
// Function: comp2DistPopAvg(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 comp2DistPopAvg (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 expected distance between individual i's population and population2 averaged across the genome
	 *
	 * D = d_R(i, P2) - d_G(Pi, 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
	 * expected difference between the distance of individuals i's population and population 2: d(Pi, P2) = |E[g_p1] - E[g_p2]|/2
	 *
	 * d_G(Pi, P2) = 1/N_G * sum_from=1_to=N_G |E[g_p1] - 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 += expect2PopDist(p1f, p2f);
			++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 average distance between populations: " << 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 0x7094
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 0x70f4
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 0x713d
movq -0x18(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x30b0
jmp 0x714f
leaq -0x218(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x3340
jmp 0x7164
leaq -0x218(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
callq 0x33a0
jmp 0x7179
movq -0x28(%rbp), %rdi
callq 0x3140
movq %rax, %rdi
callq 0xd000
movq %rdx, -0x3d0(%rbp)
movq %rax, -0x3c8(%rbp)
jmp 0x719a
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 0x71cb
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 0x7e54(%rip), %xmm1     # 0xf050
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x7e58(%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 0x725e
jmp 0x7260
leaq -0x238(%rbp), %rdi
callq 0x3470
xorb $-0x1, %al
testb $0x1, %al
jne 0x7277
jmp 0x788a
leaq -0x308(%rbp), %rdi
movq %rdi, -0x3f0(%rbp)
callq 0x33d0
movq -0x3f0(%rbp), %rsi
leaq -0x218(%rbp), %rdi
callq 0x3340
jmp 0x729f
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 0x72c7
leaq -0x218(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x3340
jmp 0x72dc
leaq -0x218(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x33a0
movq %rax, -0x3f8(%rbp)
jmp 0x72f8
movq -0x3f8(%rbp), %rdi
leaq -0x25c(%rbp), %rsi
callq 0x3060
movq %rax, -0x400(%rbp)
jmp 0x7314
movq -0x400(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x3250
movq %rax, -0x408(%rbp)
jmp 0x7330
movq -0x408(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x3250
jmp 0x7345
leaq -0x328(%rbp), %rdi
movq %rdi, -0x410(%rbp)
callq 0x33d0
movq -0x410(%rbp), %rsi
leaq -0x218(%rbp), %rdi
callq 0x3340
jmp 0x736d
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 0x7395
leaq -0x218(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x3340
jmp 0x73aa
leaq -0x218(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
callq 0x33a0
movq %rax, -0x418(%rbp)
jmp 0x73c6
movq -0x418(%rbp), %rdi
leaq -0x2b4(%rbp), %rsi
callq 0x3060
movq %rax, -0x420(%rbp)
jmp 0x73e2
movq -0x420(%rbp), %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x31a0
jmp 0x73f7
leaq -0x2b0(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x3040
movl %eax, -0x424(%rbp)
jmp 0x7412
movl -0x424(%rbp), %eax
cmpl $0x0, %eax
jne 0x742f
movl -0x2b4(%rbp), %eax
cmpl -0x25c(%rbp), %eax
je 0x74c7
movq 0xdbba(%rip), %rdi      # 0x14ff0
leaq 0x7f54(%rip), %rsi      # 0xf391
callq 0x32c0
jmp 0x7444
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x32c(%rbp)
jmp 0x7dd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x7e79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x7e3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x7e31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x308(%rbp), %rdi
callq 0x31b0
jmp 0x7e31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x328(%rbp), %rdi
callq 0x31b0
jmp 0x7e31
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 0x7505
leaq -0x60(%rbp), %rdi
callq 0x9460
movsd 0x7b2a(%rip), %xmm0     # 0xf028
movsd %xmm0, 0x8(%rax)
jmp 0x7580
cvtsi2sdl -0x2b8(%rbp), %xmm0
movsd -0x270(%rbp), %xmm1
callq 0x63d0
movsd %xmm0, -0x430(%rbp)
jmp 0x7524
leaq -0x60(%rbp), %rdi
callq 0x9460
movsd -0x430(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
movsd -0x268(%rbp), %xmm0
movsd -0x270(%rbp), %xmm1
callq 0x6320
movsd %xmm0, -0x438(%rbp)
jmp 0x7559
movsd -0x438(%rbp), %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 0x75bb
jmp 0x7861
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 0x760b
jmp 0x7651
leaq -0x60(%rbp), %rdi
callq 0x9460
movsd 0x7a04(%rip), %xmm0     # 0xf020
ucomisd 0x8(%rax), %xmm0
jbe 0x7625
jmp 0x7646
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 0x75e5
cmpl $0x0, -0x6c(%rbp)
jbe 0x7672
movl -0x6c(%rbp), %eax
cvtsi2sd %rax, %xmm1
movsd -0x78(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
jmp 0x7742
movq 0xd977(%rip), %rdi      # 0x14ff0
leaq 0x7e0b(%rip), %rsi      # 0xf48b
callq 0x32c0
movq %rax, -0x440(%rbp)
jmp 0x768e
movq -0x440(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
callq 0x3280
movq %rax, -0x448(%rbp)
jmp 0x76aa
movq -0x448(%rbp), %rdi
leaq 0x8579(%rip), %rsi      # 0xfc31
callq 0x32c0
movq %rax, -0x450(%rbp)
jmp 0x76c6
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x9550
movq -0x450(%rbp), %rdi
movl (%rax), %esi
callq 0x33b0
movq %rax, -0x458(%rbp)
jmp 0x76ea
movq -0x458(%rbp), %rdi
leaq 0x7da4(%rip), %rsi      # 0xf49c
callq 0x32c0
movq %rax, -0x460(%rbp)
jmp 0x7706
movl -0x64(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x9550
movq -0x460(%rbp), %rdi
movl (%rax), %esi
callq 0x33b0
movq %rax, -0x468(%rbp)
jmp 0x772b
movq -0x468(%rbp), %rdi
leaq 0x7d65(%rip), %rsi      # 0xf49e
callq 0x32c0
jmp 0x7740
jmp 0x7742
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
movq %rdi, -0x478(%rbp)
callq 0x9550
movq -0x478(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x46c(%rbp)
movl -0x64(%rbp), %eax
movl %eax, %esi
callq 0x9550
movl -0x46c(%rbp), %esi
movl (%rax), %edx
movl -0x6c(%rbp), %ecx
movsd -0x78(%rbp), %xmm0
leaq -0x360(%rbp), %rdi
callq 0x8cc0
jmp 0x778d
leaq -0x2e8(%rbp), %rdi
leaq -0x360(%rbp), %rsi
callq 0x9570
jmp 0x77a2
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x80(%rbp), %eax
jae 0x7828
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, -0x484(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x9550
movl -0x484(%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, -0x480(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x9550
movsd -0x480(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x77a9
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 0x7873
movq -0x18(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x30b0
jmp 0x7885
jmp 0x7260
movl -0x68(%rbp), %eax
cmpl -0x80(%rbp), %eax
jbe 0x7a78
movl -0x68(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x7a78
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 0x791f
movl -0x7c(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x9550
movsd 0x773b(%rip), %xmm0     # 0xf020
ucomisd 0x8(%rax), %xmm0
jbe 0x78ee
jmp 0x7914
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 0x78c4
cmpl $0x0, -0x6c(%rbp)
jbe 0x7940
movl -0x6c(%rbp), %eax
cvtsi2sd %rax, %xmm1
movsd -0x78(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
jmp 0x7a13
movq 0xd6a9(%rip), %rdi      # 0x14ff0
leaq 0x7b3d(%rip), %rsi      # 0xf48b
callq 0x32c0
movq %rax, -0x490(%rbp)
jmp 0x795c
movq -0x490(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
callq 0x3280
movq %rax, -0x498(%rbp)
jmp 0x7978
movq -0x498(%rbp), %rdi
leaq 0x82ab(%rip), %rsi      # 0xfc31
callq 0x32c0
movq %rax, -0x4a0(%rbp)
jmp 0x7994
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x9550
movq -0x4a0(%rbp), %rdi
movl (%rax), %esi
callq 0x33b0
movq %rax, -0x4a8(%rbp)
jmp 0x79b8
movq -0x4a8(%rbp), %rdi
leaq 0x7ad6(%rip), %rsi      # 0xf49c
callq 0x32c0
movq %rax, -0x4b0(%rbp)
jmp 0x79d4
movl -0x374(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x9550
movq -0x4b0(%rbp), %rdi
movl (%rax), %esi
callq 0x33b0
movq %rax, -0x4b8(%rbp)
jmp 0x79fc
movq -0x4b8(%rbp), %rdi
leaq 0x7a94(%rip), %rsi      # 0xf49e
callq 0x32c0
jmp 0x7a11
jmp 0x7a13
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
movq %rdi, -0x4c8(%rbp)
callq 0x9550
movq -0x4c8(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x4bc(%rbp)
movl -0x374(%rbp), %eax
movl %eax, %esi
callq 0x9550
movl -0x4bc(%rbp), %esi
movl (%rax), %edx
movl -0x6c(%rbp), %ecx
movsd -0x78(%rbp), %xmm0
leaq -0x390(%rbp), %rdi
callq 0x8cc0
jmp 0x7a61
leaq -0x2e8(%rbp), %rdi
leaq -0x390(%rbp), %rsi
callq 0x9570
jmp 0x7a76
jmp 0x7a78
cmpl $0x0, -0x8c(%rbp)
jbe 0x7aa2
movl -0x8c(%rbp), %eax
cvtsi2sd %rax, %xmm1
movsd -0x88(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
jmp 0x7acd
movq 0xd547(%rip), %rdi      # 0x14ff0
leaq 0x7a07(%rip), %rsi      # 0xf4b7
callq 0x32c0
jmp 0x7ab7
movl $0x0, -0x4(%rbp)
movl $0x1, -0x32c(%rbp)
jmp 0x7dd4
movq 0xd51c(%rip), %rdi      # 0x14ff0
leaq 0x7a29(%rip), %rsi      # 0xf504
callq 0x32c0
movq %rax, -0x4d0(%rbp)
jmp 0x7ae9
movq -0x4d0(%rbp), %rdi
movsd -0x88(%rbp), %xmm0
callq 0x3530
movq %rax, -0x4d8(%rbp)
jmp 0x7b06
movq -0x4d8(%rbp), %rdi
leaq 0x80d8(%rip), %rsi      # 0xfbec
callq 0x32c0
jmp 0x7b1b
cmpq $0x0, -0x30(%rbp)
je 0x7b82
movq -0x30(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x88(%rbp)
movq 0xd4b7(%rip), %rdi      # 0x14ff0
leaq 0x79f7(%rip), %rsi      # 0xf537
callq 0x32c0
movq %rax, -0x4e0(%rbp)
jmp 0x7b4e
movq -0x4e0(%rbp), %rdi
movsd -0x88(%rbp), %xmm0
callq 0x3530
movq %rax, -0x4e8(%rbp)
jmp 0x7b6b
movq -0x4e8(%rbp), %rdi
leaq 0x8073(%rip), %rsi      # 0xfbec
callq 0x32c0
jmp 0x7b80
jmp 0x7b82
movq 0xd467(%rip), %rdi      # 0x14ff0
leaq 0x805c(%rip), %rsi      # 0xfbec
callq 0x32c0
jmp 0x7b97
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 0x7bee
jmp 0x7dc3
leaq -0x3a8(%rbp), %rdi
movq %rdi, -0x500(%rbp)
callq 0x9680
movq -0x500(%rbp), %rdi
movsd 0x10(%rax), %xmm0
movsd -0x88(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x3a0(%rbp)
callq 0x9680
movq -0x500(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x4f4(%rbp)
callq 0x9680
movq %rax, %rcx
movl -0x4f4(%rbp), %eax
movl 0x4(%rcx), %ecx
addl %ecx, %eax
shrl %eax
movl %eax, -0x394(%rbp)
movq 0xd371(%rip), %rdi      # 0x14fc8
leaq -0x2b0(%rbp), %rsi
callq 0x3280
movq %rax, -0x4f0(%rbp)
jmp 0x7c6c
movq -0x4f0(%rbp), %rdi
leaq 0x76a9(%rip), %rsi      # 0xf323
callq 0x32c0
movq %rax, -0x508(%rbp)
jmp 0x7c88
leaq -0x3a8(%rbp), %rdi
callq 0x9680
movq -0x508(%rbp), %rdi
movl (%rax), %esi
callq 0x33b0
movq %rax, -0x510(%rbp)
jmp 0x7cab
movq -0x510(%rbp), %rdi
leaq 0x766a(%rip), %rsi      # 0xf323
callq 0x32c0
movq %rax, -0x518(%rbp)
jmp 0x7cc7
leaq -0x3a8(%rbp), %rdi
callq 0x9680
movq -0x518(%rbp), %rdi
movl 0x4(%rax), %esi
callq 0x33b0
movq %rax, -0x520(%rbp)
jmp 0x7ceb
movq -0x520(%rbp), %rdi
leaq 0x762a(%rip), %rsi      # 0xf323
callq 0x32c0
movq %rax, -0x528(%rbp)
jmp 0x7d07
movq -0x528(%rbp), %rdi
movl -0x394(%rbp), %esi
callq 0x33b0
movq %rax, -0x530(%rbp)
jmp 0x7d22
movq -0x530(%rbp), %rdi
leaq 0x75f3(%rip), %rsi      # 0xf323
callq 0x32c0
movq %rax, -0x538(%rbp)
jmp 0x7d3e
movq -0x538(%rbp), %rdi
movsd -0x3a0(%rbp), %xmm0
callq 0x3530
movq %rax, -0x540(%rbp)
jmp 0x7d5b
movq -0x540(%rbp), %rdi
leaq 0x75ba(%rip), %rsi      # 0xf323
callq 0x32c0
movq %rax, -0x548(%rbp)
jmp 0x7d77
leaq -0x3a8(%rbp), %rdi
callq 0x9680
movq -0x548(%rbp), %rdi
movl 0x8(%rax), %esi
callq 0x33b0
movq %rax, -0x550(%rbp)
jmp 0x7d9b
movq -0x550(%rbp), %rdi
leaq 0x7e43(%rip), %rsi      # 0xfbec
callq 0x32c0
jmp 0x7db0
jmp 0x7db2
leaq -0x3a8(%rbp), %rdi
callq 0x96a0
jmp 0x7bbf
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
nopl (%rax,%rax)