/* Generated by Nim Compiler v0.10.2 */
/*   (c) 2014 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 32
#include "nimbase.h"
typedef struct tident200021 tident200021;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct tidobj200015 tidobj200015;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct tcell44935 tcell44935;
typedef struct tcellseq44951 tcellseq44951;
typedef struct tgcheap47016 tgcheap47016;
typedef struct tcellset44947 tcellset44947;
typedef struct tpagedesc44943 tpagedesc44943;
typedef struct tmemregion27210 tmemregion27210;
typedef struct tsmallchunk26440 tsmallchunk26440;
typedef struct tllchunk27204 tllchunk27204;
typedef struct tbigchunk26442 tbigchunk26442;
typedef struct tintset26417 tintset26417;
typedef struct ttrunk26413 ttrunk26413;
typedef struct tavlnode27208 tavlnode27208;
typedef struct tgcstat47014 tgcstat47014;
typedef struct tbasechunk26438 tbasechunk26438;
typedef struct tfreecell26430 tfreecell26430;
typedef tident200021* TY200034[8192];
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef N_NIMCALL_PTR(void, TY3089) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3094) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3089 marker;
TY3094 deepcopy;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  tidobj200015  {
  TNimObject Sup;
NI Id;
};
struct  tident200021  {
  tidobj200015 Sup;
NimStringDesc* S;
tident200021* Next;
NI H;
};
struct  tcell44935  {
NI Refcount;
TNimType* Typ;
};
struct  tcellseq44951  {
NI Len;
NI Cap;
tcell44935** D;
};
struct  tcellset44947  {
NI Counter;
NI Max;
tpagedesc44943* Head;
tpagedesc44943** Data;
};
typedef tsmallchunk26440* TY27222[512];
typedef ttrunk26413* ttrunkbuckets26415[256];
struct  tintset26417  {
ttrunkbuckets26415 Data;
};
struct  tmemregion27210  {
NI Minlargeobj;
NI Maxlargeobj;
TY27222 Freesmallchunks;
tllchunk27204* Llmem;
NI Currmem;
NI Maxmem;
NI Freemem;
NI Lastsize;
tbigchunk26442* Freechunkslist;
tintset26417 Chunkstarts;
tavlnode27208* Root;
tavlnode27208* Deleted;
tavlnode27208* Last;
tavlnode27208* Freeavlnodes;
};
struct  tgcstat47014  {
NI Stackscans;
NI Cyclecollections;
NI Maxthreshold;
NI Maxstacksize;
NI Maxstackcells;
NI Cycletablesize;
NI64 Maxpause;
};
struct  tgcheap47016  {
void* Stackbottom;
NI Cyclethreshold;
tcellseq44951 Zct;
tcellseq44951 Decstack;
tcellset44947 Cycleroots;
tcellseq44951 Tempstack;
NI Recgclock;
tmemregion27210 Region;
tgcstat47014 Stat;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
typedef NI TY26420[16];
struct  tpagedesc44943  {
tpagedesc44943* Next;
NI Key;
TY26420 Bits;
};
struct  tbasechunk26438  {
NI Prevsize;
NI Size;
NIM_BOOL Used;
};
struct  tsmallchunk26440  {
  tbasechunk26438 Sup;
tsmallchunk26440* Next;
tsmallchunk26440* Prev;
tfreecell26430* Freelist;
NI Free;
NI Acc;
NF Data;
};
struct  tllchunk27204  {
NI Size;
NI Acc;
tllchunk27204* Next;
};
struct  tbigchunk26442  {
  tbasechunk26438 Sup;
tbigchunk26442* Next;
tbigchunk26442* Prev;
NI Align;
NF Data;
};
struct  ttrunk26413  {
ttrunk26413* Next;
NI Key;
TY26420 Bits;
};
typedef tavlnode27208* TY27214[2];
struct  tavlnode27208  {
TY27214 Link;
NI Key;
NI Upperbound;
NI Level;
};
struct  tfreecell26430  {
tfreecell26430* Next;
NI Zerofield;
};
N_NIMCALL(tident200021*, getident_200472)(NimStringDesc* identifier);
N_NIMCALL(tident200021*, getident_200268)(NCSTRING identifier, NI length, NI h);
N_NIMCALL(NI, cmpexact_200200)(NCSTRING a, NCSTRING b, NI blen);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(tcell44935*, usrtocell_48646)(void* usr);
static N_INLINE(void, rtladdzct_50204)(tcell44935* c);
N_NOINLINE(void, addzct_48617)(tcellseq44951* s, tcell44935* c);
N_NIMCALL(NI, cmpignorestyle_200044)(NCSTRING a, NCSTRING b, NI blen);
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP441)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
N_NIMCALL(NimStringDesc*, mnewString)(NI len);
N_NIMCALL(NimStringDesc*, mnewString)(NI len);
N_NIMCALL(NI, hashignorestyle_128885)(NimStringDesc* x);
N_NIMCALL(void, TMP826)(void* p, NI op);
STRING_LITERAL(TMP442, ":anonymous", 10);
STRING_LITERAL(TMP443, ":delegator", 10);
NIM_BOOL firstchariscs_200029;
TY200034 buckets_200039;
NI wordcounter_200264;
tident200021* idanon_200504;
extern tgcheap47016 gch_47044;
extern TNimType NTI3211; /* RootObj */
TNimType NTI200015; /* TIdObj */
extern TNimType NTI108; /* int */
TNimType NTI200021; /* TIdent */
extern TNimType NTI149; /* string */
extern TNimType NTI128021; /* THash */
TNimType NTI200019; /* PIdent */
tident200021* iddelegator_200559;
TNimType NTI200017; /* PIdObj */

N_NIMCALL(NI, cmpexact_200200)(NCSTRING a, NCSTRING b, NI blen) {
	NI result;
	NI i;
	NI j;
	result = 0;
	i = 0;
	j = 0;
	result = 1;
	{
		while (1) {
			NIM_CHAR aa;
			NIM_CHAR bb;
			if (!(j < blen)) goto LA2;
			aa = a[i];
			bb = b[j];
			result = (NI32)(((NI) (((NU8)(aa)))) - ((NI) (((NU8)(bb)))));
			{
				NIM_BOOL LOC5;
				LOC5 = 0;
				LOC5 = !((result == 0));
				if (LOC5) goto LA6;
				LOC5 = ((NU8)(aa) == (NU8)(0));
				LA6: ;
				if (!LOC5) goto LA7;
				goto LA1;
			}
			LA7: ;
			i += 1;
			j += 1;
		} LA2: ;
	} LA1: ;
	{
		if (!(result == 0)) goto LA11;
		{
			if (!!(((NU8)(a[i]) == (NU8)(0)))) goto LA15;
			result = 1;
		}
		LA15: ;
	}
	LA11: ;
	return result;
}

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

static N_INLINE(void, rtladdzct_50204)(tcell44935* c) {
	addzct_48617((&gch_47044.Zct), c);
}

static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src) {
	{
		tcell44935* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_48646(src);
		(*c).Refcount += 8;
	}
	LA3: ;
	{
		tcell44935* c;
		if (!!(((*dest) == NIM_NIL))) goto LA7;
		c = usrtocell_48646((*dest));
		{
			(*c).Refcount -= 8;
			if (!((NU32)((*c).Refcount) < (NU32)(8))) goto LA11;
			rtladdzct_50204(c);
		}
		LA11: ;
	}
	LA7: ;
	(*dest) = src;
}

