/* 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/treetab.o compiler/nimcache/treetab.c */
#define NIM_INTBITS 32
#include "nimbase.h"

#include <string.h>
typedef struct tnodetable188861 tnodetable188861;
typedef struct tnode188803 tnode188803;
typedef struct tnodepairseq188859 tnodepairseq188859;
typedef struct tnodepair188857 tnodepair188857;
typedef struct TGenericSeq TGenericSeq;
typedef struct ttype188837 ttype188837;
typedef struct tlineinfo163527 tlineinfo163527;
typedef struct NimStringDesc NimStringDesc;
typedef struct tsym188833 tsym188833;
typedef struct tident167019 tident167019;
typedef struct tnodeseq188797 tnodeseq188797;
typedef struct tidobj167013 tidobj167013;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct ttypeseq188835 ttypeseq188835;
typedef struct tscope188827 tscope188827;
typedef struct TY188933 TY188933;
typedef struct tinstantiation188823 tinstantiation188823;
typedef struct tstrtable188807 tstrtable188807;
typedef struct tsymseq188805 tsymseq188805;
typedef struct tloc188817 tloc188817;
typedef struct trope145007 trope145007;
typedef struct tlib188821 tlib188821;
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 TY188922 TY188922;
typedef struct tlistentry118017 tlistentry118017;
typedef struct tbasechunk22636 tbasechunk22636;
typedef struct tfreecell22628 tfreecell22628;
struct  tnodepair188857  {
NI H;
tnode188803* Key;
NI Val;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  tlineinfo163527  {
NI16 Line;
NI16 Col;
NI32 Fileindex;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  tnode188803  {
ttype188837* Typ;
tlineinfo163527 Info;
NU16 Flags;
NU8 Kind;
union {
struct {NI64 Intval;
} S1;
struct {NF Floatval;
} S2;
struct {NimStringDesc* Strval;
} S3;
struct {tsym188833* Sym;
} S4;
struct {tident167019* Ident;
} S5;
struct {tnodeseq188797* Sons;
} S6;
} kindU;
NimStringDesc* Comment;
};
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  tstrtable188807  {
NI Counter;
tsymseq188805* Data;
};
struct  tloc188817  {
NU8 K;
NU8 S;
NU8 Flags;
ttype188837* T;
trope145007* R;
trope145007* Heaproot;
NI A;
};
struct  tsym188833  {
  tidobj167013 Sup;
NU8 Kind;
union {
struct {ttypeseq188835* Typeinstcache;
tscope188827* Typscope;
} S1;
struct {TY188933* Procinstcache;
tscope188827* Scope;
} S2;
struct {TY188933* Usedgenerics;
tstrtable188807 Tab;
} S3;
} kindU;
NU16 Magic;
ttype188837* Typ;
tident167019* Name;
tlineinfo163527 Info;
tsym188833* Owner;
NU32 Flags;
tnode188803* Ast;
NU32 Options;
NI Position;
NI Offset;
tloc188817 Loc;
tlib188821* Annex;
tnode188803* Constraint;
};
struct  tnodetable188861  {
NI Counter;
tnodepairseq188859* Data;
};
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;
};
struct  ttype188837  {
  tidobj167013 Sup;
NU8 Kind;
NU8 Callconv;
NU32 Flags;
ttypeseq188835* Sons;
tnode188803* N;
tsym188833* Destructor;
tsym188833* Owner;
tsym188833* Sym;
NI64 Size;
NI Align;
tloc188817 Loc;
};
struct  tscope188827  {
NI Depthlevel;
tstrtable188807 Symbols;
tnodeseq188797* Usingsyms;
tscope188827* Parent;
};
struct  tinstantiation188823  {
tsym188833* Sym;
ttypeseq188835* Concretetypes;
TY188922* Usedby;
};
struct  trope145007  {
  TNimObject Sup;
trope145007* Left;
trope145007* Right;
NI Length;
NimStringDesc* Data;
};
struct  tlistentry118017  {
  TNimObject Sup;
tlistentry118017* Prev;
tlistentry118017* Next;
};
struct  tlib188821  {
  tlistentry118017 Sup;
NU8 Kind;
NIM_BOOL Generated;
NIM_BOOL Isoverriden;
trope145007* Name;
tnode188803* Path;
};
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;
};
struct tnodepairseq188859 {
  TGenericSeq Sup;
  tnodepair188857 data[SEQ_DECL_SIZE];
};
struct tnodeseq188797 {
  TGenericSeq Sup;
  tnode188803* data[SEQ_DECL_SIZE];
};
struct ttypeseq188835 {
  TGenericSeq Sup;
  ttype188837* data[SEQ_DECL_SIZE];
};
struct TY188933 {
  TGenericSeq Sup;
  tinstantiation188823* data[SEQ_DECL_SIZE];
};
struct tsymseq188805 {
  TGenericSeq Sup;
  tsym188833* data[SEQ_DECL_SIZE];
};
struct TY188922 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
N_NIMCALL(NI, hashtree_247022)(tnode188803* n);
static N_INLINE(NI, HEX21HEX26_119015)(NI h, NI val);
N_NIMCALL(NI, hash_119827)(NimStringDesc* x);
static N_INLINE(NI, sonslen_189181)(tnode188803* n);
N_NIMCALL(NI, nodetablerawget_247475)(tnodetable188861 t, NI k, tnode188803* key);
N_NIMCALL(NIM_BOOL, treesequivalent_247223)(tnode188803* a, tnode188803* b);
static N_INLINE(NIM_BOOL, eqStrings)(NimStringDesc* a, NimStringDesc* b);
N_NIMCALL(NIM_BOOL, sametypeornil_228128)(ttype188837* a, ttype188837* b, NU8 flags);
static N_INLINE(NI, nexttry_197192)(NI h, NI maxhash);
N_NIMCALL(NIM_BOOL, mustrehash_197187)(NI length, NI counter);
N_NIMCALL(void*, newSeq)(TNimType* typ, NI len);
N_NIMCALL(void, nodetablerawinsert_247514)(tnodepairseq188859** data, NI k, tnode188803* key, NI val);
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(void, unsureAsgnRef)(void** dest, void* src);
extern TNimType NTI188859; /* TNodePairSeq */
extern tgcheap43016 gch_43044;

