/* Generated by Nim Compiler v0.10.2 */
/*   (c) 2014 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 32
#include "nimbase.h"

#include <string.h>

#include <glob.h>

#include <setjmp.h>

#include <stdio.h>

#include <stdlib.h>
typedef struct tlinkedlist127028 tlinkedlist127028;
typedef struct tlistentry127022 tlistentry127022;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct tcell44933 tcell44933;
typedef struct TNimType TNimType;
typedef struct tcellseq44949 tcellseq44949;
typedef struct tgcheap47016 tgcheap47016;
typedef struct tcellset44945 tcellset44945;
typedef struct tpagedesc44941 tpagedesc44941;
typedef struct tmemregion27210 tmemregion27210;
typedef struct tsmallchunk26440 tsmallchunk26440;
typedef struct tllchunk27204 tllchunk27204;
typedef struct tbigchunk26442 tbigchunk26442;
typedef struct tintset26417 tintset26417;
typedef struct ttrunk26413 ttrunk26413;
typedef struct tavlnode27208 tavlnode27208;
typedef struct tgcstat47014 tgcstat47014;
typedef struct stringtableobj131012 stringtableobj131012;
typedef struct TNimNode TNimNode;
typedef struct TY119808 TY119808;
typedef struct keyvaluepair131008 keyvaluepair131008;
typedef struct TY117604 TY117604;
typedef struct Exception Exception;
typedef struct TNimObject TNimObject;
typedef struct TSafePoint TSafePoint;
typedef struct tstrentry127024 tstrentry127024;
typedef struct tbasechunk26438 tbasechunk26438;
typedef struct tfreecell26430 tfreecell26430;
typedef struct keyvaluepairseq131010 keyvaluepairseq131010;
struct  tlinkedlist127028  {
tlistentry127022* Head;
tlistentry127022* Tail;
NI Counter;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  tcell44933  {
NI Refcount;
TNimType* Typ;
};
struct  tcellseq44949  {
NI Len;
NI Cap;
tcell44933** D;
};
struct  tcellset44945  {
NI Counter;
NI Max;
tpagedesc44941* Head;
tpagedesc44941** Data;
};
typedef tsmallchunk26440* TY27222[512];
typedef ttrunk26413* ttrunkbuckets26415[256];
struct  tintset26417  {
ttrunkbuckets26415 Data;
};
struct  tmemregion27210  {
NI Minlargeobj;
NI Maxlargeobj;
TY27222 Freesmallchunks;
tllchunk27204* Llmem;
NI Currmem;
NI Maxmem;
NI Freemem;
NI Lastsize;
tbigchunk26442* Freechunkslist;
tintset26417 Chunkstarts;
tavlnode27208* Root;
tavlnode27208* Deleted;
tavlnode27208* Last;
tavlnode27208* Freeavlnodes;
};
struct  tgcstat47014  {
NI Stackscans;
NI Cyclecollections;
NI Maxthreshold;
NI Maxstacksize;
NI Maxstackcells;
NI Cycletablesize;
NI64 Maxpause;
};
struct  tgcheap47016  {
void* Stackbottom;
NI Cyclethreshold;
tcellseq44949 Zct;
tcellseq44949 Decstack;
tcellset44945 Cycleroots;
tcellseq44949 Tempstack;
NI Recgclock;
tmemregion27210 Region;
tgcstat47014 Stat;
};
typedef N_NIMCALL_PTR(void, TY3089) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3094) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3089 marker;
TY3094 deepcopy;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct keyvaluepair131008 {
NimStringDesc* Field0;
NimStringDesc* Field1;
};
struct TY117604 {
NimStringDesc* Field0;
NimStringDesc* Field1;
NimStringDesc* Field2;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  Exception  {
  TNimObject Sup;
Exception* parent;
NCSTRING name;
NimStringDesc* message;
NimStringDesc* trace;
};
typedef struct {
N_NIMCALL_PTR(NIM_BOOL, ClPrc) (Exception* e, void* ClEnv);
void* ClEnv;
} TY14809;
struct  TSafePoint  {
TSafePoint* prev;
NI status;
jmp_buf context;
NIM_BOOL hasRaiseAction;
TY14809 raiseAction;
};
typedef NimStringDesc* TY198301[1];
typedef NimStringDesc* TY170969[2];
struct  tlistentry127022  {
  TNimObject Sup;
tlistentry127022* Prev;
tlistentry127022* Next;
};
struct  tstrentry127024  {
  tlistentry127022 Sup;
NimStringDesc* Data;
};
typedef NU8 TY212607[32];
typedef NI TY26420[16];
struct  tpagedesc44941  {
tpagedesc44941* Next;
NI Key;
TY26420 Bits;
};
struct  tbasechunk26438  {
NI Prevsize;
NI Size;
NIM_BOOL Used;
};
struct  tsmallchunk26440  {
  tbasechunk26438 Sup;
tsmallchunk26440* Next;
tsmallchunk26440* Prev;
tfreecell26430* Freelist;
NI Free;
NI Acc;
NF Data;
};
struct  tllchunk27204  {
NI Size;
NI Acc;
tllchunk27204* Next;
};
struct  tbigchunk26442  {
  tbasechunk26438 Sup;
tbigchunk26442* Next;
tbigchunk26442* Prev;
NI Align;
NF Data;
};
struct  ttrunk26413  {
ttrunk26413* Next;
NI Key;
TY26420 Bits;
};
typedef tavlnode27208* TY27214[2];
struct  tavlnode27208  {
TY27214 Link;
NI Key;
NI Upperbound;
NI Level;
};
struct  stringtableobj131012  {
  TNimObject Sup;
NI Counter;
keyvaluepairseq131010* Data;
NU8 Mode;
};
struct  tfreecell26430  {
tfreecell26430* Next;
NI Zerofield;
};
struct TY119808 {
  TGenericSeq Sup;
  NimStringDesc* data[SEQ_DECL_SIZE];
};
struct keyvaluepairseq131010 {
  TGenericSeq Sup;
  keyvaluepair131008 data[SEQ_DECL_SIZE];
};
N_NIMCALL(NimStringDesc*, copyStringRC1)(NimStringDesc* src);
static N_INLINE(void, nimGCunrefNoCycle)(void* p);
static N_INLINE(tcell44933*, usrtocell_48646)(void* usr);
static N_INLINE(void, rtladdzct_50204)(tcell44933* c);
N_NOINLINE(void, addzct_48617)(tcellseq44949* s, tcell44933* c);
N_NIMCALL(stringtableobj131012*, nstnewStringTable)(NU8 mode);
static N_INLINE(void, asgnRef)(void** dest, void* src);
static N_INLINE(void, incref_51025)(tcell44933* c);
static N_INLINE(NIM_BOOL, canbecycleroot_48667)(tcell44933* c);
static N_INLINE(void, rtladdcycleroot_49429)(tcell44933* c);
N_NOINLINE(void, incl_45671)(tcellset44945* s, tcell44933* cell);
static N_INLINE(void, decref_50604)(tcell44933* c);
N_NIMCALL(void*, newSeqRC1)(TNimType* typ, NI len);
N_NIMCALL(NimStringDesc*, nosexpandFilename)(NimStringDesc* filename);
N_NIMCALL(NimStringDesc*, getprefixdir_170381)(void);
N_NIMCALL(void, nossplitPath)(NimStringDesc* path, keyvaluepair131008* Result);
N_NIMCALL(NimStringDesc*, nosgetAppDir)(void);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
static N_INLINE(void, appendChar)(NimStringDesc* dest, NIM_CHAR c);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(NIM_BOOL, nsuStartsWith)(NimStringDesc* s, NimStringDesc* prefix);
N_NIMCALL(NimStringDesc*, copyStr)(NimStringDesc* s, NI start);
N_NIMCALL(NimStringDesc*, copyStr)(NimStringDesc* s, NI first);
N_NIMCALL(NimStringDesc*, nosparentDir)(NimStringDesc* path);
N_NIMCALL(NIM_BOOL, nsthasKey)(stringtableobj131012* t, NimStringDesc* key);
N_NIMCALL(NimStringDesc*, nstGet)(stringtableobj131012* t, NimStringDesc* key);
N_NIMCALL(NimStringDesc*, HEX2F_117299)(NimStringDesc* head, NimStringDesc* tail);
N_NIMCALL(NimStringDesc*, cstrToNimstr)(NCSTRING str);
N_NIMCALL(void, nossplitFile)(NimStringDesc* path, TY117604* Result);
N_NIMCALL(void, nstPut)(stringtableobj131012* t, NimStringDesc* key, NimStringDesc* val);
N_NIMCALL(NimStringDesc*, getgeneratedpath_170429)(void);
N_NIMCALL(NimStringDesc*, shortendir_170407)(NimStringDesc* dir);
static N_INLINE(void, pushSafePoint)(TSafePoint* s);
N_NIMCALL(void, noscreateDir)(NimStringDesc* dir);
static N_INLINE(void, popSafePoint)(void);
N_NIMCALL(NIM_BOOL, isObj)(TNimType* obj, TNimType* subclass);
static N_INLINE(Exception*, getCurrentException)(void);
static N_INLINE(void, writeln_171205)(FILE* f_171209, NimStringDesc** x_171213, NI x_171213Len0);
N_NIMCALL(void, write_12865)(FILE* f, NimStringDesc* s);
static N_INLINE(void, popCurrentException)(void);
N_NIMCALL(void, reraiseException)(void);
N_NIMCALL(NimStringDesc*, nosjoinPath)(NimStringDesc* head, NimStringDesc* tail);
N_NIMCALL(NimStringDesc*, nosjoinPathOpenArray)(NimStringDesc** parts, NI partsLen0);
N_NIMCALL(NimStringDesc*, noschangeFileExt)(NimStringDesc* filename, NimStringDesc* ext);
N_NIMCALL(NimStringDesc*, getpackagename_170825)(NimStringDesc* path);
N_NIMCALL(NimStringDesc*, nosaddFileExt)(NimStringDesc* filename, NimStringDesc* ext);
N_NIMCALL(NIM_BOOL, nosexistsFile)(NimStringDesc* filename);
N_NIMCALL(NimStringDesc*, findfile_171356)(NimStringDesc* f);
N_NIMCALL(NimStringDesc*, rawfindfile_171292)(NimStringDesc* f);
N_NIMCALL(NimStringDesc*, canonicalizepath_170390)(NimStringDesc* path);
N_NIMCALL(NimStringDesc*, nsuToLowerStr)(NimStringDesc* s);
N_NIMCALL(NimStringDesc*, rawfindfile2_171318)(NimStringDesc* f);
N_NIMCALL(void, bringtofront_127741)(tlinkedlist127028* list, tlistentry127022* entry);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI start_74828, NI last);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI first, NI last);
N_NIMCALL(NimStringDesc*, canondynlibname_171468)(NimStringDesc* s);
N_NIMCALL(NI, nsuFindCharSet)(NimStringDesc* s, TY212607 chars, NI start);
N_NIMCALL(NI, nsuFindChar)(NimStringDesc* s, NIM_CHAR sub, NI start);
N_NIMCALL(void, libcandidates_171409)(NimStringDesc* s, TY119808** dest);
N_NIMCALL(TGenericSeq*, incrSeq)(TGenericSeq* seq, NI elemsize);
STRING_LITERAL(TMP41, "", 0);
STRING_LITERAL(TMP1361, "*.nimble", 8);
STRING_LITERAL(TMP1362, "*.babel", 7);
STRING_LITERAL(TMP1363, "nimcache", 8);
STRING_LITERAL(TMP1365, "\012", 1);
STRING_LITERAL(TMP1366, "cannot create directory: ", 25);
STRING_LITERAL(TMP1396, "nim", 3);
STRING_LITERAL(TMP1884, "lib", 3);
static NIM_CONST TY212607 TMP1885 = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
;
STRING_LITERAL(TMP1886, "true", 4);
NU32 goptions_170116;
NU32 gglobaloptions_170118;
NI8 gexitcode_170119;
NU8 gcmd_170120;
NU8 gselectedgc_170121;
tlinkedlist127028 searchpaths_170122;
tlinkedlist127028 lazypaths_170123;
NimStringDesc* outfile_170124;
extern tgcheap47016 gch_47044;
NimStringDesc* docseesrcurl_170125;
NimStringDesc* headerfile_170126;
NI gverbosity_170127;
NI gnumberofprocessors_170128;
NIM_BOOL gwholeproject_170129;
NimStringDesc* gevalexpr_170130;
NF glastcmdtime_170131;
NIM_BOOL glistfullpaths_170132;
NIM_BOOL isserving_170133;
NI32 gdirtybufferidx_170134;
NI32 gdirtyoriginalidx_170135;
NIM_BOOL gnonimblepath_170136;
NIM_BOOL gexperimentalmode_170137;
stringtableobj131012* gconfigvars_170231;
stringtableobj131012* gdlloverrides_170232;
NimStringDesc* libpath_170233;
NimStringDesc* gprojectname_170234;
NimStringDesc* gprojectpath_170235;
NimStringDesc* gprojectfull_170236;
NI32 gprojectmainidx_170237;
NimStringDesc* nimcachedir_170238;
NimStringDesc* command_170239;
TY119808* commandargs_170261;
extern TNimType NTI119808; /* seq[string] */
NIM_BOOL gkeepcomments_170262;
TY119808* implicitimports_170284;
TY119808* implicitincludes_170306;
stringtableobj131012* packagecache_170601;
TNimType NTI170014; /* TOption */
TNimType NTI170016; /* TOptions */
extern TSafePoint* exchandler_16243;
extern TNimType NTI3233; /* OSError */
extern Exception* currexception_16245;

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

