// File: /workspace/github_cpp_makefile_star2_O2/auton1[P]viterbi/variant_file.cpp
// Function: variant_file::add_file(parameters const&, std::vector<std::vector<bool, std::allocator<bool>>, std::allocator<std::vector<bool, std::allocator<bool>>>>&, std::vector<unsigned int, std::allocator<unsigned int>>&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&)
int variant_file::add_file(const parameters &params, vector<vector<bool> > &haplotypes, vector<unsigned int> &positions, vector<string> &haplotype_names, vector<string> &alleles)
{
	int passed_sites = 0;
	unsigned int N_chr = 2*N_kept_individuals();
	vector<vector<bool> > new_haplotypes;
	vector<unsigned int> new_positions;
	vector<string> new_alleles;
	
	new_haplotypes.resize(N_chr);
	
	for (unsigned int ui=0; ui<N_kept_individuals(); ui++)
	{
		if (include_indv[ui] == false)
			continue;
		haplotype_names.push_back(meta_data.indv[ui] + "_1");
		haplotype_names.push_back(meta_data.indv[ui] + "_2");
	}

	vector<char> variant_line;
	entry *e = get_entry_object();
	unsigned int N_alleles;

	while(!eof())
	{
		get_entry(variant_line);
		e->reset(variant_line);
		N_entries += e->apply_filters(params);

		if(!e->passed_filters)
			continue;
		N_kept_entries++;
		e->parse_basic_entry(true);

		e->parse_genotype_entries(true);
		N_alleles = e->get_N_alleles();

		if (N_alleles != 2)
		{
			LOG.one_off_warning("\tWarning: Only using biallelic sites.");
			continue;
		}
		if (e->is_diploid() == false)
		{
			LOG.one_off_warning("\tWarning: Only using fully diploid sites.");
			continue;
		}

		vector<bool> tmp;
		tmp.reserve(meta_data.N_indv*2);
		int allele_count = 0;

		pair<int, int> geno;
		bool skip = false;
		for (unsigned int ui=0; ui<meta_data.N_indv; ui++)
		{
			if (e->include_indv[ui] == false)
				continue;

			if (e->include_genotype[ui] == true)
			{
				e->get_indv_GENOTYPE_ids(ui, geno);
				if ((geno.first > 1) || (geno.second > 1))
					LOG.error("Only supporting biallelics... something bad happened", 1);
				if ((geno.first != -1) && (geno.second != -1))
				{
					tmp.push_back((bool)geno.first);
					tmp.push_back((bool)geno.second);
					allele_count += geno.first;
					allele_count += geno.second;
				}
				else
				{
					skip = true;
					LOG.one_off_warning("\tWarning: Only using sites without missing data.");
					break;
				}
			}
			else
			{
				skip = true;
				LOG.one_off_warning("\tWarning: Only using sites without missing data.");
				break;
			}
		}

		if (skip == true)
			continue;

		if (N_chr != tmp.size())
			LOG.error("Something unexpected happened.... oh dear.");

		string chr = e->get_CHROM();
		passed_sites++;

		new_alleles.push_back(e->get_REF());
		new_alleles.push_back(e->get_ALT());
		new_positions.push_back(e->get_POS());

		for (unsigned int ui=0; ui<tmp.size(); ui++)
			new_haplotypes[ui].push_back(tmp[ui]);
		
	}
	vector<vector<bool> > merged_haplotypes;
	vector<unsigned int> merged_positions;
	vector<string> merged_alleles;
	
	merged_haplotypes.resize(haplotypes.size()+new_haplotypes.size());
	for (unsigned int ui=0; ui<positions.size(); ui++)
	{
		int idx = find(new_positions.begin(), new_positions.end(), positions[ui]) - new_positions.begin();

		if (idx >= 0 && idx < new_positions.size())
		{
			if (alleles[2*ui] == new_alleles[2*idx] && alleles[2*ui+1] == new_alleles[2*idx+1])
			{
				merged_positions.push_back(positions[ui]);
				for (unsigned int uj=0; uj<haplotypes.size(); uj++)
					merged_haplotypes[uj].push_back(haplotypes[uj][ui]);

				for (unsigned int uj=0; uj<new_haplotypes.size(); uj++)
					merged_haplotypes[haplotypes.size()+uj].push_back(new_haplotypes[uj][idx]);
			}
		}
	}
	haplotypes = merged_haplotypes;
	positions = merged_positions;
	
	delete e;
	return passed_sites;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %r9, 0xa0(%rsp)
movq %r8, %r15
movq %rcx, 0x50(%rsp)
movq %rdx, 0x40(%rsp)
movq %rsi, %r14
movq %rdi, %r12
callq 0xe91e
addl %eax, %eax
xorps %xmm0, %xmm0
leaq 0xd0(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movaps %xmm0, 0x80(%rsp)
andq $0x0, 0x90(%rsp)
movaps %xmm0, 0xb0(%rsp)
andq $0x0, 0xc0(%rsp)
movq %rax, 0x118(%rsp)
movq %rax, %rsi
callq 0x9cde
leaq 0x430(%r12), %rax
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
leaq 0x10(%rsp), %rbx
xorl %ebp, %ebp
movq %r12, %rdi
callq 0xe91e
movl %eax, %eax
cmpq %rax, %rbp
jae 0xf57a
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x9cc0
testq %rdx, (%rax)
je 0xf56e
movq 0x260(%r12), %rsi
addq %r13, %rsi
movq %rbx, %rdi
leaq 0x1e286(%rip), %rdx     # 0x2d7af
callq 0xfdce
movq %r15, %rdi
movq %rbx, %rsi
callq 0x10122
movq %rbx, %rdi
callq 0x5908
movq 0x260(%r12), %rsi
addq %r13, %rsi
movq %rbx, %rdi
leaq 0x1e25c(%rip), %rdx     # 0x2d7b2
callq 0xfdce
movq %r15, %rdi
movq %rbx, %rsi
callq 0x10122
movq %rbx, %rdi
callq 0x5908
incq %rbp
addq $0x20, %r13
jmp 0xf4f3
xorps %xmm0, %xmm0
movaps %xmm0, 0x120(%rsp)
andq $0x0, 0x130(%rsp)
movq (%r12), %rax
movq %r12, %rdi
callq *0x28(%rax)
movq %rax, %rbx
addq $0x1f0, %rax            # imm = 0x1F0
movq %rax, 0x8(%rsp)
leaq 0x218(%rbx), %rax
movq %rax, 0x58(%rsp)
movq $0x0, 0x48(%rsp)
leaq 0x120(%rsp), %r15
movq %rbx, 0xa8(%rsp)
movq (%r12), %rax
movq %r12, %rdi
callq *0x18(%rax)
testb %al, %al
jne 0xf97e
movq (%r12), %rax
movq %r12, %rdi
movq %r15, %rsi
callq *0x20(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
callq *0x30(%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21614
addl %eax, 0x458(%r12)
cmpb $0x0, 0xc(%rbx)
je 0xf5cb
incl 0x45c(%r12)
movq (%rbx), %rax
movq %rbx, %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq *0x10(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq *0x28(%rax)
movq %rbx, %rdi
callq 0x1ce64
cmpl $0x2, %eax
jne 0xf680
movq %rbx, %rdi
callq 0x1bf02
testb %al, %al
jne 0xf6b8
leaq 0x1b8(%rsp), %r13
movq %r13, %rdi
leaq 0x1e176(%rip), %rsi     # 0x2d7db
leaq 0x10(%rsp), %rdx
callq 0x5160
leaq 0x31e5a(%rip), %rdi     # 0x414d0
movq %r13, %rsi
callq 0x2c10c
jmp 0xf6ab
leaq 0x1d8(%rsp), %r13
movq %r13, %rdi
leaq 0x1e123(%rip), %rsi     # 0x2d7b5
leaq 0x10(%rsp), %rdx
callq 0x5160
leaq 0x31e2d(%rip), %rdi     # 0x414d0
movq %r13, %rsi
callq 0x2c10c
movq %r13, %rdi
callq 0x5908
jmp 0xf5cb
andq $0x0, 0x10(%rsp)
andl $0x0, 0x18(%rsp)
andq $0x0, 0x20(%rsp)
andl $0x0, 0x28(%rsp)
andq $0x0, 0x30(%rsp)
movl 0x2a8(%r12), %esi
addl %esi, %esi
leaq 0x10(%rsp), %rdi
callq 0xfe06
andq $0x0, (%rsp)
xorl %ebp, %ebp
movl 0x2a8(%r12), %eax
cmpq %rax, %rbp
jae 0xf7d4
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x9cc0
testq %rdx, (%rax)
je 0xf7cc
movq 0x58(%rsp), %rdi
movq %rbp, %rsi
callq 0x9cc0
testq %rdx, (%rax)
je 0xf90c
movq %rbx, %rdi
movl %ebp, %esi
movq %rsp, %rdx
callq 0x1cb02
movl (%rsp), %eax
movl 0x4(%rsp), %ecx
cmpl $0x2, %eax
setge %dl
cmpl $0x2, %ecx
setge %sil
orb %dl, %sil
cmpb $0x1, %sil
jne 0xf793
leaq 0x198(%rsp), %r13
movq %r13, %rdi
leaq 0x1e09d(%rip), %rsi     # 0x2d805
leaq 0x60(%rsp), %rdx
callq 0x5160
leaq 0x31d57(%rip), %rdi     # 0x414d0
movq %r13, %rsi
pushq $0x1
popq %rdx
callq 0x2bf18
movq %r13, %rdi
callq 0x5908
movl (%rsp), %eax
movl 0x4(%rsp), %ecx
cmpl $-0x1, %eax
je 0xf93c
cmpl $-0x1, %ecx
je 0xf93c
xorl %esi, %esi
testl %eax, %eax
setne %sil
leaq 0x10(%rsp), %rdi
callq 0x9d32
xorl %esi, %esi
cmpl $0x0, 0x4(%rsp)
setne %sil
leaq 0x10(%rsp), %rdi
callq 0x9d32
incq %rbp
jmp 0xf6ef
movq 0x20(%rsp), %rax
movl 0x28(%rsp), %ecx
subq 0x10(%rsp), %rax
leaq (%rcx,%rax,8), %rax
cmpq 0x118(%rsp), %rax
je 0xf826
leaq 0x138(%rsp), %r13
movq %r13, %rdi
leaq 0x1e069(%rip), %rsi     # 0x2d86b
leaq 0x60(%rsp), %rdx
callq 0x5160
leaq 0x31cbd(%rip), %rdi     # 0x414d0
movq %r13, %rsi
pushq $0x1
popq %rdx
callq 0x2bf18
movq %r13, %rdi
callq 0x5908
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x1bc58
leaq 0xf0(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x1bcc8
leaq 0xb0(%rsp), %rdi
movq %r13, %rsi
callq 0x10122
movq %r13, %rdi
callq 0x5908
movq %r13, %rdi
movq %rbx, %rsi
callq 0x1bd18
leaq 0xb0(%rsp), %rdi
movq %r13, %rsi
callq 0x10122
movq %r13, %rdi
callq 0x5908
movq %rbx, %rdi
callq 0x1bc80
movl %eax, 0xf0(%rsp)
leaq 0x80(%rsp), %rdi
movq %r13, %rsi
callq 0x1027a
movq 0x48(%rsp), %rax
incl %eax
movq %rax, 0x48(%rsp)
xorl %ebx, %ebx
movl %ebx, %ebx
movq 0x20(%rsp), %rax
movl 0x28(%rsp), %ecx
subq 0x10(%rsp), %rax
leaq (%rcx,%rax,8), %rax
cmpq %rbx, %rax
jbe 0xf8f8
movq 0xd0(%rsp), %rbp
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x9cc0
imulq $0x28, %rbx, %rcx
addq %rcx, %rbp
xorl %esi, %esi
testq %rdx, (%rax)
setne %sil
movq %rbp, %rdi
callq 0x9d32
incl %ebx
jmp 0xf8ae
leaq 0x60(%rsp), %rdi
callq 0x5908
movq 0xa8(%rsp), %rbx
jmp 0xf96f
leaq 0x158(%rsp), %rbp
movq %rbp, %rdi
leaq 0x1df1c(%rip), %rsi     # 0x2d83a
leaq 0x60(%rsp), %rdx
callq 0x5160
leaq 0x31ba1(%rip), %rdi     # 0x414d0
movq %rbp, %rsi
callq 0x2c10c
movq %rbp, %rdi
jmp 0xf96a
leaq 0x178(%rsp), %r13
movq %r13, %rdi
leaq 0x1deec(%rip), %rsi     # 0x2d83a
leaq 0x60(%rsp), %rdx
callq 0x5160
leaq 0x31b71(%rip), %rdi     # 0x414d0
movq %r13, %rsi
callq 0x2c10c
movq %r13, %rdi
callq 0x5908
leaq 0x10(%rsp), %rdi
callq 0xa0a6
jmp 0xf5cb
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movaps %xmm0, 0x60(%rsp)
andq $0x0, 0x70(%rsp)
movaps %xmm0, 0xf0(%rsp)
andq $0x0, 0x100(%rsp)
movq 0x40(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
pushq $0x28
popq %r13
cqto
idivq %r13
movq %rax, %rsi
movq 0xd8(%rsp), %rax
subq 0xd0(%rsp), %rax
cqto
idivq %r13
addq %rax, %rsi
callq 0x9cde
xorl %r15d, %r15d
movl %r15d, %r15d
movq 0x50(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r15, %rcx
jbe 0xfbab
movq 0x80(%rsp), %rdi
movq 0x88(%rsp), %rsi
leaq (%rax,%r15,4), %rdx
callq 0x10359
movq 0x80(%rsp), %rcx
subq %rcx, %rax
sarq $0x2, %rax
testl %eax, %eax
js 0xfb9b
movl %eax, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq 0x88(%rsp), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
movq %rsi, 0x8(%rsp)
cmpq %rdx, %rsi
jae 0xfb9b
leal (%r15,%r15), %ebx
movq %rbx, %rdi
shlq $0x5, %rdi
movq 0xa0(%rsp), %rcx
addq (%rcx), %rdi
leal (%rax,%rax), %r12d
movq %r12, %rsi
shlq $0x5, %rsi
addq 0xb0(%rsp), %rsi
callq 0xfe37
testb %al, %al
je 0xfb9b
orl $0x1, %ebx
shlq $0x5, %rbx
movq 0xa0(%rsp), %rax
addq (%rax), %rbx
orl $0x1, %r12d
shlq $0x5, %r12
addq 0xb0(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0xfe37
testb %al, %al
je 0xfb9b
leaq (,%r15,4), %rsi
movq 0x50(%rsp), %rax
addq (%rax), %rsi
leaq 0x60(%rsp), %rdi
callq 0x9d14
xorl %r12d, %r12d
movl %r12d, %r12d
movq 0x40(%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %rax
subq %rdi, %rax
cqto
idivq %r13
cmpq %r12, %rax
jbe 0xfb27
movq 0x10(%rsp), %rbx
imulq $0x28, %r12, %r14
addq %r14, %rdi
movq %r15, %rsi
callq 0x9cc0
addq %r14, %rbx
xorl %esi, %esi
testq %rdx, (%rax)
setne %sil
movq %rbx, %rdi
callq 0x9d32
incl %r12d
jmp 0xfade
xorl %r12d, %r12d
movq %r15, 0x58(%rsp)
movl %r12d, %r12d
movq 0xd0(%rsp), %rdi
movq 0xd8(%rsp), %rax
subq %rdi, %rax
cqto
idivq %r13
cmpq %r12, %rax
jbe 0xfb9b
movq %r13, %r15
movq 0x40(%rsp), %rax
movq (%rax), %r14
movq 0x8(%rax), %r13
movq 0x10(%rsp), %rbx
imulq $0x28, %r12, %rbp
addq %rbp, %rdi
movq 0x8(%rsp), %rsi
callq 0x9cc0
subq %r14, %r13
addq %rbp, %rbx
addq %r13, %rbx
xorl %esi, %esi
testq %rdx, (%rax)
setne %sil
movq %rbx, %rdi
callq 0x9d32
incl %r12d
movq %r15, %r13
movq 0x58(%rsp), %r15
jmp 0xfb2f
incl %r15d
movq 0xa8(%rsp), %rbx
jmp 0xf9e2
leaq 0x10(%rsp), %rsi
movq 0x40(%rsp), %rdi
callq 0x9e32
leaq 0x60(%rsp), %rsi
movq 0x50(%rsp), %rdi
callq 0x9d70
testq %rbx, %rbx
je 0xfbd7
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
leaq 0xf0(%rsp), %rdi
callq 0x9f1c
leaq 0x60(%rsp), %rdi
callq 0xa14c
leaq 0x10(%rsp), %rdi
callq 0x9efa
leaq 0x120(%rsp), %rdi
callq 0xe88a
leaq 0xb0(%rsp), %rdi
callq 0x9f1c
leaq 0x80(%rsp), %rdi
callq 0xa14c
leaq 0xd0(%rsp), %rdi
callq 0x9efa
movq 0x48(%rsp), %rax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
jmp 0xfcb9
jmp 0xfcac
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
jmp 0xfcb9
jmp 0xfcac
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
jmp 0xfcb9
jmp 0xfcac
jmp 0xfc74
jmp 0xfcb1
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x5908
jmp 0xfcb4
jmp 0xfcb1
jmp 0xfcac
jmp 0xfcb1
jmp 0xfcac
jmp 0xfd33
jmp 0xfd06
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
jmp 0xfcb9
jmp 0xfcac
jmp 0xfcac
jmp 0xfd0d
jmp 0xfd0d
jmp 0xfcac
movq %rax, %rbx
jmp 0xfcbe
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x5908
leaq 0x10(%rsp), %rdi
callq 0xa0a6
jmp 0xfd36
jmp 0xfd33
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
jmp 0xfce4
movq %rax, %rbx
leaq 0x1d8(%rsp), %rdi
callq 0x5908
jmp 0xfd36
jmp 0xfd33
jmp 0xfcf3
jmp 0xfd06
jmp 0xfd06
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x5908
jmp 0xfd43
jmp 0xfd0d
jmp 0xfd06
movq %rax, %rbx
jmp 0xfd43
jmp 0xfd0d
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x9f1c
leaq 0x60(%rsp), %rdi
callq 0xa14c
leaq 0x10(%rsp), %rdi
callq 0x9efa
jmp 0xfd36
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0xe88a
leaq 0xb0(%rsp), %rdi
callq 0x9f1c
leaq 0x80(%rsp), %rdi
callq 0xa14c
leaq 0xd0(%rsp), %rdi
callq 0x9efa
movq %rbx, %rdi
callq 0x5800