// File: jliesch[P]ofxget/pugixml/pugixml.cpp
// Function: bool pugi::impl::(anonymous namespace)::strcpy_insitu<char*, unsigned long>(char*&, unsigned long&, unsigned long, char const*, unsigned long)
PUGI__FN bool strcpy_insitu(String& dest, Header& header, uintptr_t header_mask, const char_t* source, size_t source_length)
	{
		if (source_length == 0)
		{
			// empty string and null pointer are equivalent, so just deallocate old memory
			xml_allocator* alloc = PUGI__GETPAGE_IMPL(header)->allocator;

			if (header & header_mask) alloc->deallocate_string(dest);

			// mark the string as not allocated
			dest = 0;
			header &= ~header_mask;

			return true;
		}
		else if (dest && strcpy_insitu_allow(source_length, header, header_mask, dest))
		{
			// we can reuse old buffer, so just copy the new data (including zero terminator)
			memcpy(dest, source, source_length * sizeof(char_t));
			dest[source_length] = 0;

			return true;
		}
		else
		{
			xml_allocator* alloc = PUGI__GETPAGE_IMPL(header)->allocator;

			if (!alloc->reserve()) return false;

			// allocate new buffer
			char_t* buf = alloc->allocate_string(source_length + 1);
			if (!buf) return false;

			// copy the string (including zero terminator)
			memcpy(buf, source, source_length * sizeof(char_t));
			buf[source_length] = 0;

			// deallocate old buffer (*after* the above to protect against overlapping memory and/or allocation failures)
			if (header & header_mask) alloc->deallocate_string(dest);

			// the string is now allocated, so set the flag
			dest = buf;
			header |= header_mask;

			return true;
		}
	}

// 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 %r8, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x417d6
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movq (%rcx), %rdx
shrq $0x8, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
movq (%rax,%rcx), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
andq -0x20(%rbp), %rax
cmpq $0x0, %rax
je 0x417b0
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x4fc30
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
movq -0x20(%rbp), %rcx
xorq $-0x1, %rcx
movq -0x18(%rbp), %rax
andq (%rax), %rcx
movq %rcx, (%rax)
movb $0x1, -0x1(%rbp)
jmp 0x418e1
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x4182e
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rcx
callq 0x67160
testb $0x1, %al
jne 0x417fe
jmp 0x4182e
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
shlq $0x0, %rdx
callq 0x70b0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movb $0x1, -0x1(%rbp)
jmp 0x418e1
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movq (%rcx), %rdx
shrq $0x8, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
movq (%rax,%rcx), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x42d80
testb $0x1, %al
jne 0x41860
movb $0x0, -0x1(%rbp)
jmp 0x418e1
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x1, %rsi
callq 0x67220
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x41882
movb $0x0, -0x1(%rbp)
jmp 0x418e1
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
shlq $0x0, %rdx
callq 0x70b0
movq -0x48(%rbp), %rax
movq -0x30(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x18(%rbp), %rax
movq (%rax), %rax
andq -0x20(%rbp), %rax
cmpq $0x0, %rax
je 0x418c4
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x4fc30
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
orq (%rax), %rcx
movq %rcx, (%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)