// File: /workspace/github_cpp_makefile_star2_O2/jliesch[P]ofxget/pugixml/pugixml.cpp
// Function: unsigned int pugi::impl::(anonymous namespace)::string_to_integer<unsigned int>(char const*, unsigned int, unsigned int)
PUGI__FN PUGI__UNSIGNED_OVERFLOW U string_to_integer(const char_t* value, U minv, U maxv)
	{
		U result = 0;
		const char_t* s = value;

		while (PUGI__IS_CHARTYPE(*s, ct_space))
			s++;

		bool negative = (*s == '-');

		s += (*s == '+' || *s == '-');

		bool overflow = false;

		if (s[0] == '0' && (s[1] | ' ') == 'x')
		{
			s += 2;

			// since overflow detection relies on length of the sequence skip leading zeros
			while (*s == '0')
				s++;

			const char_t* start = s;

			for (;;)
			{
				if (static_cast<unsigned>(*s - '0') < 10)
					result = result * 16 + (*s - '0');
				else if (static_cast<unsigned>((*s | ' ') - 'a') < 6)
					result = result * 16 + ((*s | ' ') - 'a' + 10);
				else
					break;

				s++;
			}

			size_t digits = static_cast<size_t>(s - start);

			overflow = digits > sizeof(U) * 2;
		}
		else
		{
			// since overflow detection relies on length of the sequence skip leading zeros
			while (*s == '0')
				s++;

			const char_t* start = s;

			for (;;)
			{
				if (static_cast<unsigned>(*s - '0') < 10)
					result = result * 10 + (*s - '0');
				else
					break;

				s++;
			}

			size_t digits = static_cast<size_t>(s - start);

			PUGI__STATIC_ASSERT(sizeof(U) == 8 || sizeof(U) == 4 || sizeof(U) == 2);

			const size_t max_digits10 = sizeof(U) == 8 ? 20 : sizeof(U) == 4 ? 10 : 5;
			const char_t max_lead = sizeof(U) == 8 ? '1' : sizeof(U) == 4 ? '4' : '6';
			const size_t high_bit = sizeof(U) * 8 - 1;

			overflow = digits >= max_digits10 && !(digits == max_digits10 && (*start < max_lead || (*start == max_lead && result >> high_bit)));
		}

		if (negative)
		{
			// Workaround for crayc++ CC-3059: Expected no overflow in routine.
		#ifdef _CRAYC
			return (overflow || result > ~minv + 1) ? minv : ~result + 1;
		#else
			return (overflow || result > 0 - minv) ? minv : 0 - result;
		#endif
		}
		else
			return (overflow || result > maxv) ? maxv : result;
	}

// Assembly:
decq %rdi
leaq 0x94c6(%rip), %rcx      # 0x2bcc0
movzbl 0x1(%rdi), %eax
incq %rdi
testb $0x8, (%rax,%rcx)
jne 0x227fa
leal -0x2b(%rax), %r8d
xorl %ecx, %ecx
testb $-0x3, %r8b
sete %cl
leaq (%rdi,%rcx), %r8
cmpb $0x30, (%rdi,%rcx)
jne 0x2287d
movb 0x1(%rdi,%rcx), %r9b
andb $-0x21, %r9b
cmpb $0x58, %r9b
jne 0x2287d
addq %rcx, %rdi
addq $0x2, %rdi
movb (%rdi), %r9b
incq %rdi
cmpb $0x30, %r9b
je 0x22834
xorl %r8d, %r8d
xorl %ecx, %ecx
movsbl %r9b, %r9d
leal -0x30(%r9), %r10d
cmpl $0x9, %r10d
ja 0x2285b
shll $0x4, %ecx
orl %r10d, %ecx
jmp 0x22872
orl $0x20, %r9d
leal -0x61(%r9), %r10d
cmpl $0x5, %r10d
ja 0x228c5
shll $0x4, %ecx
addl %r9d, %ecx
addl $-0x57, %ecx
movb (%rdi), %r9b
incq %r8
incq %rdi
jmp 0x22845
movb (%r8), %r9b
incq %r8
cmpb $0x30, %r9b
je 0x2287d
xorl %edi, %edi
movl %r9d, %r11d
xorl %ecx, %ecx
movsbl %r11b, %r10d
addl $-0x30, %r10d
cmpl $0x9, %r10d
ja 0x228b0
imull $0xa, %ecx, %ecx
addl %ecx, %r10d
movb (%r8,%rdi), %r11b
incq %rdi
movl %r10d, %ecx
jmp 0x22890
cmpq $0xa, %rdi
jb 0x228c1
movb $0x1, %dil
jne 0x228dc
cmpb $0x34, %r9b
jge 0x228cf
xorl %edi, %edi
jmp 0x228dc
cmpq $0x9, %r8
setae %dil
jmp 0x228dc
setne %r8b
testl %ecx, %ecx
setns %dil
orb %r8b, %dil
cmpb $0x2d, %al
jne 0x228f4
movl %esi, %edx
negl %edx
movl %ecx, %eax
negl %eax
cmpl %edx, %ecx
cmoval %esi, %eax
testb %dil, %dil
cmovnel %esi, %eax
retq
cmpl %edx, %ecx
cmovael %edx, %ecx
testb %dil, %dil
cmovnel %edx, %ecx
movl %ecx, %eax
retq