static N_INLINE(void, rtladdzct_50204)(tcell44933* c) {
	addzct_48617((&gch_47044.Zct), c);
}

static N_INLINE(void, nimGCunrefNoCycle)(void* p) {
	tcell44933* c;
	c = usrtocell_48646(p);
	{
		(*c).Refcount -= 8;
		if (!((NU32)((*c).Refcount) < (NU32)(8))) goto LA3;
		rtladdzct_50204(c);
	}
	LA3: ;
}

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

static N_INLINE(void, rtladdcycleroot_49429)(tcell44933* c) {
	{
		if (!!((((NI) ((NI)((*c).Refcount & 3))) == 3))) goto LA3;
		(*c).Refcount = (NI)((NI)((*c).Refcount & -4) | 3);
		incl_45671((&gch_47044.Cycleroots), c);
	}
	LA3: ;
}

static N_INLINE(void, incref_51025)(tcell44933* c) {
	(*c).Refcount = (NI)((NU32)((*c).Refcount) + (NU32)(8));
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = canbecycleroot_48667(c);
		if (!LOC3) goto LA4;
		rtladdcycleroot_49429(c);
	}
	LA4: ;
}

static N_INLINE(void, decref_50604)(tcell44933* c) {
	{
		(*c).Refcount -= 8;
		if (!((NU32)((*c).Refcount) < (NU32)(8))) goto LA3;
		rtladdzct_50204(c);
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC6;
		LOC6 = 0;
		LOC6 = canbecycleroot_48667(c);
		if (!LOC6) goto LA7;
		rtladdcycleroot_49429(c);
	}
	goto LA1;
	LA7: ;
	LA1: ;
}

