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

	std::string outprefix="reference_free";
	float minproportion=0.9;
	bool variantonly=false;
	bool printkmers=false;
	std::vector < std::string > args;
	std::vector < std::string > sample;

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

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

		if (arg=="-h" || arg=="--help"){
			alignHelp();
			return 0;
		}
		else if (arg == "-o"){
			i++;
			if (i<argc){
				outprefix = std::string(argv[i]);
			}
			else {
				std::cerr << std::endl << "Expecting string after -o flag" << 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 == "-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 == "-k"){
			printkmers = true;
		}
		else if (arg == "-s"){
			i++;
			if (i<argc){
				fileToVector(argv[i], sample);
			}
			else {
				std::cerr << std::endl << "Expecting file name after -s flag" << std::endl << std::endl;
				return 1;
			}
		}
		else if (arg == "-v"){
			variantonly = true;
		}
		else if (arg[0]=='-'){
			std::cerr << std::endl << "Unrecognised flag " << arg << std::endl << std::endl;
				return 1;
		}
		else {
			args.push_back(arg);
		}
	}

	if (variantonly){
		outprefix+="_variants";
	}

	//outprefix+=".aln";
	
	if (args.size()<1){
		std::cerr << std::endl << "Too few arguments" << std::endl;
		alignHelp();
		return 1;
	}

	skaVersion();

	std::cout << "Creating reference free alignment for ";
	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;
	std::cout << "Variable sites present in more than " << minproportion*100 << "% of isolates will be included" << std::endl;
	std::cout << "Output will be written to " << outprefix << std::endl << std::endl;

	if (alignKmers(minproportion, outprefix, args, variantonly, printkmers, sample)){return 1;}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x8c61(%rip), %rsi      # 0x272ee
