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

#include "nimbase.h"
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <dirent.h>
#include <stdio.h>
typedef struct TY125202 TY125202;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Keyvaluepair140205 Keyvaluepair140205;
typedef struct Oserror3630 Oserror3630;
typedef struct Systemerror3626 Systemerror3626;
typedef struct Exception Exception;
typedef struct TNimObject TNimObject;
typedef struct Cell47505 Cell47505;
typedef struct Cellseq47521 Cellseq47521;
typedef struct Gcheap49818 Gcheap49818;
typedef struct Gcstack49816 Gcstack49816;
typedef struct Cellset47517 Cellset47517;
typedef struct Pagedesc47513 Pagedesc47513;
typedef struct Memregion29687 Memregion29687;
typedef struct Smallchunk29639 Smallchunk29639;
typedef struct Llchunk29681 Llchunk29681;
typedef struct Bigchunk29641 Bigchunk29641;
typedef struct Intset29614 Intset29614;
typedef struct Trunk29610 Trunk29610;
typedef struct Avlnode29685 Avlnode29685;
typedef struct Gcstat49814 Gcstat49814;
typedef struct TY118706 TY118706;
typedef struct Indexerror3652 Indexerror3652;
typedef struct Basechunk29637 Basechunk29637;
typedef struct Freecell29629 Freecell29629;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef N_NIMCALL_PTR(void, TY3489) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3494) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3489 marker;
TY3494 deepcopy;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct Keyvaluepair140205 {
NimStringDesc* Field0;
NimStringDesc* Field1;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  Exception  {
  TNimObject Sup;
Exception* parent;
NCSTRING name;
NimStringDesc* message;
NimStringDesc* trace;
};
struct  Systemerror3626  {
  Exception Sup;
};
struct  Oserror3630  {
  Systemerror3626 Sup;
NI32 errorcode;
};
struct  Cell47505  {
NI refcount;
TNimType* typ;
};
struct  Cellseq47521  {
NI len;
NI cap;
Cell47505** d;
};
struct  Cellset47517  {
NI counter;
NI max;
Pagedesc47513* head;
Pagedesc47513** data;
};
typedef Smallchunk29639* TY29702[512];
typedef Trunk29610* Trunkbuckets29612[256];
struct  Intset29614  {
Trunkbuckets29612 data;
};
struct  Memregion29687  {
NI minlargeobj;
NI maxlargeobj;
TY29702 freesmallchunks;
Llchunk29681* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk29641* freechunkslist;
Intset29614 chunkstarts;
Avlnode29685* root;
Avlnode29685* deleted;
Avlnode29685* last;
Avlnode29685* freeavlnodes;
};
struct  Gcstat49814  {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct  Gcheap49818  {
Gcstack49816* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq47521 zct;
Cellseq47521 decstack;
Cellset47517 cycleroots;
Cellseq47521 tempstack;
NI recgclock;
Memregion29687 region;
Gcstat49814 stat;
};
struct TY118706 {
NimStringDesc* Field0;
NimStringDesc* Field1;
NimStringDesc* Field2;
};
struct  Indexerror3652  {
  Exception Sup;
};
typedef NIM_CHAR TY110368[256];
struct  Gcstack49816  {
Gcstack49816* prev;
Gcstack49816* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY29618[16];
struct  Pagedesc47513  {
Pagedesc47513* next;
NI key;
TY29618 bits;
};
struct  Basechunk29637  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk29639  {
  Basechunk29637 Sup;
Smallchunk29639* next;
Smallchunk29639* prev;
Freecell29629* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk29681  {
NI size;
NI acc;
Llchunk29681* next;
};
struct  Bigchunk29641  {
  Basechunk29637 Sup;
Bigchunk29641* next;
Bigchunk29641* prev;
NI align;
NF data;
};
struct  Trunk29610  {
Trunk29610* next;
NI key;
TY29618 bits;
};
typedef Avlnode29685* TY29692[2];
struct  Avlnode29685  {
TY29692 link;
NI key;
NI upperbound;
NI level;
};
struct  Freecell29629  {
Freecell29629* next;
NI zerofield;
};
struct TY125202 {
  TGenericSeq Sup;
  NimStringDesc* data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP54)(void* p, NI op);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(void, nossplitPath)(NimStringDesc* path, Keyvaluepair140205* Result);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI start_79810, NI last);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI first, NI last);
N_NIMCALL(void, unsureAsgnRef)(void** dest, void* src);
N_NIMCALL(NimStringDesc*, copyStr)(NimStringDesc* s, NI start);
N_NIMCALL(NimStringDesc*, copyStr)(NimStringDesc* s, NI first);
N_NIMCALL(NI, searchextpos_118669)(NimStringDesc* s);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
N_NIMCALL(NimStringDesc*, normext_118665)(NimStringDesc* ext);
static N_INLINE(void, appendChar)(NimStringDesc* dest, NIM_CHAR c);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(NimStringDesc*, mnewString)(NI len);
N_NIMCALL(NimStringDesc*, mnewString)(NI len);
N_NOINLINE(void, raiseoserror_120803)(NI32 errorcode, NimStringDesc* additionalinfo);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
N_NIMCALL(NimStringDesc*, oserrormsg_120611)(NI32 errorcode);
N_NIMCALL(NimStringDesc*, cstrToNimstr)(NCSTRING str);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(Cell47505*, usrtocell_51440)(void* usr);
static N_INLINE(void, rtladdzct_53001)(Cell47505* c);
N_NOINLINE(void, addzct_51417)(Cellseq47521* s, Cell47505* c);
N_NIMCALL(NimStringDesc*, copyStringRC1)(NimStringDesc* src);
static N_INLINE(void, nimGCunrefNoCycle)(void* p);
N_NIMCALL(void, raiseException)(Exception* e, NCSTRING ename);
N_NIMCALL(NI32, oslasterror_120819)(void);
N_NIMCALL(NimStringDesc*, setLengthStr)(NimStringDesc* s, NI newlen);
N_NIMCALL(void, nossplitFile)(NimStringDesc* path, TY118706* Result);
N_NIMCALL(NimStringDesc*, nosgetAppFilename)(void);
N_NIMCALL(NimStringDesc*, getenv_125825)(NimStringDesc* key);
N_NIMCALL(NI, findenvvar_125802)(NimStringDesc* key);
N_NIMCALL(void, getenvvarsc_125402)(void);
N_NIMCALL(void*, newSeqRC1)(TNimType* typ, NI len);
N_NIMCALL(TGenericSeq*, incrSeqV2)(TGenericSeq* seq, NI elemsize);
N_NIMCALL(NIM_BOOL, nsuStartsWith)(NimStringDesc* s, NimStringDesc* prefix);
N_NIMCALL(NI, nsuFindChar)(NimStringDesc* s, NIM_CHAR sub, NI start);
N_NIMCALL(NimStringDesc*, getapplheuristic_132001)(void);
N_NIMCALL(NimStringDesc*, paramstr_131407)(NI i);
N_NIMCALL(NimStringDesc*, nosjoinPath)(NimStringDesc* head, NimStringDesc* tail);
N_NIMCALL(NIM_BOOL, nosexistsFile)(NimStringDesc* filename);
N_NIMCALL(NI, parentdirpos_118510)(NimStringDesc* path);
N_NIMCALL(void, rawcreatedir_127630)(NimStringDesc* dir);
N_NIMCALL(NI, cmp_5680)(NimStringDesc* x, NimStringDesc* y);
N_NIMCALL(NI, nsuCmpIgnoreCase)(NimStringDesc* a, NimStringDesc* b);
N_NIMCALL(NimStringDesc*, nosaddFileExt)(NimStringDesc* filename, NimStringDesc* ext);
N_NIMCALL(NimStringDesc*, HEX2F_118465)(NimStringDesc* head, NimStringDesc* tail);
N_NIMCALL(NimStringDesc*, expandtilde_130601)(NimStringDesc* path);
N_NIMCALL(NimStringDesc*, nosgetHomeDir)(void);
N_NIMCALL(NimStringDesc*, nososErrorMsg)(void);
static N_INLINE(NIM_BOOL, eqStrings)(NimStringDesc* a, NimStringDesc* b);
N_NIMCALL(void, nosremoveFile)(NimStringDesc* file);
N_NIMCALL(void, nosremoveDir)(NimStringDesc* dir);
N_NIMCALL(void, rawremovedir_127514)(NimStringDesc* dir);
N_NIMCALL(NIM_BOOL, open_15403)(FILE** f, NimStringDesc* filename, NU8 mode, NI bufsize);
N_NOCONV(void*, alloc_7401)(NI size);
N_NIMCALL(NI, readbuffer_15554)(FILE* f, void* buffer, NI len);
N_NIMCALL(NI, writebuffer_15576)(FILE* f, void* buffer, NI len);
N_NOCONV(void, dealloc_7448)(void* p);
N_NIMCALL(NI64, ntDiffTime)(time_t a, time_t b);
N_NIMCALL(time_t, nosgetLastModificationTime)(NimStringDesc* file);
STRING_LITERAL(TMP146, "", 0);
STRING_LITERAL(TMP1227, " ", 1);
STRING_LITERAL(TMP1228, "unknown OS error", 16);
STRING_LITERAL(TMP1231, "_", 1);
STRING_LITERAL(TMP1233, "invalid index", 13);
STRING_LITERAL(TMP1234, "PATH", 4);
STRING_LITERAL(TMP1789, "HOME", 4);
STRING_LITERAL(TMP1790, "/", 1);
STRING_LITERAL(TMP2053, "/.config/", 9);
STRING_LITERAL(TMP3668, ".", 1);
STRING_LITERAL(TMP3669, "..", 2);
NIM_BOOL envcomputed_125201;
TY125202* environment_125203;
extern NCSTRING* environ;
extern int cmdCount;
extern NCSTRING* cmdLine;
extern TNimType NTI138; /* string */
TNimType NTI125202; /* seq[string] */
extern TNimType NTI120807; /* ref OSError */
extern TNimType NTI3630; /* OSError */
extern Gcheap49818 gch_49859;
extern TNimType NTI131415; /* ref IndexError */
extern TNimType NTI3652; /* IndexError */
N_NIMCALL(void, TMP54)(void* p, NI op) {
	TY125202* a;
	NI LOC1;
	a = (TY125202*)p;
	LOC1 = 0;
	for (LOC1 = 0; LOC1 < a->Sup.len; LOC1++) {
	nimGCvisit((void*)a->data[LOC1], op);
	}
}

N_NIMCALL(void, nossplitPath)(NimStringDesc* path, Keyvaluepair140205* Result) {
	NI seppos;
	seppos = ((NI) -1);
	{
		NI i_118490;
		NI HEX3Atmp_118503;
		NI res_118506;
		i_118490 = 0;
		HEX3Atmp_118503 = 0;
		HEX3Atmp_118503 = (NI)((path ? path->Sup.len : 0) - ((NI) 1));
		res_118506 = HEX3Atmp_118503;
		{
			while (1) {
				if (!(((NI) 0) <= res_118506)) goto LA3;
				i_118490 = res_118506;
				{
					if (!(((NU8)(path->data[i_118490])) == ((NU8)(47)) || ((NU8)(path->data[i_118490])) == ((NU8)(47)))) goto LA6;
					seppos = i_118490;
					goto LA1;
				}
				LA6: ;
				res_118506 -= ((NI) 1);
			} LA3: ;
		}
	} LA1: ;
	{
		if (!(((NI) 0) <= seppos)) goto LA10;
		unsureAsgnRef((void**) (&(*Result).Field0), copyStrLast(path, ((NI) 0), (NI)(seppos - ((NI) 1))));
		unsureAsgnRef((void**) (&(*Result).Field1), copyStr(path, (NI)(seppos + ((NI) 1))));
	}
	goto LA8;
	LA10: ;
	{
		unsureAsgnRef((void**) (&(*Result).Field0), copyString(((NimStringDesc*) &TMP146)));
		unsureAsgnRef((void**) (&(*Result).Field1), copyString(path));
	}
	LA8: ;
}

N_NIMCALL(NimStringDesc*, nosextractFilename)(NimStringDesc* path) {
	NimStringDesc* result;
	result = 0;
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = ((path ? path->Sup.len : 0) == ((NI) 0));
		if (LOC3) goto LA4;
		LOC3 = (((NU8)(path->data[(NI)((path ? path->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47)) || ((NU8)(path->data[(NI)((path ? path->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47)));
		LA4: ;
		if (!LOC3) goto LA5;
		result = copyString(((NimStringDesc*) &TMP146));
	}
	goto LA1;
	LA5: ;
	{
		Keyvaluepair140205 LOC8;
		memset((void*)(&LOC8), 0, sizeof(LOC8));
		nossplitPath(path, (&LOC8));
		result = copyString(LOC8.Field1);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NI, searchextpos_118669)(NimStringDesc* s) {
	NI result;
	result = 0;
	result = ((NI) -1);
	{
		NI i_118683;
		NI HEX3Atmp_118696;
		NI res_118699;
		i_118683 = 0;
		HEX3Atmp_118696 = 0;
		HEX3Atmp_118696 = (NI)((s ? s->Sup.len : 0) - ((NI) 1));
		res_118699 = HEX3Atmp_118696;
		{
			while (1) {
				if (!(((NI) 1) <= res_118699)) goto LA3;
				i_118683 = res_118699;
				{
					if (!((NU8)(s->data[i_118683]) == (NU8)(46))) goto LA6;
					result = i_118683;
					goto LA1;
				}
				goto LA4;
				LA6: ;
				{
					if (!(((NU8)(s->data[i_118683])) == ((NU8)(47)) || ((NU8)(s->data[i_118683])) == ((NU8)(47)))) goto LA9;
					goto LA1;
				}
				goto LA4;
				LA9: ;
				LA4: ;
				res_118699 -= ((NI) 1);
			} LA3: ;
		}
	} LA1: ;
	return result;
}

static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src) {
	memcpy(((NCSTRING) ((&(*dest).data[((*dest).Sup.len)- 0]))), ((NCSTRING) ((*src).data)), (NI)((*src).Sup.len + ((NI) 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[((NI)((*dest).Sup.len + ((NI) 1)))- 0] = 0;
	(*dest).Sup.len += ((NI) 1);
}

N_NIMCALL(NimStringDesc*, normext_118665)(NimStringDesc* ext) {
	NimStringDesc* result;
	result = 0;
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = ((ext) && (ext)->Sup.len == 0);
		if (LOC3) goto LA4;
		LOC3 = ((NU8)(ext->data[((NI) 0)]) == (NU8)(46));
		LA4: ;
		if (!LOC3) goto LA5;
		result = copyString(ext);
	}
	goto LA1;
	LA5: ;
	{
		NimStringDesc* LOC8;
		LOC8 = 0;
		LOC8 = rawNewString(ext->Sup.len + 1);
appendChar(LOC8, 46);
appendString(LOC8, ext);
		result = LOC8;
	}
	LA1: ;
	return result;
}

N_NIMCALL(NimStringDesc*, noschangeFileExt)(NimStringDesc* filename, NimStringDesc* ext) {
	NimStringDesc* result;
	NI extpos;
	result = 0;
	extpos = searchextpos_118669(filename);
	{
		NimStringDesc* LOC5;
		NimStringDesc* LOC6;
		if (!(extpos < ((NI) 0))) goto LA3;
		LOC5 = 0;
		LOC6 = 0;
		LOC6 = normext_118665(ext);
		LOC5 = rawNewString(filename->Sup.len + LOC6->Sup.len + 0);
appendString(LOC5, filename);
appendString(LOC5, LOC6);
		result = LOC5;
	}
	goto LA1;
	LA3: ;
	{
		NimStringDesc* LOC8;
		NimStringDesc* LOC9;
		NimStringDesc* LOC10;
		LOC8 = 0;
		LOC9 = 0;
		LOC9 = copyStrLast(filename, ((NI) 0), (NI)(extpos - ((NI) 1)));
		LOC10 = 0;
		LOC10 = normext_118665(ext);
		LOC8 = rawNewString(LOC9->Sup.len + LOC10->Sup.len + 0);
appendString(LOC8, LOC9);
appendString(LOC8, LOC10);
		result = LOC8;
	}
	LA1: ;
	return result;
}

N_NIMCALL(NimStringDesc*, oserrormsg_120611)(NI32 errorcode) {
	NimStringDesc* result;
	result = 0;
	result = copyString(((NimStringDesc*) &TMP146));
	{
		NCSTRING LOC5;
		if (!!((errorcode == ((NI32) 0)))) goto LA3;
		LOC5 = 0;
		LOC5 = strerror(errorcode);
		result = cstrToNimstr(LOC5);
	}
	LA3: ;
	return result;
}

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

static N_INLINE(void, rtladdzct_53001)(Cell47505* c) {
	addzct_51417((&gch_49859.zct), c);
}

static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src) {
	{
		Cell47505* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_51440(src);
		(*c).refcount += ((NI) 8);
	}
	LA3: ;
	{
		Cell47505* c;
		if (!!(((*dest) == NIM_NIL))) goto LA7;
		c = usrtocell_51440((*dest));
		{
			(*c).refcount -= ((NI) 8);
			if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA11;
			rtladdzct_53001(c);
		}
		LA11: ;
	}
	LA7: ;
	(*dest) = src;
}

static N_INLINE(void, nimGCunrefNoCycle)(void* p) {
	Cell47505* c;
	c = usrtocell_51440(p);
	{
		(*c).refcount -= ((NI) 8);
		if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA3;
		rtladdzct_53001(c);
	}
	LA3: ;
}

N_NOINLINE(void, raiseoserror_120803)(NI32 errorcode, NimStringDesc* additionalinfo) {
	Oserror3630* e;
	e = 0;
	e = (Oserror3630*) newObj((&NTI120807), sizeof(Oserror3630));
	(*e).Sup.Sup.Sup.m_type = (&NTI3630);
	(*e).errorcode = errorcode;
	{
		if (!((additionalinfo ? additionalinfo->Sup.len : 0) == ((NI) 0))) goto LA3;
		asgnRefNoCycle((void**) (&(*e).Sup.Sup.message), oserrormsg_120611(errorcode));
	}
	goto LA1;
	LA3: ;
	{
		NimStringDesc* LOC6;
		NimStringDesc* LOC7;
		LOC6 = 0;
		LOC7 = 0;
		LOC7 = oserrormsg_120611(errorcode);
		LOC6 = rawNewString(additionalinfo->Sup.len + LOC7->Sup.len + 1);
appendString(LOC6, additionalinfo);
appendString(LOC6, ((NimStringDesc*) &TMP1227));
appendString(LOC6, LOC7);
		asgnRefNoCycle((void**) (&(*e).Sup.Sup.message), LOC6);
	}
	LA1: ;
	{
		NimStringDesc* LOC12;
		if (!(((*e).Sup.Sup.message) && ((*e).Sup.Sup.message)->Sup.len == 0)) goto LA10;
		LOC12 = 0;
		LOC12 = (*e).Sup.Sup.message; (*e).Sup.Sup.message = copyStringRC1(((NimStringDesc*) &TMP1228));
		if (LOC12) nimGCunrefNoCycle(LOC12);
	}
	LA10: ;
	raiseException((Exception*)e, "OSError");
}

N_NIMCALL(NI32, oslasterror_120819)(void) {
	NI32 result;
	result = 0;
	result = errno;
	return result;
}

N_NIMCALL(NimStringDesc*, nosexpandFilename)(NimStringDesc* filename) {
	NimStringDesc* result;
	NCSTRING r;
	NI LOC6;
	result = 0;
	result = mnewString(((NI) (PATH_MAX)));
	r = realpath(filename->data, result->data);
	{
		NI32 LOC5;
		if (!r == 0) goto LA3;
		LOC5 = 0;
		LOC5 = oslasterror_120819();
		raiseoserror_120803(LOC5, ((NimStringDesc*) &TMP146));
	}
	LA3: ;
	LOC6 = 0;
	LOC6 = strlen(result->data);
	result = setLengthStr(result, ((NI) (LOC6)));
	return result;
}

N_NIMCALL(void, nossplitFile)(NimStringDesc* path, TY118706* Result) {
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = ((path ? path->Sup.len : 0) == ((NI) 0));
		if (LOC3) goto LA4;
		LOC3 = (((NU8)(path->data[(NI)((path ? path->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47)) || ((NU8)(path->data[(NI)((path ? path->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47)));
		LA4: ;
		if (!LOC3) goto LA5;
		unsureAsgnRef((void**) (&(*Result).Field0), copyString(path));
		unsureAsgnRef((void**) (&(*Result).Field1), copyString(((NimStringDesc*) &TMP146)));
		unsureAsgnRef((void**) (&(*Result).Field2), copyString(((NimStringDesc*) &TMP146)));
	}
	goto LA1;
	LA5: ;
	{
		NI seppos;
		NI dotpos;
		seppos = ((NI) -1);
		dotpos = (path ? path->Sup.len : 0);
		{
			NI i_118735;
			NI HEX3Atmp_118759;
			NI res_118762;
			i_118735 = 0;
			HEX3Atmp_118759 = 0;
			HEX3Atmp_118759 = (NI)((path ? path->Sup.len : 0) - ((NI) 1));
			res_118762 = HEX3Atmp_118759;
			{
				while (1) {
					if (!(((NI) 0) <= res_118762)) goto LA10;
					i_118735 = res_118762;
					{
						if (!((NU8)(path->data[i_118735]) == (NU8)(46))) goto LA13;
						{
							NIM_BOOL LOC17;
							NIM_BOOL LOC18;
							LOC17 = 0;
							LOC18 = 0;
							LOC18 = (dotpos == (path ? path->Sup.len : 0));
							if (!(LOC18)) goto LA19;
							LOC18 = (((NI) 0) < i_118735);
							LA19: ;
							LOC17 = LOC18;
							if (!(LOC17)) goto LA20;
							LOC17 = !((((NU8)(path->data[(NI)(i_118735 - ((NI) 1))])) == ((NU8)(47)) || ((NU8)(path->data[(NI)(i_118735 - ((NI) 1))])) == ((NU8)(47))));
							LA20: ;
							if (!LOC17) goto LA21;
							dotpos = i_118735;
						}
						LA21: ;
					}
					goto LA11;
					LA13: ;
					{
						if (!(((NU8)(path->data[i_118735])) == ((NU8)(47)) || ((NU8)(path->data[i_118735])) == ((NU8)(47)))) goto LA24;
						seppos = i_118735;
						goto LA8;
					}
					goto LA11;
					LA24: ;
					LA11: ;
					res_118762 -= ((NI) 1);
				} LA10: ;
			}
		} LA8: ;
		unsureAsgnRef((void**) (&(*Result).Field0), copyStrLast(path, ((NI) 0), (NI)(seppos - ((NI) 1))));
		unsureAsgnRef((void**) (&(*Result).Field1), copyStrLast(path, (NI)(seppos + ((NI) 1)), (NI)(dotpos - ((NI) 1))));
		unsureAsgnRef((void**) (&(*Result).Field2), copyStr(path, dotpos));
	}
	LA1: ;
}

N_NIMCALL(void, getenvvarsc_125402)(void) {
	{
		NI i;
		if (!!(envcomputed_125201)) goto LA3;
		if (environment_125203) nimGCunrefNoCycle(environment_125203);
		environment_125203 = (TY125202*) newSeqRC1((&NTI125202), 0);
		i = ((NI) 0);
		{
			while (1) {
				NimStringDesc* LOC11;
				NimStringDesc* LOC12;
				{
					if (!(environ[(i)- 0] == NIM_NIL)) goto LA9;
					goto LA5;
				}
				LA9: ;
				LOC11 = 0;
				LOC11 = cstrToNimstr(environ[(i)- 0]);
				environment_125203 = (TY125202*) incrSeqV2(&(environment_125203)->Sup, sizeof(NimStringDesc*));
				LOC12 = 0;
				LOC12 = environment_125203->data[environment_125203->Sup.len]; environment_125203->data[environment_125203->Sup.len] = copyStringRC1(LOC11);
				if (LOC12) nimGCunrefNoCycle(LOC12);
				++environment_125203->Sup.len;
				i += ((NI) 1);
			}
		} LA5: ;
		envcomputed_125201 = NIM_TRUE;
	}
	LA3: ;
}

N_NIMCALL(NI, findenvvar_125802)(NimStringDesc* key) {
	NI result;
	NimStringDesc* temp;
	NimStringDesc* LOC1;
{	result = 0;
	getenvvarsc_125402();
	LOC1 = 0;
	LOC1 = rawNewString(key->Sup.len + 1);
appendString(LOC1, key);
appendChar(LOC1, 61);
	temp = LOC1;
	{
		NI i_125816;
		NI HEX3Atmp_125818;
		NI res_125821;
		i_125816 = 0;
		HEX3Atmp_125818 = 0;
		HEX3Atmp_125818 = (environment_125203 ? (environment_125203->Sup.len-1) : -1);
		res_125821 = ((NI) 0);
		{
			while (1) {
				if (!(res_125821 <= HEX3Atmp_125818)) goto LA4;
				i_125816 = res_125821;
				{
					NIM_BOOL LOC7;
					LOC7 = 0;
					LOC7 = nsuStartsWith(environment_125203->data[i_125816], temp);
					if (!LOC7) goto LA8;
					result = i_125816;
					goto BeforeRet;
				}
				LA8: ;
				res_125821 += ((NI) 1);
			} LA4: ;
		}
	}
	result = ((NI) -1);
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, getenv_125825)(NimStringDesc* key) {
	NimStringDesc* result;
	NI i;
{	result = 0;
	i = findenvvar_125802(key);
	{
		NI LOC5;
		if (!(((NI) 0) <= i)) goto LA3;
		LOC5 = 0;
		LOC5 = nsuFindChar(environment_125203->data[i], 61, ((NI) 0));
		result = copyStr(environment_125203->data[i], (NI)(LOC5 + ((NI) 1)));
		goto BeforeRet;
	}
	goto LA1;
	LA3: ;
	{
		NCSTRING env;
		env = getenv(key->data);
		{
			if (!(env == NIM_NIL)) goto LA9;
			result = copyString(((NimStringDesc*) &TMP146));
			goto BeforeRet;
		}
		LA9: ;
		result = cstrToNimstr(env);
	}
	LA1: ;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, paramstr_131407)(NI i) {
	NimStringDesc* result;
	Indexerror3652* e_131414;
	NimStringDesc* LOC7;
{	result = 0;
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = (i < ((NI) (cmdCount)));
		if (!(LOC3)) goto LA4;
		LOC3 = (((NI) 0) <= i);
		LA4: ;
		if (!LOC3) goto LA5;
		result = cstrToNimstr(cmdLine[(i)- 0]);
		goto BeforeRet;
	}
	LA5: ;
	e_131414 = 0;
	e_131414 = (Indexerror3652*) newObj((&NTI131415), sizeof(Indexerror3652));
	(*e_131414).Sup.Sup.m_type = (&NTI3652);
	LOC7 = 0;
	LOC7 = (*e_131414).Sup.message; (*e_131414).Sup.message = copyStringRC1(((NimStringDesc*) &TMP1233));
	if (LOC7) nimGCunrefNoCycle(LOC7);
	raiseException((Exception*)e_131414, "IndexError");
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nosjoinPath)(NimStringDesc* head, NimStringDesc* tail) {
	NimStringDesc* result;
	result = 0;
	{
		if (!((head ? head->Sup.len : 0) == ((NI) 0))) goto LA3;
		result = copyString(tail);
	}
	goto LA1;
	LA3: ;
	{
		if (!(((NU8)(head->data[(NI)((head ? head->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47)) || ((NU8)(head->data[(NI)((head ? head->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47)))) goto LA6;
		{
			NimStringDesc* LOC12;
			NimStringDesc* LOC13;
			if (!(((NU8)(tail->data[((NI) 0)])) == ((NU8)(47)) || ((NU8)(tail->data[((NI) 0)])) == ((NU8)(47)))) goto LA10;
			LOC12 = 0;
			LOC13 = 0;
			LOC13 = copyStr(tail, ((NI) 1));
			LOC12 = rawNewString(head->Sup.len + LOC13->Sup.len + 0);
appendString(LOC12, head);
appendString(LOC12, LOC13);
			result = LOC12;
		}
		goto LA8;
		LA10: ;
		{
			NimStringDesc* LOC15;
			LOC15 = 0;
			LOC15 = rawNewString(head->Sup.len + tail->Sup.len + 0);
appendString(LOC15, head);
appendString(LOC15, tail);
			result = LOC15;
		}
		LA8: ;
	}
	goto LA1;
	LA6: ;
	{
		{
			NimStringDesc* LOC21;
			if (!(((NU8)(tail->data[((NI) 0)])) == ((NU8)(47)) || ((NU8)(tail->data[((NI) 0)])) == ((NU8)(47)))) goto LA19;
			LOC21 = 0;
			LOC21 = rawNewString(head->Sup.len + tail->Sup.len + 0);
appendString(LOC21, head);
appendString(LOC21, tail);
			result = LOC21;
		}
		goto LA17;
		LA19: ;
		{
			NimStringDesc* LOC23;
			LOC23 = 0;
			LOC23 = rawNewString(head->Sup.len + tail->Sup.len + 1);
appendString(LOC23, head);
appendChar(LOC23, 47);
appendString(LOC23, tail);
			result = LOC23;
		}
		LA17: ;
	}
	LA1: ;
	return result;
}

N_NIMCALL(NIM_BOOL, nosexistsFile)(NimStringDesc* filename) {
	NIM_BOOL result;
	struct stat res;
	NIM_BOOL LOC1;
	int LOC2;
{	result = 0;
	memset((void*)(&res), 0, sizeof(res));
	LOC1 = 0;
	LOC2 = 0;
	LOC2 = stat(filename->data, (&res));
	LOC1 = (((NI32) 0) <= LOC2);
	if (!(LOC1)) goto LA3;
	LOC1 = S_ISREG(res.st_mode);
	LA3: ;
	result = LOC1;
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, getapplheuristic_132001)(void) {
	NimStringDesc* result;
{	result = 0;
	result = paramstr_131407(((NI) 0));
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = (((NI) 0) < (result ? result->Sup.len : 0));
		if (!(LOC3)) goto LA4;
		LOC3 = !(((NU8)(result->data[((NI) 0)]) == (NU8)(47)));
		LA4: ;
		if (!LOC3) goto LA5;
		{
			NimStringDesc* p_132202;
			NimStringDesc* HEX3Atmp_132209;
			NI last_132214;
			p_132202 = 0;
			HEX3Atmp_132209 = 0;
			HEX3Atmp_132209 = getenv_125825(((NimStringDesc*) &TMP1234));
			last_132214 = ((NI) 0);
			{
				while (1) {
					NI first_132216;
					if (!(last_132214 < (HEX3Atmp_132209 ? HEX3Atmp_132209->Sup.len : 0))) goto LA9;
					{
						while (1) {
							if (!(((NU8)(HEX3Atmp_132209->data[last_132214])) == ((NU8)(58)))) goto LA11;
							last_132214 += ((NI) 1);
						} LA11: ;
					}
					first_132216 = last_132214;
					{
						while (1) {
							NIM_BOOL LOC14;
							LOC14 = 0;
							LOC14 = (last_132214 < (HEX3Atmp_132209 ? HEX3Atmp_132209->Sup.len : 0));
							if (!(LOC14)) goto LA15;
							LOC14 = !((((NU8)(HEX3Atmp_132209->data[last_132214])) == ((NU8)(58))));
							LA15: ;
							if (!LOC14) goto LA13;
							last_132214 += ((NI) 1);
						} LA13: ;
					}
					{
						NimStringDesc* x;
						if (!(first_132216 <= (NI)(last_132214 - ((NI) 1)))) goto LA18;
						p_132202 = copyStrLast(HEX3Atmp_132209, first_132216, (NI)(last_132214 - ((NI) 1)));
						x = nosjoinPath(p_132202, result);
						{
							NIM_BOOL LOC22;
							LOC22 = 0;
							LOC22 = nosexistsFile(x);
							if (!LOC22) goto LA23;
							result = copyString(x);
							goto BeforeRet;
						}
						LA23: ;
					}
					LA18: ;
				} LA9: ;
			}
		}
	}
	LA5: ;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nosgetAppFilename)(void) {
	NimStringDesc* result;
	result = 0;
	result = getenv_125825(((NimStringDesc*) &TMP1231));
	{
		if (!((result ? result->Sup.len : 0) == ((NI) 0))) goto LA3;
		result = getapplheuristic_132001();
	}
	LA3: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nosgetAppDir)(void) {
	NimStringDesc* result;
	NimStringDesc* LOC1;
	TY118706 LOC2;
	result = 0;
	LOC1 = 0;
	LOC1 = nosgetAppFilename();
	memset((void*)(&LOC2), 0, sizeof(LOC2));
	nossplitFile(LOC1, (&LOC2));
	result = copyString(LOC2.Field0);
	return result;
}

N_NIMCALL(NI, parentdirpos_118510)(NimStringDesc* path) {
	NI result;
	NI q;
{	result = 0;
	q = ((NI) 1);
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = (((NI) 1) <= (path ? path->Sup.len : 0));
		if (!(LOC3)) goto LA4;
		LOC3 = (((NU8)(path->data[(NI)((path ? path->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47)) || ((NU8)(path->data[(NI)((path ? path->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47)));
		LA4: ;
		if (!LOC3) goto LA5;
		q = ((NI) 2);
	}
	LA5: ;
	{
		NI i_118536;
		NI HEX3Atmp_118549;
		NI res_118552;
		i_118536 = 0;
		HEX3Atmp_118549 = 0;
		HEX3Atmp_118549 = (NI)((path ? path->Sup.len : 0) - q);
		res_118552 = HEX3Atmp_118549;
		{
			while (1) {
				if (!(((NI) 0) <= res_118552)) goto LA9;
				i_118536 = res_118552;
				{
					if (!(((NU8)(path->data[i_118536])) == ((NU8)(47)) || ((NU8)(path->data[i_118536])) == ((NU8)(47)))) goto LA12;
					result = i_118536;
					goto BeforeRet;
				}
				LA12: ;
				res_118552 -= ((NI) 1);
			} LA9: ;
		}
	}
	result = ((NI) -1);
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nosparentDir)(NimStringDesc* path) {
	NimStringDesc* result;
	NI seppos;
	result = 0;
	seppos = parentdirpos_118510(path);
	{
		if (!(((NI) 0) <= seppos)) goto LA3;
		result = copyStrLast(path, ((NI) 0), (NI)(seppos - ((NI) 1)));
	}
	goto LA1;
	LA3: ;
	{
		result = copyString(((NimStringDesc*) &TMP146));
	}
	LA1: ;
	return result;
}

N_NIMCALL(NimStringDesc*, HEX2F_118465)(NimStringDesc* head, NimStringDesc* tail) {
	NimStringDesc* result;
{	result = 0;
	result = nosjoinPath(head, tail);
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(void, rawcreatedir_127630)(NimStringDesc* dir) {
	{
		NIM_BOOL LOC3;
		int LOC4;
		NI32 LOC8;
		LOC3 = 0;
		LOC4 = 0;
		LOC4 = mkdir(dir->data, ((mode_t) 511));
		LOC3 = !((LOC4 == ((NI32) 0)));
		if (!(LOC3)) goto LA5;
		LOC3 = !((errno == EEXIST));
		LA5: ;
		if (!LOC3) goto LA6;
		LOC8 = 0;
		LOC8 = oslasterror_120819();
		raiseoserror_120803(LOC8, ((NimStringDesc*) &TMP146));
	}
	LA6: ;
}

N_NIMCALL(void, noscreateDir)(NimStringDesc* dir) {
	NIM_BOOL omitnext;
	omitnext = NIM_FALSE;
	{
		NI i_128010;
		NI HEX3Atmp_128023;
		NI res_128026;
		i_128010 = 0;
		HEX3Atmp_128023 = 0;
		HEX3Atmp_128023 = (NI)((dir ? dir->Sup.len : 0) - ((NI) 1));
		res_128026 = ((NI) 1);
		{
			while (1) {
				if (!(res_128026 <= HEX3Atmp_128023)) goto LA3;
				i_128010 = res_128026;
				{
					if (!(((NU8)(dir->data[i_128010])) == ((NU8)(47)) || ((NU8)(dir->data[i_128010])) == ((NU8)(47)))) goto LA6;
					{
						if (!omitnext) goto LA10;
						omitnext = NIM_FALSE;
					}
					goto LA8;
					LA10: ;
					{
						NimStringDesc* LOC13;
						LOC13 = 0;
						LOC13 = copyStrLast(dir, ((NI) 0), (NI)(i_128010 - ((NI) 1)));
						rawcreatedir_127630(LOC13);
					}
					LA8: ;
				}
				LA6: ;
				res_128026 += ((NI) 1);
			} LA3: ;
		}
	}
	rawcreatedir_127630(dir);
}

N_NIMCALL(NimStringDesc*, nosjoinPathOpenArray)(NimStringDesc** parts, NI partsLen0) {
	NimStringDesc* result;
	result = 0;
	result = copyString(parts[((NI) 0)]);
	{
		NI i_118454;
		NI HEX3Atmp_118458;
		NI res_118461;
		i_118454 = 0;
		HEX3Atmp_118458 = 0;
		HEX3Atmp_118458 = (partsLen0-1);
		res_118461 = ((NI) 1);
		{
			while (1) {
				if (!(res_118461 <= HEX3Atmp_118458)) goto LA3;
				i_118454 = res_118461;
				result = nosjoinPath(result, parts[i_118454]);
				res_118461 += ((NI) 1);
			} LA3: ;
		}
	}
	return result;
}

N_NIMCALL(NimStringDesc*, nosaddFileExt)(NimStringDesc* filename, NimStringDesc* ext) {
	NimStringDesc* result;
	NI extpos;
	result = 0;
	extpos = searchextpos_118669(filename);
	{
		NimStringDesc* LOC5;
		NimStringDesc* LOC6;
		if (!(extpos < ((NI) 0))) goto LA3;
		LOC5 = 0;
		LOC6 = 0;
		LOC6 = normext_118665(ext);
		LOC5 = rawNewString(filename->Sup.len + LOC6->Sup.len + 0);
appendString(LOC5, filename);
appendString(LOC5, LOC6);
		result = LOC5;
	}
	goto LA1;
	LA3: ;
	{
		result = copyString(filename);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NIM_BOOL, nosisAbsolute)(NimStringDesc* path) {
	NIM_BOOL result;
	result = 0;
	result = ((NU8)(path->data[((NI) 0)]) == (NU8)(47));
	return result;
}

N_NIMCALL(NI, paramcount_131426)(void) {
	NI result;
	result = 0;
	result = ((NI) ((NI32)(cmdCount - ((NI32) 1))));
	return result;
}

N_NIMCALL(NimStringDesc*, nosunixToNativePath)(NimStringDesc* path, NimStringDesc* drive) {
	NimStringDesc* result;
	result = 0;
	result = copyString(path);
	return result;
}

N_NIMCALL(NimStringDesc*, nosgetHomeDir)(void) {
	NimStringDesc* result;
	NimStringDesc* LOC1;
	NimStringDesc* LOC2;
{	result = 0;
	LOC1 = 0;
	LOC2 = 0;
	LOC2 = getenv_125825(((NimStringDesc*) &TMP1789));
	LOC1 = rawNewString(LOC2->Sup.len + 1);
appendString(LOC1, LOC2);
appendString(LOC1, ((NimStringDesc*) &TMP1790));
	result = LOC1;
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NI, noscmpPaths)(NimStringDesc* patha, NimStringDesc* pathb) {
	NI result;
	result = 0;
	{
		if (!NIM_TRUE) goto LA3;
		result = cmp_5680(patha, pathb);
	}
	goto LA1;
	LA3: ;
	{
		result = nsuCmpIgnoreCase(patha, pathb);
	}
	LA1: ;
	return result;
}

N_NIMCALL(void, putenv_125838)(NimStringDesc* key, NimStringDesc* val) {
	NI indx;
	indx = findenvvar_125802(key);
	{
		NimStringDesc* LOC5;
		if (!(((NI) 0) <= indx)) goto LA3;
		LOC5 = 0;
		LOC5 = rawNewString(key->Sup.len + val->Sup.len + 1);
appendString(LOC5, key);
appendChar(LOC5, 61);
appendString(LOC5, val);
		asgnRefNoCycle((void**) (&environment_125203->data[indx]), LOC5);
	}
	goto LA1;
	LA3: ;
	{
		NimStringDesc* LOC7;
		NimStringDesc* LOC8;
		LOC7 = 0;
		LOC7 = rawNewString(key->Sup.len + val->Sup.len + 1);
appendString(LOC7, key);
appendChar(LOC7, 61);
appendString(LOC7, val);
		environment_125203 = (TY125202*) incrSeqV2(&(environment_125203)->Sup, sizeof(NimStringDesc*));
		LOC8 = 0;
		LOC8 = environment_125203->data[environment_125203->Sup.len]; environment_125203->data[environment_125203->Sup.len] = copyStringRC1(LOC7);
		if (LOC8) nimGCunrefNoCycle(LOC8);
		++environment_125203->Sup.len;
		indx = (environment_125203 ? (environment_125203->Sup.len-1) : -1);
	}
	LA1: ;
	{
		int LOC11;
		NI32 LOC14;
		LOC11 = 0;
		LOC11 = putenv(environment_125203->data[indx]->data);
		if (!!((LOC11 == ((NI32) 0)))) goto LA12;
		LOC14 = 0;
		LOC14 = oslasterror_120819();
		raiseoserror_120803(LOC14, ((NimStringDesc*) &TMP146));
	}
	LA12: ;
}

N_NIMCALL(NimStringDesc*, nosgetCurrentDir)(void) {
	NimStringDesc* result;
	result = 0;
	result = mnewString(((NI) 512));
	{
		NCSTRING LOC3;
		NI LOC6;
		LOC3 = 0;
		LOC3 = getcwd(result->data, ((NI) 512));
		if (!!((LOC3 == NIM_NIL))) goto LA4;
		LOC6 = 0;
		LOC6 = strlen(result->data);
		result = setLengthStr(result, ((NI) (LOC6)));
	}
	goto LA1;
	LA4: ;
	{
		NI32 LOC8;
		LOC8 = 0;
		LOC8 = oslasterror_120819();
		raiseoserror_120803(LOC8, ((NimStringDesc*) &TMP146));
	}
	LA1: ;
	return result;
}

N_NIMCALL(NIM_BOOL, nossymlinkExists)(NimStringDesc* link) {
	NIM_BOOL result;
	struct stat res;
	NIM_BOOL LOC1;
	int LOC2;
{	result = 0;
	memset((void*)(&res), 0, sizeof(res));
	LOC1 = 0;
	LOC2 = 0;
	LOC2 = lstat(link->data, (&res));
	LOC1 = (((NI32) 0) <= LOC2);
	if (!(LOC1)) goto LA3;
	LOC1 = S_ISLNK(res.st_mode);
	LA3: ;
	result = LOC1;
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, expandtilde_130601)(NimStringDesc* path) {
	NimStringDesc* result;
	result = 0;
	{
		NIM_BOOL LOC3;
		NIM_BOOL LOC4;
		NIM_BOOL LOC7;
		NimStringDesc* LOC11;
		NimStringDesc* LOC12;
		LOC3 = 0;
		LOC4 = 0;
		LOC4 = (((NI) 1) < (path ? path->Sup.len : 0));
		if (!(LOC4)) goto LA5;
		LOC4 = ((NU8)(path->data[((NI) 0)]) == (NU8)(126));
		LA5: ;
		LOC3 = LOC4;
		if (!(LOC3)) goto LA6;
		LOC7 = 0;
		LOC7 = ((NU8)(path->data[((NI) 1)]) == (NU8)(47));
		if (LOC7) goto LA8;
		LOC7 = ((NU8)(path->data[((NI) 1)]) == (NU8)(92));
		LA8: ;
		LOC3 = LOC7;
		LA6: ;
		if (!LOC3) goto LA9;
		LOC11 = 0;
		LOC11 = nosgetHomeDir();
		LOC12 = 0;
		LOC12 = copyStr(path, ((NI) 2));
		result = HEX2F_118465(LOC11, LOC12);
	}
	goto LA1;
	LA9: ;
	{
		result = copyString(path);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NimStringDesc*, findexe_130801)(NimStringDesc* exe) {
	NimStringDesc* result;
	NimStringDesc* path;
{	result = 0;
	result = nosaddFileExt(exe, ((NimStringDesc*) &TMP146));
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = nosexistsFile(result);
		if (!LOC3) goto LA4;
		goto BeforeRet;
	}
	LA4: ;
	path = getenv_125825(((NimStringDesc*) &TMP1234));
	{
		NimStringDesc* candidate_130806;
		NI last_131007;
		candidate_130806 = 0;
		last_131007 = ((NI) 0);
		{
			if (!(((NI) 0) < (path ? path->Sup.len : 0))) goto LA9;
			{
				while (1) {
					NI first_131009;
					NimStringDesc* x;
					NimStringDesc* LOC17;
					if (!(last_131007 <= (path ? path->Sup.len : 0))) goto LA12;
					first_131009 = last_131007;
					{
						while (1) {
							NIM_BOOL LOC15;
							LOC15 = 0;
							LOC15 = (last_131007 < (path ? path->Sup.len : 0));
							if (!(LOC15)) goto LA16;
							LOC15 = !(((NU8)(path->data[last_131007]) == (NU8)(58)));
							LA16: ;
							if (!LOC15) goto LA14;
							last_131007 += ((NI) 1);
						} LA14: ;
					}
					candidate_130806 = copyStrLast(path, first_131009, (NI)(last_131007 - ((NI) 1)));
					LOC17 = 0;
					LOC17 = expandtilde_130601(candidate_130806);
					x = HEX2F_118465(LOC17, result);
					{
						NIM_BOOL LOC20;
						LOC20 = 0;
						LOC20 = nosexistsFile(x);
						if (!LOC20) goto LA21;
						result = copyString(x);
						goto BeforeRet;
					}
					LA21: ;
					last_131007 += ((NI) 1);
				} LA12: ;
			}
		}
		LA9: ;
	}
	result = copyString(((NimStringDesc*) &TMP146));
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, expandsymlink_131201)(NimStringDesc* symlinkpath) {
	NimStringDesc* result;
	NI len;
	result = 0;
	result = mnewString(((NI) 256));
	len = readlink(symlinkpath->data, result->data, ((NI) 256));
	{
		NI32 LOC5;
		if (!(len < ((NI) 0))) goto LA3;
		LOC5 = 0;
		LOC5 = oslasterror_120819();
		raiseoserror_120803(LOC5, ((NimStringDesc*) &TMP146));
	}
	LA3: ;
	{
		if (!(((NI) 256) < len)) goto LA8;
		result = mnewString(((NI) ((NI)(len + ((NI) 1)))));
		len = readlink(symlinkpath->data, result->data, len);
	}
	LA8: ;
	result = setLengthStr(result, ((NI) (len)));
	return result;
}

N_NIMCALL(NimStringDesc*, nosgetConfigDir)(void) {
	NimStringDesc* result;
	NimStringDesc* LOC1;
	NimStringDesc* LOC2;
{	result = 0;
	LOC1 = 0;
	LOC2 = 0;
	LOC2 = getenv_125825(((NimStringDesc*) &TMP1789));
	LOC1 = rawNewString(LOC2->Sup.len + 9);
appendString(LOC1, LOC2);
appendString(LOC1, ((NimStringDesc*) &TMP2053));
	result = LOC1;
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_BOOL, nosisRootDir)(NimStringDesc* path) {
	NIM_BOOL result;
	NI LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = parentdirpos_118510(path);
	result = (LOC1 < ((NI) 0));
	return result;
}

N_NIMCALL(NIM_BOOL, existsenv_125834)(NimStringDesc* key) {
	NIM_BOOL result;
{	result = 0;
	{
		NCSTRING LOC3;
		LOC3 = 0;
		LOC3 = getenv(key->data);
		if (!!((LOC3 == NIM_NIL))) goto LA4;
		result = NIM_TRUE;
		goto BeforeRet;
	}
	goto LA1;
	LA4: ;
	{
		NI LOC7;
		LOC7 = 0;
		LOC7 = findenvvar_125802(key);
		result = (((NI) 0) <= LOC7);
		goto BeforeRet;
	}
	LA1: ;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_BOOL, nosexistsDir)(NimStringDesc* dir) {
	NIM_BOOL result;
	struct stat res;
	NIM_BOOL LOC1;
	int LOC2;
{	result = 0;
	memset((void*)(&res), 0, sizeof(res));
	LOC1 = 0;
	LOC2 = 0;
	LOC2 = stat(dir->data, (&res));
	LOC1 = (((NI32) 0) <= LOC2);
	if (!(LOC1)) goto LA3;
	LOC1 = S_ISDIR(res.st_mode);
	LA3: ;
	result = LOC1;
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nososErrorMsg)(void) {
	NimStringDesc* result;
	result = 0;
	result = copyString(((NimStringDesc*) &TMP146));
	{
		NCSTRING LOC5;
		if (!!((errno == ((NI32) 0)))) goto LA3;
		LOC5 = 0;
		LOC5 = strerror(errno);
		result = cstrToNimstr(LOC5);
	}
	LA3: ;
	return result;
}

N_NOINLINE(void, nosraiseOSError)(NimStringDesc* msg) {
	{
		NimStringDesc* m;
		Oserror3630* e_120408;
		if (!((msg ? msg->Sup.len : 0) == ((NI) 0))) goto LA3;
		m = nososErrorMsg();
		e_120408 = 0;
		e_120408 = (Oserror3630*) newObj((&NTI120807), sizeof(Oserror3630));
		(*e_120408).Sup.Sup.Sup.m_type = (&NTI3630);
		{
			NimStringDesc* LOC9;
			if (!(((NI) 0) < (m ? m->Sup.len : 0))) goto LA7;
			LOC9 = 0;
			LOC9 = (*e_120408).Sup.Sup.message; (*e_120408).Sup.Sup.message = copyStringRC1(m);
			if (LOC9) nimGCunrefNoCycle(LOC9);
		}
		goto LA5;
		LA7: ;
		{
			NimStringDesc* LOC11;
			LOC11 = 0;
			LOC11 = (*e_120408).Sup.Sup.message; (*e_120408).Sup.Sup.message = copyStringRC1(((NimStringDesc*) &TMP1228));
			if (LOC11) nimGCunrefNoCycle(LOC11);
		}
		LA5: ;
		raiseException((Exception*)e_120408, "OSError");
	}
	goto LA1;
	LA3: ;
	{
		Oserror3630* e_120421;
		NimStringDesc* LOC13;
		e_120421 = 0;
		e_120421 = (Oserror3630*) newObj((&NTI120807), sizeof(Oserror3630));
		(*e_120421).Sup.Sup.Sup.m_type = (&NTI3630);
		LOC13 = 0;
		LOC13 = (*e_120421).Sup.Sup.message; (*e_120421).Sup.Sup.message = copyStringRC1(msg);
		if (LOC13) nimGCunrefNoCycle(LOC13);
		raiseException((Exception*)e_120421, "OSError");
	}
	LA1: ;
}

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(void, nosremoveFile)(NimStringDesc* file) {
	{
		NIM_BOOL LOC3;
		int LOC4;
		NI32 LOC8;
		NCSTRING LOC9;
		NimStringDesc* LOC10;
		LOC3 = 0;
		LOC4 = 0;
		LOC4 = remove(file->data);
		LOC3 = !((LOC4 == ((NI32) 0)));
		if (!(LOC3)) goto LA5;
		LOC3 = !((errno == ENOENT));
		LA5: ;
		if (!LOC3) goto LA6;
		LOC8 = 0;
		LOC8 = oslasterror_120819();
		LOC9 = 0;
		LOC9 = strerror(errno);
		LOC10 = 0;
		LOC10 = cstrToNimstr(LOC9);
		raiseoserror_120803(LOC8, LOC10);
	}
	LA6: ;
}

N_NIMCALL(void, rawremovedir_127514)(NimStringDesc* dir) {
	{
		NIM_BOOL LOC3;
		int LOC4;
		NI32 LOC8;
		LOC3 = 0;
		LOC4 = 0;
		LOC4 = rmdir(dir->data);
		LOC3 = !((LOC4 == ((NI32) 0)));
		if (!(LOC3)) goto LA5;
		LOC3 = !((errno == ENOENT));
		LA5: ;
		if (!LOC3) goto LA6;
		LOC8 = 0;
		LOC8 = oslasterror_120819();
		raiseoserror_120803(LOC8, ((NimStringDesc*) &TMP146));
	}
	LA6: ;
}

N_NIMCALL(void, nosremoveDir)(NimStringDesc* dir) {
	{
		NU8 kind_127604;
		NimStringDesc* path_127605;
		DIR* d_127621;
		kind_127604 = 0;
		path_127605 = 0;
		d_127621 = opendir(dir->data);
		{
			int LOC39;
			if (!!((d_127621 == NIM_NIL))) goto LA4;
			{
				while (1) {
					struct dirent* x_127623;
					NimStringDesc* y_127625;
					x_127623 = readdir(d_127621);
					{
						if (!(x_127623 == NIM_NIL)) goto LA10;
						goto LA6;
					}
					LA10: ;
					y_127625 = cstrToNimstr(((NCSTRING) ((*x_127623).d_name)));
					{
						NIM_BOOL LOC14;
						struct stat s_127627;
						NU8 k_127629;
						LOC14 = 0;
						LOC14 = !(eqStrings(y_127625, ((NimStringDesc*) &TMP3668)));
						if (!(LOC14)) goto LA15;
						LOC14 = !(eqStrings(y_127625, ((NimStringDesc*) &TMP3669)));
						LA15: ;
						if (!LOC14) goto LA16;
						memset((void*)(&s_127627), 0, sizeof(s_127627));
						{
							if (!NIM_TRUE) goto LA20;
							y_127625 = HEX2F_118465(dir, y_127625);
						}
						LA20: ;
						k_127629 = ((NU8) 0);
						{
							int LOC24;
							LOC24 = 0;
							LOC24 = lstat(y_127625->data, (&s_127627));
							if (!(LOC24 < ((NI32) 0))) goto LA25;
							goto LA6;
						}
						LA25: ;
						{
							NIM_BOOL LOC29;
							LOC29 = 0;
							LOC29 = S_ISDIR(s_127627.st_mode);
							if (!LOC29) goto LA30;
							k_127629 = ((NU8) 2);
						}
						LA30: ;
						{
							NIM_BOOL LOC34;
							LOC34 = 0;
							LOC34 = S_ISLNK(s_127627.st_mode);
							if (!LOC34) goto LA35;
							k_127629 = (NU8)(k_127629 + ((NI) 1));
						}
						LA35: ;
						kind_127604 = k_127629;
						path_127605 = y_127625;
						switch (kind_127604) {
						case ((NU8) 0):
						case ((NU8) 1):
						case ((NU8) 3):
						{
							nosremoveFile(path_127605);
						}
						break;
						case ((NU8) 2):
						{
							nosremoveDir(path_127605);
						}
						break;
						}
					}
					LA16: ;
				}
			} LA6: ;
			LOC39 = 0;
			LOC39 = closedir(d_127621);
		}
		LA4: ;
	}
	rawremovedir_127514(dir);
}

N_NIMCALL(void, nosmoveFile)(NimStringDesc* source, NimStringDesc* dest) {
	{
		int LOC3;
		NI32 LOC6;
		NCSTRING LOC7;
		NimStringDesc* LOC8;
		LOC3 = 0;
		LOC3 = rename(source->data, dest->data);
		if (!!((LOC3 == ((NI32) 0)))) goto LA4;
		LOC6 = 0;
		LOC6 = oslasterror_120819();
		LOC7 = 0;
		LOC7 = strerror(errno);
		LOC8 = 0;
		LOC8 = cstrToNimstr(LOC7);
		raiseoserror_120803(LOC6, LOC8);
	}
	LA4: ;
}

N_NIMCALL(void, noscopyFile)(NimStringDesc* source, NimStringDesc* dest) {
	FILE* d;
	FILE* s;
	void* buf;
	d = 0;
	s = 0;
	{
		NIM_BOOL LOC3;
		NI32 LOC6;
		LOC3 = 0;
		LOC3 = open_15403(&s, source, ((NU8) 0), ((NI) -1));
		if (!!(LOC3)) goto LA4;
		LOC6 = 0;
		LOC6 = oslasterror_120819();
		raiseoserror_120803(LOC6, ((NimStringDesc*) &TMP146));
	}
	LA4: ;
	{
		NIM_BOOL LOC9;
		NI32 LOC12;
		LOC9 = 0;
		LOC9 = open_15403(&d, dest, ((NU8) 1), ((NI) -1));
		if (!!(LOC9)) goto LA10;
		fclose(s);
		LOC12 = 0;
		LOC12 = oslasterror_120819();
		raiseoserror_120803(LOC12, ((NimStringDesc*) &TMP146));
	}
	LA10: ;
	buf = alloc_7401(((NI) 8000));
	{
		while (1) {
			NI bytesread;
			bytesread = readbuffer_15554(s, buf, ((NI) 8000));
			{
				NI byteswritten;
				if (!(((NI) 0) < bytesread)) goto LA17;
				byteswritten = writebuffer_15576(d, buf, ((NI) (bytesread)));
				{
					NI32 LOC23;
					if (!!((bytesread == byteswritten))) goto LA21;
					dealloc_7448(buf);
					fclose(s);
					fclose(d);
					LOC23 = 0;
					LOC23 = oslasterror_120819();
					raiseoserror_120803(LOC23, ((NimStringDesc*) &TMP146));
				}
				LA21: ;
			}
			LA17: ;
			{
				if (!!((bytesread == ((NI) 8000)))) goto LA26;
				goto LA13;
			}
			LA26: ;
		}
	} LA13: ;
	dealloc_7448(buf);
	fclose(s);
	fclose(d);
}

N_NIMCALL(time_t, nosgetLastModificationTime)(NimStringDesc* file) {
	time_t result;
	struct stat res;
{	result = 0;
	memset((void*)(&res), 0, sizeof(res));
	{
		int LOC3;
		NI32 LOC6;
		LOC3 = 0;
		LOC3 = stat(file->data, (&res));
		if (!(LOC3 < ((NI32) 0))) goto LA4;
		LOC6 = 0;
		LOC6 = oslasterror_120819();
		raiseoserror_120803(LOC6, ((NimStringDesc*) &TMP146));
	}
	LA4: ;
	result = res.st_mtime;
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_BOOL, nosfileNewer)(NimStringDesc* a, NimStringDesc* b) {
	NIM_BOOL result;
	time_t LOC1;
	time_t LOC2;
	NI64 LOC3;
	result = 0;
	LOC1 = 0;
	LOC1 = nosgetLastModificationTime(a);
	LOC2 = 0;
	LOC2 = nosgetLastModificationTime(b);
	LOC3 = 0;
	LOC3 = ntDiffTime(LOC1, LOC2);
	result = (IL64(0) <= LOC3);
	return result;
}

N_NIMCALL(void, nossleep)(NI milsecs) {
	struct timespec a;
	struct timespec b;
	int LOC1;
	memset((void*)(&a), 0, sizeof(a));
	memset((void*)(&b), 0, sizeof(b));
	a.tv_sec = (NI)(milsecs / ((NI) 1000));
	a.tv_nsec = ((NI) ((NI)(((NI) ((NI)(((NI) ((NI)(milsecs % ((NI) 1000)))) * ((NI) 1000)))) * ((NI) 1000))));
	LOC1 = 0;
	LOC1 = nanosleep((&a), (&b));
}
NIM_EXTERNC N_NOINLINE(void, stdlib_osInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, stdlib_osDatInit000)(void) {
NTI125202.size = sizeof(TY125202*);
NTI125202.kind = 24;
NTI125202.base = (&NTI138);
NTI125202.flags = 2;
NTI125202.marker = TMP54;
}