static N_INLINE(void, asgnRef)(void** dest, void* src) {
	{
		tcell44933* LOC5;
		if (!!((src == NIM_NIL))) goto LA3;
		LOC5 = 0;
		LOC5 = usrtocell_48646(src);
		incref_51025(LOC5);
	}
	LA3: ;
	{
		tcell44933* LOC10;
		if (!!(((*dest) == NIM_NIL))) goto LA8;
		LOC10 = 0;
		LOC10 = usrtocell_48646((*dest));
		decref_50604(LOC10);
	}
	LA8: ;
	(*dest) = src;
}

N_NIMCALL(NimStringDesc*, canonicalizepath_170390)(NimStringDesc* path) {
	NimStringDesc* result;
	result = 0;
	result = nosexpandFilename(path);
	return result;
}

N_NIMCALL(NimStringDesc*, getprefixdir_170381)(void) {
	NimStringDesc* result;
	NimStringDesc* LOC1;
	keyvaluepair131008 LOC2;
	result = 0;
	LOC1 = 0;
	LOC1 = nosgetAppDir();
	memset((void*)(&LOC2), 0, sizeof(LOC2));
	nossplitPath(LOC1, (&LOC2));
	result = copyString(LOC2.Field0);
	return result;
}

static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src) {
	memcpy(((NCSTRING) ((&(*dest).data[((*dest).Sup.len)- 0]))), ((NCSTRING) ((*src).data)), (NI32)((*src).Sup.len + 1));
	(*dest).Sup.len += (*src).Sup.len;
}

