// File: jliesch[P]ofxget/pugixml/pugixml.cpp
// Function: pugi::xml_parse_status pugi::impl::(anonymous namespace)::load_stream_data_noseek<char>(std::basic_istream<char, std::char_traits<char>>&, void**, unsigned long*)
PUGI__FN xml_parse_status load_stream_data_noseek(std::basic_istream<T>& stream, void** out_buffer, size_t* out_size)
	{
		auto_deleter<xml_stream_chunk<T> > chunks(0, xml_stream_chunk<T>::destroy);

		// read file to a chunk list
		size_t total = 0;
		xml_stream_chunk<T>* last = 0;

		while (!stream.eof())
		{
			// allocate new chunk
			xml_stream_chunk<T>* chunk = xml_stream_chunk<T>::create();
			if (!chunk) return status_out_of_memory;

			// append chunk to list
			if (last) last = last->next = chunk;
			else chunks.data = last = chunk;

			// read data to chunk
			stream.read(chunk->data, static_cast<std::streamsize>(sizeof(chunk->data) / sizeof(T)));
			chunk->size = static_cast<size_t>(stream.gcount()) * sizeof(T);

			// read may set failbit | eofbit in case gcount() is less than read length, so check for other I/O errors
			if (stream.bad() || (!stream.eof() && stream.fail())) return status_io_error;

			// guard against huge files (chunk size is small enough to make this overflow check work)
			if (total + chunk->size < total) return status_out_of_memory;
			total += chunk->size;
		}

		size_t max_suffix_size = sizeof(char_t);

		// copy chunk list to a contiguous buffer
		char* buffer = static_cast<char*>(xml_memory::allocate(total + max_suffix_size));
		if (!buffer) return status_out_of_memory;

		char* write = buffer;

		for (xml_stream_chunk<T>* chunk = chunks.data; chunk; chunk = chunk->next)
		{
			assert(write + chunk->size <= buffer + total);
			memcpy(write, chunk->data, chunk->size);
			write += chunk->size;
		}

		assert(write == buffer + total);

		// return buffer
		*out_buffer = buffer;
		*out_size = total;

		return status_ok;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
leaq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq 0x58a(%rip), %rdx       # 0x67ca0
callq 0x67ce0
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x7b30
movb %al, -0x81(%rbp)
jmp 0x67746
movb -0x81(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x67757
jmp 0x678c3
callq 0x67d10
movq %rax, -0x90(%rbp)
jmp 0x67765
movq -0x90(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x677a4
movl $0x3, -0x4(%rbp)
movl $0x1, -0x5c(%rbp)
jmp 0x679ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x67d60
jmp 0x679ff
cmpq $0x0, -0x40(%rbp)
je 0x677bc
movq -0x58(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rax, (%rcx)
movq %rax, -0x40(%rbp)
jmp 0x677c8
movq -0x58(%rbp), %rax
movq %rax, -0x40(%rbp)
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq $0x10, %rsi
movl $0x7fd8, %edx           # imm = 0x7FD8
callq 0x7470
jmp 0x677e0
movq -0x10(%rbp), %rdi
callq 0x7210
movq %rax, -0x98(%rbp)
jmp 0x677f2
movq -0x98(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x76a0
movb %al, -0x99(%rbp)
jmp 0x6781c
movb -0x99(%rbp), %al
testb $0x1, %al
jne 0x67876
jmp 0x67828
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x7b30
movb %al, -0x9a(%rbp)
jmp 0x67843
movb -0x9a(%rbp), %al
testb $0x1, %al
jne 0x67889
jmp 0x6784f
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x79a0
movb %al, -0x9b(%rbp)
jmp 0x6786a
movb -0x9b(%rbp), %al
testb $0x1, %al
jne 0x67876
jmp 0x67889
movl $0x2, -0x4(%rbp)
movl $0x1, -0x5c(%rbp)
jmp 0x679ea
movq -0x38(%rbp), %rax
movq -0x58(%rbp), %rcx
addq 0x8(%rcx), %rax
cmpq -0x38(%rbp), %rax
jae 0x678ae
movl $0x3, -0x4(%rbp)
movl $0x1, -0x5c(%rbp)
jmp 0x679ea
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x6772b
movq $0x1, -0x68(%rbp)
movq 0x2e116(%rip), %rax     # 0x959e8
movq -0x38(%rbp), %rdi
movq -0x68(%rbp), %rcx
addq %rcx, %rdi
callq *%rax
movq %rax, -0xa8(%rbp)
jmp 0x678e8
movq -0xa8(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x6790d
movl $0x3, -0x4(%rbp)
movl $0x1, -0x5c(%rbp)
jmp 0x679ea
movq -0x70(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
je 0x67994
movq -0x78(%rbp), %rax
movq -0x80(%rbp), %rcx
addq 0x8(%rcx), %rax
movq -0x70(%rbp), %rcx
addq -0x38(%rbp), %rcx
cmpq %rcx, %rax
ja 0x6793f
jmp 0x6795e
leaq 0x770a(%rip), %rdi      # 0x6f050
leaq 0x3a08(%rip), %rsi      # 0x6b355
movl $0x1313, %edx           # imm = 0x1313
leaq 0x771d(%rip), %rcx      # 0x6f076
callq 0x7180
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %rsi
addq $0x10, %rsi
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x70b0
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rax
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x80(%rbp)
jmp 0x6791d
movq -0x78(%rbp), %rax
movq -0x70(%rbp), %rcx
addq -0x38(%rbp), %rcx
cmpq %rcx, %rax
jne 0x679a7
jmp 0x679c6
leaq 0x774b(%rip), %rdi      # 0x6f0f9
leaq 0x39a0(%rip), %rsi      # 0x6b355
movl $0x1318, %edx           # imm = 0x1318
leaq 0x76b5(%rip), %rcx      # 0x6f076
callq 0x7180
movq -0x70(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
movl $0x1, -0x5c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x67d60
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x7600
nopl (%rax,%rax)