/* Generated by Nim Compiler v0.12.0 */
/*   (c) 2015 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 32

#include "nimbase.h"
#include <string.h>
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Tlistentry141022 Tlistentry141022;
typedef struct TNimObject TNimObject;
typedef struct Tlinkedlist141028 Tlinkedlist141028;
typedef struct Cell49147 Cell49147;
typedef struct Cellset49159 Cellset49159;
typedef struct Gcheap51218 Gcheap51218;
typedef struct Gcstack51216 Gcstack51216;
typedef struct Cellseq49163 Cellseq49163;
typedef struct Pagedesc49155 Pagedesc49155;
typedef struct Memregion31090 Memregion31090;
typedef struct Smallchunk31042 Smallchunk31042;
typedef struct Llchunk31084 Llchunk31084;
typedef struct Bigchunk31044 Bigchunk31044;
typedef struct Intset31017 Intset31017;
typedef struct Trunk31013 Trunk31013;
typedef struct Avlnode31088 Avlnode31088;
typedef struct Gcstat51214 Gcstat51214;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Tstrentry141024 Tstrentry141024;
typedef struct Basechunk31040 Basechunk31040;
typedef struct Freecell31032 Freecell31032;
typedef N_NIMCALL_PTR(void, TY3889) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3894) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3889 marker;
TY3894 deepcopy;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  Tlistentry141022  {
  TNimObject Sup;
Tlistentry141022* prev;
Tlistentry141022* next;
};
struct  Tlinkedlist141028  {
Tlistentry141022* head;
Tlistentry141022* tail;
NI counter;
};
struct  Cell49147  {
NI refcount;
TNimType* typ;
};
struct  Cellseq49163  {
NI len;
NI cap;
Cell49147** d;
};
struct  Cellset49159  {
NI counter;
NI max;
Pagedesc49155* head;
Pagedesc49155** data;
};
typedef Smallchunk31042* TY31105[512];
typedef Trunk31013* Trunkbuckets31015[256];
struct  Intset31017  {
Trunkbuckets31015 data;
};
struct  Memregion31090  {
NI minlargeobj;
NI maxlargeobj;
TY31105 freesmallchunks;
Llchunk31084* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk31044* freechunkslist;
Intset31017 chunkstarts;
Avlnode31088* root;
Avlnode31088* deleted;
Avlnode31088* last;
Avlnode31088* freeavlnodes;
};
struct  Gcstat51214  {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct  Gcheap51218  {
Gcstack51216* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq49163 zct;
Cellseq49163 decstack;
Cellset49159 cycleroots;
Cellseq49163 tempstack;
NI recgclock;
Memregion31090 region;
Gcstat51214 stat;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Tstrentry141024  {
  Tlistentry141022 Sup;
NimStringDesc* data;
};
struct  Gcstack51216  {
Gcstack51216* prev;
Gcstack51216* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY31021[16];
struct  Pagedesc49155  {
Pagedesc49155* next;
NI key;
TY31021 bits;
};
struct  Basechunk31040  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk31042  {
  Basechunk31040 Sup;
Smallchunk31042* next;
Smallchunk31042* prev;
Freecell31032* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk31084  {
NI size;
NI acc;
Llchunk31084* next;
};
struct  Bigchunk31044  {
  Basechunk31040 Sup;
Bigchunk31044* next;
Bigchunk31044* prev;
NI align;
NF data;
};
struct  Trunk31013  {
Trunk31013* next;
NI key;
TY31021 bits;
};
typedef Avlnode31088* TY31095[2];
struct  Avlnode31088  {
TY31095 link;
NI key;
NI upperbound;
NI level;
};
struct  Freecell31032  {
Freecell31032* next;
NI zerofield;
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP854)(void* p, NI op);
N_NIMCALL(void, remove_141639)(Tlinkedlist141028* list, Tlistentry141022* entry);
N_NIMCALL(void, unsureAsgnRef)(void** dest, void* src);
static N_INLINE(void, asgnRef)(void** dest, void* src);
static N_INLINE(void, incref_55222)(Cell49147* c);
static N_INLINE(NIM_BOOL, canbecycleroot_52867)(Cell49147* c);
static N_INLINE(void, rtladdcycleroot_53623)(Cell49147* c);
N_NOINLINE(void, incl_49865)(Cellset49159* s, Cell49147* cell);
static N_INLINE(Cell49147*, usrtocell_52846)(void* usr);
static N_INLINE(void, decref_54804)(Cell49147* c);
static N_INLINE(void, rtladdzct_54404)(Cell49147* c);
N_NOINLINE(void, addzct_52817)(Cellseq49163* s, Cell49147* c);
N_NIMCALL(void, prepend_141291)(Tlinkedlist141028* list, Tlistentry141022* entry);
static N_INLINE(NIM_BOOL, eqStrings)(NimStringDesc* a, NimStringDesc* b);
N_NIMCALL(Tstrentry141024*, newstrentry_141250)(NimStringDesc* data);
N_NIMCALL(void, TMP1749)(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(NI, noscmpPaths)(NimStringDesc* patha, NimStringDesc* pathb);
N_NIMCALL(void, append_141053)(Tlinkedlist141028* list, Tlistentry141022* entry);
N_NIMCALL(NIM_BOOL, contains_141219)(Tlinkedlist141028 list, NimStringDesc* data);
N_NIMCALL(void, appendstr_141268)(Tlinkedlist141028* list, NimStringDesc* data);
extern TNimType NTI4011; /* RootObj */
TNimType NTI141022; /* TListEntry */
TNimType NTI141020; /* PListEntry */
TNimType NTI141028; /* TLinkedList */
extern TNimType NTI108; /* int */
extern Gcheap51218 gch_51259;
TNimType NTI141024; /* TStrEntry */
extern TNimType NTI149; /* string */
TNimType NTI141026; /* PStrEntry */
N_NIMCALL(void, TMP854)(void* p, NI op) {
	Tlistentry141022* a;
	a = (Tlistentry141022*)p;
	nimGCvisit((void*)(*a).prev, op);
	nimGCvisit((void*)(*a).next, op);
}