static N_INLINE(void, appendChar)(NimStringDesc* dest, NIM_CHAR c) {
	(*dest).data[((*dest).Sup.len)- 0] = c;
	(*dest).data[((NI32)((*dest).Sup.len + 1))- 0] = 0;
	(*dest).Sup.len += 1;
}

N_NIMCALL(NimStringDesc*, shortendir_170407)(NimStringDesc* dir) {
	NimStringDesc* result;
	NimStringDesc* prefix;
	NimStringDesc* LOC1;
	NimStringDesc* LOC2;
	NimStringDesc* LOC8;
	result = 0;
	LOC1 = 0;
	LOC2 = 0;
	LOC2 = getprefixdir_170381();
	LOC1 = rawNewString(LOC2->Sup.len + 1);
appendString(LOC1, LOC2);
appendChar(LOC1, 47);
	prefix = LOC1;
	{
		NIM_BOOL LOC5;
		LOC5 = 0;
		LOC5 = nsuStartsWith(dir, prefix);
		if (!LOC5) goto LA6;
		result = copyStr(dir, prefix->Sup.len);
		goto BeforeRet;
	}
	LA6: ;
	LOC8 = 0;
	LOC8 = rawNewString(gprojectpath_170235->Sup.len + 1);
appendString(LOC8, gprojectpath_170235);
appendChar(LOC8, 47);
	prefix = LOC8;
	{
		NIM_BOOL LOC11;
		LOC11 = 0;
		LOC11 = nsuStartsWith(dir, prefix);
		if (!LOC11) goto LA12;
		result = copyStr(dir, prefix->Sup.len);
		goto BeforeRet;
	}
	LA12: ;
	result = copyString(dir);
	BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, getpackagename_170825)(NimStringDesc* path) {
	NimStringDesc* result;
	NI parents;
	result = 0;
	parents = 0;
	{
		{
			NimStringDesc* d_170831;
			NimStringDesc* current_170890;
			d_170831 = 0;
			current_170890 = copyString(path);
			{
				while (1) {
					current_170890 = nosparentDir(current_170890);
					{
						if (!(current_170890->Sup.len == 0)) goto LA7;
						goto LA3;
					}
					LA7: ;
					d_170831 = current_170890;
					{
						NIM_BOOL LOC11;
						LOC11 = 0;
						LOC11 = nsthasKey(packagecache_170601, d_170831);
						if (!LOC11) goto LA12;
						result = nstGet(packagecache_170601, d_170831);
						goto BeforeRet;
					}
					LA12: ;
					parents += 1;
					{
						NimStringDesc* file_170844;
						NimStringDesc* HEX3Atmp_170861;
						glob_t f_170865;
						NI res_170867;
						int LOC15;
						file_170844 = 0;
						HEX3Atmp_170861 = 0;
						HEX3Atmp_170861 = HEX2F_117299(d_170831, ((NimStringDesc*) &TMP1361));
						memset((void*)(&f_170865), 0, sizeof(f_170865));
						res_170867 = 0;
						f_170865.gl_offs = 0;
						f_170865.gl_pathc = 0;
						f_170865.gl_pathv = NIM_NIL;
						LOC15 = 0;
						LOC15 = glob(HEX3Atmp_170861->data, ((int) 0), NIM_NIL, (&f_170865));
						res_170867 = ((NI) (LOC15));
						{
							if (!(res_170867 == 0)) goto LA18;
							{
								NI i_170869;
								NI HEX3Atmp_170871;
								NI res_170873;
								i_170869 = 0;
								HEX3Atmp_170871 = 0;
								HEX3Atmp_170871 = (NI32)(f_170865.gl_pathc - 1);
								res_170873 = 0;
								{
									while (1) {
										TY117604 LOC23;
										if (!(res_170873 <= HEX3Atmp_170871)) goto LA22;
										i_170869 = res_170873;
										file_170844 = cstrToNimstr(f_170865.gl_pathv[(i_170869)- 0]);
										memset((void*)(&LOC23), 0, sizeof(LOC23));
										nossplitFile(file_170844, (&LOC23));
										result = copyString(LOC23.Field1);
										goto LA1;
										res_170873 += 1;
									} LA22: ;
								}
							}
						}
						LA18: ;
						globfree((&f_170865));
					}
					{
						NimStringDesc* file_170845;
						NimStringDesc* HEX3Atmp_170875;
						glob_t f_170879;
						NI res_170881;
						int LOC25;
						file_170845 = 0;
						HEX3Atmp_170875 = 0;
						HEX3Atmp_170875 = HEX2F_117299(d_170831, ((NimStringDesc*) &TMP1362));
						memset((void*)(&f_170879), 0, sizeof(f_170879));
						res_170881 = 0;
						f_170879.gl_offs = 0;
						f_170879.gl_pathc = 0;
						f_170879.gl_pathv = NIM_NIL;
						LOC25 = 0;
						LOC25 = glob(HEX3Atmp_170875->data, ((int) 0), NIM_NIL, (&f_170879));
						res_170881 = ((NI) (LOC25));
						{
							if (!(res_170881 == 0)) goto LA28;
							{
								NI i_170883;
								NI HEX3Atmp_170885;
								NI res_170887;
								i_170883 = 0;
								HEX3Atmp_170885 = 0;
								HEX3Atmp_170885 = (NI32)(f_170879.gl_pathc - 1);
								res_170887 = 0;
								{
									while (1) {
										TY117604 LOC33;
										if (!(res_170887 <= HEX3Atmp_170885)) goto LA32;
										i_170883 = res_170887;
										file_170845 = cstrToNimstr(f_170879.gl_pathv[(i_170883)- 0]);
										memset((void*)(&LOC33), 0, sizeof(LOC33));
										nossplitFile(file_170845, (&LOC33));
										result = copyString(LOC33.Field1);
										goto LA1;
										res_170887 += 1;
									} LA32: ;
								}
							}
						}
						LA28: ;
						globfree((&f_170879));
					}
				}
			} LA3: ;
		}
	} LA1: ;
	{
		if (!result == 0) goto LA36;
		result = copyString(((NimStringDesc*) &TMP41));
	}
	LA36: ;
	{
		NimStringDesc* d_170846;
		NimStringDesc* current_170894;
		d_170846 = 0;
		current_170894 = copyString(path);
		{
			while (1) {
				current_170894 = nosparentDir(current_170894);
				{
					if (!(current_170894->Sup.len == 0)) goto LA43;
					goto LA39;
				}
				LA43: ;
				d_170846 = current_170894;
				nstPut(packagecache_170601, d_170846, result);
				parents -= 1;
				{
					if (!(parents <= 0)) goto LA47;
					goto LA38;
				}
				LA47: ;
			}
		} LA39: ;
	} LA38: ;
	BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, getgeneratedpath_170429)(void) {
	NimStringDesc* result;
	result = 0;
	{
		if (!(0 < nimcachedir_170238->Sup.len)) goto LA3;
		result = copyString(nimcachedir_170238);
	}
	goto LA1;
	LA3: ;
	{
		NimStringDesc* LOC6;
		LOC6 = 0;
		LOC6 = shortendir_170407(gprojectpath_170235);
		result = HEX2F_117299(LOC6, ((NimStringDesc*) &TMP1363));
	}
	LA1: ;
	return result;
}

