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

#include <string.h>
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct tlistentry118017 tlistentry118017;
typedef struct TNimObject TNimObject;
typedef struct tlinkedlist118023 tlinkedlist118023;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct tstrentry118019 tstrentry118019;
typedef struct tcell41090 tcell41090;
typedef struct tcellset41102 tcellset41102;
typedef struct tgcheap43016 tgcheap43016;
typedef struct tcellseq41106 tcellseq41106;
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  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  tlistentry118017  {
  TNimObject Sup;
tlistentry118017* Prev;
tlistentry118017* Next;
};
struct  tlinkedlist118023  {
tlistentry118017* Head;
tlistentry118017* Tail;
NI Counter;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  tstrentry118019  {
  tlistentry118017 Sup;
NimStringDesc* Data;
};
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;
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP768)(void* p, NI op);
static N_INLINE(NIM_BOOL, eqStrings)(NimStringDesc* a, NimStringDesc* b);
N_NIMCALL(void, prepend_118283)(tlinkedlist118023* list, tlistentry118017* entry);
static N_INLINE(void, asgnRef)(void** dest, void* src);
static N_INLINE(void, incref_46827)(tcell41090* c);
static N_INLINE(NIM_BOOL, canbecycleroot_44462)(tcell41090* c);
static N_INLINE(void, rtladdcycleroot_45235)(tcell41090* c);
N_NOINLINE(void, incl_41855)(tcellset41102* s, tcell41090* cell);
static N_INLINE(tcell41090*, usrtocell_44443)(void* usr);
static N_INLINE(void, decref_46402)(tcell41090* c);
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);
N_NIMCALL(tstrentry118019*, newstrentry_118246)(NimStringDesc* data);
N_NIMCALL(void, TMP1152)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
N_NIMCALL(NimStringDesc*, copyStringRC1)(NimStringDesc* src);
static N_INLINE(void, nimGCunrefNoCycle)(void* p);
N_NIMCALL(void, remove_118652)(tlinkedlist118023* list, tlistentry118017* entry);
N_NIMCALL(void, append_118042)(tlinkedlist118023* list, tlistentry118017* entry);
N_NIMCALL(NIM_BOOL, contains_118220)(tlinkedlist118023 list, NimStringDesc* data);
N_NIMCALL(void, appendstr_118268)(tlinkedlist118023* list, NimStringDesc* data);
extern TNimType NTI2409; /* TObject */
TNimType NTI118017; /* TListEntry */
TNimType NTI118015; /* PListEntry */
TNimType NTI118023; /* TLinkedList */
extern TNimType NTI106; /* int */
extern tgcheap43016 gch_43044;
TNimType NTI118019; /* TStrEntry */
extern TNimType NTI143; /* string */
TNimType NTI118021; /* PStrEntry */
N_NIMCALL(void, TMP768)(void* p, NI op) {
	tlistentry118017* a;
	a = (tlistentry118017*)p;
	nimGCvisit((void*)(*a).Prev, op);
	nimGCvisit((void*)(*a).Next, op);
}

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, contains_118220)(tlinkedlist118023 list, NimStringDesc* data) {
	NIM_BOOL result;
	tlistentry118017* it;
	result = 0;
	it = list.Head;
	while (1) {
		if (!!((it == NIM_NIL))) goto LA1;
		{
			if (!eqStrings((*((tstrentry118019*) (it))).Data, data)) goto LA4;
			result = NIM_TRUE;
			goto BeforeRet;
		}
		LA4: ;
		it = (*it).Next;
	} LA1: ;
	BeforeRet: ;
	return result;
}

static N_INLINE(NIM_BOOL, canbecycleroot_44462)(tcell41090* c) {
	NIM_BOOL result;
	result = 0;
	result = !((((*(*c).Typ).flags &(1<<((((NU8) 1))&7)))!=0));
	return result;
}

static N_INLINE(void, rtladdcycleroot_45235)(tcell41090* c) {
	{
		if (!!((((NI) ((NI)((*c).Refcount & 3))) == 3))) goto LA3;
		(*c).Refcount = (NI)((NI)((*c).Refcount & -4) | 3);
		incl_41855(&gch_43044.Cycleroots, c);
	}
	LA3: ;
}