N_NIMCALL(NI, cmpignorestyle_200044)(NCSTRING a, NCSTRING b, NI blen) {
	NI result;
	NI i;
	NI j;
	result = 0;
	{
		if (!firstchariscs_200029) goto LA3;
		{
			if (!!(((NU8)(a[0]) == (NU8)(b[0])))) goto LA7;
			result = 1;
			goto BeforeRet;
		}
		LA7: ;
	}
	LA3: ;
	i = 0;
	j = 0;
	result = 1;
	{
		while (1) {
			NIM_CHAR aa;
			NIM_CHAR bb;
			if (!(j < blen)) goto LA10;
			{
				while (1) {
					if (!((NU8)(a[i]) == (NU8)(95))) goto LA12;
					i += 1;
				} LA12: ;
			}
			{
				while (1) {
					if (!((NU8)(b[j]) == (NU8)(95))) goto LA14;
					j += 1;
				} LA14: ;
			}
			aa = a[i];
			bb = b[j];
			{
				NIM_BOOL LOC17;
				LOC17 = 0;
				LOC17 = ((NU8)(65) <= (NU8)(aa));
				if (!(LOC17)) goto LA18;
				LOC17 = ((NU8)(aa) <= (NU8)(90));
				LA18: ;
				if (!LOC17) goto LA19;
				aa = ((NIM_CHAR) (((NI) ((NI32)(((NI) (((NU8)(aa)))) + 32)))));
			}
			LA19: ;
			{
				NIM_BOOL LOC23;
				LOC23 = 0;
				LOC23 = ((NU8)(65) <= (NU8)(bb));
				if (!(LOC23)) goto LA24;
				LOC23 = ((NU8)(bb) <= (NU8)(90));
				LA24: ;
				if (!LOC23) goto LA25;
				bb = ((NIM_CHAR) (((NI) ((NI32)(((NI) (((NU8)(bb)))) + 32)))));
			}
			LA25: ;
			result = (NI32)(((NI) (((NU8)(aa)))) - ((NI) (((NU8)(bb)))));
			{
				NIM_BOOL LOC29;
				LOC29 = 0;
				LOC29 = !((result == 0));
				if (LOC29) goto LA30;
				LOC29 = ((NU8)(aa) == (NU8)(0));
				LA30: ;
				if (!LOC29) goto LA31;
				goto LA9;
			}
			LA31: ;
			i += 1;
			j += 1;
		} LA10: ;
	} LA9: ;
	{
		if (!(result == 0)) goto LA35;
		{
			if (!!(((NU8)(a[i]) == (NU8)(0)))) goto LA39;
			result = 1;
		}
		LA39: ;
	}
	LA35: ;
	BeforeRet: ;
	return result;
}
N_NIMCALL(void, TMP441)(void* p, NI op) {
	tident200021* a;
	a = (tident200021*)p;
	nimGCvisit((void*)(*a).S, op);
	nimGCvisit((void*)(*a).Next, op);
}

N_NIMCALL(tident200021*, getident_200268)(NCSTRING identifier, NI length, NI h) {
	tident200021* result;
	NI idx;
	tident200021* last;
	NI id;
	result = 0;
	idx = (NI)(h & 8191);
	result = buckets_200039[(idx)- 0];
	last = NIM_NIL;
	id = 0;
	{
		while (1) {
			if (!!((result == NIM_NIL))) goto LA2;
			{
				NI LOC5;
				LOC5 = 0;
				LOC5 = cmpexact_200200((*result).S->data, identifier, length);
				if (!(LOC5 == 0)) goto LA6;
				{
					if (!!((last == NIM_NIL))) goto LA10;
					asgnRefNoCycle((void**) (&(*last).Next), (*result).Next);
					asgnRefNoCycle((void**) (&(*result).Next), buckets_200039[(idx)- 0]);
					asgnRefNoCycle((void**) (&buckets_200039[(idx)- 0]), result);
				}
				LA10: ;
				goto BeforeRet;
			}
			goto LA3;
			LA6: ;
			{
				NI LOC13;
				LOC13 = 0;
				LOC13 = cmpignorestyle_200044((*result).S->data, identifier, length);
				if (!(LOC13 == 0)) goto LA14;
				id = (*result).Sup.Id;
			}
			goto LA3;
			LA14: ;
			LA3: ;
			last = result;
			result = (*result).Next;
		} LA2: ;
	}
	result = (tident200021*) newObj((&NTI200019), sizeof(tident200021));
	(*result).Sup.Sup.m_type = (&NTI200021);
	(*result).H = h;
	asgnRefNoCycle((void**) (&(*result).S), mnewString(length));
	{
		NI i_200429;
		NI HEX3Atmp_200446;
		NI res_200449;
		i_200429 = 0;
		HEX3Atmp_200446 = 0;
		HEX3Atmp_200446 = (NI32)(length - 1);
		res_200449 = 0;
		{
			while (1) {
				if (!(res_200449 <= HEX3Atmp_200446)) goto LA18;
				i_200429 = res_200449;
				(*result).S->data[i_200429] = identifier[i_200429];
				res_200449 += 1;
			} LA18: ;
		}
	}
	asgnRefNoCycle((void**) (&(*result).Next), buckets_200039[(idx)- 0]);
	asgnRefNoCycle((void**) (&buckets_200039[(idx)- 0]), result);
	{
		if (!(id == 0)) goto LA21;
		wordcounter_200264 += 1;
		(*result).Sup.Id = ((NI32)-(wordcounter_200264));
	}
	goto LA19;
	LA21: ;
	{
		(*result).Sup.Id = id;
	}
	LA19: ;
	BeforeRet: ;
	return result;
}