static N_INLINE(void, pushSafePoint)(TSafePoint* s) {
	(*s).hasRaiseAction = NIM_FALSE;
	(*s).prev = exchandler_16243;
	exchandler_16243 = s;
}

static N_INLINE(void, popSafePoint)(void) {
	exchandler_16243 = (*exchandler_16243).prev;
}

static N_INLINE(Exception*, getCurrentException)(void) {
	Exception* result;
	result = 0;
	result = currexception_16245;
	return result;
}

static N_INLINE(void, writeln_171205)(FILE* f_171209, NimStringDesc** x_171213, NI x_171213Len0) {
	{
		NimStringDesc* i_171226;
		NI i_171234;
		i_171226 = 0;
		i_171234 = 0;
		{
			while (1) {
				if (!(i_171234 < x_171213Len0)) goto LA3;
				i_171226 = x_171213[i_171234];
				write_12865(f_171209, i_171226);
				i_171234 += 1;
			} LA3: ;
		}
	}
	write_12865(f_171209, ((NimStringDesc*) &TMP1365));
}

static N_INLINE(void, popCurrentException)(void) {
	asgnRef((void**) (&currexception_16245), (*currexception_16245).parent);
}

N_NIMCALL(NimStringDesc*, completegeneratedfilepath_171001)(NimStringDesc* f, NIM_BOOL createsubdir) {
	NimStringDesc* result;
	keyvaluepair131008 LOC1;
	NimStringDesc* head;
	NimStringDesc* tail;
	NimStringDesc* subdir;
	result = 0;
	memset((void*)(&LOC1), 0, sizeof(LOC1));
	nossplitPath(f, (&LOC1));
	head = 0;
	head = copyString(LOC1.Field0);
	tail = 0;
	tail = copyString(LOC1.Field1);
	subdir = getgeneratedpath_170429();
	{
		TSafePoint TMP1364;
		if (!createsubdir) goto LA4;
		pushSafePoint(&TMP1364);
		TMP1364.status = setjmp(TMP1364.context);
		if (TMP1364.status == 0) {
			noscreateDir(subdir);
			popSafePoint();
		}
		else {
			popSafePoint();
			if (isObj(getCurrentException()->Sup.m_type, (&NTI3233))) {
				TY198301 LOC9;
				NimStringDesc* LOC10;
				TMP1364.status = 0;
				memset((void*)LOC9, 0, sizeof(LOC9));
				LOC10 = 0;
				LOC10 = rawNewString(subdir->Sup.len + 25);
appendString(LOC10, ((NimStringDesc*) &TMP1366));
appendString(LOC10, subdir);
				LOC9[0] = LOC10;
				writeln_171205(stdout, LOC9, 1);
				exit(1);
				popCurrentException();
			}
		}
		if (TMP1364.status != 0) reraiseException();
	}
	LA4: ;
	result = nosjoinPath(subdir, tail);
	return result;
}

N_NIMCALL(NimStringDesc*, togeneratedfile_170960)(NimStringDesc* path, NimStringDesc* ext) {
	NimStringDesc* result;
	keyvaluepair131008 LOC1;
	NimStringDesc* head;
	NimStringDesc* tail;
	TY170969 LOC2;
	result = 0;
	memset((void*)(&LOC1), 0, sizeof(LOC1));
	nossplitPath(path, (&LOC1));
	head = 0;
	head = copyString(LOC1.Field0);
	tail = 0;
	tail = copyString(LOC1.Field1);
	memset((void*)LOC2, 0, sizeof(LOC2));
	LOC2[0] = getgeneratedpath_170429();
	LOC2[1] = noschangeFileExt(tail, ext);
	result = nosjoinPathOpenArray(LOC2, 2);
	return result;
}

