// File: auton1[P]viterbi/entry_filters.cpp
// Function: entry::filter_sites_by_allele_count(double, double, double, double, double)
void entry::filter_sites_by_allele_count(double min_mac, double max_mac, double min_non_ref_ac, double max_non_ref_ac, double max_missing_call_count)
{
	// Filter sites so that all allele counts are between limits
	if (passed_filters == false)
		return;

	if ((min_mac <= 0) && (max_mac == numeric_limits<int>::max()) &&
			(min_non_ref_ac <= 0) && (max_non_ref_ac == numeric_limits<int>::max()) &&
			(max_missing_call_count == numeric_limits<int>::max()))
		return;

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

	if (entry_header.has_genotypes == false)
		LOG.error("Require Genotypes in variant file to filter by allele counts and/or missing data");

	N_alleles = get_N_alleles();

	if (N_alleles <= 1 && min_mac > 0)
		passed_filters = false;

	vector<int> allele_counts;
	get_allele_counts(allele_counts, N_non_missing_chr);
	N_chr = get_N_chr();

	int mac = numeric_limits<int>::max();
	for (unsigned int ui=0; ui<N_alleles; ui++)
	{
		mac = min(allele_counts[ui], mac);
		if ((ui > 0) && ((allele_counts[ui] < min_non_ref_ac) || (allele_counts[ui] > max_non_ref_ac)))
			passed_filters = false;
	}

	if ((mac < min_mac) || (mac > max_mac))
		passed_filters = false;

	if ((N_chr-N_non_missing_chr) > max_missing_call_count)
		passed_filters = false;
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xd0(%rsp)
movsd %xmm0, 0xc8(%rsp)
movsd %xmm1, 0xc0(%rsp)
movsd %xmm2, 0xb8(%rsp)
movsd %xmm3, 0xb0(%rsp)
movsd %xmm4, 0xa8(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x38(%rsp)
movb 0xc(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5e13b
jmp 0x5e44b
xorps %xmm0, %xmm0
ucomisd 0xc8(%rsp), %xmm0
jb 0x5e1d2
movsd 0xc0(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
callq 0x10bd0
movsd 0x30(%rsp), %xmm0
cvtsi2sd %eax, %xmm1
ucomisd %xmm1, %xmm0
jne 0x5e1d2
jp 0x5e1d2
xorps %xmm0, %xmm0
ucomisd 0xb8(%rsp), %xmm0
jb 0x5e1d2
movsd 0xb0(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
callq 0x10bd0
movsd 0x28(%rsp), %xmm0
cvtsi2sd %eax, %xmm1
ucomisd %xmm1, %xmm0
jne 0x5e1d2
jp 0x5e1d2
movsd 0xa8(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
callq 0x10bd0
movsd 0x20(%rsp), %xmm0
cvtsi2sd %eax, %xmm1
ucomisd %xmm1, %xmm0
jne 0x5e1d2
jp 0x5e1d2
jmp 0x5e44b
movq 0x38(%rsp), %rdi
movq (%rdi), %rax
movl $0x1, %esi
xorl %ecx, %ecx
movl %ecx, %edx
callq *0x10(%rax)
movq 0x38(%rsp), %rdi
movq (%rdi), %rax
movl $0x1, %esi
xorl %r8d, %r8d
movl %r8d, %edx
movl %r8d, %ecx
callq *0x28(%rax)
movq 0x38(%rsp), %rax
movb 0x15(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5e2a1
leaq 0x77(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x69f0
movq 0x18(%rsp), %rdx
leaq 0x17b6b(%rip), %rsi     # 0x75d9b
leaq 0x78(%rsp), %rdi
callq 0x67c0
jmp 0x5e23c
leaq 0x353bd(%rip), %rdi     # 0x93600
leaq 0x78(%rsp), %rsi
movl $0x1, %edx
callq 0x712f0
jmp 0x5e254
leaq 0x78(%rsp), %rdi
callq 0x6b50
leaq 0x77(%rsp), %rdi
callq 0x65f0
jmp 0x5e2a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
jmp 0x5e292
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x6b50
leaq 0x77(%rsp), %rdi
callq 0x65f0
jmp 0x5e453
movq 0x38(%rsp), %rdi
callq 0x4c290
movl %eax, 0xa4(%rsp)
cmpl $0x1, 0xa4(%rsp)
ja 0x5e2d7
movsd 0xc8(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x5e2d7
movq 0x38(%rsp), %rax
movb $0x0, 0xc(%rax)
leaq 0x48(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0xea00
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
leaq 0x9c(%rsp), %rdx
callq 0x4c3c0
jmp 0x5e2ff
movq 0x38(%rsp), %rdi
callq 0x4c2f0
movl %eax, 0xc(%rsp)
jmp 0x5e30f
movl 0xc(%rsp), %eax
movl %eax, 0xa0(%rsp)
callq 0x10bd0
movl %eax, 0x44(%rsp)
movl $0x0, 0x40(%rsp)
movl 0x40(%rsp), %eax
cmpl 0xa4(%rsp), %eax
jae 0x5e3e9
movl 0x40(%rsp), %eax
movl %eax, %esi
leaq 0x48(%rsp), %rdi
callq 0xecf0
movq %rax, %rdi
leaq 0x44(%rsp), %rsi
callq 0xf8c0
movq %rax, (%rsp)
jmp 0x5e35f
movq (%rsp), %rax
movl (%rax), %eax
movl %eax, 0x44(%rsp)
cmpl $0x0, 0x40(%rsp)
jbe 0x5e3d7
movl 0x40(%rsp), %eax
movl %eax, %esi
leaq 0x48(%rsp), %rdi
callq 0xecf0
cvtsi2sdl (%rax), %xmm1
movsd 0xb8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x5e3b2
movl 0x40(%rsp), %eax
movl %eax, %esi
leaq 0x48(%rsp), %rdi
callq 0xecf0
cvtsi2sdl (%rax), %xmm0
ucomisd 0xb0(%rsp), %xmm0
jbe 0x5e3d7
movq 0x38(%rsp), %rax
movb $0x0, 0xc(%rax)
jmp 0x5e3d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
leaq 0x48(%rsp), %rdi
callq 0xed70
jmp 0x5e453
jmp 0x5e3d9
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x5e32b
cvtsi2sdl 0x44(%rsp), %xmm1
movsd 0xc8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x5e40f
cvtsi2sdl 0x44(%rsp), %xmm0
ucomisd 0xc0(%rsp), %xmm0
jbe 0x5e418
movq 0x38(%rsp), %rax
movb $0x0, 0xc(%rax)
movl 0xa0(%rsp), %eax
movl 0x9c(%rsp), %ecx
subl %ecx, %eax
cvtsi2sd %rax, %xmm0
ucomisd 0xa8(%rsp), %xmm0
jbe 0x5e441
movq 0x38(%rsp), %rax
movb $0x0, 0xc(%rax)
leaq 0x48(%rsp), %rdi
callq 0xed70
addq $0xd8, %rsp
retq
movq 0x68(%rsp), %rdi
callq 0x69e0
nopl (%rax)