leaq 0x30(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x77c0
movl $0x3f666666, 0xc(%rsp)  # imm = 0x3F666666
xorl %eax, %eax
movb %al, 0x9(%rsp)
movb %al, 0xb(%rsp)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x50(%rsp), %rax
andq $0x0, 0x10(%rax)
movaps %xmm0, (%rax)
pushq $0x2
popq %r15
leaq 0x88(%rsp), %r12
leaq 0x68(%rsp), %r13
cmpl %ebp, %r15d
jge 0x1ea19
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
movq %r12, %rdi
movq %r13, %rdx
callq 0x77c0
movq %r12, %rdi
leaq 0x88ef(%rip), %rsi      # 0x26ff3
callq 0x132f3
testb %al, %al
jne 0x1e720
movq %r12, %rdi
leaq 0x88df(%rip), %rsi      # 0x26ff6
callq 0x132f3
testb %al, %al
je 0x1e745
xorl %r13d, %r13d
callq 0x1e566
xorl %r14d, %r14d
movq %r12, %rdi
callq 0x5778
incl %r15d
testb %r13b, %r13b
leaq 0x68(%rsp), %r13
jne 0x1e6df
jmp 0x1eb6e
movq %r12, %rdi
leaq 0x8bae(%rip), %rsi      # 0x272fd
callq 0x132f3
testb %al, %al
je 0x1e792
incl %r15d
cmpl %ebp, %r15d
jge 0x1e7f3
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
leaq 0xa(%rsp), %rdx
callq 0x77c0
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x54a0
movq %r13, %rdi
callq 0x5778
movb $0x1, %r13b
jmp 0x1e72b
movq %r12, %rdi
leaq 0x8b83(%rip), %rsi      # 0x2731f
callq 0x132f3
testb %al, %al
je 0x1e823
incl %r15d
cmpl %ebp, %r15d
jge 0x1e864
movslq %r15d, %rax
movq (%rbx,%rax,8), %rdi
callq 0x1dd0d
movss %xmm0, 0xc(%rsp)
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
ja 0x1e7db
movb $0x1, %r13b
ucomiss 0x682f(%rip), %xmm0     # 0x25004
jbe 0x1e72b
movq 0x1780e(%rip), %rdi     # 0x35ff0
callq 0x51c0
leaq 0x8b62(%rip), %rsi      # 0x27350
jmp 0x1e877
movq 0x177f6(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x8af7(%rip), %rsi      # 0x27300
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x1e8d9
movq %r12, %rdi
leaq 0x8846(%rip), %rsi      # 0x27073
callq 0x132f3
testb %al, %al
je 0x1e891
incl %r15d
cmpl %ebp, %r15d
jge 0x1e8ae
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
leaq 0xa(%rsp), %rdx
callq 0x77c0
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
callq 0x7529
jmp 0x1e785
movq 0x17785(%rip), %rdi     # 0x35ff0
callq 0x51c0
leaq 0x8aab(%rip), %rsi      # 0x27322
movq %rax, %rdi
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x1e8d9
movq %r12, %rdi
leaq 0x8762(%rip), %rsi      # 0x26ffd
callq 0x132f3
testb %al, %al
je 0x1e8e5
movb $0x1, 0xb(%rsp)
jmp 0x1e78d
movq 0x1773b(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x87b2(%rip), %rsi      # 0x27076
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
xorl %r13d, %r13d
pushq $0x1
popq %r14
jmp 0x1e72b
movq %r12, %rdi
leaq 0x8a8c(%rip), %rsi      # 0x2737b
callq 0x132f3
testb %al, %al
je 0x1e926
incl %r15d
cmpl %ebp, %r15d
jge 0x1e943
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
leaq 0xa(%rsp), %rdx
callq 0x77c0
movq %r13, %rdi
leaq 0x50(%rsp), %rsi
callq 0x7529
jmp 0x1e785
movq %r12, %rdi
leaq 0x8a70(%rip), %rsi      # 0x273a0
callq 0x132f3
testb %al, %al
je 0x1e973
movb $0x1, 0x9(%rsp)
jmp 0x1e78d
movq 0x176a6(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x8a25(%rip), %rsi      # 0x2737e
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x1e8d9
movq 0x88(%rsp), %rax
cmpb $0x2d, (%rax)
jne 0x1e9bb
movq 0x17669(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x8702(%rip), %rsi      # 0x27098
callq 0x53f0
movq %rax, %rdi
movq %r12, %rsi
callq 0x53a0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x1e8d9
movb $0x1, %r13b
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x77fc
jmp 0x1e72b
movq %rax, %r14
cmpl $0x1, %edx
jne 0x1ec15
movq %r14, %rdi
callq 0x5170
movq 0x17605(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x8928(%rip), %rsi      # 0x27322
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
callq 0x5640
jmp 0x1e8d9
cmpb $0x1, 0x9(%rsp)
jne 0x1ea31
leaq 0x897c(%rip), %rsi      # 0x273a3
leaq 0x30(%rsp), %rdi
callq 0x5720
movq 0x18(%rsp), %rax
cmpq 0x10(%rsp), %rax
je 0x1eb42
callq 0x1df8a
movq 0x1756b(%rip), %rdi     # 0x35fb8
leaq 0x8959(%rip), %rsi      # 0x273ad
callq 0x53f0
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %rax
movq %rax, %rsi
subq %rbx, %rsi
sarq $0x5, %rsi
movslq 0x17a8c(%rip), %rcx     # 0x36500
cmpq %rcx, %rsi
jbe 0x1eba1
movq 0x17534(%rip), %rdi     # 0x35fb8
callq 0x5280
leaq 0x8035(%rip), %rsi      # 0x26ac5
movq %rax, %rdi
callq 0x53f0
movq 0x17519(%rip), %rdi     # 0x35fb8
callq 0x51c0
movq 0x1750d(%rip), %rdi     # 0x35fb8
leaq 0x8922(%rip), %rsi      # 0x273d4
callq 0x53f0
movss 0xc(%rsp), %xmm0
mulss 0x6ba7(%rip), %xmm0     # 0x2566c
movq %rax, %rdi
callq 0x5300
leaq 0x8925(%rip), %rsi      # 0x273f9
movq %rax, %rdi
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq 0x174cd(%rip), %rdi     # 0x35fb8
leaq 0x8926(%rip), %rsi      # 0x27418
callq 0x53f0
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x53a0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
leaq 0xc(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x9(%rsp), %rcx
leaq 0xb(%rsp), %r8
leaq 0x50(%rsp), %r9
callq 0xb44c
xorl %r14d, %r14d
testl %eax, %eax
setne %r14b
jmp 0x1eb6e
movq 0x174a7(%rip), %rdi     # 0x35ff0
callq 0x51c0
leaq 0x8556(%rip), %rsi      # 0x270ab
movq %rax, %rdi
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
callq 0x1e566
pushq $0x1
popq %r14
leaq 0x50(%rsp), %rdi
callq 0x911e
leaq 0x10(%rsp), %rdi
callq 0x911e
leaq 0x30(%rsp), %rdi
callq 0x5778
movl %r14d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x17410(%rip), %r14     # 0x35fb8
leaq 0x77ae(%rip), %r15      # 0x2635d
cmpq %rax, %rbx
je 0x1ea98
movq %r14, %rdi
movq %rbx, %rsi
callq 0x53a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x53f0
addq $0x20, %rbx
movq 0x18(%rsp), %rax
jmp 0x1ebaf
jmp 0x1ec12
movq %rax, %r14
callq 0x5640
jmp 0x1ec15
movq %rax, %rdi
callq 0x7102
jmp 0x1ebf1
jmp 0x1ec12
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0x5778
jmp 0x1ec15
jmp 0x1ec12
jmp 0x1ec12
movq %rax, %r14
jmp 0x1ec40
jmp 0x1ec0d
jmp 0x1ec0d
movq %rax, %r14
jmp 0x1ec22
movq %rax, %r14
leaq 0x88(%rsp), %rdi
callq 0x5778
leaq 0x50(%rsp), %rdi
callq 0x911e
leaq 0x10(%rsp), %rdi
callq 0x911e
leaq 0x30(%rsp), %rdi
callq 0x5778
movq %r14, %rdi
callq 0x56c0