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

#include "nimbase.h"
#include <string.h>
#include <stdlib.h>
#include <time.h>
typedef struct TY127402 TY127402;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Keyvaluepair143205 Keyvaluepair143205;
typedef struct Oserror3630 Oserror3630;
typedef struct Systemerror3626 Systemerror3626;
typedef struct Exception Exception;
typedef struct TNimObject TNimObject;
typedef struct Cell47304 Cell47304;
typedef struct Cellseq47320 Cellseq47320;
typedef struct Gcheap49618 Gcheap49618;
typedef struct Gcstack49616 Gcstack49616;
typedef struct Cellset47316 Cellset47316;
typedef struct Pagedesc47312 Pagedesc47312;
typedef struct Memregion29488 Memregion29488;
typedef struct Smallchunk29440 Smallchunk29440;
typedef struct Llchunk29482 Llchunk29482;
typedef struct Bigchunk29442 Bigchunk29442;
typedef struct Intset29414 Intset29414;
typedef struct Trunk29410 Trunk29410;
typedef struct Avlnode29486 Avlnode29486;
typedef struct Gcstat49614 Gcstat49614;
typedef struct TY117115 TY117115;
typedef struct Win32finddata107213 Win32finddata107213;
typedef struct Filetime106255 Filetime106255;
typedef struct Basechunk29438 Basechunk29438;
typedef struct Freecell29430 Freecell29430;
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 Keyvaluepair143205 {
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;
};
typedef N_STDCALL_PTR(NI32, TY106633) (NI32 dwflags, void* lpsource, NI32 dwmessageid, NI32 dwlanguageid, void* lpbuffer, NI32 nsize, void* Arguments);
typedef N_STDCALL_PTR(void, TY106802) (void* p);
struct  Cell47304  {
NI refcount;
TNimType* typ;
};
struct  Cellseq47320  {
NI len;
NI cap;
Cell47304** d;
};
struct  Cellset47316  {
NI counter;
NI max;
Pagedesc47312* head;
Pagedesc47312** data;
};
typedef Smallchunk29440* TY29503[512];
typedef Trunk29410* Trunkbuckets29412[256];
struct  Intset29414  {
Trunkbuckets29412 data;
};
struct  Memregion29488  {
NI minlargeobj;
NI maxlargeobj;
TY29503 freesmallchunks;
Llchunk29482* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk29442* freechunkslist;
Intset29414 chunkstarts;
Avlnode29486* root;
Avlnode29486* deleted;
Avlnode29486* last;
Avlnode29486* freeavlnodes;
};
struct  Gcstat49614  {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct  Gcheap49618  {
Gcstack49616* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq47320 zct;
Cellseq47320 decstack;
Cellset47316 cycleroots;
Cellseq47320 tempstack;
NI recgclock;
Memregion29488 region;
Gcstat49614 stat;
};
typedef N_STDCALL_PTR(NI32, TY106631) (void);
typedef N_STDCALL_PTR(NI32, TY107405) (NI16* lpfilename, NI32 nbufferlength, NI16* lpbuffer, NI16** lpfilepart);
struct TY117115 {
NimStringDesc* Field0;
NimStringDesc* Field1;
NimStringDesc* Field2;
};
typedef N_STDCALL_PTR(NI32, TY106823) (NI handle, NI16* buf, NI32 size);
typedef N_STDCALL_PTR(NI, TY107231) (NI16* lpfilename, Win32finddata107213* lpfindfiledata);
typedef N_STDCALL_PTR(NI32, TY106812) (NI16* pathname, void* security);
typedef N_STDCALL_PTR(NI32, TY107412) (NI16* lpfilename);
typedef N_STDCALL_PTR(NI16*, TY107434) (void);
typedef N_STDCALL_PTR(NI16*, TY107429) (void);
typedef N_STDCALL_PTR(NI32, TY107431) (NI16* para1);
typedef N_STDCALL_PTR(NI32, TY106819) (NI16* lpname, NI16* lpvalue);
typedef N_STDCALL_PTR(NI32, TY106805) (NI32 nbufferlength, NI16* lpbuffer);
struct  Filetime106255  {
NI32 dwlowdatetime;
NI32 dwhighdatetime;
};
typedef NI16 TY107224[260];
typedef NI16 TY107227[14];
struct  Win32finddata107213  {
NI32 dwfileattributes;
Filetime106255 ftcreationtime;
Filetime106255 ftlastaccesstime;
Filetime106255 ftlastwritetime;
NI32 nfilesizehigh;
NI32 nfilesizelow;
NI32 dwreserved0;
NI32 dwreserved1;
TY107224 cfilename;
TY107227 calternatefilename;
};
typedef N_STDCALL_PTR(NI32, TY108215) (NI16* pathname);
typedef N_STDCALL_PTR(NI32, TY107415) (NI16* lpfilename, NI32 dwfileattributes);
typedef N_STDCALL_PTR(NI32, TY107236) (NI hfindfile, Win32finddata107213* lpfindfiledata);
typedef N_STDCALL_PTR(void, TY107402) (NI hfindfile);
typedef N_STDCALL_PTR(NI32, TY106816) (NI16* lppathname);
typedef N_STDCALL_PTR(int, TY107424) (NI16* lpexistingfilename, NI16* lpnewfilename, int bfailifexists);
typedef N_STDCALL_PTR(int, TY107419) (NI16* lpexistingfilename, NI16* lpnewfilename, int bfailifexists);
typedef N_STDCALL_PTR(void, TY107614) (NI32 dwmilliseconds);
struct  Gcstack49616  {
Gcstack49616* prev;
Gcstack49616* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY29419[8];
struct  Pagedesc47312  {
Pagedesc47312* next;
NI key;
TY29419 bits;
};
struct  Basechunk29438  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk29440  {
  Basechunk29438 Sup;
Smallchunk29440* next;
Smallchunk29440* prev;
Freecell29430* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk29482  {
NI size;
NI acc;
Llchunk29482* next;
};
struct  Bigchunk29442  {
  Basechunk29438 Sup;
Bigchunk29442* next;
Bigchunk29442* prev;
NI align;
NF data;
};
struct  Trunk29410  {
Trunk29410* next;
NI key;
TY29419 bits;
};
typedef Avlnode29486* TY29493[2];
struct  Avlnode29486  {
TY29493 link;
NI key;
NI upperbound;
NI level;
};
struct  Freecell29430  {
Freecell29430* next;
NI zerofield;
};
struct TY127402 {
  TGenericSeq Sup;
  NimStringDesc* data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP56)(void* p, NI op);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(void, nossplitPath)(NimStringDesc* path, Keyvaluepair143205* Result);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI start_79610, 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_117078)(NimStringDesc* s);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
N_NIMCALL(NimStringDesc*, normext_117074)(NimStringDesc* ext);
static N_INLINE(void, appendChar)(NimStringDesc* dest, NIM_CHAR c);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
N_NIMCALL(NimStringDesc*, oserrormsg_119611)(NI32 errorcode);
N_NIMCALL(NimStringDesc*, HEX24_83672)(NI16* s);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(Cell47304*, usrtocell_51240)(void* usr);
static N_INLINE(void, rtladdzct_52801)(Cell47304* c);
N_NOINLINE(void, addzct_51217)(Cellseq47320* s, Cell47304* c);
N_NIMCALL(NimStringDesc*, copyStringRC1)(NimStringDesc* src);
static N_INLINE(void, nimGCunrefNoCycle)(void* p);
N_NIMCALL(void, raiseException)(Exception* e, NCSTRING ename);
N_NIMCALL(NI16*, newwidecstring_83412)(NCSTRING source, NI L);
N_NIMCALL(NI16*, newwidecstring_83602)(NimStringDesc* s);
N_NOINLINE(void, raiseoserror_120024)(NI32 errorcode, NimStringDesc* additionalinfo);
N_NIMCALL(NI32, oslasterror_120040)(void);
N_NIMCALL(NimStringDesc*, HEX24_83606)(NI16* w, NI estimate, NI replacement);
N_NIMCALL(void, nossplitFile)(NimStringDesc* path, TY117115* Result);
N_NIMCALL(NimStringDesc*, nosgetAppFilename)(void);
N_NIMCALL(NI, parentdirpos_116919)(NimStringDesc* path);
N_NIMCALL(NimStringDesc*, nosjoinPath)(NimStringDesc* head, NimStringDesc* tail);
N_NIMCALL(NIM_BOOL, nosisAbsolute)(NimStringDesc* path);
N_NIMCALL(void, rawcreatedir_130035)(NimStringDesc* dir);
N_NIMCALL(TY127402*, nosparseCmdLine)(NimStringDesc* c);
N_NIMCALL(void*, newSeq)(TNimType* typ, NI len);
N_NIMCALL(NimStringDesc*, setLengthStr)(NimStringDesc* s, NI newlen);
N_NIMCALL(NimStringDesc*, addChar)(NimStringDesc* s, NIM_CHAR c);
N_NIMCALL(TGenericSeq*, incrSeqV2)(TGenericSeq* seq, NI elemsize);
N_NIMCALL(NimStringDesc*, resizeString)(NimStringDesc* dest, NI addlen);
N_NIMCALL(NimStringDesc*, getenv_128224)(NimStringDesc* key);
N_NIMCALL(NI, findenvvar_128201)(NimStringDesc* key);
N_NIMCALL(void, getenvvarsc_127805)(void);
N_NIMCALL(void*, newSeqRC1)(TNimType* typ, NI len);
N_NIMCALL(NIM_BOOL, nsuStartsWith)(NimStringDesc* s, NimStringDesc* prefix);
N_NIMCALL(NI, nsuFindChar)(NimStringDesc* s, NIM_CHAR sub, NI start);
N_NIMCALL(NimStringDesc*, cstrToNimstr)(NCSTRING str);
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(NIM_BOOL, nosexistsFile)(NimStringDesc* filename);
N_NIMCALL(NimStringDesc*, HEX2F_116874)(NimStringDesc* head, NimStringDesc* tail);
N_NIMCALL(NI, findfirstfile_120416)(NimStringDesc* a, Win32finddata107213* b);
static N_INLINE(NIM_BOOL, skipfinddata_120434)(Win32finddata107213* f);
N_NIMCALL(NimStringDesc*, nosextractFilename)(NimStringDesc* path);
N_NIMCALL(void, nosremoveFile)(NimStringDesc* file);
N_NIMCALL(void, nosremoveDir)(NimStringDesc* dir);
N_NIMCALL(void, rawremovedir_129716)(NimStringDesc* dir);
N_NIMCALL(time_t, wintimetounixtime_110845)(NI64 t);
N_NIMCALL(NI64, rdfiletime_107601)(Filetime106255 f);
N_NIMCALL(NI64, ntDiffTime)(time_t a, time_t b);
N_NIMCALL(time_t, nosgetLastModificationTime)(NimStringDesc* file);
N_NIMCALL(NimStringDesc*, nosgetHomeDir)(void);
STRING_LITERAL(TMP157, "", 0);
STRING_LITERAL(TMP1207, " ", 1);
STRING_LITERAL(TMP1208, "unknown OS error", 16);
STRING_LITERAL(TMP1683, ":\\", 2);
STRING_LITERAL(TMP1684, "\\", 1);
STRING_LITERAL(TMP1685, ".", 1);
STRING_LITERAL(TMP1686, "..\\", 3);
STRING_LITERAL(TMP1803, "USERPROFILE", 11);
STRING_LITERAL(TMP2042, "exe", 3);
STRING_LITERAL(TMP2043, "PATH", 4);
STRING_LITERAL(TMP2061, "APPDATA", 7);
STRING_LITERAL(TMP3672, "*", 1);
NIM_BOOL envcomputed_127401;
TY127402* environment_127403;
TY127402* ownargv_134402;
extern TNimType NTI138; /* string */
TNimType NTI127402; /* seq[string] */
extern TNimType NTI120028; /* ref OSError */
extern TNimType NTI3630; /* OSError */
extern TY106633 Dl_106632;
extern TY106802 Dl_106801;
extern Gcheap49618 gch_49659;
extern TY106631 Dl_106630;
extern TY107405 Dl_107404;
extern TY106823 Dl_106822;
extern TY107231 Dl_107230;
extern TY106812 Dl_106811;
extern TY107412 Dl_107411;
extern TY107434 Dl_107433;
extern TY107429 Dl_107428;
extern TY107431 Dl_107430;
extern TY106819 Dl_106818;
extern TY106805 Dl_106804;
extern TY108215 Dl_108214;
extern TY107415 Dl_107414;
extern TY107236 Dl_107235;
extern TY107402 Dl_107401;
extern TY106816 Dl_106815;
extern TY107424 Dl_107423;
extern TY107419 Dl_107418;
extern TY107614 Dl_107613;
N_NIMCALL(void, TMP56)(void* p, NI op) {
	TY127402* a;
	NI LOC1;
	a = (TY127402*)p;
	LOC1 = 0;
	for (LOC1 = 0; LOC1 < a->Sup.len; LOC1++) {
	nimGCvisit((void*)a->data[LOC1], op);
	}
}

N_NIMCALL(void, nossplitPath)(NimStringDesc* path, Keyvaluepair143205* Result) {
	NI seppos;
	seppos = ((NI) -1);
	{
		NI i_116899;
		NI HEX3Atmp_116912;
		NI res_116915;
		i_116899 = 0;
		HEX3Atmp_116912 = 0;
		HEX3Atmp_116912 = (NI)((path ? path->Sup.len : 0) - ((NI) 1));
		res_116915 = HEX3Atmp_116912;
		{
			while (1) {
				if (!(((NI) 0) <= res_116915)) goto LA3;
				i_116899 = res_116915;
				{
					if (!(((NU8)(path->data[i_116899])) == ((NU8)(92)) || ((NU8)(path->data[i_116899])) == ((NU8)(47)))) goto LA6;
					seppos = i_116899;
					goto LA1;
				}
				LA6: ;
				res_116915 -= ((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*) &TMP157)));
		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)(92)) || ((NU8)(path->data[(NI)((path ? path->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47)));
		LA4: ;
		if (!LOC3) goto LA5;
		result = copyString(((NimStringDesc*) &TMP157));
	}
	goto LA1;
	LA5: ;
	{
		Keyvaluepair143205 LOC8;
		memset((void*)(&LOC8), 0, sizeof(LOC8));
		nossplitPath(path, (&LOC8));
		result = copyString(LOC8.Field1);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NI, searchextpos_117078)(NimStringDesc* s) {
	NI result;
	result = 0;
	result = ((NI) -1);
	{
		NI i_117092;
		NI HEX3Atmp_117105;
		NI res_117108;
		i_117092 = 0;
		HEX3Atmp_117105 = 0;
		HEX3Atmp_117105 = (NI)((s ? s->Sup.len : 0) - ((NI) 1));
		res_117108 = HEX3Atmp_117105;
		{
			while (1) {
				if (!(((NI) 1) <= res_117108)) goto LA3;
				i_117092 = res_117108;
				{
					if (!((NU8)(s->data[i_117092]) == (NU8)(46))) goto LA6;
					result = i_117092;
					goto LA1;
				}
				goto LA4;
				LA6: ;
				{
					if (!(((NU8)(s->data[i_117092])) == ((NU8)(92)) || ((NU8)(s->data[i_117092])) == ((NU8)(47)))) goto LA9;
					goto LA1;
				}
				goto LA4;
				LA9: ;
				LA4: ;
				res_117108 -= ((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_117074)(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_117078(filename);
	{
		NimStringDesc* LOC5;
		NimStringDesc* LOC6;
		if (!(extpos < ((NI) 0))) goto LA3;
		LOC5 = 0;
		LOC6 = 0;
		LOC6 = normext_117074(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_117074(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_119611)(NI32 errorcode) {
	NimStringDesc* result;
	result = 0;
	result = copyString(((NimStringDesc*) &TMP157));
	{
		NI16* msgbuf;
		if (!!((errorcode == ((NI32) 0)))) goto LA3;
		msgbuf = 0;
		{
			NI32 LOC7;
			LOC7 = 0;
			LOC7 = Dl_106632(((NI32) 4864), NIM_NIL, errorcode, ((NI32) 0), ((void*) (&msgbuf)), ((NI32) 0), NIM_NIL);
			if (!!((LOC7 == ((NI32) 0)))) goto LA8;
			result = HEX24_83672(msgbuf);
			{
				if (!!((msgbuf == NIM_NIL))) goto LA12;
				Dl_106801(((void*) (msgbuf)));
			}
			LA12: ;
		}
		LA8: ;
	}
	LA3: ;
	return result;
}

static N_INLINE(Cell47304*, usrtocell_51240)(void* usr) {
	Cell47304* result;
	result = 0;
	result = ((Cell47304*) ((NI)((NU64)(((NI) (usr))) - (NU64)(((NI)sizeof(Cell47304))))));
	return result;
}

static N_INLINE(void, rtladdzct_52801)(Cell47304* c) {
	addzct_51217((&gch_49659.zct), c);
}

static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src) {
	{
		Cell47304* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_51240(src);
		(*c).refcount += ((NI) 8);
	}
	LA3: ;
	{
		Cell47304* c;
		if (!!(((*dest) == NIM_NIL))) goto LA7;
		c = usrtocell_51240((*dest));
		{
			(*c).refcount -= ((NI) 8);
			if (!((NU64)((*c).refcount) < (NU64)(((NI) 8)))) goto LA11;
			rtladdzct_52801(c);
		}
		LA11: ;
	}
	LA7: ;
	(*dest) = src;
}

static N_INLINE(void, nimGCunrefNoCycle)(void* p) {
	Cell47304* c;
	c = usrtocell_51240(p);
	{
		(*c).refcount -= ((NI) 8);
		if (!((NU64)((*c).refcount) < (NU64)(((NI) 8)))) goto LA3;
		rtladdzct_52801(c);
	}
	LA3: ;
}

N_NOINLINE(void, raiseoserror_120024)(NI32 errorcode, NimStringDesc* additionalinfo) {
	Oserror3630* e;
	e = 0;
	e = (Oserror3630*) newObj((&NTI120028), 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_119611(errorcode));
	}
	goto LA1;
	LA3: ;
	{
		NimStringDesc* LOC6;
		NimStringDesc* LOC7;
		LOC6 = 0;
		LOC7 = 0;
		LOC7 = oserrormsg_119611(errorcode);
		LOC6 = rawNewString(additionalinfo->Sup.len + LOC7->Sup.len + 1);
appendString(LOC6, additionalinfo);
appendString(LOC6, ((NimStringDesc*) &TMP1207));
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*) &TMP1208));
		if (LOC12) nimGCunrefNoCycle(LOC12);
	}
	LA10: ;
	raiseException((Exception*)e, "OSError");
}

N_NIMCALL(NI32, oslasterror_120040)(void) {
	NI32 result;
	result = 0;
	result = Dl_106630();
	return result;
}

N_NIMCALL(NimStringDesc*, nosexpandFilename)(NimStringDesc* filename) {
	NimStringDesc* result;
	NI16* unused;
	NI16* res;
	NI32 L;
	NI16* LOC1;
	result = 0;
	unused = 0;
	res = newwidecstring_83412("", ((NI) 1536));
	LOC1 = 0;
	LOC1 = newwidecstring_83602(filename);
	L = Dl_107404(LOC1, ((NI32) 3072), res, &unused);
	{
		NIM_BOOL LOC4;
		NI32 LOC8;
		LOC4 = 0;
		LOC4 = (L <= ((NI32) 0));
		if (LOC4) goto LA5;
		LOC4 = (((NI32) 3072) <= L);
		LA5: ;
		if (!LOC4) goto LA6;
		LOC8 = 0;
		LOC8 = oslasterror_120040();
		raiseoserror_120024(LOC8, ((NimStringDesc*) &TMP157));
	}
	LA6: ;
	result = HEX24_83606(res, ((NI) (L)), ((NI) 65533));
	return result;
}

N_NIMCALL(void, nossplitFile)(NimStringDesc* path, TY117115* 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)(92)) || ((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*) &TMP157)));
		unsureAsgnRef((void**) (&(*Result).Field2), copyString(((NimStringDesc*) &TMP157)));
	}
	goto LA1;
	LA5: ;
	{
		NI seppos;
		NI dotpos;
		seppos = ((NI) -1);
		dotpos = (path ? path->Sup.len : 0);
		{
			NI i_117144;
			NI HEX3Atmp_117168;
			NI res_117171;
			i_117144 = 0;
			HEX3Atmp_117168 = 0;
			HEX3Atmp_117168 = (NI)((path ? path->Sup.len : 0) - ((NI) 1));
			res_117171 = HEX3Atmp_117168;
			{
				while (1) {
					if (!(((NI) 0) <= res_117171)) goto LA10;
					i_117144 = res_117171;
					{
						if (!((NU8)(path->data[i_117144]) == (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_117144);
							LA19: ;
							LOC17 = LOC18;
							if (!(LOC17)) goto LA20;
							LOC17 = !((((NU8)(path->data[(NI)(i_117144 - ((NI) 1))])) == ((NU8)(92)) || ((NU8)(path->data[(NI)(i_117144 - ((NI) 1))])) == ((NU8)(47))));
							LA20: ;
							if (!LOC17) goto LA21;
							dotpos = i_117144;
						}
						LA21: ;
					}
					goto LA11;
					LA13: ;
					{
						if (!(((NU8)(path->data[i_117144])) == ((NU8)(92)) || ((NU8)(path->data[i_117144])) == ((NU8)(47)))) goto LA24;
						seppos = i_117144;
						goto LA8;
					}
					goto LA11;
					LA24: ;
					LA11: ;
					res_117171 -= ((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(NimStringDesc*, nosgetAppFilename)(void) {
	NimStringDesc* result;
	NI16* buf;
	NI32 len;
	result = 0;
	buf = newwidecstring_83412("", ((NI) 256));
	len = Dl_106822(((NI) 0), buf, ((NI32) 256));
	result = HEX24_83606(buf, ((NI) (len)), ((NI) 65533));
	return result;
}

N_NIMCALL(NimStringDesc*, nosgetAppDir)(void) {
	NimStringDesc* result;
	NimStringDesc* LOC1;
	TY117115 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_116919)(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)(92)) || ((NU8)(path->data[(NI)((path ? path->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47)));
		LA4: ;
		if (!LOC3) goto LA5;
		q = ((NI) 2);
	}
	LA5: ;
	{
		NI i_116945;
		NI HEX3Atmp_116958;
		NI res_116961;
		i_116945 = 0;
		HEX3Atmp_116958 = 0;
		HEX3Atmp_116958 = (NI)((path ? path->Sup.len : 0) - q);
		res_116961 = HEX3Atmp_116958;
		{
			while (1) {
				if (!(((NI) 0) <= res_116961)) goto LA9;
				i_116945 = res_116961;
				{
					if (!(((NU8)(path->data[i_116945])) == ((NU8)(92)) || ((NU8)(path->data[i_116945])) == ((NU8)(47)))) goto LA12;
					result = i_116945;
					goto BeforeRet;
				}
				LA12: ;
				res_116961 -= ((NI) 1);
			} LA9: ;
		}
	}
	result = ((NI) -1);
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nosparentDir)(NimStringDesc* path) {
	NimStringDesc* result;
	NI seppos;
	result = 0;
	seppos = parentdirpos_116919(path);
	{
		if (!(((NI) 0) <= seppos)) goto LA3;
		result = copyStrLast(path, ((NI) 0), (NI)(seppos - ((NI) 1)));
	}
	goto LA1;
	LA3: ;
	{
		result = copyString(((NimStringDesc*) &TMP157));
	}
	LA1: ;
	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)(92)) || ((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)(92)) || ((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)(92)) || ((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, 92);
appendString(LOC23, tail);
			result = LOC23;
		}
		LA17: ;
	}
	LA1: ;
	return result;
}

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

N_NIMCALL(NI, findfirstfile_120416)(NimStringDesc* a, Win32finddata107213* b) {
	NI result;
	NI16* LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = newwidecstring_83602(a);
	result = Dl_107230(LOC1, b);
	return result;
}

N_NIMCALL(NIM_BOOL, nosisAbsolute)(NimStringDesc* path) {
	NIM_BOOL result;
	NI len;
	NIM_BOOL LOC1;
	NIM_BOOL LOC2;
	NIM_BOOL LOC5;
	NIM_BOOL LOC6;
	result = 0;
	len = (path ? path->Sup.len : 0);
	LOC1 = 0;
	LOC2 = 0;
	LOC2 = (((NI) 1) < len);
	if (!(LOC2)) goto LA3;
	LOC2 = (((NU8)(path->data[((NI) 0)])) == ((NU8)(47)) || ((NU8)(path->data[((NI) 0)])) == ((NU8)(92)));
	LA3: ;
	LOC1 = LOC2;
	if (LOC1) goto LA4;
	LOC5 = 0;
	LOC6 = 0;
	LOC6 = (((NI) 2) < len);
	if (!(LOC6)) goto LA7;
	LOC6 = (((NU8)(path->data[((NI) 0)])) >= ((NU8)(97)) && ((NU8)(path->data[((NI) 0)])) <= ((NU8)(122)) || ((NU8)(path->data[((NI) 0)])) >= ((NU8)(65)) && ((NU8)(path->data[((NI) 0)])) <= ((NU8)(90)));
	LA7: ;
	LOC5 = LOC6;
	if (!(LOC5)) goto LA8;
	LOC5 = ((NU8)(path->data[((NI) 1)]) == (NU8)(58));
	LA8: ;
	LOC1 = LOC5;
	LA4: ;
	result = LOC1;
	return result;
}

N_NIMCALL(void, rawcreatedir_130035)(NimStringDesc* dir) {
	NI32 res;
	NI16* LOC1;
	LOC1 = 0;
	LOC1 = newwidecstring_83602(dir);
	res = Dl_106811(LOC1, NIM_NIL);
	{
		NIM_BOOL LOC4;
		NI32 LOC6;
		NI32 LOC9;
		LOC4 = 0;
		LOC4 = (res == ((NI32) 0));
		if (!(LOC4)) goto LA5;
		LOC6 = 0;
		LOC6 = Dl_106630();
		LOC4 = !((LOC6 == ((NI32) 183)));
		LA5: ;
		if (!LOC4) goto LA7;
		LOC9 = 0;
		LOC9 = oslasterror_120040();
		raiseoserror_120024(LOC9, ((NimStringDesc*) &TMP157));
	}
	LA7: ;
}

N_NIMCALL(void, noscreateDir)(NimStringDesc* dir) {
	NIM_BOOL omitnext;
	omitnext = NIM_FALSE;
	omitnext = nosisAbsolute(dir);
	{
		NI i_130610;
		NI HEX3Atmp_130623;
		NI res_130626;
		i_130610 = 0;
		HEX3Atmp_130623 = 0;
		HEX3Atmp_130623 = (NI)((dir ? dir->Sup.len : 0) - ((NI) 1));
		res_130626 = ((NI) 1);
		{
			while (1) {
				if (!(res_130626 <= HEX3Atmp_130623)) goto LA3;
				i_130610 = res_130626;
				{
					if (!(((NU8)(dir->data[i_130610])) == ((NU8)(92)) || ((NU8)(dir->data[i_130610])) == ((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_130610 - ((NI) 1)));
						rawcreatedir_130035(LOC13);
					}
					LA8: ;
				}
				LA6: ;
				res_130626 += ((NI) 1);
			} LA3: ;
		}
	}
	rawcreatedir_130035(dir);
}

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

N_NIMCALL(NIM_BOOL, nosexistsFile)(NimStringDesc* filename) {
	NIM_BOOL result;
	NI32 a;
	NI16* LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = newwidecstring_83602(filename);
	a = Dl_107411(LOC1);
	{
		if (!!((a == ((NI32) -1)))) goto LA4;
		result = ((NI32)(a & ((NI32) 16)) == ((NI32) 0));
	}
	LA4: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nosaddFileExt)(NimStringDesc* filename, NimStringDesc* ext) {
	NimStringDesc* result;
	NI extpos;
	result = 0;
	extpos = searchextpos_117078(filename);
	{
		NimStringDesc* LOC5;
		NimStringDesc* LOC6;
		if (!(extpos < ((NI) 0))) goto LA3;
		LOC5 = 0;
		LOC6 = 0;
		LOC6 = normext_117074(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(TY127402*, nosparseCmdLine)(NimStringDesc* c) {
	TY127402* result;
	NI i;
	NimStringDesc* a;
	result = 0;
	result = (TY127402*) newSeq((&NTI127402), 0);
	i = ((NI) 0);
	a = copyString(((NimStringDesc*) &TMP157));
	{
		while (1) {
			NIM_BOOL inquote;
			NimStringDesc* LOC49;
			a = setLengthStr(a, ((NI) 0));
			{
				while (1) {
					NIM_BOOL LOC5;
					NIM_BOOL LOC6;
					NIM_BOOL LOC7;
					LOC5 = 0;
					LOC6 = 0;
					LOC7 = 0;
					LOC7 = ((NU8)(c->data[i]) == (NU8)(32));
					if (LOC7) goto LA8;
					LOC7 = ((NU8)(c->data[i]) == (NU8)(9));
					LA8: ;
					LOC6 = LOC7;
					if (LOC6) goto LA9;
					LOC6 = ((NU8)(c->data[i]) == (NU8)(10));
					LA9: ;
					LOC5 = LOC6;
					if (LOC5) goto LA10;
					LOC5 = ((NU8)(c->data[i]) == (NU8)(13));
					LA10: ;
					if (!LOC5) goto LA4;
					i += ((NI) 1);
				} LA4: ;
			}
			{
				if (!((NU8)(c->data[i]) == (NU8)(0))) goto LA13;
				goto LA1;
			}
			LA13: ;
			inquote = NIM_FALSE;
			{
				while (1) {
					switch (((NU8)(c->data[i]))) {
					case 0:
					{
						goto LA15;
					}
					break;
					case 92:
					{
						NI j;
						j = i;
						{
							while (1) {
								if (!((NU8)(c->data[j]) == (NU8)(92))) goto LA20;
								j += ((NI) 1);
							} LA20: ;
						}
						{
							if (!((NU8)(c->data[j]) == (NU8)(34))) goto LA23;
							{
								NI k_131621;
								NI HEX3Atmp_131683;
								NI res_131686;
								k_131621 = 0;
								HEX3Atmp_131683 = 0;
								HEX3Atmp_131683 = (NI)((NI)(j - i) / ((NI) 2));
								res_131686 = ((NI) 1);
								{
									while (1) {
										if (!(res_131686 <= HEX3Atmp_131683)) goto LA27;
										k_131621 = res_131686;
										a = addChar(a, 92);
										res_131686 += ((NI) 1);
									} LA27: ;
								}
							}
							{
								if (!(((NI) ((NI)((NI)(j - i) % ((NI) 2)))) == ((NI) 0))) goto LA30;
								i = j;
							}
							goto LA28;
							LA30: ;
							{
								a = addChar(a, 34);
								i = (NI)(j + ((NI) 1));
							}
							LA28: ;
						}
						goto LA21;
						LA23: ;
						{
							a = addChar(a, c->data[i]);
							i += ((NI) 1);
						}
						LA21: ;
					}
					break;
					case 34:
					{
						i += ((NI) 1);
						{
							if (!!(inquote)) goto LA37;
							inquote = NIM_TRUE;
						}
						goto LA35;
						LA37: ;
						{
							if (!((NU8)(c->data[i]) == (NU8)(34))) goto LA40;
							a = addChar(a, c->data[i]);
							i += ((NI) 1);
						}
						goto LA35;
						LA40: ;
						{
							inquote = NIM_FALSE;
							goto LA15;
						}
						LA35: ;
					}
					break;
					case 32:
					case 9:
					{
						{
							if (!!(inquote)) goto LA46;
							goto LA15;
						}
						LA46: ;
						a = addChar(a, c->data[i]);
						i += ((NI) 1);
					}
					break;
					default:
					{
						a = addChar(a, c->data[i]);
						i += ((NI) 1);
					}
					break;
					}
				}
			} LA15: ;
			result = (TY127402*) incrSeqV2(&(result)->Sup, sizeof(NimStringDesc*));
			LOC49 = 0;
			LOC49 = result->data[result->Sup.len]; result->data[result->Sup.len] = copyStringRC1(a);
			if (LOC49) nimGCunrefNoCycle(LOC49);
			++result->Sup.len;
		}
	} LA1: ;
	return result;
}

N_NIMCALL(NI, nosparamCount)(void) {
	NI result;
	result = 0;
	{
		NI16* LOC5;
		NimStringDesc* LOC6;
		if (!ownargv_134402 == 0) goto LA3;
		LOC5 = 0;
		LOC5 = Dl_107433();
		LOC6 = 0;
		LOC6 = HEX24_83672(LOC5);
		asgnRefNoCycle((void**) (&ownargv_134402), nosparseCmdLine(LOC6));
	}
	LA3: ;
	result = (NI)((ownargv_134402 ? ownargv_134402->Sup.len : 0) - ((NI) 1));
	return result;
}

N_NIMCALL(NimStringDesc*, nosparamStr)(NI i) {
	NimStringDesc* result;
{	result = 0;
	{
		NI16* LOC5;
		NimStringDesc* LOC6;
		if (!ownargv_134402 == 0) goto LA3;
		LOC5 = 0;
		LOC5 = Dl_107433();
		LOC6 = 0;
		LOC6 = HEX24_83672(LOC5);
		asgnRefNoCycle((void**) (&ownargv_134402), nosparseCmdLine(LOC6));
	}
	LA3: ;
	result = copyString(ownargv_134402->data[i]);
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nosunixToNativePath)(NimStringDesc* path, NimStringDesc* drive) {
	NimStringDesc* result;
	NI start;
	NI i;
	result = 0;
	start = 0;
	{
		if (!((NU8)(path->data[((NI) 0)]) == (NU8)(47))) goto LA3;
		{
			NimStringDesc* LOC9;
			if (!!(((drive) && (drive)->Sup.len == 0))) goto LA7;
			LOC9 = 0;
			LOC9 = rawNewString(drive->Sup.len + 2);
appendString(LOC9, drive);
appendString(LOC9, ((NimStringDesc*) &TMP1683));
			result = LOC9;
		}
		goto LA5;
		LA7: ;
		{
			result = copyString(((NimStringDesc*) &TMP1684));
		}
		LA5: ;
		start = ((NI) 1);
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC12;
		LOC12 = 0;
		LOC12 = ((NU8)(path->data[((NI) 0)]) == (NU8)(46));
		if (!(LOC12)) goto LA13;
		LOC12 = ((NU8)(path->data[((NI) 1)]) == (NU8)(47));
		LA13: ;
		if (!LOC12) goto LA14;
		result = copyString(((NimStringDesc*) &TMP1685));
		start = ((NI) 2);
	}
	goto LA1;
	LA14: ;
	{
		result = copyString(((NimStringDesc*) &TMP157));
		start = ((NI) 0);
	}
	LA1: ;
	i = start;
	{
		while (1) {
			if (!(i < (path ? path->Sup.len : 0))) goto LA18;
			{
				NIM_BOOL LOC21;
				NIM_BOOL LOC22;
				LOC21 = 0;
				LOC22 = 0;
				LOC22 = ((NU8)(path->data[i]) == (NU8)(46));
				if (!(LOC22)) goto LA23;
				LOC22 = ((NU8)(path->data[(NI)(i + ((NI) 1))]) == (NU8)(46));
				LA23: ;
				LOC21 = LOC22;
				if (!(LOC21)) goto LA24;
				LOC21 = ((NU8)(path->data[(NI)(i + ((NI) 2))]) == (NU8)(47));
				LA24: ;
				if (!LOC21) goto LA25;
				result = resizeString(result, 3);
appendString(result, ((NimStringDesc*) &TMP1686));
				i += ((NI) 3);
			}
			goto LA19;
			LA25: ;
			{
				if (!((NU8)(path->data[i]) == (NU8)(47))) goto LA28;
				result = addChar(result, 92);
				i += ((NI) 1);
			}
			goto LA19;
			LA28: ;
			{
				result = addChar(result, path->data[i]);
				i += ((NI) 1);
			}
			LA19: ;
		} LA18: ;
	}
	return result;
}

N_NIMCALL(void, getenvvarsc_127805)(void) {
{	{
		NI16* env;
		NI16* e;
		NI32 LOC17;
		if (!!(envcomputed_127401)) goto LA3;
		if (environment_127403) nimGCunrefNoCycle(environment_127403);
		environment_127403 = (TY127402*) newSeqRC1((&NTI127402), 0);
		env = Dl_107428();
		e = env;
		{
			if (!(e == NIM_NIL)) goto LA7;
			goto BeforeRet;
		}
		LA7: ;
		{
			while (1) {
				NI16* eend;
				NimStringDesc* LOC11;
				NimStringDesc* LOC12;
				eend = wcschr(e, ((NI32) 0));
				LOC11 = 0;
				LOC11 = HEX24_83672(e);
				environment_127403 = (TY127402*) incrSeqV2(&(environment_127403)->Sup, sizeof(NimStringDesc*));
				LOC12 = 0;
				LOC12 = environment_127403->data[environment_127403->Sup.len]; environment_127403->data[environment_127403->Sup.len] = copyStringRC1(LOC11);
				if (LOC12) nimGCunrefNoCycle(LOC12);
				++environment_127403->Sup.len;
				e = ((NI16*) ((NI)(((NI) (eend)) + ((NI) 2))));
				{
					if (!(((NI) (eend[(((NI) 1))- 0])) == ((NI) 0))) goto LA15;
					goto LA9;
				}
				LA15: ;
			}
		} LA9: ;
		LOC17 = 0;
		LOC17 = Dl_107430(env);
		envcomputed_127401 = NIM_TRUE;
	}
	LA3: ;
	}BeforeRet: ;
}

N_NIMCALL(NI, findenvvar_128201)(NimStringDesc* key) {
	NI result;
	NimStringDesc* temp;
	NimStringDesc* LOC1;
{	result = 0;
	getenvvarsc_127805();
	LOC1 = 0;
	LOC1 = rawNewString(key->Sup.len + 1);
appendString(LOC1, key);
appendChar(LOC1, 61);
	temp = LOC1;
	{
		NI i_128215;
		NI HEX3Atmp_128217;
		NI res_128220;
		i_128215 = 0;
		HEX3Atmp_128217 = 0;
		HEX3Atmp_128217 = (environment_127403 ? (environment_127403->Sup.len-1) : -1);
		res_128220 = ((NI) 0);
		{
			while (1) {
				if (!(res_128220 <= HEX3Atmp_128217)) goto LA4;
				i_128215 = res_128220;
				{
					NIM_BOOL LOC7;
					LOC7 = 0;
					LOC7 = nsuStartsWith(environment_127403->data[i_128215], temp);
					if (!LOC7) goto LA8;
					result = i_128215;
					goto BeforeRet;
				}
				LA8: ;
				res_128220 += ((NI) 1);
			} LA4: ;
		}
	}
	result = ((NI) -1);
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, getenv_128224)(NimStringDesc* key) {
	NimStringDesc* result;
	NI i;
{	result = 0;
	i = findenvvar_128201(key);
	{
		NI LOC5;
		if (!(((NI) 0) <= i)) goto LA3;
		LOC5 = 0;
		LOC5 = nsuFindChar(environment_127403->data[i], 61, ((NI) 0));
		result = copyStr(environment_127403->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*) &TMP157));
			goto BeforeRet;
		}
		LA9: ;
		result = cstrToNimstr(env);
	}
	LA1: ;
	}BeforeRet: ;
	return result;
}

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

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

N_NIMCALL(void, putenv_128237)(NimStringDesc* key, NimStringDesc* val) {
	NI indx;
	NI16* k;
	NI16* v;
	indx = findenvvar_128201(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_127403->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_127403 = (TY127402*) incrSeqV2(&(environment_127403)->Sup, sizeof(NimStringDesc*));
		LOC8 = 0;
		LOC8 = environment_127403->data[environment_127403->Sup.len]; environment_127403->data[environment_127403->Sup.len] = copyStringRC1(LOC7);
		if (LOC8) nimGCunrefNoCycle(LOC8);
		++environment_127403->Sup.len;
		indx = (environment_127403 ? (environment_127403->Sup.len-1) : -1);
	}
	LA1: ;
	k = newwidecstring_83602(key);
	v = newwidecstring_83602(val);
	{
		NI32 LOC11;
		NI32 LOC14;
		LOC11 = 0;
		LOC11 = Dl_106818(k, v);
		if (!(LOC11 == ((NI32) 0))) goto LA12;
		LOC14 = 0;
		LOC14 = oslasterror_120040();
		raiseoserror_120024(LOC14, ((NimStringDesc*) &TMP157));
	}
	LA12: ;
}

N_NIMCALL(NimStringDesc*, nosgetCurrentDir)(void) {
	NimStringDesc* result;
	NI16* res;
	NI32 L;
	result = 0;
	res = newwidecstring_83412("", ((NI) 512));
	L = Dl_106804(((NI32) 512), res);
	{
		NI32 LOC5;
		if (!(L == ((NI32) 0))) goto LA3;
		LOC5 = 0;
		LOC5 = oslasterror_120040();
		raiseoserror_120024(LOC5, ((NimStringDesc*) &TMP157));
	}
	LA3: ;
	result = HEX24_83606(res, ((NI) (L)), ((NI) 65533));
	return result;
}

N_NIMCALL(NIM_BOOL, nossymlinkExists)(NimStringDesc* link) {
	NIM_BOOL result;
	NI32 a;
	NI16* LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = newwidecstring_83602(link);
	a = Dl_107411(LOC1);
	{
		if (!!((a == ((NI32) -1)))) goto LA4;
		result = !(((NI32)(a & ((NI32) 1024)) == ((NI32) 0)));
	}
	LA4: ;
	return result;
}

N_NIMCALL(NimStringDesc*, findexe_133801)(NimStringDesc* exe) {
	NimStringDesc* result;
	NimStringDesc* path;
{	result = 0;
	result = nosaddFileExt(exe, ((NimStringDesc*) &TMP2042));
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = nosexistsFile(result);
		if (!LOC3) goto LA4;
		goto BeforeRet;
	}
	LA4: ;
	path = getenv_128224(((NimStringDesc*) &TMP2043));
	{
		NimStringDesc* candidate_133806;
		NI last_134007;
		candidate_133806 = 0;
		last_134007 = ((NI) 0);
		{
			if (!(((NI) 0) < (path ? path->Sup.len : 0))) goto LA9;
			{
				while (1) {
					NI first_134009;
					NimStringDesc* x;
					if (!(last_134007 <= (path ? path->Sup.len : 0))) goto LA12;
					first_134009 = last_134007;
					{
						while (1) {
							NIM_BOOL LOC15;
							LOC15 = 0;
							LOC15 = (last_134007 < (path ? path->Sup.len : 0));
							if (!(LOC15)) goto LA16;
							LOC15 = !(((NU8)(path->data[last_134007]) == (NU8)(59)));
							LA16: ;
							if (!LOC15) goto LA14;
							last_134007 += ((NI) 1);
						} LA14: ;
					}
					candidate_133806 = copyStrLast(path, first_134009, (NI)(last_134007 - ((NI) 1)));
					x = HEX2F_116874(candidate_133806, result);
					{
						NIM_BOOL LOC19;
						LOC19 = 0;
						LOC19 = nosexistsFile(x);
						if (!LOC19) goto LA20;
						result = copyString(x);
						goto BeforeRet;
					}
					LA20: ;
					last_134007 += ((NI) 1);
				} LA12: ;
			}
		}
		LA9: ;
	}
	result = copyString(((NimStringDesc*) &TMP157));
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, expandsymlink_134201)(NimStringDesc* symlinkpath) {
	NimStringDesc* result;
	result = 0;
	result = copyString(symlinkpath);
	return result;
}

N_NIMCALL(NimStringDesc*, nosgetConfigDir)(void) {
	NimStringDesc* result;
	NimStringDesc* LOC1;
	NimStringDesc* LOC2;
{	result = 0;
	LOC1 = 0;
	LOC2 = 0;
	LOC2 = getenv_128224(((NimStringDesc*) &TMP2061));
	LOC1 = rawNewString(LOC2->Sup.len + 1);
appendString(LOC1, LOC2);
appendString(LOC1, ((NimStringDesc*) &TMP1684));
	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_116919(path);
	result = (LOC1 < ((NI) 0));
	return result;
}

N_NIMCALL(NIM_BOOL, existsenv_128233)(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_128201(key);
		result = (((NI) 0) <= LOC7);
		goto BeforeRet;
	}
	LA1: ;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_BOOL, nosexistsDir)(NimStringDesc* dir) {
	NIM_BOOL result;
	NI32 a;
	NI16* LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = newwidecstring_83602(dir);
	a = Dl_107411(LOC1);
	{
		if (!!((a == ((NI32) -1)))) goto LA4;
		result = !(((NI32)(a & ((NI32) 16)) == ((NI32) 0)));
	}
	LA4: ;
	return result;
}

static N_INLINE(NIM_BOOL, skipfinddata_120434)(Win32finddata107213* f) {
	NIM_BOOL result;
	NIM_BOOL LOC1;
	NIM_BOOL LOC3;
	NIM_BOOL LOC5;
	result = 0;
	LOC1 = 0;
	LOC1 = (((NI) ((*f).cfilename[(((NI) 0))- 0])) == ((NI) 46));
	if (!(LOC1)) goto LA2;
	LOC3 = 0;
	LOC3 = (((NI) ((*f).cfilename[(((NI) 1))- 0])) == ((NI) 0));
	if (LOC3) goto LA4;
	LOC5 = 0;
	LOC5 = (((NI) ((*f).cfilename[(((NI) 1))- 0])) == ((NI) 46));
	if (!(LOC5)) goto LA6;
	LOC5 = (((NI) ((*f).cfilename[(((NI) 2))- 0])) == ((NI) 0));
	LA6: ;
	LOC3 = LOC5;
	LA4: ;
	LOC1 = LOC3;
	LA2: ;
	result = LOC1;
	return result;
}

N_NIMCALL(void, nosremoveFile)(NimStringDesc* file) {
	NI16* f;
	f = newwidecstring_83602(file);
	{
		NI32 LOC3;
		LOC3 = 0;
		LOC3 = Dl_108214(f);
		if (!(LOC3 == ((NI32) 0))) goto LA4;
		{
			NI32 LOC8;
			LOC8 = 0;
			LOC8 = Dl_106630();
			if (!(LOC8 == ((NI32) 5))) goto LA9;
			{
				NI32 LOC13;
				NI32 LOC16;
				LOC13 = 0;
				LOC13 = Dl_107414(f, ((NI32) 128));
				if (!(LOC13 == ((NI32) 0))) goto LA14;
				LOC16 = 0;
				LOC16 = oslasterror_120040();
				raiseoserror_120024(LOC16, ((NimStringDesc*) &TMP157));
			}
			LA14: ;
			{
				NI32 LOC19;
				NI32 LOC22;
				LOC19 = 0;
				LOC19 = Dl_108214(f);
				if (!(LOC19 == ((NI32) 0))) goto LA20;
				LOC22 = 0;
				LOC22 = oslasterror_120040();
				raiseoserror_120024(LOC22, ((NimStringDesc*) &TMP157));
			}
			LA20: ;
		}
		LA9: ;
	}
	LA4: ;
}

N_NIMCALL(void, rawremovedir_129716)(NimStringDesc* dir) {
	NI32 res;
	NI16* LOC1;
	NI32 lasterror;
	LOC1 = 0;
	LOC1 = newwidecstring_83602(dir);
	res = Dl_106815(LOC1);
	lasterror = oslasterror_120040();
	{
		NIM_BOOL LOC4;
		NIM_BOOL LOC5;
		NIM_BOOL LOC6;
		LOC4 = 0;
		LOC5 = 0;
		LOC6 = 0;
		LOC6 = (res == ((NI32) 0));
		if (!(LOC6)) goto LA7;
		LOC6 = !((lasterror == ((NI32) 3)));
		LA7: ;
		LOC5 = LOC6;
		if (!(LOC5)) goto LA8;
		LOC5 = !((lasterror == ((NI32) 18)));
		LA8: ;
		LOC4 = LOC5;
		if (!(LOC4)) goto LA9;
		LOC4 = !((lasterror == ((NI32) 2)));
		LA9: ;
		if (!LOC4) goto LA10;
		raiseoserror_120024(lasterror, ((NimStringDesc*) &TMP157));
	}
	LA10: ;
}

N_NIMCALL(void, nosremoveDir)(NimStringDesc* dir) {
	{
		NU8 kind_130009;
		NimStringDesc* path_130010;
		Win32finddata107213 f_130026;
		NI h_130028;
		NimStringDesc* LOC2;
		kind_130009 = 0;
		path_130010 = 0;
		memset((void*)(&f_130026), 0, sizeof(f_130026));
		LOC2 = 0;
		LOC2 = HEX2F_116874(dir, ((NimStringDesc*) &TMP3672));
		h_130028 = findfirstfile_120416(LOC2, (&f_130026));
		{
			if (!!((h_130028 == ((NI) -1)))) goto LA5;
			{
				while (1) {
					NU8 k_130030;
					k_130030 = ((NU8) 0);
					{
						NIM_BOOL LOC11;
						NimStringDesc* xx_130032;
						LOC11 = 0;
						LOC11 = skipfinddata_120434((&f_130026));
						if (!!(LOC11)) goto LA12;
						{
							if (!!(((NI32)(f_130026.dwfileattributes & ((NI32) 16)) == ((NI32) 0)))) goto LA16;
							k_130030 = ((NU8) 2);
						}
						LA16: ;
						{
							if (!!(((NI32)(f_130026.dwfileattributes & ((NI32) 1024)) == ((NI32) 0)))) goto LA20;
							k_130030 = (NU8)(k_130030 + ((NI) 1));
						}
						LA20: ;
						{
							NimStringDesc* LOC26;
							if (!NIM_FALSE) goto LA24;
							LOC26 = 0;
							LOC26 = HEX24_83672(((NI16*) ((&f_130026.cfilename[(((NI) 0))- 0]))));
							xx_130032 = nosextractFilename(LOC26);
						}
						goto LA22;
						LA24: ;
						{
							NimStringDesc* LOC28;
							NimStringDesc* LOC29;
							LOC28 = 0;
							LOC28 = HEX24_83672(((NI16*) ((&f_130026.cfilename[(((NI) 0))- 0]))));
							LOC29 = 0;
							LOC29 = nosextractFilename(LOC28);
							xx_130032 = HEX2F_116874(dir, LOC29);
						}
						LA22: ;
						kind_130009 = k_130030;
						path_130010 = xx_130032;
						switch (kind_130009) {
						case ((NU8) 0):
						case ((NU8) 1):
						case ((NU8) 3):
						{
							nosremoveFile(path_130010);
						}
						break;
						case ((NU8) 2):
						{
							nosremoveDir(path_130010);
						}
						break;
						}
					}
					LA12: ;
					{
						NI32 LOC34;
						LOC34 = 0;
						LOC34 = Dl_107235(h_130028, (&f_130026));
						if (!(LOC34 == ((NI32) 0))) goto LA35;
						goto LA7;
					}
					LA35: ;
				}
			} LA7: ;
			Dl_107401(h_130028);
		}
		LA5: ;
	}
	rawremovedir_129716(dir);
}

N_NIMCALL(void, nosmoveFile)(NimStringDesc* source, NimStringDesc* dest) {
	NI16* s;
	NI16* d;
	s = newwidecstring_83602(source);
	d = newwidecstring_83602(dest);
	{
		int LOC3;
		NI32 LOC6;
		LOC3 = 0;
		LOC3 = Dl_107423(s, d, ((NI32) 0));
		if (!(LOC3 == ((NI32) 0))) goto LA4;
		LOC6 = 0;
		LOC6 = oslasterror_120040();
		raiseoserror_120024(LOC6, ((NimStringDesc*) &TMP157));
	}
	LA4: ;
}

N_NIMCALL(void, noscopyFile)(NimStringDesc* source, NimStringDesc* dest) {
	NI16* s;
	NI16* d;
	s = newwidecstring_83602(source);
	d = newwidecstring_83602(dest);
	{
		int LOC3;
		NI32 LOC6;
		LOC3 = 0;
		LOC3 = Dl_107418(s, d, ((NI32) 0));
		if (!(LOC3 == ((NI32) 0))) goto LA4;
		LOC6 = 0;
		LOC6 = oslasterror_120040();
		raiseoserror_120024(LOC6, ((NimStringDesc*) &TMP157));
	}
	LA4: ;
}

N_NIMCALL(time_t, nosgetLastModificationTime)(NimStringDesc* file) {
	time_t result;
	Win32finddata107213 f;
	NI h;
	NI64 LOC6;
	result = 0;
	memset((void*)(&f), 0, sizeof(f));
	h = findfirstfile_120416(file, (&f));
	{
		NI32 LOC5;
		if (!(h == ((NI) -1))) goto LA3;
		LOC5 = 0;
		LOC5 = oslasterror_120040();
		raiseoserror_120024(LOC5, ((NimStringDesc*) &TMP157));
	}
	LA3: ;
	LOC6 = 0;
	LOC6 = rdfiletime_107601(f.ftlastwritetime);
	result = wintimetounixtime_110845(LOC6);
	Dl_107401(h);
	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) {
	Dl_107613(((NI32) (milsecs)));
}

N_NIMCALL(NimStringDesc*, expandtilde_133602)(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_116874(LOC11, LOC12);
	}
	goto LA1;
	LA9: ;
	{
		result = copyString(path);
	}
	LA1: ;
	return result;
}
NIM_EXTERNC N_NOINLINE(void, stdlib_osInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, stdlib_osDatInit000)(void) {
NTI127402.size = sizeof(TY127402*);
NTI127402.kind = 24;
NTI127402.base = (&NTI138);
NTI127402.flags = 2;
NTI127402.marker = TMP56;
}

