// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq %rdi, %r13
testl %r8d, %r8d
je 0x3a06
movq 0x5638(%rip), %rbx      # 0x8ff0
leaq 0x2d33(%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 %r14, %rdi
callq 0x471c
leaq 0x2ac8(%rip), %rsi      # 0x64dd
movq %r13, %rdi
callq 0x2090
testl %eax, %eax
movq %r15, 0x28(%rsp)
movq %r13, 0x18(%rsp)
je 0x3a84
movq (%r13), %rdi
leaq 0x2ab8(%rip), %rsi      # 0x64ee
callq 0x2260
movq %rax, %rbx
leaq 0x50(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x40(%rsp), %r15
movq %r15, %rdi
callq 0x4770
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2734
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x3a8e
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0x3a8e
movq 0x5545(%rip), %rax      # 0x8fd0
movq (%rax), %rbx
movq %rbx, %rdi
callq 0x2240
leaq 0x2a51(%rip), %rsi      # 0x64ee
movl %eax, %edi
callq 0x23a0
movq %rax, %r15
movl $0x1, %edi
movl $0x70, %esi
callq 0x2150
movq %rax, %r13
movl $0x1, %edi
movl $0x20, %esi
callq 0x2150
movq %rax, %rbx
movq %r15, 0x20(%rsp)
movq %r15, 0x18(%rax)
movl $0x4000, %edi           # imm = 0x4000
callq 0x22d0
movq %rax, (%rbx)
movq %rbx, 0x68(%r13)
leaq 0x48(%r13), %rax
movq %rax, 0x38(%rsp)
leaq 0x30(%r13), %rax
movq %rax, 0x10(%rsp)
leaq 0x18(%r13), %rax
movq %rax, 0x30(%rsp)
movslq %ebp, %rax
negq %rax
movq %rax, 0x8(%rsp)
leaq 0x60(%rsp), %r15
movq 0x68(%r13), %rbx
cmpl $0x0, 0x60(%r13)
jne 0x3b97
jmp 0x3b2c
movl $0x1, 0x10(%rbx)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x3b79
cmpl $0x0, 0x10(%rbx)
je 0x3b40
movl 0x8(%rbx), %eax
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpl 0xc(%rbx), %eax
jge 0x3b79
movl 0x8(%rbx), %eax
cmpl 0xc(%rbx), %eax
jl 0x3b67
movl $0x0, 0x8(%rbx)
movq (%rbx), %rsi
movq 0x18(%rbx), %rdi
movl $0x4000, %edx           # imm = 0x4000
callq 0x23b0
movl %eax, 0xc(%rbx)
testl %eax, %eax
je 0x3b1d
movq (%rbx), %rax
movslq 0x8(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x8(%rbx)
movzbl (%rax,%rcx), %r12d
movl %r12d, (%rsp)
cmpl $-0x1, %r12d
je 0x3df4
cmpl $0x40, %r12d
je 0x3b93
cmpl $0x3e, %r12d
jne 0x3b2c
movl %r12d, 0x60(%r13)
xorl %eax, %eax
movq %rax, 0x48(%r13)
movq %rax, 0x30(%r13)
movq %rax, 0x18(%r13)
movq %rbx, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %rsp, %rcx
xorl %r8d, %r8d
callq 0x3648
testl %eax, %eax
js 0x3cab
cmpl $0xa, (%rsp)
je 0x3bdd
movq %rbx, %rdi
movl $0x2, %esi
movq 0x30(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3648
cmpq $0x0, 0x40(%r13)
movq 0x10(%rsp), %r12
jne 0x3bff
movq $0x100, 0x38(%r13)      # imm = 0x100
movl $0x100, %edi            # imm = 0x100
callq 0x22d0
movq %rax, 0x40(%r13)
cmpl $0x0, 0x10(%rbx)
je 0x3c12
movl 0x8(%rbx), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl 0xc(%rbx), %ecx
jge 0x3c4a
movl 0x8(%rbx), %eax
cmpl 0xc(%rbx), %eax
jl 0x3c39
movl $0x0, 0x8(%rbx)
movq (%rbx), %rsi
movq 0x18(%rbx), %rdi
movl $0x4000, %edx           # imm = 0x4000
callq 0x23b0
movl %eax, 0xc(%rbx)
testl %eax, %eax
je 0x3c9d
movq (%rbx), %rax
movslq 0x8(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x8(%rbx)
movzbl (%rax,%rcx), %eax
movl %eax, (%rsp)
cmpl $0x2a, %eax
jg 0x3c5e
cmpl $0xa, %eax
je 0x3bff
cmpl $-0x1, %eax
jne 0x3c6d
jmp 0x3cba
cmpl $0x2b, %eax
je 0x3cba
cmpl $0x3e, %eax
je 0x3cb6
cmpl $0x40, %eax
je 0x3cb6
movq 0x30(%r13), %rcx
movq 0x40(%r13), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x30(%r13)
movb %al, (%rdx,%rcx)
movq %rbx, %rdi
movl $0x2, %esi
movq %r12, %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x3648
jmp 0x3bff
movl $0x1, 0x10(%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x3c4a
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x3df4
movl %eax, 0x60(%r13)
movq 0x30(%r13), %r12
leaq 0x1(%r12), %rax
cmpq 0x38(%r13), %rax
jb 0x3d0e
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x38(%r13)
movq 0x40(%r13), %rdi
callq 0x2350
movq %rax, 0x40(%r13)
movq 0x40(%r13), %rax
movb $0x0, (%rax,%r12)
cmpl $0x2b, (%rsp)
jne 0x3df4
movq 0x38(%r13), %rsi
cmpq %rsi, 0x50(%r13)
jae 0x3d3c
movq %rsi, 0x50(%r13)
movq 0x58(%r13), %rdi
callq 0x2350
movq %rax, 0x58(%r13)
movq 0x38(%rsp), %r12
cmpl $0x0, 0x10(%rbx)
je 0x3d54
movl 0x8(%rbx), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl 0xc(%rbx), %ecx
jge 0x3d8c
movl 0x8(%rbx), %eax
cmpl 0xc(%rbx), %eax
jl 0x3d7b
movl $0x0, 0x8(%rbx)
movq (%rbx), %rsi
movq 0x18(%rbx), %rdi
movl $0x4000, %edx           # imm = 0x4000
callq 0x23b0
movl %eax, 0xc(%rbx)
testl %eax, %eax
je 0x3d9b
movq (%rbx), %rax
movslq 0x8(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x8(%rbx)
movzbl (%rax,%rcx), %eax
movl %eax, (%rsp)
cmpl $-0x1, %eax
je 0x3dee
cmpl $0xa, %eax
jne 0x3d41
jmp 0x3da9
movl $0x1, 0x10(%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x3d8c
movq %rbx, %rdi
movl $0x2, %esi
movq %r12, %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x3648
testl %eax, %eax
js 0x3dd3
movq (%r12), %rax
movq 0x10(%rsp), %rcx
cmpq (%rcx), %rax
jb 0x3da9
movl $0x0, 0x60(%r13)
movq 0x30(%r13), %r12
cmpq 0x48(%r13), %r12
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
cmovnel %eax, %r12d
jmp 0x3df4
movl $0xfffffffe, %r12d      # imm = 0xFFFFFFFE
testl %r12d, %r12d
js 0x3e51
movq 0x40(%r13), %rbx
movq 0x30(%r13), %r12
addq %rbx, %r12
movq 0x8(%rsp), %rax
addq %r12, %rax
incq %rax
cmpq %rax, %rbx
jae 0x3b10
addq 0x8(%rsp), %r12
movq %rbx, %rdi
movl %ebp, %esi
movq %r15, %rdx
callq 0x4b19
testl %eax, %eax
jne 0x3e40
movq %r14, (%rsp)
movq %r14, %rdi
movq %r15, %rsi
movq %rsp, %rdx
callq 0x4c14
leaq 0x1(%rbx), %rax
cmpq %r12, %rbx
movq %rax, %rbx
jb 0x3e1d
jmp 0x3b10
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x3e75
movq 0x18(%rsp), %rax
movq (%rax), %rdx
movq 0x18(%r14), %rcx
leaq 0x288d(%rip), %rsi      # 0x66fb
xorl %eax, %eax
callq 0x22e0
testq %r13, %r13
je 0x3ebf
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 0x3eb7
movq (%rbx), %rdi
callq 0x2270
movq %rbx, %rdi
callq 0x2270
movq %r13, %rdi
callq 0x2270
movq 0x20(%rsp), %rdi
callq 0x2360
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x3ef4
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2230
movq %rbx, %rdi
callq 0x2380