// File: smallmuou[P]tinyhtml/tinyxmlparser.cpp
// Function: TiXmlDocument::Parse(char const*, TiXmlParsingData*, TiXmlEncoding)
const char* TiXmlDocument::Parse( const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding )
{
	ClearError();

	// Parse away, at the document level. Since a document
	// contains nothing but other tags, most of what happens
	// here is skipping white space.
	if ( !p || !*p )
	{
		SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
		return 0;
	}

	// Note that, for a document, this needs to come
	// before the while space skip, so that parsing
	// starts from the pointer we are given.
	location.Clear();
	if ( prevData )
	{
		location.row = prevData->cursor.row;
		location.col = prevData->cursor.col;
	}
	else
	{
		location.row = 0;
		location.col = 0;
	}
	TiXmlParsingData data( p, TabSize(), location.row, location.col );
	location = data.Cursor();

	if ( encoding == TIXML_ENCODING_UNKNOWN )
	{
		// Check for the Microsoft UTF-8 lead bytes.
		const unsigned char* pU = (const unsigned char*)p;
		if (	*(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0
			 && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1
			 && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 )
		{
			encoding = TIXML_ENCODING_UTF8;
			useMicrosoftBOM = true;
		}
	}

    p = SkipWhiteSpace( p, encoding );
	if ( !p )
	{
		SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
		return 0;
	}

	while ( p && *p )
	{
		TiXmlNode* node = Identify( p, encoding );
		if ( node )
		{
			p = node->Parse( p, &data, encoding );
			LinkEndChild( node );
		}
		else
		{
			break;
		}

		// Did we get encoding info?
		if (    encoding == TIXML_ENCODING_UNKNOWN
			 && node->ToDeclaration() )
		{
			TiXmlDeclaration* dec = node->ToDeclaration();
			const char* enc = dec->Encoding();
			assert( enc );

			if ( *enc == 0 )
				encoding = TIXML_ENCODING_UTF8;
			else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) )
				encoding = TIXML_ENCODING_UTF8;
			else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) )
				encoding = TIXML_ENCODING_UTF8;	// incorrect, but be nice
			else 
				encoding = TIXML_ENCODING_LEGACY;
		}

		p = SkipWhiteSpace( p, encoding );
	}

	// Was this empty?
	if ( !firstChild ) {
		SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding );
		return 0;
	}

	// All is well.
	return p;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x68(%rbp)
callq 0x7b40
cmpq $0x0, -0x18(%rbp)
je 0x9967
movq -0x18(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x998c
movq -0x68(%rbp), %rdi
movl $0xc, %esi
xorl %eax, %eax
movl %eax, %ecx
xorl %r8d, %r8d
movq %rcx, %rdx
callq 0x9c50
movq $0x0, -0x8(%rbp)
jmp 0x9c3a
movq -0x68(%rbp), %rdi
addq $0x8, %rdi
callq 0x7c50
cmpq $0x0, -0x20(%rbp)
je 0x99b9
movq -0x68(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rcx
movl 0x4(%rcx), %ecx
movl %ecx, 0xc(%rax)
jmp 0x99cb
movq -0x68(%rbp), %rax
movl $0x0, 0x8(%rax)
movl $0x0, 0xc(%rax)
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rax
movq %rax, -0x70(%rbp)
callq 0xb8b0
movq -0x70(%rbp), %rsi
movl %eax, %edx
movq -0x68(%rbp), %rax
movl 0x8(%rax), %ecx
movl 0xc(%rax), %r8d
leaq -0x40(%rbp), %rdi
callq 0xb8d0
leaq -0x40(%rbp), %rdi
callq 0xb950
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, 0x8(%rax)
cmpl $0x0, -0x24(%rbp)
jne 0x9a75
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpb $0x0, (%rax)
je 0x9a73
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xef, %eax
jne 0x9a73
movq -0x48(%rbp), %rax
cmpb $0x0, 0x1(%rax)
je 0x9a73
movq -0x48(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0xbb, %eax
jne 0x9a73
movq -0x48(%rbp), %rax
cmpb $0x0, 0x2(%rax)
je 0x9a73
movq -0x48(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl $0xbf, %eax
jne 0x9a73
movq -0x68(%rbp), %rax
movl $0x1, -0x24(%rbp)
movb $0x1, 0x6c(%rax)
jmp 0x9a75
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x8e00
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x9ab1
movq -0x68(%rbp), %rdi
movl $0xc, %esi
xorl %eax, %eax
movl %eax, %ecx
xorl %r8d, %r8d
movq %rcx, %rdx
callq 0x9c50
movq $0x0, -0x8(%rbp)
jmp 0x9c3a
jmp 0x9ab3
xorl %eax, %eax
cmpq $0x0, -0x18(%rbp)
movb %al, -0x71(%rbp)
je 0x9acc
movq -0x18(%rbp), %rax
cmpb $0x0, (%rax)
setne %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x9ad8
jmp 0x9c04
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x9d30
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x9b1b
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %ecx
movq (%rdi), %rax
leaq -0x40(%rbp), %rdx
callq *0x18(%rax)
movq -0x68(%rbp), %rdi
movq %rax, -0x18(%rbp)
movq -0x50(%rbp), %rsi
callq 0x3890
jmp 0x9b20
jmp 0x9c04
cmpl $0x0, -0x24(%rbp)
jne 0x9bef
movq -0x50(%rbp), %rdi
movq (%rdi), %rax
callq *0x78(%rax)
cmpq $0x0, %rax
je 0x9bef
movq -0x50(%rbp), %rdi
movq (%rdi), %rax
callq *0x78(%rax)
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0xb960
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x9b62
jmp 0x9b81
leaq 0x508c(%rip), %rdi      # 0xebf5
leaq 0x4ee3(%rip), %rsi      # 0xea53
movl $0x305, %edx            # imm = 0x305
leaq 0x507d(%rip), %rcx      # 0xebf9
callq 0x30e0
movq -0x60(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x9b96
movl $0x1, -0x24(%rbp)
jmp 0x9bed
movq -0x60(%rbp), %rdi
leaq 0x50b2(%rip), %rsi      # 0xec53
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x9540
testb $0x1, %al
jne 0x9bb3
jmp 0x9bbc
movl $0x1, -0x24(%rbp)
jmp 0x9beb
movq -0x60(%rbp), %rdi
leaq 0x5092(%rip), %rsi      # 0xec59
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x9540
testb $0x1, %al
jne 0x9bd9
jmp 0x9be2
movl $0x1, -0x24(%rbp)
jmp 0x9be9
movl $0x2, -0x24(%rbp)
jmp 0x9beb
jmp 0x9bed
jmp 0x9bef
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x8e00
movq %rax, -0x18(%rbp)
jmp 0x9ab3
movq -0x68(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x9c32
movq -0x68(%rbp), %rdi
movl -0x24(%rbp), %r8d
movl $0xc, %esi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x9c50
movq $0x0, -0x8(%rbp)
jmp 0x9c3a
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)