/* Generated by Nim Compiler v0.12.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 TY132408 TY132408;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Keyvaluepair148208 Keyvaluepair148208;
typedef struct Oserror4033 Oserror4033;
typedef struct Systemerror4029 Systemerror4029;
typedef struct Exception Exception;
typedef struct TNimObject TNimObject;
typedef struct Cell48946 Cell48946;
typedef struct Cellseq48962 Cellseq48962;
typedef struct Gcheap51018 Gcheap51018;
typedef struct Gcstack51016 Gcstack51016;
typedef struct Cellset48958 Cellset48958;
typedef struct Pagedesc48954 Pagedesc48954;
typedef struct Memregion30891 Memregion30891;
typedef struct Smallchunk30843 Smallchunk30843;
typedef struct Llchunk30885 Llchunk30885;
typedef struct Bigchunk30845 Bigchunk30845;
typedef struct Intset30817 Intset30817;
typedef struct Trunk30813 Trunk30813;
typedef struct Avlnode30889 Avlnode30889;
typedef struct Gcstat51014 Gcstat51014;
typedef struct TY122218 TY122218;
typedef struct Win32finddata112219 Win32finddata112219;
typedef struct Filetime111273 Filetime111273;
typedef struct Basechunk30841 Basechunk30841;
typedef struct Freecell30833 Freecell30833;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef N_NIMCALL_PTR(void, TY3889) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3894) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3889 marker;
TY3894 deepcopy;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct Keyvaluepair148208 {
NimStringDesc* Field0;
NimStringDesc* Field1;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  Exception  {
  TNimObject Sup;
Exception* parent;
NCSTRING name;
NimStringDesc* message;
NimStringDesc* trace;
};
struct  Systemerror4029  {
  Exception Sup;
};
struct  Oserror4033  {
  Systemerror4029 Sup;
NI32 errorcode;
};
typedef N_STDCALL_PTR(NI32, TY111663) (NI32 dwflags, void* lpsource, NI32 dwmessageid, NI32 dwlanguageid, void* lpbuffer, NI32 nsize, void* Arguments);
typedef N_STDCALL_PTR(void, TY111805) (void* p);
struct  Cell48946  {
NI refcount;
TNimType* typ;
};
struct  Cellseq48962  {
NI len;
NI cap;
Cell48946** d;
};
struct  Cellset48958  {
NI counter;
NI max;
Pagedesc48954* head;
Pagedesc48954** data;
};
typedef Smallchunk30843* TY30906[512];
typedef Trunk30813* Trunkbuckets30815[256];
struct  Intset30817  {
Trunkbuckets30815 data;
};
struct  Memregion30891  {
NI minlargeobj;
NI maxlargeobj;
TY30906 freesmallchunks;
Llchunk30885* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk30845* freechunkslist;
Intset30817 chunkstarts;
Avlnode30889* root;
Avlnode30889* deleted;
Avlnode30889* last;
Avlnode30889* freeavlnodes;
};
struct  Gcstat51014  {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct  Gcheap51018  {
Gcstack51016* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq48962 zct;
Cellseq48962 decstack;
Cellset48958 cycleroots;
Cellseq48962 tempstack;
NI recgclock;
Memregion30891 region;
Gcstat51014 stat;
};
typedef N_STDCALL_PTR(NI32, TY111658) (void);
typedef N_STDCALL_PTR(NI32, TY112411) (NI16* lpfilename, NI32 nbufferlength, NI16* lpbuffer, NI16** lpfilepart);
struct TY122218 {
NimStringDesc* Field0;
NimStringDesc* Field1;
NimStringDesc* Field2;
};
typedef N_STDCALL_PTR(NI32, TY111829) (NI handle, NI16* buf, NI32 size);
typedef N_STDCALL_PTR(NI, TY112244) (NI16* lpfilename, Win32finddata112219* lpfindfiledata);
typedef N_STDCALL_PTR(NI32, TY111818) (NI16* pathname, void* security);
typedef N_STDCALL_PTR(NI32, TY112418) (NI16* lpfilename);
typedef N_STDCALL_PTR(NI16*, TY112440) (void);
typedef N_STDCALL_PTR(NI16*, TY112435) (void);
typedef N_STDCALL_PTR(NI32, TY112437) (NI16* para1);
typedef N_STDCALL_PTR(NI32, TY111825) (NI16* lpname, NI16* lpvalue);
typedef N_STDCALL_PTR(NI32, TY111811) (NI32 nbufferlength, NI16* lpbuffer);
struct  Filetime111273  {
NI32 dwlowdatetime;
NI32 dwhighdatetime;
};
typedef NI16 TY112230[260];
typedef NI16 TY112234[14];
struct  Win32finddata112219  {
NI32 dwfileattributes;
Filetime111273 ftcreationtime;
Filetime111273 ftlastaccesstime;
Filetime111273 ftlastwritetime;
NI32 nfilesizehigh;
NI32 nfilesizelow;
NI32 dwreserved0;
NI32 dwreserved1;
TY112230 cfilename;
TY112234 calternatefilename;
};
typedef N_STDCALL_PTR(NI32, TY113371) (NI16* pathname);
typedef N_STDCALL_PTR(NI32, TY112421) (NI16* lpfilename, NI32 dwfileattributes);
typedef N_STDCALL_PTR(NI32, TY112249) (NI hfindfile, Win32finddata112219* lpfindfiledata);
typedef N_STDCALL_PTR(void, TY112405) (NI hfindfile);
typedef N_STDCALL_PTR(NI32, TY111822) (NI16* lppathname);
typedef N_STDCALL_PTR(int, TY112430) (NI16* lpexistingfilename, NI16* lpnewfilename, int bfailifexists);
typedef N_STDCALL_PTR(int, TY112425) (NI16* lpexistingfilename, NI16* lpnewfilename, int bfailifexists);
typedef N_STDCALL_PTR(void, TY112632) (NI32 dwmilliseconds);
struct  Gcstack51016  {
Gcstack51016* prev;
Gcstack51016* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY30822[8];
struct  Pagedesc48954  {
Pagedesc48954* next;
NI key;
TY30822 bits;
};
struct  Basechunk30841  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk30843  {
  Basechunk30841 Sup;
Smallchunk30843* next;
Smallchunk30843* prev;
Freecell30833* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk30885  {
NI size;
NI acc;
Llchunk30885* next;
};
struct  Bigchunk30845  {
  Basechunk30841 Sup;
Bigchunk30845* next;
Bigchunk30845* prev;
NI align;
NF data;
};
struct  Trunk30813  {
Trunk30813* next;
NI key;
TY30822 bits;
};
typedef Avlnode30889* TY30896[2];
struct  Avlnode30889  {
TY30896 link;
NI key;
NI upperbound;
NI level;
};
struct  Freecell30833  {
Freecell30833* next;
NI zerofield;
};
struct TY132408 {
  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, Keyvaluepair148208* Result);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI start_81016, 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_122168)(NimStringDesc* s);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
N_NIMCALL(NimStringDesc*, normext_122161)(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_124620)(NI32 errorcode);
N_NIMCALL(NimStringDesc*, HEX24_85487)(NI16* s);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(Cell48946*, usrtocell_52646)(void* usr);
static N_INLINE(void, rtladdzct_54204)(Cell48946* c);
N_NOINLINE(void, addzct_52617)(Cellseq48962* s, Cell48946* 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_85221)(NCSTRING source, NI L);
N_NIMCALL(NI16*, newwidecstring_85405)(NimStringDesc* s);
N_NOINLINE(void, raiseoserror_125030)(NI32 errorcode, NimStringDesc* additionalinfo);
N_NIMCALL(NI32, oslasterror_125055)(void);
N_NIMCALL(NimStringDesc*, HEX24_85412)(NI16* w, NI estimate, NI replacement);
N_NIMCALL(void, nossplitFile)(NimStringDesc* path, TY122218* Result);
N_NIMCALL(NimStringDesc*, nosgetAppFilename)(void);
N_NOCONV(void*, alloc_8401)(NI size);
N_NIMCALL(NI, parentdirpos_121951)(NimStringDesc* path);
N_NIMCALL(NimStringDesc*, nosjoinPath)(NimStringDesc* head, NimStringDesc* tail);
N_NIMCALL(NIM_BOOL, nosisAbsolute)(NimStringDesc* path);
N_NIMCALL(void, rawcreatedir_134444)(NimStringDesc* dir);
N_NIMCALL(TY132408*, 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_133243)(NimStringDesc* key);
N_NIMCALL(NI, findenvvar_133204)(NimStringDesc* key);
N_NIMCALL(void, getenvvarsc_132805)(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_6577)(NimStringDesc* x, NimStringDesc* y);
N_NIMCALL(NI, nsuCmpIgnoreCase)(NimStringDesc* a, NimStringDesc* b);
N_NIMCALL(NI, findfirstfile_125416)(NimStringDesc* a, Win32finddata112219* b);
N_NIMCALL(NimStringDesc*, HEX2F_121890)(NimStringDesc* head, NimStringDesc* tail);
static N_INLINE(NIM_BOOL, skipfinddata_125437)(Win32finddata112219* f);
N_NIMCALL(NimStringDesc*, nosextractFilename)(NimStringDesc* path);
N_NIMCALL(void, nosremoveFile)(NimStringDesc* file);
N_NIMCALL(void, nosremoveDir)(NimStringDesc* dir);
N_NIMCALL(void, rawremovedir_134153)(NimStringDesc* dir);
N_NIMCALL(time_t, wintimetounixtime_115872)(NI64 t);
N_NIMCALL(NI64, rdfiletime_112604)(Filetime111273 f);
N_NIMCALL(NI64, ntDiffTime)(time_t a, time_t b);
N_NIMCALL(time_t, nosgetLastModificationTime)(NimStringDesc* file);
N_NIMCALL(NimStringDesc*, nosgetHomeDir)(void);
N_NIMCALL(NimStringDesc*, nosaddFileExt)(NimStringDesc* filename, NimStringDesc* ext);
N_NIMCALL(NIM_BOOL, nosexistsFile)(NimStringDesc* filename);
STRING_LITERAL(TMP155, "", 0);
STRING_LITERAL(TMP1168, " ", 1);
STRING_LITERAL(TMP1169, "unknown OS error", 16);
STRING_LITERAL(TMP1647, ":\\", 2);
STRING_LITERAL(TMP1648, "\\", 1);
STRING_LITERAL(TMP1649, ".", 1);
STRING_LITERAL(TMP1650, "..\\", 3);
STRING_LITERAL(TMP1767, "USERPROFILE", 11);
STRING_LITERAL(TMP2022, "APPDATA", 7);
STRING_LITERAL(TMP3654, "*", 1);
STRING_LITERAL(TMP5290, "exe", 3);
STRING_LITERAL(TMP5291, "PATH", 4);
NIM_BOOL envcomputed_132407;
TY132408* environment_132409;
TY132408* ownargv_138808;
extern TNimType NTI149; /* string */
TNimType NTI132408; /* seq[string] */
extern TNimType NTI125034; /* ref OSError */
extern TNimType NTI4033; /* OSError */
extern TY111663 Dl_111662;
extern TY111805 Dl_111804;
extern Gcheap51018 gch_51059;
extern TY111658 Dl_111657;
extern TY112411 Dl_112410;
extern TY111829 Dl_111828;
extern TY112244 Dl_112243;
extern TY111818 Dl_111817;
extern TY112418 Dl_112417;
extern TY112440 Dl_112439;
extern TY112435 Dl_112434;
extern TY112437 Dl_112436;
extern TY111825 Dl_111824;
extern TY111811 Dl_111810;
extern TY113371 Dl_113370;
extern TY112421 Dl_112420;
extern TY112249 Dl_112248;
extern TY112405 Dl_112404;
extern TY111822 Dl_111821;
extern TY112430 Dl_112429;
extern TY112425 Dl_112424;
extern TY112632 Dl_112631;
N_NIMCALL(void, TMP56)(void* p, NI op) {
	TY132408* a;
	NI LOC1;
	a = (TY132408*)p;
	LOC1 = 0;
	for (LOC1 = 0; LOC1 < a->Sup.len; LOC1++) {
	nimGCvisit((void*)a->data[LOC1], op);
	}
}

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

