// File: /workspace/github_cpp_makefile_star2_O1/DimitriDaSilva[P]42_ft_containers/containers/vector.hpp
// Function: void ft::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>::insert<ft::random_access_iterator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const>>(ft::random_access_iterator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, ft::random_access_iterator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const>, ft::random_access_iterator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const>, ft::enable_if<!ft::is_integral<ft::random_access_iterator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const>>::value, ft::random_access_iterator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<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 $0x38, %rsp
movq %rdx, %r14
movq (%rcx), %rbx
subq (%rdx), %rbx
movq %rbx, %r15
sarq $0x5, %r15
movq 0x18(%rdi), %r12
movq 0x20(%rdi), %rax
leaq (%r15,%r12), %rcx
cmpq %rax, %rcx
movq %rdi, -0x30(%rbp)
movq %rsi, -0x40(%rbp)
jbe 0x29652
movq %rcx, %r12
testq %rax, %rax
je 0x2953f
movq %rax, %r12
addq %rax, %rax
cmpq %r12, %rcx
ja 0x29534
movq %rcx, -0x50(%rbp)
movq -0x30(%rbp), %rax
leaq 0x10(%rax), %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x28382
movq -0x30(%rbp), %rdx
movq %rax, -0x48(%rbp)
cmpq $0x0, 0x18(%rdx)
sete %al
testq %r15, %r15
setle %cl
testb %cl, %al
jne 0x2962e
movq 0x8(%rdx), %rbx
movq -0x48(%rbp), %r13
movq -0x40(%rbp), %rax
cmpq (%rax), %rbx
jne 0x295c9
movq %r15, %rax
subq $0x1, %rax
jae 0x29592
movq %rax, %r15
jmp 0x295c9
movq %r13, %rdi
addq $0x20, %r13
movq (%r14), %rax
leaq 0x20(%rax), %rcx
movq %rcx, (%r14)
leaq 0x10(%rdi), %rcx
movq %rcx, (%rdi)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
callq 0x728c
decq %r15
jne 0x29592
movq $-0x1, %r15
movq -0x30(%rbp), %rdx
movq 0x18(%rdx), %rax
shlq $0x5, %rax
addq 0x8(%rdx), %rax
cmpq %rax, %rbx
je 0x29610
leaq 0x20(%r13), %rax
movq %rax, -0x38(%rbp)
leaq 0x20(%rbx), %rax
movq %rax, -0x58(%rbp)
leaq 0x10(%r13), %rax
movq %rax, (%r13)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x728c
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %r13
movq -0x58(%rbp), %rbx
movq 0x18(%rdx), %rax
shlq $0x5, %rax
addq 0x8(%rdx), %rax
cmpq %rax, %rbx
jne 0x2957b
testq %r15, %r15
jg 0x2957b
movq (%rdx), %rax
movq %rdx, %rbx
movq %rdx, %rdi
callq *(%rax)
movq -0x48(%rbp), %rax
movq %rax, 0x8(%rbx)
movq -0x50(%rbp), %rax
movq %rax, 0x18(%rbx)
movq %r12, 0x20(%rbx)
jmp 0x296fd
shlq $0x5, %r12
addq 0x8(%rdi), %r12
movq (%rsi), %r13
cmpq %r13, %r12
je 0x296be
addq %rbx, %r12
movq %r15, %rax
shlq $0x5, %rax
negq %rax
movq %rax, -0x38(%rbp)
leaq -0x10(%r12), %rax
movq %rax, -0x20(%r12)
movq -0x38(%rbp), %rax
leaq (%r12,%rax), %r13
addq $-0x10, %r13
addq $-0x20, %r12
movq -0x10(%r13), %rsi
movq -0x8(%r13), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x728c
movq -0x10(%r13), %rdi
cmpq %rdi, %r13
je 0x296ae
callq 0x5190
movq -0x40(%rbp), %rax
movq (%rax), %r13
leaq (%rbx,%r13), %rax
cmpq %rax, %r12
jne 0x29673
movq -0x40(%rbp), %r12
movq (%r12), %rax
addq %rbx, %rax
cmpq %rax, %r13
je 0x296f5
movq (%r14), %rax
leaq 0x10(%r13), %rcx
movq %rcx, (%r13)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x728c
addq $0x20, (%r14)
addq $0x20, %r13
jmp 0x296c2
movq -0x30(%rbp), %rax
addq %r15, 0x18(%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq