/* 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 tcell44935 tcell44935;
typedef struct TNimType TNimType;
typedef struct tcellseq44951 tcellseq44951;
typedef struct tgcheap47016 tgcheap47016;
typedef struct tcellset44947 tcellset44947;
typedef struct tpagedesc44943 tpagedesc44943;
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  tcell44935  {
NI Refcount;
TNimType* Typ;
};
struct  tcellseq44951  {
NI Len;
NI Cap;
tcell44935** D;
};
struct  tcellset44947  {
NI Counter;
NI Max;
tpagedesc44943* Head;
tpagedesc44943** 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;
tcellseq44951 Zct;
tcellseq44951 Decstack;
tcellset44947 Cycleroots;
tcellseq44951 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* TY197301[1];
typedef NimStringDesc* TY169969[2];
struct  tlistentry127022  {
  TNimObject Sup;
tlistentry127022* Prev;
tlistentry127022* Next;
};
struct  tstrentry127024  {
  tlistentry127022 Sup;
NimStringDesc* Data;
};
typedef NU8 TY211607[32];
typedef NI TY26420[16];
struct  tpagedesc44943  {
tpagedesc44943* 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(tcell44935*, usrtocell_48646)(void* usr);
static N_INLINE(void, rtladdzct_50204)(tcell44935* c);
N_NOINLINE(void, addzct_48617)(tcellseq44951* s, tcell44935* c);
N_NIMCALL(stringtableobj131012*, nstnewStringTable)(NU8 mode);
static N_INLINE(void, asgnRef)(void** dest, void* src);
static N_INLINE(void, incref_51025)(tcell44935* c);
static N_INLINE(NIM_BOOL, canbecycleroot_48667)(tcell44935* c);
static N_INLINE(void, rtladdcycleroot_49429)(tcell44935* c);
N_NOINLINE(void, incl_45671)(tcellset44947* s, tcell44935* cell);
static N_INLINE(void, decref_50604)(tcell44935* c);
N_NIMCALL(void*, newSeqRC1)(TNimType* typ, NI len);
N_NIMCALL(NimStringDesc*, nosexpandFilename)(NimStringDesc* filename);
N_NIMCALL(NimStringDesc*, getprefixdir_169381)(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_169429)(void);
N_NIMCALL(NimStringDesc*, shortendir_169407)(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_170205)(FILE* f_170209, NimStringDesc** x_170213, NI x_170213Len0);
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_169825)(NimStringDesc* path);
N_NIMCALL(NimStringDesc*, nosaddFileExt)(NimStringDesc* filename, NimStringDesc* ext);
N_NIMCALL(NIM_BOOL, nosexistsFile)(NimStringDesc* filename);
N_NIMCALL(NimStringDesc*, findfile_170356)(NimStringDesc* f);
N_NIMCALL(NimStringDesc*, rawfindfile_170292)(NimStringDesc* f);
N_NIMCALL(NimStringDesc*, canonicalizepath_169390)(NimStringDesc* path);
N_NIMCALL(NimStringDesc*, nsuToLowerStr)(NimStringDesc* s);
N_NIMCALL(NimStringDesc*, rawfindfile2_170318)(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_170468)(NimStringDesc* s);
N_NIMCALL(NI, nsuFindCharSet)(NimStringDesc* s, TY211607 chars, NI start);
N_NIMCALL(NI, nsuFindChar)(NimStringDesc* s, NIM_CHAR sub, NI start);
N_NIMCALL(void, libcandidates_170409)(NimStringDesc* s, TY119808** dest);
N_NIMCALL(TGenericSeq*, incrSeq)(TGenericSeq* seq, NI elemsize);
STRING_LITERAL(TMP39, "", 0);
STRING_LITERAL(TMP1360, "*.nimble", 8);
STRING_LITERAL(TMP1361, "*.babel", 7);
STRING_LITERAL(TMP1362, "nimcache", 8);
STRING_LITERAL(TMP1364, "\012", 1);
STRING_LITERAL(TMP1365, "cannot create directory: ", 25);
STRING_LITERAL(TMP1395, "nim", 3);
STRING_LITERAL(TMP1883, "lib", 3);
static NIM_CONST TY211607 TMP1884 = {
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(TMP1885, "true", 4);
NU32 goptions_169116;
NU32 gglobaloptions_169118;
NI8 gexitcode_169119;
NU8 gcmd_169120;
NU8 gselectedgc_169121;
tlinkedlist127028 searchpaths_169122;
tlinkedlist127028 lazypaths_169123;
NimStringDesc* outfile_169124;
extern tgcheap47016 gch_47044;
NimStringDesc* docseesrcurl_169125;
NimStringDesc* headerfile_169126;
NI gverbosity_169127;
NI gnumberofprocessors_169128;
NIM_BOOL gwholeproject_169129;
NimStringDesc* gevalexpr_169130;
NF glastcmdtime_169131;
NIM_BOOL glistfullpaths_169132;
NIM_BOOL isserving_169133;
NI32 gdirtybufferidx_169134;
NI32 gdirtyoriginalidx_169135;
NIM_BOOL gnonimblepath_169136;
NIM_BOOL gexperimentalmode_169137;
stringtableobj131012* gconfigvars_169231;
stringtableobj131012* gdlloverrides_169232;
NimStringDesc* libpath_169233;
NimStringDesc* gprojectname_169234;
NimStringDesc* gprojectpath_169235;
NimStringDesc* gprojectfull_169236;
NI32 gprojectmainidx_169237;
NimStringDesc* nimcachedir_169238;
NimStringDesc* command_169239;
TY119808* commandargs_169261;
extern TNimType NTI119808; /* seq[string] */
NIM_BOOL gkeepcomments_169262;
TY119808* implicitimports_169284;
TY119808* implicitincludes_169306;
stringtableobj131012* packagecache_169601;
TNimType NTI169014; /* TOption */
TNimType NTI169016; /* TOptions */
extern TSafePoint* exchandler_16243;
extern TNimType NTI3233; /* OSError */
extern Exception* currexception_16245;

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

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

static N_INLINE(void, nimGCunrefNoCycle)(void* p) {
	tcell44935* 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)(tcell44935* c) {
	NIM_BOOL result;
	result = 0;
	result = !((((*(*c).Typ).flags &(1<<((((NU8) 1))&7)))!=0));
	return result;
}

static N_INLINE(void, rtladdcycleroot_49429)(tcell44935* 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)(tcell44935* 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)(tcell44935* 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) {
	{
		tcell44935* LOC5;
		if (!!((src == NIM_NIL))) goto LA3;
		LOC5 = 0;
		LOC5 = usrtocell_48646(src);
		incref_51025(LOC5);
	}
	LA3: ;
	{
		tcell44935* LOC10;
		if (!!(((*dest) == NIM_NIL))) goto LA8;
		LOC10 = 0;
		LOC10 = usrtocell_48646((*dest));
		decref_50604(LOC10);
	}
	LA8: ;
	(*dest) = src;
}

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

N_NIMCALL(NimStringDesc*, getprefixdir_169381)(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_169407)(NimStringDesc* dir) {
	NimStringDesc* result;
	NimStringDesc* prefix;
	NimStringDesc* LOC1;
	NimStringDesc* LOC2;
	NimStringDesc* LOC8;
	result = 0;
	LOC1 = 0;
	LOC2 = 0;
	LOC2 = getprefixdir_169381();
	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_169235->Sup.len + 1);
appendString(LOC8, gprojectpath_169235);
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_169825)(NimStringDesc* path) {
	NimStringDesc* result;
	NI parents;
	result = 0;
	parents = 0;
	{
		{
			NimStringDesc* d_169831;
			NimStringDesc* current_169890;
			d_169831 = 0;
			current_169890 = copyString(path);
			{
				while (1) {
					current_169890 = nosparentDir(current_169890);
					{
						if (!(current_169890->Sup.len == 0)) goto LA7;
						goto LA3;
					}
					LA7: ;
					d_169831 = current_169890;
					{
						NIM_BOOL LOC11;
						LOC11 = 0;
						LOC11 = nsthasKey(packagecache_169601, d_169831);
						if (!LOC11) goto LA12;
						result = nstGet(packagecache_169601, d_169831);
						goto BeforeRet;
					}
					LA12: ;
					parents += 1;
					{
						NimStringDesc* file_169844;
						NimStringDesc* HEX3Atmp_169861;
						glob_t f_169865;
						NI res_169867;
						int LOC15;
						file_169844 = 0;
						HEX3Atmp_169861 = 0;
						HEX3Atmp_169861 = HEX2F_117299(d_169831, ((NimStringDesc*) &TMP1360));
						memset((void*)(&f_169865), 0, sizeof(f_169865));
						res_169867 = 0;
						f_169865.gl_offs = 0;
						f_169865.gl_pathc = 0;
						f_169865.gl_pathv = NIM_NIL;
						LOC15 = 0;
						LOC15 = glob(HEX3Atmp_169861->data, ((int) 0), NIM_NIL, (&f_169865));
						res_169867 = ((NI) (LOC15));
						{
							if (!(res_169867 == 0)) goto LA18;
							{
								NI i_169869;
								NI HEX3Atmp_169871;
								NI res_169873;
								i_169869 = 0;
								HEX3Atmp_169871 = 0;
								HEX3Atmp_169871 = (NI32)(f_169865.gl_pathc - 1);
								res_169873 = 0;
								{
									while (1) {
										TY117604 LOC23;
										if (!(res_169873 <= HEX3Atmp_169871)) goto LA22;
										i_169869 = res_169873;
										file_169844 = cstrToNimstr(f_169865.gl_pathv[(i_169869)- 0]);
										memset((void*)(&LOC23), 0, sizeof(LOC23));
										nossplitFile(file_169844, (&LOC23));
										result = copyString(LOC23.Field1);
										goto LA1;
										res_169873 += 1;
									} LA22: ;
								}
							}
						}
						LA18: ;
						globfree((&f_169865));
					}
					{
						NimStringDesc* file_169845;
						NimStringDesc* HEX3Atmp_169875;
						glob_t f_169879;
						NI res_169881;
						int LOC25;
						file_169845 = 0;
						HEX3Atmp_169875 = 0;
						HEX3Atmp_169875 = HEX2F_117299(d_169831, ((NimStringDesc*) &TMP1361));
						memset((void*)(&f_169879), 0, sizeof(f_169879));
						res_169881 = 0;
						f_169879.gl_offs = 0;
						f_169879.gl_pathc = 0;
						f_169879.gl_pathv = NIM_NIL;
						LOC25 = 0;
						LOC25 = glob(HEX3Atmp_169875->data, ((int) 0), NIM_NIL, (&f_169879));
						res_169881 = ((NI) (LOC25));
						{
							if (!(res_169881 == 0)) goto LA28;
							{
								NI i_169883;
								NI HEX3Atmp_169885;
								NI res_169887;
								i_169883 = 0;
								HEX3Atmp_169885 = 0;
								HEX3Atmp_169885 = (NI32)(f_169879.gl_pathc - 1);
								res_169887 = 0;
								{
									while (1) {
										TY117604 LOC33;
										if (!(res_169887 <= HEX3Atmp_169885)) goto LA32;
										i_169883 = res_169887;
										file_169845 = cstrToNimstr(f_169879.gl_pathv[(i_169883)- 0]);
										memset((void*)(&LOC33), 0, sizeof(LOC33));
										nossplitFile(file_169845, (&LOC33));
										result = copyString(LOC33.Field1);
										goto LA1;
										res_169887 += 1;
									} LA32: ;
								}
							}
						}
						LA28: ;
						globfree((&f_169879));
					}
				}
			} LA3: ;
		}
	} LA1: ;
	{
		if (!result == 0) goto LA36;
		result = copyString(((NimStringDesc*) &TMP39));
	}
	LA36: ;
	{
		NimStringDesc* d_169846;
		NimStringDesc* current_169894;
		d_169846 = 0;
		current_169894 = copyString(path);
		{
			while (1) {
				current_169894 = nosparentDir(current_169894);
				{
					if (!(current_169894->Sup.len == 0)) goto LA43;
					goto LA39;
				}
				LA43: ;
				d_169846 = current_169894;
				nstPut(packagecache_169601, d_169846, result);
				parents -= 1;
				{
					if (!(parents <= 0)) goto LA47;
					goto LA38;
				}
				LA47: ;
			}
		} LA39: ;
	} LA38: ;
	BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, getgeneratedpath_169429)(void) {
	NimStringDesc* result;
	result = 0;
	{
		if (!(0 < nimcachedir_169238->Sup.len)) goto LA3;
		result = copyString(nimcachedir_169238);
	}
	goto LA1;
	LA3: ;
	{
		NimStringDesc* LOC6;
		LOC6 = 0;
		LOC6 = shortendir_169407(gprojectpath_169235);
		result = HEX2F_117299(LOC6, ((NimStringDesc*) &TMP1362));
	}
	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_170205)(FILE* f_170209, NimStringDesc** x_170213, NI x_170213Len0) {
	{
		NimStringDesc* i_170226;
		NI i_170234;
		i_170226 = 0;
		i_170234 = 0;
		{
			while (1) {
				if (!(i_170234 < x_170213Len0)) goto LA3;
				i_170226 = x_170213[i_170234];
				write_12865(f_170209, i_170226);
				i_170234 += 1;
			} LA3: ;
		}
	}
	write_12865(f_170209, ((NimStringDesc*) &TMP1364));
}

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

