// File: /workspace/github_cpp_makefile_star2_O1/wichtounet[P]articles/plf_colony_alpha/plf_colony.h
// Function: plf::colony<Trivial<8>, std::allocator<Trivial<8>>, unsigned short>::insert(unsigned long, Trivial<8> 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, %r12
testq %rdx, %rdx
je 0x90063
movq %rcx, %r15
movq %rdx, %rbp
cmpq $0x0, 0x30(%r14)
je 0x90077
movq %r12, 0x8(%rsp)
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xc7d8
leaq -0x1(%rbp), %r13
movq (%r14), %rax
movq 0x18(%rax), %rbx
subq 0x8(%r14), %rbx
sarq $0x3, %rbx
addq 0x70(%r14), %rbx
je 0x8ffd2
movq %rbp, (%rsp)
negq %rbx
xorl %eax, %eax
leaq 0x10(%rsp), %rbp
movq %rax, %r12
cmpq %rax, %r13
je 0x8ffc7
movq %rbp, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xc7d8
leaq 0x1(%r12), %rax
movq %rbx, %rcx
addq %rax, %rcx
jne 0x8ffa4
movq (%rsp), %r13
subq %r12, %r13
addq $-0x2, %r13
movzwl 0x42(%r14), %ecx
cmpq %rcx, %r13
jbe 0x90111
movq %r13, %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %r12
movq %rax, %rbp
movzwl 0x42(%r14), %esi
movq %r14, %rdi
callq 0x90228
movzwl 0x42(%r14), %eax
movq 0x8(%r14), %rcx
movl %eax, %edx
shll $0x3, %edx
movq (%r15), %rsi
movq %rsi, (%rcx)
addq $0x8, %rcx
addq $-0x8, %rdx
jne 0x90009
decq %rbp
movq %rcx, 0x8(%r14)
movq (%r14), %rdx
movq %rcx, (%rdx)
movw %ax, 0x30(%rdx)
jne 0x8ffee
testw %r12w, %r12w
je 0x90150
movzwl 0x42(%r14), %esi
movq %r14, %rdi
callq 0x90228
movq 0x8(%r14), %rax
movzwl %r12w, %ecx
leaq (%rax,%rcx,8), %rcx
movq (%r15), %rdx
movq %rdx, (%rax)
addq $0x8, %rax
cmpq %rcx, %rax
jne 0x9004f
jmp 0x90141
vmovups (%r14), %xmm0
vmovups %xmm0, (%r12)
movq 0x10(%r14), %rax
jmp 0x90210
movzwl 0x42(%r14), %eax
cmpq %rbp, %rax
jae 0x9016f
movzwl %ax, %esi
movq %r14, %rdi
callq 0xcab4
movzwl 0x42(%r14), %ecx
movq 0x8(%r14), %rax
movl %ecx, %edx
shll $0x3, %edx
movq (%r15), %rsi
movq %rsi, (%rax)
addq $0x8, %rax
addq $-0x8, %rdx
jne 0x9009e
movq %rax, 0x8(%r14)
movq (%r14), %rdx
movq %rax, (%rdx)
movw %cx, 0x30(%rdx)
movq %rbp, %rbx
movq %rbp, %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %r13
movq %rax, %rbp
decq %rbp
je 0x901ab
movzwl 0x42(%r14), %esi
movq %r14, %rdi
callq 0x90228
movzwl 0x42(%r14), %eax
movq 0x8(%r14), %rcx
movl %eax, %edx
shll $0x3, %edx
movq (%r15), %rsi
movq %rsi, (%rcx)
addq $0x8, %rcx
addq $-0x8, %rdx
jne 0x900f1
movq %rcx, 0x8(%r14)
movq (%r14), %rdx
movq %rcx, (%rdx)
movw %ax, 0x30(%rdx)
jmp 0x900cd
cmpq 0x38(%r14), %r13
jbe 0x90150
movzwl %r13w, %r12d
movq %r14, %rdi
movl %r12d, %esi
callq 0x90228
movq 0x8(%r14), %rax
shll $0x3, %r12d
movq (%r15), %rcx
movq %rcx, (%rax)
addq $0x8, %rax
addq $-0x8, %r12
jne 0x9012e
movl %r13d, %r12d
movq %rax, 0x8(%r14)
movq (%r14), %rcx
movq %rax, (%rcx)
movw %r12w, 0x30(%rcx)
movq (%r14), %rax
movzwl 0x30(%rax), %ecx
addl %ecx, %ecx
addq 0x18(%rax), %rcx
movq %rcx, 0x10(%r14)
addq %r13, 0x38(%r14)
movq 0x8(%rsp), %r12
jmp 0x90215
movzwl 0x40(%r14), %esi
cmpq %rbp, %rsi
cmovbel %ebp, %esi
movl $0xffff, %ebx           # imm = 0xFFFF
andl %ebx, %esi
movq %r14, %rdi
callq 0xcab4
movq 0x8(%r14), %rax
andl %ebp, %ebx
shll $0x3, %ebx
movq (%r15), %rcx
movq %rcx, (%rax)
addq $0x8, %rax
addq $-0x8, %rbx
jne 0x90192
movq %rax, 0x8(%r14)
movl %ebp, %r13d
jmp 0x901e0
testw %r13w, %r13w
movq %rbx, %rbp
je 0x901eb
movzwl 0x42(%r14), %esi
movq %r14, %rdi
callq 0x90228
movq 0x8(%r14), %rax
movzwl %r13w, %ecx
leaq (%rax,%rcx,8), %rcx
movq (%r15), %rdx
movq %rdx, (%rax)
addq $0x8, %rax
cmpq %rcx, %rax
jne 0x901cd
movq %rax, 0x8(%r14)
movq (%r14), %rcx
movq %rax, (%rcx)
movw %r13w, 0x30(%rcx)
movq (%r14), %rax
movzwl 0x30(%rax), %ecx
addl %ecx, %ecx
addq 0x18(%rax), %rcx
movq %rcx, 0x10(%r14)
addq %rbp, 0x38(%r14)
vmovups 0x18(%r14), %xmm0
vmovups %xmm0, (%r12)
movq 0x28(%r14), %rax
movq %rax, 0x10(%r12)
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop