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

	std::vector < std::string > args;
	std::vector < std::string > sample;
	std::string outfile="merged.skf";

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

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

		if (arg=="-h" || arg=="--help"){
			mergeHelp();
			return 0;
		}
		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 == "-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[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;
		mergeHelp();
		return 1;
	}

	if (outfile==""){
		std::cerr << std::endl << "Output file name is required" << std::endl;
		mergeHelp();
		return 1;
	}

	skaVersion();

	std::cout << "Merging ";
	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 << "Output will be written to " << outfile << std::endl << std::endl;

	if (mergeKmerFiles(outfile, args, sample)){return 1;}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %rbp
movl %edi, 0x8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
leaq 0x6524(%rip), %rsi      # 0x28884
leaq 0x58(%rsp), %rdi
leaq 0x98(%rsp), %rdx
callq 0x77c0
pushq $0x2
popq %r12
leaq 0x98(%rsp), %r14
leaq 0x78(%rsp), %r15
leaq 0xb8(%rsp), %rbx
cmpl 0x8(%rsp), %r12d
jge 0x225f0
movslq %r12d, %rax
movq (%rbp,%rax,8), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x77c0
movq %r14, %rdi
leaq 0x4c40(%rip), %rsi      # 0x26ff3
callq 0x132f3
testb %al, %al
jne 0x223cf
movq %r14, %rdi
leaq 0x4c30(%rip), %rsi      # 0x26ff6
callq 0x132f3
testb %al, %al
je 0x223f4
xorl %r13d, %r13d
callq 0x22263
xorl %r15d, %r15d
movq %r14, %rdi
callq 0x5778
incl %r12d
testb %r15b, %r15b
leaq 0x78(%rsp), %r15
jne 0x2238b
jmp 0x22707
movq %r14, %rdi
leaq 0x4eff(%rip), %rsi      # 0x272fd
callq 0x132f3
testb %al, %al
je 0x2246e
incl %r12d
cmpl 0x8(%rsp), %r12d
jge 0x224b1
movslq %r12d, %rax
movq %rbp, 0x50(%rsp)
movq (%rbp,%rax,8), %rsi
movq %rbx, %rbp
movq %rbx, %rdi
leaq 0xf(%rsp), %rdx
callq 0x77c0
movq %r15, %rdi
movq %rbp, %rsi
leaq 0x58e3(%rip), %rdx      # 0x27d22
callq 0xf751
leaq 0x58(%rsp), %rdi
movq %r15, %rsi
callq 0x54a0
movq %r15, %rdi
callq 0x5778
movq %rbp, %rdi
callq 0x5778
movb $0x1, %r15b
movq 0x50(%rsp), %rbp
jmp 0x223da
movq %r14, %rdi
leaq 0x4bfb(%rip), %rsi      # 0x27073
callq 0x132f3
testb %al, %al
je 0x224e1
incl %r12d
cmpl 0x8(%rsp), %r12d
jge 0x22532
movslq %r12d, %rax
movq (%rbp,%rax,8), %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x77c0
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
callq 0x7529
jmp 0x22522
movq 0x13b38(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x5081(%rip), %rsi      # 0x27548
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x225cf
movq %r14, %rdi
leaq 0x4e90(%rip), %rsi      # 0x2737b
callq 0x132f3
testb %al, %al
je 0x2255f
incl %r12d
cmpl 0x8(%rsp), %r12d
jge 0x225a4
movslq %r12d, %rax
movq (%rbp,%rax,8), %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x77c0
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
callq 0x7529
movq %r15, %rdi
callq 0x5778
movb $0x1, %r15b
jmp 0x223da
movq 0x13ab7(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x4b2e(%rip), %rsi      # 0x27076
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x225cf
movq 0x98(%rsp), %rax
cmpb $0x2d, (%rax)
jne 0x225db
movq 0x13a7d(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x4b16(%rip), %rsi      # 0x27098
callq 0x53f0
movq %rax, %rdi
movq %r14, %rsi
callq 0x53a0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
jmp 0x225cf
movq 0x13a45(%rip), %rdi     # 0x35ff0
callq 0x51c0
movq %rax, %rdi
leaq 0x4dc4(%rip), %rsi      # 0x2737e
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
xorl %r15d, %r15d
pushq $0x1
popq %r13
jmp 0x223da
movb $0x1, %r15b
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x77fc
jmp 0x223da
movq 0x18(%rsp), %rax
cmpq 0x10(%rsp), %rax
je 0x22626
leaq 0x3cbf(%rip), %rsi      # 0x262c2
leaq 0x58(%rsp), %rdi
callq 0x132f3
testb %al, %al
je 0x22657
movq 0x139d8(%rip), %rdi     # 0x35ff0
callq 0x51c0
leaq 0x626b(%rip), %rsi      # 0x2888f
jmp 0x22639
movq 0x139c3(%rip), %rdi     # 0x35ff0
callq 0x51c0
leaq 0x4a72(%rip), %rsi      # 0x270ab
movq %rax, %rdi
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
callq 0x22263
pushq $0x1
popq %r13
jmp 0x22707
callq 0x1df8a
movq 0x13955(%rip), %rdi     # 0x35fb8
leaq 0x6242(%rip), %rsi      # 0x288ac
callq 0x53f0
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %rax
movq %rax, %rsi
subq %rbx, %rsi
sarq $0x5, %rsi
movslq 0x13e76(%rip), %rcx     # 0x36500
cmpq %rcx, %rsi
jbe 0x2273a
movq 0x1391e(%rip), %rdi     # 0x35fb8
callq 0x5280
leaq 0x441f(%rip), %rsi      # 0x26ac5
movq %rax, %rdi
callq 0x53f0
movq 0x13903(%rip), %rdi     # 0x35fb8
callq 0x51c0
movq 0x138f7(%rip), %rdi     # 0x35fb8
leaq 0x4d50(%rip), %rsi      # 0x27418
callq 0x53f0
leaq 0x58(%rsp), %rsi
movq %rax, %rdi
callq 0x53a0
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x51c0
leaq 0x58(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x14fa4
xorl %r13d, %r13d
testl %eax, %eax
setne %r13b
leaq 0x58(%rsp), %rdi
callq 0x5778
leaq 0x30(%rsp), %rdi
callq 0x911e
leaq 0x10(%rsp), %rdi
callq 0x911e
movl %r13d, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x13877(%rip), %r14     # 0x35fb8
leaq 0x3c15(%rip), %r15      # 0x2635d
cmpq %rax, %rbx
je 0x226ae
movq %r14, %rdi
movq %rbx, %rsi
callq 0x53a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x53f0
addq $0x20, %rbx
movq 0x18(%rsp), %rax
jmp 0x22748
jmp 0x22776
jmp 0x227a4
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
jmp 0x2278d
jmp 0x227a4
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x5778
jmp 0x227a7
jmp 0x227a4
movq %rax, %rbx
jmp 0x227be
jmp 0x2279f
jmp 0x2279f
movq %rax, %rbx
jmp 0x227b4
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x5778
leaq 0x58(%rsp), %rdi
callq 0x5778
leaq 0x30(%rsp), %rdi
callq 0x911e
leaq 0x10(%rsp), %rdi
callq 0x911e
movq %rbx, %rdi
callq 0x56c0