static N_INLINE(void, incref_46827)(tcell41090* c) {
	(*c).Refcount = (NI)((NU32)((*c).Refcount) + (NU32)(8));
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = canbecycleroot_44462(c);
		if (!LOC3) goto LA4;
		rtladdcycleroot_45235(c);
	}
	LA4: ;
}

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, decref_46402)(tcell41090* c) {
	{
		(*c).Refcount -= 8;
		if (!((NU32)((*c).Refcount) < (NU32)(8))) goto LA3;
		rtladdzct_46002(c);
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC6;
		LOC6 = 0;
		LOC6 = canbecycleroot_44462(c);
		if (!LOC6) goto LA7;
		rtladdcycleroot_45235(c);
	}
	goto LA1;
	LA7: ;
	LA1: ;
}

static N_INLINE(void, asgnRef)(void** dest, void* src) {
	{
		tcell41090* LOC5;
		if (!!((src == NIM_NIL))) goto LA3;
		LOC5 = 0;
		LOC5 = usrtocell_44443(src);
		incref_46827(LOC5);
	}
	LA3: ;
	{
		tcell41090* LOC10;
		if (!!(((*dest) == NIM_NIL))) goto LA8;
		LOC10 = 0;
		LOC10 = usrtocell_44443((*dest));
		decref_46402(LOC10);
	}
	LA8: ;
	(*dest) = src;
}

N_NIMCALL(void, prepend_118283)(tlinkedlist118023* list, tlistentry118017* entry) {
	(*list).Counter += 1;
	asgnRef((void**) &(*entry).Prev, NIM_NIL);
	asgnRef((void**) &(*entry).Next, (*list).Head);
	{
		if (!!(((*list).Head == NIM_NIL))) goto LA3;
		asgnRef((void**) &(*(*list).Head).Prev, entry);
	}
	LA3: ;
	unsureAsgnRef((void**) &(*list).Head, entry);
	{
		if (!((*list).Tail == NIM_NIL)) goto LA7;
		unsureAsgnRef((void**) &(*list).Tail, entry);
	}
	LA7: ;
}
N_NIMCALL(void, TMP1152)(void* p, NI op) {
	tstrentry118019* a;
	a = (tstrentry118019*)p;
	nimGCvisit((void*)(*a).Sup.Prev, op);
	nimGCvisit((void*)(*a).Sup.Next, op);
	nimGCvisit((void*)(*a).Data, op);
}

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(tstrentry118019*, newstrentry_118246)(NimStringDesc* data) {
	tstrentry118019* result;
	NimStringDesc* LOC1;
	result = 0;
	result = (tstrentry118019*) newObj((&NTI118021), sizeof(tstrentry118019));
	(*result).Sup.Sup.m_type = (&NTI118019);
	LOC1 = 0;
	LOC1 = (*result).Data; (*result).Data = copyStringRC1(data);
	if (LOC1) nimGCunrefNoCycle(LOC1);
	return result;
}

N_NIMCALL(void, prependstr_118420)(tlinkedlist118023* list, NimStringDesc* data) {
	tstrentry118019* LOC1;
	LOC1 = 0;
	LOC1 = newstrentry_118246(data);
	prepend_118283(list, &LOC1->Sup);
}

N_NIMCALL(void, remove_118652)(tlinkedlist118023* list, tlistentry118017* entry) {
	(*list).Counter -= 1;
	{
		if (!(entry == (*list).Tail)) goto LA3;
		unsureAsgnRef((void**) &(*list).Tail, (*entry).Prev);
	}
	LA3: ;
	{
		if (!(entry == (*list).Head)) goto LA7;
		unsureAsgnRef((void**) &(*list).Head, (*entry).Next);
	}
	LA7: ;
	{
		if (!!(((*entry).Next == NIM_NIL))) goto LA11;
		asgnRef((void**) &(*(*entry).Next).Prev, (*entry).Prev);
	}
	LA11: ;
	{
		if (!!(((*entry).Prev == NIM_NIL))) goto LA15;
		asgnRef((void**) &(*(*entry).Prev).Next, (*entry).Next);
	}
	LA15: ;
}

N_NIMCALL(void, excludestr_118803)(tlinkedlist118023* list, NimStringDesc* data) {
	tlistentry118017* it;
	it = (*list).Head;
	while (1) {
		tlistentry118017* nxt;
		if (!!((it == NIM_NIL))) goto LA1;
		nxt = (*it).Next;
		{
			if (!eqStrings((*((tstrentry118019*) (it))).Data, data)) goto LA4;
			remove_118652(list, it);
		}
		LA4: ;
		it = nxt;
	} LA1: ;
}

