// File: /workspace/github_cpp_makefile_star2_O2/wichtounet[P]articles/plf_colony_alpha/plf_colony.h
// Function: plf::colony<NonTrivialStringMovable, std::allocator<NonTrivialStringMovable>, unsigned short>::insert(unsigned long, NonTrivialStringMovable const&)
iterator insert(const size_type number_of_elements, const element_type &element)
	{
		if (number_of_elements == 0)
		{
			return end_iterator;
		}

		if (first_group == NULL) // Empty colony, no groups created yet
		{
			if (number_of_elements > group_allocator_pair.max_elements_per_group)
			{
				// Create and fill first group:
				initialize(group_allocator_pair.max_elements_per_group); // Construct first group
				group_fill(element, group_allocator_pair.max_elements_per_group);

				// Create and fill all remaining groups:
				size_type multiples = (number_of_elements / static_cast<size_type>(group_allocator_pair.max_elements_per_group));
				const skipfield_type element_remainder = static_cast<const skipfield_type>(number_of_elements - (multiples * static_cast<size_type>(group_allocator_pair.max_elements_per_group)));

				while (--multiples != 0)
				{
					group_create(group_allocator_pair.max_elements_per_group);
					group_fill(element, group_allocator_pair.max_elements_per_group);
				}

				if (element_remainder != 0)
				{
					group_create(group_allocator_pair.max_elements_per_group);
					group_fill(element, element_remainder);
				}
			}
			else
			{
				initialize((number_of_elements < min_elements_per_group) ? min_elements_per_group : static_cast<skipfield_type>(number_of_elements)); // Construct first group
				group_fill(element, static_cast<skipfield_type>(number_of_elements));
			}

			end_iterator.skipfield_pointer = end_iterator.group_pointer->skipfield + end_iterator.group_pointer->number_of_elements;
			total_number_of_elements += number_of_elements;
			return begin_iterator;
		}
		else
		{
			const iterator return_iterator = insert(element);
			size_type num_elements = number_of_elements - 1;
			size_type capacity_available = (reinterpret_cast<element_pointer_type>(end_iterator.group_pointer->skipfield) - end_iterator.element_pointer) + erased_locations.total_number_of_elements;

			// Use up erased locations and remainder of current group first:
			while (capacity_available-- != 0 && num_elements-- != 0)
			{
				insert(element);
			}

			// If still some left over, create new groups and fill:
			if (num_elements > group_allocator_pair.max_elements_per_group)
			{
				size_type multiples = (num_elements / static_cast<size_type>(group_allocator_pair.max_elements_per_group));
				const skipfield_type element_remainder = static_cast<const skipfield_type>(num_elements - (multiples * static_cast<size_type>(group_allocator_pair.max_elements_per_group)));

				while (multiples-- != 0)
				{
					group_create(group_allocator_pair.max_elements_per_group);
					group_fill(element, group_allocator_pair.max_elements_per_group);
				}

				if (element_remainder != 0)
				{
					group_create(group_allocator_pair.max_elements_per_group);
					group_fill(element, element_remainder);
				}
			}
			else if (num_elements > total_number_of_elements)
			{
				group_create(static_cast<skipfield_type>(num_elements));
				group_fill(element, static_cast<skipfield_type>(num_elements));
			}

			end_iterator.skipfield_pointer = end_iterator.group_pointer->skipfield + end_iterator.group_pointer->number_of_elements;
			total_number_of_elements += num_elements; // Adds the remainder - the insert functions above will already have incremented total_number_of_elements

			return return_iterator;
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, %rbx
testq %rdx, %rdx
je 0x71a8e
cmpq $0x0, 0x30(%r14)
movq %rcx, %r15
movq %rdx, %r12
je 0x71aa0
movq %rbx, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1493a
movq (%r14), %rax
movq 0x18(%rax), %rax
subq 0x8(%r14), %rax
pushq $0x28
popq %rcx
cqto
idivq %rcx
movq %rax, %r13
addq 0x70(%r14), %r13
negq %r13
pushq $0x1
popq %rbx
leaq 0x10(%rsp), %rbp
leaq (%r13,%rbx), %rax
cmpq $0x1, %rax
je 0x71b04
cmpq %rbx, %r12
je 0x71b23
movq %rbp, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1493a
incq %rbx
jmp 0x71a63
vmovups (%r14), %xmm0
vmovups %xmm0, (%rbx)
movq 0x10(%r14), %rax
jmp 0x71be1
movzwl 0x42(%r14), %eax
cmpq %r12, %rax
jae 0x71b80
movzwl %ax, %esi
movq %r14, %rdi
callq 0x14c64
movzwl 0x42(%r14), %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x71c3e
movzwl 0x42(%r14), %ecx
movq %r12, %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %r13
movq %rax, %rbp
decq %rbp
je 0x71b9c
movzwl 0x42(%r14), %esi
movq %r14, %rdi
callq 0x71cdc
movzwl 0x42(%r14), %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x71c3e
jmp 0x71adc
movzwl 0x42(%r14), %ecx
movq %r12, %r13
subq %rbx, %r13
cmpq %rcx, %r13
jbe 0x71be7
leaq 0x42(%r14), %rax
movq %rax, 0x8(%rsp)
jmp 0x71b35
movzwl 0x42(%r14), %ecx
leaq 0x42(%r14), %rax
movq %rax, 0x8(%rsp)
pushq $-0x1
popq %r13
movq %r13, %rax
xorl %edx, %edx
divq %rcx
movq (%rsp), %rbx
movq %rdx, %rbp
movq %rax, %r12
subq $0x1, %r12
jb 0x71b6c
movzwl 0x42(%r14), %esi
movq %r14, %rdi
callq 0x71cdc
movzwl 0x42(%r14), %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x71c3e
jmp 0x71b47
testw %bp, %bp
je 0x71c11
movq 0x8(%rsp), %rax
movzwl (%rax), %r12d
jmp 0x71bf7
movzwl 0x40(%r14), %eax
movq %r14, %rdi
cmpq %r12, %rax
cmovbel %r12d, %eax
movzwl %ax, %esi
callq 0x14c64
movl %r12d, %r13d
jmp 0x71baf
testw %r13w, %r13w
je 0x71bbe
movzwl 0x42(%r14), %esi
movq %r14, %rdi
callq 0x71cdc
movzwl %r13w, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x71c3e
movq (%r14), %rax
movzwl 0x30(%rax), %ecx
addl %ecx, %ecx
addq 0x18(%rax), %rcx
movq %rcx, 0x10(%r14)
addq %r12, 0x38(%r14)
vmovups 0x18(%r14), %xmm0
vmovups %xmm0, (%rbx)
movq 0x28(%r14), %rax
movq %rax, 0x10(%rbx)
jmp 0x71c26
cmpq 0x38(%r14), %r13
jbe 0x71c38
subl %ebx, %r12d
movq (%rsp), %rbx
movl %r12d, %ebp
movzwl %r12w, %esi
movq %r14, %rdi
callq 0x71cdc
movzwl %bp, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x71c3e
movq (%r14), %rax
movzwl 0x30(%rax), %ecx
addl %ecx, %ecx
addq 0x18(%rax), %rcx
movq %rcx, 0x10(%r14)
addq %r13, 0x38(%r14)
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rbx
jmp 0x71c11