N_NIMCALL(NimStringDesc*, completegeneratedfilepath_170001)(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_169429();
	{
		TSafePoint TMP1363;
		if (!createsubdir) goto LA4;
		pushSafePoint(&TMP1363);
		TMP1363.status = _setjmp(TMP1363.context);
		if (TMP1363.status == 0) {
			noscreateDir(subdir);
			popSafePoint();
		}
		else {
			popSafePoint();
			if (isObj(getCurrentException()->Sup.m_type, (&NTI3233))) {
				TY197301 LOC9;
				NimStringDesc* LOC10;
				TMP1363.status = 0;
				memset((void*)LOC9, 0, sizeof(LOC9));
				LOC10 = 0;
				LOC10 = rawNewString(subdir->Sup.len + 25);
appendString(LOC10, ((NimStringDesc*) &TMP1365));
appendString(LOC10, subdir);
				LOC9[0] = LOC10;
				writeln_170205(stdout, LOC9, 1);
				exit(1);
				popCurrentException();
			}
		}
		if (TMP1363.status != 0) reraiseException();
	}
	LA4: ;
	result = nosjoinPath(subdir, tail);
	return result;
}

N_NIMCALL(NimStringDesc*, togeneratedfile_169960)(NimStringDesc* path, NimStringDesc* ext) {
	NimStringDesc* result;
	keyvaluepair131008 LOC1;
	NimStringDesc* head;
	NimStringDesc* tail;
	TY169969 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_169429();
	LOC2[1] = noschangeFileExt(tail, ext);
	result = nosjoinPathOpenArray(LOC2, 2);
	return result;
}

N_NIMCALL(NimStringDesc*, withpackagename_169946)(NimStringDesc* path) {
	NimStringDesc* result;
	NimStringDesc* x;
	result = 0;
	x = getpackagename_169825(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_170292)(NimStringDesc* f) {
	NimStringDesc* result;
	result = 0;
	{
		NimStringDesc* it_170296;
		tstrentry127024* it_170302;
		it_170296 = 0;
		it_170302 = ((tstrentry127024*) (searchpaths_169122.Head));
		{
			while (1) {
				if (!!((it_170302 == NIM_NIL))) goto LA3;
				it_170296 = (*it_170302).Data;
				result = nosjoinPath(it_170296, f);
				{
					NIM_BOOL LOC6;
					LOC6 = 0;
					LOC6 = nosexistsFile(result);
					if (!LOC6) goto LA7;
					result = canonicalizepath_169390(result);
					goto BeforeRet;
				}
				LA7: ;
				it_170302 = ((tstrentry127024*) ((*it_170302).Sup.Next));
			} LA3: ;
		}
	}
	result = copyString(((NimStringDesc*) &TMP39));
	BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, rawfindfile2_170318)(NimStringDesc* f) {
	NimStringDesc* result;
	tstrentry127024* it;
	result = 0;
	it = ((tstrentry127024*) (lazypaths_169123.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_169123), LOC8);
				result = canonicalizepath_169390(result);
				goto BeforeRet;
			}
			LA6: ;
			it = ((tstrentry127024*) ((*it).Sup.Next));
		} LA2: ;
	}
	result = copyString(((NimStringDesc*) &TMP39));
	BeforeRet: ;
	return result;
}

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

N_NIMCALL(NimStringDesc*, findmodule_170366)(NimStringDesc* modulename, NimStringDesc* currentmodule) {
	NimStringDesc* result;
	NimStringDesc* m;
	NimStringDesc* currentpath;
	TY117604 LOC1;
	result = 0;
	m = nosaddFileExt(modulename, ((NimStringDesc*) &TMP1395));
	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_170356(m);
	}
	LA5: ;
	return result;
}

