// File: /workspace/github_cpp_makefile_star2_O1/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:
xorl %ecx, %ecx
leaq 0xa84a(%rip), %r8       # 0x32c80
movzbl (%rdi,%rcx), %eax
incq %rcx
testb $0x8, (%rax,%r8)
jne 0x28436
leal -0x2b(%rax), %r9d
xorl %r8d, %r8d
testb $-0x3, %r9b
sete %r8b
leaq (%rdi,%r8), %r9
cmpb $0x30, -0x1(%rcx,%r9)
jne 0x284b4
movb (%rcx,%r9), %r10b
andb $-0x21, %r10b
cmpb $0x58, %r10b
jne 0x284b4
addq %rcx, %r9
cmpb $0x30, 0x1(%r9)
leaq 0x1(%r9), %r9
je 0x28470
xorl %edi, %edi
xorl %ecx, %ecx
movsbl (%r9), %r8d
leal -0x30(%r8), %r10d
cmpl $0x9, %r10d
ja 0x28495
shll $0x4, %ecx
orl %r10d, %ecx
jmp 0x284ac
orl $0x20, %r8d
leal -0x61(%r8), %r10d
cmpl $0x5, %r10d
ja 0x28521
shll $0x4, %ecx
addl %r8d, %ecx
addl $-0x57, %ecx
incq %r9
incq %rdi
jmp 0x2847f
addq %rcx, %r8
movb -0x1(%rdi,%r8), %r9b
incq %r8
cmpb $0x30, %r9b
je 0x284b7
leaq (%rdi,%r8), %r10
addq $-0x2, %r10
movsbl (%r10), %r11d
addl $-0x30, %r11d
xorl %ecx, %ecx
cmpl $0x9, %r11d
ja 0x284f8
xorl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
leal (%r11,%rcx,2), %ecx
movsbl 0x1(%r10), %r11d
incq %r10
addl $-0x30, %r11d
cmpl $0xa, %r11d
jb 0x284df
subq %rdi, %r10
movq %r10, %rdi
subq %r8, %rdi
addq $0x2, %rdi
cmpq $0xa, %rdi
jb 0x2851d
addq $-0x8, %r10
movb $0x1, %dil
cmpq %r8, %r10
jne 0x28538
cmpb $0x34, %r9b
jge 0x2852b
xorl %edi, %edi
jmp 0x28538
cmpq $0x9, %rdi
setae %dil
jmp 0x28538
setne %r8b
testl %ecx, %ecx
setns %dil
orb %r8b, %dil
cmpb $0x2d, %al
jne 0x28550
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