N_NIMCALL(NimStringDesc*, withpackagename_170946)(NimStringDesc* path) {
	NimStringDesc* result;
	NimStringDesc* x;
	result = 0;
	x = getpackagename_170825(path);
	{
		if (!(x->Sup.len == 0)) goto LA3;
		result = copyString(path);
	}
	goto LA1;
	LA3: ;
	{
		TY117604 LOC6;
		NimStringDesc* p;
		NimStringDesc* file;
		NimStringDesc* ext;
		NimStringDesc* LOC7;
		NimStringDesc* LOC8;
		NimStringDesc* LOC9;
		memset((void*)(&LOC6), 0, sizeof(LOC6));
		nossplitFile(path, (&LOC6));
		p = 0;
		p = LOC6.Field0;
		file = 0;
		file = LOC6.Field1;
		ext = 0;
		ext = LOC6.Field2;
		LOC7 = 0;
		LOC8 = 0;
		LOC8 = rawNewString(x->Sup.len + file->Sup.len + 1);
appendString(LOC8, x);
appendChar(LOC8, 95);
appendString(LOC8, file);
		LOC9 = 0;
		LOC9 = HEX2F_117299(p, LOC8);
		LOC7 = rawNewString(LOC9->Sup.len + ext->Sup.len + 0);
appendString(LOC7, LOC9);
appendString(LOC7, ext);
		result = LOC7;
	}
	LA1: ;
	return result;
}

N_NIMCALL(NimStringDesc*, rawfindfile_171292)(NimStringDesc* f) {
	NimStringDesc* result;
	result = 0;
	{
		NimStringDesc* it_171296;
		tstrentry127024* it_171302;
		it_171296 = 0;
		it_171302 = ((tstrentry127024*) (searchpaths_170122.Head));
		{
			while (1) {
				if (!!((it_171302 == NIM_NIL))) goto LA3;
				it_171296 = (*it_171302).Data;
				result = nosjoinPath(it_171296, f);
				{
					NIM_BOOL LOC6;
					LOC6 = 0;
					LOC6 = nosexistsFile(result);
					if (!LOC6) goto LA7;
					result = canonicalizepath_170390(result);
					goto BeforeRet;
				}
				LA7: ;
				it_171302 = ((tstrentry127024*) ((*it_171302).Sup.Next));
			} LA3: ;
		}
	}
	result = copyString(((NimStringDesc*) &TMP41));
	BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, rawfindfile2_171318)(NimStringDesc* f) {
	NimStringDesc* result;
	tstrentry127024* it;
	result = 0;
	it = ((tstrentry127024*) (lazypaths_170123.Head));
	{
		while (1) {
			if (!!((it == NIM_NIL))) goto LA2;
			result = nosjoinPath((*it).Data, f);
			{
				NIM_BOOL LOC5;
				tlistentry127022* LOC8;
				LOC5 = 0;
				LOC5 = nosexistsFile(result);
				if (!LOC5) goto LA6;
				LOC8 = 0;
				LOC8 = &it->Sup;
				bringtofront_127741((&lazypaths_170123), LOC8);
				result = canonicalizepath_170390(result);
				goto BeforeRet;
			}
			LA6: ;
			it = ((tstrentry127024*) ((*it).Sup.Next));
		} LA2: ;
	}
	result = copyString(((NimStringDesc*) &TMP41));
	BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, findfile_171356)(NimStringDesc* f) {
	NimStringDesc* result;
	result = 0;
	result = rawfindfile_171292(f);
	{
		NimStringDesc* LOC5;
		if (!(result->Sup.len == 0)) goto LA3;
		LOC5 = 0;
		LOC5 = nsuToLowerStr(f);
		result = rawfindfile_171292(LOC5);
		{
			if (!(result->Sup.len == 0)) goto LA8;
			result = rawfindfile2_171318(f);
			{
				NimStringDesc* LOC14;
				if (!(result->Sup.len == 0)) goto LA12;
				LOC14 = 0;
				LOC14 = nsuToLowerStr(f);
				result = rawfindfile2_171318(LOC14);
			}
			LA12: ;
		}
		LA8: ;
	}
	LA3: ;
	return result;
}

N_NIMCALL(NimStringDesc*, findmodule_171366)(NimStringDesc* modulename, NimStringDesc* currentmodule) {
	NimStringDesc* result;
	NimStringDesc* m;
	NimStringDesc* currentpath;
	TY117604 LOC1;
	result = 0;
	m = nosaddFileExt(modulename, ((NimStringDesc*) &TMP1396));
	memset((void*)(&LOC1), 0, sizeof(LOC1));
	nossplitFile(currentmodule, (&LOC1));
	currentpath = LOC1.Field0;
	result = HEX2F_117299(currentpath, m);
	{
		NIM_BOOL LOC4;
		LOC4 = 0;
		LOC4 = nosexistsFile(result);
		if (!!(LOC4)) goto LA5;
		result = findfile_171356(m);
	}
	LA5: ;
	return result;
}

N_NIMCALL(NimStringDesc*, removetrailingdirsep_170418)(NimStringDesc* path) {
	NimStringDesc* result;
	result = 0;
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = (0 < path->Sup.len);
		if (!(LOC3)) goto LA4;
		LOC3 = ((NU8)(path->data[(NI32)(path->Sup.len - 1)]) == (NU8)(47));
		LA4: ;
		if (!LOC3) goto LA5;
		result = copyStrLast(path, 0, (NI32)(path->Sup.len - 2));
	}
	goto LA1;
	LA5: ;
	{
		result = copyString(path);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NIM_BOOL, existsconfigvar_170340)(NimStringDesc* key) {
	NIM_BOOL result;
	result = 0;
	result = nsthasKey(gconfigvars_170231, key);
	return result;
}

