// File: /workspace/github_cpp_makefile_star2_O1/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 0x2ebe8
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x50(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xc6f7(%rip), %rsi      # 0x3b0e0
leaq 0xc70f(%rip), %rdx      # 0x3b0ff
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0xc868
leaq 0x1baa4(%rip), %rdi     # 0x4a4a8
movq %r14, %rsi
callq 0x371c8
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x2ea1b
callq 0x5410
cmpb $0x0, 0x255(%rbx)
jne 0x2ea6b
leaq 0x30(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xc6cc(%rip), %rsi      # 0x3b100
leaq 0xc6fa(%rip), %rdx      # 0x3b135
leaq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0xc868
leaq 0x1ba59(%rip), %rdi     # 0x4a4a8
movq %r14, %rsi
movl $0x1, %edx
callq 0x3721e
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x2ea6b
callq 0x5410
movq %rbx, %rdi
callq 0x114e6
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 0x2f332
cmpl $0x0, 0x2a8(%rbx)
je 0x2ead6
movq 0x430(%rbx), %rax
xorl %ecx, %ecx
movq 0x8(%rsp), %rdx
xorl %esi, %esi
movq %rcx, %rdi
shrq $0x6, %rdi
movq (%rax,%rdi,8), %rdi
btq %rcx, %rdi
jae 0x2eac8
movslq %esi, %rsi
movl %ecx, (%rdx,%rsi,4)
incl %esi
incq %rcx
movl 0x2a8(%rbx), %edi
cmpq %rdi, %rcx
jb 0x2eaaf
movq 0x8(%rsp), %r14
movq 0x10(%rsp), %r15
cmpq %r15, %r14
je 0x2eb38
leaq 0x4(%r14), %rax
cmpq %r15, %rax
je 0x2eb38
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 0x2eb27
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 0x2eaf4
leaq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rax
subq (%rdi), %rax
shrq $0x2, %rax
cmpl %ebp, %eax
cmovll %eax, %ebp
movslq %ebp, %rsi
callq 0x1b394
movl 0x2a8(%rbx), %eax
testq %rax, %rax
je 0x2ebd9
movq 0x430(%rbx), %rdx
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdi
movq %rdi, %r8
subq %rsi, %r8
sarq $0x2, %r8
xorl %ecx, %ecx
movl $0x1, %r9d
movl $0x1, %r10d
shlq %cl, %r10
movq %rcx, %r11
shrq $0x6, %r11
movq (%rdx,%r11,8), %rbx
btq %rcx, %rbx
jae 0x2ebd1
cmpq %rsi, %rdi
je 0x2ebc7
xorl %r14d, %r14d
xorl %ebp, %ebp
movl (%rsi,%r14,4), %r15d
cmpq %r15, %rcx
movzbl %bpl, %ebp
cmovel %r9d, %ebp
incq %r14
movl %r14d, %r15d
cmpq %r15, %r8
ja 0x2eba7
testb $0x1, %bpl
jne 0x2ebd1
notq %r10
andq %r10, %rbx
movq %rbx, (%rdx,%r11,8)
incq %rcx
cmpq %rax, %rcx
jne 0x2eb83
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x2ebe8
callq 0x5410
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x20(%rsp), %rdi
jmp 0x2ec1b
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
jne 0x2ec20
jmp 0x2ec25
movq %rax, %rbx
jmp 0x2ec25
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x2ec25
callq 0x5410
movq %rbx, %rdi
callq 0x57d0
nop