N_NIMCALL(tident200021*, getident_200472)(NimStringDesc* identifier) {
	tident200021* result;
	NI LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = hashignorestyle_128885(identifier);
	result = getident_200268(identifier->data, identifier->Sup.len, LOC1);
	return result;
}

N_NIMCALL(tident200021*, getident_200482)(NimStringDesc* identifier, NI h) {
	tident200021* result;
	result = 0;
	result = getident_200268(identifier->data, identifier->Sup.len, h);
	return result;
}
N_NIMCALL(void, TMP826)(void* p, NI op) {
	tidobj200015* a;
	a = (tidobj200015*)p;
}

N_NIMCALL(NIM_BOOL, identeq_200493)(tident200021* id, NimStringDesc* name) {
	NIM_BOOL result;
	tident200021* LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = getident_200472(name);
	result = ((*id).Sup.Id == (*LOC1).Sup.Id);
	return result;
}
NIM_EXTERNC N_NOINLINE(void, HEX00_identsInit)(void) {
	wordcounter_200264 = 1;
	asgnRefNoCycle((void**) (&idanon_200504), getident_200472(((NimStringDesc*) &TMP442)));
	asgnRefNoCycle((void**) (&iddelegator_200559), getident_200472(((NimStringDesc*) &TMP443)));
}

NIM_EXTERNC N_NOINLINE(void, HEX00_identsDatInit)(void) {
static TNimNode* TMP440[3];
static TNimNode TMP438[5];
NTI200015.size = sizeof(tidobj200015);
NTI200015.kind = 17;
NTI200015.base = (&NTI3211);
NTI200015.flags = 1;
TMP438[0].kind = 1;
TMP438[0].offset = offsetof(tidobj200015, Id);
TMP438[0].typ = (&NTI108);
TMP438[0].name = "id";
NTI200015.node = &TMP438[0];
NTI200021.size = sizeof(tident200021);
NTI200021.kind = 17;
NTI200021.base = (&NTI200015);
NTI200021.flags = 2;
TMP440[0] = &TMP438[2];
TMP438[2].kind = 1;
TMP438[2].offset = offsetof(tident200021, S);
TMP438[2].typ = (&NTI149);
TMP438[2].name = "s";
TMP440[1] = &TMP438[3];
TMP438[3].kind = 1;
TMP438[3].offset = offsetof(tident200021, Next);
TMP438[3].typ = (&NTI200019);
TMP438[3].name = "next";
TMP440[2] = &TMP438[4];
TMP438[4].kind = 1;
TMP438[4].offset = offsetof(tident200021, H);
TMP438[4].typ = (&NTI128021);
TMP438[4].name = "h";
TMP438[1].len = 3; TMP438[1].kind = 2; TMP438[1].sons = &TMP440[0];
NTI200021.node = &TMP438[1];
NTI200019.size = sizeof(tident200021*);
NTI200019.kind = 22;
NTI200019.base = (&NTI200021);
NTI200019.flags = 2;
NTI200019.marker = TMP441;
NTI200017.size = sizeof(tidobj200015*);
NTI200017.kind = 22;
NTI200017.base = (&NTI200015);
NTI200017.marker = TMP826;
}

