// File: /workspace/github_cpp_makefile_star2_O3/DimitriDaSilva[P]42_ft_containers/containers/vector.hpp
// Function: 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>>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
iterator
		insert(iterator position, const value_type& val)
		{
			iterator	ret_position = NULL;
			value_type*	new_vec;
			size_type	new_size = _size + 1;
			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. If empty, size 2, otherwise * 2
				new_vec = _allocator.allocate(new_capacity);

				// Copy sequence to new array
				it_old = begin();
				it_new = new_vec;
				// We need to parse until we didn't reach the end AND we haven't
				// found the position
				while (it_old != end() || ret_position == NULL)
				{
					// Position found
					if (it_old == position)
					{
						ret_position = it_new;
						_allocator.construct(&*it_new++, val);
					}
					// In the case the position is the last element, we need to
					// make sure we won't be constructing beyond the sequence
					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 need to reallocate so iterator position will still be valid
			else
			{
				insert(position, 1, val);
				ret_position = position;
			}

			return ret_position;
		}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, %r14
movq $0x0, (%rdi)
movq 0x18(%rsi), %rdx
movq 0x20(%rsi), %rax
incq %rdx
cmpq %rax, %rdx
jbe 0x301c1
movq %rcx, -0x50(%rbp)
movq %rdx, %rcx
testq %rax, %rax
je 0x300d4
movq %rax, %rcx
addq %rax, %rax
cmpq %rcx, %rdx
ja 0x300c9
movq %rdx, -0x48(%rbp)
leaq 0x10(%rbx), %rdi
movq %rcx, -0x40(%rbp)
movq %rcx, %rsi
xorl %edx, %edx
callq 0x2724a
movq %rax, %rdi
movq 0x8(%rbx), %rax
movq %rbx, -0x30(%rbp)
movq 0x18(%rbx), %rcx
movq %rax, %r12
movq %rdi, -0x38(%rbp)
cmpq (%r13), %r12
jne 0x30136
movq %rdi, (%r14)
leaq 0x20(%rdi), %rbx
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
movq -0x50(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
callq 0x71e4
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rax
movq 0x18(%rcx), %rcx
movq %rbx, %rdi
movq %rcx, %rdx
shlq $0x5, %rdx
addq %rax, %rdx
cmpq %rdx, %r12
je 0x3017e
leaq 0x20(%rdi), %rbx
movq %r14, %r15
leaq 0x20(%r12), %r14
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
callq 0x71e4
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rax
movq 0x18(%rcx), %rcx
movq %rbx, %rdi
movq %r14, %r12
movq %r15, %r14
movq %rcx, %rdx
shlq $0x5, %rdx
addq %rax, %rdx
cmpq %rdx, %r12
jne 0x30100
cmpq $0x0, (%r14)
je 0x30100
movq -0x30(%rbp), %rbx
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movq -0x38(%rbp), %rax
movq %rax, 0x8(%rbx)
movq -0x48(%rbp), %rax
movq %rax, 0x18(%rbx)
movq -0x40(%rbp), %rax
movq %rax, 0x20(%rbx)
jmp 0x301e5
movq (%r13), %rax
leaq -0x58(%rbp), %rsi
movq %rax, (%rsi)
movl $0x1, %edx
movq %rbx, %rdi
callq 0x301f8
cmpq %r13, %r14
je 0x301e5
movq (%r13), %rax
movq %rax, (%r14)
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop