// File: /workspace/github_cpp_makefile_star2_O3/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 (%rdx), %rdx
movq (%rcx), %r8
movq %r8, %r15
subq %rdx, %r15
movq %r15, %rbx
sarq $0x5, %rbx
movq 0x18(%rdi), %r12
movq 0x20(%rdi), %rax
leaq (%rbx,%r12), %rcx
cmpq %rax, %rcx
movq %rdi, -0x30(%rbp)
movq %rsi, -0x50(%rbp)
jbe 0x28528
movq %rcx, %r12
testq %rax, %rax
je 0x2840d
movq %rax, %r12
addq %rax, %rax
cmpq %r12, %rcx
ja 0x28402
movq %rcx, -0x58(%rbp)
movq -0x30(%rbp), %rax
leaq 0x10(%rax), %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x2724a
movq -0x30(%rbp), %rsi
movq %rax, -0x38(%rbp)
movq 0x18(%rsi), %rax
testq %rax, %rax
sete %cl
testq %rbx, %rbx
setle %dl
testb %dl, %cl
jne 0x28504
movq 0x8(%rsi), %rcx
movq %rcx, %r15
movq -0x38(%rbp), %r13
movq -0x50(%rbp), %rdx
cmpq (%rdx), %r15
jne 0x2849b
testq %rbx, %rbx
je 0x28494
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 0x71e4
decq %rbx
jne 0x2845c
movq -0x30(%rbp), %rsi
movq 0x8(%rsi), %rcx
movq 0x18(%rsi), %rax
movq $-0x1, %rbx
movq %rax, %rdx
shlq $0x5, %rdx
addq %rcx, %rdx
cmpq %rdx, %r15
je 0x284e8
leaq 0x20(%r13), %rax
movq %rax, -0x48(%rbp)
leaq 0x20(%r15), %rax
movq %rax, -0x40(%rbp)
leaq 0x10(%r13), %rax
movq %rax, (%r13)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x71e4
movq -0x30(%rbp), %rsi
movq 0x8(%rsi), %rcx
movq 0x18(%rsi), %rax
movq -0x48(%rbp), %r13
movq -0x40(%rbp), %r15
movq %rax, %rdx
shlq $0x5, %rdx
addq %rcx, %rdx
cmpq %rdx, %r15
jne 0x2844e
testq %rbx, %rbx
jg 0x2844e
movq (%rsi), %rax
movq %rsi, %rbx
movq %rsi, %rdi
callq *(%rax)
movq -0x38(%rbp), %rax
movq %rax, 0x8(%rbx)
movq -0x58(%rbp), %rax
movq %rax, 0x18(%rbx)
movq %r12, 0x20(%rbx)
jmp 0x285e9
movq %r8, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
shlq $0x5, %r12
addq 0x8(%rdi), %r12
movq (%rsi), %r13
cmpq %r13, %r12
je 0x2859c
addq %r15, %r12
movq %rbx, %rax
shlq $0x5, %rax
negq %rax
movq %rax, -0x48(%rbp)
leaq -0x10(%r12), %rax
movq %rax, -0x20(%r12)
movq -0x48(%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 0x71e4
movq -0x10(%r13), %rdi
cmpq %rdi, %r13
je 0x2858c
callq 0x5190
movq -0x50(%rbp), %rax
movq (%rax), %r13
leaq (%r15,%r13), %rax
cmpq %rax, %r12
jne 0x28551
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
movq -0x50(%rbp), %r12
je 0x285e1
movq (%r14), %rax
leaq 0x10(%r13), %rcx
movq %rcx, (%r13)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x71e4
addq $0x20, %r13
movq (%r14), %rax
addq $0x20, %rax
movq %rax, (%r14)
movq (%r12), %rcx
addq %r15, %rcx
cmpq %rcx, %r13
jne 0x285ad
movq -0x30(%rbp), %rax
addq %rbx, 0x18(%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq