// File: /workspace/github_cpp_makefile_star2_O2/tonymugen[P]sampleSNPs/varfiles.cpp
// Function: sampFiles::BedFileI::sample(sampFiles::BedFileO&, unsigned long const&)
void BedFileI::sample(BedFileO &out, const uint64_t &n){

	if (n == 0) {
		cerr << "WARNING: zero SNPs requested. Nothing to be done." << endl;
		return;
	}
	// start by figuring out the number of SNPs in the .bed file
	if (out._varFile.is_open()) {
		out.close();
	}
	// First have to know the number of lines
	string outFam  = out._fileStub + ".fam";
	string famName = _fileStub + ".fam";

	try {
		_famFile.open(famName.c_str(), ios::in);
		if (!_famFile.is_open()) {
			cerr << "ERROR: failed to open .fam file " << famName << " for input" << endl;
			exit(2);
		}

	} catch (system_error &error) {
		cerr << "ERROR: cannot open .fam file " << _fileName << " for input: " << error.code().message() << flush;
		perror(" ");
		exit(1);
	}

	try {
		out._famFile.open(outFam.c_str(), ios::out | ios::trunc);
		if (!out._famFile.is_open()) {
			cerr << "ERROR: failed to open .fam file " << outFam << " for output" << endl;
			exit(2);
		}

	} catch (system_error &error) {
		cerr << "ERROR: cannot open .fam file " << out._fileName << " for output: " << error.code().message() << flush;
		perror(" ");
		exit(1);
	}

	_nCols        = _famLines(out._famFile); // copying the .fam file
    uint64_t N    = _numLines(); // number of SNPs in the .bed file
    uint64_t Nbed = (_nCols/4UL) + static_cast<uint64_t>( (_nCols%4UL) > 0UL );
	_varFile.close();

	// Test for potential problems
	string inBim  = _fileStub + ".bim";
	string outBim = out._fileStub + ".bim";
	if (N < n) {
		cerr << "ERROR: requested a sample of " << n << " SNPs that is greater than the number of SNPs (" << N << ") in the input file." << endl;
		return;
	} else if (N == n) {
		cerr << "WARNING: sample size (" << n << ") the same as the number of SNPs (" << N << ") in the input file. Simply copying the files." << endl;
		char *buf;
		const size_t bufSize = BUF_SIZE;
		try {
			buf = new char[bufSize];
		} catch (bad_alloc&) {
			cerr << "ERROR: failed to allocate buffer" << endl;
			exit(4);
		}

		// Copy .bed
		try {
			_varFile.open(_fileName.c_str(), ios::in | ios::binary);
			if (!_varFile.is_open()) {
				cerr << "ERROR: failed to open .bed file " << _fileName << " for input" << endl;
				exit(2);
			}

			// check the magic bytes and SNP-major status
			char magic[3];
			_varFile.read(magic, 3);
			if ( (magic[0] != static_cast<char>(0x6C)) || (magic[1] != static_cast<char>(0x1B)) ) {
				cerr << "ERROR: binary file " << _fileName << " not recognized as BED" << endl;
				exit(2);
			} else if (magic[2] != static_cast<char>(0x01)){
				cerr << "ERROR: binary file " << _fileName << " not SNP-major. Run a newer version of plink to fix it." << endl;
				exit(3);
			}

		} catch (system_error &error) {
			cerr << "ERROR: cannot open .bed file " << _fileName << " for input: " << error.code().message() << flush;
			perror(" ");
			exit(1);
		}
		try {
			out._varFile.open(out._fileName.c_str(), ios::out);
			if (!out._varFile.is_open()) {
				cerr << "ERROR: failed to open .bed file " << out._fileName << " for output" << endl;
				exit(2);
			}

		} catch (system_error &error) {
			cerr << "ERROR: cannot open .bed file " << out._fileName << " for output: " << error.code().message() << flush;
			perror(" ");
			exit(1);
		}
		while (_varFile) {
			_varFile.read(buf, bufSize);
			out._varFile.write(buf, _varFile.gcount()); // must be gcount() in case we got to the end of the file
		}
		_varFile.close();
		out._varFile.close();

		// Copy .bim
		try {
			_bimFile.open(inBim.c_str(), ios::in);
			if (!_bimFile.is_open()) {
				cerr << "ERROR: failed to open .bim file " << inBim << " for input" << endl;
				exit(2);
			}

		} catch (system_error &error) {
			cerr << "ERROR: cannot open .bim file " << inBim << " for input: " << error.code().message() << flush;
			perror(" ");
			exit(1);
		}
		try {
			out._bimFile.open(outBim.c_str(), ios::out);
			if (!out._bimFile.is_open()) {
				cerr << "ERROR: failed to open .bim file " << outBim << " for output" << endl;
				exit(2);
			}

		} catch (system_error &error) {
			cerr << "ERROR: cannot open .bim file " << outBim << " for output: " << error.code().message() << flush;
			perror(" ");
			exit(1);
		}
		while (_bimFile) {
			_bimFile.read(buf, bufSize);
			out._bimFile.write(buf, _bimFile.gcount());
		}
		_bimFile.close();
		out._bimFile.close();
		delete [] buf;
		return;
	}

	// Passed all the tests, proceed to sampling
	char *SNPbuf;
	try {
		SNPbuf = new char[Nbed]; // .read() does not append a null-character
	} catch (bad_alloc &) {
		cerr << "ERROR: failed to allocate the SNP buffer" << endl;
		exit(4);

	}
	string bimLine;

	try {
		_bimFile.open(inBim.c_str(), ios::in);
		if (!_bimFile.is_open()) {
			cerr << "ERROR: failed to open .bim file " << inBim << " for input" << endl;
			exit(2);
		}

	} catch (system_error &error) {
		cerr << "ERROR: cannot open .bim file " << inBim << " for input: " << error.code().message() << flush;
		perror(" ");
		exit(1);
	}
	try {
		out._bimFile.open(outBim.c_str(), ios::out);
		if (!out._bimFile.is_open()) {
			cerr << "ERROR: failed to open .bim file " << outBim << " for output" << endl;
			exit(2);
		}


	} catch (system_error &error) {
		cerr << "ERROR: cannot open .bim file " << outBim << " for output: " << error.code().message() << flush;
		perror(" ");
		exit(1);
	}

	try {
		_varFile.open(_fileName.c_str(), ios::in | ios::binary);
		if (!_varFile.is_open()) {
			cerr << "ERROR: failed to open .bed file " << _fileName << " for input" << endl;
			exit(2);
		}
		// check the magic bytes and SNP-major status
		char magic[3];
		_varFile.read(magic, 3);
		if ( (magic[0] != static_cast<char>(0x6C)) || (magic[1] != static_cast<char>(0x1B)) ) {
			cerr << "ERROR: binary file " << _fileName << " not recognized as BED" << endl;
			exit(2);
		} else if (magic[2] != static_cast<char>(0x01)){
			cerr << "ERROR: binary file " << _fileName << " not SNP-major. Run a newer version of plink to fix it." << endl;
			exit(3);
		}
	} catch (system_error &error) {
		cerr << "ERROR: cannot open .bed file " << _fileName << " for input: " << error.code().message() << flush;
		perror(" ");
		exit(1);
	}
	try {
		out._varFile.open(out._fileName.c_str(), ios::out | ios::binary | ios::trunc);
		if (!out._varFile.is_open()) {
			cerr << "ERROR: failed to open .bed file " << out._fileName << " for output" << endl;
			exit(2);
		}

		// write the magic bytes and the SNP-major status byte
		char magic[3] = {static_cast<char>(0x6C), static_cast<char>(0x1B), static_cast<char>(0x01)};
		out._varFile.write(magic, 3);

	} catch (system_error &error) {
		cerr << "ERROR: cannot open .bed file " << out._fileName << " for output: " << error.code().message() << flush;
		perror(" ");
		exit(1);
	}

	uint64_t nloc = n; // local copy of n
	uint64_t S;
	uint64_t cumS = 0; // cumulative position in the file
	RanDraw *snpSamp;  // so that I can catch RanDraw constructor exceptions
	try {
		snpSamp = new RanDraw();
	} catch (string error) {
		cerr << "ERROR: " << error << endl;
		exit(5);
	}
	while (nloc) {
		try {
			S = snpSamp->vitter(nloc, N); // sample the number of SNPs to skip; keep track of the running total
		} catch (string error) {
			cerr << "ERROR: " << error << endl;
			exit(5);
		}
		cumS += S;
		N    -= S + 1;
		_varFile.seekg(cumS*Nbed + 3); // seekg() index is base-0
		_varFile.read(SNPbuf, Nbed);
		cumS++;                        // step up cumS because seekg() will not change it (unlike the getline() that automatially advances)
		out._varFile.write(SNPbuf, Nbed);
		while (S) { // skipping S lines in the bim file
			_bimFile.ignore(numeric_limits<streamsize>::max(), '\n');
			S--;
		}
		getline(_bimFile, bimLine);
		out._bimFile << bimLine << endl;
		nloc--;

	}
	_varFile.close();
	out._varFile.close();
	_bimFile.close();
	out._bimFile.close();
	delete [] SNPbuf;
	delete snpSamp;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
cmpq $0x0, (%rdx)
je 0x9d25
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %r15
leaq 0x88(%rsi), %rdi
movq %rdi, 0x38(%rsp)
callq 0x40b0
testb %al, %al
je 0x9bb1
movq (%r13), %rax
movq %r13, %rdi
callq *0x8(%rax)
movl $0x668, %ebp            # imm = 0x668
movq %r13, %rbx
addq %rbp, %rbx
leaq 0xabd2(%rip), %r14      # 0x14795
leaq 0xf8(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x5e08
addq %r15, %rbp
leaq 0xd8(%rsp), %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x5e08
leaq 0x248(%r15), %rdi
movq 0xd8(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x4280
leaq 0x2c8(%r15), %rdi
callq 0x40b0
testb %al, %al
je 0xa277
leaq 0x248(%r13), %r14
movq 0xf8(%rsp), %rsi
pushq $0x30
popq %rdx
movq %r14, %rdi
callq 0x4280
leaq 0x2c8(%r13), %rdi
callq 0x40b0
testb %al, %al
je 0xa2b3
movq %r15, %rdi
movq %r14, %rsi
callq 0x7a46
movq %rax, 0x238(%r15)
movq %r15, %rdi
callq 0x75fe
movq %rax, 0x60(%rsp)
movq 0x238(%r15), %rax
movq %rax, %rcx
shrq $0x2, %rcx
andl $0x3, %eax
cmpq $0x1, %rax
sbbq $-0x1, %rcx
movq %rcx, 0x68(%rsp)
leaq 0x8(%r15), %rdi
movq %rdi, 0x8(%rsp)
callq 0x4050
leaq 0xab9d(%rip), %rdx      # 0x14834
leaq 0x70(%rsp), %rdi
movq %rbp, %rsi
callq 0x5e08
leaq 0xab89(%rip), %rdx      # 0x14834
leaq 0x98(%rsp), %rdi
movq %rbx, %rsi
callq 0x5e08
leaq 0x8(%r13), %rbp
movq 0x60(%rsp), %rax
cmpq (%r12), %rax
jae 0x9d51
movq 0x1231b(%rip), %rdi     # 0x1bff0
leaq 0xa91a(%rip), %rsi      # 0x145f6
callq 0x42a0
movq (%r12), %rsi
movq %rax, %rdi
callq 0x41b0
leaq 0xac04(%rip), %rsi      # 0x148f8
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
movq 0x60(%rsp), %rsi
callq 0x41b0
leaq 0xa934(%rip), %rsi      # 0x14644
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0xa234
movq 0x122c4(%rip), %rdi     # 0x1bff0
leaq 0xa891(%rip), %rsi      # 0x145c4
callq 0x42a0
movq %rax, %rdi
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4140
jne 0x9e7e
movq 0x12292(%rip), %rdi     # 0x1bff0
leaq 0xa8f4(%rip), %rsi      # 0x14659
callq 0x42a0
movq (%r12), %rsi
movq %rax, %rdi
callq 0x41b0
leaq 0xabab(%rip), %rsi      # 0x14928
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
movq 0x60(%rsp), %rsi
callq 0x41b0
leaq 0xabb2(%rip), %rsi      # 0x1494b
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
movl $0xa00000, %edi         # imm = 0xA00000
callq 0x4030
movq %rax, %r12
leaq 0x218(%r15), %rbx
movq 0x218(%r15), %rsi
pushq $0xc
popq %rdx
movq 0x8(%rsp), %rdi
callq 0x4280
leaq 0x88(%r15), %rdi
callq 0x40b0
testb %al, %al
je 0xa3a5
leaq 0x40(%rsp), %rsi
pushq $0x3
popq %rdx
movq 0x8(%rsp), %rdi
callq 0x4340
cmpb $0x6c, 0x40(%rsp)
jne 0xa454
cmpb $0x1b, 0x41(%rsp)
jne 0xa454
cmpb $0x1, 0x42(%rsp)
jne 0xa48e
leaq 0x218(%r13), %rbx
movq 0x218(%r13), %rsi
pushq $0x10
popq %rdx
movq %rbp, %rdi
callq 0x4280
movq 0x38(%rsp), %rdi
callq 0x40b0
testb %al, %al
je 0xa504
leaq 0x18(%r13), %rbx
movq 0x8(%r15), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x28(%r15,%rax)
jne 0xa10d
movl $0xa00000, %edx         # imm = 0xA00000
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x4340
movq 0x10(%r15), %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4390
jmp 0x9e47
movq 0x68(%rsp), %rdi
callq 0x4030
movq %rax, 0x90(%rsp)
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x458(%r15), %rbx
movq 0x70(%rsp), %rsi
pushq $0x8
popq %rdx
movq %rbx, %rdi
callq 0x4280
leaq 0x4d8(%r15), %rdi
callq 0x40b0
testb %al, %al
je 0xa2f4
leaq 0x458(%r13), %r14
movq 0x98(%rsp), %rsi
pushq $0x10
popq %rdx
movq %r14, %rdi
callq 0x4280
leaq 0x4d8(%r13), %rdi
callq 0x40b0
testb %al, %al
je 0xa32d
leaq 0x218(%r15), %rax
movq %rax, 0x30(%rsp)
movq 0x218(%r15), %rsi
pushq $0xc
popq %rdx
movq 0x8(%rsp), %rdi
callq 0x4280
addq $0x88, %r15
movq %r15, %rdi
callq 0x40b0
testb %al, %al
je 0xa369
leaq 0x10(%rsp), %rsi
pushq $0x3
popq %rdx
movq 0x8(%rsp), %rdi
callq 0x4340
cmpb $0x6c, 0x10(%rsp)
jne 0xa3df
cmpb $0x1b, 0x11(%rsp)
jne 0xa3df
cmpb $0x1, 0x12(%rsp)
jne 0xa41b
leaq 0x218(%r13), %r15
movq 0x218(%r13), %rsi
pushq $0x34
popq %rdx
movq %rbp, %rdi
callq 0x4280
movq 0x38(%rsp), %rdi
callq 0x40b0
testb %al, %al
je 0xa4ca
movq %r14, 0xb8(%rsp)
leaq 0x10(%rsp), %rsi
movb $0x1, 0x2(%rsi)
movw $0x1b6c, (%rsi)         # imm = 0x1B6C
leaq 0x18(%r13), %rdi
pushq $0x3
popq %rdx
movq %rdi, 0x30(%rsp)
callq 0x4390
movq (%r12), %r14
pushq $0x8
popq %rdi
callq 0x42c0
movq %rbp, 0xc0(%rsp)
movq %rax, 0x38(%rsp)
movq %rax, %rdi
callq 0x12bf2
addq $0x468, %r13            # imm = 0x468
movq %r13, 0xc8(%rsp)
xorl %r13d, %r13d
movabsq $0x7fffffffffffffff, %rbp # imm = 0x7FFFFFFFFFFFFFFF
pushq $0xa
popq %r15
movq %r14, %r12
subq $0x1, %r12
jb 0xa1d3
movq %r14, %xmm0
movq 0xa48f(%rip), %xmm2     # 0x144a0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0xa493(%rip), %xmm3     # 0x144b0
subpd %xmm3, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movq 0x60(%rsp), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm3, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd %xmm1, 0xd0(%rsp)
movq 0x38(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
callq 0x12edc
movq %rax, %r14
addq %rax, %r13
movq %r13, %rsi
imulq 0x68(%rsp), %rsi
addq $0x3, %rsi
movq 0x8(%rsp), %rdi
xorl %edx, %edx
callq 0x4350
movq 0x8(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x68(%rsp), %rdx
callq 0x4340
movq 0x30(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x68(%rsp), %rdx
callq 0x4390
movq %r14, %rax
notq %rax
addq %rax, 0x60(%rsp)
incq %r13
subq $0x1, %r14
jb 0xa0de
movq %rbx, %rdi
movq %rbp, %rsi
movl %r15d, %edx
callq 0x41a0
jmp 0xa0c8
movq %rbx, %rdi
leaq 0x40(%rsp), %rsi
callq 0x4060
movq 0xc8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x4270
movq %rax, %rdi
callq 0x4140
movq %r12, %r14
jmp 0x9ffa
movq 0x8(%rsp), %rdi
callq 0x4050
movq %rbp, %rdi
callq 0x4050
leaq 0x458(%r15), %rbx
movq 0x70(%rsp), %rsi
pushq $0x8
popq %rdx
movq %rbx, %rdi
callq 0x4280
leaq 0x4d8(%r15), %rdi
callq 0x40b0
testb %al, %al
je 0xa53e
leaq 0x458(%r13), %r14
movq 0x98(%rsp), %rsi
pushq $0x10
popq %rdx
movq %r14, %rdi
callq 0x4280
leaq 0x4d8(%r13), %rdi
callq 0x40b0
testb %al, %al
je 0xa57a
addq $0x468, %r13            # imm = 0x468
movq 0x458(%r15), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x478(%r15,%rax)
jne 0xa1b9
movl $0xa00000, %edx         # imm = 0xA00000
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4340
movq 0x460(%r15), %rdx
movq %r13, %rdi
movq %r12, %rsi
callq 0x4390
jmp 0xa17f
movq %rbx, %rdi
callq 0x4050
movq %r14, %rdi
callq 0x4050
movq %r12, %rdi
callq 0x4370
jmp 0xa234
movq 0x8(%rsp), %rdi
callq 0x4050
movq 0xc0(%rsp), %rdi
callq 0x4050
movq %rbx, %rdi
callq 0x4050
movq 0xb8(%rsp), %rdi
callq 0x4050
movq 0x90(%rsp), %rdi
callq 0x4370
movq 0x38(%rsp), %rbx
movq (%rbx), %rdi
testq %rdi, %rdi
je 0xa21f
movq (%rdi), %rax
callq *0x8(%rax)
pushq $0x8
popq %rsi
movq %rbx, %rdi
callq 0x42d0
leaq 0x40(%rsp), %rdi
callq 0x4558
leaq 0x98(%rsp), %rdi
callq 0x4558
leaq 0x70(%rsp), %rdi
callq 0x4558
leaq 0xd8(%rsp), %rdi
callq 0x4558
leaq 0xf8(%rsp), %rdi
callq 0x4558
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x11d72(%rip), %rdi     # 0x1bff0
leaq 0xa515(%rip), %rsi      # 0x1479a
callq 0x42a0
leaq 0xd8(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0xa2cb(%rip), %rsi      # 0x1456c
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0xa2ed
movq 0x11d36(%rip), %rdi     # 0x1bff0
leaq 0xa4d9(%rip), %rsi      # 0x1479a
callq 0x42a0
leaq 0xf8(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0xa405(%rip), %rsi      # 0x146e2
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
pushq $0x2
jmp 0xad30
movq 0x11cf5(%rip), %rdi     # 0x1bff0
leaq 0xa5b7(%rip), %rsi      # 0x148b9
callq 0x42a0
leaq 0x70(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0xa251(%rip), %rsi      # 0x1456c
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0xa2ed
movq 0x11cbc(%rip), %rdi     # 0x1bff0
leaq 0xa57e(%rip), %rsi      # 0x148b9
callq 0x42a0
leaq 0x98(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0xa38b(%rip), %rsi      # 0x146e2
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0xa2ed
movq 0x11c80(%rip), %rdi     # 0x1bff0
leaq 0xa603(%rip), %rsi      # 0x1497a
callq 0x42a0
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x4270
leaq 0xa1dc(%rip), %rsi      # 0x1456c
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0xa2ed
movq 0x11c44(%rip), %rdi     # 0x1bff0
leaq 0xa5c7(%rip), %rsi      # 0x1497a
callq 0x42a0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4270
leaq 0xa1a2(%rip), %rsi      # 0x1456c
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0xa2ed
movq 0x11c0a(%rip), %rdi     # 0x1bff0
leaq 0xa469(%rip), %rsi      # 0x14856
callq 0x42a0
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x4270
leaq 0xa464(%rip), %rsi      # 0x1486a
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0xa2ed
movq 0x11bce(%rip), %rdi     # 0x1bff0
leaq 0xa42d(%rip), %rsi      # 0x14856
callq 0x42a0
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x4270
leaq 0xa43f(%rip), %rsi      # 0x14881
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0xa4c3
movq 0x11b95(%rip), %rdi     # 0x1bff0
leaq 0xa3f4(%rip), %rsi      # 0x14856
callq 0x42a0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4270
leaq 0xa3f1(%rip), %rsi      # 0x1486a
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0xa2ed
movq 0x11b5b(%rip), %rdi     # 0x1bff0
leaq 0xa3ba(%rip), %rsi      # 0x14856
callq 0x42a0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4270
leaq 0xa3ce(%rip), %rsi      # 0x14881
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
pushq $0x3
jmp 0xad30
movq 0x11b1f(%rip), %rdi     # 0x1bff0
leaq 0xa4a2(%rip), %rsi      # 0x1497a
callq 0x42a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x4270
leaq 0xa1f3(%rip), %rsi      # 0x146e2
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0xa2ed
movq 0x11ae5(%rip), %rdi     # 0x1bff0
leaq 0xa468(%rip), %rsi      # 0x1497a
callq 0x42a0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4270
leaq 0xa1b9(%rip), %rsi      # 0x146e2
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0xa2ed
movq 0x11aab(%rip), %rdi     # 0x1bff0
leaq 0xa36d(%rip), %rsi      # 0x148b9
callq 0x42a0
leaq 0x70(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0xa007(%rip), %rsi      # 0x1456c
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0xa2ed
movq 0x11a6f(%rip), %rdi     # 0x1bff0
leaq 0xa331(%rip), %rsi      # 0x148b9
callq 0x42a0
leaq 0x98(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0xa13e(%rip), %rsi      # 0x146e2
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0xa2ed
movq %rdx, %rbx
movq %rax, %r14
pushq $0x8
popq %rsi
movq 0x38(%rsp), %rdi
callq 0x42d0
jmp 0xa5d4
movq %rdx, %rbx
movq %rax, %r14
cmpl $0x3, %ebx
jne 0xad5e
movq %r14, %rdi
callq 0x4330
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x43b0
movq %r14, %rdi
callq 0x4110
movq 0x119ef(%rip), %rdi     # 0x1bff0
leaq 0xa11d(%rip), %rsi      # 0x14725
callq 0x42a0
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x4140
jmp 0xad2e
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x4558
callq 0x4470
jmp 0xad5e
jmp 0xa87f
movq %rax, %r14
cmpl $0x2, %edx
jne 0xad68
movq %r14, %rdi
callq 0x4110
movq 0x11992(%rip), %rdi     # 0x1bff0
leaq 0xa05c(%rip), %rsi      # 0x146c1
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0xa6b0
movq %rax, %r14
callq 0x4470
jmp 0xad68
movq %rax, %r14
cmpl $0x2, %edx
jne 0xad68
movq %r14, %rdi
callq 0x4110
movq 0x11954(%rip), %rdi     # 0x1bff0
leaq 0xa316(%rip), %rsi      # 0x149b9
callq 0x42a0
movq %rax, %rdi
callq 0x4140
pushq $0x4
jmp 0xad30
movq %rax, %r14
callq 0x4470
jmp 0xad68
movq %rax, %r14
cmpl $0x1, %edx
jne 0xad68
movq %r14, %rdi
callq 0x4110
movq %rax, %rbx
movq 0x1190e(%rip), %rdi     # 0x1bff0
leaq 0xa1f1(%rip), %rsi      # 0x148da
callq 0x42a0
leaq 0x98(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0x9fe9(%rip), %rsi      # 0x146ee
movq %rax, %rdi
callq 0x42a0
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x40(%rsp), %rdi
callq *0x20(%rax)
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
jmp 0xaab2
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x4558
jmp 0xa750
jmp 0xa74d
movq %rax, %r14
callq 0x4470
jmp 0xad68
movq %rax, %r14
cmpl $0x1, %edx
jne 0xad68
movq %r14, %rdi
callq 0x4110
movq %rax, %rbx
movq 0x11878(%rip), %rdi     # 0x1bff0
leaq 0xa15b(%rip), %rsi      # 0x148da
callq 0x42a0
leaq 0x70(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0xa265(%rip), %rsi      # 0x149fd
movq %rax, %rdi
callq 0x42a0
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x40(%rsp), %rdi
callq *0x20(%rax)
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
jmp 0xaab2
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x4558
jmp 0xa7e3
jmp 0xa7e0
movq %rax, %r14
callq 0x4470
jmp 0xad68
movq %rax, %r14
cmpl $0x1, %edx
jne 0xad68
movq %r14, %rdi
callq 0x4110
movq %rax, %r14
movq 0x117e5(%rip), %rdi     # 0x1bff0
leaq 0xa189(%rip), %rsi      # 0x1499b
callq 0x42a0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4270
leaq 0x9ec5(%rip), %rsi      # 0x146ee
movq %rax, %rdi
callq 0x42a0
movq %rax, %rbx
movq 0x18(%r14), %rsi
movl 0x10(%r14), %edx
movq (%rsi), %rax
leaq 0x40(%rsp), %rdi
callq *0x20(%rax)
leaq 0x40(%rsp), %rsi
movq %rbx, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
jmp 0xaab2
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x4558
jmp 0xa875
jmp 0xa872
movq %rax, %r14
callq 0x4470
jmp 0xad68
movq %rax, %r14
cmpl $0x1, %edx
jne 0xad5e
movq %r14, %rdi
callq 0x4110
movq %rax, %rbx
movq 0x11753(%rip), %rdi     # 0x1bff0
leaq 0xa0f7(%rip), %rsi      # 0x1499b
callq 0x42a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x4270
leaq 0x9e33(%rip), %rsi      # 0x146ee
movq %rax, %rdi
callq 0x42a0
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x10(%rsp), %rdi
callq *0x20(%rax)
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
jmp 0xab4a
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x4558
jmp 0xa906
jmp 0xa903
movq %rax, %r14
callq 0x4470
jmp 0xad5e
jmp 0xaa43
jmp 0xaada
movq %rax, %r14
cmpl $0x1, %edx
jne 0xad5e
movq %r14, %rdi
callq 0x4110
movq %rax, %rbx
movq 0x116b8(%rip), %rdi     # 0x1bff0
leaq 0x9f9b(%rip), %rsi      # 0x148da
callq 0x42a0
leaq 0x98(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0x9d93(%rip), %rsi      # 0x146ee
movq %rax, %rdi
callq 0x42a0
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x10(%rsp), %rdi
callq *0x20(%rax)
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
jmp 0xab4a
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x4558
jmp 0xa9a6
jmp 0xa9a3
movq %rax, %r14
callq 0x4470
jmp 0xad5e
movq %rax, %r14
cmpl $0x1, %edx
jne 0xad5e
movq %r14, %rdi
callq 0x4110
movq %rax, %rbx
movq 0x11622(%rip), %rdi     # 0x1bff0
leaq 0x9f05(%rip), %rsi      # 0x148da
callq 0x42a0
leaq 0x70(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0xa00f(%rip), %rsi      # 0x149fd
movq %rax, %rdi
callq 0x42a0
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x10(%rsp), %rdi
callq *0x20(%rax)
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
jmp 0xab4a
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x4558
jmp 0xaa39
jmp 0xaa36
movq %rax, %r14
callq 0x4470
jmp 0xad5e
movq %rax, %r14
cmpl $0x1, %edx
jne 0xad68
movq %r14, %rdi
callq 0x4110
movq %rax, %r14
movq 0x1158f(%rip), %rdi     # 0x1bff0
leaq 0x9f33(%rip), %rsi      # 0x1499b
callq 0x42a0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4270
leaq 0x9f7e(%rip), %rsi      # 0x149fd
movq %rax, %rdi
callq 0x42a0
movq %rax, %rbx
movq 0x18(%r14), %rsi
movl 0x10(%r14), %edx
movq (%rsi), %rax
leaq 0x40(%rsp), %rdi
callq *0x20(%rax)
leaq 0x40(%rsp), %rsi
movq %rbx, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
leaq 0x40(%rsp), %rdi
jmp 0xacac
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x4558
jmp 0xaad0
jmp 0xaacd
movq %rax, %r14
callq 0x4470
jmp 0xad68
movq %rax, %r14
cmpl $0x1, %edx
jne 0xad5e
movq %r14, %rdi
callq 0x4110
movq %rax, %rbx
movq 0x114f8(%rip), %rdi     # 0x1bff0
leaq 0x9e9c(%rip), %rsi      # 0x1499b
callq 0x42a0
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x4270
leaq 0x9ee5(%rip), %rsi      # 0x149fd
movq %rax, %rdi
callq 0x42a0
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x10(%rsp), %rdi
callq *0x20(%rax)
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
leaq 0x10(%rsp), %rdi
jmp 0xacac
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x4558
jmp 0xab68
jmp 0xab65
movq %rax, %r14
callq 0x4470
jmp 0xad5e
jmp 0xad5b
jmp 0xad54
movq %rax, %r14
jmp 0xad75
jmp 0xab8a
jmp 0xab8a
jmp 0xab8a
movq %rax, %r14
jmp 0xad7f
movq %rax, %r14
jmp 0xad8c
movq %rax, %r14
cmpl $0x1, %edx
jne 0xad7f
movq %r14, %rdi
callq 0x4110
movq %rax, %rbx
movq 0x11438(%rip), %rdi     # 0x1bff0
leaq 0x9bfc(%rip), %rsi      # 0x147bb
callq 0x42a0
addq $0x218, %r13            # imm = 0x218
movq %rax, %rdi
movq %r13, %rsi
callq 0x4270
leaq 0x9b11(%rip), %rsi      # 0x146ee
movq %rax, %rdi
callq 0x42a0
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x70(%rsp), %rdi
callq *0x20(%rax)
leaq 0x70(%rsp), %rsi
movq %r14, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
jmp 0xaca7
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0x4558
jmp 0xac28
jmp 0xac25
movq %rax, %r14
callq 0x4470
jmp 0xad7f
movq %rax, %r14
cmpl $0x1, %edx
jne 0xad7f
movq %r14, %rdi
callq 0x4110
movq %rax, %rbx
movq 0x113a0(%rip), %rdi     # 0x1bff0
leaq 0x9b64(%rip), %rsi      # 0x147bb
callq 0x42a0
addq $0x218, %r15            # imm = 0x218
movq %rax, %rdi
movq %r15, %rsi
callq 0x4270
leaq 0x9d88(%rip), %rsi      # 0x149fd
movq %rax, %rdi
callq 0x42a0
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x70(%rsp), %rdi
callq *0x20(%rax)
leaq 0x70(%rsp), %rsi
movq %r14, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
leaq 0x70(%rsp), %rdi
callq 0x4558
leaq 0x9b5a(%rip), %rdi      # 0x14812
callq 0x4250
pushq $0x1
jmp 0xad30
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0x4558
jmp 0xacd5
jmp 0xacd2
movq %rax, %r14
callq 0x4470
jmp 0xad7f
jmp 0xad54
movq %rax, %r14
cmpl $0x3, %edx
jne 0xad5e
movq %r14, %rdi
callq 0x4330
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x43b0
movq %r14, %rdi
callq 0x4110
movq 0x112e3(%rip), %rdi     # 0x1bff0
leaq 0x9a11(%rip), %rsi      # 0x14725
callq 0x42a0
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x4140
pushq $0x5
popq %rdi
callq 0x4310
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x4558
callq 0x4470
jmp 0xad5e
movq %rax, %rdi
callq 0x6194
jmp 0xad54
movq %rax, %r14
jmp 0xad68
jmp 0xad5b
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x4558
leaq 0x98(%rsp), %rdi
callq 0x4558
leaq 0x70(%rsp), %rdi
callq 0x4558
leaq 0xd8(%rsp), %rdi
callq 0x4558
leaq 0xf8(%rsp), %rdi
callq 0x4558
movq %r14, %rdi
callq 0x44d0
nop