/* Generated by re2c */
// re2c $INPUT -o $OUTPUT -ci --loop-switch
#include <stdint.h>
#include <limits.h>
#include <assert.h>

static const uint64_t ERROR = ~0lu;
enum YYCONDTYPE {
	yycinit = 0,
	yycbin = 10,
	yycdec = 14,
	yychex = 18,
	yycoct = 24
};


template<int BASE> static void adddgt(uint64_t &u, unsigned int d)
{
    u = u * BASE + d;
    if (u > UINT32_MAX) u = ERROR;
}

static uint64_t parse_u32(const char *s)
{
    const char *YYMARKER;
    int c = yycinit;
    uint64_t u = 0;

loop:
    
{
	char yych;
	unsigned int yystate = c;
	for (;;) {
		switch (yystate) {
			case 0:
				yych = *s;
				++s;
				switch (yych) {
					case '0':
						yystate = 2;
						continue;
					case '1':
					case '2':
					case '3':
					case '4':
					case '5':
					case '6':
					case '7':
					case '8':
					case '9':
						yystate = 4;
						continue;
					default:
						yystate = 1;
						continue;
				}
			case 1: { return ERROR; }
			case 2:
				YYMARKER = s;
				yych = *s;
				switch (yych) {
					case 'B':
					case 'b':
						++s;
						yystate = 5;
						continue;
					case 'X':
					case 'x':
						++s;
						yystate = 7;
						continue;
					default:
						yystate = 3;
						continue;
				}
			case 3:
				c = yycoct;
				yystate = yycoct;
				continue;
			case 4:
				s -= 1;
				c = yycdec;
				yystate = yycdec;
				continue;
			case 5:
				yych = *s;
				switch (yych) {
					case '0':
					case '1':
						++s;
						yystate = 8;
						continue;
					default:
						yystate = 6;
						continue;
				}
			case 6:
				s = YYMARKER;
				yystate = 3;
				continue;
			case 7:
				yych = *s;
				switch (yych) {
					case '0':
					case '1':
					case '2':
					case '3':
					case '4':
					case '5':
					case '6':
					case '7':
					case '8':
					case '9':
					case 'A':
					case 'B':
					case 'C':
					case 'D':
					case 'E':
					case 'F':
					case 'a':
					case 'b':
					case 'c':
					case 'd':
					case 'e':
					case 'f':
						++s;
						yystate = 9;
						continue;
					default:
						yystate = 6;
						continue;
				}
			case 8:
				s -= 1;
				c = yycbin;
				yystate = yycbin;
				continue;
			case 9:
				s -= 1;
				c = yychex;
				yystate = yychex;
				continue;
			case 10:
				yych = *s;
				++s;
				switch (yych) {
					case 0x00:
						yystate = 11;
						continue;
					case '0':
					case '1':
						yystate = 13;
						continue;
					default:
						yystate = 12;
						continue;
				}
			case 11: { return u; }
			case 12: { return ERROR; }
			case 13: { adddgt<2> (u, s[-1] - '0');      goto loop; }
			case 14:
				yych = *s;
				++s;
				switch (yych) {
					case 0x00:
						yystate = 15;
						continue;
					case '0':
					case '1':
					case '2':
					case '3':
					case '4':
					case '5':
					case '6':
					case '7':
					case '8':
					case '9':
						yystate = 17;
						continue;
					default:
						yystate = 16;
						continue;
				}
			case 15: { return u; }
			case 16: { return ERROR; }
			case 17: { adddgt<10>(u, s[-1] - '0');      goto loop; }
			case 18:
				yych = *s;
				++s;
				switch (yych) {
					case 0x00:
						yystate = 19;
						continue;
					case '0':
					case '1':
					case '2':
					case '3':
					case '4':
					case '5':
					case '6':
					case '7':
					case '8':
					case '9':
						yystate = 21;
						continue;
					case 'A':
					case 'B':
					case 'C':
					case 'D':
					case 'E':
					case 'F':
						yystate = 22;
						continue;
					case 'a':
					case 'b':
					case 'c':
					case 'd':
					case 'e':
					case 'f':
						yystate = 23;
						continue;
					default:
						yystate = 20;
						continue;
				}
			case 19: { return u; }
			case 20: { return ERROR; }
			case 21: { adddgt<16>(u, s[-1] - '0');      goto loop; }
			case 22: { adddgt<16>(u, s[-1] - 'A' + 10); goto loop; }
			case 23: { adddgt<16>(u, s[-1] - 'a' + 10); goto loop; }
			case 24:
				yych = *s;
				++s;
				switch (yych) {
					case 0x00:
						yystate = 25;
						continue;
					case '0':
					case '1':
					case '2':
					case '3':
					case '4':
					case '5':
					case '6':
					case '7':
						yystate = 27;
						continue;
					default:
						yystate = 26;
						continue;
				}
			case 25: { return u; }
			case 26: { return ERROR; }
			case 27: { adddgt<8> (u, s[-1] - '0');      goto loop; }
		}
	}
}

}

int main()
{
    assert(parse_u32("1234567890") == 1234567890);
    assert(parse_u32("0b1101") == 13);
    assert(parse_u32("0x7Fe") == 2046);
    assert(parse_u32("0644") == 420);
    assert(parse_u32("9999999999") == ERROR);
    assert(parse_u32("") == ERROR);
    return 0;
}