static N_INLINE(NIM_BOOL, canbecycleroot_52867)(Cell49147* c) {
	NIM_BOOL result;
	result = 0;
	result = !((((*(*c).typ).flags &(1<<((((NU8) 1))&7)))!=0));
	return result;
}

static N_INLINE(void, rtladdcycleroot_53623)(Cell49147* c) {
	{
		if (!!((((NI) ((NI)((*c).refcount & ((NI) 3)))) == ((NI) 3)))) goto LA3;
		(*c).refcount = (NI)((NI)((*c).refcount & ((NI) -4)) | ((NI) 3));
		incl_49865((&gch_51259.cycleroots), c);
	}
	LA3: ;
}

static N_INLINE(void, incref_55222)(Cell49147* c) {
	(*c).refcount = (NI)((NU32)((*c).refcount) + (NU32)(((NI) 8)));
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = canbecycleroot_52867(c);
		if (!LOC3) goto LA4;
		rtladdcycleroot_53623(c);
	}
	LA4: ;
}

static N_INLINE(Cell49147*, usrtocell_52846)(void* usr) {
	Cell49147* result;
	result = 0;
	result = ((Cell49147*) ((NI)((NU32)(((NI) (usr))) - (NU32)(((NI)sizeof(Cell49147))))));
	return result;
}

static N_INLINE(void, rtladdzct_54404)(Cell49147* c) {
	addzct_52817((&gch_51259.zct), c);
}

static N_INLINE(void, decref_54804)(Cell49147* c) {
	{
		(*c).refcount -= ((NI) 8);
		if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA3;
		rtladdzct_54404(c);
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC6;
		LOC6 = 0;
		LOC6 = canbecycleroot_52867(c);
		if (!LOC6) goto LA7;
		rtladdcycleroot_53623(c);
	}
	goto LA1;
	LA7: ;
	LA1: ;
}

