/* 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_strtabs.o compiler/nimcache/stdlib_strtabs.c */
#define NIM_INTBITS 32
#include "nimbase.h"
typedef struct tstringtable121810 tstringtable121810;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct tkeyvaluepairseq121808 tkeyvaluepairseq121808;
typedef struct tkeyvaluepair121806 tkeyvaluepair121806;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
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 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  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct tkeyvaluepair121806 {
NimStringDesc* Field0;
NimStringDesc* Field1;
};
struct  tstringtable121810  {
  TNimObject Sup;
NI Counter;
tkeyvaluepairseq121808* Data;
NU8 Mode;
};
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 tkeyvaluepairseq121808 {
  TGenericSeq Sup;
  tkeyvaluepair121806 data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP42)(void* p, NI op);
N_NIMCALL(void, TMP46)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
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*, newSeqRC1)(TNimType* typ, NI len);
N_NIMCALL(NI, rawget_122012)(tstringtable121810* t, NimStringDesc* key);
N_NIMCALL(NI, myhash_121908)(tstringtable121810* t, NimStringDesc* key);
N_NIMCALL(NI, hash_119827)(NimStringDesc* x);
N_NIMCALL(NI, hashignorecase_119935)(NimStringDesc* x);
N_NIMCALL(NI, hashignorestyle_119859)(NimStringDesc* x);
N_NIMCALL(NIM_BOOL, mycmp_121915)(tstringtable121810* t, NimStringDesc* a, NimStringDesc* b);
N_NIMCALL(NI, cmp_3490)(NimStringDesc* x, NimStringDesc* y);
N_NIMCALL(NI, nsuCmpIgnoreCase)(NimStringDesc* a, NimStringDesc* b);
N_NIMCALL(NI, nsuCmpIgnoreStyle)(NimStringDesc* a, NimStringDesc* b);
static N_INLINE(NI, nexttry_122005)(NI h, NI maxhash);
N_NIMCALL(NimStringDesc*, copyStringRC1)(NimStringDesc* src);
N_NIMCALL(NIM_BOOL, mustrehash_121923)(NI length, NI counter);
N_NIMCALL(void, enlarge_122080)(tstringtable121810* t);
N_NIMCALL(void*, newSeq)(TNimType* typ, NI len);
N_NIMCALL(void, rawinsert_122068)(tstringtable121810* t, tkeyvaluepairseq121808** data, NimStringDesc* key, NimStringDesc* val);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
STRING_LITERAL(TMP1171, "", 0);
extern TNimType NTI2409; /* TObject */
TNimType NTI121810; /* TStringTable */
extern TNimType NTI106; /* int */
TNimType NTI121806; /* TKeyValuePair */
extern TNimType NTI143; /* string */
TNimType NTI121808; /* TKeyValuePairSeq */
TNimType NTI121804; /* TStringTableMode */
TNimType NTI121812; /* PStringTable */
extern tgcheap43016 gch_43044;
N_NIMCALL(void, TMP42)(void* p, NI op) {
	tkeyvaluepairseq121808* a;
	NI LOC1;
	a = (tkeyvaluepairseq121808*)p;
	LOC1 = 0;
	for (LOC1 = 0; LOC1 < a->Sup.len; LOC1++) {
	nimGCvisit((void*)a->data[LOC1].Field0, op);
	nimGCvisit((void*)a->data[LOC1].Field1, op);
	}
}
N_NIMCALL(void, TMP46)(void* p, NI op) {
	tstringtable121810* a;
	a = (tstringtable121810*)p;
	nimGCvisit((void*)(*a).Data, op);
}

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(tstringtable121810*, nstnewStringTable)(NU8 mode) {
	tstringtable121810* result;
	result = 0;
	result = (tstringtable121810*) newObj((&NTI121812), sizeof(tstringtable121810));
	(*result).Sup.m_type = (&NTI121810);
	(*result).Mode = mode;
	(*result).Counter = 0;
	if ((*result).Data) nimGCunrefNoCycle((*result).Data);
	(*result).Data = (tkeyvaluepairseq121808*) newSeqRC1((&NTI121808), 64);
	return result;
}

N_NIMCALL(NI, myhash_121908)(tstringtable121810* t, NimStringDesc* key) {
	NI result;
	result = 0;
	switch ((*t).Mode) {
	case ((NU8) 0):
	{
		result = hash_119827(key);
	}
	break;
	case ((NU8) 1):
	{
		result = hashignorecase_119935(key);
	}
	break;
	case ((NU8) 2):
	{
		result = hashignorestyle_119859(key);
	}
	break;
	}
	return result;
}