static N_INLINE(NI, HEX21HEX26_119015)(NI h, NI val) {
	NI result;
	result = 0;
	result = (NI)((NU32)(h) + (NU32)(val));
	result = (NI)((NU32)(result) + (NU32)((NI)((NU32)(result) << (NU32)(10))));
	result = (NI)(result ^ (NI)((NU32)(result) >> (NU32)(6)));
	return result;
}

static N_INLINE(NI, sonslen_189181)(tnode188803* n) {
	NI result;
	result = 0;
	{
		if (!(*n).kindU.S6.Sons == 0) goto LA3;
		result = 0;
	}
	goto LA1;
	LA3: ;
	{
		result = (*n).kindU.S6.Sons->Sup.len;
	}
	LA1: ;
	return result;
}

N_NIMCALL(NI, hashtree_247022)(tnode188803* n) {
	NI result;
	result = 0;
	{
		if (!(n == NIM_NIL)) goto LA3;
		goto BeforeRet;
	}
	LA3: ;
	result = ((NI) ((*n).Kind));
	switch ((*n).Kind) {
	case ((NU8) 1):
	case ((NU8) 23):
	case ((NU8) 4):
	{
	}
	break;
	case ((NU8) 2):
	{
		result = HEX21HEX26_119015(result, (*(*n).kindU.S5.Ident).H);
	}
	break;
	case ((NU8) 3):
	{
		result = HEX21HEX26_119015(result, (*(*(*n).kindU.S4.Sym).Name).H);
	}
	break;
	case ((NU8) 5) ... ((NU8) 15):
	{
		{
			NIM_BOOL LOC11;
			LOC11 = 0;
			LOC11 = ((-2147483647 -1) <= (*n).kindU.S1.Intval);
			if (!(LOC11)) goto LA12;
			LOC11 = ((*n).kindU.S1.Intval <= 2147483647);
			LA12: ;
			if (!LOC11) goto LA13;
			result = HEX21HEX26_119015(result, ((NI) ((*n).kindU.S1.Intval)));
		}
		LA13: ;
	}
	break;
	case ((NU8) 16) ... ((NU8) 18):
	{
		{
			NIM_BOOL LOC18;
			LOC18 = 0;
			LOC18 = (-1.0000000000000000e+06 <= (*n).kindU.S2.Floatval);
			if (!(LOC18)) goto LA19;
			LOC18 = ((*n).kindU.S2.Floatval <= 1.0000000000000000e+06);
			LA19: ;
			if (!LOC18) goto LA20;
			result = HEX21HEX26_119015(result, float64ToInt32((*n).kindU.S2.Floatval));
		}
		LA20: ;
	}
	break;
	case ((NU8) 20) ... ((NU8) 22):
	{
		NI LOC23;
		LOC23 = 0;
		LOC23 = hash_119827((*n).kindU.S3.Strval);
		result = HEX21HEX26_119015(result, LOC23);
	}
	break;
	default:
	{
		NI i_247197;
		NI HEX3Atmp_247216;
		NI LOC25;
		NI res_247218;
		i_247197 = 0;
		HEX3Atmp_247216 = 0;
		LOC25 = 0;
		LOC25 = sonslen_189181(n);
		HEX3Atmp_247216 = (NI32)(LOC25 - 1);
		res_247218 = 0;
		while (1) {
			NI LOC27;
			if (!(res_247218 <= HEX3Atmp_247216)) goto LA26;
			i_247197 = res_247218;
			LOC27 = 0;
			LOC27 = hashtree_247022((*n).kindU.S6.Sons->data[i_247197]);
			result = HEX21HEX26_119015(result, LOC27);
			res_247218 += 1;
		} LA26: ;
	}
	break;
	}
	BeforeRet: ;
	return result;
}

