// File: /workspace/github_cpp_makefile_star2_O2/simonrharris[P]SKA/src/ska.cpp
// Function: weedSubcommand(int, char**)
int weedSubcommand(int argc, char *argv[]){

	std::string infile="";
	std::string kmerfile="";
	float minproportion=0.0;
	float maxproportion=1.0;
	int minsamples=0;
	int maxsamples=0;
	std::vector < std::string > args;

	for (int i=2; i<argc; ++i){

		std::string arg=(argv[i]);

		if (arg=="-h" || arg=="--help"){
			weedHelp();
			return 0;
		}
		else if (arg == "-f"){
			i++;
			if (i<argc){
				fileToVector(argv[i], args);
			}
			else {
				std::cerr << std::endl << "Expecting file name after -f flag" << std::endl << std::endl;
				return 1;
			}
		}
		else if (arg == "-i"){
			i++;
			if (i<argc){
				infile = argv[i];
			}
			else {
				std::cerr << std::endl << "Expecting file name after -i flag" << std::endl << std::endl;
				return 1;
			}
		}
		else if (arg == "-m"){
			i++;
			if (i<argc){
				try {
					minsamples = getint(argv[i]);
				}
				catch (const std::invalid_argument& e) {
					std::cerr << std::endl << "Expecting positive int after -m flag" << std::endl << std::endl;
					return 1;
				}
			}
			else {
				std::cerr << std::endl << "Expecting positive int after -m flag" << std::endl << std::endl;
				return 1;
			}
			if (minsamples < 0){
				std::cerr << std::endl << "Minimum number of samples must be 0 or greater" << std::endl << std::endl;
				return 1;
			}
		}
		else if (arg == "-M"){
			i++;
			if (i<argc){
				try {
					maxsamples = getint(argv[i]);
				}
				catch (const std::invalid_argument& e) {
					std::cerr << std::endl << "Expecting positive int after -m flag" << std::endl << std::endl;
					return 1;
				}
			}
			else {
				std::cerr << std::endl << "Expecting positive int after -m flag" << std::endl << std::endl;
				return 1;
			}
			if (maxsamples < 0){
				std::cerr << std::endl << "Maximum number of samples must be 0 or greater" << std::endl << std::endl;
				return 1;
			}
		}
		else if (arg == "-p"){
			i++;
			if (i<argc){
				try {
					minproportion = getfloat(argv[i]);
				}
				catch (const std::invalid_argument& e) {
					std::cerr << std::endl << "Expecting float between 0 and 1 after -p flag" << std::endl << std::endl;
					return 1;
				}
			}
			else {
				std::cerr << std::endl << "Expecting float between 0 and 1 after -p flag" << std::endl << std::endl;
				return 1;
			}
			if (minproportion < 0 || minproportion > 1){
				std::cerr << std::endl << "Minimum proportion must be between 0 and 1" << std::endl << std::endl;
				return 1;
			}
		}
		else if (arg == "-P"){
			i++;
			if (i<argc){
				try {
					maxproportion = getfloat(argv[i]);
				}
				catch (const std::invalid_argument& e) {
					std::cerr << std::endl << "Expecting float between 0 and 1 after -P flag" << std::endl << std::endl;
					return 1;
				}
			}
			else {
				std::cerr << std::endl << "Expecting float between 0 and 1 after -P flag" << std::endl << std::endl;
				return 1;
			}
			if (maxproportion < 0 || maxproportion > 1){
				std::cerr << std::endl << "Maximum proportion must be between 0 and 1" << std::endl << std::endl;
				return 1;
			}
		}
		else if (arg[0]=='-'){
			std::cerr << std::endl << "Unrecognised flag " << arg << std::endl << std::endl;
				return 1;
		}
		else {
			args.push_back(arg);
		}
	}

	if (args.size()<1){
		std::cerr << std::endl << "Too few arguments" << std::endl;
		weedHelp();
		return 1;
	}

	if (infile=="" && minproportion==0 && minsamples==0 && maxproportion==1 && maxproportion==0){
		std::cerr << "Input split kmer file is required if no sample numbers or proportions are set" << std::endl;
		weedHelp();
		return 1;
	}

	if (minproportion>=maxproportion){
		std::cerr << "Maxproportion must be greater than minproportion" << std::endl;
		weedHelp();
		return 1;
	}
	if (minsamples>=maxsamples && maxsamples!=0){
		std::cerr << "Maxsamples must be greater than minsamples" << std::endl;
		weedHelp();
		return 1;
	}

	skaVersion();

	std::cout << "Weeding kmers in " << infile << std::endl;
	std::cout << "From ";
	if (args.size()>maxNamesToPrint){
		std::cout << args.size() << " files";
	}
	else {
		for (std::vector < std::string >::iterator it = args.begin(); it != args.end(); ++it){
			std::cout << *it << " ";
		}
	}

	std::cout << std::endl;

	if (weedKmers(args, infile, minproportion, maxproportion, minsamples, maxsamples)){return 1;}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rsi, %r15
movl %edi, %r12d
leaq 0x2c7e(%rip), %rsi      # 0x262c2
leaq 0x48(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x77c0
leaq 0x2c65(%rip), %rsi      # 0x262c2
leaq 0x88(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x77c0
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rax
andq $0x0, 0x10(%rax)
movaps %xmm0, (%rax)
pushq $0x2
popq %r13
movl $0x0, 0x1c(%rsp)
movss 0x1971(%rip), %xmm0     # 0x25004
leaq 0x68(%rsp), %rbp
leaq 0xa8(%rsp), %rbx
movq 0x12949(%rip), %rax     # 0x35ff0
movq %rax, 0x40(%rsp)
movss %xmm0, 0xc(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x10(%rsp)
movl $0x0, 0x18(%rsp)
cmpl %r12d, %r13d
jge 0x23c31
movslq %r13d, %rax
movq (%r15,%rax,8), %rsi
movq %rbp, %rdi
movq %rbx, %rdx
callq 0x77c0
movq %rbp, %rdi
leaq 0x390b(%rip), %rsi      # 0x26ff3
callq 0x132f3
testb %al, %al
jne 0x23704
movq %rbp, %rdi
leaq 0x38fb(%rip), %rsi      # 0x26ff6
callq 0x132f3
testb %al, %al
je 0x2372a
xorl %ebx, %ebx
callq 0x23524
xorl %r14d, %r14d
movq %rbp, %rdi
callq 0x5778
incl %r13d
testb %bl, %bl
leaq 0xa8(%rsp), %rbx
jne 0x236c3
jmp 0x23cf5
movq %rbp, %rdi
leaq 0x393f(%rip), %rsi      # 0x27073
callq 0x132f3
testb %al, %al
je 0x23772
incl %r13d
cmpl %r12d, %r13d
jge 0x237a9
movslq %r13d, %rax
movq (%r15,%rax,8), %rsi
movq %rbx, %rdi
leaq 0x17(%rsp), %rdx
callq 0x77c0
movq %rbx, %rdi
leaq 0x20(%rsp), %rsi
callq 0x7529
movq %rbx, %rdi
callq 0x5778
movb $0x1, %bl
jmp 0x2370e
movq %rbp, %rdi
leaq 0x3dc9(%rip), %rsi      # 0x27545
callq 0x132f3
testb %al, %al
je 0x237d9
incl %r13d
cmpl %r12d, %r13d
jge 0x23846
movslq %r13d, %rax
movq (%r15,%rax,8), %rsi
movb $0x1, %bl
leaq 0x48(%rsp), %rdi
callq 0x5730
jmp 0x2370e
movq 0x12840(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x38b7(%rip), %rsi      # 0x27076
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x23b05
movq %rbp, %rdi
leaq 0x48fd(%rip), %rsi      # 0x280e0
callq 0x132f3
testb %al, %al
je 0x23876
incl %r13d
cmpl %r12d, %r13d
jge 0x238e3
movslq %r13d, %rax
movq (%r15,%rax,8), %rdi
callq 0x1dca8
movb $0x1, %bl
movl %eax, 0x1c(%rsp)
testl %eax, %eax
jns 0x2370e
movq 0x127d3(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x5659(%rip), %rsi      # 0x28e85
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x23b05
movq 0x127a3(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x4a8a(%rip), %rsi      # 0x282e6
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x23b05
movq %rbp, %rdi
leaq 0x5634(%rip), %rsi      # 0x28eb4
callq 0x132f3
testb %al, %al
je 0x23913
incl %r13d
cmpl %r12d, %r13d
jge 0x23967
movslq %r13d, %rax
movq (%r15,%rax,8), %rdi
callq 0x1dca8
movb $0x1, %bl
movl %eax, 0x18(%rsp)
testl %eax, %eax
jns 0x2370e
movq 0x12736(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x55ee(%rip), %rsi      # 0x28eb7
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x23b05
movq 0x12706(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x5567(%rip), %rsi      # 0x28e60
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x23b05
movq %rbp, %rdi
leaq 0x3a02(%rip), %rsi      # 0x2731f
callq 0x132f3
testb %al, %al
je 0x23997
incl %r13d
cmpl %r12d, %r13d
jge 0x239eb
movslq %r13d, %rax
movq (%r15,%rax,8), %rdi
callq 0x1dd0d
movaps %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
ja 0x23aa1
movb $0x1, %bl
ucomiss 0x16ae(%rip), %xmm1     # 0x25004
ja 0x23aa1
movss %xmm1, 0x10(%rsp)
jmp 0x2370e
movq 0x12682(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x54e3(%rip), %rsi      # 0x28e60
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x23b05
movq %rbp, %rdi
leaq 0x5545(%rip), %rsi      # 0x28ee6
callq 0x132f3
testb %al, %al
je 0x23a1b
incl %r13d
cmpl %r12d, %r13d
jge 0x23a60
movslq %r13d, %rax
movq (%r15,%rax,8), %rdi
callq 0x1dd0d
movaps %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
ja 0x23ad4
movb $0x1, %bl
ucomiss 0x162a(%rip), %xmm1     # 0x25004
ja 0x23ad4
movss %xmm1, 0xc(%rsp)
jmp 0x2370e
movq 0x125fe(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x3921(%rip), %rsi      # 0x27322
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x23b05
movq 0x68(%rsp), %rax
cmpb $0x2d, (%rax)
jne 0x23a8d
movq 0x125c4(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x365d(%rip), %rsi      # 0x27098
callq 0x53f0
movq %rax, %rdi
movq %rbp, %rsi
callq 0x53a0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x23b05
movq 0x12589(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x5473(%rip), %rsi      # 0x28ee9
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x23b05
movb $0x1, %bl
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x77fc
jmp 0x2370e
movss %xmm1, 0x10(%rsp)
movq 0x12542(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x3893(%rip), %rsi      # 0x27350
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x23b05
movss %xmm1, 0xc(%rsp)
movq 0x1250f(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x5427(%rip), %rsi      # 0x28f17
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
xorl %ebx, %ebx
pushq $0x1
popq %r14
jmp 0x2370e
movq %rax, %r14
cmpl $0x1, %edx
jne 0x23e76
movq %r14, %rdi
callq 0x5170
movq 0x124c5(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x53af(%rip), %rsi      # 0x28ee9
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
callq 0x5640
jmp 0x23b05
movq %rax, %r14
cmpl $0x1, %edx
jne 0x23e76
movq %r14, %rdi
callq 0x5170
movq 0x1247f(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x37a2(%rip), %rsi      # 0x27322
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
callq 0x5640
jmp 0x23b05
movq %rax, %r14
cmpl $0x1, %edx
jne 0x23e76
movq %r14, %rdi
callq 0x5170
movq 0x12436(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x5297(%rip), %rsi      # 0x28e60
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
callq 0x5640
jmp 0x23b05
movq %rax, %r14
cmpl $0x1, %edx
jne 0x23e76
movq %r14, %rdi
callq 0x5170
movq 0x123ed(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x524e(%rip), %rsi      # 0x28e60
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
callq 0x5640
jmp 0x23b05
movq 0x28(%rsp), %rax
cmpq 0x20(%rsp), %rax
je 0x23c94
leaq 0x267e(%rip), %rsi      # 0x262c2
leaq 0x48(%rsp), %rdi
callq 0x132f3
testb %al, %al
movl 0x1c(%rsp), %ebp
je 0x23cae
xorps %xmm0, %xmm0
movss 0x10(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jne 0x23cae
jp 0x23cae
testl %ebp, %ebp
jne 0x23cae
movss 0xc(%rsp), %xmm0
ucomiss 0x138d(%rip), %xmm0     # 0x25004
jne 0x23cae
jp 0x23cae
xorps %xmm0, %xmm0
movss 0xc(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jne 0x23cae
jp 0x23cae
leaq 0x52b0(%rip), %rsi      # 0x28f42
jmp 0x23cda
movq 0x12355(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, 0x40(%rsp)
leaq 0x33ff(%rip), %rsi      # 0x270ab
jmp 0x23cda
movss 0x10(%rsp), %xmm0
ucomiss 0xc(%rsp), %xmm0
jae 0x23cd3
movl 0x18(%rsp), %r12d
cmpl %r12d, %ebp
jl 0x23d2b
testl %r12d, %r12d
je 0x23d2b
leaq 0x52f0(%rip), %rsi      # 0x28fc1
jmp 0x23cda
leaq 0x52b6(%rip), %rsi      # 0x28f90
movq 0x40(%rsp), %rdi
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
callq 0x23524
pushq $0x1
popq %r14
leaq 0x20(%rsp), %rdi
callq 0x911e
leaq 0x88(%rsp), %rdi
callq 0x5778
leaq 0x48(%rsp), %rdi
callq 0x5778
movl %r14d, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1df8a
movq 0x12281(%rip), %rdi     # 0x35fb8
leaq 0x52ae(%rip), %rsi      # 0x28fec
callq 0x53f0
leaq 0x48(%rsp), %rsi
movq %rax, %rdi
callq 0x53a0
movq %rax, %rdi
callq 0x51c0
movq 0x12259(%rip), %rdi     # 0x35fb8
leaq 0x5298(%rip), %rsi      # 0x28ffe
callq 0x53f0
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %rax
movq %rax, %rsi
subq %rbx, %rsi
sarq $0x5, %rsi
movslq 0x1277a(%rip), %rcx     # 0x36500
cmpq %rcx, %rsi
jbe 0x23de0
movq 0x12226(%rip), %rdi     # 0x35fb8
callq 0x5280
leaq 0x2d27(%rip), %rsi      # 0x26ac5
movq %rax, %rdi
callq 0x53f0
movq 0x1220b(%rip), %rdi     # 0x35fb8
callq 0x51c0
leaq 0x20(%rsp), %rdi
leaq 0x48(%rsp), %rsi
movss 0x10(%rsp), %xmm0
movss 0xc(%rsp), %xmm1
movl %ebp, %edx
movl %r12d, %ecx
callq 0x1ccc5
xorl %r14d, %r14d
testl %eax, %eax
setne %r14b
jmp 0x23cf5
movq 0x121d1(%rip), %r14     # 0x35fb8
leaq 0x256f(%rip), %r15      # 0x2635d
cmpq %rax, %rbx
je 0x23da6
movq %r14, %rdi
movq %rbx, %rsi
callq 0x53a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x53f0
addq $0x20, %rbx
movq 0x28(%rsp), %rax
jmp 0x23dee
jmp 0x23e73
movq %rax, %r14
callq 0x5640
jmp 0x23e76
jmp 0x23e73
movq %rax, %r14
callq 0x5640
jmp 0x23e76
jmp 0x23e73
movq %rax, %r14
callq 0x5640
jmp 0x23e76
jmp 0x23e73
movq %rax, %r14
callq 0x5640
jmp 0x23e76
movq %rax, %rdi
callq 0x7102
movq %rax, %r14
leaq 0xa8(%rsp), %rdi
callq 0x5778
jmp 0x23e76
jmp 0x23e73
movq %rax, %r14
jmp 0x23e97
movq %rax, %r14
jmp 0x23ea1
jmp 0x23e6e
jmp 0x23e6e
movq %rax, %r14
jmp 0x23e80
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0x5778
leaq 0x20(%rsp), %rdi
callq 0x911e
leaq 0x88(%rsp), %rdi
callq 0x5778
leaq 0x48(%rsp), %rdi
callq 0x5778
movq %r14, %rdi
callq 0x56c0