// File: /workspace/github_cpp_makefile_star2_O2/auton1[P]viterbi/entry_filters.cpp
// Function: entry::filter_sites_by_mask(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool, int)
void entry::filter_sites_by_mask(const string &mask_file, bool invert_mask, int min_kept_mask_value)
{
	// Filter sites on the basis of a fasta-like mask file.
	if (passed_filters == false || mask_file == "")
		return;

	if (!mask.is_open())
	{
		mask.open(mask_file.c_str());
		mask_chr = "";
		mask_line = "";

		if (!mask.is_open())
			LOG.error("Could not open mask file: " + mask_file);
	}

	string line;
	string next_chr="";
	unsigned int next_pos = 0;

	parse_basic_entry();
	next_chr = CHROM;

	if (mask_chr != next_chr)
	{
		mask_chr = "";
		mask_line = "";
		while (!mask.eof())
		{
			getline(mask, line);
			line.erase( line.find_last_not_of(" \t") + 1);

			if (line[0] == '>')
			// Header
				mask_chr = line.substr(1, line.find_first_of(" \t")-1);
			else
			{
				mask_line = line;
				if (mask_chr == next_chr)
					break;
			}
		}
	}

	if (next_chr == mask_chr)
		next_pos = (unsigned)POS;
	else
	{
		passed_filters = false;
		return;
	}

	if (next_pos <= mask_line.size())
	{
		char mask_base = mask_line[next_pos-1]-48;
		bool keep = (mask_base <= min_kept_mask_value);

		if (invert_mask == true)
			keep = !keep;

		if (keep == false)
			passed_filters = false;
	}
	else
		passed_filters = false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %ecx, 0x8(%rsp)
movl %edx, 0xc(%rsp)
cmpb $0x0, 0xc(%rdi)
je 0x23821
movq %rsi, %rbx
movq %rdi, %r15
leaq 0xb85d(%rip), %rsi      # 0x2ee37
movq %rbx, %rdi
callq 0x96f3
testb %al, %al
jne 0x23821
leaq 0x1ee4f(%rip), %rdi     # 0x42440
callq 0x50d0
testb %al, %al
jne 0x23674
movq (%rbx), %rsi
leaq 0x1edc4(%rip), %rdi     # 0x423c8
pushq $0x8
popq %rdx
callq 0x5260
leaq 0x1efbd(%rip), %rdi     # 0x425d0
leaq 0xb81d(%rip), %r14      # 0x2ee37
movq %r14, %rsi
callq 0x58b0
leaq 0x1efc7(%rip), %rdi     # 0x425f0
movq %r14, %rsi
callq 0x58b0
leaq 0x1ee08(%rip), %rdi     # 0x42440
callq 0x50d0
testb %al, %al
jne 0x23674
leaq 0xb7d2(%rip), %rsi      # 0x2ee1a
leaq 0x58(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rdx
callq 0x967d
leaq 0x1de71(%rip), %rdi     # 0x414d0
pushq $0x1
popq %rdx
movq %r14, %rsi
callq 0x2bf18
leaq 0x58(%rsp), %rdi
callq 0x5908
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0xb7ab(%rip), %rsi      # 0x2ee37
leaq 0x18(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x5160
movq (%r15), %rax
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq *0x10(%rax)
leaq 0x3e0(%r15), %rsi
leaq 0x18(%rsp), %rdi
callq 0x5210
movq %r15, 0x10(%rsp)
leaq 0x1ef09(%rip), %rdi     # 0x425d0
leaq 0x18(%rsp), %rsi
callq 0x244a2
testb %al, %al
je 0x237c2
leaq 0x1eef0(%rip), %rdi     # 0x425d0
leaq 0xb750(%rip), %rsi      # 0x2ee37
callq 0x58b0
leaq 0x1eefd(%rip), %rdi     # 0x425f0
leaq 0xb73d(%rip), %rsi      # 0x2ee37
callq 0x58b0
leaq 0x1ecc2(%rip), %r15     # 0x423c8
leaq 0x38(%rsp), %r12
leaq 0xb723(%rip), %r13      # 0x2ee35
pushq $-0x1
popq %rbp
leaq 0x78(%rsp), %r14
leaq 0x1eeaf(%rip), %rbx     # 0x425d0
movq 0x1eca0(%rip), %rax     # 0x423c8
movq -0x18(%rax), %rax
testb $0x2, 0x20(%rax,%r15)
jne 0x237c2
movq %r15, %rdi
movq %r12, %rsi
callq 0x5090
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x5840
leaq 0x1(%rax), %rsi
movq %r12, %rdi
movq %rbp, %rdx
callq 0x50c0
movq 0x38(%rsp), %rax
cmpb $0x3e, (%rax)
jne 0x2379e
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x51f0
leaq -0x1(%rax), %rcx
movq %r14, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
callq 0x54c0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5580
movq %r14, %rdi
callq 0x5908
jmp 0x23721
leaq 0x1ee4b(%rip), %rdi     # 0x425f0
movq %r12, %rsi
callq 0x5210
movq %rbx, %rdi
leaq 0x18(%rsp), %rsi
callq 0xfe37
testb %al, %al
je 0x23721
leaq 0x1ee07(%rip), %rsi     # 0x425d0
leaq 0x18(%rsp), %rdi
callq 0xfe37
testb %al, %al
movq 0x10(%rsp), %rdx
je 0x23809
movl 0x400(%rdx), %eax
cmpq %rax, 0x1ee0f(%rip)     # 0x425f8
jb 0x23809
decl %eax
movq 0x1edfc(%rip), %rcx     # 0x425f0
movb (%rcx,%rax), %al
addb $-0x30, %al
movsbl %al, %eax
cmpl 0x8(%rsp), %eax
setle %al
xorb 0xc(%rsp), %al
jne 0x2380d
movb $0x0, 0xc(%rdx)
leaq 0x18(%rsp), %rdi
callq 0x5908
leaq 0x38(%rsp), %rdi
callq 0x5908
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
jmp 0x23858
movq %rax, %rbx
jmp 0x23853
jmp 0x23846
jmp 0x23846
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x5908
leaq 0x38(%rsp), %rdi
callq 0x5908
movq %rbx, %rdi
callq 0x5800
nop