// File: /workspace/github_cpp_makefile_star2_O3/splatlab[P]debgr/main.cc
// Function: reads_to_kmers(kmercounting::chunk&, flush_object*)
void reads_to_kmers(chunk &c, flush_object *obj)
{
	auto fs = c.get_reads();
	auto fe = c.get_reads();
	auto end = fs + c.get_size();
	while (fs && fs!=end) {
		fs = static_cast<char*>(memchr(fs, '\n', end-fs)); // ignore the first line
		fs++; // increment the pointer

		fe = static_cast<char*>(memchr(fs, '\n', end-fs)); // read the read
		string read(fs, fe-fs);
		/*cout << read << endl;*/

start_read:
		if (read.length() < K) // start with the next read if length is smaller than K
			goto next_read;
		{
			uint64_t first = 0;
			uint64_t first_rev = 0;
			uint64_t first_can = 0;
			uint64_t item = 0;
			//cout << "K " << read.substr(0,K) << endl;
			for(int i=0; i<K; i++) { //First kmer
				uint8_t curr = kmer::map_base(read[i]);
				if (curr > DNA_MAP::G) { // 'N' is encountered
					read = read.substr(i+1, read.length());
					goto start_read;
				}
				first = first | curr;
				first = first << 2;
			}
			first = first >> 2;
			first_rev = kmer::reverse_complement(first);

			//cout << "kmer: "; cout << int_to_str(first);
			//cout << " reverse-comp: "; cout << int_to_str(first_rev) << endl;

			if (kmer::compare_kmers(first, first_rev))
				first_can = first;
			else
				first_can = first_rev;

			// create a set of true k-mers
			uint64_t exact_hash = HashUtil::hash_64(first_can, BITMASK(2*K));
			qf_insert(obj->exact_qf, exact_hash, 0, 1, true, true);
			//true_kmers.insert(first_can);

			// this is the first kmer of the read, hash using invertible hash and insert
			// in the first QF
			// No need to use the range, because by default the QF will use the
			// lower order 56 (q+r) bits.
			uint64_t node = kmer::prefix(first, K-1);
			node = canonicalize_node(node);
			record_end(node, first_can, obj);

			// hash the kmer using murmurhash/xxHash before adding to the list
			item = HashUtil::MurmurHash64A(((void*)&first_can), sizeof(first_can),
																		 obj->local_qf->metadata->seed);
			/*
			 * first try and insert in the main QF.
			 * If lock can't be accuired in the first attempt then
			 * insert the item in the local QF.
			 */
			if (!qf_insert(obj->main_qf, item%obj->main_qf->metadata->range, 0, 1,
										 true, false)) {
				qf_insert(obj->local_qf, item%obj->local_qf->metadata->range, 0, 1,
									false, false);
				obj->count++;
				// check of the load factor of the local QF is more than 50%
				if (obj->count > 1ULL<<(QBITS_LOCAL_QF-1)) {
					dump_local_qf_to_main(obj);
					obj->count = 0;
				}
			}
			//cout<< "X " << bitset<64>(first)<<endl;

			uint64_t next = first;
			uint64_t next_rev = first_rev;
			uint64_t next_can = first_can;

			for(uint32_t i=K; i<read.length(); i++) { //next kmers
				uint64_t nextn = kmer::suffix(next, K-1);
				nextn = canonicalize_node(nextn);
				if (can_have_duplex_edges(nextn))
					record_end(nextn, next_can, obj);
				//cout << "K: " << read.substr(i-K+1,K) << endl;
				uint8_t curr = kmer::map_base(read[i]);
				if (curr > DNA_MAP::G) { // 'N' is encountered
					read = read.substr(i+1, read.length());
					// don't insert if i = K and node is a duplex node.
					if (i > K || !can_have_duplex_edges(nextn)) {
						nextn = kmer::suffix(next, K-1);
						nextn = canonicalize_node(nextn);
						record_end(nextn, next_can, obj);
					}
					goto start_read;
				}
				next = (next << 2) & BITMASK(2*K);
				next_rev = next_rev >> 2;
				
				next |= curr;
				uint64_t tmp = kmer::reverse_complement_base(curr);
				tmp <<= (K*2-2);
				next_rev = next_rev | tmp;
				if (kmer::compare_kmers(next, next_rev))
					next_can = next;
				else
					next_can = next_rev;

				uint64_t exact_hash = HashUtil::hash_64(next_can, BITMASK(2*K));
				qf_insert(obj->exact_qf, exact_hash, 0, 1, true, true);
				//true_kmers.insert(next_can);

				// hash the kmer using murmurhash/xxHash before adding to the list
				item = HashUtil::MurmurHash64A(((void*)&next_can), sizeof(next_can),
																			 obj->local_qf->metadata->seed);
				//item = XXH63 (((void*)&item), sizeof(item), seed);

				/*
				 * first try and insert in the main QF.
				 * If lock can't be accuired in the first attempt then
				 * insert the item in the local QF.
				 */
				if (!qf_insert(obj->main_qf, item%obj->main_qf->metadata->range, 0, 1, true,
											 false)) {
					qf_insert(obj->local_qf, item%obj->local_qf->metadata->range, 0, 1, false,
										false);
					obj->count++;
					// check of the load factor of the local QF is more than 50%
					if (obj->count > 1ULL<<(QBITS_LOCAL_QF-1)) {
						dump_local_qf_to_main(obj);
						obj->count = 0;
					}
				}

				//cout<<bitset<64>(next)<<endl;
				//assert(next == str_to_int(read.substr(i-K+1,K)));

				if (can_have_duplex_edges(nextn))
					record_end(nextn, next_can, obj);
			}
			node = kmer::suffix(next, K-1);
			node = canonicalize_node(node);
			record_end(node, next_can, obj);
		}

next_read:
		fs = ++fe;		// increment the pointer
		fs = static_cast<char*>(memchr(fs, '\n', end-fs)); // ignore one line
		fs++; // increment the pointer
		fs = static_cast<char*>(memchr(fs, '\n', end-fs)); // ignore one more line
		fs++; // increment the pointer
	}
	free(c.get_reads());
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, 0x8(%rsp)
movq (%rdi), %rbx
movl 0x8(%rdi), %eax
testq %rbx, %rbx
setne %cl
testl %eax, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x574f
movq %rdi, 0x60(%rsp)
movl %eax, %r14d
addq %rbx, %r14
leaq 0x20(%rsp), %r12
movq %r14, 0x58(%rsp)
movq %r14, %rdx
subq %rbx, %rdx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x43c0
leaq 0x1(%rax), %rbx
movq %r14, %rdx
subq %rbx, %rdx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x43c0
movq %rax, %r13
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r12, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x91ca
movq 0x28(%rsp), %rcx
cmpq $0x1c, %rcx
jb 0x56fa
movq %r13, 0x40(%rsp)
movq $0x0, 0x18(%rsp)
movl $0x1, %edx
movq 0x20(%rsp), %rax
xorl %r15d, %r15d
movzbl -0x1(%rax,%rdx), %esi
cmpl $0x46, %esi
jg 0x51f8
movl $0x1, %r13d
cmpl $0x41, %esi
je 0x5214
cmpl $0x43, %esi
jne 0x55cf
xorl %r13d, %r13d
jmp 0x5214
cmpl $0x47, %esi
je 0x520e
cmpl $0x54, %esi
jne 0x55cf
movl $0x2, %r13d
jmp 0x5214
movl $0x3, %r13d
orq %r15, %r13
leaq (,%r13,4), %r15
incq %rdx
cmpq $0x1d, %rdx
jne 0x51d5
movabsq $0x3fffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFFF
andq %rax, %r13
movl $0x1c, %eax
xorl %r12d, %r12d
movq %r13, %rcx
movl %ecx, %edx
andl $0x3, %edx
addq %r12, %rdx
shrq $0x2, %rcx
shlq $0x2, %rdx
movq %rdx, %r12
xorq $0xc, %r12
decl %eax
jne 0x5240
shrq $0x2, %r12
cmpq %r12, %r13
movq %r12, %rdi
cmovaq %r13, %rdi
movq %rdi, 0x18(%rsp)
movabsq $0xffffffffffffff, %rsi # imm = 0xFFFFFFFFFFFFFF
callq 0xa012
movq 0x8(%rsp), %rcx
movq 0x20(%rcx), %rdi
movl $0x1, %ecx
movq %rax, %rsi
xorl %edx, %edx
movl $0x1, %r8d
movl $0x1, %r9d
callq 0xa819
shrq $0x4, %r15
movq %r15, %rdi
callq 0x4d6d
movq 0x18(%rsp), %rsi
movq %rax, %rdi
movq 0x8(%rsp), %rdx
callq 0x50a5
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movl 0x8(%rax), %edx
leaq 0x18(%rsp), %rdi
movl $0x8, %esi
callq 0x9e48
movq %rax, %r15
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rbx
movq 0x8(%rbx), %rax
movq 0x40(%rax), %rdx
movq 0x48(%rax), %rcx
movq %r15, %rdi
xorl %esi, %esi
callq 0x4560
movl $0x1, %ecx
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0xa819
testb %al, %al
jne 0x5380
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rbx
movq 0x8(%rbx), %rax
movq 0x40(%rax), %rdx
movq 0x48(%rax), %rcx
movq %r15, %rdi
xorl %esi, %esi
callq 0x4560
movl $0x1, %ecx
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xa819
movq 0x8(%rsp), %rcx
movl 0x28(%rcx), %eax
incl %eax
movl %eax, 0x28(%rcx)
cmpl $0x8001, %eax           # imm = 0x8001
jb 0x5380
movq 0x8(%rsp), %rdi
callq 0x5796
movq 0x8(%rsp), %rax
movl $0x0, 0x28(%rax)
movq 0x18(%rsp), %rbx
movq %rbx, 0x10(%rsp)
cmpq $0x1d, 0x28(%rsp)
jb 0x56c6
movl $0x1c, %r14d
movl $0x1c, %ebx
movabsq $0x3fffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFF
andq %rax, %r13
movq %r13, %rdi
callq 0x4d6d
movq %rax, %r15
movl $0x1b, %ecx
xorl %eax, %eax
movq %r15, %rdx
movl %edx, %esi
andl $0x3, %esi
addq %rax, %rsi
shrq $0x2, %rdx
shlq $0x2, %rsi
movq %rsi, %rax
xorq $0xc, %rax
decl %ecx
jne 0x53c3
shrq $0x2, %rax
movl %r15d, %edx
andl $0x3, %edx
movabsq $0x55555555555555, %rcx # imm = 0x55555555555555
imulq %rcx, %rdx
movq %rdx, 0x50(%rsp)
cmpq %r15, %rax
je 0x5407
cmpq %r15, 0x50(%rsp)
jne 0x5419
movq 0x10(%rsp), %rsi
movq %r15, %rdi
movq 0x8(%rsp), %rdx
callq 0x50a5
movq %r14, 0x48(%rsp)
movq 0x20(%rsp), %rax
movzbl (%rax,%rbx), %ecx
cmpl $0x46, %ecx
jg 0x5440
movb $0x1, %al
cmpl $0x41, %ecx
je 0x5454
cmpl $0x43, %ecx
jne 0x5617
xorl %eax, %eax
jmp 0x5454
cmpl $0x47, %ecx
je 0x5452
cmpl $0x54, %ecx
jne 0x5617
movb $0x2, %al
jmp 0x5454
movb $0x3, %al
movq %r12, %rcx
shrq $0x2, %rcx
movzbl %al, %eax
leaq (%rax,%r13,4), %r13
xorb $0x3, %al
movzbl %al, %r12d
shlq $0x36, %r12
orq %rcx, %r12
cmpq %r12, %r13
movq %r12, %rdi
cmovaq %r13, %rdi
movq %rdi, 0x10(%rsp)
movabsq $0xffffffffffffff, %rsi # imm = 0xFFFFFFFFFFFFFF
callq 0xa012
movq 0x8(%rsp), %rcx
movq 0x20(%rcx), %rdi
movl $0x1, %ecx
movq %rax, %rsi
xorl %edx, %edx
movl $0x1, %r8d
movl $0x1, %r9d
callq 0xa819
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movl 0x8(%rax), %edx
leaq 0x10(%rsp), %rdi
movl $0x8, %esi
callq 0x9e48
movq %rax, %rbx
movq 0x8(%rsp), %r14
movq 0x18(%r14), %rbp
movq 0x8(%rbp), %rax
movq 0x40(%rax), %rdx
movq 0x48(%rax), %rcx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4560
movl $0x1, %ecx
movq %rbp, %rdi
movq %rax, %rsi
xorl %edx, %edx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0xa819
testb %al, %al
jne 0x556d
movq 0x10(%r14), %rbp
movq 0x8(%rbp), %rax
movq 0x40(%rax), %rdx
movq 0x48(%rax), %rcx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4560
movl $0x1, %ecx
movq %rbp, %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xa819
movq 0x8(%rsp), %rcx
movl 0x28(%rcx), %eax
incl %eax
movl %eax, 0x28(%rcx)
cmpl $0x8001, %eax           # imm = 0x8001
jb 0x556d
movq 0x8(%rsp), %rdi
callq 0x5796
movq 0x8(%rsp), %rax
movl $0x0, 0x28(%rax)
movl $0x1b, %eax
xorl %edx, %edx
movq %r15, %rcx
movl %ecx, %esi
andl $0x3, %esi
addq %rdx, %rsi
shrq $0x2, %rcx
shlq $0x2, %rsi
movq %rsi, %rdx
xorq $0xc, %rdx
decl %eax
jne 0x5577
shrq $0x2, %rdx
cmpq %r15, %rdx
je 0x55a2
cmpq %r15, 0x50(%rsp)
jne 0x55b4
movq 0x10(%rsp), %rsi
movq %r15, %rdi
movq 0x8(%rsp), %rdx
callq 0x50a5
movq 0x48(%rsp), %r14
incl %r14d
movq %r14, %rbx
cmpq %r14, 0x28(%rsp)
ja 0x53a1
jmp 0x56c1
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4390
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4440
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
movq 0x40(%rsp), %r13
je 0x5603
callq 0x4310
movq 0x28(%rsp), %rcx
cmpq $0x1c, %rcx
jae 0x51bf
jmp 0x56fa
movq 0x48(%rsp), %rax
leal 0x1(%rax), %edx
movq 0x28(%rsp), %rcx
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
leaq 0x20(%rsp), %r12
movq %r12, %rsi
callq 0x4390
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4440
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
movq 0x58(%rsp), %r14
movq 0x40(%rsp), %r13
je 0x5662
callq 0x4310
cmpl $0x1c, 0x48(%rsp)
ja 0x569e
movl $0x1b, %eax
xorl %edx, %edx
movq %r15, %rcx
movl %ecx, %esi
andl $0x3, %esi
addq %rdx, %rsi
shrq $0x2, %rcx
shlq $0x2, %rsi
movq %rsi, %rdx
xorq $0xc, %rdx
decl %eax
jne 0x5673
shrq $0x2, %rdx
cmpq %r15, %rdx
je 0x56b0
cmpq %r15, 0x50(%rsp)
je 0x56b0
movq 0x10(%rsp), %rsi
movq %r15, %rdi
movq 0x8(%rsp), %rdx
callq 0x50a5
movq 0x28(%rsp), %rcx
cmpq $0x1b, %rcx
ja 0x51bf
jmp 0x56fa
movq 0x10(%rsp), %rbx
movabsq $0x3fffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFF
andq %rax, %r13
movq %r13, %rdi
callq 0x4d6d
movq %rax, %rdi
movq %rbx, %rsi
movq 0x8(%rsp), %rdx
callq 0x50a5
movq 0x58(%rsp), %r14
leaq 0x20(%rsp), %r12
movq 0x40(%rsp), %r13
incq %r13
movq %r14, %rdx
subq %r13, %rdx
movq %r13, %rdi
movl $0xa, %esi
callq 0x43c0
leaq 0x1(%rax), %rdi
movq %r14, %rdx
subq %rdi, %rdx
movl $0xa, %esi
callq 0x43c0
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x573b
callq 0x4310
incq %rbx
cmpq %r14, %rbx
jne 0x5166
movq 0x60(%rsp), %rax
movq (%rax), %rbx
movq %rbx, %rdi
callq 0x4410
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5777
jmp 0x5777
jmp 0x5777
jmp 0x5777
jmp 0x5777
jmp 0x5777
jmp 0x5777
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x578e
callq 0x4310
movq %rbx, %rdi
callq 0x4600