// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %r15
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %r13
testl %r8d, %r8d
je 0x33f1
movq 0x4c1e(%rip), %rdi      # 0x7ff0
leaq 0x2319(%rip), %rsi      # 0x56f2
callq 0x21c0
movq %rax, %rdi
movq %r13, %rsi
callq 0x21b0
movq %rax, %rdi
callq 0x20e0
movq %r12, %rdi
callq 0x3d24
leaq 0x20dd(%rip), %rsi      # 0x54dd
movq %r13, %rdi
callq 0x334f
testb %al, %al
movq %r15, 0x28(%rsp)
movq %r13, 0x18(%rsp)
je 0x3422
movq 0x4bb3(%rip), %rax      # 0x7fd0
movq (%rax), %rbx
jmp 0x345a
movq (%r13), %rdi
leaq 0x20c1(%rip), %rsi      # 0x54ee
callq 0x2210
movq %rax, %rbx
leaq 0x48(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x22a0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2626
leaq 0x48(%rsp), %rdi
callq 0x20d0
movq %r12, 0x8(%rsp)
movq %rbx, %rdi
callq 0x2200
leaq 0x2080(%rip), %rsi      # 0x54ee
movl %eax, %edi
callq 0x2380
movq %rax, %r14
pushq $0x1
popq %rbx
pushq $0x70
popq %rsi
movq %rbx, %rdi
callq 0x2130
movq %rax, %r13
pushq $0x20
popq %rsi
movq %rbx, %rdi
callq 0x2130
movq %rax, %r15
movq %r14, 0x20(%rsp)
movq %r14, 0x18(%rax)
movl $0x4000, %edi           # imm = 0x4000
callq 0x2290
movq %rax, (%r15)
movq %r15, 0x68(%r13)
leaq 0x48(%r13), %rbx
leaq 0x30(%r13), %rax
movq %rax, 0x10(%rsp)
leaq 0x18(%r13), %rax
movq %rax, 0x30(%rsp)
movslq %ebp, %rax
negq %rax
movq %rax, 0x38(%rsp)
xorl %eax, %eax
testl %eax, %eax
jne 0x34fb
movq %r15, %rdi
callq 0x305e
cmpl $-0x1, %eax
je 0x36d4
cmpl $0x40, %eax
je 0x34f3
cmpl $0x3e, %eax
jne 0x34d8
movl %eax, 0x4(%rsp)
movl %eax, 0x60(%r13)
andq $0x0, 0x48(%r13)
andq $0x0, 0x30(%r13)
andq $0x0, 0x18(%r13)
movq %r15, %rdi
xorl %esi, %esi
movq %r13, %rdx
leaq 0x4(%rsp), %rcx
callq 0x30c7
testl %eax, %eax
js 0x36d4
cmpl $0xa, 0x4(%rsp)
je 0x353d
movq %r15, %rdi
pushq $0x2
popq %rsi
movq 0x30(%rsp), %rdx
xorl %ecx, %ecx
callq 0x30c7
cmpq $0x0, 0x40(%r13)
movq 0x10(%rsp), %r14
jne 0x355f
movq $0x100, 0x38(%r13)      # imm = 0x100
movl $0x100, %edi            # imm = 0x100
callq 0x2290
movq %rax, 0x40(%r13)
movq %r15, %rdi
callq 0x305e
movl %eax, 0x4(%rsp)
cmpl $0xa, %eax
je 0x355f
cmpl $-0x1, %eax
je 0x35b1
cmpl $0x2b, %eax
je 0x35b1
cmpl $0x3e, %eax
je 0x35ad
cmpl $0x40, %eax
je 0x35ad
movq 0x30(%r13), %rcx
movq 0x40(%r13), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x30(%r13)
movb %al, (%rdx,%rcx)
movq %r15, %rdi
pushq $0x2
popq %rsi
movq %r14, %rdx
xorl %ecx, %ecx
pushq $0x1
popq %r8
callq 0x30cc
jmp 0x355f
movl %eax, 0x60(%r13)
movq 0x30(%r13), %r12
movq 0x38(%r13), %r14
leaq 0x1(%r12), %rcx
movq 0x40(%r13), %rax
cmpq %r14, %rcx
jb 0x360e
movq %rcx, %rdx
shrq %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x2, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x4, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x8, %rcx
orq %rdx, %rcx
movq %rcx, %r14
shrq $0x10, %r14
orq %rcx, %r14
incq %r14
movq %r14, 0x38(%r13)
movq %rax, %rdi
movq %r14, %rsi
callq 0x2330
movq %rax, 0x40(%r13)
movb $0x0, (%rax,%r12)
cmpl $0x2b, 0x4(%rsp)
jne 0x3680
cmpq %r14, 0x50(%r13)
jae 0x3634
movq %r14, 0x50(%r13)
movq 0x58(%r13), %rdi
movq %r14, %rsi
callq 0x2330
movq %rax, 0x58(%r13)
movq %r15, %rdi
callq 0x305e
movl %eax, 0x4(%rsp)
cmpl $-0x1, %eax
je 0x36d4
cmpl $0xa, %eax
jne 0x3634
movq 0x10(%rsp), %r14
movq %r15, %rdi
pushq $0x2
popq %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
pushq $0x1
popq %r8
callq 0x30cc
movq (%r14), %r12
movq (%rbx), %rcx
testl %eax, %eax
js 0x3676
cmpq %r12, %rcx
jb 0x3653
andl $0x0, 0x60(%r13)
cmpq %rcx, %r12
jne 0x36d4
testl %r12d, %r12d
js 0x36d4
movq 0x40(%r13), %r14
addq %r14, %r12
movq 0x38(%rsp), %rax
leaq (%rax,%r12), %r15
incq %r15
movq 0x8(%rsp), %r12
cmpq %r15, %r14
jae 0x36c7
movq %r14, %rdi
movl %ebp, %esi
leaq 0x40(%rsp), %rdx
callq 0x41fd
testl %eax, %eax
jne 0x36c2
movq %r12, %rdi
leaq 0x40(%rsp), %rsi
callq 0x42fe
incq %r14
jmp 0x369d
movq 0x68(%r13), %r15
movl 0x60(%r13), %eax
jmp 0x34d4
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x36fd
movq 0x18(%rsp), %rax
movq (%rax), %rdx
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rcx
leaq 0x2005(%rip), %rsi      # 0x56fb
xorl %eax, %eax
callq 0x22c0
testq %r13, %r13
je 0x3747
movq 0x10(%r13), %rdi
callq 0x2220
movq 0x28(%r13), %rdi
callq 0x2220
movq 0x40(%r13), %rdi
callq 0x2220
movq 0x58(%r13), %rdi
callq 0x2220
movq 0x68(%r13), %rbx
testq %rbx, %rbx
je 0x373f
movq (%rbx), %rdi
callq 0x2220
movq %rbx, %rdi
callq 0x2220
movq %r13, %rdi
callq 0x2220
movq 0x20(%rsp), %rdi
callq 0x2340
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x20d0
movq %rbx, %rdi
callq 0x2360