/* 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/idents.o compiler/nimcache/idents.c */
#define NIM_INTBITS 32
#include "nimbase.h"
typedef struct tident167019 tident167019;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct tidobj167013 tidobj167013;
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;
typedef tident167019* TY167028[8192];
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  tidobj167013  {
  TNimObject Sup;
NI Id;
};
struct  tident167019  {
  tidobj167013 Sup;
NimStringDesc* S;
tident167019* Next;
NI H;
};
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;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
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(tident167019*, getident_167456)(NimStringDesc* identifier);
N_NIMCALL(tident167019*, getident_167250)(NCSTRING identifier, NI length, NI h);
N_NIMCALL(NI, cmpexact_167186)(NCSTRING a, NCSTRING b, NI blen);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
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(NI, cmpignorestyle_167036)(NCSTRING a, NCSTRING b, NI blen);
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP438)(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_119859)(NimStringDesc* x);
N_NIMCALL(void, TMP818)(void* p, NI op);
STRING_LITERAL(TMP439, ":anonymous", 10);
STRING_LITERAL(TMP440, ":delegator", 10);
NIM_BOOL firstchariscs_167025;
TY167028 buckets_167033;
NI wordcounter_167248;
tident167019* idanon_167476;
extern tgcheap43016 gch_43044;
extern TNimType NTI2409; /* TObject */
TNimType NTI167013; /* TIdObj */
extern TNimType NTI106; /* int */
TNimType NTI167019; /* TIdent */
extern TNimType NTI143; /* string */
extern TNimType NTI119013; /* THash */
TNimType NTI167017; /* PIdent */
tident167019* iddelegator_167478;
TNimType NTI167015; /* PIdObj */

N_NIMCALL(NI, cmpexact_167186)(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 LA1;
		aa = a[i];
		bb = b[j];
		result = (NI32)(((NI) (((NU8)(aa)))) - ((NI) (((NU8)(bb)))));
		{
			NIM_BOOL LOC4;
			LOC4 = 0;
			LOC4 = !((result == 0));
			if (LOC4) goto LA5;
			LOC4 = ((NU8)(aa) == (NU8)(0));
			LA5: ;
			if (!LOC4) goto LA6;
			goto LA1;
		}
		LA6: ;
		i += 1;
		j += 1;
	} LA1: ;
	{
		if (!(result == 0)) goto LA10;
		{
			if (!!(((NU8)(a[i]) == (NU8)(0)))) goto LA14;
			result = 1;
		}
		LA14: ;
	}
	LA10: ;
	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, asgnRefNoCycle)(void** dest, void* src) {
	{
		tcell41090* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_44443(src);
		(*c).Refcount += 8;
	}
	LA3: ;
	{
		tcell41090* c;
		if (!!(((*dest) == NIM_NIL))) goto LA7;
		c = usrtocell_44443((*dest));
		{
			(*c).Refcount -= 8;
			if (!((NU32)((*c).Refcount) < (NU32)(8))) goto LA11;
			rtladdzct_46002(c);
		}
		LA11: ;
	}
	LA7: ;
	(*dest) = src;
}

N_NIMCALL(NI, cmpignorestyle_167036)(NCSTRING a, NCSTRING b, NI blen) {
	NI result;
	NI i;
	NI j;
	result = 0;
	{
		if (!firstchariscs_167025) 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 LA9;
		while (1) {
			if (!((NU8)(a[i]) == (NU8)(95))) goto LA10;
			i += 1;
		} LA10: ;
		while (1) {
			if (!((NU8)(b[j]) == (NU8)(95))) goto LA11;
			j += 1;
		} LA11: ;
		aa = a[i];
		bb = b[j];
		{
			NIM_BOOL LOC14;
			LOC14 = 0;
			LOC14 = ((NU8)(65) <= (NU8)(aa));
			if (!(LOC14)) goto LA15;
			LOC14 = ((NU8)(aa) <= (NU8)(90));
			LA15: ;
			if (!LOC14) goto LA16;
			aa = ((NIM_CHAR) (((NI) ((NI32)(((NI) (((NU8)(aa)))) + 32)))));
		}
		LA16: ;
		{
			NIM_BOOL LOC20;
			LOC20 = 0;
			LOC20 = ((NU8)(65) <= (NU8)(bb));
			if (!(LOC20)) goto LA21;
			LOC20 = ((NU8)(bb) <= (NU8)(90));
			LA21: ;
			if (!LOC20) goto LA22;
			bb = ((NIM_CHAR) (((NI) ((NI32)(((NI) (((NU8)(bb)))) + 32)))));
		}
		LA22: ;
		result = (NI32)(((NI) (((NU8)(aa)))) - ((NI) (((NU8)(bb)))));
		{
			NIM_BOOL LOC26;
			LOC26 = 0;
			LOC26 = !((result == 0));
			if (LOC26) goto LA27;
			LOC26 = ((NU8)(aa) == (NU8)(0));
			LA27: ;
			if (!LOC26) goto LA28;
			goto LA9;
		}
		LA28: ;
		i += 1;
		j += 1;
	} LA9: ;
	{
		if (!(result == 0)) goto LA32;
		{
			if (!!(((NU8)(a[i]) == (NU8)(0)))) goto LA36;
			result = 1;
		}
		LA36: ;
	}
	LA32: ;
	BeforeRet: ;
	return result;
}
N_NIMCALL(void, TMP438)(void* p, NI op) {
	tident167019* a;
	a = (tident167019*)p;
	nimGCvisit((void*)(*a).S, op);
	nimGCvisit((void*)(*a).Next, op);
}

