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

	std::string outfile="fasta.skf";
	long int kmersize=15;
	bool circular=false;
	std::vector < std::string > args;

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

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

		if (arg=="-h" || arg=="--help"){
			fastaHelp();
			return 0;
		}
		else if (arg=="-c"){
			circular=true;
		}
		else if (arg == "-k"){
			i++;
			if (i<argc){
				try {
					kmersize = getint(argv[i]);
				}
				catch (const std::invalid_argument& e) {
					std::cerr << std::endl << "Expecting positive integer after -k flag" << std::endl << std::endl;
					return 1;
				}
			}
			else {
				std::cerr << std::endl << "Expecting positive integer after -k flag" << std::endl << std::endl;
				return 1;
			}
			if (kmersize < MinKmer || kmersize > MaxKmer || kmersize % 3 != 0){
				std::cerr << std::endl << "Kmer size must be a positive integer between " << MinKmer << " and " << MaxKmer << " and must be divisible by 3" << std::endl << std::endl;
				return 1;
			}
		}
		else if (arg == "-o"){
			i++;
			if (i<argc){
				outfile = std::string(argv[i])+".skf";
			}
			else {
				std::cerr << std::endl << "Expecting file name after -o flag" << 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[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;
		fastaHelp();
		return 1;
	}

	skaVersion();

	std::cout << "Creating split " << kmersize << "mers 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;
	if (circular){
		std::cout << "Contigs will be treated as circular" << std::endl;
	}
	else {
		std::cout << "Contigs will be treated as linear" << std::endl;
	}
	std::cout << "Output will be written to " << outfile << std::endl;

	std::cout << std::endl;

	if (fastaToKmers(args, outfile, kmersize, circular)){return 1;}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, 0x10(%rsp)
movl %edi, 0x4(%rsp)
leaq 0x7d04(%rip), %rsi      # 0x27d1d
leaq 0x38(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x77c0
movq $0xf, 0x18(%rsp)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
pushq $0x2
popq %r13
movl $0x0, 0xc(%rsp)
leaq 0x78(%rsp), %r15
leaq 0x98(%rsp), %rbx
leaq 0x58(%rsp), %rbp
cmpl 0x4(%rsp), %r13d
jge 0x203a0
movslq %r13d, %rax
movq 0x10(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x77c0
movq %r15, %rdi
leaq 0x6f68(%rip), %rsi      # 0x26ff3
callq 0x132f3
testb %al, %al
jne 0x200a7
movq %r15, %rdi
leaq 0x6f58(%rip), %rsi      # 0x26ff6
callq 0x132f3
testb %al, %al
je 0x200c7
xorl %r12d, %r12d
callq 0x1ff1c
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x5778
incl %r13d
testb %r12b, %r12b
jne 0x2005f
jmp 0x204e3
movq %r15, %rdi
leaq 0x78b2(%rip), %rsi      # 0x27983
callq 0x132f3
movb $0x1, %r12b
testb %al, %al
je 0x200e5
movb $0x1, %al
movl %eax, 0xc(%rsp)
jmp 0x200b2
movq %r15, %rdi
leaq 0x6f0e(%rip), %rsi      # 0x26ffd
callq 0x132f3
testb %al, %al
je 0x2019e
incl %r13d
cmpl 0x4(%rsp), %r13d
jge 0x20218
movslq %r13d, %rax
movq 0x10(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
callq 0x1dca8
movq %rax, %rcx
movq %rax, 0x18(%rsp)
cqto
pushq $0x3
popq %rsi
idivq %rsi
testq %rdx, %rdx
jne 0x2014c
movslq 0x163b9(%rip), %rax     # 0x364f0
cmpq %rax, %rcx
jl 0x2014c
movslq 0x163b1(%rip), %rax     # 0x364f4
cmpq %rax, %rcx
jle 0x200b2
movq 0x15e9d(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x6ec7(%rip), %rsi      # 0x27029
callq 0x53f0
movl 0x16383(%rip), %esi     # 0x364f0
movq %rax, %rdi
callq 0x56a0
movq %rax, %rdi
leaq 0x6407(%rip), %rsi      # 0x26586
callq 0x53f0
movl 0x1636a(%rip), %esi     # 0x364f4
movq %rax, %rdi
callq 0x56a0
leaq 0x6ebe(%rip), %rsi      # 0x27057
jmp 0x2022b
movq %r15, %rdi
leaq 0x7155(%rip), %rsi      # 0x272fd
callq 0x132f3
testb %al, %al
je 0x20248
incl %r13d
cmpl 0x4(%rsp), %r13d
jge 0x202a2
movslq %r13d, %rax
movq 0x10(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
movq %rbp, %rdi
leaq 0xb(%rsp), %rdx
callq 0x77c0
movq %rbp, %rsi
movq %rbx, %rbp
movq %rbx, %rdi
leaq 0x7b36(%rip), %rdx      # 0x27d22
callq 0xf751
leaq 0x38(%rsp), %rdi
movq %rbp, %rsi
callq 0x54a0
movq %rbp, %rdi
callq 0x5778
leaq 0x58(%rsp), %rbp
movq %rbp, %rdi
callq 0x5778
jmp 0x200b2
movq 0x15dd1(%rip), %rdi     # 0x35ff0
callq 0x51c0
leaq 0x6dd5(%rip), %rsi      # 0x27000
movq %rax, %rdi
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x2033c
movq %r15, %rdi
leaq 0x6e21(%rip), %rsi      # 0x27073
callq 0x132f3
testb %al, %al
je 0x202cf
incl %r13d
cmpl 0x4(%rsp), %r13d
jge 0x20311
movslq %r13d, %rax
movq 0x10(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
movq %rbx, %rdi
movq %rbp, %rdx
movq %rbx, %rbp
callq 0x77c0
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x7529
movq %rbp, %rdi
callq 0x5778
leaq 0x58(%rsp), %rbp
jmp 0x200b2
movq 0x15d47(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x7290(%rip), %rsi      # 0x27548
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x2033c
movq 0x78(%rsp), %rax
cmpb $0x2d, (%rax)
jne 0x20348
movq 0x15d10(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x6da9(%rip), %rsi      # 0x27098
callq 0x53f0
movq %rax, %rdi
movq %r15, %rsi
callq 0x53a0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x2033c
movq 0x15cd8(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x6d4f(%rip), %rsi      # 0x27076
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
xorl %r12d, %r12d
pushq $0x1
popq %r14
jmp 0x200b2
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x77fc
jmp 0x200b2
movq %rax, %r14
cmpl $0x1, %edx
jne 0x20589
movq %r14, %rdi
callq 0x5170
movq 0x15c7b(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x6c7c(%rip), %rsi      # 0x27000
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
callq 0x5640
jmp 0x2033c
movq 0x28(%rsp), %rax
cmpq 0x20(%rsp), %rax
je 0x204b7
callq 0x1df8a
movl 0xc(%rsp), %ebp
movq 0x15bf8(%rip), %rdi     # 0x35fb8
leaq 0x6cf6(%rip), %rsi      # 0x270bd
callq 0x53f0
movq 0x18(%rsp), %rsi
movq %rax, %rdi
callq 0x53e0
leaq 0x5401(%rip), %rsi      # 0x257e1
movq %rax, %rdi
callq 0x53f0
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %rax
movq %rax, %rsi
subq %rbx, %rsi
sarq $0x5, %rsi
movslq 0x160fd(%rip), %rcx     # 0x36500
cmpq %rcx, %rsi
jbe 0x2050c
movq 0x15ba5(%rip), %rdi     # 0x35fb8
callq 0x5280
leaq 0x66a6(%rip), %rsi      # 0x26ac5
movq %rax, %rdi
callq 0x53f0
movq 0x15b8a(%rip), %rdi     # 0x35fb8
callq 0x51c0
leaq 0x78ed(%rip), %rax      # 0x27d27
leaq 0x790a(%rip), %rsi      # 0x27d4b
testb $0x1, %bpl
cmovneq %rax, %rsi
movq 0x15b68(%rip), %rdi     # 0x35fb8
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq 0x15b54(%rip), %rdi     # 0x35fb8
leaq 0x6fad(%rip), %rsi      # 0x27418
callq 0x53f0
leaq 0x38(%rsp), %rsi
movq %rax, %rdi
callq 0x53a0
movq %rax, %rdi
callq 0x51c0
movq 0x15b2c(%rip), %rdi     # 0x35fb8
callq 0x51c0
movzbl %bpl, %ecx
andl $0x1, %ecx
leaq 0x20(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x101d0
xorl %r14d, %r14d
testl %eax, %eax
setne %r14b
jmp 0x204e3
movq 0x15b32(%rip), %rdi     # 0x35ff0
callq 0x51c0
leaq 0x6be1(%rip), %rsi      # 0x270ab
movq %rax, %rdi
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
callq 0x1ff1c
pushq $0x1
popq %r14
leaq 0x20(%rsp), %rdi
callq 0x911e
leaq 0x38(%rsp), %rdi
callq 0x5778
movl %r14d, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x15aa5(%rip), %r14     # 0x35fb8
leaq 0x5e43(%rip), %r15      # 0x2635d
cmpq %rax, %rbx
je 0x20427
movq %r14, %rdi
movq %rbx, %rsi
callq 0x53a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x53f0
addq $0x20, %rbx
movq 0x28(%rsp), %rax
jmp 0x2051a
jmp 0x20586
movq %rax, %r14
callq 0x5640
jmp 0x20589
movq %rax, %rdi
callq 0x7102
movq %rax, %r14
leaq 0x98(%rsp), %rdi
jmp 0x2056f
jmp 0x20586
movq %rax, %r14
leaq 0x58(%rsp), %rdi
callq 0x5778
jmp 0x20589
jmp 0x20586
movq %rax, %r14
jmp 0x205a7
jmp 0x20581
jmp 0x20581
movq %rax, %r14
jmp 0x20593
movq %rax, %r14
leaq 0x78(%rsp), %rdi
callq 0x5778
leaq 0x20(%rsp), %rdi
callq 0x911e
leaq 0x38(%rsp), %rdi
callq 0x5778
movq %r14, %rdi
callq 0x56c0