// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movq %rsi, %rbx
movq %rdi, %r12
movq $0x0, (%rdi)
movq 0x18(%rsi), %rdx
movq 0x20(%rsi), %rax
incq %rdx
cmpq %rax, %rdx
jbe 0x31389
movq %rcx, -0x48(%rbp)
movq %rdx, %r13
testq %rax, %rax
je 0x312a2
movq %rax, %r13
addq %rax, %rax
cmpq %r13, %rdx
ja 0x31297
movq %rdx, -0x40(%rbp)
leaq 0x10(%rbx), %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x28382
movq %rax, -0x30(%rbp)
cmpq $0x0, 0x18(%rbx)
jne 0x312ca
cmpq $0x0, (%r12)
jne 0x3136b
movq 0x8(%rbx), %r14
movq -0x30(%rbp), %rdi
movq %rbx, -0x38(%rbp)
movq %r15, -0x50(%rbp)
cmpq (%r15), %r14
jne 0x31308
movq %rdi, (%r12)
leaq 0x20(%rdi), %rbx
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
movq -0x48(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
callq 0x728c
movq %rbx, %rdi
movq -0x38(%rbp), %rbx
movq 0x18(%rbx), %rax
shlq $0x5, %rax
addq 0x8(%rbx), %rax
cmpq %rax, %r14
je 0x3134b
leaq 0x20(%rdi), %rbx
movq %r12, %r15
leaq 0x20(%r14), %r12
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
callq 0x728c
movq %rbx, %rdi
movq -0x38(%rbp), %rbx
movq %r12, %r14
movq %r15, %r12
movq -0x50(%rbp), %r15
movq 0x18(%rbx), %rax
shlq $0x5, %rax
addq 0x8(%rbx), %rax
cmpq %rax, %r14
jne 0x312da
cmpq $0x0, (%r12)
je 0x312da
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movq -0x30(%rbp), %rax
movq %rax, 0x8(%rbx)
movq -0x40(%rbp), %rax
movq %rax, 0x18(%rbx)
movq %r13, 0x20(%rbx)
jmp 0x313ac
movq (%r15), %rax
leaq -0x58(%rbp), %rsi
movq %rax, (%rsi)
movl $0x1, %edx
movq %rbx, %rdi
callq 0x313be
cmpq %r15, %r12
je 0x313ac
movq (%r15), %rax
movq %rax, (%r12)
movq %r12, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq