// File: /workspace/github_cpp_makefile_star2_O1/ChnMasterOG[P]KmerGO2/kmergo/../kmc_api/kmer_api.h
// Function: bool CKmerAPI::from_string_impl<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>(__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, unsigned int)
inline bool from_string_impl(const RandomAccessIterator iter, uint32 len)
	{
		unsigned char c_char;
		uchar c_binary;
		uchar temp_byte_alignment;
		if (kmer_length != len)
		{
			if (kmer_length && kmer_data)
				delete[] kmer_data;

			kmer_length = len;

			if (kmer_length % 4)
				byte_alignment = 4 - (kmer_length % 4);
			else
				byte_alignment = 0;


			if (kmer_length != 0)
			{
				no_of_rows = (((kmer_length + byte_alignment) % 32) ? (kmer_length + byte_alignment) / 32 + 1 : (kmer_length + byte_alignment) / 32);
				//no_of_rows = (int)ceil((double)(kmer_length + byte_alignment) / 32);
				kmer_data = new uint64[no_of_rows];
				//memset(kmer_data, 0, sizeof(*kmer_data) * no_of_rows);
			}
		}

		memset(kmer_data, 0, sizeof(*kmer_data) * no_of_rows);
		temp_byte_alignment = byte_alignment;
		uint32 i = 0;
		uint32 i_in_string = 0;
		uchar *byte_ptr;

		for (uint32 row_index = 0; row_index < no_of_rows; row_index++)
		{
			byte_ptr = reinterpret_cast<uchar*>(&kmer_data[row_index]);
			byte_ptr += 7;					// shift a pointer towards a MSB

			while (i < kmer_length)
			{
				if ((i_in_string == 0) && temp_byte_alignment)				// check if a byte_alignment placed before a prefix is to be skipped
				{
					temp_byte_alignment--;
					i++;
				}
				else
				{
					c_char = *(iter + i_in_string);
					c_binary = num_codes[c_char];
					c_binary = c_binary << 6;		//11000000
					*byte_ptr = *byte_ptr | c_binary;
					i++;
					i_in_string++;
					if (i_in_string == kmer_length) break;
				}

				if ((i_in_string == 0) && temp_byte_alignment)				// check if a byte_alignment placed before a prefix is to be skipped
				{
					temp_byte_alignment--;
					i++;
				}
				else
				{
					c_char = *(iter + i_in_string);
					c_binary = num_codes[c_char];
					c_binary = c_binary << 4;
					*byte_ptr = *byte_ptr | c_binary;
					i++;
					i_in_string++;
					if (i_in_string == kmer_length) break;
				}

				//!!!if((i == 0) && temp_byte_alignment)	//poprawka zg3oszona przez Maaka D3ugosza			// check if a byte_alignment placed before a prefix is to be skipped
				if ((i_in_string == 0) && temp_byte_alignment)				// check if a byte_alignment placed before a prefix is to be skipped
				{
					temp_byte_alignment--;
					i++;
				}
				else
				{
					c_char = *(iter + i_in_string);
					c_binary = num_codes[c_char];
					c_binary = c_binary << 2;
					*byte_ptr = *byte_ptr | c_binary;
					i++;
					i_in_string++;
					if (i_in_string == kmer_length) break;
				}

				c_char = *(iter + i_in_string);
				c_binary = num_codes[c_char];
				*byte_ptr = *byte_ptr | c_binary;
				i++;
				i_in_string++;
				if (i_in_string == kmer_length) break;

				if (i % 32 == 0)
					break; //check if a new "row" is to be started
				byte_ptr--;
			}
		};
		return true;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movl 0x8(%rdi), %eax
cmpl %edx, %eax
je 0x40b3aa
movl %edx, %ebp
testl %eax, %eax
je 0x40b369
movq (%r14), %rdi
testq %rdi, %rdi
je 0x40b369
callq 0x41b3b0
movl %ebp, 0x8(%r14)
movl %ebp, %eax
andl $0x3, %eax
movb $0x4, %cl
subb %al, %cl
testl %eax, %eax
movzbl %cl, %ecx
cmovel %eax, %ecx
movb %cl, 0xc(%r14)
testl %ebp, %ebp
je 0x40b3aa
movzbl 0xc(%r14), %edi
addl %ebp, %edi
movl %edi, %eax
andl $0x1f, %eax
shrl $0x5, %edi
cmpl $0x1, %eax
sbbl $-0x1, %edi
movl %edi, 0x10(%r14)
shll $0x3, %edi
callq 0x41c2a0
movq %rax, (%r14)
movq (%r14), %rdi
movl 0x10(%r14), %edx
shlq $0x3, %rdx
xorl %r15d, %r15d
xorl %esi, %esi
callq 0x401098
cmpl $0x0, 0x10(%r14)
je 0x40b4c4
movb 0xc(%r14), %al
movq $0x1b71940, %rcx        # imm = 0x1B71940
xorl %edx, %edx
xorl %esi, %esi
cmpl 0x8(%r14), %esi
jae 0x40b4b4
movq (%r14), %rdi
leaq (%rdi,%rdx,8), %rdi
addq $0x7, %rdi
testl %r15d, %r15d
jne 0x40b400
testb %al, %al
je 0x40b400
decb %al
incl %esi
xorl %r15d, %r15d
jmp 0x40b422
movl %r15d, %r8d
movzbl (%rbx,%r8), %r8d
movb (%rcx,%r8), %r8b
shlb $0x6, %r8b
orb %r8b, (%rdi)
incl %esi
incl %r15d
cmpl 0x8(%r14), %r15d
je 0x40b4b4
testl %r15d, %r15d
jne 0x40b434
testb %al, %al
je 0x40b434
decb %al
incl %esi
xorl %r15d, %r15d
jmp 0x40b452
movl %r15d, %r8d
movzbl (%rbx,%r8), %r8d
movb (%rcx,%r8), %r8b
shlb $0x4, %r8b
orb %r8b, (%rdi)
incl %esi
incl %r15d
cmpl 0x8(%r14), %r15d
je 0x40b4b4
testl %r15d, %r15d
jne 0x40b464
testb %al, %al
je 0x40b464
decb %al
incl %esi
xorl %r15d, %r15d
jmp 0x40b482
movl %r15d, %r8d
movzbl (%rbx,%r8), %r8d
movb (%rcx,%r8), %r8b
shlb $0x2, %r8b
orb %r8b, (%rdi)
incl %esi
incl %r15d
cmpl 0x8(%r14), %r15d
je 0x40b4b4
movl %r15d, %r8d
movzbl (%rbx,%r8), %r8d
movb (%rcx,%r8), %r8b
orb %r8b, (%rdi)
incl %esi
incl %r15d
movl 0x8(%r14), %r8d
cmpl %r8d, %r15d
je 0x40b4b4
movl %esi, %r9d
andl $0x1f, %r9d
je 0x40b4b4
decq %rdi
cmpl %r8d, %esi
jb 0x40b3ee
incq %rdx
movl 0x10(%r14), %edi
cmpq %rdi, %rdx
jb 0x40b3d9
movb $0x1, %al
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop