// File: jliesch[P]ofxget/pugixml/pugixml.cpp
// Function: pugi::impl::(anonymous namespace)::xpath_allocator::reallocate(void*, unsigned long, unsigned long)
void* reallocate(void* ptr, size_t old_size, size_t new_size)
		{
			// round size up to block alignment boundary
			old_size = (old_size + xpath_memory_block_alignment - 1) & ~(xpath_memory_block_alignment - 1);
			new_size = (new_size + xpath_memory_block_alignment - 1) & ~(xpath_memory_block_alignment - 1);

			// we can only reallocate the last object
			assert(ptr == 0 || static_cast<char*>(ptr) + old_size == &_root->data[0] + _root_size);

			// try to reallocate the object inplace
			if (ptr && _root_size - old_size + new_size <= _root->capacity)
			{
				_root_size = _root_size - old_size + new_size;
				return ptr;
			}

			// allocate a new block
			void* result = allocate(new_size);
			if (!result) return 0;

			// we have a new block
			if (ptr)
			{
				// copy old data (we only support growing)
				assert(new_size >= old_size);
				memcpy(result, ptr, old_size);

				// free the previous page if it had no other objects
				assert(_root->data == result);
				assert(_root->next);

				if (_root->next->data == ptr)
				{
					// deallocate the whole page, unless it was the first one
					xpath_memory_block* next = _root->next->next;

					if (next)
					{
						xml_memory::deallocate(_root->next);
						_root->next = next;
					}
				}
			}

			return result;
		}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
addq $0x8, %rax
subq $0x1, %rax
andq $-0x8, %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
addq $0x8, %rax
subq $0x1, %rax
andq $-0x8, %rax
movq %rax, -0x28(%rbp)
movb $0x1, %al
cmpq $0x0, -0x18(%rbp)
movb %al, -0x39(%rbp)
je 0x61024
movq -0x48(%rbp), %rdx
movq -0x18(%rbp), %rax
addq -0x20(%rbp), %rax
movq (%rdx), %rcx
addq $0x10, %rcx
addq 0x8(%rdx), %rcx
cmpq %rcx, %rax
sete %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x6102d
jmp 0x6102f
jmp 0x6104e
leaq 0xce94(%rip), %rdi      # 0x6deca
leaq 0xa318(%rip), %rsi      # 0x6b355
movl $0x1d7a, %edx           # imm = 0x1D7A
leaq 0xced0(%rip), %rcx      # 0x6df19
callq 0x7180
cmpq $0x0, -0x18(%rbp)
je 0x6108f
movq -0x48(%rbp), %rcx
movq 0x8(%rcx), %rax
subq -0x20(%rbp), %rax
addq -0x28(%rbp), %rax
movq (%rcx), %rcx
cmpq 0x8(%rcx), %rax
ja 0x6108f
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rcx
subq -0x20(%rbp), %rcx
addq -0x28(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x611b4
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x5cde0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x610b4
movq $0x0, -0x8(%rbp)
jmp 0x611b4
cmpq $0x0, -0x18(%rbp)
je 0x611ac
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x610cb
jmp 0x610ea
leaq 0xcea4(%rip), %rdi      # 0x6df76
leaq 0xa27c(%rip), %rsi      # 0x6b355
movl $0x1d8b, %edx           # imm = 0x1D8B
leaq 0xce34(%rip), %rcx      # 0x6df19
callq 0x7180
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x70b0
movq -0x48(%rbp), %rax
movq (%rax), %rax
addq $0x10, %rax
cmpq -0x30(%rbp), %rax
jne 0x6110e
jmp 0x6112d
leaq 0xce76(%rip), %rdi      # 0x6df8b
leaq 0xa239(%rip), %rsi      # 0x6b355
movl $0x1d8f, %edx           # imm = 0x1D8F
leaq 0xcdf1(%rip), %rcx      # 0x6df19
callq 0x7180
movq -0x48(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, (%rax)
je 0x6113c
jmp 0x6115b
leaq 0xce5e(%rip), %rdi      # 0x6dfa1
leaq 0xa20b(%rip), %rsi      # 0x6b355
movl $0x1d90, %edx           # imm = 0x1D90
leaq 0xcdc3(%rip), %rcx      # 0x6df19
callq 0x7180
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
addq $0x10, %rax
cmpq -0x18(%rbp), %rax
jne 0x611aa
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x611a8
movq -0x48(%rbp), %rcx
movq 0x3484e(%rip), %rax     # 0x959e0
movq (%rcx), %rcx
movq (%rcx), %rdi
callq *%rax
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax), %rax
movq %rcx, (%rax)
jmp 0x611aa
jmp 0x611ac
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nop