N_NIMCALL(void, bringtofront_118741)(tlinkedlist118023* list, tlistentry118017* entry) {
	remove_118652(list, entry);
	prepend_118283(list, entry);
}

N_NIMCALL(void, append_118042)(tlinkedlist118023* list, tlistentry118017* entry) {
	(*list).Counter += 1;
	asgnRef((void**) &(*entry).Next, NIM_NIL);
	asgnRef((void**) &(*entry).Prev, (*list).Tail);
	{
		if (!!(((*list).Tail == NIM_NIL))) goto LA3;
		asgnRef((void**) &(*(*list).Tail).Next, entry);
	}
	LA3: ;
	unsureAsgnRef((void**) &(*list).Tail, entry);
	{
		if (!((*list).Head == NIM_NIL)) goto LA7;
		unsureAsgnRef((void**) &(*list).Head, entry);
	}
	LA7: ;
}

N_NIMCALL(void, appendstr_118268)(tlinkedlist118023* list, NimStringDesc* data) {
	tstrentry118019* LOC1;
	LOC1 = 0;
	LOC1 = newstrentry_118246(data);
	append_118042(list, &LOC1->Sup);
}

N_NIMCALL(void, initlinkedlist_118036)(tlinkedlist118023* list) {
	(*list).Counter = 0;
	unsureAsgnRef((void**) &(*list).Head, NIM_NIL);
	unsureAsgnRef((void**) &(*list).Tail, NIM_NIL);
}

N_NIMCALL(NIM_BOOL, includestr_118275)(tlinkedlist118023* list, NimStringDesc* data) {
	NIM_BOOL result;
	result = 0;
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = contains_118220((*list), data);
		if (!LOC3) goto LA4;
		result = NIM_TRUE;
		goto BeforeRet;
	}
	LA4: ;
	appendstr_118268(list, data);
	BeforeRet: ;
	return result;
}
N_NOINLINE(void, listsInit)(void) {
}

N_NOINLINE(void, listsDatInit)(void) {
static TNimNode* TMP767[2];
static TNimNode* TMP949[3];
static TNimNode TMP23[8];
NTI118017.size = sizeof(tlistentry118017);
NTI118017.kind = 17;
NTI118017.base = (&NTI2409);
TMP767[0] = &TMP23[1];
NTI118015.size = sizeof(tlistentry118017*);
NTI118015.kind = 22;
NTI118015.base = (&NTI118017);
NTI118015.marker = TMP768;
TMP23[1].kind = 1;
TMP23[1].offset = offsetof(tlistentry118017, Prev);
TMP23[1].typ = (&NTI118015);
TMP23[1].name = "prev";
TMP767[1] = &TMP23[2];
TMP23[2].kind = 1;
TMP23[2].offset = offsetof(tlistentry118017, Next);
TMP23[2].typ = (&NTI118015);
TMP23[2].name = "next";
TMP23[0].len = 2; TMP23[0].kind = 2; TMP23[0].sons = &TMP767[0];
NTI118017.node = &TMP23[0];
NTI118023.size = sizeof(tlinkedlist118023);
NTI118023.kind = 18;
NTI118023.base = 0;
TMP949[0] = &TMP23[4];
TMP23[4].kind = 1;
TMP23[4].offset = offsetof(tlinkedlist118023, Head);
TMP23[4].typ = (&NTI118015);
TMP23[4].name = "head";
TMP949[1] = &TMP23[5];
TMP23[5].kind = 1;
TMP23[5].offset = offsetof(tlinkedlist118023, Tail);
TMP23[5].typ = (&NTI118015);
TMP23[5].name = "tail";
TMP949[2] = &TMP23[6];
TMP23[6].kind = 1;
TMP23[6].offset = offsetof(tlinkedlist118023, Counter);
TMP23[6].typ = (&NTI106);
TMP23[6].name = "counter";
TMP23[3].len = 3; TMP23[3].kind = 2; TMP23[3].sons = &TMP949[0];
NTI118023.node = &TMP23[3];
NTI118019.size = sizeof(tstrentry118019);
NTI118019.kind = 17;
NTI118019.base = (&NTI118017);
TMP23[7].kind = 1;
TMP23[7].offset = offsetof(tstrentry118019, Data);
TMP23[7].typ = (&NTI143);
TMP23[7].name = "data";
NTI118019.node = &TMP23[7];
NTI118021.size = sizeof(tstrentry118019*);
NTI118021.kind = 22;
NTI118021.base = (&NTI118019);
NTI118021.marker = TMP1152;
}