N_NIMCALL(tident167019*, getident_167250)(NCSTRING identifier, NI length, NI h) {
	tident167019* result;
	NI idx;
	tident167019* last;
	NI id;
	NI i_167429;
	NI HEX3Atmp_167448;
	NI res_167450;
	result = 0;
	idx = (NI)(h & 8191);
	result = buckets_167033[(idx)- 0];
	last = NIM_NIL;
	id = 0;
	while (1) {
		if (!!((result == NIM_NIL))) goto LA1;
		{
			NI LOC4;
			LOC4 = 0;
			LOC4 = cmpexact_167186((*result).S->data, identifier, length);
			if (!(LOC4 == 0)) goto LA5;
			{
				if (!!((last == NIM_NIL))) goto LA9;
				asgnRefNoCycle((void**) &(*last).Next, (*result).Next);
				asgnRefNoCycle((void**) &(*result).Next, buckets_167033[(idx)- 0]);
				asgnRefNoCycle((void**) &buckets_167033[(idx)- 0], result);
			}
			LA9: ;
			goto BeforeRet;
		}
		goto LA2;
		LA5: ;
		{
			NI LOC12;
			LOC12 = 0;
			LOC12 = cmpignorestyle_167036((*result).S->data, identifier, length);
			if (!(LOC12 == 0)) goto LA13;
			id = (*result).Sup.Id;
		}
		goto LA2;
		LA13: ;
		LA2: ;
		last = result;
		result = (*result).Next;
	} LA1: ;
	result = (tident167019*) newObj((&NTI167017), sizeof(tident167019));
	(*result).Sup.Sup.m_type = (&NTI167019);
	(*result).H = h;
	asgnRefNoCycle((void**) &(*result).S, mnewString(length));
	i_167429 = 0;
	HEX3Atmp_167448 = 0;
	HEX3Atmp_167448 = (NI32)(length - 1);
	res_167450 = 0;
	while (1) {
		if (!(res_167450 <= HEX3Atmp_167448)) goto LA15;
		i_167429 = res_167450;
		(*result).S->data[i_167429] = identifier[i_167429];
		res_167450 += 1;
	} LA15: ;
	asgnRefNoCycle((void**) &(*result).Next, buckets_167033[(idx)- 0]);
	asgnRefNoCycle((void**) &buckets_167033[(idx)- 0], result);
	{
		if (!(id == 0)) goto LA18;
		wordcounter_167248 += 1;
		(*result).Sup.Id = ((NI32)-(wordcounter_167248));
	}
	goto LA16;
	LA18: ;
	{
		(*result).Sup.Id = id;
	}
	LA16: ;
	BeforeRet: ;
	return result;
}

N_NIMCALL(tident167019*, getident_167456)(NimStringDesc* identifier) {
	tident167019* result;
	NI LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = hashignorestyle_119859(identifier);
	result = getident_167250(identifier->data, identifier->Sup.len, LOC1);
	return result;
}

N_NIMCALL(tident167019*, getident_167462)(NimStringDesc* identifier, NI h) {
	tident167019* result;
	result = 0;
	result = getident_167250(identifier->data, identifier->Sup.len, h);
	return result;
}
N_NIMCALL(void, TMP818)(void* p, NI op) {
	tidobj167013* a;
	a = (tidobj167013*)p;
}

N_NIMCALL(NIM_BOOL, identeq_167469)(tident167019* id, NimStringDesc* name) {
	NIM_BOOL result;
	tident167019* LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = getident_167456(name);
	result = ((*id).Sup.Id == (*LOC1).Sup.Id);
	return result;
}
N_NOINLINE(void, identsInit)(void) {
	wordcounter_167248 = 1;
	asgnRefNoCycle((void**) &idanon_167476, getident_167456(((NimStringDesc*) &TMP439)));
	asgnRefNoCycle((void**) &iddelegator_167478, getident_167456(((NimStringDesc*) &TMP440)));
}

N_NOINLINE(void, identsDatInit)(void) {
static TNimNode* TMP437[3];
static TNimNode TMP435[5];
NTI167013.size = sizeof(tidobj167013);
NTI167013.kind = 17;
NTI167013.base = (&NTI2409);
NTI167013.flags = 1;
TMP435[0].kind = 1;
TMP435[0].offset = offsetof(tidobj167013, Id);
TMP435[0].typ = (&NTI106);
TMP435[0].name = "id";
NTI167013.node = &TMP435[0];
NTI167019.size = sizeof(tident167019);
NTI167019.kind = 17;
NTI167019.base = (&NTI167013);
NTI167019.flags = 2;
TMP437[0] = &TMP435[2];
TMP435[2].kind = 1;
TMP435[2].offset = offsetof(tident167019, S);
TMP435[2].typ = (&NTI143);
TMP435[2].name = "s";
TMP437[1] = &TMP435[3];
TMP435[3].kind = 1;
TMP435[3].offset = offsetof(tident167019, Next);
TMP435[3].typ = (&NTI167017);
TMP435[3].name = "next";
TMP437[2] = &TMP435[4];
TMP435[4].kind = 1;
TMP435[4].offset = offsetof(tident167019, H);
TMP435[4].typ = (&NTI119013);
TMP435[4].name = "h";
TMP435[1].len = 3; TMP435[1].kind = 2; TMP435[1].sons = &TMP437[0];
NTI167019.node = &TMP435[1];
NTI167017.size = sizeof(tident167019*);
NTI167017.kind = 22;
NTI167017.base = (&NTI167019);
NTI167017.flags = 2;
NTI167017.marker = TMP438;
NTI167015.size = sizeof(tidobj167013*);
NTI167015.kind = 22;
NTI167015.base = (&NTI167013);
NTI167015.marker = TMP818;
}

