// File: jliesch[P]ofxget/pugixml/pugixml.cpp
// Function: pugi::impl::(anonymous namespace)::convert_buffer(char*&, unsigned long&, pugi::xml_encoding, void const*, unsigned long, bool)
PUGI__FN bool convert_buffer(char_t*& out_buffer, size_t& out_length, xml_encoding encoding, const void* contents, size_t size, bool is_mutable)
	{
		// fast path: no conversion required
		if (encoding == encoding_utf8)
			return get_mutable_buffer(out_buffer, out_length, contents, size, is_mutable);

		// source encoding is utf16
		if (encoding == encoding_utf16_be || encoding == encoding_utf16_le)
		{
			xml_encoding native_encoding = is_little_endian() ? encoding_utf16_le : encoding_utf16_be;

			return (native_encoding == encoding) ?
				convert_buffer_generic(out_buffer, out_length, contents, size, utf16_decoder<opt_false>()) :
				convert_buffer_generic(out_buffer, out_length, contents, size, utf16_decoder<opt_true>());
		}

		// source encoding is utf32
		if (encoding == encoding_utf32_be || encoding == encoding_utf32_le)
		{
			xml_encoding native_encoding = is_little_endian() ? encoding_utf32_le : encoding_utf32_be;

			return (native_encoding == encoding) ?
				convert_buffer_generic(out_buffer, out_length, contents, size, utf32_decoder<opt_false>()) :
				convert_buffer_generic(out_buffer, out_length, contents, size, utf32_decoder<opt_true>());
		}

		// source encoding is latin1
		if (encoding == encoding_latin1)
			return convert_buffer_latin1(out_buffer, out_length, contents, size, is_mutable);

		assert(false && "Invalid encoding"); // unreachable
		return false;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %r9b, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
andb $0x1, %al
movb %al, -0x31(%rbp)
cmpl $0x1, -0x1c(%rbp)
jne 0x501b1
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movb -0x31(%rbp), %al
andb $0x1, %al
movzbl %al, %r8d
callq 0x50e20
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x502d2
cmpl $0x3, -0x1c(%rbp)
je 0x501bd
cmpl $0x2, -0x1c(%rbp)
jne 0x5021e
callq 0x505b0
movb %al, %dl
movl $0x3, %eax
movl $0x2, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x501f9
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x50f10
movb %al, -0x43(%rbp)
jmp 0x50211
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x51000
movb %al, -0x43(%rbp)
movb -0x43(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x502d2
cmpl $0x6, -0x1c(%rbp)
je 0x5022a
cmpl $0x5, -0x1c(%rbp)
jne 0x50288
callq 0x505b0
movb %al, %dl
movl $0x6, %eax
movl $0x5, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x50266
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x510f0
movb %al, -0x44(%rbp)
jmp 0x5027e
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x511e0
movb %al, -0x44(%rbp)
movb -0x44(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x502d2
cmpl $0x9, -0x1c(%rbp)
jne 0x502b3
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movb -0x31(%rbp), %al
andb $0x1, %al
movzbl %al, %r8d
callq 0x512d0
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x502d2
leaq 0x1bfaa(%rip), %rdi     # 0x6c264
leaq 0x1b094(%rip), %rsi     # 0x6b355
movl $0x8e3, %edx            # imm = 0x8E3
leaq 0x1bfb3(%rip), %rcx     # 0x6c280
callq 0x7180
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)