// File: 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
subq $0x110, %rsp            # imm = 0x110
movq %rdx, -0xd0(%rbp)
movq %rdi, -0xc8(%rbp)
movq %rdi, %rax
movq %rax, -0xc0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb8(%rbp)
movb $0x0, -0x21(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x56570
movq -0xb8(%rbp), %rax
movq 0x18(%rax), %rax
incq %rax
movq %rax, -0x38(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x56510
jmp 0x64ab8
leaq -0x60(%rbp), %rdi
callq 0x56510
jmp 0x64ac3
movq -0xb8(%rbp), %rcx
movq -0x38(%rbp), %rax
cmpq 0x20(%rcx), %rax
jbe 0x64ed1
movq -0xb8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x55820
movq -0xb8(%rbp), %rdi
movq %rax, -0x40(%rbp)
addq $0x10, %rdi
movq -0x40(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x53eb0
movq %rax, -0xd8(%rbp)
jmp 0x64b0d
movq -0xb8(%rbp), %rsi
movq -0xd8(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x564a0
jmp 0x64b2a
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x56530
jmp 0x64b39
leaq -0x68(%rbp), %rdi
callq 0x564d0
jmp 0x64b44
movq -0x30(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x56570
jmp 0x64b53
leaq -0x60(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x56530
jmp 0x64b62
leaq -0x70(%rbp), %rdi
callq 0x564d0
jmp 0x64b6d
jmp 0x64b6f
movq -0xb8(%rbp), %rsi
movb $0x0, -0x81(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x565c0
jmp 0x64b88
leaq -0x48(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x56590
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0xd9(%rbp)
jne 0x64be0
xorl %eax, %eax
movl %eax, %esi
leaq -0x80(%rbp), %rdi
callq 0x56570
jmp 0x64bb3
movq -0xc8(%rbp), %rdi
movb $0x1, -0x81(%rbp)
leaq -0x80(%rbp), %rsi
callq 0x56630
movb %al, -0xda(%rbp)
jmp 0x64bd2
movb -0xda(%rbp), %al
movb %al, -0xd9(%rbp)
jmp 0x64be0
movb -0xd9(%rbp), %al
movb %al, -0xdb(%rbp)
testb $0x1, -0x81(%rbp)
jne 0x64bf7
jmp 0x64c04
leaq -0x80(%rbp), %rdi
callq 0x564d0
jmp 0x64c02
jmp 0x64c04
leaq -0x78(%rbp), %rdi
callq 0x564d0
jmp 0x64c0f
movb -0xdb(%rbp), %al
testb $0x1, %al
jne 0x64c1e
jmp 0x64e9f
movq -0xd0(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x56630
movb %al, -0xdc(%rbp)
jmp 0x64c36
movb -0xdc(%rbp), %al
testb $0x1, %al
jne 0x64c45
jmp 0x64d7f
movq -0xc8(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x56530
jmp 0x64c57
movq -0xb8(%rbp), %rax
addq $0x10, %rax
movq %rax, -0xe8(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x60(%rbp), %rsi
xorl %edx, %edx
callq 0x56660
jmp 0x64c7d
leaq -0x90(%rbp), %rdi
callq 0x566c0
movq -0xe8(%rbp), %rdi
movq %rax, %rsi
movq -0x20(%rbp), %rdx
callq 0x53e60
jmp 0x64c9e
leaq -0x90(%rbp), %rdi
callq 0x564d0
jmp 0x64cac
jmp 0x64d7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x64f9d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x64f74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x64f5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x564d0
jmp 0x64cfb
jmp 0x64f5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x564d0
jmp 0x64d17
jmp 0x64f5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x64d50
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
testb $0x1, -0x81(%rbp)
jne 0x64d41
jmp 0x64d4e
leaq -0x80(%rbp), %rdi
callq 0x564d0
jmp 0x64d4c
jmp 0x64d4e
jmp 0x64d50
leaq -0x78(%rbp), %rdi
callq 0x564d0
jmp 0x64d5b
jmp 0x64f5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x564d0
jmp 0x64d7a
jmp 0x64f5f
movq -0xb8(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0x565c0
jmp 0x64d94
leaq -0x48(%rbp), %rdi
leaq -0x98(%rbp), %rsi
movq %rsi, -0xf8(%rbp)
callq 0x56590
movq -0xf8(%rbp), %rdi
movb %al, -0xe9(%rbp)
callq 0x564d0
jmp 0x64dbf
movb -0xe9(%rbp), %al
testb $0x1, %al
jne 0x64dce
jmp 0x64e9a
movq -0xb8(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x100(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
xorl %edx, %edx
callq 0x56660
jmp 0x64df4
leaq -0xa0(%rbp), %rdi
callq 0x566c0
movq %rax, -0x108(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
xorl %edx, %edx
callq 0x56660
jmp 0x64e1b
leaq -0xa8(%rbp), %rdi
callq 0x566c0
movq -0x100(%rbp), %rdi
movq -0x108(%rbp), %rsi
movq %rax, %rdx
callq 0x53e60
jmp 0x64e3f
leaq -0xa8(%rbp), %rdi
callq 0x564d0
jmp 0x64e4d
leaq -0xa0(%rbp), %rdi
callq 0x564d0
jmp 0x64e5b
jmp 0x64e9a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x64e87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x564d0
jmp 0x64e85
jmp 0x64e87
leaq -0xa0(%rbp), %rdi
callq 0x564d0
jmp 0x64e95
jmp 0x64f5f
jmp 0x64b6f
movq -0xb8(%rbp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
jmp 0x64eb0
movq -0xb8(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rcx
movq %rcx, 0x20(%rax)
jmp 0x64f45
movq -0xd0(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x56ac0
jmp 0x64ee6
movq -0xb8(%rbp), %rdi
movq -0x20(%rbp), %rcx
leaq -0xb0(%rbp), %rsi
movl $0x1, %edx
callq 0x64fc0
jmp 0x64f04
leaq -0xb0(%rbp), %rdi
callq 0x564d0
jmp 0x64f12
movq -0xd0(%rbp), %rsi
movq -0xc8(%rbp), %rdi
callq 0x56530
jmp 0x64f27
jmp 0x64f45
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x564d0
jmp 0x64f43
jmp 0x64f5f
movb $0x1, -0x21(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x564d0
jmp 0x64f54
leaq -0x48(%rbp), %rdi
callq 0x564d0
jmp 0x64f6c
leaq -0x60(%rbp), %rdi
callq 0x564d0
jmp 0x64f6a
jmp 0x64f74
testb $0x1, -0x21(%rbp)
jne 0x64f8d
jmp 0x64f81
leaq -0x48(%rbp), %rdi
callq 0x564d0
jmp 0x64f7f
jmp 0x64f9d
movq -0xc8(%rbp), %rdi
callq 0x564d0
movq -0xc0(%rbp), %rax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0xc8(%rbp), %rdi
callq 0x564d0
jmp 0x64fab
jmp 0x64fad
movq -0x50(%rbp), %rdi
callq 0x6310
movq %rax, %rdi
callq 0x7110
nop