static N_INLINE(NIM_BOOL, eqStrings)(NimStringDesc* a, NimStringDesc* b) {
	NIM_BOOL result;
	NIM_BOOL LOC11;
	int LOC13;
	result = 0;
	{
		if (!(a == b)) goto LA3;
		result = NIM_TRUE;
		goto BeforeRet;
	}
	LA3: ;
	{
		NIM_BOOL LOC7;
		LOC7 = 0;
		LOC7 = (a == NIM_NIL);
		if (LOC7) goto LA8;
		LOC7 = (b == NIM_NIL);
		LA8: ;
		if (!LOC7) goto LA9;
		result = NIM_FALSE;
		goto BeforeRet;
	}
	LA9: ;
	LOC11 = 0;
	LOC11 = ((*a).Sup.len == (*b).Sup.len);
	if (!(LOC11)) goto LA12;
	LOC13 = 0;
	LOC13 = memcmp(((NCSTRING) ((*a).data)), ((NCSTRING) ((*b).data)), (NI32)((*a).Sup.len * 1));
	LOC11 = (LOC13 == ((NI32) 0));
	LA12: ;
	result = LOC11;
	goto BeforeRet;
	BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_BOOL, treesequivalent_247223)(tnode188803* a, tnode188803* b) {
	NIM_BOOL result;
	result = 0;
	{
		if (!(a == b)) goto LA3;
		result = NIM_TRUE;
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC6;
		NIM_BOOL LOC7;
		LOC6 = 0;
		LOC7 = 0;
		LOC7 = !((a == NIM_NIL));
		if (!(LOC7)) goto LA8;
		LOC7 = !((b == NIM_NIL));
		LA8: ;
		LOC6 = LOC7;
		if (!(LOC6)) goto LA9;
		LOC6 = ((*a).Kind == (*b).Kind);
		LA9: ;
		if (!LOC6) goto LA10;
		switch ((*a).Kind) {
		case ((NU8) 1):
		case ((NU8) 23):
		case ((NU8) 4):
		{
			result = NIM_TRUE;
		}
		break;
		case ((NU8) 3):
		{
			result = ((*(*a).kindU.S4.Sym).Sup.Id == (*(*b).kindU.S4.Sym).Sup.Id);
		}
		break;
		case ((NU8) 2):
		{
			result = ((*(*a).kindU.S5.Ident).Sup.Id == (*(*b).kindU.S5.Ident).Sup.Id);
		}
		break;
		case ((NU8) 5) ... ((NU8) 15):
		{
			result = ((*a).kindU.S1.Intval == (*b).kindU.S1.Intval);
		}
		break;
		case ((NU8) 16) ... ((NU8) 18):
		{
			result = ((*a).kindU.S2.Floatval == (*b).kindU.S2.Floatval);
		}
		break;
		case ((NU8) 20) ... ((NU8) 22):
		{
			result = eqStrings((*a).kindU.S3.Strval, (*b).kindU.S3.Strval);
		}
		break;
		default:
		{
			{
				NI LOC21;
				NI LOC22;
				NI i_247439;
				NI HEX3Atmp_247468;
				NI LOC25;
				NI res_247470;
				LOC21 = 0;
				LOC21 = sonslen_189181(a);
				LOC22 = 0;
				LOC22 = sonslen_189181(b);
				if (!(LOC21 == LOC22)) goto LA23;
				i_247439 = 0;
				HEX3Atmp_247468 = 0;
				LOC25 = 0;
				LOC25 = sonslen_189181(a);
				HEX3Atmp_247468 = (NI32)(LOC25 - 1);
				res_247470 = 0;
				while (1) {
					if (!(res_247470 <= HEX3Atmp_247468)) goto LA26;
					i_247439 = res_247470;
					{
						NIM_BOOL LOC29;
						LOC29 = 0;
						LOC29 = treesequivalent_247223((*a).kindU.S6.Sons->data[i_247439], (*b).kindU.S6.Sons->data[i_247439]);
						if (!!(LOC29)) goto LA30;
						goto BeforeRet;
					}
					LA30: ;
					res_247470 += 1;
				} LA26: ;
				result = NIM_TRUE;
			}
			LA23: ;
		}
		break;
		}
		{
			if (!result) goto LA34;
			result = sametypeornil_228128((*a).Typ, (*b).Typ, 0);
		}
		LA34: ;
	}
	goto LA1;
	LA10: ;
	LA1: ;
	BeforeRet: ;
	return result;
}

