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

	std::string outfile="annotation.vcf";
	std::string reference="";
	std::vector < std::string > args;
	bool snponly=false;
	bool includerepeats=false;
	bool includeproduct=false;

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

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

		if (arg=="-h" || arg=="--help"){
			annotateHelp();
			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"){
			includerepeats = true;
		}
		else if (arg == "-p"){
			includeproduct = true;
		}
		else if (arg == "-o"){
			i++;
			if (i<argc){
				outfile = std::string(argv[i])+".vcf";
			}
			else {
				std::cerr << std::endl << "Expecting file name after -o flag" << std::endl << std::endl;
				return 1;
			}
		}
		else if (arg == "-r"){
			i++;
			if (i<argc){
				reference = argv[i];
			}
			else {
				std::cerr << std::endl << "Expecting file name after -r flag" << std::endl << std::endl;
				return 1;
			}
		}
		else if (arg == "-v"){
			snponly = true;
		}
		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;
		annotateHelp();
		return 1;
	}
	if (reference==""){
		std::cerr << std::endl << "Reference sequence is required" << std::endl;
		annotateHelp();
		return 1;
	}

	skaVersion();

	std::cout << "Annotating split kmer matches in " << reference << " 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 (snponly){
		std::cout << "Only variant sites will be included" << std::endl;
	}
	if (includerepeats){
		std::cout << "Matches in repeats will be included" << std::endl;
	}
	else {
		std::cout << "Matches in repeats will not be included" << std::endl;
	}
	if (includeproduct){
		std::cout << "Product information for CDSs will be printed" << std::endl;
	}
	else{
		std::cout << "Product information for CDSs will not be printed" << std::endl;
	}

	std::cout << "Output will be written to " << outfile << std::endl << std::endl;


	if (findKmersInFasta(args, reference, snponly, includerepeats, includeproduct, outfile)){return 1;}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, 0x18(%rsp)
