// File: tplinderoth[P]introDist/Dxyz.cpp
// Function: vcf2Dxyz(std::basic_ifstream<char, std::char_traits<char>>&, std::basic_ifstream<char, std::char_traits<char>>&, std::basic_ofstream<char, std::char_traits<char>>&, int, int, double, int)
int vcf2Dxyz (std::ifstream &poptab, std::ifstream &vcf, std::ofstream &outf, int winsize, int step, double minmaf, int infmt) {
		// set up population table map
		std::map <std::string, int> popmap;
		if (setPopTable(poptab, popmap) <= 0) {
			return -1;
		}

		// set up instream
		std::streambuf *inbuf = NULL;
		boost::iostreams::filtering_streambuf<boost::iostreams::input> zipbuf;
		zipbuf.push(boost::iostreams::gzip_decompressor());
		if (infmt == 0) {
			inbuf = vcf.rdbuf();
		}
		else if (infmt == 1) {
			zipbuf.push(vcf);
			inbuf = &zipbuf;
		} else if (infmt == 2) {
			inbuf = std::cin.rdbuf();
		}
		std::istream instream(inbuf);

		// set up outstream
		std::streambuf *outbuf = NULL;
		if (outf.is_open()) {
			outbuf = outf.rdbuf();
		} else {
			outbuf = std::cout.rdbuf();
		}
		std::ostream outstream(outbuf);

		// print header to output
		printHeader(outstream);

		// process VCF file
		std::string vcfline;

		// skip headers and set up vector to hold tokens
		while (getline(instream, vcfline)) {
			if (vcfline[0] != '#' || vcfline[1] != '#')
				break;
		}

		// find individual's positions in allele vector
		std::vector<int> source_idx; // this is the source pop index positions
		std::vector<int> sink_idx; // this is the sink pop index positions
		std::vector<int> outgroup_idx; // this is the outgroup index positions

		std::stringstream ss(vcfline);
		std::string tok;
		int idxpos [2];
		int c = -9;
		int c2 = 0;
		int pop;
		while (ss >> tok) {
			if (c >= 0) {
				if (popmap.find(tok) != popmap.end()) {
					pop = popmap.find(tok)->second;
					idxpos[0] = c2;
					idxpos[1] = c2+1;

					if (pop == 0) {
						source_idx.insert(source_idx.end(), idxpos, idxpos+2);
					} else if (pop == 1) {
						sink_idx.insert(sink_idx.end(), idxpos, idxpos+2);
					} else if (pop == 2) {
						outgroup_idx.insert(outgroup_idx.end(), idxpos, idxpos+2);
					} else {
						std::cerr << "Invalid population code: " << pop << "\n";
						return -1;
					}

				}
				c2 += 2;
			}
			++c;
		}
		unsigned int nind = c;
		int nfields = c+9;
		std::cerr << "Number of individuals in VCF: " << nind << "\n";

		// set up data structures to hold site information

		// matrix to hold Dxy values
		Matrix<double> dxy(winsize, 5); // 0:source-sink dxy, 1:source-out dxy, 2:position, 3:number sequences with data, 4: maf

		// vector to hold alleles
		std::vector<int> alleles;
		alleles.resize(nind*2);

		// loop through VCF sites
		int i = 0, j = 0;
		std::string seqid;
		std::string prevseq;
		int nsitedata; // tracks number of sites in a window with data
		double nseqdata_win; // tracks average number of sequences per site in a window with data
		double dxy_components [2]; // 0=Source-Sink Dxy, 1=Source-Outgroup Dxy
		double dxyz;
		double winstart = 0; // holds start position of last printed window
		while (getline(instream, vcfline)) {
		// assume vcf fields are [0]=CHROM, [1]=POS, [2]=ID, [3]=REF, [4]=ALT, [5]=QUAL, [6]=FILTER, [7]=INFO, [8]=FORMAT

			// parse site information
			ss.clear();
			ss.str(vcfline);
			ss >> seqid; // extract CHROM
			ss >> dxy(j,2); // extract POS
			i=2;
			while (ss >> tok) {
				if (i > 8) {
					// extract genotypes
					if(parseGenotype(tok, alleles) == alleles.end()) {
						return -1;
					}
				} else if (i == 8) {
					// ensure genotypes are present
					if (tok[0] != 'G' || tok[1] != 'T') {
						std::cerr << "No GT subfield for " << seqid << " " << dxy(j,2) << "\n";
						return -1;
					}
				}
				++i;
			}

			if (i < nfields) {
				std::cerr << "Input VCF appears truncated\n";
				return -1;
			}

			// calculate average number of pairwise differences for site
			dxyComponents(alleles, source_idx, sink_idx, outgroup_idx, dxy, j);
			++j;

			if (j == winsize || (!prevseq.empty() && prevseq != seqid)) {
				winstart=dxy(0,2);

				// calculate Dxyz window
				dxyz = calcDxyzWindow(dxy, dxy.nrow()-1, &nseqdata_win, &nsitedata, minmaf, dxy_components);

				// print window
				printWindow(outstream, dxyz, seqid, dxy(0,2), dxy(winsize-1,2), nseqdata_win, nsitedata, dxy_components);

				// slide dxy window
				j = slideWindow(dxy, winsize, step, j);
			}

			prevseq = seqid;
		}

		// process last window if necessary
		if (dxy(0,2) != winstart) {
			dxyz = calcDxyzWindow(dxy, j-1, &nseqdata_win, &nsitedata, minmaf, dxy_components);
			printWindow(outstream, dxyz, seqid, dxy(0,2), dxy(j-1,2), nseqdata_win, nsitedata, dxy_components);
		}

		return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x8c0, %rsp            # imm = 0x8C0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movsd %xmm0, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
leaq -0x68(%rbp), %rdi
movq %rdi, -0x728(%rbp)
callq 0xb410
movq -0x728(%rbp), %rsi
movq -0x10(%rbp), %rdi
callq 0xa510
movl %eax, -0x71c(%rbp)
jmp 0x917f
movl -0x71c(%rbp), %eax
cmpl $0x0, %eax
jg 0x91ae
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x78(%rbp)
jmp 0xa057
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0xa06c
movq $0x0, -0x80(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0xb430
jmp 0x91c4
leaq -0xa0(%rbp), %rax
movq %rax, -0x730(%rbp)
leaq -0x188(%rbp), %rdi
movl $0xf, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0xb4d0
jmp 0x91ea
movq -0x730(%rbp), %rdi
xorl %eax, %eax
movl %eax, %r8d
leaq -0x188(%rbp), %rsi
movq $-0x1, %rcx
movq %rcx, %rdx
callq 0xb480
jmp 0x920e
leaq -0x188(%rbp), %rdi
callq 0xb5e0
cmpl $0x0, -0x34(%rbp)
jne 0x9270
movq -0x18(%rbp), %rdi
callq 0x8720
movq %rax, -0x738(%rbp)
jmp 0x9232
movq -0x738(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x92d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0xa049
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x188(%rbp), %rdi
callq 0xb5e0
jmp 0xa049
cmpl $0x1, -0x34(%rbp)
jne 0x929f
leaq -0xa0(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq $-0x1, %rcx
movq %rcx, %rdx
callq 0xb620
jmp 0x9292
leaq -0xe0(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x92d1
cmpl $0x2, -0x34(%rbp)
jne 0x92cf
movq 0x23d24(%rip), %rdi     # 0x2cfd0
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x8200
movq %rax, -0x740(%rbp)
jmp 0x92c4
movq -0x740(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x92d1
jmp 0x92d3
movq -0x80(%rbp), %rsi
leaq -0x2a0(%rbp), %rdi
callq 0x88b0
jmp 0x92e5
movq $0x0, -0x2a8(%rbp)
movq -0x20(%rbp), %rdi
callq 0x8350
movb %al, -0x741(%rbp)
jmp 0x9301
movb -0x741(%rbp), %al
testb $0x1, %al
jne 0x930d
jmp 0x9340
movq -0x20(%rbp), %rdi
callq 0x88a0
movq %rax, -0x750(%rbp)
jmp 0x931f
movq -0x750(%rbp), %rax
movq %rax, -0x2a8(%rbp)
jmp 0x936d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0xa03d
movq 0x23c61(%rip), %rdi     # 0x2cfa8
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x8200
movq %rax, -0x758(%rbp)
jmp 0x935f
movq -0x758(%rbp), %rax
movq %rax, -0x2a8(%rbp)
movq -0x2a8(%rbp), %rsi
leaq -0x3b8(%rbp), %rdi
callq 0x81c0
jmp 0x9382
leaq -0x3b8(%rbp), %rdi
callq 0xa700
jmp 0x9390
leaq -0x3d8(%rbp), %rdi
callq 0x8620
leaq -0x2a0(%rbp), %rdi
leaq -0x3d8(%rbp), %rsi
callq 0x80b0
movq %rax, -0x760(%rbp)
jmp 0x93b8
movq -0x760(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x8570
movb %al, -0x761(%rbp)
jmp 0x93d6
movb -0x761(%rbp), %al
testb $0x1, %al
jne 0x93e2
jmp 0x945c
xorl %eax, %eax
movl %eax, %esi
leaq -0x3d8(%rbp), %rdi
callq 0x88e0
movq %rax, -0x770(%rbp)
jmp 0x93fb
movq -0x770(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x9433
leaq -0x3d8(%rbp), %rdi
movl $0x1, %esi
callq 0x88e0
movq %rax, -0x778(%rbp)
jmp 0x9424
movq -0x778(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
je 0x9457
jmp 0x945c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0xa031
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0xa025
jmp 0x939c
leaq -0x3f0(%rbp), %rdi
callq 0xb670
leaq -0x408(%rbp), %rdi
callq 0xb670
leaq -0x420(%rbp), %rdi
callq 0xb670
movl $0x10, %edi
movl $0x8, %esi
callq 0xb3f0
movl %eax, -0x77c(%rbp)
jmp 0x9497
movl -0x77c(%rbp), %edx
leaq -0x5a8(%rbp), %rdi
leaq -0x3d8(%rbp), %rsi
callq 0x8750
jmp 0x94b2
leaq -0x5c8(%rbp), %rdi
callq 0x8620
movl $0xfffffff7, -0x5d4(%rbp) # imm = 0xFFFFFFF7
movl $0x0, -0x5d8(%rbp)
leaq -0x5a8(%rbp), %rdi
leaq -0x5c8(%rbp), %rsi
callq 0x8590
movq %rax, -0x788(%rbp)
jmp 0x94ee
movq -0x788(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x8570
movb %al, -0x789(%rbp)
jmp 0x950c
movb -0x789(%rbp), %al
testb $0x1, %al
jne 0x951b
jmp 0x97d6
cmpl $0x0, -0x5d4(%rbp)
jl 0x97c2
leaq -0x68(%rbp), %rdi
leaq -0x5c8(%rbp), %rsi
callq 0xb6c0
movq %rax, -0x798(%rbp)
jmp 0x9541
movq -0x798(%rbp), %rax
movq %rax, -0x5e8(%rbp)
leaq -0x68(%rbp), %rdi
callq 0xb6f0
movq %rax, -0x5f0(%rbp)
leaq -0x5e8(%rbp), %rdi
leaq -0x5f0(%rbp), %rsi
callq 0xb690
testb $0x1, %al
jne 0x957b
jmp 0x97b3
leaq -0x68(%rbp), %rdi
leaq -0x5c8(%rbp), %rsi
callq 0xb6c0
movq %rax, -0x7a0(%rbp)
jmp 0x9594
movq -0x7a0(%rbp), %rax
movq %rax, -0x5f8(%rbp)
leaq -0x5f8(%rbp), %rdi
callq 0xb720
movl 0x20(%rax), %eax
movl %eax, -0x5dc(%rbp)
movl -0x5d8(%rbp), %eax
movl %eax, -0x5d0(%rbp)
movl -0x5d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5cc(%rbp)
cmpl $0x0, -0x5dc(%rbp)
jne 0x966b
leaq -0x3f0(%rbp), %rdi
movq %rdi, -0x7b0(%rbp)
callq 0xb7e0
movq %rax, -0x608(%rbp)
leaq -0x600(%rbp), %rdi
leaq -0x608(%rbp), %rsi
callq 0xb810
movq -0x7b0(%rbp), %rdi
leaq -0x5c8(%rbp), %rcx
movq -0x600(%rbp), %rsi
leaq -0x5d0(%rbp), %rdx
callq 0xb740
movq %rax, -0x7a8(%rbp)
jmp 0x9636
movq -0x7a8(%rbp), %rax
movq %rax, -0x610(%rbp)
jmp 0x97b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0xa001
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x9fe9
cmpl $0x1, -0x5dc(%rbp)
jne 0x96de
leaq -0x408(%rbp), %rdi
movq %rdi, -0x7c0(%rbp)
callq 0xb7e0
movq %rax, -0x620(%rbp)
leaq -0x618(%rbp), %rdi
leaq -0x620(%rbp), %rsi
callq 0xb810
movq -0x7c0(%rbp), %rdi
leaq -0x5c8(%rbp), %rcx
movq -0x618(%rbp), %rsi
leaq -0x5d0(%rbp), %rdx
callq 0xb740
movq %rax, -0x7b8(%rbp)
jmp 0x96cb
movq -0x7b8(%rbp), %rax
movq %rax, -0x628(%rbp)
jmp 0x97af
cmpl $0x2, -0x5dc(%rbp)
jne 0x974e
leaq -0x420(%rbp), %rdi
movq %rdi, -0x7d0(%rbp)
callq 0xb7e0
movq %rax, -0x638(%rbp)
leaq -0x630(%rbp), %rdi
leaq -0x638(%rbp), %rsi
callq 0xb810
movq -0x7d0(%rbp), %rdi
leaq -0x5c8(%rbp), %rcx
movq -0x630(%rbp), %rsi
leaq -0x5d0(%rbp), %rdx
callq 0xb740
movq %rax, -0x7c8(%rbp)
jmp 0x973e
movq -0x7c8(%rbp), %rax
movq %rax, -0x640(%rbp)
jmp 0x97ad
movq 0x23893(%rip), %rdi     # 0x2cfe8
leaq 0x14c8b(%rip), %rsi     # 0x1e3e7
callq 0x8400
movq %rax, -0x7d8(%rbp)
jmp 0x976a
movq -0x7d8(%rbp), %rdi
movl -0x5dc(%rbp), %esi
callq 0x8820
movq %rax, -0x7e0(%rbp)
jmp 0x9785
movq -0x7e0(%rbp), %rdi
leaq 0x148f0(%rip), %rsi     # 0x1e083
callq 0x8400
jmp 0x979a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x78(%rbp)
jmp 0x9f7b
jmp 0x97af
jmp 0x97b1
jmp 0x97b3
movl -0x5d8(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x5d8(%rbp)
movl -0x5d4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5d4(%rbp)
jmp 0x94d2
movl -0x5d4(%rbp), %eax
movl %eax, -0x644(%rbp)
movl -0x5d4(%rbp), %eax
addl $0x9, %eax
movl %eax, -0x648(%rbp)
movq 0x237f0(%rip), %rdi     # 0x2cfe8
leaq 0x14c02(%rip), %rsi     # 0x1e401
callq 0x8400
movq %rax, -0x7e8(%rbp)
jmp 0x980d
movq -0x7e8(%rbp), %rdi
movl -0x644(%rbp), %esi
callq 0x85f0
movq %rax, -0x7f0(%rbp)
jmp 0x9828
movq -0x7f0(%rbp), %rdi
leaq 0x1484d(%rip), %rsi     # 0x1e083
callq 0x8400
jmp 0x983d
movslq -0x24(%rbp), %rsi
leaq -0x658(%rbp), %rdi
movl $0x5, %edx
callq 0xb850
jmp 0x9854
leaq -0x670(%rbp), %rdi
movq %rdi, -0x7f8(%rbp)
callq 0xb670
movq -0x7f8(%rbp), %rdi
movl -0x644(%rbp), %eax
addl %eax, %eax
movl %eax, %esi
callq 0xb980
jmp 0x987f
movl $0x0, -0x674(%rbp)
movl $0x0, -0x678(%rbp)
leaq -0x698(%rbp), %rdi
callq 0x8620
leaq -0x6b8(%rbp), %rdi
callq 0x8620
xorps %xmm0, %xmm0
movsd %xmm0, -0x6f0(%rbp)
leaq -0x2a0(%rbp), %rdi
leaq -0x3d8(%rbp), %rsi
callq 0x80b0
movq %rax, -0x800(%rbp)
jmp 0x98d2
movq -0x800(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x8570
movb %al, -0x801(%rbp)
jmp 0x98f0
movb -0x801(%rbp), %al
testb $0x1, %al
jne 0x98ff
jmp 0x9de4
movq -0x5a8(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x5a8(%rbp,%rax), %rdi
xorl %esi, %esi
callq 0x87f0
jmp 0x991b
leaq -0x5a8(%rbp), %rdi
leaq -0x3d8(%rbp), %rsi
callq 0x84f0
jmp 0x9930
leaq -0x5a8(%rbp), %rdi
leaq -0x698(%rbp), %rsi
callq 0x8590
jmp 0x9945
movl -0x678(%rbp), %esi
leaq -0x658(%rbp), %rdi
movl $0x2, %edx
callq 0xba10
movq %rax, -0x810(%rbp)
jmp 0x9965
movq -0x810(%rbp), %rsi
leaq -0x5a8(%rbp), %rdi
callq 0x8380
jmp 0x997a
movl $0x2, -0x674(%rbp)
leaq -0x5a8(%rbp), %rdi
leaq -0x5c8(%rbp), %rsi
callq 0x8590
movq %rax, -0x818(%rbp)
jmp 0x99a0
movq -0x818(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x8570
movb %al, -0x819(%rbp)
jmp 0x99be
movb -0x819(%rbp), %al
testb $0x1, %al
jne 0x99cd
jmp 0x9baa
cmpl $0x8, -0x674(%rbp)
jle 0x9a74
leaq -0x5c8(%rbp), %rdi
leaq -0x670(%rbp), %rsi
callq 0xa740
movq %rax, -0x828(%rbp)
jmp 0x99f6
leaq -0x670(%rbp), %rdi
callq 0xb7e0
movq -0x828(%rbp), %rdi
movq %rax, -0x6f8(%rbp)
leaq -0x6f8(%rbp), %rsi
callq 0xbae0
testb $0x1, %al
jne 0x9a22
jmp 0x9a6f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x78(%rbp)
jmp 0x9f2f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x9f61
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x6b8(%rbp), %rdi
callq 0x82a0
leaq -0x698(%rbp), %rdi
callq 0x82a0
jmp 0x9f61
jmp 0x9b96
cmpl $0x8, -0x674(%rbp)
jne 0x9b94
xorl %eax, %eax
movl %eax, %esi
leaq -0x5c8(%rbp), %rdi
callq 0x88e0
movq %rax, -0x830(%rbp)
jmp 0x9a9a
movq -0x830(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x47, %eax
jne 0x9ad6
leaq -0x5c8(%rbp), %rdi
movl $0x1, %esi
callq 0x88e0
movq %rax, -0x838(%rbp)
jmp 0x9ac3
movq -0x838(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x54, %eax
je 0x9b92
movq 0x2350b(%rip), %rdi     # 0x2cfe8
leaq 0x1493c(%rip), %rsi     # 0x1e420
callq 0x8400
movq %rax, -0x840(%rbp)
jmp 0x9af2
movq -0x840(%rbp), %rdi
leaq -0x698(%rbp), %rsi
callq 0x83c0
movq %rax, -0x848(%rbp)
jmp 0x9b0e
movq -0x848(%rbp), %rdi
leaq 0x14902(%rip), %rsi     # 0x1e41e
callq 0x8400
movq %rax, -0x850(%rbp)
jmp 0x9b2a
movl -0x678(%rbp), %esi
leaq -0x658(%rbp), %rdi
movl $0x2, %edx
callq 0xba10
movq %rax, -0x858(%rbp)
jmp 0x9b4a
movq -0x850(%rbp), %rdi
movq -0x858(%rbp), %rax
movsd (%rax), %xmm0
callq 0x88c0
movq %rax, -0x860(%rbp)
jmp 0x9b6a
movq -0x860(%rbp), %rdi
leaq 0x1450b(%rip), %rsi     # 0x1e083
callq 0x8400
jmp 0x9b7f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x78(%rbp)
jmp 0x9f2f
jmp 0x9b94
jmp 0x9b96
movl -0x674(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x674(%rbp)
jmp 0x9984
movl -0x674(%rbp), %eax
cmpl -0x648(%rbp), %eax
jge 0x9be0
movq 0x23429(%rip), %rdi     # 0x2cfe8
leaq 0x1486e(%rip), %rsi     # 0x1e434
callq 0x8400
jmp 0x9bcd
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x78(%rbp)
jmp 0x9f2f
movl -0x678(%rbp), %r9d
leaq -0x670(%rbp), %rdi
leaq -0x3f0(%rbp), %rsi
leaq -0x408(%rbp), %rdx
leaq -0x420(%rbp), %rcx
leaq -0x658(%rbp), %r8
callq 0xa950
jmp 0x9c11
movl -0x678(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x678(%rbp)
movl -0x678(%rbp), %eax
cmpl -0x24(%rbp), %eax
je 0x9c5b
leaq -0x6b8(%rbp), %rdi
callq 0x87c0
testb $0x1, %al
jne 0x9dca
leaq -0x6b8(%rbp), %rdi
leaq -0x698(%rbp), %rsi
callq 0xbb20
testb $0x1, %al
jne 0x9c5b
jmp 0x9dca
leaq -0x658(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0xba10
movq %rax, -0x868(%rbp)
jmp 0x9c77
movq -0x868(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x6f0(%rbp)
leaq -0x658(%rbp), %rdi
callq 0xbb50
movl %eax, -0x86c(%rbp)
jmp 0x9c9e
movl -0x86c(%rbp), %esi
decl %esi
movsd -0x30(%rbp), %xmm0
leaq -0x658(%rbp), %rdi
leaq -0x6c8(%rbp), %rdx
leaq -0x6bc(%rbp), %rcx
leaq -0x6e0(%rbp), %r8
callq 0xace0
movsd %xmm0, -0x878(%rbp)
jmp 0x9cd6
movsd -0x878(%rbp), %xmm0
movsd %xmm0, -0x6e8(%rbp)
leaq -0x658(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0xba10
movq %rax, -0x880(%rbp)
jmp 0x9d02
movq -0x880(%rbp), %rax
cvttsd2si (%rax), %rax
movl %eax, -0x6fc(%rbp)
movl -0x24(%rbp), %esi
decl %esi
leaq -0x658(%rbp), %rdi
movl $0x2, %edx
callq 0xba10
movq %rax, -0x888(%rbp)
jmp 0x9d33
movq -0x888(%rbp), %rax
cvttsd2si (%rax), %rax
movl %eax, -0x700(%rbp)
cvtsi2sdl -0x6bc(%rbp), %xmm0
movsd %xmm0, -0x708(%rbp)
movq %rsp, %rax
leaq -0x6e0(%rbp), %rcx
movq %rcx, 0x8(%rax)
leaq -0x708(%rbp), %rcx
movq %rcx, (%rax)
leaq -0x3b8(%rbp), %rdi
leaq -0x6e8(%rbp), %rsi
leaq -0x698(%rbp), %rdx
leaq -0x6fc(%rbp), %rcx
leaq -0x700(%rbp), %r8
leaq -0x6c8(%rbp), %r9
callq 0xaec0
jmp 0x9d9e
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
movl -0x678(%rbp), %ecx
leaq -0x658(%rbp), %rdi
callq 0xb010
movl %eax, -0x88c(%rbp)
jmp 0x9dbe
movl -0x88c(%rbp), %eax
movl %eax, -0x678(%rbp)
leaq -0x6b8(%rbp), %rdi
leaq -0x698(%rbp), %rsi
callq 0x8050
jmp 0x9ddf
jmp 0x98b6
leaq -0x658(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0xba10
movq %rax, -0x898(%rbp)
jmp 0x9e00
movq -0x898(%rbp), %rax
movsd (%rax), %xmm0
ucomisd -0x6f0(%rbp), %xmm0
jne 0x9e1c
jp 0x9e1c
jmp 0x9f21
movl -0x678(%rbp), %esi
decl %esi
movsd -0x30(%rbp), %xmm0
leaq -0x658(%rbp), %rdi
leaq -0x6c8(%rbp), %rdx
leaq -0x6bc(%rbp), %rcx
leaq -0x6e0(%rbp), %r8
callq 0xace0
movsd %xmm0, -0x8a0(%rbp)
jmp 0x9e54
movsd -0x8a0(%rbp), %xmm0
movsd %xmm0, -0x6e8(%rbp)
leaq -0x658(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0xba10
movq %rax, -0x8a8(%rbp)
jmp 0x9e80
movq -0x8a8(%rbp), %rax
cvttsd2si (%rax), %rax
movl %eax, -0x70c(%rbp)
movl -0x678(%rbp), %esi
decl %esi
leaq -0x658(%rbp), %rdi
movl $0x2, %edx
callq 0xba10
movq %rax, -0x8b0(%rbp)
jmp 0x9eb4
movq -0x8b0(%rbp), %rax
cvttsd2si (%rax), %rax
movl %eax, -0x710(%rbp)
cvtsi2sdl -0x6bc(%rbp), %xmm0
movsd %xmm0, -0x718(%rbp)
movq %rsp, %rax
leaq -0x6e0(%rbp), %rcx
movq %rcx, 0x8(%rax)
leaq -0x718(%rbp), %rcx
movq %rcx, (%rax)
leaq -0x3b8(%rbp), %rdi
leaq -0x6e8(%rbp), %rsi
leaq -0x698(%rbp), %rdx
leaq -0x70c(%rbp), %rcx
leaq -0x710(%rbp), %r8
leaq -0x6c8(%rbp), %r9
callq 0xaec0
jmp 0x9f1f
jmp 0x9f21
movl $0x0, -0x4(%rbp)
movl $0x1, -0x78(%rbp)
leaq -0x6b8(%rbp), %rdi
callq 0x82a0
leaq -0x698(%rbp), %rdi
callq 0x82a0
leaq -0x670(%rbp), %rdi
callq 0xbb60
leaq -0x658(%rbp), %rdi
callq 0xbbc0
jmp 0x9f7b
leaq -0x670(%rbp), %rdi
callq 0xbb60
leaq -0x658(%rbp), %rdi
callq 0xbbc0
jmp 0x9fe9
leaq -0x5c8(%rbp), %rdi
callq 0x82a0
leaq -0x5a8(%rbp), %rdi
callq 0x8330
leaq -0x420(%rbp), %rdi
callq 0xbb60
leaq -0x408(%rbp), %rdi
callq 0xbb60
leaq -0x3f0(%rbp), %rdi
callq 0xbb60
leaq -0x3d8(%rbp), %rdi
callq 0x82a0
leaq -0x3b8(%rbp), %rdi
callq 0x8760
leaq -0x2a0(%rbp), %rdi
callq 0x87e0
leaq -0xe0(%rbp), %rdi
callq 0xbc50
jmp 0xa057
leaq -0x5c8(%rbp), %rdi
callq 0x82a0
leaq -0x5a8(%rbp), %rdi
callq 0x8330
leaq -0x420(%rbp), %rdi
callq 0xbb60
leaq -0x408(%rbp), %rdi
callq 0xbb60
leaq -0x3f0(%rbp), %rdi
callq 0xbb60
leaq -0x3d8(%rbp), %rdi
callq 0x82a0
leaq -0x3b8(%rbp), %rdi
callq 0x8760
leaq -0x2a0(%rbp), %rdi
callq 0x87e0
leaq -0xe0(%rbp), %rdi
callq 0xbc50
jmp 0xa06c
leaq -0x68(%rbp), %rdi
callq 0xbcc0
movl -0x4(%rbp), %eax
addq $0x8c0, %rsp            # imm = 0x8C0
popq %rbp
retq
leaq -0x68(%rbp), %rdi
callq 0xbcc0
movq -0x70(%rbp), %rdi
callq 0x8830
nop