N_NIMCALL(NIM_BOOL, mycmp_121915)(tstringtable121810* t, NimStringDesc* a, NimStringDesc* b) {
	NIM_BOOL result;
	result = 0;
	switch ((*t).Mode) {
	case ((NU8) 0):
	{
		NI LOC2;
		LOC2 = 0;
		LOC2 = cmp_3490(a, b);
		result = (LOC2 == 0);
	}
	break;
	case ((NU8) 1):
	{
		NI LOC4;
		LOC4 = 0;
		LOC4 = nsuCmpIgnoreCase(a, b);
		result = (LOC4 == 0);
	}
	break;
	case ((NU8) 2):
	{
		NI LOC6;
		LOC6 = 0;
		LOC6 = nsuCmpIgnoreStyle(a, b);
		result = (LOC6 == 0);
	}
	break;
	}
	return result;
}

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

N_NIMCALL(NI, rawget_122012)(tstringtable121810* t, NimStringDesc* key) {
	NI result;
	NI h;
	NI LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = myhash_121908(t, key);
	h = (NI)(LOC1 & ((*t).Data->Sup.len-1));
	while (1) {
		if (!!((*t).Data->data[h].Field0 == 0)) goto LA2;
		{
			NIM_BOOL LOC5;
			LOC5 = 0;
			LOC5 = mycmp_121915(t, (*t).Data->data[h].Field0, key);
			if (!LOC5) goto LA6;
			result = h;
			goto BeforeRet;
		}
		LA6: ;
		h = nexttry_122005(h, ((*t).Data->Sup.len-1));
	} LA2: ;
	result = -1;
	BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_BOOL, mustrehash_121923)(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;
}

N_NIMCALL(void, rawinsert_122068)(tstringtable121810* t, tkeyvaluepairseq121808** data, NimStringDesc* key, NimStringDesc* val) {
	NI h;
	NI LOC1;
	NimStringDesc* LOC3;
	NimStringDesc* LOC4;
	LOC1 = 0;
	LOC1 = myhash_121908(t, key);
	h = (NI)(LOC1 & ((*data)->Sup.len-1));
	while (1) {
		if (!!((*data)->data[h].Field0 == 0)) goto LA2;
		h = nexttry_122005(h, ((*data)->Sup.len-1));
	} LA2: ;
	LOC3 = 0;
	LOC3 = (*data)->data[h].Field0; (*data)->data[h].Field0 = copyStringRC1(key);
	if (LOC3) nimGCunrefNoCycle(LOC3);
	LOC4 = 0;
	LOC4 = (*data)->data[h].Field1; (*data)->data[h].Field1 = copyStringRC1(val);
	if (LOC4) nimGCunrefNoCycle(LOC4);
}

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, enlarge_122080)(tstringtable121810* t) {
	tkeyvaluepairseq121808* n;
	NI i_122123;
	NI HEX3Atmp_122141;
	NI res_122143;
	tkeyvaluepairseq121808* LOC6;
	n = 0;
	n = (tkeyvaluepairseq121808*) newSeq((&NTI121808), (NI32)((*t).Data->Sup.len * 2));
	i_122123 = 0;
	HEX3Atmp_122141 = 0;
	HEX3Atmp_122141 = ((*t).Data->Sup.len-1);
	res_122143 = 0;
	while (1) {
		if (!(res_122143 <= HEX3Atmp_122141)) goto LA1;
		i_122123 = res_122143;
		{
			if (!!((*t).Data->data[i_122123].Field0 == 0)) goto LA4;
			rawinsert_122068(t, &n, (*t).Data->data[i_122123].Field0, (*t).Data->data[i_122123].Field1);
		}
		LA4: ;
		res_122143 += 1;
	} LA1: ;
	LOC6 = 0;
	LOC6 = (*t).Data;
	asgnRefNoCycle((void**) &(*t).Data, n);
	n = LOC6;
}

N_NIMCALL(void, nstPut)(tstringtable121810* t, NimStringDesc* key, NimStringDesc* val) {
	NI index;
	index = rawget_122012(t, key);
	{
		NimStringDesc* LOC5;
		if (!(0 <= index)) goto LA3;
		LOC5 = 0;
		LOC5 = (*t).Data->data[index].Field1; (*t).Data->data[index].Field1 = copyStringRC1(val);
		if (LOC5) nimGCunrefNoCycle(LOC5);
	}
	goto LA1;
	LA3: ;
	{
		{
			NIM_BOOL LOC9;
			LOC9 = 0;
			LOC9 = mustrehash_121923((*t).Data->Sup.len, (*t).Counter);
			if (!LOC9) goto LA10;
			enlarge_122080(t);
		}
		LA10: ;
		rawinsert_122068(t, &(*t).Data, key, val);
		(*t).Counter += 1;
	}
	LA1: ;
}