static N_INLINE(void, asgnRef)(void** dest, void* src) {
	{
		Cell49147* LOC5;
		if (!!((src == NIM_NIL))) goto LA3;
		LOC5 = 0;
		LOC5 = usrtocell_52846(src);
		incref_55222(LOC5);
	}
	LA3: ;
	{
		Cell49147* LOC10;
		if (!!(((*dest) == NIM_NIL))) goto LA8;
		LOC10 = 0;
		LOC10 = usrtocell_52846((*dest));
		decref_54804(LOC10);
	}
	LA8: ;
	(*dest) = src;
}

N_NIMCALL(void, remove_141639)(Tlinkedlist141028* list, Tlistentry141022* entry) {
	(*list).counter -= ((NI) 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, prepend_141291)(Tlinkedlist141028* list, Tlistentry141022* entry) {
	(*list).counter += ((NI) 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, bringtofront_141705)(Tlinkedlist141028* list, Tlistentry141022* entry) {
	remove_141639(list, entry);
	prepend_141291(list, entry);
}

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)), (*a).Sup.len);
	LOC11 = (LOC13 == ((NI32) 0));
	LA12: ;
	result = LOC11;
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_BOOL, contains_141219)(Tlinkedlist141028 list, NimStringDesc* data) {
	NIM_BOOL result;
	Tlistentry141022* it;
{	result = 0;
	it = list.head;
	{
		while (1) {
			if (!!((it == NIM_NIL))) goto LA2;
			{
				if (!eqStrings((*((Tstrentry141024*) (it))).data, data)) goto LA5;
				result = NIM_TRUE;
				goto BeforeRet;
			}
			LA5: ;
			it = (*it).next;
		} LA2: ;
	}
	}BeforeRet: ;
	return result;
}
N_NIMCALL(void, TMP1749)(void* p, NI op) {
	Tstrentry141024* a;
	a = (Tstrentry141024*)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) {
	Cell49147* c;
	c = usrtocell_52846(p);
	{
		(*c).refcount -= ((NI) 8);
		if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA3;
		rtladdzct_54404(c);
	}
	LA3: ;
}

N_NIMCALL(Tstrentry141024*, newstrentry_141250)(NimStringDesc* data) {
	Tstrentry141024* result;
	NimStringDesc* LOC1;
	result = 0;
	result = (Tstrentry141024*) newObj((&NTI141026), sizeof(Tstrentry141024));
	(*result).Sup.Sup.m_type = (&NTI141024);
	LOC1 = 0;
	LOC1 = (*result).data; (*result).data = copyStringRC1(data);
	if (LOC1) nimGCunrefNoCycle(LOC1);
	return result;
}

N_NIMCALL(void, prependstr_141419)(Tlinkedlist141028* list, NimStringDesc* data) {
	Tstrentry141024* LOC1;
	Tlistentry141022* LOC2;
	LOC1 = 0;
	LOC1 = newstrentry_141250(data);
	LOC2 = 0;
	LOC2 = &LOC1->Sup;
	prepend_141291(list, LOC2);
}

N_NIMCALL(void, excludepath_141807)(Tlinkedlist141028* list, NimStringDesc* data) {
	Tlistentry141022* it;
	it = (*list).head;
	{
		while (1) {
			Tlistentry141022* nxt;
			if (!!((it == NIM_NIL))) goto LA2;
			nxt = (*it).next;
			{
				NI LOC5;
				LOC5 = 0;
				LOC5 = noscmpPaths((*((Tstrentry141024*) (it))).data, data);
				if (!(LOC5 == ((NI) 0))) goto LA6;
				remove_141639(list, it);
			}
			LA6: ;
			it = nxt;
		} LA2: ;
	}
}

