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

#include <string.h>
typedef struct ttable163560 ttable163560;
typedef struct tkeyvaluepairseq163563 tkeyvaluepairseq163563;
typedef struct tkeyvaluepair163566 tkeyvaluepair163566;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
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];
};
struct tkeyvaluepair163566 {
NU8 Field0;
NimStringDesc* Field1;
NI32 Field2;
};
struct  ttable163560  {
tkeyvaluepairseq163563* Data;
NI Counter;
};
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  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;
};
struct tkeyvaluepairseq163563 {
  TGenericSeq Sup;
  tkeyvaluepair163566 data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP134)(void* p, NI op);
N_NIMCALL(void*, newSeq)(TNimType* typ, NI len);
N_NIMCALL(void, unsureAsgnRef)(void** dest, void* src);
N_NIMCALL(NI, rawget_163744)(ttable163560 t_163751, NimStringDesc* key_163754);
N_NIMCALL(NI, hash_119827)(NimStringDesc* x);
static N_INLINE(NIM_BOOL, eqStrings)(NimStringDesc* a, NimStringDesc* b);
static N_INLINE(NI, nexttry_139605)(NI h, NI maxhash);
static N_INLINE(NIM_BOOL, mustrehash_139414)(NI length, NI counter);
N_NIMCALL(void, enlarge_163886)(ttable163560* t_163895);
N_NIMCALL(void, rawinsert_163956)(ttable163560* t_163965, tkeyvaluepairseq163563** data_163973, NimStringDesc* key_163977, NI32 val_163979);
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);
TNimType NTI163566; /* TKeyValuePair */
TNimType NTI139010; /* TSlotEnum */
extern TNimType NTI143; /* string */
extern TNimType NTI112; /* int32 */
TNimType NTI163563; /* TKeyValuePairSeq */
TNimType NTI163560; /* TTable */
extern TNimType NTI106; /* int */
extern tgcheap43016 gch_43044;
N_NIMCALL(void, TMP134)(void* p, NI op) {
	tkeyvaluepairseq163563* a;
	NI LOC1;
	a = (tkeyvaluepairseq163563*)p;
	LOC1 = 0;
	for (LOC1 = 0; LOC1 < a->Sup.len; LOC1++) {
	nimGCvisit((void*)a->data[LOC1].Field1, op);
	}
}

N_NIMCALL(void, inittable_163552)(NI initialsize_163557, ttable163560* Result) {
	(*Result).Counter = 0;
	unsureAsgnRef((void**) &(*Result).Data, (tkeyvaluepairseq163563*) newSeq((&NTI163563), initialsize_163557));
}

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;
}

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

N_NIMCALL(NI, rawget_163744)(ttable163560 t_163751, NimStringDesc* key_163754) {
	NI result;
	NI h;
	NI LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = hash_119827(key_163754);
	h = (NI)(LOC1 & (t_163751.Data->Sup.len-1));
	while (1) {
		if (!!((t_163751.Data->data[h].Field0 == ((NU8) 0)))) goto LA2;
		{
			NIM_BOOL LOC5;
			LOC5 = 0;
			LOC5 = eqStrings(t_163751.Data->data[h].Field1, key_163754);
			if (!(LOC5)) goto LA6;
			LOC5 = (t_163751.Data->data[h].Field0 == ((NU8) 1));
			LA6: ;
			if (!LOC5) goto LA7;
			result = h;
			goto BeforeRet;
		}
		LA7: ;
		h = nexttry_139605(h, (t_163751.Data->Sup.len-1));
	} LA2: ;
	result = -1;
	BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_BOOL, haskey_163730)(ttable163560 t_163737, NimStringDesc* key_163740) {
	NIM_BOOL result;
	NI LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = rawget_163744(t_163737, key_163740);
	result = (0 <= LOC1);
	return result;
}

N_NIMCALL(NI32, HEX5BHEX5D_163781)(ttable163560 t_163788, NimStringDesc* key_163791) {
	NI32 result;
	NI index;
	result = 0;
	index = rawget_163744(t_163788, key_163791);
	{
		if (!(0 <= index)) goto LA3;
		result = t_163788.Data->data[index].Field2;
	}
	LA3: ;
	return result;
}

