// File: 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
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x1ab40
leaq -0x40(%rbp), %rdi
callq 0x1ab40
leaq -0x61(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x6910
movq -0x150(%rbp), %rdx
leaq 0x7c26(%rip), %rsi      # 0x5c878
leaq -0x60(%rbp), %rdi
callq 0xab20
jmp 0x54c5d
leaq -0x61(%rbp), %rdi
callq 0x65a0
movl $0x2, -0x78(%rbp)
movl -0x78(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x55308
movq -0x10(%rbp), %rax
movslq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x160(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x6910
movq -0x160(%rbp), %rsi
movq -0x158(%rbp), %rdx
leaq -0x98(%rbp), %rdi
callq 0xab20
jmp 0x54cbb
leaq -0x99(%rbp), %rdi
callq 0x65a0
leaq 0x6319(%rip), %rsi      # 0x5afe7
leaq -0x98(%rbp), %rdi
callq 0x2dce0
movb %al, -0x161(%rbp)
jmp 0x54ce2
movb -0x161(%rbp), %al
testb $0x1, %al
jne 0x54d15
jmp 0x54cee
leaq 0x62f5(%rip), %rsi      # 0x5afea
leaq -0x98(%rbp), %rdi
callq 0x2dce0
movb %al, -0x162(%rbp)
jmp 0x54d09
movb -0x162(%rbp), %al
testb $0x1, %al
jne 0x54d15
jmp 0x54d7a
callq 0x54ae0
jmp 0x54d1c
movl $0x0, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x552cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x61(%rbp), %rdi
callq 0x65a0
jmp 0x55603
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x99(%rbp), %rdi
callq 0x65a0
jmp 0x555fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x552f7
leaq 0x6570(%rip), %rsi      # 0x5b2f1
leaq -0x98(%rbp), %rdi
callq 0x2dce0
movb %al, -0x163(%rbp)
jmp 0x54d95
movb -0x163(%rbp), %al
testb $0x1, %al
jne 0x54da4
jmp 0x54f0b
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x54e87
movq -0x10(%rbp), %rax
movslq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x178(%rbp)
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x6910
movq -0x178(%rbp), %rsi
movq -0x170(%rbp), %rdx
leaq -0xe0(%rbp), %rdi
callq 0xab20
jmp 0x54dfb
leaq 0x6f14(%rip), %rdx      # 0x5bd16
leaq -0xc0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x24a10
jmp 0x54e17
leaq -0x60(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x6640
leaq -0xc0(%rbp), %rdi
callq 0x6a08
leaq -0xe0(%rbp), %rdi
callq 0x6a08
leaq -0xe1(%rbp), %rdi
callq 0x65a0
jmp 0x54f06
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x54e76
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x6a08
leaq -0xe1(%rbp), %rdi
callq 0x65a0
jmp 0x552f7
movq 0x24162(%rip), %rdi     # 0x78ff0
movq 0x240fb(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x180(%rbp)
jmp 0x54ea3
movq -0x180(%rbp), %rdi
leaq 0x668b(%rip), %rsi      # 0x5b53c
callq 0x6520
movq %rax, -0x188(%rbp)
jmp 0x54ebf
movq -0x188(%rbp), %rdi
movq 0x240c3(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x190(%rbp)
jmp 0x54edb
movq -0x190(%rbp), %rdi
movq 0x240a7(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x54ef0
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x552cb
jmp 0x552bf
leaq 0x6155(%rip), %rsi      # 0x5b067
leaq -0x98(%rbp), %rdi
callq 0x2dce0
movb %al, -0x191(%rbp)
jmp 0x54f26
movb -0x191(%rbp), %al
testb $0x1, %al
jne 0x54f35
jmp 0x55076
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x54ff2
movq -0x10(%rbp), %rax
movslq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x1a8(%rbp)
leaq -0x109(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x6910
movq -0x1a8(%rbp), %rsi
movq -0x1a0(%rbp), %rdx
leaq -0x108(%rbp), %rdi
callq 0xab20
jmp 0x54f8c
leaq -0x108(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xa6a0
jmp 0x54f9e
leaq -0x108(%rbp), %rdi
callq 0x6a08
leaq -0x109(%rbp), %rdi
callq 0x65a0
jmp 0x55071
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x54fe1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x6a08
leaq -0x109(%rbp), %rdi
callq 0x65a0
jmp 0x552f7
movq 0x23ff7(%rip), %rdi     # 0x78ff0
movq 0x23f90(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x1b0(%rbp)
jmp 0x5500e
movq -0x1b0(%rbp), %rdi
leaq 0x604e(%rip), %rsi      # 0x5b06a
callq 0x6520
movq %rax, -0x1b8(%rbp)
jmp 0x5502a
movq -0x1b8(%rbp), %rdi
movq 0x23f58(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x1c0(%rbp)
jmp 0x55046
movq -0x1c0(%rbp), %rdi
movq 0x23f3c(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x5505b
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x552cb
jmp 0x552bd
leaq 0x62f2(%rip), %rsi      # 0x5b36f
leaq -0x98(%rbp), %rdi
callq 0x2dce0
movb %al, -0x1c1(%rbp)
jmp 0x55091
movb -0x1c1(%rbp), %al
testb $0x1, %al
jne 0x550a0
jmp 0x551e1
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x5515d
movq -0x10(%rbp), %rax
movslq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x1d8(%rbp)
leaq -0x131(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x6910
movq -0x1d8(%rbp), %rsi
movq -0x1d0(%rbp), %rdx
leaq -0x130(%rbp), %rdi
callq 0xab20
jmp 0x550f7
leaq -0x130(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xa6a0
jmp 0x55109
leaq -0x130(%rbp), %rdi
callq 0x6a08
leaq -0x131(%rbp), %rdi
callq 0x65a0
jmp 0x551dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x5514c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x6a08
leaq -0x131(%rbp), %rdi
callq 0x65a0
jmp 0x552f7
movq 0x23e8c(%rip), %rdi     # 0x78ff0
movq 0x23e25(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x1e0(%rbp)
jmp 0x55179
movq -0x1e0(%rbp), %rdi
leaq 0x61eb(%rip), %rsi      # 0x5b372
callq 0x6520
movq %rax, -0x1e8(%rbp)
jmp 0x55195
movq -0x1e8(%rbp), %rdi
movq 0x23ded(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x1f0(%rbp)
jmp 0x551b1
movq -0x1f0(%rbp), %rdi
movq 0x23dd1(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x551c6
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x552cb
jmp 0x552bb
xorl %eax, %eax
movl %eax, %esi
leaq -0x98(%rbp), %rdi
callq 0x69e0
movq %rax, -0x1f8(%rbp)
jmp 0x551fa
movq -0x1f8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x552a5
movq 0x23ddc(%rip), %rdi     # 0x78ff0
movq 0x23d75(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x200(%rbp)
jmp 0x55229
movq -0x200(%rbp), %rdi
leaq 0x5e55(%rip), %rsi      # 0x5b08c
callq 0x6520
movq %rax, -0x208(%rbp)
jmp 0x55245
movq -0x208(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x64d0
movq %rax, -0x210(%rbp)
jmp 0x55261
movq -0x210(%rbp), %rdi
movq 0x23d21(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x218(%rbp)
jmp 0x5527d
movq -0x218(%rbp), %rdi
movq 0x23d05(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x55292
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x552cb
leaq -0x28(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xabd0
jmp 0x552b7
jmp 0x552b9
jmp 0x552bb
jmp 0x552bd
jmp 0x552bf
jmp 0x552c1
movl $0x0, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x6a08
movl -0xa0(%rbp), %eax
testl %eax, %eax
jne 0x555d3
jmp 0x552e7
jmp 0x552e9
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x54c6d
leaq -0x98(%rbp), %rdi
callq 0x6a08
jmp 0x555fa
leaq -0x28(%rbp), %rdi
callq 0xb670
cmpq $0x1, %rax
jae 0x55392
movq 0x23cd2(%rip), %rdi     # 0x78ff0
movq 0x23c6b(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x220(%rbp)
jmp 0x55333
movq -0x220(%rbp), %rdi
leaq 0x5d5e(%rip), %rsi      # 0x5b09f
callq 0x6520
movq %rax, -0x228(%rbp)
jmp 0x5534f
movq -0x228(%rbp), %rdi
movq 0x23c33(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x55364
callq 0x54ae0
jmp 0x5536b
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x555d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x555fa
leaq 0x4f19(%rip), %rsi      # 0x5a2b2
leaq -0x60(%rbp), %rdi
callq 0x2dce0
movb %al, -0x229(%rbp)
jmp 0x553aa
movb -0x229(%rbp), %al
testb $0x1, %al
jne 0x553b6
jmp 0x55420
movq 0x23c33(%rip), %rdi     # 0x78ff0
movq 0x23bcc(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x238(%rbp)
jmp 0x553d2
movq -0x238(%rbp), %rdi
leaq 0x74a3(%rip), %rsi      # 0x5c883
callq 0x6520
movq %rax, -0x240(%rbp)
jmp 0x553ee
movq -0x240(%rbp), %rdi
movq 0x23b94(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x55403
callq 0x54ae0
jmp 0x5540a
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x555d3
callq 0x4c460
jmp 0x55427
movq 0x23b7a(%rip), %rdi     # 0x78fa8
leaq 0x746b(%rip), %rsi      # 0x5c8a0
callq 0x6520
jmp 0x5543c
leaq -0x28(%rbp), %rdi
callq 0xb670
movslq 0x241f4(%rip), %rcx     # 0x79640
cmpq %rcx, %rax
jbe 0x5548c
leaq -0x28(%rbp), %rdi
callq 0xb670
movq %rax, %rsi
movq 0x23b44(%rip), %rdi     # 0x78fa8
callq 0x6120
movq %rax, -0x248(%rbp)
jmp 0x55472
movq -0x248(%rbp), %rdi
leaq 0x5639(%rip), %rsi      # 0x5aab9
callq 0x6520
jmp 0x55487
jmp 0x55510
leaq -0x28(%rbp), %rdi
callq 0xb4c0
movq %rax, -0x140(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xb340
movq %rax, -0x148(%rbp)
leaq -0x140(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x4a690
testb $0x1, %al
jne 0x554c5
jmp 0x5550e
leaq -0x140(%rbp), %rdi
callq 0x30840
movq %rax, %rsi
movq 0x23acd(%rip), %rdi     # 0x78fa8
callq 0x64d0
movq %rax, -0x250(%rbp)
jmp 0x554e9
movq -0x250(%rbp), %rdi
leaq 0x4e56(%rip), %rsi      # 0x5a34d
callq 0x6520
jmp 0x554fe
jmp 0x55500
leaq -0x140(%rbp), %rdi
callq 0x4a6d0
jmp 0x5549c
jmp 0x55510
movq 0x23a91(%rip), %rdi     # 0x78fa8
movq 0x23a72(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x55525
movq 0x23a7c(%rip), %rdi     # 0x78fa8
leaq 0x5ed9(%rip), %rsi      # 0x5b40c
callq 0x6520
movq %rax, -0x258(%rbp)
jmp 0x55541
movq -0x258(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x64d0
movq %rax, -0x260(%rbp)
jmp 0x5555a
movq -0x260(%rbp), %rdi
movq 0x23a28(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x268(%rbp)
jmp 0x55576
movq -0x268(%rbp), %rdi
movq 0x23a0c(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x5558b
leaq -0x60(%rbp), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0x33ef0
movl %eax, -0x26c(%rbp)
jmp 0x555a4
movl -0x26c(%rbp), %eax
cmpl $0x0, %eax
je 0x555c2
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x555d3
movl $0x0, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x6a08
leaq -0x40(%rbp), %rdi
callq 0xfe90
leaq -0x28(%rbp), %rdi
callq 0xfe90
movl -0x4(%rbp), %eax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
leaq -0x60(%rbp), %rdi
callq 0x6a08
leaq -0x40(%rbp), %rdi
callq 0xfe90
leaq -0x28(%rbp), %rdi
callq 0xfe90
movq -0x70(%rbp), %rdi
callq 0x6900
nop