// File: /workspace/github_cpp_makefile_star2_O2/auton1[P]viterbi/variant_file_filters.cpp
// Function: variant_file::filter_individuals_randomly(int)
void variant_file::filter_individuals_randomly(int max_N_indv)
{
	// Filter individuals randomly until have a random subset
	if (max_N_indv < 0)
		return;
	LOG.printLOG("Filtering Individuals Randomly\n");

	if (meta_data.has_genotypes == false)
		LOG.error("Require Genotypes in variant file filter individuals.");

	unsigned int N_kept_indv = N_kept_individuals();

	srand ( time(NULL) );
	vector<unsigned int> keep_index(N_kept_indv);
	int count = 0;
	for (unsigned int ui=0; ui<meta_data.N_indv; ui++)
	{
		if (include_indv[ui] == true)
		{
			keep_index[count] = ui;
			count++;
		}
	}

	random_shuffle(keep_index.begin(), keep_index.end());			// Get a random order
	keep_index.resize(min(max_N_indv, (signed)keep_index.size()));	// Only keep a subset

	for (unsigned int ui=0; ui<meta_data.N_indv; ui++)
	{
		if (include_indv[ui] == false)
			continue;
		bool found = false;
		for (unsigned int uj=0; uj<keep_index.size(); uj++)
		{
			if (keep_index[uj] == ui)
			{
				found = true;
			}
		}
		if (found == false)
			include_indv[ui] = false;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x60, %rsp
testl %esi, %esi
js 0x26766
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x8a1e(%rip), %rsi      # 0x2f018
leaq 0x40(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x5160
leaq 0x1aec0(%rip), %rdi     # 0x414d0
leaq 0x40(%rsp), %rsi
callq 0x2beca
leaq 0x40(%rsp), %rdi
callq 0x5908
cmpb $0x0, 0x255(%rbx)
jne 0x26661
leaq 0x8a04(%rip), %rsi      # 0x2f038
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x5160
leaq 0x1ae86(%rip), %rdi     # 0x414d0
leaq 0x20(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x2bf18
leaq 0x20(%rsp), %rdi
callq 0x5908
movq %rbx, %rdi
callq 0xe91e
movl %eax, %r14d
xorl %r12d, %r12d
xorl %edi, %edi
callq 0x5430
movl %eax, %edi
callq 0x5470
movl %r14d, %esi
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x26d6e
leaq 0x430(%rbx), %r14
xorl %r15d, %r15d
movl 0x2a8(%rbx), %eax
cmpq %rax, %r15
jae 0x266c8
movq %r14, %rdi
movq %r15, %rsi
callq 0x9cc0
testq %rdx, (%rax)
je 0x266c3
movslq %r12d, %r12
movq 0x8(%rsp), %rax
movl %r15d, (%rax,%r12,4)
incl %r12d
incq %r15
jmp 0x26699
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x26dbf
leaq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rax
subq (%rdi), %rax
shrq $0x2, %rax
cmpl %ebp, %eax
cmovll %eax, %ebp
movslq %ebp, %rsi
callq 0x162cc
xorl %r15d, %r15d
pushq $0x1
popq %rbp
movl 0x2a8(%rbx), %eax
cmpq %rax, %r15
jae 0x2675c
movq %r14, %rdi
movq %r15, %rsi
callq 0x9cc0
testq %rdx, (%rax)
je 0x26757
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
xorl %edx, %edx
xorl %esi, %esi
movl %esi, %esi
cmpq %rsi, %rcx
jbe 0x26741
movl (%rax,%rsi,4), %edi
cmpq %rdi, %r15
movzbl %dl, %edx
cmovel %ebp, %edx
incl %esi
jmp 0x2672a
testb $0x1, %dl
jne 0x26757
movq %r14, %rdi
movq %r15, %rsi
callq 0x9cc0
notq %rdx
andq %rdx, (%rax)
incq %r15
jmp 0x266fa
leaq 0x8(%rsp), %rdi
callq 0xa14c
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
jmp 0x2678d
jmp 0x26794
jmp 0x2679d
jmp 0x2679d
jmp 0x26794
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x5908
jmp 0x267aa
movq %rax, %rbx
jmp 0x267aa
jmp 0x2679d
jmp 0x2679d
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0xa14c
movq %rbx, %rdi
callq 0x5800