// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movq %rcx, %r14
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %r13
testl %r8d, %r8d
je 0x39f9
movq 0x5645(%rip), %rbx      # 0x8ff0
leaq 0x2d40(%rip), %rsi      # 0x66f2
movl $0x8, %edx
movq %rbx, %rdi
callq 0x2250
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq %rbx, %rdi
callq 0x2250
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
movq %r12, %rdi
callq 0x46b6
leaq 0x2ad5(%rip), %rsi      # 0x64dd
movq %r13, %rdi
callq 0x2090
testl %eax, %eax
movq %r14, 0x48(%rsp)
movq %r13, 0x30(%rsp)
je 0x3a76
movq (%r13), %rdi
leaq 0x2ac5(%rip), %rsi      # 0x64ee
callq 0x2260
movq %rax, %rbx
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %r14
movq %r14, %rdi
callq 0x470a
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2734
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x3a80
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0x3a80
movq 0x5553(%rip), %rax      # 0x8fd0
movq (%rax), %rbx
movq %r12, 0x28(%rsp)
movq %rbx, %rdi
callq 0x2240
leaq 0x2a5a(%rip), %rsi      # 0x64ee
movl %eax, %edi
callq 0x23a0
movq %rax, %rbx
movl $0x1, %edi
movl $0x70, %esi
callq 0x2150
movq %rax, %r13
movl $0x1, %edi
movl $0x20, %esi
callq 0x2150
movq %rax, %r14
movq %rbx, 0x40(%rsp)
movq %rbx, 0x18(%rax)
movl $0x4000, %edi           # imm = 0x4000
callq 0x22d0
movq %rax, (%r14)
movq %r14, 0x68(%r13)
leaq 0x48(%r13), %rbx
leaq 0x30(%r13), %rax
movq %rax, 0x20(%rsp)
leaq 0x18(%r13), %rax
movq %rax, 0x38(%rsp)
movl %ebp, 0x14(%rsp)
movslq %ebp, %rax
negq %rax
movq %rax, 0x18(%rsp)
xorl %eax, %eax
testl %eax, %eax
jne 0x3b70
leaq 0x10(%r14), %rbp
movl 0x8(%r14), %ecx
movl 0xc(%r14), %eax
cmpl $0x0, (%rbp)
je 0x3b21
cmpl %eax, %ecx
jge 0x3e52
movq (%r14), %rsi
cmpl %eax, %ecx
jl 0x3b51
movl $0x0, 0x8(%r14)
movq 0x18(%r14), %rdi
movl $0x4000, %edx           # imm = 0x4000
callq 0x23b0
movl %eax, 0xc(%r14)
testl %eax, %eax
je 0x3e4b
movl 0x8(%r14), %ecx
movq (%r14), %rsi
movslq %ecx, %rdx
incl %ecx
movl %ecx, 0x8(%r14)
movzbl (%rsi,%rdx), %edx
movl %edx, 0x8(%rsp)
cmpl $0x40, %edx
je 0x3b6c
cmpl $0x3e, %edx
jne 0x3b13
movl %edx, 0x60(%r13)
xorl %eax, %eax
movq %rax, 0x48(%r13)
movq %rax, 0x30(%r13)
movq %rax, 0x18(%r13)
movq %r14, %rdi
xorl %esi, %esi
movq %r13, %rdx
leaq 0x8(%rsp), %rcx
xorl %r8d, %r8d
callq 0x362c
testl %eax, %eax
js 0x3e52
cmpl $0xa, 0x8(%rsp)
je 0x3bb9
movq %r14, %rdi
movl $0x2, %esi
movq 0x38(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x362c
cmpq $0x0, 0x40(%r13)
jne 0x3bd6
movq $0x100, 0x38(%r13)      # imm = 0x100
movl $0x100, %edi            # imm = 0x100
callq 0x22d0
movq %rax, 0x40(%r13)
cmpl $0x0, 0x10(%r14)
leaq 0x10(%r14), %rbp
sete %sil
movl 0x8(%r14), %ecx
movl 0xc(%r14), %eax
cmpl %eax, %ecx
setl %dl
orb %dl, %sil
testb $0x1, %sil
movq 0x20(%rsp), %r15
je 0x3cba
movq (%r14), %rsi
testb $0x1, %dl
jne 0x3c33
movl $0x0, 0x8(%r14)
movq 0x18(%r14), %rdi
movl $0x4000, %edx           # imm = 0x4000
callq 0x23b0
movl %eax, 0xc(%r14)
testl %eax, %eax
je 0x3cb3
movl 0x8(%r14), %ecx
movq (%r14), %rsi
movslq %ecx, %rdx
incl %ecx
movl %ecx, 0x8(%r14)
movb (%rsi,%rdx), %dl
movzbl %dl, %esi
movl %esi, 0x8(%rsp)
cmpl $0x2a, %esi
jg 0x3c52
cmpl $0xa, %esi
je 0x3c94
jmp 0x3c61
cmpl $0x2b, %esi
je 0x3cc2
cmpl $0x3e, %esi
je 0x3cad
cmpl $0x40, %esi
je 0x3cad
movq 0x30(%r13), %rax
movq 0x40(%r13), %rcx
leaq 0x1(%rax), %rsi
movq %rsi, 0x30(%r13)
movb %dl, (%rcx,%rax)
movq %r14, %rdi
movl $0x2, %esi
movq %r15, %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x362c
movl 0x8(%r14), %ecx
movl 0xc(%r14), %eax
cmpl %eax, %ecx
setl %dl
cmpl $0x0, (%rbp)
je 0x3c02
cmpl %eax, %ecx
jl 0x3c02
jmp 0x3cba
movl %esi, 0x60(%r13)
jmp 0x3cc2
movl $0x1, (%rbp)
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movq 0x30(%r13), %r12
movq 0x38(%r13), %r15
leaq 0x1(%r12), %rcx
movq 0x40(%r13), %rax
cmpq %r15, %rcx
jb 0x3d1f
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, %r15
shrq $0x10, %r15
orq %rcx, %r15
incq %r15
movq %r15, 0x38(%r13)
movq %rax, %rdi
movq %r15, %rsi
callq 0x2350
movq %rax, 0x40(%r13)
movb $0x0, (%rax,%r12)
cmpl $0x2b, 0x8(%rsp)
jne 0x3dde
cmpq %r15, 0x50(%r13)
jae 0x3d49
movq %r15, 0x50(%r13)
movq 0x58(%r13), %rdi
movq %r15, %rsi
callq 0x2350
movq %rax, 0x58(%r13)
movl 0x8(%r14), %ecx
movl 0xc(%r14), %eax
cmpl $0x0, (%rbp)
je 0x3d5f
cmpl %eax, %ecx
jge 0x3e52
movq (%r14), %rsi
cmpl %eax, %ecx
jl 0x3d8f
movl $0x0, 0x8(%r14)
movq 0x18(%r14), %rdi
movl $0x4000, %edx           # imm = 0x4000
callq 0x23b0
movl %eax, 0xc(%r14)
testl %eax, %eax
je 0x3e4b
movl 0x8(%r14), %ecx
movq (%r14), %rsi
movslq %ecx, %rdx
incl %ecx
movl %ecx, 0x8(%r14)
movzbl (%rsi,%rdx), %edx
movl %edx, 0x8(%rsp)
cmpl $0xa, %edx
jne 0x3d51
movq 0x20(%rsp), %r15
movq %r14, %rdi
movl $0x2, %esi
movq %rbx, %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x362c
movq (%r15), %r12
movq (%rbx), %rcx
testl %eax, %eax
js 0x3dd1
cmpq %r12, %rcx
jb 0x3daa
movl $0x0, 0x60(%r13)
cmpq %rcx, %r12
jne 0x3e52
testl %r12d, %r12d
js 0x3e52
movq 0x40(%r13), %r14
addq %r14, %r12
movq 0x18(%rsp), %rax
addq %r12, %rax
incq %rax
cmpq %rax, %r14
movq 0x28(%rsp), %r15
movl 0x14(%rsp), %ebp
jae 0x3e3e
addq 0x18(%rsp), %r12
movq %r14, %rdi
movl %ebp, %esi
leaq 0x50(%rsp), %rdx
callq 0x4ac7
testl %eax, %eax
jne 0x3e32
movq %r15, 0x8(%rsp)
movq %r15, %rdi
leaq 0x50(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x4ba4
leaq 0x1(%r14), %rax
cmpq %r12, %r14
movq %rax, %r14
jb 0x3e08
movq 0x68(%r13), %r14
movl 0x60(%r13), %eax
jmp 0x3b03
movl $0x1, (%rbp)
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
movq 0x28(%rsp), %rax
je 0x3e7b
movq 0x30(%rsp), %rcx
movq (%rcx), %rdx
movq 0x18(%rax), %rcx
leaq 0x2887(%rip), %rsi      # 0x66fb
xorl %eax, %eax
callq 0x22e0
testq %r13, %r13
je 0x3ec5
movq 0x10(%r13), %rdi
callq 0x2270
movq 0x28(%r13), %rdi
callq 0x2270
movq 0x40(%r13), %rdi
callq 0x2270
movq 0x58(%r13), %rdi
callq 0x2270
movq 0x68(%r13), %rbx
testq %rbx, %rbx
je 0x3ebd
movq (%rbx), %rdi
callq 0x2270
movq %rbx, %rdi
callq 0x2270
movq %r13, %rdi
callq 0x2270
movq 0x40(%rsp), %rdi
callq 0x2360
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x3efa
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2230
movq %rbx, %rdi
callq 0x2380