// File: 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
movq %rsp, %rbp
subq $0x2a0, %rsp            # imm = 0x2A0
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x6910
movq -0x130(%rbp), %rdx
leaq 0xb7a1(%rip), %rsi      # 0x5bd11
leaq -0x30(%rbp), %rdi
callq 0xab20
jmp 0x5057b
leaq -0x31(%rbp), %rdi
callq 0x65a0
movq $0xf, -0x50(%rbp)
movb $0x0, -0x51(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x1ab40
movl $0x2, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x50de0
movq -0x10(%rbp), %rax
movslq -0x74(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x140(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x6910
movq -0x140(%rbp), %rsi
movq -0x138(%rbp), %rdx
leaq -0x98(%rbp), %rdi
callq 0xab20
jmp 0x505ee
leaq -0x99(%rbp), %rdi
callq 0x65a0
leaq 0xa9e6(%rip), %rsi      # 0x5afe7
leaq -0x98(%rbp), %rdi
callq 0x2dce0
movb %al, -0x141(%rbp)
jmp 0x50615
movb -0x141(%rbp), %al
testb $0x1, %al
jne 0x50648
jmp 0x50621
leaq 0xa9c2(%rip), %rsi      # 0x5afea
leaq -0x98(%rbp), %rdi
callq 0x2dce0
movb %al, -0x142(%rbp)
jmp 0x5063c
movb -0x142(%rbp), %al
testb $0x1, %al
jne 0x50648
jmp 0x506ad
callq 0x503f0
jmp 0x5064f
movl $0x0, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x50da3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x65a0
jmp 0x510ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x99(%rbp), %rdi
callq 0x65a0
jmp 0x510dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x50dcf
leaq 0xb2c3(%rip), %rsi      # 0x5b977
leaq -0x98(%rbp), %rdi
callq 0x2dce0
movb %al, -0x143(%rbp)
jmp 0x506c8
movb -0x143(%rbp), %al
testb $0x1, %al
jne 0x506d4
jmp 0x506dd
movb $0x1, -0x51(%rbp)
jmp 0x50d97
leaq 0xa90d(%rip), %rsi      # 0x5aff1
leaq -0x98(%rbp), %rdi
callq 0x2dce0
movb %al, -0x144(%rbp)
jmp 0x506f8
movb -0x144(%rbp), %al
testb $0x1, %al
jne 0x50707
jmp 0x509bb
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x50812
movq -0x10(%rbp), %rax
movslq -0x74(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x4c020
movq %rax, -0x150(%rbp)
jmp 0x50736
movq -0x150(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x50810
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x50dcf
movq -0x40(%rbp), %rdi
callq 0x6200
movq %rax, -0xa8(%rbp)
movq 0x28877(%rip), %rdi     # 0x78ff0
movq 0x28810(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x158(%rbp)
jmp 0x5078e
movq -0x158(%rbp), %rdi
leaq 0xa858(%rip), %rsi      # 0x5aff4
callq 0x6520
movq %rax, -0x160(%rbp)
jmp 0x507aa
movq -0x160(%rbp), %rdi
movq 0x287d8(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x168(%rbp)
jmp 0x507c6
movq -0x168(%rbp), %rdi
movq 0x287bc(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x507db
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
callq 0x6860
jmp 0x50806
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x6860
jmp 0x5080b
jmp 0x50da3
jmp 0x50dcf
jmp 0x50891
movq 0x287d7(%rip), %rdi     # 0x78ff0
movq 0x28770(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x170(%rbp)
jmp 0x5082e
movq -0x170(%rbp), %rdi
leaq 0xa7b8(%rip), %rsi      # 0x5aff4
callq 0x6520
movq %rax, -0x178(%rbp)
jmp 0x5084a
movq -0x178(%rbp), %rdi
movq 0x28738(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x180(%rbp)
jmp 0x50866
movq -0x180(%rbp), %rdi
movq 0x2871c(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x5087b
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x50da3
movq -0x50(%rbp), %rax
movslq 0x28d94(%rip), %rcx     # 0x79630
cmpq %rcx, %rax
jl 0x508c9
movq -0x50(%rbp), %rax
movslq 0x28d88(%rip), %rcx     # 0x79634
cmpq %rcx, %rax
jg 0x508c9
movq -0x50(%rbp), %rax
movl $0x3, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
je 0x509b6
movq 0x28720(%rip), %rdi     # 0x78ff0
movq 0x286b9(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x188(%rbp)
jmp 0x508e5
movq -0x188(%rbp), %rdi
leaq 0xa72a(%rip), %rsi      # 0x5b01d
callq 0x6520
movq %rax, -0x190(%rbp)
jmp 0x50901
movq -0x190(%rbp), %rdi
movl 0x28d22(%rip), %esi     # 0x79630
callq 0x68d0
movq %rax, -0x198(%rbp)
jmp 0x5091c
movq -0x198(%rbp), %rdi
leaq 0x9c4c(%rip), %rsi      # 0x5a576
callq 0x6520
movq %rax, -0x1a0(%rbp)
jmp 0x50938
movq -0x1a0(%rbp), %rdi
movl 0x28cef(%rip), %esi     # 0x79634
callq 0x68d0
movq %rax, -0x1a8(%rbp)
jmp 0x50953
movq -0x1a8(%rbp), %rdi
leaq 0xa6ea(%rip), %rsi      # 0x5b04b
callq 0x6520
movq %rax, -0x1b0(%rbp)
jmp 0x5096f
movq -0x1b0(%rbp), %rdi
movq 0x28613(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x1b8(%rbp)
jmp 0x5098b
movq -0x1b8(%rbp), %rdi
movq 0x285f7(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x509a0
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x50da3
jmp 0x50d95
leaq 0xa92f(%rip), %rsi      # 0x5b2f1
leaq -0x98(%rbp), %rdi
callq 0x2dce0
movb %al, -0x1b9(%rbp)
jmp 0x509d6
movb -0x1b9(%rbp), %al
testb $0x1, %al
jne 0x509e5
jmp 0x50b4c
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x50ac8
movq -0x10(%rbp), %rax
movslq -0x74(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x1d0(%rbp)
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x6910
movq -0x1d0(%rbp), %rsi
movq -0x1c8(%rbp), %rdx
leaq -0xe8(%rbp), %rdi
callq 0xab20
jmp 0x50a3c
leaq 0xb2d3(%rip), %rdx      # 0x5bd16
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x24a10
jmp 0x50a58
leaq -0x30(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x6640
leaq -0xc8(%rbp), %rdi
callq 0x6a08
leaq -0xe8(%rbp), %rdi
callq 0x6a08
leaq -0xe9(%rbp), %rdi
callq 0x65a0
jmp 0x50b47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x50ab7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x6a08
leaq -0xe9(%rbp), %rdi
callq 0x65a0
jmp 0x50dcf
movq 0x28521(%rip), %rdi     # 0x78ff0
movq 0x284ba(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x1d8(%rbp)
jmp 0x50ae4
movq -0x1d8(%rbp), %rdi
leaq 0xaa4a(%rip), %rsi      # 0x5b53c
callq 0x6520
movq %rax, -0x1e0(%rbp)
jmp 0x50b00
movq -0x1e0(%rbp), %rdi
movq 0x28482(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x1e8(%rbp)
jmp 0x50b1c
movq -0x1e8(%rbp), %rdi
movq 0x28466(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x50b31
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x50da3
jmp 0x50d93
leaq 0xa514(%rip), %rsi      # 0x5b067
leaq -0x98(%rbp), %rdi
callq 0x2dce0
movb %al, -0x1e9(%rbp)
jmp 0x50b67
movb -0x1e9(%rbp), %al
testb $0x1, %al
jne 0x50b76
jmp 0x50cb7
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x50c33
movq -0x10(%rbp), %rax
movslq -0x74(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x200(%rbp)
leaq -0x111(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x6910
movq -0x200(%rbp), %rsi
movq -0x1f8(%rbp), %rdx
leaq -0x110(%rbp), %rdi
callq 0xab20
jmp 0x50bcd
leaq -0x110(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xa6a0
jmp 0x50bdf
leaq -0x110(%rbp), %rdi
callq 0x6a08
leaq -0x111(%rbp), %rdi
callq 0x65a0
jmp 0x50cb2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x50c22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x6a08
leaq -0x111(%rbp), %rdi
callq 0x65a0
jmp 0x50dcf
movq 0x283b6(%rip), %rdi     # 0x78ff0
movq 0x2834f(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x208(%rbp)
jmp 0x50c4f
movq -0x208(%rbp), %rdi
leaq 0xa40d(%rip), %rsi      # 0x5b06a
callq 0x6520
movq %rax, -0x210(%rbp)
jmp 0x50c6b
movq -0x210(%rbp), %rdi
movq 0x28317(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x218(%rbp)
jmp 0x50c87
movq -0x218(%rbp), %rdi
movq 0x282fb(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x50c9c
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x50da3
jmp 0x50d91
xorl %eax, %eax
movl %eax, %esi
leaq -0x98(%rbp), %rdi
callq 0x69e0
movq %rax, -0x220(%rbp)
jmp 0x50cd0
movq -0x220(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x50d7b
movq 0x28306(%rip), %rdi     # 0x78ff0
movq 0x2829f(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x228(%rbp)
jmp 0x50cff
movq -0x228(%rbp), %rdi
leaq 0xa37f(%rip), %rsi      # 0x5b08c
callq 0x6520
movq %rax, -0x230(%rbp)
jmp 0x50d1b
movq -0x230(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x64d0
movq %rax, -0x238(%rbp)
jmp 0x50d37
movq -0x238(%rbp), %rdi
movq 0x2824b(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x240(%rbp)
jmp 0x50d53
movq -0x240(%rbp), %rdi
movq 0x2822f(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x50d68
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x50da3
leaq -0x70(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xabd0
jmp 0x50d8d
jmp 0x50d8f
jmp 0x50d91
jmp 0x50d93
jmp 0x50d95
jmp 0x50d97
jmp 0x50d99
movl $0x0, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x6a08
movl -0xa0(%rbp), %eax
testl %eax, %eax
jne 0x510be
jmp 0x50dbf
jmp 0x50dc1
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x505a0
leaq -0x98(%rbp), %rdi
callq 0x6a08
jmp 0x510dc
leaq -0x70(%rbp), %rdi
callq 0xb670
cmpq $0x1, %rax
jae 0x50e6a
movq 0x281fa(%rip), %rdi     # 0x78ff0
movq 0x28193(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x248(%rbp)
jmp 0x50e0b
movq -0x248(%rbp), %rdi
leaq 0xa286(%rip), %rsi      # 0x5b09f
callq 0x6520
movq %rax, -0x250(%rbp)
jmp 0x50e27
movq -0x250(%rbp), %rdi
movq 0x2815b(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x50e3c
callq 0x503f0
jmp 0x50e43
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x510be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x510dc
callq 0x4c460
jmp 0x50e71
movq 0x28130(%rip), %rdi     # 0x78fa8
leaq 0xa232(%rip), %rsi      # 0x5b0b1
callq 0x6520
movq %rax, -0x258(%rbp)
jmp 0x50e8d
movq -0x258(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x6950
movq %rax, -0x260(%rbp)
jmp 0x50ea6
movq -0x260(%rbp), %rdi
leaq 0x8925(%rip), %rsi      # 0x597d9
callq 0x6520
jmp 0x50ebb
leaq -0x70(%rbp), %rdi
callq 0xb670
movslq 0x28775(%rip), %rcx     # 0x79640
cmpq %rcx, %rax
jbe 0x50f0b
leaq -0x70(%rbp), %rdi
callq 0xb670
movq %rax, %rsi
movq 0x280c5(%rip), %rdi     # 0x78fa8
callq 0x6120
movq %rax, -0x268(%rbp)
jmp 0x50ef1
movq -0x268(%rbp), %rdi
leaq 0x9bba(%rip), %rsi      # 0x5aab9
callq 0x6520
jmp 0x50f06
jmp 0x50f8f
leaq -0x70(%rbp), %rdi
callq 0xb4c0
movq %rax, -0x120(%rbp)
leaq -0x70(%rbp), %rdi
callq 0xb340
movq %rax, -0x128(%rbp)
leaq -0x120(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x4a690
testb $0x1, %al
jne 0x50f44
jmp 0x50f8d
leaq -0x120(%rbp), %rdi
callq 0x30840
movq %rax, %rsi
movq 0x2804e(%rip), %rdi     # 0x78fa8
callq 0x64d0
movq %rax, -0x270(%rbp)
jmp 0x50f68
movq -0x270(%rbp), %rdi
leaq 0x93d7(%rip), %rsi      # 0x5a34d
callq 0x6520
jmp 0x50f7d
jmp 0x50f7f
leaq -0x120(%rbp), %rdi
callq 0x4a6d0
jmp 0x50f1b
jmp 0x50f8f
movq 0x28012(%rip), %rdi     # 0x78fa8
movq 0x27ff3(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x50fa4
testb $0x1, -0x51(%rbp)
je 0x50fdd
movq 0x27ff7(%rip), %rdi     # 0x78fa8
leaq 0xad63(%rip), %rsi      # 0x5bd1b
callq 0x6520
movq %rax, -0x278(%rbp)
jmp 0x50fc6
movq -0x278(%rbp), %rdi
movq 0x27fbc(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x50fdb
jmp 0x51010
movq 0x27fc4(%rip), %rdi     # 0x78fa8
leaq 0xad54(%rip), %rsi      # 0x5bd3f
callq 0x6520
movq %rax, -0x280(%rbp)
jmp 0x50ff9
movq -0x280(%rbp), %rdi
movq 0x27f89(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x5100e
jmp 0x51010
movq 0x27f91(%rip), %rdi     # 0x78fa8
leaq 0xa3ee(%rip), %rsi      # 0x5b40c
callq 0x6520
movq %rax, -0x288(%rbp)
jmp 0x5102c
movq -0x288(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x64d0
movq %rax, -0x290(%rbp)
jmp 0x51045
movq -0x290(%rbp), %rdi
movq 0x27f3d(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x5105a
movq 0x27f47(%rip), %rdi     # 0x78fa8
movq 0x27f28(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x5106f
movzbl -0x51(%rbp), %ecx
andl $0x1, %ecx
leaq -0x70(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x281b0
movl %eax, -0x294(%rbp)
jmp 0x5108f
movl -0x294(%rbp), %eax
cmpl $0x0, %eax
je 0x510ad
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x510be
movl $0x0, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
leaq -0x70(%rbp), %rdi
callq 0xfe90
leaq -0x30(%rbp), %rdi
callq 0x6a08
movl -0x4(%rbp), %eax
addq $0x2a0, %rsp            # imm = 0x2A0
popq %rbp
retq
leaq -0x70(%rbp), %rdi
callq 0xfe90
leaq -0x30(%rbp), %rdi
callq 0x6a08
movq -0x40(%rbp), %rdi
callq 0x6900
movq %rax, %rdi
callq 0x9b50
nop