// File: /workspace/github_cpp_makefile_star2_O3/auton1[P]viterbi/entry_filters.cpp
// Function: entry::filter_sites_by_frequency_and_call_rate(double, double, double, double, double)
void entry::filter_sites_by_frequency_and_call_rate(double min_maf, double max_maf, double min_non_ref_af, double max_non_ref_af, double min_site_call_rate)
{
	// Filter sites so that all allele frequencies are between limits
	if (passed_filters == false)
		return;

	if ((min_maf <= 0.0) && (max_maf >= 1.0) && (min_site_call_rate <= 0) && (min_non_ref_af <= 0.0) && (max_non_ref_af >= 1.0))
		return;

	unsigned int N_alleles;
	unsigned int N_non_missing_chr;
	parse_basic_entry(true);
	parse_genotype_entries(true);

	if (GT_idx == -1)
		LOG.error("Require Genotypes in variant file to filter by frequency and/or call rate");

	N_alleles = get_N_alleles();

	vector<int> allele_counts;
	get_allele_counts(allele_counts, N_non_missing_chr);

	double freq, folded_freq;
	double maf=numeric_limits<double>::max();
	for (unsigned int ui=0; ui<N_alleles; ui++)
	{
		freq = allele_counts[ui] / (double)N_non_missing_chr;
		folded_freq = min(freq, 1.0 - freq);

		maf = min(maf, folded_freq);
		if ((ui > 0) && ((freq < min_non_ref_af) || (freq > max_non_ref_af)))
			passed_filters = false;
	}

	if ((maf < min_maf) || (maf > max_maf))
		passed_filters = false;

	double call_rate = N_non_missing_chr / double(get_N_chr());

	if (call_rate < min_site_call_rate)
		passed_filters = false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x68, %rsp
cmpb $0x0, 0xc(%rdi)
je 0x2ba87
movq %rdi, %rbx
ucomisd 0xc74f(%rip), %xmm3     # 0x38018
jb 0x2b8ef
xorpd %xmm5, %xmm5
ucomisd %xmm2, %xmm5
jb 0x2b8ef
ucomisd %xmm0, %xmm5
jb 0x2b8ef
ucomisd 0xc735(%rip), %xmm1     # 0x38018
jb 0x2b8ef
ucomisd %xmm4, %xmm5
jae 0x2ba87
movsd %xmm2, 0x18(%rsp)
movsd %xmm3, 0x20(%rsp)
movsd %xmm0, 0x28(%rsp)
movsd %xmm1, 0x8(%rsp)
movsd %xmm4, 0x10(%rsp)
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x1, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq *0x10(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x1, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq *0x28(%rax)
cmpl $-0x1, 0x630(%rbx)
jne 0x2b984
leaq 0x58(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xe58b(%rip), %rsi      # 0x39ed8
leaq 0xe5cd(%rip), %rdx      # 0x39f21
leaq 0x48(%rsp), %r14
movq %r14, %rdi
callq 0xc85e
leaq 0x1db40(%rip), %rdi     # 0x494a8
movq %r14, %rsi
movl $0x1, %edx
callq 0x36ec8
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x2b984
callq 0x5410
movq %rbx, %rdi
callq 0x22eb0
movl %eax, %ebp
xorpd %xmm0, %xmm0
leaq 0x30(%rsp), %rsi
movapd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
leaq 0x4(%rsp), %rdx
movq %rbx, %rdi
callq 0x22f60
testl %ebp, %ebp
movsd 0x20(%rsp), %xmm5
movsd 0x18(%rsp), %xmm6
je 0x2ba24
movq 0x30(%rsp), %rax
movl 0x4(%rsp), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movl %ebp, %ecx
movsd 0xc665(%rip), %xmm2     # 0x38040
xorl %edx, %edx
movsd 0xc633(%rip), %xmm1     # 0x38018
xorps %xmm4, %xmm4
cvtsi2sdl (%rax,%rdx,4), %xmm4
divsd %xmm0, %xmm4
testq %rdx, %rdx
je 0x2ba06
ucomisd %xmm4, %xmm6
ja 0x2ba02
ucomisd %xmm5, %xmm4
jbe 0x2ba06
movb $0x0, 0xc(%rbx)
movapd %xmm1, %xmm3
subsd %xmm4, %xmm3
minsd %xmm4, %xmm3
minsd %xmm2, %xmm3
incq %rdx
movapd %xmm3, %xmm2
cmpq %rdx, %rcx
jne 0x2b9e5
jmp 0x2ba2c
movsd 0xc614(%rip), %xmm3     # 0x38040
movsd 0x28(%rsp), %xmm0
ucomisd %xmm3, %xmm0
ja 0x2ba40
ucomisd 0x8(%rsp), %xmm3
jbe 0x2ba44
movb $0x0, 0xc(%rbx)
movl 0x4(%rsp), %ebp
movq %rbx, %rdi
callq 0x22eee
movl %ebp, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movl %eax, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x2ba78
movb $0x0, 0xc(%rbx)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2ba87
callq 0x5410
addq $0x68, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
jne 0x2bab0
jmp 0x2bab5
jmp 0x2baa3
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2bab5
callq 0x5410
movq %rbx, %rdi
callq 0x57d0
nop