N_NIMCALL(void, append_141053)(Tlinkedlist141028* list, Tlistentry141022* entry) {
	(*list).counter += ((NI) 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_141268)(Tlinkedlist141028* list, NimStringDesc* data) {
	Tstrentry141024* LOC1;
	Tlistentry141022* LOC2;
	LOC1 = 0;
	LOC1 = newstrentry_141250(data);
	LOC2 = 0;
	LOC2 = &LOC1->Sup;
	append_141053(list, LOC2);
}

N_NIMCALL(void, initlinkedlist_141043)(Tlinkedlist141028* list) {
	(*list).counter = ((NI) 0);
	unsureAsgnRef((void**) (&(*list).head), NIM_NIL);
	unsureAsgnRef((void**) (&(*list).tail), NIM_NIL);
}

N_NIMCALL(NIM_BOOL, includestr_141279)(Tlinkedlist141028* list, NimStringDesc* data) {
	NIM_BOOL result;
{	result = 0;
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = contains_141219((*list), data);
		if (!LOC3) goto LA4;
		result = NIM_TRUE;
		goto BeforeRet;
	}
	LA4: ;
	appendstr_141268(list, data);
	}BeforeRet: ;
	return result;
}
NIM_EXTERNC N_NOINLINE(void, compiler_listsInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, compiler_listsDatInit000)(void) {
static TNimNode* TMP853[2];
static TNimNode* TMP1129[3];
static TNimNode TMP23[8];
NTI141022.size = sizeof(Tlistentry141022);
NTI141022.kind = 17;
NTI141022.base = (&NTI4011);
TMP853[0] = &TMP23[1];
NTI141020.size = sizeof(Tlistentry141022*);
NTI141020.kind = 22;
NTI141020.base = (&NTI141022);
NTI141020.marker = TMP854;
TMP23[1].kind = 1;
TMP23[1].offset = offsetof(Tlistentry141022, prev);
TMP23[1].typ = (&NTI141020);
TMP23[1].name = "prev";
TMP853[1] = &TMP23[2];
TMP23[2].kind = 1;
TMP23[2].offset = offsetof(Tlistentry141022, next);
TMP23[2].typ = (&NTI141020);
TMP23[2].name = "next";
TMP23[0].len = 2; TMP23[0].kind = 2; TMP23[0].sons = &TMP853[0];
NTI141022.node = &TMP23[0];
NTI141028.size = sizeof(Tlinkedlist141028);
NTI141028.kind = 18;
NTI141028.base = 0;
TMP1129[0] = &TMP23[4];
TMP23[4].kind = 1;
TMP23[4].offset = offsetof(Tlinkedlist141028, head);
TMP23[4].typ = (&NTI141020);
TMP23[4].name = "head";
TMP1129[1] = &TMP23[5];
TMP23[5].kind = 1;
TMP23[5].offset = offsetof(Tlinkedlist141028, tail);
TMP23[5].typ = (&NTI141020);
TMP23[5].name = "tail";
TMP1129[2] = &TMP23[6];
TMP23[6].kind = 1;
TMP23[6].offset = offsetof(Tlinkedlist141028, counter);
TMP23[6].typ = (&NTI108);
TMP23[6].name = "counter";
TMP23[3].len = 3; TMP23[3].kind = 2; TMP23[3].sons = &TMP1129[0];
NTI141028.node = &TMP23[3];
NTI141024.size = sizeof(Tstrentry141024);
NTI141024.kind = 17;
NTI141024.base = (&NTI141022);
TMP23[7].kind = 1;
TMP23[7].offset = offsetof(Tstrentry141024, data);
TMP23[7].typ = (&NTI149);
TMP23[7].name = "data";
NTI141024.node = &TMP23[7];
NTI141026.size = sizeof(Tstrentry141024*);
NTI141026.kind = 22;
NTI141026.base = (&NTI141024);
NTI141026.marker = TMP1749;
}

