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

	long int kmersize=15;
	std::vector < std::string > args;

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

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

		if (arg=="-h" || arg=="--help"){
			allelesHelp();
			return 0;
		}
		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 == "-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 << std::endl;
		allelesHelp();
		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 << std::endl;

	if (allelesToKmers(args, kmersize)){return 1;}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0xf, -0x18(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x1ab40
movl $0x2, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x4cd19
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xc0(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x6910
movq -0xc0(%rbp), %rsi
movq -0xb8(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0xab20
jmp 0x4c742
leaq -0x59(%rbp), %rdi
callq 0x65a0
leaq 0xe895(%rip), %rsi      # 0x5afe7
leaq -0x58(%rbp), %rdi
callq 0x2dce0
movb %al, -0xc1(%rbp)
jmp 0x4c763
movb -0xc1(%rbp), %al
testb $0x1, %al
jne 0x4c793
jmp 0x4c76f
leaq 0xe874(%rip), %rsi      # 0x5afea
leaq -0x58(%rbp), %rdi
callq 0x2dce0
movb %al, -0xc2(%rbp)
jmp 0x4c787
movb -0xc2(%rbp), %al
testb $0x1, %al
jne 0x4c793
jmp 0x4c7d8
callq 0x4c510
jmp 0x4c79a
movl $0x0, -0x4(%rbp)
movl $0x1, -0x70(%rbp)
jmp 0x4cce5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x59(%rbp), %rdi
callq 0x65a0
jmp 0x4cf69
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x4cd0b
leaq 0xe812(%rip), %rsi      # 0x5aff1
leaq -0x58(%rbp), %rdi
callq 0x2dce0
movb %al, -0xc3(%rbp)
jmp 0x4c7f0
movb -0xc3(%rbp), %al
testb $0x1, %al
jne 0x4c7ff
jmp 0x4caa7
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x4c904
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x4c020
movq %rax, -0xd0(%rbp)
jmp 0x4c82e
movq -0xd0(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x4c902
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x4cd0b
movq -0x68(%rbp), %rdi
callq 0x6200
movq %rax, -0x78(%rbp)
movq 0x2c782(%rip), %rdi     # 0x78ff0
movq 0x2c71b(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0xd8(%rbp)
jmp 0x4c883
movq -0xd8(%rbp), %rdi
leaq 0xe763(%rip), %rsi      # 0x5aff4
callq 0x6520
movq %rax, -0xe0(%rbp)
jmp 0x4c89f
movq -0xe0(%rbp), %rdi
movq 0x2c6e3(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0xe8(%rbp)
jmp 0x4c8bb
movq -0xe8(%rbp), %rdi
movq 0x2c6c7(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x4c8d0
movl $0x1, -0x4(%rbp)
movl $0x1, -0x70(%rbp)
callq 0x6860
jmp 0x4c8f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
callq 0x6860
jmp 0x4c8fd
jmp 0x4cce5
jmp 0x4cd0b
jmp 0x4c980
movq 0x2c6e5(%rip), %rdi     # 0x78ff0
movq 0x2c67e(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0xf0(%rbp)
jmp 0x4c920
movq -0xf0(%rbp), %rdi
leaq 0xe6c6(%rip), %rsi      # 0x5aff4
callq 0x6520
movq %rax, -0xf8(%rbp)
jmp 0x4c93c
movq -0xf8(%rbp), %rdi
movq 0x2c646(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x100(%rbp)
jmp 0x4c958
movq -0x100(%rbp), %rdi
movq 0x2c62a(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x4c96d
movl $0x1, -0x4(%rbp)
movl $0x1, -0x70(%rbp)
jmp 0x4cce5
movq -0x18(%rbp), %rax
movslq 0x2cca5(%rip), %rcx     # 0x79630
cmpq %rcx, %rax
jl 0x4c9b8
movq -0x18(%rbp), %rax
movslq 0x2cc99(%rip), %rcx     # 0x79634
cmpq %rcx, %rax
jg 0x4c9b8
movq -0x18(%rbp), %rax
movl $0x3, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
je 0x4caa2
movq 0x2c631(%rip), %rdi     # 0x78ff0
movq 0x2c5ca(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x108(%rbp)
jmp 0x4c9d4
movq -0x108(%rbp), %rdi
leaq 0xe63b(%rip), %rsi      # 0x5b01d
callq 0x6520
movq %rax, -0x110(%rbp)
jmp 0x4c9f0
movq -0x110(%rbp), %rdi
movl 0x2cc33(%rip), %esi     # 0x79630
callq 0x68d0
movq %rax, -0x118(%rbp)
jmp 0x4ca0b
movq -0x118(%rbp), %rdi
leaq 0xdb5d(%rip), %rsi      # 0x5a576
callq 0x6520
movq %rax, -0x120(%rbp)
jmp 0x4ca27
movq -0x120(%rbp), %rdi
movl 0x2cc00(%rip), %esi     # 0x79634
callq 0x68d0
movq %rax, -0x128(%rbp)
jmp 0x4ca42
movq -0x128(%rbp), %rdi
leaq 0xe5fb(%rip), %rsi      # 0x5b04b
callq 0x6520
movq %rax, -0x130(%rbp)
jmp 0x4ca5e
movq -0x130(%rbp), %rdi
movq 0x2c524(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x138(%rbp)
jmp 0x4ca7a
movq -0x138(%rbp), %rdi
movq 0x2c508(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x4ca8f
movl $0x1, -0x4(%rbp)
movl $0x1, -0x70(%rbp)
jmp 0x4cce5
jmp 0x4ccdc
leaq 0xe5b9(%rip), %rsi      # 0x5b067
leaq -0x58(%rbp), %rdi
callq 0x2dce0
movb %al, -0x139(%rbp)
jmp 0x4cabf
movb -0x139(%rbp), %al
testb $0x1, %al
jne 0x4cace
jmp 0x4cc0c
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x4cb8b
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x150(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x6910
movq -0x150(%rbp), %rsi
movq -0x148(%rbp), %rdx
leaq -0x98(%rbp), %rdi
callq 0xab20
jmp 0x4cb25
leaq -0x98(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xa6a0
jmp 0x4cb37
leaq -0x98(%rbp), %rdi
callq 0x6a08
leaq -0x99(%rbp), %rdi
callq 0x65a0
jmp 0x4cc07
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x4cb7a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x6a08
leaq -0x99(%rbp), %rdi
callq 0x65a0
jmp 0x4cd0b
movq 0x2c45e(%rip), %rdi     # 0x78ff0
movq 0x2c3f7(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x158(%rbp)
jmp 0x4cba7
movq -0x158(%rbp), %rdi
leaq 0xe4b5(%rip), %rsi      # 0x5b06a
callq 0x6520
movq %rax, -0x160(%rbp)
jmp 0x4cbc3
movq -0x160(%rbp), %rdi
movq 0x2c3bf(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x168(%rbp)
jmp 0x4cbdf
movq -0x168(%rbp), %rdi
movq 0x2c3a3(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x4cbf4
movl $0x1, -0x4(%rbp)
movl $0x1, -0x70(%rbp)
jmp 0x4cce5
jmp 0x4ccda
xorl %eax, %eax
movl %eax, %esi
leaq -0x58(%rbp), %rdi
callq 0x69e0
movq %rax, -0x170(%rbp)
jmp 0x4cc22
movq -0x170(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x4ccc7
movq 0x2c3b4(%rip), %rdi     # 0x78ff0
movq 0x2c34d(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x178(%rbp)
jmp 0x4cc51
movq -0x178(%rbp), %rdi
leaq 0xe42d(%rip), %rsi      # 0x5b08c
callq 0x6520
movq %rax, -0x180(%rbp)
jmp 0x4cc6d
movq -0x180(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x64d0
movq %rax, -0x188(%rbp)
jmp 0x4cc86
movq -0x188(%rbp), %rdi
movq 0x2c2fc(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x190(%rbp)
jmp 0x4cca2
movq -0x190(%rbp), %rdi
movq 0x2c2e0(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x4ccb7
movl $0x1, -0x4(%rbp)
movl $0x1, -0x70(%rbp)
jmp 0x4cce5
leaq -0x30(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0xabd0
jmp 0x4ccd6
jmp 0x4ccd8
jmp 0x4ccda
jmp 0x4ccdc
jmp 0x4ccde
movl $0x0, -0x70(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x6a08
movl -0x70(%rbp), %eax
testl %eax, %eax
jne 0x4cf54
jmp 0x4ccfb
jmp 0x4ccfd
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x4c6fa
leaq -0x58(%rbp), %rdi
callq 0x6a08
jmp 0x4cf69
leaq -0x30(%rbp), %rdi
callq 0xb670
cmpq $0x1, %rax
jae 0x4cdc0
movq 0x2c2bd(%rip), %rdi     # 0x78ff0
movq 0x2c256(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x198(%rbp)
jmp 0x4cd48
movq -0x198(%rbp), %rdi
leaq 0xe349(%rip), %rsi      # 0x5b09f
callq 0x6520
movq %rax, -0x1a0(%rbp)
jmp 0x4cd64
movq -0x1a0(%rbp), %rdi
movq 0x2c21e(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x1a8(%rbp)
jmp 0x4cd80
movq -0x1a8(%rbp), %rdi
movq 0x2c202(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x4cd95
callq 0x4c510
jmp 0x4cd9c
movl $0x1, -0x4(%rbp)
movl $0x1, -0x70(%rbp)
jmp 0x4cf54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x4cf69
callq 0x4c460
jmp 0x4cdc7
movq 0x2c1da(%rip), %rdi     # 0x78fa8
leaq 0xe2dc(%rip), %rsi      # 0x5b0b1
callq 0x6520
movq %rax, -0x1b0(%rbp)
jmp 0x4cde3
movq -0x1b0(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6950
movq %rax, -0x1b8(%rbp)
jmp 0x4cdfc
movq -0x1b8(%rbp), %rdi
leaq 0xc9cf(%rip), %rsi      # 0x597d9
callq 0x6520
jmp 0x4ce11
leaq -0x30(%rbp), %rdi
callq 0xb670
movslq 0x2c81f(%rip), %rcx     # 0x79640
cmpq %rcx, %rax
jbe 0x4ce61
leaq -0x30(%rbp), %rdi
callq 0xb670
movq %rax, %rsi
movq 0x2c16f(%rip), %rdi     # 0x78fa8
callq 0x6120
movq %rax, -0x1c0(%rbp)
jmp 0x4ce47
movq -0x1c0(%rbp), %rdi
leaq 0xdc64(%rip), %rsi      # 0x5aab9
callq 0x6520
jmp 0x4ce5c
jmp 0x4cee5
leaq -0x30(%rbp), %rdi
callq 0xb4c0
movq %rax, -0xa8(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xb340
movq %rax, -0xb0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x4a690
testb $0x1, %al
jne 0x4ce9a
jmp 0x4cee3
leaq -0xa8(%rbp), %rdi
callq 0x30840
movq %rax, %rsi
movq 0x2c0f8(%rip), %rdi     # 0x78fa8
callq 0x64d0
movq %rax, -0x1c8(%rbp)
jmp 0x4cebe
movq -0x1c8(%rbp), %rdi
leaq 0xd481(%rip), %rsi      # 0x5a34d
callq 0x6520
jmp 0x4ced3
jmp 0x4ced5
leaq -0xa8(%rbp), %rdi
callq 0x4a6d0
jmp 0x4ce71
jmp 0x4cee5
movq 0x2c0bc(%rip), %rdi     # 0x78fa8
movq 0x2c09d(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x1d0(%rbp)
jmp 0x4cf01
movq -0x1d0(%rbp), %rdi
movq 0x2c081(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x4cf16
leaq -0x30(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x1cee0
movl %eax, -0x1d4(%rbp)
jmp 0x4cf2b
movl -0x1d4(%rbp), %eax
cmpl $0x0, %eax
je 0x4cf46
movl $0x1, -0x4(%rbp)
movl $0x1, -0x70(%rbp)
jmp 0x4cf54
movl $0x0, -0x4(%rbp)
movl $0x1, -0x70(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xfe90
movl -0x4(%rbp), %eax
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0xfe90
movq -0x68(%rbp), %rdi
callq 0x6900
movq %rax, %rdi
callq 0x9b50
nopw %cs:(%rax,%rax)