static N_INLINE(NIM_BOOL, mustrehash_139414)(NI length, NI counter) {
	NIM_BOOL result;
	NIM_BOOL LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = ((NI32)(length * 2) < (NI32)(counter * 3));
	if (LOC1) goto LA2;
	LOC1 = ((NI32)(length - counter) < 4);
	LA2: ;
	result = LOC1;
	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(void, rawinsert_163956)(ttable163560* t_163965, tkeyvaluepairseq163563** data_163973, NimStringDesc* key_163977, NI32 val_163979) {
	NI h;
	NI LOC1;
	NimStringDesc* LOC3;
	LOC1 = 0;
	LOC1 = hash_119827(key_163977);
	h = (NI)(LOC1 & ((*data_163973)->Sup.len-1));
	while (1) {
		if (!((*data_163973)->data[h].Field0 == ((NU8) 1))) goto LA2;
		h = nexttry_139605(h, ((*data_163973)->Sup.len-1));
	} LA2: ;
	LOC3 = 0;
	LOC3 = (*data_163973)->data[h].Field1; (*data_163973)->data[h].Field1 = copyStringRC1(key_163977);
	if (LOC3) nimGCunrefNoCycle(LOC3);
	(*data_163973)->data[h].Field2 = val_163979;
	(*data_163973)->data[h].Field0 = ((NU8) 1);
}

N_NIMCALL(void, enlarge_163886)(ttable163560* t_163895) {
	tkeyvaluepairseq163563* n;
	NI i_163941;
	NI HEX3Atmp_164011;
	NI res_164013;
	tkeyvaluepairseq163563* LOC6;
	n = 0;
	n = (tkeyvaluepairseq163563*) newSeq((&NTI163563), (NI32)((*t_163895).Data->Sup.len * 2));
	i_163941 = 0;
	HEX3Atmp_164011 = 0;
	HEX3Atmp_164011 = ((*t_163895).Data->Sup.len-1);
	res_164013 = 0;
	while (1) {
		if (!(res_164013 <= HEX3Atmp_164011)) goto LA1;
		i_163941 = res_164013;
		{
			if (!((*t_163895).Data->data[i_163941].Field0 == ((NU8) 1))) goto LA4;
			rawinsert_163956(t_163895, &n, (*t_163895).Data->data[i_163941].Field1, (*t_163895).Data->data[i_163941].Field2);
		}
		LA4: ;
		res_164013 += 1;
	} LA1: ;
	LOC6 = 0;
	LOC6 = (*t_163895).Data;
	unsureAsgnRef((void**) &(*t_163895).Data, n);
	n = LOC6;
}

N_NIMCALL(void, HEX5BHEX5DHEX3D_163841)(ttable163560* t_163850, NimStringDesc* key_163854, NI32 val_163856) {
	NI index;
	index = rawget_163744((*t_163850), key_163854);
	{
		if (!(0 <= index)) goto LA3;
		(*t_163850).Data->data[index].Field2 = val_163856;
	}
	goto LA1;
	LA3: ;
	{
		{
			NIM_BOOL LOC8;
			LOC8 = 0;
			LOC8 = mustrehash_139414((*t_163850).Data->Sup.len, (*t_163850).Counter);
			if (!LOC8) goto LA9;
			enlarge_163886(t_163850);
		}
		LA9: ;
		rawinsert_163956(t_163850, &(*t_163850).Data, key_163854, val_163856);
		(*t_163850).Counter += 1;
	}
	LA1: ;
}
N_NOINLINE(void, stdlibtablesInit)(void) {
}

N_NOINLINE(void, stdlibtablesDatInit)(void) {
static TNimNode* TMP130[3];
static TNimNode* TMP131[3];
NI TMP133;
static char* NIM_CONST TMP132[3] = {
"seEmpty", 
"seFilled", 
"seDeleted"};
static TNimNode* TMP137[2];
static TNimNode TMP53[11];
NTI163566.size = sizeof(tkeyvaluepair163566);
NTI163566.kind = 18;
NTI163566.base = 0;
NTI163566.flags = 2;
TMP130[0] = &TMP53[1];
NTI139010.size = sizeof(NU8);
NTI139010.kind = 14;
NTI139010.base = 0;
NTI139010.flags = 3;
for (TMP133 = 0; TMP133 < 3; TMP133++) {
TMP53[TMP133+2].kind = 1;
TMP53[TMP133+2].offset = TMP133;
TMP53[TMP133+2].name = TMP132[TMP133];
TMP131[TMP133] = &TMP53[TMP133+2];
}
TMP53[5].len = 3; TMP53[5].kind = 2; TMP53[5].sons = &TMP131[0];
NTI139010.node = &TMP53[5];
TMP53[1].kind = 1;
TMP53[1].offset = offsetof(tkeyvaluepair163566, Field0);
TMP53[1].typ = (&NTI139010);
TMP53[1].name = "Field0";
TMP130[1] = &TMP53[6];
TMP53[6].kind = 1;
TMP53[6].offset = offsetof(tkeyvaluepair163566, Field1);
TMP53[6].typ = (&NTI143);
TMP53[6].name = "Field1";
TMP130[2] = &TMP53[7];
TMP53[7].kind = 1;
TMP53[7].offset = offsetof(tkeyvaluepair163566, Field2);
TMP53[7].typ = (&NTI112);
TMP53[7].name = "Field2";
TMP53[0].len = 3; TMP53[0].kind = 2; TMP53[0].sons = &TMP130[0];
NTI163566.node = &TMP53[0];
NTI163563.size = sizeof(tkeyvaluepairseq163563*);
NTI163563.kind = 24;
NTI163563.base = (&NTI163566);
NTI163563.flags = 2;
NTI163563.marker = TMP134;
NTI163560.size = sizeof(ttable163560);
NTI163560.kind = 18;
NTI163560.base = 0;
NTI163560.flags = 2;
TMP137[0] = &TMP53[9];
TMP53[9].kind = 1;
TMP53[9].offset = offsetof(ttable163560, Data);
TMP53[9].typ = (&NTI163563);
TMP53[9].name = "data";
TMP137[1] = &TMP53[10];
TMP53[10].kind = 1;
TMP53[10].offset = offsetof(ttable163560, Counter);
TMP53[10].typ = (&NTI106);
TMP53[10].name = "counter";
TMP53[8].len = 2; TMP53[8].kind = 2; TMP53[8].sons = &TMP137[0];
NTI163560.node = &TMP53[8];
}

