// File: jliesch[P]ofxget/pugixml/pugixml.cpp
// Function: pugi::impl::(anonymous namespace)::parse_declaration_encoding(unsigned char const*, unsigned long, unsigned char const*&, unsigned long&)
PUGI__FN bool parse_declaration_encoding(const uint8_t* data, size_t size, const uint8_t*& out_encoding, size_t& out_length)
	{
	#define PUGI__SCANCHAR(ch) { if (offset >= size || data[offset] != ch) return false; offset++; }
	#define PUGI__SCANCHARTYPE(ct) { while (offset < size && PUGI__IS_CHARTYPE(data[offset], ct)) offset++; }

		// check if we have a non-empty XML declaration
		if (size < 6 || !((data[0] == '<') & (data[1] == '?') & (data[2] == 'x') & (data[3] == 'm') & (data[4] == 'l') && PUGI__IS_CHARTYPE(data[5], ct_space)))
			return false;

		// scan XML declaration until the encoding field
		for (size_t i = 6; i + 1 < size; ++i)
		{
			// declaration can not contain ? in quoted values
			if (data[i] == '?')
				return false;

			if (data[i] == 'e' && data[i + 1] == 'n')
			{
				size_t offset = i;

				// encoding follows the version field which can't contain 'en' so this has to be the encoding if XML is well formed
				PUGI__SCANCHAR('e'); PUGI__SCANCHAR('n'); PUGI__SCANCHAR('c'); PUGI__SCANCHAR('o');
				PUGI__SCANCHAR('d'); PUGI__SCANCHAR('i'); PUGI__SCANCHAR('n'); PUGI__SCANCHAR('g');

				// S? = S?
				PUGI__SCANCHARTYPE(ct_space);
				PUGI__SCANCHAR('=');
				PUGI__SCANCHARTYPE(ct_space);

				// the only two valid delimiters are ' and "
				uint8_t delimiter = (offset < size && data[offset] == '"') ? '"' : '\'';

				PUGI__SCANCHAR(delimiter);

				size_t start = offset;

				out_encoding = data + offset;

				PUGI__SCANCHARTYPE(ct_symbol);

				out_length = offset - start;

				PUGI__SCANCHAR(delimiter);

				return true;
			}
		}

		return false;

	#undef PUGI__SCANCHAR
	#undef PUGI__SCANCHARTYPE
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
cmpq $0x6, -0x18(%rbp)
jb 0x50a2b
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x3c, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movq -0x10(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
cmpl $0x3f, %ecx
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0x2(%rcx), %ecx
cmpl $0x78, %ecx
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0x3(%rcx), %ecx
cmpl $0x6d, %ecx
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0x4(%rcx), %ecx
cmpl $0x6c, %ecx
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x50a2b
movq -0x10(%rbp), %rax
movzbl 0x5(%rax), %eax
movl %eax, %ecx
leaq 0x1a6b1(%rip), %rax     # 0x6b0d0
movzbl (%rax,%rcx), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0x50a34
movb $0x0, -0x1(%rbp)
jmp 0x50e14
movq $0x6, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
cmpq -0x18(%rbp), %rax
jae 0x50e10
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x3f, %eax
jne 0x50a68
movb $0x0, -0x1(%rbp)
jmp 0x50e14
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x65, %eax
jne 0x50dfd
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl 0x1(%rax,%rcx), %eax
cmpl $0x6e, %eax
jne 0x50dfd
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x50ab6
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x65, %eax
je 0x50abf
movb $0x0, -0x1(%rbp)
jmp 0x50e14
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x50ae6
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x6e, %eax
je 0x50aef
movb $0x0, -0x1(%rbp)
jmp 0x50e14
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x50b16
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x63, %eax
je 0x50b1f
movb $0x0, -0x1(%rbp)
jmp 0x50e14
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x50b46
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x6f, %eax
je 0x50b4f
movb $0x0, -0x1(%rbp)
jmp 0x50e14
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x50b76
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x64, %eax
je 0x50b7f
movb $0x0, -0x1(%rbp)
jmp 0x50e14
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x50ba6
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x69, %eax
je 0x50baf
movb $0x0, -0x1(%rbp)
jmp 0x50e14
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x50bd6
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x6e, %eax
je 0x50bdf
movb $0x0, -0x1(%rbp)
jmp 0x50e14
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x50c06
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x67, %eax
je 0x50c0f
movb $0x0, -0x1(%rbp)
jmp 0x50e14
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq -0x18(%rbp), %rcx
movb %al, -0x49(%rbp)
jae 0x50c4f
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x1a491(%rip), %rax     # 0x6b0d0
movzbl (%rax,%rcx), %eax
andl $0x8, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x50c58
jmp 0x50c66
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x50c1b
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x50c81
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x3d, %eax
je 0x50c8a
movb $0x0, -0x1(%rbp)
jmp 0x50e14
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq -0x18(%rbp), %rcx
movb %al, -0x4a(%rbp)
jae 0x50cca
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x1a416(%rip), %rax     # 0x6b0d0
movzbl (%rax,%rcx), %eax
andl $0x8, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x4a(%rbp)
movb -0x4a(%rbp), %al
testb $0x1, %al
jne 0x50cd3
jmp 0x50ce1
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x50c96
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq -0x18(%rbp), %rcx
movb %al, -0x4b(%rbp)
jae 0x50d05
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x22, %eax
sete %al
movb %al, -0x4b(%rbp)
movb -0x4b(%rbp), %cl
movb $0x22, %al
movb $0x27, %dl
movb %dl, -0x4d(%rbp)
testb $0x1, %cl
movb %al, -0x4c(%rbp)
jne 0x50d1d
movb -0x4d(%rbp), %al
movb %al, -0x4c(%rbp)
movb -0x4c(%rbp), %al
movb %al, -0x39(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x50d41
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movzbl -0x39(%rbp), %ecx
cmpl %ecx, %eax
je 0x50d4a
movb $0x0, -0x1(%rbp)
jmp 0x50e14
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rcx
addq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq -0x18(%rbp), %rcx
movb %al, -0x4e(%rbp)
jae 0x50da1
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x1a33f(%rip), %rax     # 0x6b0d0
movzbl (%rax,%rcx), %eax
andl $0x40, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x4e(%rbp)
movb -0x4e(%rbp), %al
testb $0x1, %al
jne 0x50daa
jmp 0x50db8
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x50d6d
movq -0x38(%rbp), %rcx
subq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x50de5
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movzbl -0x39(%rbp), %ecx
cmpl %ecx, %eax
je 0x50deb
movb $0x0, -0x1(%rbp)
jmp 0x50e14
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movb $0x1, -0x1(%rbp)
jmp 0x50e14
jmp 0x50dff
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x50a3c
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
popq %rbp
retq
nopl (%rax,%rax)