// File: 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:
subq $0x108, %rsp            # imm = 0x108
movb %dl, %al
movq %rdi, 0x100(%rsp)
movq %rsi, 0xf8(%rsp)
andb $0x1, %al
movb %al, 0xf7(%rsp)
movl %ecx, 0xf0(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0x48(%rsp)
movb 0xc(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x5d46d
movq 0xf8(%rsp), %rdi
leaq 0x188c7(%rip), %rsi     # 0x75d29
callq 0xea20
testb $0x1, %al
jne 0x5d46d
jmp 0x5d472
jmp 0x5d895
leaq 0x3707f(%rip), %rdi     # 0x944f8
callq 0x68d0
testb $0x1, %al
jne 0x5d54d
movq 0xf8(%rsp), %rdi
callq 0x61a0
movq %rax, %rsi
leaq 0x3705b(%rip), %rdi     # 0x944f8
movl $0x8, %edx
callq 0x62c0
leaq 0x37252(%rip), %rdi     # 0x94700
leaq 0x18874(%rip), %rsi     # 0x75d29
callq 0x67b0
leaq 0x3725f(%rip), %rdi     # 0x94720
leaq 0x18861(%rip), %rsi     # 0x75d29
callq 0x67b0
leaq 0x37024(%rip), %rdi     # 0x944f8
callq 0x68d0
testb $0x1, %al
jne 0x5d54b
movq 0xf8(%rsp), %rdx
leaq 0x18820(%rip), %rsi     # 0x75d0c
leaq 0xd0(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0xe8d0
movq 0x40(%rsp), %rsi
leaq 0x360f6(%rip), %rdi     # 0x93600
movl $0x1, %edx
callq 0x712f0
jmp 0x5d516
leaq 0xd0(%rsp), %rdi
callq 0x6b50
jmp 0x5d54b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x6b50
jmp 0x5d8aa
jmp 0x5d54d
leaq 0xa0(%rsp), %rdi
callq 0x67e0
leaq 0x7f(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x69f0
movq 0x38(%rsp), %rdx
leaq 0x187b4(%rip), %rsi     # 0x75d29
leaq 0x80(%rsp), %rdi
callq 0x67c0
jmp 0x5d584
leaq 0x7f(%rsp), %rdi
callq 0x65f0
movq 0x48(%rsp), %rdi
movl $0x0, 0x78(%rsp)
movq (%rdi), %rax
movq 0x10(%rax), %rax
xorl %ecx, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq *%rax
jmp 0x5d5ac
movq 0x48(%rsp), %rsi
addq $0x3e0, %rsi            # imm = 0x3E0
leaq 0x80(%rsp), %rdi
callq 0x6060
jmp 0x5d5c7
leaq 0x37132(%rip), %rdi     # 0x94700
leaq 0x80(%rsp), %rsi
callq 0x5f290
testb $0x1, %al
jne 0x5d5e4
jmp 0x5d794
leaq 0x37115(%rip), %rdi     # 0x94700
leaq 0x18737(%rip), %rsi     # 0x75d29
callq 0x67b0
jmp 0x5d5f9
leaq 0x37120(%rip), %rdi     # 0x94720
leaq 0x18722(%rip), %rsi     # 0x75d29
callq 0x67b0
jmp 0x5d60e
jmp 0x5d610
leaq 0x36ee1(%rip), %rdi     # 0x944f8
movq 0x36eda(%rip), %rax     # 0x944f8
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x6a70
movb %al, 0x37(%rsp)
jmp 0x5d630
movb 0x37(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x5d63f
jmp 0x5d792
leaq 0x36eb2(%rip), %rdi     # 0x944f8
leaq 0xa0(%rsp), %rsi
callq 0x60c0
jmp 0x5d655
leaq 0x186cb(%rip), %rsi     # 0x75d27
leaq 0xa0(%rsp), %rdi
movq %rdi, 0x20(%rsp)
movq $-0x1, %rdx
movq %rdx, 0x28(%rsp)
callq 0x6a30
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rdx
movq %rax, %rsi
incq %rsi
callq 0x60f0
jmp 0x5d691
xorl %eax, %eax
movl %eax, %esi
leaq 0xa0(%rsp), %rdi
callq 0x6b20
movq %rax, 0x18(%rsp)
jmp 0x5d6a9
movq 0x18(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x3e, %eax
jne 0x5d759
leaq 0x18666(%rip), %rsi     # 0x75d27
xorl %eax, %eax
movl %eax, %edx
leaq 0xa0(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x6230
movq 0x10(%rsp), %rsi
movq %rax, %rcx
decq %rcx
leaq 0x58(%rsp), %rdi
movl $0x1, %edx
callq 0x6580
jmp 0x5d6f3
leaq 0x37006(%rip), %rdi     # 0x94700
leaq 0x58(%rsp), %rsi
callq 0x66c0
leaq 0x58(%rsp), %rdi
callq 0x6b50
jmp 0x5d78d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
leaq 0x7f(%rsp), %rdi
callq 0x65f0
jmp 0x5d89d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x6b50
jmp 0x5d89d
leaq 0x36fc0(%rip), %rdi     # 0x94720
leaq 0xa0(%rsp), %rsi
callq 0x6060
jmp 0x5d76f
leaq 0x36f8a(%rip), %rdi     # 0x94700
leaq 0x80(%rsp), %rsi
callq 0x2a430
testb $0x1, %al
jne 0x5d789
jmp 0x5d78b
jmp 0x5d792
jmp 0x5d78d
jmp 0x5d610
jmp 0x5d794
leaq 0x80(%rsp), %rdi
leaq 0x36f5d(%rip), %rsi     # 0x94700
callq 0x2a430
testb $0x1, %al
jne 0x5d7ae
jmp 0x5d7bf
movq 0x48(%rsp), %rax
movl 0x400(%rax), %eax
movl %eax, 0x78(%rsp)
jmp 0x5d7d5
movq 0x48(%rsp), %rax
movb $0x0, 0xc(%rax)
movl $0x1, 0x54(%rsp)
jmp 0x5d87b
movl 0x78(%rsp), %eax
movq %rax, 0x8(%rsp)
leaq 0x36f3b(%rip), %rdi     # 0x94720
callq 0x6350
movq %rax, %rcx
movq 0x8(%rsp), %rax
cmpq %rcx, %rax
ja 0x5d86a
movl 0x78(%rsp), %eax
decl %eax
movl %eax, %esi
leaq 0x36f1a(%rip), %rdi     # 0x94720
callq 0x6b20
movq %rax, (%rsp)
jmp 0x5d811
movq (%rsp), %rax
movsbl (%rax), %eax
subl $0x30, %eax
movb %al, 0x53(%rsp)
movsbl 0x53(%rsp), %eax
cmpl 0xf0(%rsp), %eax
setle %al
andb $0x1, %al
movb %al, 0x52(%rsp)
movb 0xf7(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x5d851
movb 0x52(%rsp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, 0x52(%rsp)
movb 0x52(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5d868
movq 0x48(%rsp), %rax
movb $0x0, 0xc(%rax)
jmp 0x5d873
movq 0x48(%rsp), %rax
movb $0x0, 0xc(%rax)
movl $0x0, 0x54(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x6b50
leaq 0xa0(%rsp), %rdi
callq 0x6b50
addq $0x108, %rsp            # imm = 0x108
retq
leaq 0xa0(%rsp), %rdi
callq 0x6b50
movq 0xc8(%rsp), %rdi
callq 0x69e0
nopw (%rax,%rax)