// File: /workspace/github_cpp_makefile_star2_O2/DimitriDaSilva[P]42_ft_containers/containers/vector.hpp
// Function: void ft::vector<char, std::allocator<char>>::insert<ft::random_access_iterator<char const>>(ft::random_access_iterator<char>, ft::random_access_iterator<char const>, ft::random_access_iterator<char const>, ft::enable_if<!ft::is_integral<ft::random_access_iterator<char const>>::value, ft::random_access_iterator<char const>>::type*)
void
		insert(iterator position, InputIterator first, InputIterator last,
				typename ft::enable_if<!ft::is_integral<InputIterator>::value,
					InputIterator>::type* = NULL)
		{
			value_type*		new_vec;
			difference_type	distance = ft::distance(first, last);
			size_type		new_size = _size + distance;
			size_type		new_capacity;
			iterator 		it_old;
			iterator 		it_new;

			// New element requires reallocation because vector is full
			if (new_size > _capacity)
			{
				new_capacity = get_new_capacity(new_size);

				// Reallocate new
				new_vec = _allocator.allocate(new_capacity);

				// Copy sequence to new array
				it_old = begin();
				it_new = new_vec;
				while (it_old != end() || distance > 0)
				{
					// Position found
					if (it_old == position)
					{
						while (distance--)
							_allocator.construct(&*it_new++, *first++);
					}

					// Copy old to new
					if (it_old != end())
						_allocator.construct(&*it_new++, *it_old++);
				}

				// Update private data of vector
				this->~vector();
				_start = new_vec;
				_size = new_size;
				_capacity = new_capacity;
			}
			// No reallocation
			else
			{
				// We offset the whole vector by distance one item at a time
				// We need to start by the end to avoid overwritting values
				for (reverse_iterator it = rbegin() - distance;
						it != reverse_iterator(position) - distance;
						it++)
				{
					_allocator.construct(&*it, *(it + distance));
					_allocator.destroy(&*(it + distance));
				}

				// Setting the new values before position
				for (iterator it = position; it != position + distance; it++, first++)
					_allocator.construct(&*it, *first);

				// Update private data of vector
				_size += distance;
			}
		}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq (%rdx), %rax
leaq -0x48(%rbp), %rdi
movq %rax, (%rdi)
movq (%rcx), %rax
leaq -0x40(%rbp), %rsi
movq %rax, (%rsi)
callq 0x10198
movq %rax, %r12
movq 0x18(%rbx), %rax
leaq (%rax,%r12), %rcx
movq %rcx, -0x30(%rbp)
cmpq 0x20(%rbx), %rcx
jbe 0x11aa2
leaq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x11b0a
leaq 0x10(%rbx), %rdi
movq %rax, -0x38(%rbp)
movq %rax, %rsi
xorl %edx, %edx
callq 0x11994
movq %rax, %r13
movq 0x8(%rbx), %rsi
pushq $-0x1
popq %rax
movq %r13, %rcx
movq %rsi, %rdx
movq 0x18(%rbx), %rdi
leaq (%rsi,%rdi), %r8
cmpq %r8, %rdx
setne %r8b
testq %r12, %r12
setg %r9b
orb %r8b, %r9b
cmpb $0x1, %r9b
jne 0x11abb
cmpq (%r15), %rdx
jne 0x11a88
jmp 0x11a77
movq (%r14), %rsi
leaq 0x1(%rsi), %rdi
movq %rdi, (%r14)
movb (%rsi), %sil
movb %sil, (%rcx)
incq %rcx
subq $0x1, %r12
jae 0x11a64
movq 0x8(%rbx), %rsi
movq 0x18(%rbx), %rdi
movq %rax, %r12
addq %rsi, %rdi
cmpq %rdi, %rdx
je 0x11a3e
movb (%rdx), %sil
incq %rdx
movb %sil, (%rcx)
incq %rcx
movq 0x8(%rbx), %rsi
jmp 0x11a3e
addq 0x8(%rbx), %rax
movq (%r15), %rcx
cmpq %rcx, %rax
je 0x11ad9
movb -0x1(%rax), %cl
movb %cl, -0x1(%rax,%r12)
decq %rax
jmp 0x11aa6
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movq %r13, 0x8(%rbx)
movq -0x30(%rbp), %rax
movq %rax, 0x18(%rbx)
movq -0x38(%rbp), %rax
movq %rax, 0x20(%rbx)
jmp 0x11afa
movq %rcx, %rax
addq %r12, %rcx
cmpq %rcx, %rax
je 0x11af6
movq (%r14), %rcx
movb (%rcx), %cl
movb %cl, (%rax)
incq %rax
incq (%r14)
movq (%r15), %rcx
jmp 0x11adc
addq %r12, 0x18(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop