/* Generated by Nimrod Compiler v0.9.5 */
/*   (c) 2014 Andreas Rumpf */
/* The generated code is subject to the original license. */
/* Compiled for: Linux, i386, gcc */
/* Command for C compiler:
   gcc -c  -w -O3 -fno-strict-aliasing  -I/build/nimrod/src/nimrod/lib -o compiler/nimcache/stdlib_parseutils.o compiler/nimcache/stdlib_parseutils.c */
#define NIM_INTBITS 32
#include "nimbase.h"
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct EOverflow EOverflow;
typedef struct earithmetic2441 earithmetic2441;
typedef struct esynch2429 esynch2429;
typedef struct E_Base E_Base;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct tcell41090 tcell41090;
typedef struct tcellseq41106 tcellseq41106;
typedef struct tgcheap43016 tgcheap43016;
typedef struct tcellset41102 tcellset41102;
typedef struct tpagedesc41098 tpagedesc41098;
typedef struct tmemregion23410 tmemregion23410;
typedef struct tsmallchunk22638 tsmallchunk22638;
typedef struct tllchunk23404 tllchunk23404;
typedef struct tbigchunk22640 tbigchunk22640;
typedef struct tintset22615 tintset22615;
typedef struct ttrunk22611 ttrunk22611;
typedef struct tavlnode23408 tavlnode23408;
typedef struct tgcstat43014 tgcstat43014;
typedef struct tbasechunk22636 tbasechunk22636;
typedef struct tfreecell22628 tfreecell22628;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef N_NIMCALL_PTR(void, TY2289) (void* p, NI op);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY2289 marker;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  E_Base  {
  TNimObject Sup;
E_Base* parent;
NCSTRING name;
NimStringDesc* message;
NimStringDesc* trace;
};
struct  esynch2429  {
  E_Base Sup;
};
struct  earithmetic2441  {
  esynch2429 Sup;
};
struct  EOverflow  {
  earithmetic2441 Sup;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  tcell41090  {
NI Refcount;
TNimType* Typ;
};
struct  tcellseq41106  {
NI Len;
NI Cap;
tcell41090** D;
};
struct  tcellset41102  {
NI Counter;
NI Max;
tpagedesc41098* Head;
tpagedesc41098** Data;
};
typedef tsmallchunk22638* TY23422[512];
typedef ttrunk22611* ttrunkbuckets22613[256];
struct  tintset22615  {
ttrunkbuckets22613 Data;
};
struct  tmemregion23410  {
NI Minlargeobj;
NI Maxlargeobj;
TY23422 Freesmallchunks;
tllchunk23404* Llmem;
NI Currmem;
NI Maxmem;
NI Freemem;
NI Lastsize;
tbigchunk22640* Freechunkslist;
tintset22615 Chunkstarts;
tavlnode23408* Root;
tavlnode23408* Deleted;
tavlnode23408* Last;
tavlnode23408* Freeavlnodes;
};
struct  tgcstat43014  {
NI Stackscans;
NI Cyclecollections;
NI Maxthreshold;
NI Maxstacksize;
NI Maxstackcells;
NI Cycletablesize;
NI64 Maxpause;
};
struct  tgcheap43016  {
void* Stackbottom;
NI Cyclethreshold;
tcellseq41106 Zct;
tcellseq41106 Decstack;
tcellset41102 Cycleroots;
tcellseq41106 Tempstack;
NI Recgclock;
tmemregion23410 Region;
tgcstat43014 Stat;
};
typedef NI TY22618[16];
struct  tpagedesc41098  {
tpagedesc41098* Next;
NI Key;
TY22618 Bits;
};
struct  tbasechunk22636  {
NI Prevsize;
NI Size;
NIM_BOOL Used;
};
struct  tsmallchunk22638  {
  tbasechunk22636 Sup;
tsmallchunk22638* Next;
tsmallchunk22638* Prev;
tfreecell22628* Freelist;
NI Free;
NI Acc;
NF Data;
};
struct  tllchunk23404  {
NI Size;
NI Acc;
tllchunk23404* Next;
};
struct  tbigchunk22640  {
  tbasechunk22636 Sup;
tbigchunk22640* Next;
tbigchunk22640* Prev;
NI Align;
NF Data;
};
struct  ttrunk22611  {
ttrunk22611* Next;
NI Key;
TY22618 Bits;
};
typedef tavlnode23408* TY23414[2];
struct  tavlnode23408  {
TY23414 Link;
NI Key;
NI Upperbound;
NI Level;
};
struct  tfreecell22628  {
tfreecell22628* Next;
NI Zerofield;
};
N_NIMCALL(NI, npuParseBiggestInt)(NimStringDesc* s, NI64* number, NI start);
N_NIMCALL(NI, rawparseint_85531)(NimStringDesc* s, NI64* b, NI start);
static N_INLINE(NI, addInt)(NI a, NI b);
N_NOINLINE(void, raiseOverflow)(void);
N_NIMCALL(NI64, mulInt64)(NI64 a, NI64 b);
static N_INLINE(NI, subInt)(NI a, NI b);
static N_INLINE(NI64, subInt64)(NI64 a, NI64 b);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
N_NIMCALL(NimStringDesc*, copyStringRC1)(NimStringDesc* src);
static N_INLINE(void, nimGCunrefNoCycle)(void* p);
static N_INLINE(tcell41090*, usrtocell_44443)(void* usr);
static N_INLINE(void, rtladdzct_46002)(tcell41090* c);
N_NOINLINE(void, addzct_44418)(tcellseq41106* s, tcell41090* c);
N_NIMCALL(void, raiseException)(E_Base* e, NCSTRING ename);
N_NIMCALL(NI, npuParseBiggestFloat)(NimStringDesc* s, NF* number, NI start);
N_NIMCALL(NF, tentothepowerof_85712)(NI b_85714);
static N_INLINE(void, HEX2AHEX3D_85723)(NF* x_85729, NF y_85732);
STRING_LITERAL(TMP1170, "overflow", 8);
extern TNimType NTI18401; /* ref EOverflow */
extern TNimType NTI2445; /* EOverflow */
extern tgcheap43016 gch_43044;

static N_INLINE(NI, addInt)(NI a, NI b) {
	NI result;
	result = 0;
	result = (NI)((NU32)(a) + (NU32)(b));
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = (0 <= (NI)(result ^ a));
		if (LOC3) goto LA4;
		LOC3 = (0 <= (NI)(result ^ b));
		LA4: ;
		if (!LOC3) goto LA5;
		goto BeforeRet;
	}
	LA5: ;
	raiseOverflow();
	BeforeRet: ;
	return result;
}

static N_INLINE(NI, subInt)(NI a, NI b) {
	NI result;
	result = 0;
	result = (NI)((NU32)(a) - (NU32)(b));
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = (0 <= (NI)(result ^ a));
		if (LOC3) goto LA4;
		LOC3 = (0 <= (NI)(result ^ (NI)((NU32) ~(b))));
		LA4: ;
		if (!LOC3) goto LA5;
		goto BeforeRet;
	}
	LA5: ;
	raiseOverflow();
	BeforeRet: ;
	return result;
}

static N_INLINE(NI64, subInt64)(NI64 a, NI64 b) {
	NI64 result;
	result = 0;
	result = (NI64)((NU64)(a) - (NU64)(b));
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = (0 <= (NI64)(result ^ a));
		if (LOC3) goto LA4;
		LOC3 = (0 <= (NI64)(result ^ (NI64)((NU64) ~(b))));
		LA4: ;
		if (!LOC3) goto LA5;
		goto BeforeRet;
	}
	LA5: ;
	raiseOverflow();
	BeforeRet: ;
	return result;
}

N_NIMCALL(NI, rawparseint_85531)(NimStringDesc* s, NI64* b, NI start) {
	NI result;
	NI64 sign;
	NI i;
	result = 0;
	sign = -1;
	i = start;
	{
		if (!((NU8)(s->data[i]) == (NU8)(43))) goto LA3;
		i = addInt(i, 1);
	}
	goto LA1;
	LA3: ;
	{
		if (!((NU8)(s->data[i]) == (NU8)(45))) goto LA6;
		i = addInt(i, 1);
		sign = 1;
	}
	goto LA1;
	LA6: ;
	LA1: ;
	{
		NI64 TMP1168;
		NI TMP1169;
		if (!(((NU8)(s->data[i])) >= ((NU8)(48)) && ((NU8)(s->data[i])) <= ((NU8)(57)))) goto LA10;
		(*b) = 0;
		while (1) {
			NI64 TMP1165;
			NI TMP1166;
			NI64 TMP1167;
			if (!(((NU8)(s->data[i])) >= ((NU8)(48)) && ((NU8)(s->data[i])) <= ((NU8)(57)))) goto LA12;
			TMP1165 = mulInt64((*b), 10);
			TMP1166 = subInt(((NI) (((NU8)(s->data[i])))), 48);
			TMP1167 = subInt64((NI64)(TMP1165), ((NI64) ((NI32)(TMP1166))));
			(*b) = (NI64)(TMP1167);
			i = addInt(i, 1);
			while (1) {
				if (!((NU8)(s->data[i]) == (NU8)(95))) goto LA13;
				i = addInt(i, 1);
			} LA13: ;
		} LA12: ;
		TMP1168 = mulInt64((*b), sign);
		(*b) = (NI64)(TMP1168);
		TMP1169 = subInt(i, start);
		result = (NI32)(TMP1169);
	}
	LA10: ;
	return result;
}

N_NIMCALL(NI, npuParseBiggestInt)(NimStringDesc* s, NI64* number, NI start) {
	NI result;
	NI64 res;
	result = 0;
	res = 0;
	result = rawparseint_85531(s, &res, start);
	(*number) = res;
	return result;
}

static N_INLINE(tcell41090*, usrtocell_44443)(void* usr) {
	tcell41090* result;
	result = 0;
	result = ((tcell41090*) ((NI)((NU32)(((NI) (usr))) - (NU32)(((NI)sizeof(tcell41090))))));
	return result;
}

static N_INLINE(void, rtladdzct_46002)(tcell41090* c) {
	addzct_44418(&gch_43044.Zct, c);
}

static N_INLINE(void, nimGCunrefNoCycle)(void* p) {
	tcell41090* c;
	c = usrtocell_44443(p);
	{
		(*c).Refcount -= 8;
		if (!((NU32)((*c).Refcount) < (NU32)(8))) goto LA3;
		rtladdzct_46002(c);
	}
	LA3: ;
}

N_NIMCALL(NI, npuParseInt)(NimStringDesc* s, NI* number, NI start) {
	NI result;
	NI64 res;
	result = 0;
	res = 0;
	result = npuParseBiggestInt(s, &res, start);
	{
		NIM_BOOL LOC3;
		NIM_BOOL LOC5;
		EOverflow* e_85686;
		NimStringDesc* LOC9;
		LOC3 = 0;
		LOC3 = NIM_TRUE;
		if (!(LOC3)) goto LA4;
		LOC5 = 0;
		LOC5 = (res < (-2147483647 -1));
		if (LOC5) goto LA6;
		LOC5 = (2147483647 < res);
		LA6: ;
		LOC3 = LOC5;
		LA4: ;
		if (!LOC3) goto LA7;
		e_85686 = 0;
		e_85686 = (EOverflow*) newObj((&NTI18401), sizeof(EOverflow));
		(*e_85686).Sup.Sup.Sup.Sup.m_type = (&NTI2445);
		LOC9 = 0;
		LOC9 = (*e_85686).Sup.Sup.Sup.message; (*e_85686).Sup.Sup.Sup.message = copyStringRC1(((NimStringDesc*) &TMP1170));
		if (LOC9) nimGCunrefNoCycle(LOC9);
		raiseException((E_Base*)e_85686, "EOverflow");
	}
	goto LA1;
	LA7: ;
	{
		(*number) = ((NI) (res));
	}
	LA1: ;
	return result;
}

static N_INLINE(void, HEX2AHEX3D_85723)(NF* x_85729, NF y_85732) {
	(*x_85729) = ((NF)((*x_85729)) * (NF)(y_85732));
}

N_NIMCALL(NF, tentothepowerof_85712)(NI b_85714) {
	NF result;
	NI b;
	NF a;
	result = 0;
	b = b_85714;
	a = 1.0000000000000000e+01;
	result = 1.0000000000000000e+00;
	while (1) {
		{
			if (!(((NI) ((NI)(b & 1))) == 1)) goto LA4;
			HEX2AHEX3D_85723(&result, a);
		}
		LA4: ;
		b = (NI)((NU32)(b) >> (NU32)(1));
		{
			if (!(b == 0)) goto LA8;
			goto LA1;
		}
		LA8: ;
		HEX2AHEX3D_85723(&a, a);
	} LA1: ;
	return result;
}

N_NIMCALL(NI, npuParseBiggestFloat)(NimStringDesc* s, NF* number, NI start) {
	NI result;
	NF esign;
	NF sign;
	NI i;
	NI exponent;
	NI flags;
	NF hd;
	result = 0;
	esign = 1.0000000000000000e+00;
	sign = 1.0000000000000000e+00;
	i = start;
	exponent = 0;
	flags = 0;
	(*number) = 0.0;
	{
		if (!((NU8)(s->data[i]) == (NU8)(43))) goto LA3;
		i += 1;
	}
	goto LA1;
	LA3: ;
	{
		if (!((NU8)(s->data[i]) == (NU8)(45))) goto LA6;
		sign = -1.0000000000000000e+00;
		i += 1;
	}
	goto LA1;
	LA6: ;
	LA1: ;
	{
		NIM_BOOL LOC10;
		LOC10 = 0;
		LOC10 = ((NU8)(s->data[i]) == (NU8)(78));
		if (LOC10) goto LA11;
		LOC10 = ((NU8)(s->data[i]) == (NU8)(110));
		LA11: ;
		if (!LOC10) goto LA12;
		{
			NIM_BOOL LOC16;
			LOC16 = 0;
			LOC16 = ((NU8)(s->data[(NI32)(i + 1)]) == (NU8)(65));
			if (LOC16) goto LA17;
			LOC16 = ((NU8)(s->data[(NI32)(i + 1)]) == (NU8)(97));
			LA17: ;
			if (!LOC16) goto LA18;
			{
				NIM_BOOL LOC22;
				LOC22 = 0;
				LOC22 = ((NU8)(s->data[(NI32)(i + 2)]) == (NU8)(78));
				if (LOC22) goto LA23;
				LOC22 = ((NU8)(s->data[(NI32)(i + 2)]) == (NU8)(110));
				LA23: ;
				if (!LOC22) goto LA24;
				{
					if (!!((((NU8)(s->data[(NI32)(i + 3)])) >= ((NU8)(97)) && ((NU8)(s->data[(NI32)(i + 3)])) <= ((NU8)(122)) || ((NU8)(s->data[(NI32)(i + 3)])) >= ((NU8)(65)) && ((NU8)(s->data[(NI32)(i + 3)])) <= ((NU8)(90)) || ((NU8)(s->data[(NI32)(i + 3)])) >= ((NU8)(48)) && ((NU8)(s->data[(NI32)(i + 3)])) <= ((NU8)(57)) || ((NU8)(s->data[(NI32)(i + 3)])) == ((NU8)(95))))) goto LA28;
					(*number) = NAN;
					result = (NI32)((NI32)(i + 3) - start);
					goto BeforeRet;
				}
				LA28: ;
			}
			LA24: ;
		}
		LA18: ;
		result = 0;
		goto BeforeRet;
	}
	LA12: ;
	{
		NIM_BOOL LOC32;
		LOC32 = 0;
		LOC32 = ((NU8)(s->data[i]) == (NU8)(73));
		if (LOC32) goto LA33;
		LOC32 = ((NU8)(s->data[i]) == (NU8)(105));
		LA33: ;
		if (!LOC32) goto LA34;
		{
			NIM_BOOL LOC38;
			LOC38 = 0;
			LOC38 = ((NU8)(s->data[(NI32)(i + 1)]) == (NU8)(78));
			if (LOC38) goto LA39;
			LOC38 = ((NU8)(s->data[(NI32)(i + 1)]) == (NU8)(110));
			LA39: ;
			if (!LOC38) goto LA40;
			{
				NIM_BOOL LOC44;
				LOC44 = 0;
				LOC44 = ((NU8)(s->data[(NI32)(i + 2)]) == (NU8)(70));
				if (LOC44) goto LA45;
				LOC44 = ((NU8)(s->data[(NI32)(i + 2)]) == (NU8)(102));
				LA45: ;
				if (!LOC44) goto LA46;
				{
					if (!!((((NU8)(s->data[(NI32)(i + 3)])) >= ((NU8)(97)) && ((NU8)(s->data[(NI32)(i + 3)])) <= ((NU8)(122)) || ((NU8)(s->data[(NI32)(i + 3)])) >= ((NU8)(65)) && ((NU8)(s->data[(NI32)(i + 3)])) <= ((NU8)(90)) || ((NU8)(s->data[(NI32)(i + 3)])) >= ((NU8)(48)) && ((NU8)(s->data[(NI32)(i + 3)])) <= ((NU8)(57)) || ((NU8)(s->data[(NI32)(i + 3)])) == ((NU8)(95))))) goto LA50;
					(*number) = ((NF)(INF) * (NF)(sign));
					result = (NI32)((NI32)(i + 3) - start);
					goto BeforeRet;
				}
				LA50: ;
			}
			LA46: ;
		}
		LA40: ;
		result = 0;
		goto BeforeRet;
	}
	LA34: ;
	while (1) {
		if (!(((NU8)(s->data[i])) >= ((NU8)(48)) && ((NU8)(s->data[i])) <= ((NU8)(57)))) goto LA52;
		flags = (NI)(flags | 1);
		(*number) = ((NF)(((NF)((*number)) * (NF)(1.0000000000000000e+01))) + (NF)(((double) (((NI) ((NI32)(((NI) (((NU8)(s->data[i])))) - 48)))))));
		i += 1;
		while (1) {
			if (!((NU8)(s->data[i]) == (NU8)(95))) goto LA53;
			i += 1;
		} LA53: ;
	} LA52: ;
	{
		NF hd;
		if (!((NU8)(s->data[i]) == (NU8)(46))) goto LA56;
		hd = 1.0000000000000000e+00;
		i += 1;
		while (1) {
			if (!(((NU8)(s->data[i])) >= ((NU8)(48)) && ((NU8)(s->data[i])) <= ((NU8)(57)))) goto LA58;
			flags = (NI)(flags | 2);
			(*number) = ((NF)(((NF)((*number)) * (NF)(1.0000000000000000e+01))) + (NF)(((double) (((NI) ((NI32)(((NI) (((NU8)(s->data[i])))) - 48)))))));
			hd = ((NF)(hd) * (NF)(1.0000000000000000e+01));
			i += 1;
			while (1) {
				if (!((NU8)(s->data[i]) == (NU8)(95))) goto LA59;
				i += 1;
			} LA59: ;
		} LA58: ;
		(*number) = ((NF)((*number)) / (NF)(hd));
	}
	LA56: ;
	{
		if (!(flags == 0)) goto LA62;
		result = 0;
		goto BeforeRet;
	}
	LA62: ;
	{
		if (!(((NU8)(s->data[i])) == ((NU8)(101)) || ((NU8)(s->data[i])) == ((NU8)(69)))) goto LA66;
		i += 1;
		{
			if (!((NU8)(s->data[i]) == (NU8)(43))) goto LA70;
			i += 1;
		}
		goto LA68;
		LA70: ;
		{
			if (!((NU8)(s->data[i]) == (NU8)(45))) goto LA73;
			esign = -1.0000000000000000e+00;
			i += 1;
		}
		goto LA68;
		LA73: ;
		LA68: ;
		{
			if (!!((((NU8)(s->data[i])) >= ((NU8)(48)) && ((NU8)(s->data[i])) <= ((NU8)(57))))) goto LA77;
			result = 0;
			goto BeforeRet;
		}
		LA77: ;
		while (1) {
			if (!(((NU8)(s->data[i])) >= ((NU8)(48)) && ((NU8)(s->data[i])) <= ((NU8)(57)))) goto LA79;
			exponent = (NI32)((NI32)((NI32)(exponent * 10) + ((NI) (((NU8)(s->data[i]))))) - 48);
			i += 1;
			while (1) {
				if (!((NU8)(s->data[i]) == (NU8)(95))) goto LA80;
				i += 1;
			} LA80: ;
		} LA79: ;
	}
	LA66: ;
	hd = tentothepowerof_85712(exponent);
	{
		if (!(0.0 < esign)) goto LA83;
		(*number) = ((NF)((*number)) * (NF)(hd));
	}
	goto LA81;
	LA83: ;
	{
		(*number) = ((NF)((*number)) / (NF)(hd));
	}
	LA81: ;
	(*number) = ((NF)((*number)) * (NF)(sign));
	result = (NI32)(i - start);
	BeforeRet: ;
	return result;
}

N_NIMCALL(NI, npuParseFloat)(NimStringDesc* s, NF* number, NI start) {
	NI result;
	NF bf;
	result = 0;
	bf = 0;
	result = npuParseBiggestFloat(s, &bf, start);
	(*number) = bf;
	return result;
}
N_NOINLINE(void, stdlibparseutilsInit)(void) {
}

N_NOINLINE(void, stdlibparseutilsDatInit)(void) {
}