static N_INLINE(NI, nexttry_197192)(NI h, NI maxhash) {
	NI result;
	result = 0;
	result = (NI)((NI32)((NI32)(5 * h) + 1) & maxhash);
	return result;
}

N_NIMCALL(NI, nodetablerawget_247475)(tnodetable188861 t, NI k, tnode188803* key) {
	NI result;
	NI h;
	result = 0;
	h = (NI)(k & (t.Data->Sup.len-1));
	while (1) {
		if (!!((t.Data->data[h].Key == NIM_NIL))) goto LA1;
		{
			NIM_BOOL LOC4;
			LOC4 = 0;
			LOC4 = (t.Data->data[h].H == k);
			if (!(LOC4)) goto LA5;
			LOC4 = treesequivalent_247223(t.Data->data[h].Key, key);
			LA5: ;
			if (!LOC4) goto LA6;
			result = h;
			goto BeforeRet;
		}
		LA6: ;
		h = nexttry_197192(h, (t.Data->Sup.len-1));
	} LA1: ;
	result = -1;
	BeforeRet: ;
	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(void, nodetablerawinsert_247514)(tnodepairseq188859** data, NI k, tnode188803* key, NI val) {
	NI h;
	h = (NI)(k & ((*data)->Sup.len-1));
	while (1) {
		if (!!(((*data)->data[h].Key == NIM_NIL))) goto LA1;
		h = nexttry_197192(h, ((*data)->Sup.len-1));
	} LA1: ;
	(*data)->data[h].H = k;
	asgnRefNoCycle((void**) &(*data)->data[h].Key, key);
	(*data)->data[h].Val = val;
}

N_NIMCALL(NI, nodetabletestorset_247911)(tnodetable188861* t, tnode188803* key, NI val) {
	NI result;
	tnodepairseq188859* n;
	NI k;
	NI index;
	result = 0;
	n = 0;
	k = hashtree_247022(key);
	index = nodetablerawget_247475((*t), k, key);
	{
		if (!(0 <= index)) goto LA3;
		result = (*t).Data->data[index].Val;
	}
	goto LA1;
	LA3: ;
	{
		{
			NIM_BOOL LOC8;
			NI i_248051;
			NI HEX3Atmp_248104;
			NI res_248106;
			tnodepairseq188859* LOC16;
			LOC8 = 0;
			LOC8 = mustrehash_197187((*t).Data->Sup.len, (*t).Counter);
			if (!LOC8) goto LA9;
			n = (tnodepairseq188859*) newSeq((&NTI188859), (NI32)((*t).Data->Sup.len * 2));
			i_248051 = 0;
			HEX3Atmp_248104 = 0;
			HEX3Atmp_248104 = ((*t).Data->Sup.len-1);
			res_248106 = 0;
			while (1) {
				if (!(res_248106 <= HEX3Atmp_248104)) goto LA11;
				i_248051 = res_248106;
				{
					if (!!(((*t).Data->data[i_248051].Key == NIM_NIL))) goto LA14;
					nodetablerawinsert_247514(&n, (*t).Data->data[i_248051].H, (*t).Data->data[i_248051].Key, (*t).Data->data[i_248051].Val);
				}
				LA14: ;
				res_248106 += 1;
			} LA11: ;
			LOC16 = 0;
			LOC16 = (*t).Data;
			unsureAsgnRef((void**) &(*t).Data, n);
			n = LOC16;
		}
		LA9: ;
		nodetablerawinsert_247514(&(*t).Data, k, key, val);
		result = val;
		(*t).Counter += 1;
	}
	LA1: ;
	return result;
}
N_NOINLINE(void, treetabInit)(void) {
}

N_NOINLINE(void, treetabDatInit)(void) {
}

