// File: /workspace/github_cpp_makefile_star2_O2/auton1[P]viterbi/entry_filters.cpp
// Function: entry::filter_sites_by_positions(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void entry::filter_sites_by_positions(const string &positions_file, const string &exclude_positions_file)
{
	// Filter sites by a user defined file containing a list of positions
	if (passed_filters == false)
		return;

	if ((positions_file == "") && (exclude_positions_file == ""))
		return;

	int idx;
	if (keep_positions.empty() && positions_file != "")
	{
		string chr;
		int pos1;
		unsigned int N_chr=chr_to_idx.size();
		stringstream ss;
		string line;
		unsigned int gzMAX_LINE_LEN = 1024*1024;
		char *gz_readbuffer = new char[gzMAX_LINE_LEN];

		gzFile gz_in = gzopen(positions_file.c_str(), "rb");
		if (gz_in == NULL)
			LOG.error("Could not open Positions file: " + positions_file);

		while (!gzeof(gz_in))
		{
			line = "";
			bool again = true;
			while (again == true)
			{
				gzgets(gz_in, gz_readbuffer, gzMAX_LINE_LEN);
				line.append(gz_readbuffer);
				if (strlen(gz_readbuffer) != gzMAX_LINE_LEN-1)
					again = false;
			}
			if (line[0] == '#')
				continue;
			line.erase( line.find_last_not_of(" \t\n\r") + 1);	// Trim whitespace at end of line (required in gzipped case!)

			ss.clear();
			ss.str(line);
			ss >> chr >> pos1;

			if (chr_to_idx.find(chr) == chr_to_idx.end())
			{
				N_chr++;
				chr_to_idx[chr] = (N_chr-1);
				keep_positions.resize(N_chr);
			}

			idx = chr_to_idx[chr];
			keep_positions[idx].insert(pos1);
		}
		gzclose(gz_in);
		delete [] gz_readbuffer;
	}
	if (exclude_positions.empty() && exclude_positions_file != "")
	{
		string chr;
		int pos1;
		unsigned int N_chr=0;
		stringstream ss;
		string line;
		unsigned int gzMAX_LINE_LEN = 1024*1024;
		char *gz_readbuffer = new char[gzMAX_LINE_LEN];

		gzFile gz_in = gzopen(exclude_positions_file.c_str(), "rb");
		if (gz_in == NULL)
			LOG.error("Could not open Positions file: " + exclude_positions_file);

		while (!gzeof(gz_in))
		{
			line = "";
			bool again = true;
			while (again == true)
			{
				gzgets(gz_in, gz_readbuffer, gzMAX_LINE_LEN);
				line.append(gz_readbuffer);
				if (strlen(gz_readbuffer) != gzMAX_LINE_LEN-1)
					again = false;
			}
			if (line[0] == '#')
				continue;
			line.erase( line.find_last_not_of(" \t\n\r") + 1);	// Trim whitespace at end of line (required in gzipped case!)

			ss.clear();
			ss.str(line);
			ss >> chr >> pos1;

			if (chr_to_idx.find(chr) == chr_to_idx.end())
			{
				N_chr++;
				chr_to_idx[chr] = (N_chr-1);
				exclude_positions.resize(N_chr);
			}

			idx = chr_to_idx[chr];
			exclude_positions[idx].insert(pos1);
		}
		gzclose(gz_in);
		delete [] gz_readbuffer;
	}

	parse_basic_entry();

	if (!keep_positions.empty())
	{	// Check to see if position is in keep list
			if (chr_to_idx.find(CHROM) == chr_to_idx.end())
				passed_filters = false;
			else
			{
				idx = chr_to_idx[CHROM];
				bool found=false;

				if (keep_positions[idx].find(POS) != keep_positions[idx].end())
					found = true;

				if (found == false)
					passed_filters = false;
			}
	}
	if (!exclude_positions.empty())
	{	// Check to see if position is in exclude list
		if (chr_to_idx.find(CHROM) != chr_to_idx.end())
		{
			idx = chr_to_idx[CHROM];
			bool found=false;

			if (exclude_positions[idx].find(POS) != exclude_positions[idx].end())
				found = true;

				if (found == true)
					passed_filters = false;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
cmpb $0x0, 0xc(%rdi)
je 0x221f6
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0xd1cc(%rip), %rsi      # 0x2ee37
movq %r15, %rdi
callq 0x96f3
testb %al, %al
je 0x21c8e
leaq 0xd1b9(%rip), %rsi      # 0x2ee37
movq %r14, %rdi
callq 0x96f3
testb %al, %al
jne 0x221f6
movq 0x206bb(%rip), %rax     # 0x42350
cmpq 0x206bc(%rip), %rax     # 0x42358
jne 0x21ed2
leaq 0xd18e(%rip), %rsi      # 0x2ee37
movq %r15, %rdi
callq 0x12f17
testb %al, %al
je 0x21ed2
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl 0x206d7(%rip), %r12d    # 0x423a8
leaq 0xa0(%rsp), %rdi
callq 0x5300
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl $0x100000, %edi         # imm = 0x100000
callq 0x5030
movq %rax, %r13
movq (%r15), %rdi
leaq 0xb7a7(%rip), %rsi      # 0x2d4ad
callq 0x56a0
movq %rax, %rbp
testq %rax, %rax
jne 0x21d4e
leaq 0xd0ab(%rip), %rsi      # 0x2edc5
leaq 0x80(%rsp), %rdi
movq %r15, %rdx
callq 0x967d
leaq 0x1f79f(%rip), %rdi     # 0x414d0
leaq 0x80(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x2bf18
leaq 0x80(%rsp), %rdi
callq 0x5908
movq %r12, 0x18(%rsp)
leaq 0xd0dd(%rip), %r12      # 0x2ee37
leaq 0x40(%rsp), %r15
movq %rbp, %rdi
callq 0x5120
testl %eax, %eax
jne 0x21ea1
movq %r15, %rdi
movq %r12, %rsi
callq 0x58b0
movq %rbp, %rdi
movq %r13, %rsi
movl $0x100000, %edx         # imm = 0x100000
callq 0x57b0
movq %r15, %rdi
movq %r13, %rsi
callq 0x58a0
movq %r13, %rdi
callq 0x5190
cmpq $0xfffff, %rax          # imm = 0xFFFFF
je 0x21d7a
movq 0x40(%rsp), %rax
cmpb $0x23, (%rax)
je 0x21d5f
movq %r15, %rdi
leaq 0xb8e4(%rip), %rsi      # 0x2d69d
movq %r14, 0x10(%rsp)
pushq $-0x1
popq %r14
movq %r14, %rdx
callq 0x5840
leaq 0x1(%rax), %rsi
movq %r15, %rdi
movq %r14, %rdx
movq 0x10(%rsp), %r14
callq 0x50c0
movq 0xa0(%rsp), %rax
movq -0x18(%rax), %rdi
leaq 0xa0(%rsp), %rax
addq %rax, %rdi
xorl %esi, %esi
callq 0x5790
leaq 0xb8(%rsp), %rdi
movq %r15, %rsi
callq 0x5690
leaq 0xa0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x55c0
movq %rax, %rdi
leaq 0xc(%rsp), %rsi
callq 0x5250
leaq 0x2054e(%rip), %rdi     # 0x42380
leaq 0x20(%rsp), %rsi
callq 0x13a1a
leaq 0x20545(%rip), %rcx     # 0x42388
cmpq %rcx, %rax
jne 0x21e73
leaq 0x20531(%rip), %rdi     # 0x42380
leaq 0x20(%rsp), %rsi
callq 0x1316c
movq 0x18(%rsp), %rsi
movl %esi, (%rax)
incl %esi
leaq 0x204e7(%rip), %rdi     # 0x42350
movq %rsi, 0x18(%rsp)
callq 0x243ee
leaq 0x20506(%rip), %rdi     # 0x42380
leaq 0x20(%rsp), %rsi
callq 0x1316c
movslq (%rax), %rax
imulq $0x30, %rax, %rdi
addq 0x204be(%rip), %rdi     # 0x42350
leaq 0xc(%rsp), %rsi
callq 0x24c9c
jmp 0x21d5f
movq %rbp, %rdi
callq 0x5780
movq %r13, %rdi
callq 0x55e0
leaq 0x40(%rsp), %rdi
callq 0x5908
leaq 0xa0(%rsp), %rdi
callq 0x5360
leaq 0x20(%rsp), %rdi
callq 0x5908
movq 0x2048f(%rip), %rax     # 0x42368
cmpq 0x20490(%rip), %rax     # 0x42370
jne 0x220fd
leaq 0xcf4a(%rip), %rsi      # 0x2ee37
movq %r14, %rdi
callq 0x12f17
testb %al, %al
je 0x220fd
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0xa0(%rsp), %rdi
callq 0x5300
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl $0x100000, %edi         # imm = 0x100000
callq 0x5030
movq %rax, %r12
movq (%r14), %rdi
leaq 0xb56a(%rip), %rsi      # 0x2d4ad
callq 0x56a0
movq %rax, %r13
testq %rax, %rax
jne 0x21f82
leaq 0xce6e(%rip), %rsi      # 0x2edc5
leaq 0x60(%rsp), %rdi
movq %r14, %rdx
callq 0x967d
leaq 0x1f565(%rip), %rdi     # 0x414d0
leaq 0x60(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x2bf18
leaq 0x60(%rsp), %rdi
callq 0x5908
movq $0x0, 0x10(%rsp)
leaq 0xcea5(%rip), %rbp      # 0x2ee37
leaq 0x40(%rsp), %r15
movq %r13, %rdi
callq 0x5120
testl %eax, %eax
jne 0x220cc
movq %r15, %rdi
movq %rbp, %rsi
callq 0x58b0
movq %r13, %rdi
movq %r12, %rsi
movl $0x100000, %edx         # imm = 0x100000
callq 0x57b0
movq %r15, %rdi
movq %r12, %rsi
callq 0x58a0
movq %r12, %rdi
callq 0x5190
cmpq $0xfffff, %rax          # imm = 0xFFFFF
je 0x21fb2
movq 0x40(%rsp), %rax
cmpb $0x23, (%rax)
je 0x21f97
movq %r15, %rdi
leaq 0xb6ac(%rip), %rsi      # 0x2d69d
pushq $-0x1
popq %r14
movq %r14, %rdx
callq 0x5840
leaq 0x1(%rax), %rsi
movq %r15, %rdi
movq %r14, %rdx
leaq 0x20(%rsp), %r14
callq 0x50c0
movq 0xa0(%rsp), %rax
movq -0x18(%rax), %rdi
leaq 0xa0(%rsp), %rax
addq %rax, %rdi
xorl %esi, %esi
callq 0x5790
leaq 0xb8(%rsp), %rdi
movq %r15, %rsi
callq 0x5690
leaq 0xa0(%rsp), %rdi
movq %r14, %rsi
callq 0x55c0
movq %rax, %rdi
leaq 0xc(%rsp), %rsi
callq 0x5250
leaq 0x2031d(%rip), %rdi     # 0x42380
movq %r14, %rsi
callq 0x13a1a
leaq 0x20316(%rip), %rcx     # 0x42388
cmpq %rcx, %rax
jne 0x220a0
leaq 0x20302(%rip), %rdi     # 0x42380
movq %r14, %rsi
callq 0x1316c
movq 0x10(%rsp), %rsi
movl %esi, (%rax)
incl %esi
leaq 0x202d2(%rip), %rdi     # 0x42368
movq %rsi, 0x10(%rsp)
callq 0x243ee
leaq 0x202d9(%rip), %rdi     # 0x42380
movq %r14, %rsi
callq 0x1316c
movslq (%rax), %rax
imulq $0x30, %rax, %rdi
addq 0x202ab(%rip), %rdi     # 0x42368
leaq 0xc(%rsp), %rsi
callq 0x24c9c
jmp 0x21f97
movq %r13, %rdi
callq 0x5780
movq %r12, %rdi
callq 0x55e0
leaq 0x40(%rsp), %rdi
callq 0x5908
leaq 0xa0(%rsp), %rdi
callq 0x5360
leaq 0x20(%rsp), %rdi
callq 0x5908
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq *0x10(%rax)
movq 0x2023d(%rip), %rax     # 0x42350
cmpq 0x2023e(%rip), %rax     # 0x42358
je 0x22181
leaq 0x3e0(%rbx), %r14
leaq 0x20256(%rip), %rdi     # 0x42380
movq %r14, %rsi
callq 0x13a1a
leaq 0x2024f(%rip), %rcx     # 0x42388
cmpq %rcx, %rax
je 0x2217d
leaq 0x2023b(%rip), %rdi     # 0x42380
movq %r14, %rsi
callq 0x1316c
movslq (%rax), %rax
imulq $0x30, %rax, %r14
movq 0x201f5(%rip), %rdi     # 0x42350
addq %r14, %rdi
leaq 0x400(%rbx), %rsi
callq 0x24dee
movq 0x201df(%rip), %rcx     # 0x42350
addq %r14, %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
jne 0x22181
movb $0x0, 0xc(%rbx)
movq 0x201e0(%rip), %rax     # 0x42368
cmpq 0x201e1(%rip), %rax     # 0x42370
je 0x221f6
leaq 0x3e0(%rbx), %r14
leaq 0x201e1(%rip), %rdi     # 0x42380
movq %r14, %rsi
callq 0x13a1a
leaq 0x201da(%rip), %rcx     # 0x42388
cmpq %rcx, %rax
je 0x221f6
leaq 0x201c6(%rip), %rdi     # 0x42380
movq %r14, %rsi
callq 0x1316c
movslq (%rax), %rax
imulq $0x30, %rax, %r14
movq 0x20198(%rip), %rdi     # 0x42368
addq %r14, %rdi
leaq 0x400(%rbx), %rsi
callq 0x24dee
movq 0x20182(%rip), %rcx     # 0x42368
addq %r14, %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
je 0x221f6
movb $0x0, 0xc(%rbx)
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
jmp 0x2221d
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x5908
jmp 0x22244
jmp 0x22241
jmp 0x22241
jmp 0x22241
jmp 0x2222e
jmp 0x22241
movq %rax, %rbx
jmp 0x2225b
jmp 0x22241
jmp 0x22241
jmp 0x22241
jmp 0x22241
jmp 0x22241
jmp 0x22241
jmp 0x22241
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x5908
leaq 0xa0(%rsp), %rdi
callq 0x5360
leaq 0x20(%rsp), %rdi
callq 0x5908
movq %rbx, %rdi
callq 0x5800
nop