N_NIMCALL(NimStringDesc*, getconfigvar_170350)(NimStringDesc* key) {
	NimStringDesc* result;
	result = 0;
	result = nstGet(gconfigvars_170231, key);
	return result;
}

N_NIMCALL(NimStringDesc*, canondynlibname_171468)(NimStringDesc* s) {
	NimStringDesc* result;
	NI start;
	NI ende;
	result = 0;
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = nsuStartsWith(s, ((NimStringDesc*) &TMP1884));
		if (!LOC3) goto LA4;
		start = 3;
	}
	goto LA1;
	LA4: ;
	{
		start = 0;
	}
	LA1: ;
	ende = nsuFindCharSet(s, TMP1885, 0);
	{
		if (!(0 <= ende)) goto LA9;
		result = copyStrLast(s, start, (NI32)(ende - 1));
	}
	goto LA7;
	LA9: ;
	{
		result = copyStr(s, start);
	}
	LA7: ;
	return result;
}

N_NIMCALL(void, incldynliboverride_171481)(NimStringDesc* lib) {
	NimStringDesc* LOC1;
	LOC1 = 0;
	LOC1 = canondynlibname_171468(lib);
	nstPut(gdlloverrides_170232, LOC1, ((NimStringDesc*) &TMP1886));
}

N_NIMCALL(void, setconfigvar_170360)(NimStringDesc* key, NimStringDesc* val) {
	nstPut(gconfigvars_170231, key, val);
}

N_NIMCALL(NIM_BOOL, isdynliboverride_171490)(NimStringDesc* lib) {
	NIM_BOOL result;
	NimStringDesc* LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = canondynlibname_171468(lib);
	result = nsthasKey(gdlloverrides_170232, LOC1);
	return result;
}

N_NIMCALL(void, libcandidates_171409)(NimStringDesc* s, TY119808** dest) {
	NI le;
	NI ri;
	le = nsuFindChar(s, 40, 0);
	ri = nsuFindChar(s, 41, (NI32)(le + 1));
	{
		NIM_BOOL LOC3;
		NimStringDesc* prefix;
		NimStringDesc* suffix;
		LOC3 = 0;
		LOC3 = (0 <= le);
		if (!(LOC3)) goto LA4;
		LOC3 = (le < ri);
		LA4: ;
		if (!LOC3) goto LA5;
		prefix = copyStrLast(s, 0, (NI32)(le - 1));
		suffix = copyStr(s, (NI32)(ri + 1));
		{
			NimStringDesc* middle_171420;
			NimStringDesc* HEX3Atmp_171440;
			NI last_171444;
			middle_171420 = 0;
			HEX3Atmp_171440 = 0;
			HEX3Atmp_171440 = copyStrLast(s, (NI32)(le + 1), (NI32)(ri - 1));
			last_171444 = 0;
			{
				if (!(0 < HEX3Atmp_171440->Sup.len)) goto LA10;
				{
					while (1) {
						NI first_171446;
						NimStringDesc* LOC18;
						if (!(last_171444 <= HEX3Atmp_171440->Sup.len)) goto LA13;
						first_171446 = last_171444;
						{
							while (1) {
								NIM_BOOL LOC16;
								LOC16 = 0;
								LOC16 = (last_171444 < HEX3Atmp_171440->Sup.len);
								if (!(LOC16)) goto LA17;
								LOC16 = !(((NU8)(HEX3Atmp_171440->data[last_171444]) == (NU8)(124)));
								LA17: ;
								if (!LOC16) goto LA15;
								last_171444 += 1;
							} LA15: ;
						}
						middle_171420 = copyStrLast(HEX3Atmp_171440, first_171446, (NI32)(last_171444 - 1));
						LOC18 = 0;
						LOC18 = rawNewString(prefix->Sup.len + middle_171420->Sup.len + suffix->Sup.len + 0);
appendString(LOC18, prefix);
appendString(LOC18, middle_171420);
appendString(LOC18, suffix);
						libcandidates_171409(LOC18, dest);
						last_171444 += 1;
					} LA13: ;
				}
			}
			LA10: ;
		}
	}
	goto LA1;
	LA5: ;
	{
		NimStringDesc* LOC20;
		(*dest) = (TY119808*) incrSeq(&((*dest))->Sup, sizeof(NimStringDesc*));
		LOC20 = 0;
		LOC20 = (*dest)->data[(*dest)->Sup.len-1]; (*dest)->data[(*dest)->Sup.len-1] = copyStringRC1(s);
		if (LOC20) nimGCunrefNoCycle(LOC20);
	}
	LA1: ;
}