N_NIMCALL(NimStringDesc*, nstGet)(tstringtable121810* t, NimStringDesc* key) {
	NimStringDesc* result;
	NI index;
	result = 0;
	index = rawget_122012(t, key);
	{
		if (!(0 <= index)) goto LA3;
		result = copyString((*t).Data->data[index].Field1);
	}
	goto LA1;
	LA3: ;
	{
		result = copyString(((NimStringDesc*) &TMP1171));
	}
	LA1: ;
	return result;
}

N_NIMCALL(NIM_BOOL, nsthasKey)(tstringtable121810* t, NimStringDesc* key) {
	NIM_BOOL result;
	NI LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = rawget_122012(t, key);
	result = (0 <= LOC1);
	return result;
}

N_NIMCALL(NI, nstlen)(tstringtable121810* t) {
	NI result;
	result = 0;
	result = (*t).Counter;
	return result;
}
N_NOINLINE(void, stdlibstrtabsInit)(void) {
}

N_NOINLINE(void, stdlibstrtabsDatInit)(void) {
static TNimNode* TMP40[3];
static TNimNode* TMP41[2];
static TNimNode* TMP43[3];
NI TMP45;
static char* NIM_CONST TMP44[3] = {
"modeCaseSensitive", 
"modeCaseInsensitive", 
"modeStyleInsensitive"};
static TNimNode TMP25[11];
NTI121810.size = sizeof(tstringtable121810);
NTI121810.kind = 17;
NTI121810.base = (&NTI2409);
TMP40[0] = &TMP25[1];
TMP25[1].kind = 1;
TMP25[1].offset = offsetof(tstringtable121810, Counter);
TMP25[1].typ = (&NTI106);
TMP25[1].name = "counter";
TMP40[1] = &TMP25[2];
NTI121806.size = sizeof(tkeyvaluepair121806);
NTI121806.kind = 18;
NTI121806.base = 0;
NTI121806.flags = 2;
TMP41[0] = &TMP25[4];
TMP25[4].kind = 1;
TMP25[4].offset = offsetof(tkeyvaluepair121806, Field0);
TMP25[4].typ = (&NTI143);
TMP25[4].name = "Field0";
TMP41[1] = &TMP25[5];
TMP25[5].kind = 1;
TMP25[5].offset = offsetof(tkeyvaluepair121806, Field1);
TMP25[5].typ = (&NTI143);
TMP25[5].name = "Field1";
TMP25[3].len = 2; TMP25[3].kind = 2; TMP25[3].sons = &TMP41[0];
NTI121806.node = &TMP25[3];
NTI121808.size = sizeof(tkeyvaluepairseq121808*);
NTI121808.kind = 24;
NTI121808.base = (&NTI121806);
NTI121808.flags = 2;
NTI121808.marker = TMP42;
TMP25[2].kind = 1;
TMP25[2].offset = offsetof(tstringtable121810, Data);
TMP25[2].typ = (&NTI121808);
TMP25[2].name = "data";
TMP40[2] = &TMP25[6];
NTI121804.size = sizeof(NU8);
NTI121804.kind = 14;
NTI121804.base = 0;
NTI121804.flags = 3;
for (TMP45 = 0; TMP45 < 3; TMP45++) {
TMP25[TMP45+7].kind = 1;
TMP25[TMP45+7].offset = TMP45;
TMP25[TMP45+7].name = TMP44[TMP45];
TMP43[TMP45] = &TMP25[TMP45+7];
}
TMP25[10].len = 3; TMP25[10].kind = 2; TMP25[10].sons = &TMP43[0];
NTI121804.node = &TMP25[10];
TMP25[6].kind = 1;
TMP25[6].offset = offsetof(tstringtable121810, Mode);
TMP25[6].typ = (&NTI121804);
TMP25[6].name = "mode";
TMP25[0].len = 3; TMP25[0].kind = 2; TMP25[0].sons = &TMP40[0];
NTI121810.node = &TMP25[0];
NTI121812.size = sizeof(tstringtable121810*);
NTI121812.kind = 22;
NTI121812.base = (&NTI121810);
NTI121812.marker = TMP46;
}

