// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
testq %r8, %r8
je 0x183a4
movq %r8, %r12
movq %rcx, %r13
movq (%r15), %rdi
testq %rdi, %rdi
setne %al
movq (%rbx), %rcx
testb $0x40, %cl
sete %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x182ba
callq 0x18462
movq (%rbx), %rcx
testq %r14, %rcx
je 0x183d5
movq %rax, %rdx
subq %r12, %rdx
jb 0x182ba
cmpq $0x20, %rax
jb 0x183de
shrq %rax
cmpq %rax, %rdx
jb 0x183de
movq %r13, 0x10(%rsp)
movq %r15, 0x18(%rsp)
shrq $0x8, %rcx
movq %rbx, %rax
subq %rcx, %rax
movq (%rax), %rdi
leaq 0xc(%r12), %r15
movq %r15, %rbp
andq $-0x8, %rbp
leaq 0x20(%rsp), %rdx
movq %rdi, 0x8(%rsp)
movq %rbp, %rsi
callq 0x19db4
testq %rax, %rax
je 0x183d1
movq %rax, %r13
movq 0x20(%rsp), %rax
movq %r13, %rcx
subq %rax, %rcx
testb $0x7, %cl
jne 0x18405
addq $-0x28, %rcx
cmpq $0x80000, %rcx          # imm = 0x80000
jae 0x18424
movq %r13, %rsi
movl %ecx, %edx
shrl $0x3, %edx
movw %dx, (%r13)
cmpq $0x80000, %r15          # imm = 0x80000
jb 0x18349
testq %rcx, %rcx
jne 0x18443
cmpq %rbp, 0x18(%rax)
jne 0x18443
movl %r15d, %eax
shrl $0x3, %eax
xorl %ecx, %ecx
cmpq $0x80000, %r15          # imm = 0x80000
cmovbl %eax, %ecx
movw %cx, 0x2(%rsi)
addq $0x4, %r13
movq %r13, %rdi
movq %rsi, %r15
movq 0x10(%rsp), %rsi
movq %r12, %rdx
callq 0x6080
movb $0x0, 0x4(%r15,%r12)
movq (%rbx), %rax
testq %r14, %rax
movq 0x18(%rsp), %r15
je 0x18399
movq (%r15), %rsi
movq 0x8(%rsp), %rdi
callq 0x22c1c
movq (%rbx), %rax
movq %r13, (%r15)
orq %r14, %rax
movq %rax, (%rbx)
jmp 0x183f4
movq (%rbx), %rax
testq %r14, %rax
je 0x183c2
shrq $0x8, %rax
negq %rax
movq (%rbx,%rax), %rdi
movq (%r15), %rsi
callq 0x22c1c
movq (%rbx), %rax
andq $0x0, (%r15)
notq %r14
andq %rax, %r14
movq %r14, (%rbx)
jmp 0x183f4
xorl %eax, %eax
jmp 0x183f6
cmpq %r12, %rax
jb 0x182ba
movq (%r15), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x6080
movq (%r15), %rax
movb $0x0, (%rax,%r12)
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16f71(%rip), %rdi     # 0x2f37d
leaq 0x13b22(%rip), %rsi     # 0x2bf35
leaq 0x16f91(%rip), %rcx     # 0x2f3ab
movl $0x291, %edx            # imm = 0x291
callq 0x6100
leaq 0x16fd2(%rip), %rdi     # 0x2f3fd
leaq 0x13b03(%rip), %rsi     # 0x2bf35
leaq 0x16f72(%rip), %rcx     # 0x2f3ab
movl $0x292, %edx            # imm = 0x292
callq 0x6100
leaq 0x16ffd(%rip), %rdi     # 0x2f447
leaq 0x13ae4(%rip), %rsi     # 0x2bf35
leaq 0x16f53(%rip), %rcx     # 0x2f3ab
movl $0x297, %edx            # imm = 0x297
callq 0x6100