N_NIMCALL(NI, searchextpos_122168)(NimStringDesc* s) {
	NI result;
	result = 0;
	result = ((NI) -1);
	{
		NI i_122183;
		NI HEX3Atmp_122196;
		NI res_122199;
		i_122183 = 0;
		HEX3Atmp_122196 = 0;
		HEX3Atmp_122196 = (NI)((s ? s->Sup.len : 0) - ((NI) 1));
		res_122199 = HEX3Atmp_122196;
		{
			while (1) {
				if (!(((NI) 1) <= res_122199)) goto LA3;
				i_122183 = res_122199;
				{
					if (!((NU8)(s->data[i_122183]) == (NU8)(46))) goto LA6;
					result = i_122183;
					goto LA1;
				}
				goto LA4;
				LA6: ;
				{
					if (!(((NU8)(s->data[i_122183])) == ((NU8)(92)) || ((NU8)(s->data[i_122183])) == ((NU8)(47)))) goto LA9;
					goto LA1;
				}
				goto LA4;
				LA9: ;
				LA4: ;
				res_122199 -= ((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_122161)(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_122168(filename);
	{
		NimStringDesc* LOC5;
		NimStringDesc* LOC6;
		if (!(extpos < ((NI) 0))) goto LA3;
		LOC5 = 0;
		LOC6 = 0;
		LOC6 = normext_122161(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_122161(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_124620)(NI32 errorcode) {
	NimStringDesc* result;
	result = 0;
	result = copyString(((NimStringDesc*) &TMP155));
	{
		NI16* msgbuf;
		if (!!((errorcode == ((NI32) 0)))) goto LA3;
		msgbuf = 0;
		{
			NI32 LOC7;
			LOC7 = 0;
			LOC7 = Dl_111662(((NI32) 4864), NIM_NIL, errorcode, ((NI32) 0), ((void*) (&msgbuf)), ((NI32) 0), NIM_NIL);
			if (!!((LOC7 == ((NI32) 0)))) goto LA8;
			result = HEX24_85487(msgbuf);
			{
				if (!!((msgbuf == NIM_NIL))) goto LA12;
				Dl_111804(((void*) (msgbuf)));
			}
			LA12: ;
		}
		LA8: ;
	}
	LA3: ;
	return result;
}

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

static N_INLINE(void, rtladdzct_54204)(Cell48946* c) {
	addzct_52617((&gch_51059.zct), c);
}

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

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

N_NOINLINE(void, raiseoserror_125030)(NI32 errorcode, NimStringDesc* additionalinfo) {
	Oserror4033* e;
	e = 0;
	e = (Oserror4033*) newObj((&NTI125034), sizeof(Oserror4033));
	(*e).Sup.Sup.Sup.m_type = (&NTI4033);
	(*e).errorcode = errorcode;
	{
		if (!((additionalinfo ? additionalinfo->Sup.len : 0) == ((NI) 0))) goto LA3;
		asgnRefNoCycle((void**) (&(*e).Sup.Sup.message), oserrormsg_124620(errorcode));
	}
	goto LA1;
	LA3: ;
	{
		NimStringDesc* LOC6;
		NimStringDesc* LOC7;
		LOC6 = 0;
		LOC7 = 0;
		LOC7 = oserrormsg_124620(errorcode);
		LOC6 = rawNewString(additionalinfo->Sup.len + LOC7->Sup.len + 1);
appendString(LOC6, additionalinfo);
appendString(LOC6, ((NimStringDesc*) &TMP1168));
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*) &TMP1169));
		if (LOC12) nimGCunrefNoCycle(LOC12);
	}
	LA10: ;
	raiseException((Exception*)e, "OSError");
}

N_NIMCALL(NI32, oslasterror_125055)(void) {
	NI32 result;
	result = 0;
	result = Dl_111657();
	return result;
}

N_NIMCALL(NimStringDesc*, nosexpandFilename)(NimStringDesc* filename) {
	NimStringDesc* result;
	NI16* unused;
	NI16* res;
	NI32 L;
	NI16* LOC1;
	result = 0;
	unused = 0;
	res = newwidecstring_85221("", ((NI) 1536));
	LOC1 = 0;
	LOC1 = newwidecstring_85405(filename);
	L = Dl_112410(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_125055();
		raiseoserror_125030(LOC8, ((NimStringDesc*) &TMP155));
	}
	LA6: ;
	result = HEX24_85412(res, ((NI) (L)), ((NI) 65533));
	return result;
}

N_NIMCALL(void, nossplitFile)(NimStringDesc* path, TY122218* 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*) &TMP155)));
		unsureAsgnRef((void**) (&(*Result).Field2), copyString(((NimStringDesc*) &TMP155)));
	}
	goto LA1;
	LA5: ;
	{
		NI seppos;
		NI dotpos;
		seppos = ((NI) -1);
		dotpos = (path ? path->Sup.len : 0);
		{
			NI i_122248;
			NI HEX3Atmp_122272;
			NI res_122275;
			i_122248 = 0;
			HEX3Atmp_122272 = 0;
			HEX3Atmp_122272 = (NI)((path ? path->Sup.len : 0) - ((NI) 1));
			res_122275 = HEX3Atmp_122272;
			{
				while (1) {
					if (!(((NI) 0) <= res_122275)) goto LA10;
					i_122248 = res_122275;
					{
						if (!((NU8)(path->data[i_122248]) == (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_122248);
							LA19: ;
							LOC17 = LOC18;
							if (!(LOC17)) goto LA20;
							LOC17 = !((((NU8)(path->data[(NI)(i_122248 - ((NI) 1))])) == ((NU8)(92)) || ((NU8)(path->data[(NI)(i_122248 - ((NI) 1))])) == ((NU8)(47))));
							LA20: ;
							if (!LOC17) goto LA21;
							dotpos = i_122248;
						}
						LA21: ;
					}
					goto LA11;
					LA13: ;
					{
						if (!(((NU8)(path->data[i_122248])) == ((NU8)(92)) || ((NU8)(path->data[i_122248])) == ((NU8)(47)))) goto LA24;
						seppos = i_122248;
						goto LA8;
					}
					goto LA11;
					LA24: ;
					LA11: ;
					res_122275 -= ((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;
	void* LOC1;
	NI32 len;
	result = 0;
	LOC1 = 0;
	LOC1 = alloc_8401(((NI) 512));
	buf = ((NI16*) (LOC1));
	len = Dl_111828(((NI) 0), buf, ((NI32) 256));
	result = HEX24_85412(buf, ((NI) (len)), ((NI) 65533));
	return result;
}

N_NIMCALL(NimStringDesc*, nosgetAppDir)(void) {
	NimStringDesc* result;
	NimStringDesc* LOC1;
	TY122218 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_121951)(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_121978;
		NI HEX3Atmp_121991;
		NI res_121994;
		i_121978 = 0;
		HEX3Atmp_121991 = 0;
		HEX3Atmp_121991 = (NI)((path ? path->Sup.len : 0) - q);
		res_121994 = HEX3Atmp_121991;
		{
			while (1) {
				if (!(((NI) 0) <= res_121994)) goto LA9;
				i_121978 = res_121994;
				{
					if (!(((NU8)(path->data[i_121978])) == ((NU8)(92)) || ((NU8)(path->data[i_121978])) == ((NU8)(47)))) goto LA12;
					result = i_121978;
					goto BeforeRet;
				}
				LA12: ;
				res_121994 -= ((NI) 1);
			} LA9: ;
		}
	}
	result = ((NI) -1);
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nosparentDir)(NimStringDesc* path) {
	NimStringDesc* result;
	NI seppos;
	result = 0;
	seppos = parentdirpos_121951(path);
	{
		if (!(((NI) 0) <= seppos)) goto LA3;
		result = copyStrLast(path, ((NI) 0), (NI)(seppos - ((NI) 1)));
	}
	goto LA1;
	LA3: ;
	{
		result = copyString(((NimStringDesc*) &TMP155));
	}
	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_121890)(NimStringDesc* head, NimStringDesc* tail) {
	NimStringDesc* result;
{	result = 0;
	result = nosjoinPath(head, tail);
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NI, findfirstfile_125416)(NimStringDesc* a, Win32finddata112219* b) {
	NI result;
	NI16* LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = newwidecstring_85405(a);
	result = Dl_112243(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_134444)(NimStringDesc* dir) {
	NI32 res;
	NI16* LOC1;
	LOC1 = 0;
	LOC1 = newwidecstring_85405(dir);
	res = Dl_111817(LOC1, NIM_NIL);
	{
		NIM_BOOL LOC4;
		NI32 LOC6;
		NI32 LOC9;
		LOC4 = 0;
		LOC4 = (res == ((NI32) 0));
		if (!(LOC4)) goto LA5;
		LOC6 = 0;
		LOC6 = Dl_111657();
		LOC4 = !((LOC6 == ((NI32) 183)));
		LA5: ;
		if (!LOC4) goto LA7;
		LOC9 = 0;
		LOC9 = oslasterror_125055();
		raiseoserror_125030(LOC9, ((NimStringDesc*) &TMP155));
	}
	LA7: ;
}

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

N_NIMCALL(NimStringDesc*, nosjoinPathOpenArray)(NimStringDesc** parts, NI partsLen0) {
	NimStringDesc* result;
	result = 0;
	result = copyString(parts[((NI) 0)]);
	{
		NI i_121867;
		NI HEX3Atmp_121871;
		NI res_121874;
		i_121867 = 0;
		HEX3Atmp_121871 = 0;
		HEX3Atmp_121871 = (partsLen0-1);
		res_121874 = ((NI) 1);
		{
			while (1) {
				if (!(res_121874 <= HEX3Atmp_121871)) goto LA3;
				i_121867 = res_121874;
				result = nosjoinPath(result, parts[i_121867]);
				res_121874 += ((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_85405(filename);
	a = Dl_112417(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_122168(filename);
	{
		NimStringDesc* LOC5;
		NimStringDesc* LOC6;
		if (!(extpos < ((NI) 0))) goto LA3;
		LOC5 = 0;
		LOC6 = 0;
		LOC6 = normext_122161(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(TY132408*, nosparseCmdLine)(NimStringDesc* c) {
	TY132408* result;
	NI i;
	NimStringDesc* a;
	result = 0;
	result = (TY132408*) newSeq((&NTI132408), 0);
	i = ((NI) 0);
	a = copyString(((NimStringDesc*) &TMP155));
	{
		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_136022;
								NI HEX3Atmp_136084;
								NI res_136087;
								k_136022 = 0;
								HEX3Atmp_136084 = 0;
								HEX3Atmp_136084 = (NI)((NI)(j - i) / ((NI) 2));
								res_136087 = ((NI) 1);
								{
									while (1) {
										if (!(res_136087 <= HEX3Atmp_136084)) goto LA27;
										k_136022 = res_136087;
										a = addChar(a, 92);
										res_136087 += ((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 = (TY132408*) 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_138808 == 0) goto LA3;
		LOC5 = 0;
		LOC5 = Dl_112439();
		LOC6 = 0;
		LOC6 = HEX24_85487(LOC5);
		asgnRefNoCycle((void**) (&ownargv_138808), nosparseCmdLine(LOC6));
	}
	LA3: ;
	result = (NI)((ownargv_138808 ? ownargv_138808->Sup.len : 0) - ((NI) 1));
	return result;
}

N_NIMCALL(NimStringDesc*, nosparamStr)(NI i) {
	NimStringDesc* result;
{	result = 0;
	{
		NI16* LOC5;
		NimStringDesc* LOC6;
		if (!ownargv_138808 == 0) goto LA3;
		LOC5 = 0;
		LOC5 = Dl_112439();
		LOC6 = 0;
		LOC6 = HEX24_85487(LOC5);
		asgnRefNoCycle((void**) (&ownargv_138808), nosparseCmdLine(LOC6));
	}
	LA3: ;
	result = copyString(ownargv_138808->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*) &TMP1647));
			result = LOC9;
		}
		goto LA5;
		LA7: ;
		{
			result = copyString(((NimStringDesc*) &TMP1648));
		}
		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*) &TMP1649));
		start = ((NI) 2);
	}
	goto LA1;
	LA14: ;
	{
		result = copyString(((NimStringDesc*) &TMP155));
		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*) &TMP1650));
				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_132805)(void) {
{	{
		NI16* env;
		NI16* e;
		NI32 LOC17;
		if (!!(envcomputed_132407)) goto LA3;
		if (environment_132409) nimGCunrefNoCycle(environment_132409);
		environment_132409 = (TY132408*) newSeqRC1((&NTI132408), 0);
		env = Dl_112434();
		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_85487(e);
				environment_132409 = (TY132408*) incrSeqV2(&(environment_132409)->Sup, sizeof(NimStringDesc*));
				LOC12 = 0;
				LOC12 = environment_132409->data[environment_132409->Sup.len]; environment_132409->data[environment_132409->Sup.len] = copyStringRC1(LOC11);
				if (LOC12) nimGCunrefNoCycle(LOC12);
				++environment_132409->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_112436(env);
		envcomputed_132407 = NIM_TRUE;
	}
	LA3: ;
	}BeforeRet: ;
}

N_NIMCALL(NI, findenvvar_133204)(NimStringDesc* key) {
	NI result;
	NimStringDesc* temp;
	NimStringDesc* LOC1;
{	result = 0;
	getenvvarsc_132805();
	LOC1 = 0;
	LOC1 = rawNewString(key->Sup.len + 1);
appendString(LOC1, key);
appendChar(LOC1, 61);
	temp = LOC1;
	{
		NI i_133219;
		NI HEX3Atmp_133221;
		NI res_133224;
		i_133219 = 0;
		HEX3Atmp_133221 = 0;
		HEX3Atmp_133221 = (environment_132409 ? (environment_132409->Sup.len-1) : -1);
		res_133224 = ((NI) 0);
		{
			while (1) {
				if (!(res_133224 <= HEX3Atmp_133221)) goto LA4;
				i_133219 = res_133224;
				{
					NIM_BOOL LOC7;
					LOC7 = 0;
					LOC7 = nsuStartsWith(environment_132409->data[i_133219], temp);
					if (!LOC7) goto LA8;
					result = i_133219;
					goto BeforeRet;
				}
				LA8: ;
				res_133224 += ((NI) 1);
			} LA4: ;
		}
	}
	result = ((NI) -1);
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, getenv_133243)(NimStringDesc* key) {
	NimStringDesc* result;
	NI i;
{	result = 0;
	i = findenvvar_133204(key);
	{
		NI LOC5;
		if (!(((NI) 0) <= i)) goto LA3;
		LOC5 = 0;
		LOC5 = nsuFindChar(environment_132409->data[i], 61, ((NI) 0));
		result = copyStr(environment_132409->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*) &TMP155));
			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_133243(((NimStringDesc*) &TMP1767));
	LOC1 = rawNewString(LOC2->Sup.len + 1);
appendString(LOC1, LOC2);
appendString(LOC1, ((NimStringDesc*) &TMP1648));
	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_6577(patha, pathb);
	}
	goto LA1;
	LA3: ;
	{
		result = nsuCmpIgnoreCase(patha, pathb);
	}
	LA1: ;
	return result;
}

N_NIMCALL(void, putenv_133268)(NimStringDesc* key, NimStringDesc* val) {
	NI indx;
	NI16* k;
	NI16* v;
	indx = findenvvar_133204(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_132409->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_132409 = (TY132408*) incrSeqV2(&(environment_132409)->Sup, sizeof(NimStringDesc*));
		LOC8 = 0;
		LOC8 = environment_132409->data[environment_132409->Sup.len]; environment_132409->data[environment_132409->Sup.len] = copyStringRC1(LOC7);
		if (LOC8) nimGCunrefNoCycle(LOC8);
		++environment_132409->Sup.len;
		indx = (environment_132409 ? (environment_132409->Sup.len-1) : -1);
	}
	LA1: ;
	k = newwidecstring_85405(key);
	v = newwidecstring_85405(val);
	{
		NI32 LOC11;
		NI32 LOC14;
		LOC11 = 0;
		LOC11 = Dl_111824(k, v);
		if (!(LOC11 == ((NI32) 0))) goto LA12;
		LOC14 = 0;
		LOC14 = oslasterror_125055();
		raiseoserror_125030(LOC14, ((NimStringDesc*) &TMP155));
	}
	LA12: ;
}

N_NIMCALL(NimStringDesc*, nosgetCurrentDir)(void) {
	NimStringDesc* result;
	NI16* res;
	NI32 L;
	result = 0;
	res = newwidecstring_85221("", ((NI) 512));
	L = Dl_111810(((NI32) 512), res);
	{
		NI32 LOC5;
		if (!(L == ((NI32) 0))) goto LA3;
		LOC5 = 0;
		LOC5 = oslasterror_125055();
		raiseoserror_125030(LOC5, ((NimStringDesc*) &TMP155));
	}
	LA3: ;
	result = HEX24_85412(res, ((NI) (L)), ((NI) 65533));
	return result;
}

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

N_NIMCALL(NIM_BOOL, existsenv_133258)(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_133204(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_85405(dir);
	a = Dl_112417(LOC1);
	{
		if (!!((a == ((NI32) -1)))) goto LA4;
		result = !(((NI32)(a & ((NI32) 16)) == ((NI32) 0)));
	}
	LA4: ;
	return result;
}

static N_INLINE(NIM_BOOL, skipfinddata_125437)(Win32finddata112219* 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_85405(file);
	{
		NI32 LOC3;
		LOC3 = 0;
		LOC3 = Dl_113370(f);
		if (!(LOC3 == ((NI32) 0))) goto LA4;
		{
			NI32 LOC8;
			LOC8 = 0;
			LOC8 = Dl_111657();
			if (!(LOC8 == ((NI32) 5))) goto LA9;
			{
				NI32 LOC13;
				NI32 LOC16;
				LOC13 = 0;
				LOC13 = Dl_112420(f, ((NI32) 128));
				if (!(LOC13 == ((NI32) 0))) goto LA14;
				LOC16 = 0;
				LOC16 = oslasterror_125055();
				raiseoserror_125030(LOC16, ((NimStringDesc*) &TMP155));
			}
			LA14: ;
			{
				NI32 LOC19;
				NI32 LOC22;
				LOC19 = 0;
				LOC19 = Dl_113370(f);
				if (!(LOC19 == ((NI32) 0))) goto LA20;
				LOC22 = 0;
				LOC22 = oslasterror_125055();
				raiseoserror_125030(LOC22, ((NimStringDesc*) &TMP155));
			}
			LA20: ;
		}
		LA9: ;
	}
	LA4: ;
}

N_NIMCALL(void, rawremovedir_134153)(NimStringDesc* dir) {
	NI32 res;
	NI16* LOC1;
	NI32 lasterror;
	LOC1 = 0;
	LOC1 = newwidecstring_85405(dir);
	res = Dl_111821(LOC1);
	lasterror = oslasterror_125055();
	{
		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_125030(lasterror, ((NimStringDesc*) &TMP155));
	}
	LA10: ;
}

N_NIMCALL(void, nosremoveDir)(NimStringDesc* dir) {
	{
		NU8 kind_134415;
		NimStringDesc* path_134416;
		Win32finddata112219 f_134420;
		NI h_134422;
		NimStringDesc* LOC2;
		kind_134415 = 0;
		path_134416 = 0;
		memset((void*)(&f_134420), 0, sizeof(f_134420));
		LOC2 = 0;
		LOC2 = HEX2F_121890(dir, ((NimStringDesc*) &TMP3654));
		h_134422 = findfirstfile_125416(LOC2, (&f_134420));
		{
			if (!!((h_134422 == ((NI) -1)))) goto LA5;
			{
				while (1) {
					NU8 k_134424;
					k_134424 = ((NU8) 0);
					{
						NIM_BOOL LOC11;
						NimStringDesc* xx_134426;
						LOC11 = 0;
						LOC11 = skipfinddata_125437((&f_134420));
						if (!!(LOC11)) goto LA12;
						{
							if (!!(((NI32)(f_134420.dwfileattributes & ((NI32) 16)) == ((NI32) 0)))) goto LA16;
							k_134424 = ((NU8) 2);
						}
						LA16: ;
						{
							if (!!(((NI32)(f_134420.dwfileattributes & ((NI32) 1024)) == ((NI32) 0)))) goto LA20;
							k_134424 = (NU8)(k_134424 + ((NI) 1));
						}
						LA20: ;
						{
							NimStringDesc* LOC26;
							if (!NIM_FALSE) goto LA24;
							LOC26 = 0;
							LOC26 = HEX24_85487(((NI16*) ((&f_134420.cfilename[(((NI) 0))- 0]))));
							xx_134426 = nosextractFilename(LOC26);
						}
						goto LA22;
						LA24: ;
						{
							NimStringDesc* LOC28;
							NimStringDesc* LOC29;
							LOC28 = 0;
							LOC28 = HEX24_85487(((NI16*) ((&f_134420.cfilename[(((NI) 0))- 0]))));
							LOC29 = 0;
							LOC29 = nosextractFilename(LOC28);
							xx_134426 = HEX2F_121890(dir, LOC29);
						}
						LA22: ;
						kind_134415 = k_134424;
						path_134416 = xx_134426;
						switch (kind_134415) {
						case ((NU8) 0):
						case ((NU8) 1):
						case ((NU8) 3):
						{
							nosremoveFile(path_134416);
						}
						break;
						case ((NU8) 2):
						{
							nosremoveDir(path_134416);
						}
						break;
						}
					}
					LA12: ;
					{
						NI32 LOC34;
						LOC34 = 0;
						LOC34 = Dl_112248(h_134422, (&f_134420));
						if (!(LOC34 == ((NI32) 0))) goto LA35;
						goto LA7;
					}
					LA35: ;
				}
			} LA7: ;
			Dl_112404(h_134422);
		}
		LA5: ;
	}
	rawremovedir_134153(dir);
}

N_NIMCALL(void, nosmoveFile)(NimStringDesc* source, NimStringDesc* dest) {
	NI16* s;
	NI16* d;
	s = newwidecstring_85405(source);
	d = newwidecstring_85405(dest);
	{
		int LOC3;
		NI32 LOC6;
		LOC3 = 0;
		LOC3 = Dl_112429(s, d, ((NI32) 0));
		if (!(LOC3 == ((NI32) 0))) goto LA4;
		LOC6 = 0;
		LOC6 = oslasterror_125055();
		raiseoserror_125030(LOC6, ((NimStringDesc*) &TMP155));
	}
	LA4: ;
}

N_NIMCALL(void, noscopyFile)(NimStringDesc* source, NimStringDesc* dest) {
	NI16* s;
	NI16* d;
	s = newwidecstring_85405(source);
	d = newwidecstring_85405(dest);
	{
		int LOC3;
		NI32 LOC6;
		LOC3 = 0;
		LOC3 = Dl_112424(s, d, ((NI32) 0));
		if (!(LOC3 == ((NI32) 0))) goto LA4;
		LOC6 = 0;
		LOC6 = oslasterror_125055();
		raiseoserror_125030(LOC6, ((NimStringDesc*) &TMP155));
	}
	LA4: ;
}

N_NIMCALL(time_t, nosgetLastModificationTime)(NimStringDesc* file) {
	time_t result;
	Win32finddata112219 f;
	NI h;
	NI64 LOC6;
	result = 0;
	memset((void*)(&f), 0, sizeof(f));
	h = findfirstfile_125416(file, (&f));
	{
		NI32 LOC5;
		if (!(h == ((NI) -1))) goto LA3;
		LOC5 = 0;
		LOC5 = oslasterror_125055();
		raiseoserror_125030(LOC5, ((NimStringDesc*) &TMP155));
	}
	LA3: ;
	LOC6 = 0;
	LOC6 = rdfiletime_112604(f.ftlastwritetime);
	result = wintimetounixtime_115872(LOC6);
	Dl_112404(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_112631(((NI32) (milsecs)));
}

N_NIMCALL(NimStringDesc*, expandtilde_138005)(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_121890(LOC11, LOC12);
	}
	goto LA1;
	LA9: ;
	{
		result = copyString(path);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NimStringDesc*, findexe_138201)(NimStringDesc* exe) {
	NimStringDesc* result;
	NimStringDesc* path;
{	result = 0;
	result = nosaddFileExt(exe, ((NimStringDesc*) &TMP5290));
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = nosexistsFile(result);
		if (!LOC3) goto LA4;
		goto BeforeRet;
	}
	LA4: ;
	path = getenv_133243(((NimStringDesc*) &TMP5291));
	{
		NimStringDesc* candidate_138206;
		NI last_138407;
		candidate_138206 = 0;
		last_138407 = ((NI) 0);
		{
			if (!(((NI) 0) < (path ? path->Sup.len : 0))) goto LA9;
			{
				while (1) {
					NI first_138409;
					NimStringDesc* x;
					if (!(last_138407 <= (path ? path->Sup.len : 0))) goto LA12;
					first_138409 = last_138407;
					{
						while (1) {
							NIM_BOOL LOC15;
							LOC15 = 0;
							LOC15 = (last_138407 < (path ? path->Sup.len : 0));
							if (!(LOC15)) goto LA16;
							LOC15 = !(((NU8)(path->data[last_138407]) == (NU8)(59)));
							LA16: ;
							if (!LOC15) goto LA14;
							last_138407 += ((NI) 1);
						} LA14: ;
					}
					candidate_138206 = copyStrLast(path, first_138409, (NI)(last_138407 - ((NI) 1)));
					x = HEX2F_121890(candidate_138206, result);
					{
						NIM_BOOL LOC19;
						LOC19 = 0;
						LOC19 = nosexistsFile(x);
						if (!LOC19) goto LA20;
						result = copyString(x);
						goto BeforeRet;
					}
					LA20: ;
					last_138407 += ((NI) 1);
				} LA12: ;
			}
		}
		LA9: ;
	}
	result = copyString(((NimStringDesc*) &TMP155));
	}BeforeRet: ;
	return result;
}
NIM_EXTERNC N_NOINLINE(void, stdlib_osInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, stdlib_osDatInit000)(void) {
NTI132408.size = sizeof(TY132408*);
NTI132408.kind = 24;
NTI132408.base = (&NTI149);
NTI132408.flags = 2;
NTI132408.marker = TMP56;
}