movl %edi, %ebp
leaq 0x87c5(%rip), %rsi      # 0x27536
leaq 0x78(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x77c0
leaq 0x753b(%rip), %rsi      # 0x262c2
leaq 0x38(%rsp), %rdi
leaq 0xb8(%rsp), %rdx
callq 0x77c0
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
pushq $0x2
popq %r13
movl $0x0, 0xc(%rsp)
leaq 0xb8(%rsp), %r15
leaq 0x58(%rsp), %r12
leaq 0x98(%rsp), %rbx
movl $0x0, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
cmpl %ebp, %r13d
jge 0x1f097
movslq %r13d, %rax
movq 0x18(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x77c0
movq %r15, %rdi
leaq 0x81ef(%rip), %rsi      # 0x26ff3
callq 0x132f3
testb %al, %al
jne 0x1ee20
movq %r15, %rdi
leaq 0x81df(%rip), %rsi      # 0x26ff6
callq 0x132f3
testb %al, %al
je 0x1ee45
xorl %r14d, %r14d
callq 0x1ec48
xorl %r12d, %r12d
movq %r15, %rdi
callq 0x5778
incl %r13d
testb %r12b, %r12b
leaq 0x58(%rsp), %r12
jne 0x1edda
jmp 0x1f263
movq %r15, %rdi
leaq 0x8224(%rip), %rsi      # 0x27073
callq 0x132f3
testb %al, %al
je 0x1ee91
incl %r13d
cmpl %ebp, %r13d
jge 0x1eeb2
movslq %r13d, %rax
movq 0x18(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
movq %r12, %rdi
movq %rbx, %rdx
callq 0x77c0
movq %r12, %rdi
leaq 0x20(%rsp), %rsi
callq 0x7529
movq %r12, %rdi
callq 0x5778
movb $0x1, %r12b
jmp 0x1ee2b
movq %r15, %rdi
leaq 0x86aa(%rip), %rsi      # 0x27545
callq 0x132f3
movb $0x1, %r12b
testb %al, %al
je 0x1eee9
movb $0x1, %al
movl %eax, 0x14(%rsp)
jmp 0x1ee2b
movq 0x17137(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x81ae(%rip), %rsi      # 0x27076
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
xorl %r12d, %r12d
pushq $0x1
popq %r14
jmp 0x1ee2b
movq %r15, %rdi
leaq 0x842c(%rip), %rsi      # 0x2731f
callq 0x132f3
movb $0x1, %r12b
testb %al, %al
je 0x1ef0a
movb $0x1, %al
movl %eax, 0x10(%rsp)
jmp 0x1ee2b
movq %r15, %rdi
leaq 0x83e9(%rip), %rsi      # 0x272fd
callq 0x132f3
testb %al, %al
je 0x1ef86
incl %r13d
cmpl %ebp, %r13d
jge 0x1efbc
movslq %r13d, %rax
movq 0x18(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
movq %rbx, %rdi
leaq 0xb(%rsp), %rdx
callq 0x77c0
leaq 0x58(%rsp), %rdi
leaq 0x98(%rsp), %rsi
leaq 0x85ea(%rip), %rdx      # 0x27540
callq 0xf751
leaq 0x78(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x54a0
leaq 0x58(%rsp), %rdi
callq 0x5778
leaq 0x98(%rsp), %rdi
callq 0x5778
jmp 0x1ee2b
movq %r15, %rdi
leaq 0x85da(%rip), %rsi      # 0x2756a
callq 0x132f3
testb %al, %al
je 0x1efec
incl %r13d
cmpl %ebp, %r13d
jge 0x1f00d
movslq %r13d, %rax
movq 0x18(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
leaq 0x38(%rsp), %rdi
callq 0x5730
jmp 0x1ee2b
movq 0x1702d(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x8576(%rip), %rsi      # 0x27548
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x1eedd
movq %r15, %rdi
leaq 0x83aa(%rip), %rsi      # 0x273a0
callq 0x132f3
movb $0x1, %r12b
testb %al, %al
je 0x1f03d
movb $0x1, %al
movl %eax, 0xc(%rsp)
jmp 0x1ee2b
movq 0x16fdc(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x854a(%rip), %rsi      # 0x2756d
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x1eedd
movq 0xb8(%rsp), %rax
cmpb $0x2d, (%rax)
jne 0x1f085
movq 0x16f9f(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x8038(%rip), %rsi      # 0x27098
callq 0x53f0
movq %rax, %rdi
movq %r15, %rsi
callq 0x53a0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x1eedd
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x77fc
jmp 0x1ee2b
movq 0x28(%rsp), %rax
cmpq 0x20(%rsp), %rax
je 0x1f0cd
leaq 0x7218(%rip), %rsi      # 0x262c2
leaq 0x38(%rsp), %rdi
callq 0x132f3
testb %al, %al
je 0x1f0fe
movq 0x16f31(%rip), %rdi     # 0x35ff0
callq 0x51c0
leaq 0x84c4(%rip), %rsi      # 0x2758f
jmp 0x1f0e0
movq 0x16f1c(%rip), %rdi     # 0x35ff0
callq 0x51c0
leaq 0x7fcb(%rip), %rsi      # 0x270ab
movq %rax, %rdi
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
callq 0x1ec48
pushq $0x1
popq %r14
jmp 0x1f263
callq 0x1df8a
movl 0xc(%rsp), %ebp
movl 0x10(%rsp), %r12d
movl 0x14(%rsp), %r13d
movq 0x16ea0(%rip), %rdi     # 0x35fb8
leaq 0x848f(%rip), %rsi      # 0x275ae
callq 0x53f0
leaq 0x38(%rsp), %rsi
movq %rax, %rdi
callq 0x53a0
leaq 0x6846(%rip), %rsi      # 0x2597e
movq %rax, %rdi
callq 0x53f0
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %rax
movq %rax, %rsi
subq %rbx, %rsi
sarq $0x5, %rsi
movslq 0x173a5(%rip), %rcx     # 0x36500
cmpq %rcx, %rsi
jbe 0x1f296
movq 0x16e4d(%rip), %rdi     # 0x35fb8
callq 0x5280
leaq 0x794e(%rip), %rsi      # 0x26ac5
movq %rax, %rdi
callq 0x53f0
movq 0x16e32(%rip), %rdi     # 0x35fb8
callq 0x51c0
testb $0x1, %bpl
je 0x1f1ac
movq 0x16e20(%rip), %rdi     # 0x35fb8
leaq 0x8431(%rip), %rsi      # 0x275d0
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
leaq 0x8441(%rip), %rax      # 0x275f4
leaq 0x845e(%rip), %rsi      # 0x27618
testb $0x1, %r13b
cmovneq %rax, %rsi
movq 0x16def(%rip), %rdi     # 0x35fb8
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
leaq 0x8463(%rip), %rax      # 0x27640
leaq 0x8489(%rip), %rsi      # 0x2766d
testb $0x1, %r12b
cmovneq %rax, %rsi
movq 0x16dc5(%rip), %rdi     # 0x35fb8
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq 0x16db1(%rip), %rdi     # 0x35fb8
leaq 0x820a(%rip), %rsi      # 0x27418
callq 0x53f0
leaq 0x78(%rsp), %rsi
movq %rax, %rdi
callq 0x53a0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
movzbl %bpl, %edx
andl $0x1, %edx
movzbl %r13b, %ecx
andl $0x1, %ecx
movzbl %r12b, %r8d
andl $0x1, %r8d
leaq 0x20(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x78(%rsp), %r9
callq 0x10d5a
xorl %r14d, %r14d
testl %eax, %eax
setne %r14b
leaq 0x20(%rsp), %rdi
callq 0x911e
leaq 0x38(%rsp), %rdi
callq 0x5778
leaq 0x78(%rsp), %rdi
callq 0x5778
movl %r14d, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x16d1b(%rip), %r14     # 0x35fb8
leaq 0x70b9(%rip), %r15      # 0x2635d
cmpq %rax, %rbx
je 0x1f17f
movq %r14, %rdi
movq %rbx, %rsi
callq 0x53a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x53f0
addq $0x20, %rbx
movq 0x28(%rsp), %rax
jmp 0x1f2a4
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
jmp 0x1f2e5
jmp 0x1f2fc
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x5778
jmp 0x1f2ff
jmp 0x1f2fc
movq %rax, %rbx
jmp 0x1f320
jmp 0x1f2f7
jmp 0x1f2f7
movq %rax, %rbx
jmp 0x1f30c
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x5778
leaq 0x20(%rsp), %rdi
callq 0x911e
leaq 0x38(%rsp), %rdi
callq 0x5778
leaq 0x78(%rsp), %rdi
callq 0x5778
movq %rbx, %rdi
callq 0x56c0