N_NIMCALL(NimStringDesc*, getoutfile_170370)(NimStringDesc* filename, NimStringDesc* ext) {
	NimStringDesc* result;
	result = 0;
	{
		if (!!(((outfile_170124) && (outfile_170124)->Sup.len == 0))) goto LA3;
		result = copyString(outfile_170124);
	}
	goto LA1;
	LA3: ;
	{
		result = noschangeFileExt(filename, ext);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NimStringDesc*, maincommandarg_170319)(void) {
	NimStringDesc* result;
	result = 0;
	{
		if (!(0 < commandargs_170261->Sup.len)) goto LA3;
		result = copyString(commandargs_170261->data[0]);
	}
	goto LA1;
	LA3: ;
	{
		result = copyString(gprojectname_170234);
	}
	LA1: ;
	return result;
}

N_NIMCALL(void, resetpackagecache_170605)(void) {
	asgnRef((void**) (&packagecache_170601), nstnewStringTable(((NU8) 1)));
}
NIM_EXTERNC N_NOINLINE(void, HEX00_optionsInit)(void) {
	NimStringDesc* LOC1;
	NimStringDesc* LOC2;
	NimStringDesc* LOC3;
	NimStringDesc* LOC4;
	NimStringDesc* LOC5;
	NimStringDesc* LOC6;
	NimStringDesc* LOC7;
	NimStringDesc* LOC8;
	NimStringDesc* LOC9;
	NimStringDesc* LOC10;
	goptions_170116 = 2202238;
	gglobaloptions_170118 = 134217728;
	gcmd_170120 = ((NU8) 0);
	gselectedgc_170121 = ((NU8) 3);
	LOC1 = 0;
	LOC1 = outfile_170124; outfile_170124 = copyStringRC1(((NimStringDesc*) &TMP41));
	if (LOC1) nimGCunrefNoCycle(LOC1);
	LOC2 = 0;
	LOC2 = docseesrcurl_170125; docseesrcurl_170125 = copyStringRC1(((NimStringDesc*) &TMP41));
	if (LOC2) nimGCunrefNoCycle(LOC2);
	LOC3 = 0;
	LOC3 = headerfile_170126; headerfile_170126 = copyStringRC1(((NimStringDesc*) &TMP41));
	if (LOC3) nimGCunrefNoCycle(LOC3);
	gverbosity_170127 = 1;
	LOC4 = 0;
	LOC4 = gevalexpr_170130; gevalexpr_170130 = copyStringRC1(((NimStringDesc*) &TMP41));
	if (LOC4) nimGCunrefNoCycle(LOC4);
	isserving_170133 = NIM_FALSE;
	gdirtybufferidx_170134 = ((NI32) 0);
	gdirtyoriginalidx_170135 = ((NI32) 0);
	gnonimblepath_170136 = NIM_FALSE;
	asgnRef((void**) (&gconfigvars_170231), nstnewStringTable(((NU8) 2)));
	asgnRef((void**) (&gdlloverrides_170232), nstnewStringTable(((NU8) 1)));
	LOC5 = 0;
	LOC5 = libpath_170233; libpath_170233 = copyStringRC1(((NimStringDesc*) &TMP41));
	if (LOC5) nimGCunrefNoCycle(LOC5);
	LOC6 = 0;
	LOC6 = gprojectname_170234; gprojectname_170234 = copyStringRC1(((NimStringDesc*) &TMP41));
	if (LOC6) nimGCunrefNoCycle(LOC6);
	LOC7 = 0;
	LOC7 = gprojectpath_170235; gprojectpath_170235 = copyStringRC1(((NimStringDesc*) &TMP41));
	if (LOC7) nimGCunrefNoCycle(LOC7);
	LOC8 = 0;
	LOC8 = gprojectfull_170236; gprojectfull_170236 = copyStringRC1(((NimStringDesc*) &TMP41));
	if (LOC8) nimGCunrefNoCycle(LOC8);
	LOC9 = 0;
	LOC9 = nimcachedir_170238; nimcachedir_170238 = copyStringRC1(((NimStringDesc*) &TMP41));
	if (LOC9) nimGCunrefNoCycle(LOC9);
	LOC10 = 0;
	LOC10 = command_170239; command_170239 = copyStringRC1(((NimStringDesc*) &TMP41));
	if (LOC10) nimGCunrefNoCycle(LOC10);
	if (commandargs_170261) nimGCunrefNoCycle(commandargs_170261);
	commandargs_170261 = (TY119808*) newSeqRC1((&NTI119808), 0);
	gkeepcomments_170262 = NIM_TRUE;
	if (implicitimports_170284) nimGCunrefNoCycle(implicitimports_170284);
	implicitimports_170284 = (TY119808*) newSeqRC1((&NTI119808), 0);
	if (implicitincludes_170306) nimGCunrefNoCycle(implicitincludes_170306);
	implicitincludes_170306 = (TY119808*) newSeqRC1((&NTI119808), 0);
	asgnRef((void**) (&packagecache_170601), nstnewStringTable(((NU8) 1)));
}

NIM_EXTERNC N_NOINLINE(void, HEX00_optionsDatInit)(void) {
static TNimNode* TMP764[22];
NI TMP766;
static char* NIM_CONST TMP765[22] = {
"optNone", 
"optObjCheck", 
"optFieldCheck", 
"optRangeCheck", 
"optBoundsCheck", 
"optOverflowCheck", 
"optNilCheck", 
"optNaNCheck", 
"optInfCheck", 
"optAssert", 
"optLineDir", 
"optWarns", 
"optHints", 
"optOptimizeSpeed", 
"optOptimizeSize", 
"optStackTrace", 
"optLineTrace", 
"optEndb", 
"optByRef", 
"optProfiler", 
"optImplicitStatic", 
"optPatterns"};
static TNimNode TMP21[24];
NTI170014.size = sizeof(NU8);
NTI170014.kind = 14;
NTI170014.base = 0;
NTI170014.flags = 3;
for (TMP766 = 0; TMP766 < 22; TMP766++) {
TMP21[TMP766+0].kind = 1;
TMP21[TMP766+0].offset = TMP766;
TMP21[TMP766+0].name = TMP765[TMP766];
TMP764[TMP766] = &TMP21[TMP766+0];
}
TMP21[22].len = 22; TMP21[22].kind = 2; TMP21[22].sons = &TMP764[0];
NTI170014.node = &TMP21[22];
NTI170016.size = sizeof(NU32);
NTI170016.kind = 19;
NTI170016.base = (&NTI170014);
NTI170016.flags = 3;
TMP21[23].len = 0; TMP21[23].kind = 0;
NTI170016.node = &TMP21[23];
}

