// File: 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:
subq $0x168, %rsp            # imm = 0x168
movq %rdi, 0x160(%rsp)
movl %esi, 0x15c(%rsp)
movq 0x160(%rsp), %rax
movq %rax, 0x78(%rsp)
cmpl $0x0, 0x15c(%rsp)
jge 0x659d2
jmp 0x65ed1
leaq 0x137(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x69f0
movq 0x70(%rsp), %rdx
leaq 0x1051a(%rip), %rsi     # 0x75f0a
leaq 0x138(%rsp), %rdi
callq 0x67c0
jmp 0x659ff
leaq 0x2dbfa(%rip), %rdi     # 0x93600
leaq 0x138(%rsp), %rsi
callq 0x71280
jmp 0x65a15
leaq 0x138(%rsp), %rdi
callq 0x6b50
leaq 0x137(%rsp), %rdi
callq 0x65f0
movq 0x78(%rsp), %rax
movb 0x255(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x65b41
leaq 0xff(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x69f0
movq 0x68(%rsp), %rdx
leaq 0x104c4(%rip), %rsi     # 0x75f2a
leaq 0x100(%rsp), %rdi
callq 0x67c0
jmp 0x65a75
leaq 0x2db84(%rip), %rdi     # 0x93600
leaq 0x100(%rsp), %rsi
movl $0x1, %edx
callq 0x712f0
jmp 0x65a90
leaq 0x100(%rsp), %rdi
callq 0x6b50
leaq 0xff(%rsp), %rdi
callq 0x65f0
jmp 0x65b41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
jmp 0x65ae6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x6b50
leaq 0x137(%rsp), %rdi
callq 0x65f0
jmp 0x65ed9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
jmp 0x65b2f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x6b50
leaq 0xff(%rsp), %rdi
callq 0x65f0
jmp 0x65ed9
movq 0x78(%rsp), %rdi
callq 0x27690
movl %eax, 0xf8(%rsp)
xorl %eax, %eax
movl %eax, %edi
callq 0x64d0
movl %eax, %edi
callq 0x6520
movl 0xf8(%rsp), %eax
movq %rax, 0x58(%rsp)
leaq 0xdf(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x11210
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq 0xe0(%rsp), %rdi
callq 0x669c0
jmp 0x65b99
leaq 0xdf(%rsp), %rdi
callq 0x119d0
movl $0x0, 0xd8(%rsp)
movl $0x0, 0xd4(%rsp)
movq 0x78(%rsp), %rcx
movl 0xd4(%rsp), %eax
cmpl 0x2a8(%rcx), %eax
jae 0x65ccc
movq 0x78(%rsp), %rdi
addq $0x430, %rdi            # imm = 0x430
movl 0xd4(%rsp), %eax
movl %eax, %esi
callq 0x102b0
movq %rdx, 0x48(%rsp)
movq %rax, 0x50(%rsp)
jmp 0x65bfa
movq 0x48(%rsp), %rax
movq 0x50(%rsp), %rcx
movq %rcx, 0xc0(%rsp)
movq %rax, 0xc8(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x10310
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x65cb4
movl 0xd4(%rsp), %eax
movl %eax, 0x44(%rsp)
movslq 0xd8(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
callq 0xe8b0
movl 0x44(%rsp), %ecx
movl %ecx, (%rax)
movl 0xd8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd8(%rsp)
jmp 0x65cb4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
leaq 0xdf(%rsp), %rdi
callq 0x119d0
jmp 0x65ed9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x10c00
jmp 0x65ed9
jmp 0x65cb6
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0x65bbc
leaq 0xe0(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x1b9c0
movq 0x38(%rsp), %rdi
movq %rax, 0xb8(%rsp)
callq 0x1b840
movq %rax, 0xb0(%rsp)
movq 0xb8(%rsp), %rdi
movq 0xb0(%rsp), %rsi
callq 0x66a40
jmp 0x65d0f
leaq 0xe0(%rsp), %rdi
callq 0xe850
movl %eax, 0xac(%rsp)
leaq 0x15c(%rsp), %rdi
leaq 0xac(%rsp), %rsi
callq 0xf8c0
movq %rax, 0x30(%rsp)
jmp 0x65d3f
movq 0x30(%rsp), %rax
movslq (%rax), %rsi
leaq 0xe0(%rsp), %rdi
callq 0x393f0
jmp 0x65d56
movl $0x0, 0xa8(%rsp)
movq 0x78(%rsp), %rcx
movl 0xa8(%rsp), %eax
cmpl 0x2a8(%rcx), %eax
jae 0x65ec4
movq 0x78(%rsp), %rdi
addq $0x430, %rdi            # imm = 0x430
movl 0xa8(%rsp), %eax
movl %eax, %esi
callq 0x102b0
movq %rdx, 0x20(%rsp)
movq %rax, 0x28(%rsp)
jmp 0x65d9f
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, 0x98(%rsp)
movq %rax, 0xa0(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x10310
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x65dd5
jmp 0x65eae
movb $0x0, 0x97(%rsp)
movl $0x0, 0x90(%rsp)
movl 0x90(%rsp), %eax
movq %rax, 0x18(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0xe850
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
jae 0x65e4c
movl 0x90(%rsp), %eax
movl %eax, %esi
leaq 0xe0(%rsp), %rdi
callq 0xe8b0
movl (%rax), %eax
cmpl 0xa8(%rsp), %eax
jne 0x65e37
movb $0x1, 0x97(%rsp)
jmp 0x65e39
movl 0x90(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x90(%rsp)
jmp 0x65de8
movb 0x97(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x65eac
movq 0x78(%rsp), %rdi
addq $0x430, %rdi            # imm = 0x430
movl 0xa8(%rsp), %eax
movl %eax, %esi
callq 0x102b0
movq %rdx, 0x8(%rsp)
movq %rax, 0x10(%rsp)
jmp 0x65e83
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0x80(%rsp)
movq %rax, 0x88(%rsp)
leaq 0x80(%rsp), %rdi
xorl %esi, %esi
callq 0x1bd30
jmp 0x65eae
movl 0xa8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa8(%rsp)
jmp 0x65d61
leaq 0xe0(%rsp), %rdi
callq 0x10c00
addq $0x168, %rsp            # imm = 0x168
retq
movq 0x128(%rsp), %rdi
callq 0x69e0
nopw %cs:(%rax,%rax)