N_NIMCALL(NimStringDesc*, removetrailingdirsep_169418)(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_169340)(NimStringDesc* key) {
	NIM_BOOL result;
	result = 0;
	result = nsthasKey(gconfigvars_169231, key);
	return result;
}

N_NIMCALL(NimStringDesc*, getconfigvar_169350)(NimStringDesc* key) {
	NimStringDesc* result;
	result = 0;
	result = nstGet(gconfigvars_169231, key);
	return result;
}

N_NIMCALL(NimStringDesc*, canondynlibname_170468)(NimStringDesc* s) {
	NimStringDesc* result;
	NI start;
	NI ende;
	result = 0;
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = nsuStartsWith(s, ((NimStringDesc*) &TMP1883));
		if (!LOC3) goto LA4;
		start = 3;
	}
	goto LA1;
	LA4: ;
	{
		start = 0;
	}
	LA1: ;
	ende = nsuFindCharSet(s, TMP1884, 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_170481)(NimStringDesc* lib) {
	NimStringDesc* LOC1;
	LOC1 = 0;
	LOC1 = canondynlibname_170468(lib);
	nstPut(gdlloverrides_169232, LOC1, ((NimStringDesc*) &TMP1885));
}

N_NIMCALL(void, setconfigvar_169360)(NimStringDesc* key, NimStringDesc* val) {
	nstPut(gconfigvars_169231, key, val);
}

N_NIMCALL(NIM_BOOL, isdynliboverride_170490)(NimStringDesc* lib) {
	NIM_BOOL result;
	NimStringDesc* LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = canondynlibname_170468(lib);
	result = nsthasKey(gdlloverrides_169232, LOC1);
	return result;
}

