// File: prophyle[P]prophasm/src/prophasm.cpp
// Function: int kmers_from_fasta<std::unordered_set<unsigned long, std::hash<unsigned long>, std::equal_to<unsigned long>, std::allocator<unsigned long>>>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::unordered_set<unsigned long, std::hash<unsigned long>, std::equal_to<unsigned long>, std::allocator<unsigned long>>&, int, _IO_FILE*, bool)
int kmers_from_fasta(const std::string &fasta_fn, _set_T &set, int32_t k, FILE* fstats,bool verbose){

	if (verbose){
		std::cerr << "Loading " << fasta_fn << std::endl;
	}

	set.clear();

	kseq_t *seq;
	int64_t l;

	FILE *instream = nullptr;
	if(fasta_fn=="-"){
		instream = stdin;
	}
	else {
		instream = fopen(fasta_fn.c_str(), "r");
		test_file(instream, fasta_fn);
	}
	gzFile fp = gzdopen(fileno(instream), "r");
	seq = kseq_init(fp);

	typename _set_T::value_type nkmer;

	for(int32_t seqid=0;(l = kseq_read(seq)) >= 0;seqid++) {
		//std::cerr << "kmers from fasta" << std::endl;

		//std::cerr << "starting iterator" << std::endl;
		for(char *kmer=seq->seq.s; kmer < (seq->seq.s) + (seq->seq.l) -k +1 ;kmer++){
			int c = encode_canonical(kmer, k, nkmer);
			if (c==0){
				set.insert(nkmer);
			}
			else{
				//std::cerr << "problem" <<std::endl;
			}
		}
	}

	if(fstats){
		fprintf(fstats,"%s\t%lu\n",fasta_fn.c_str(),set.size());
	}
	//std::cerr << "iterator finished" << std::endl;

	kseq_destroy(seq);
	gzclose(fp);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
testb $0x1, -0x21(%rbp)
je 0x55f6
movq 0xca21(%rip), %rdi      # 0x11ff0
leaq 0x71e2(%rip), %rsi      # 0xc7b8
callq 0x3270
movq %rax, %rdi
movq -0x8(%rbp), %rsi
callq 0x3250
movq %rax, %rdi
movq 0xc9c7(%rip), %rsi      # 0x11fb8
callq 0x32b0
movq -0x10(%rbp), %rdi
callq 0x8500
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x6f91(%rip), %rsi      # 0xc5a3
callq 0x5480
testb $0x1, %al
jne 0x561d
jmp 0x562d
movq 0xc9ac(%rip), %rax      # 0x11fd0
movq (%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x56a2
movq -0x8(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
leaq 0x6f74(%rip), %rsi      # 0xc5b4
callq 0x3310
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x60(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x30f0
movq -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x3780
jmp 0x567d
leaq -0x60(%rbp), %rdi
callq 0x3170
jmp 0x56a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x3170
jmp 0x57fe
movq -0x40(%rbp), %rdi
callq 0x32d0
movl %eax, %edi
leaq 0x6f00(%rip), %rsi      # 0xc5b4
callq 0x3480
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
callq 0x48e0
movq %rax, -0x30(%rbp)
movl $0x0, -0x84(%rbp)
movq -0x30(%rbp), %rdi
callq 0x4920
cltq
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jl 0x5797
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x40(%rcx), %rcx
movq -0x30(%rbp), %rdx
addq 0x30(%rdx), %rcx
movslq -0x14(%rbp), %rsi
xorl %edx, %edx
subq %rsi, %rdx
addq %rdx, %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x5781
movq -0x90(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq -0x80(%rbp), %rdx
callq 0x8520
movl %eax, -0x94(%rbp)
cmpl $0x0, -0x94(%rbp)
jne 0x5766
movq -0x10(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x85a0
movq %rax, -0xa8(%rbp)
movb %dl, -0xa0(%rbp)
jmp 0x5768
jmp 0x5768
jmp 0x576a
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x56fc
jmp 0x5783
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x56d4
cmpq $0x0, -0x20(%rbp)
je 0x57e1
movq -0x20(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x30e0
movq %rax, -0xc0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5900
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rdx
movq %rax, %rcx
leaq 0x6fe7(%rip), %rsi      # 0xc7c1
movb $0x0, %al
callq 0x33c0
movq -0x30(%rbp), %rdi
callq 0x4d00
movq -0x78(%rbp), %rdi
callq 0x3430
xorl %eax, %eax
addq $0xd0, %rsp
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x3450
nopw (%rax,%rax)