// File: /workspace/github_cpp_makefile_star2_O3/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 0x2e8bc
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x50(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xb9fb(%rip), %rsi      # 0x3a0b8
leaq 0xba13(%rip), %rdx      # 0x3a0d7
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0xc85e
leaq 0x1add0(%rip), %rdi     # 0x494a8
movq %r14, %rsi
callq 0x36e72
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x2e6ef
callq 0x5410
cmpb $0x0, 0x255(%rbx)
jne 0x2e73f
leaq 0x30(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xb9d0(%rip), %rsi      # 0x3a0d8
leaq 0xb9fe(%rip), %rdx      # 0x3a10d
leaq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0xc85e
leaq 0x1ad85(%rip), %rdi     # 0x494a8
movq %r14, %rsi
movl $0x1, %edx
callq 0x36ec8
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x2e73f
callq 0x5410
movq %rbx, %rdi
callq 0x11532
movl %eax, %r14d
xorl %edi, %edi
callq 0x5400
movl %eax, %edi
callq 0x5430
movl %r14d, %esi
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x2effe
movl 0x2a8(%rbx), %eax
movq 0x8(%rsp), %r14
testl %eax, %eax
je 0x2e7a8
movq 0x430(%rbx), %rcx
xorl %edx, %edx
xorl %esi, %esi
movl %edx, %edi
shrl $0x6, %edi
movq (%rcx,%rdi,8), %rdi
btq %rdx, %rdi
jae 0x2e7a2
movslq %esi, %rsi
movl %edx, (%r14,%rsi,4)
incl %esi
movl 0x2a8(%rbx), %eax
incl %edx
cmpl %eax, %edx
jb 0x2e784
movq 0x10(%rsp), %r15
cmpq %r15, %r14
je 0x2e811
leaq 0x4(%r14), %rax
cmpq %r15, %rax
je 0x2e814
movl $0x4, %r12d
callq 0x50c0
cltq
movq %r12, %rcx
sarq $0x2, %rcx
incq %rcx
cqto
idivq %rcx
leaq (,%rdx,4), %rax
cmpq %rax, %r12
je 0x2e7f4
leaq (%r14,%r12), %rax
leaq (%r14,%rdx,4), %rcx
movl (%rax), %edx
movl (%rcx), %esi
movl %esi, (%rax)
movl %edx, (%rcx)
leaq (%r14,%r12), %rax
addq $0x4, %rax
addq $0x4, %r12
cmpq %r15, %rax
jne 0x2e7c1
movq 0x8(%rsp), %r14
movq 0x10(%rsp), %r15
jmp 0x2e814
movq %r14, %r15
subq %r14, %r15
shrq $0x2, %r15
cmpl %ebp, %r15d
cmovll %r15d, %ebp
movslq %ebp, %rsi
leaq 0x8(%rsp), %rdi
callq 0x1b294
movl 0x2a8(%rbx), %eax
movq 0x8(%rsp), %rdi
testl %eax, %eax
je 0x2e8b2
movq 0x430(%rbx), %rdx
movq 0x10(%rsp), %rsi
movq %rsi, %r8
subq %rdi, %r8
sarq $0x2, %r8
xorl %ecx, %ecx
movl $0x1, %r9d
movl $0x1, %r10d
shlq %cl, %r10
movl %ecx, %r11d
shrl $0x6, %r11d
movq (%rdx,%r11,8), %rbx
btq %rcx, %rbx
jae 0x2e8a7
cmpq %rdi, %rsi
je 0x2e89d
xorl %r14d, %r14d
xorl %ebp, %ebp
cmpl %ecx, (%rdi,%r14,4)
movzbl %bpl, %ebp
cmovel %r9d, %ebp
incq %r14
movl %r14d, %r15d
cmpq %r15, %r8
ja 0x2e880
testb $0x1, %bpl
jne 0x2e8a7
notq %r10
andq %r10, %rbx
movq %rbx, (%rdx,%r11,8)
incl %ecx
cmpl %eax, %ecx
jne 0x2e85c
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x2e8bc
callq 0x5410
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x20(%rsp), %rdi
jmp 0x2e8ef
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
jne 0x2e8f4
jmp 0x2e8f9
movq %rax, %rbx
jmp 0x2e8f9
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x2e8f9
callq 0x5410
movq %rbx, %rdi
callq 0x57d0
nop