N_NIMCALL(void, libcandidates_170409)(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_170420;
			NimStringDesc* HEX3Atmp_170440;
			NI last_170444;
			middle_170420 = 0;
			HEX3Atmp_170440 = 0;
			HEX3Atmp_170440 = copyStrLast(s, (NI32)(le + 1), (NI32)(ri - 1));
			last_170444 = 0;
			{
				if (!(0 < HEX3Atmp_170440->Sup.len)) goto LA10;
				{
					while (1) {
						NI first_170446;
						NimStringDesc* LOC18;
						if (!(last_170444 <= HEX3Atmp_170440->Sup.len)) goto LA13;
						first_170446 = last_170444;
						{
							while (1) {
								NIM_BOOL LOC16;
								LOC16 = 0;
								LOC16 = (last_170444 < HEX3Atmp_170440->Sup.len);
								if (!(LOC16)) goto LA17;
								LOC16 = !(((NU8)(HEX3Atmp_170440->data[last_170444]) == (NU8)(124)));
								LA17: ;
								if (!LOC16) goto LA15;
								last_170444 += 1;
							} LA15: ;
						}
						middle_170420 = copyStrLast(HEX3Atmp_170440, first_170446, (NI32)(last_170444 - 1));
						LOC18 = 0;
						LOC18 = rawNewString(prefix->Sup.len + middle_170420->Sup.len + suffix->Sup.len + 0);
appendString(LOC18, prefix);
appendString(LOC18, middle_170420);
appendString(LOC18, suffix);
						libcandidates_170409(LOC18, dest);
						last_170444 += 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_169370)(NimStringDesc* filename, NimStringDesc* ext) {
	NimStringDesc* result;
	result = 0;
	{
		if (!!(((outfile_169124) && (outfile_169124)->Sup.len == 0))) goto LA3;
		result = copyString(outfile_169124);
	}
	goto LA1;
	LA3: ;
	{
		result = noschangeFileExt(filename, ext);
	}
	LA1: ;
	return result;
}

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

N_NIMCALL(void, resetpackagecache_169605)(void) {
	asgnRef((void**) (&packagecache_169601), 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_169116 = 2202238;
	gglobaloptions_169118 = 134217728;
	gcmd_169120 = ((NU8) 0);
	gselectedgc_169121 = ((NU8) 3);
	LOC1 = 0;
	LOC1 = outfile_169124; outfile_169124 = copyStringRC1(((NimStringDesc*) &TMP39));
	if (LOC1) nimGCunrefNoCycle(LOC1);
	LOC2 = 0;
	LOC2 = docseesrcurl_169125; docseesrcurl_169125 = copyStringRC1(((NimStringDesc*) &TMP39));
	if (LOC2) nimGCunrefNoCycle(LOC2);
	LOC3 = 0;
	LOC3 = headerfile_169126; headerfile_169126 = copyStringRC1(((NimStringDesc*) &TMP39));
	if (LOC3) nimGCunrefNoCycle(LOC3);
	gverbosity_169127 = 1;
	LOC4 = 0;
	LOC4 = gevalexpr_169130; gevalexpr_169130 = copyStringRC1(((NimStringDesc*) &TMP39));
	if (LOC4) nimGCunrefNoCycle(LOC4);
	isserving_169133 = NIM_FALSE;
	gdirtybufferidx_169134 = ((NI32) 0);
	gdirtyoriginalidx_169135 = ((NI32) 0);
	gnonimblepath_169136 = NIM_FALSE;
	asgnRef((void**) (&gconfigvars_169231), nstnewStringTable(((NU8) 2)));
	asgnRef((void**) (&gdlloverrides_169232), nstnewStringTable(((NU8) 1)));
	LOC5 = 0;
	LOC5 = libpath_169233; libpath_169233 = copyStringRC1(((NimStringDesc*) &TMP39));
	if (LOC5) nimGCunrefNoCycle(LOC5);
	LOC6 = 0;
	LOC6 = gprojectname_169234; gprojectname_169234 = copyStringRC1(((NimStringDesc*) &TMP39));
	if (LOC6) nimGCunrefNoCycle(LOC6);
	LOC7 = 0;
	LOC7 = gprojectpath_169235; gprojectpath_169235 = copyStringRC1(((NimStringDesc*) &TMP39));
	if (LOC7) nimGCunrefNoCycle(LOC7);
	LOC8 = 0;
	LOC8 = gprojectfull_169236; gprojectfull_169236 = copyStringRC1(((NimStringDesc*) &TMP39));
	if (LOC8) nimGCunrefNoCycle(LOC8);
	LOC9 = 0;
	LOC9 = nimcachedir_169238; nimcachedir_169238 = copyStringRC1(((NimStringDesc*) &TMP39));
	if (LOC9) nimGCunrefNoCycle(LOC9);
	LOC10 = 0;
	LOC10 = command_169239; command_169239 = copyStringRC1(((NimStringDesc*) &TMP39));
	if (LOC10) nimGCunrefNoCycle(LOC10);
	if (commandargs_169261) nimGCunrefNoCycle(commandargs_169261);
	commandargs_169261 = (TY119808*) newSeqRC1((&NTI119808), 0);
	gkeepcomments_169262 = NIM_TRUE;
	if (implicitimports_169284) nimGCunrefNoCycle(implicitimports_169284);
	implicitimports_169284 = (TY119808*) newSeqRC1((&NTI119808), 0);
	if (implicitincludes_169306) nimGCunrefNoCycle(implicitincludes_169306);
	implicitincludes_169306 = (TY119808*) newSeqRC1((&NTI119808), 0);
	asgnRef((void**) (&packagecache_169601), nstnewStringTable(((NU8) 1)));
}

NIM_EXTERNC N_NOINLINE(void, HEX00_optionsDatInit)(void) {
static TNimNode* TMP762[22];
NI TMP764;
static char* NIM_CONST TMP763[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];
NTI169014.size = sizeof(NU8);
NTI169014.kind = 14;
NTI169014.base = 0;
NTI169014.flags = 3;
for (TMP764 = 0; TMP764 < 22; TMP764++) {
TMP21[TMP764+0].kind = 1;
TMP21[TMP764+0].offset = TMP764;
TMP21[TMP764+0].name = TMP763[TMP764];
TMP762[TMP764] = &TMP21[TMP764+0];
}
TMP21[22].len = 22; TMP21[22].kind = 2; TMP21[22].sons = &TMP762[0];
NTI169014.node = &TMP21[22];
NTI169016.size = sizeof(NU32);
NTI169016.kind = 19;
NTI169016.base = (&NTI169014);
NTI169016.flags = 3;
TMP21[23].len = 0; TMP21[23].kind = 0;
NTI169016.node = &TMP21[23];
}

