/* Generated by Nim Compiler v0.10.2 */
/*   (c) 2014 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 TY120608 TY120608;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct oserror3233 oserror3233;
typedef struct systemerror3229 systemerror3229;
typedef struct Exception Exception;
typedef struct TNimObject TNimObject;
typedef struct tcell44733 tcell44733;
typedef struct tcellseq44749 tcellseq44749;
typedef struct tgcheap46816 tgcheap46816;
typedef struct tcellset44745 tcellset44745;
typedef struct tpagedesc44741 tpagedesc44741;
typedef struct tmemregion27010 tmemregion27010;
typedef struct tsmallchunk26240 tsmallchunk26240;
typedef struct tllchunk27004 tllchunk27004;
typedef struct tbigchunk26242 tbigchunk26242;
typedef struct tintset26217 tintset26217;
typedef struct ttrunk26213 ttrunk26213;
typedef struct tavlnode27008 tavlnode27008;
typedef struct tgcstat46814 tgcstat46814;
typedef struct keyvaluepair133008 keyvaluepair133008;
typedef struct TY116804 TY116804;
typedef struct twin32finddata104019 twin32finddata104019;
typedef struct tfiletime103079 tfiletime103079;
typedef struct slice85779 slice85779;
typedef struct tbasechunk26238 tbasechunk26238;
typedef struct tfreecell26230 tfreecell26230;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef N_NIMCALL_PTR(void, TY3089) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3094) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3089 marker;
TY3094 deepcopy;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  Exception  {
  TNimObject Sup;
Exception* parent;
NCSTRING name;
NimStringDesc* message;
NimStringDesc* trace;
};
struct  systemerror3229  {
  Exception Sup;
};
struct  oserror3233  {
  systemerror3229 Sup;
NI32 Errorcode;
};
typedef N_STDCALL_PTR(NI32, TY103463) (NI32 dwflags, void* lpsource, NI32 dwmessageid, NI32 dwlanguageid, void* lpbuffer, NI32 nsize, void* arguments);
typedef N_STDCALL_PTR(void, TY103605) (void* p);
struct  tcell44733  {
NI Refcount;
TNimType* Typ;
};
struct  tcellseq44749  {
NI Len;
NI Cap;
tcell44733** D;
};
struct  tcellset44745  {
NI Counter;
NI Max;
tpagedesc44741* Head;
tpagedesc44741** Data;
};
typedef tsmallchunk26240* TY27022[512];
typedef ttrunk26213* ttrunkbuckets26215[256];
struct  tintset26217  {
ttrunkbuckets26215 Data;
};
struct  tmemregion27010  {
NI Minlargeobj;
NI Maxlargeobj;
TY27022 Freesmallchunks;
tllchunk27004* Llmem;
NI Currmem;
NI Maxmem;
NI Freemem;
NI Lastsize;
tbigchunk26242* Freechunkslist;
tintset26217 Chunkstarts;
tavlnode27008* Root;
tavlnode27008* Deleted;
tavlnode27008* Last;
tavlnode27008* Freeavlnodes;
};
struct  tgcstat46814  {
NI Stackscans;
NI Cyclecollections;
NI Maxthreshold;
NI Maxstacksize;
NI Maxstackcells;
NI Cycletablesize;
NI64 Maxpause;
};
struct  tgcheap46816  {
void* Stackbottom;
NI Cyclethreshold;
tcellseq44749 Zct;
tcellseq44749 Decstack;
tcellset44745 Cycleroots;
tcellseq44749 Tempstack;
NI Recgclock;
tmemregion27010 Region;
tgcstat46814 Stat;
};
typedef N_STDCALL_PTR(NI32, TY103458) (void);
struct keyvaluepair133008 {
NimStringDesc* Field0;
NimStringDesc* Field1;
};
typedef N_STDCALL_PTR(NI32, TY104211) (NI16* lpfilename, NI32 nbufferlength, NI16* lpbuffer, NI16** lpfilepart);
struct TY116804 {
NimStringDesc* Field0;
NimStringDesc* Field1;
NimStringDesc* Field2;
};
typedef N_STDCALL_PTR(NI32, TY103629) (NI handle, NI16* buf, NI32 size);
typedef N_STDCALL_PTR(NI, TY104040) (NI16* lpfilename, twin32finddata104019* lpfindfiledata);
typedef N_STDCALL_PTR(NI32, TY103618) (NI16* pathname, void* security);
typedef N_STDCALL_PTR(NI32, TY104218) (NI16* lpfilename);
typedef N_STDCALL_PTR(NI16*, TY104235) (void);
typedef N_STDCALL_PTR(NI16*, TY104230) (void);
typedef N_STDCALL_PTR(NI32, TY104232) (NI16* para1);
typedef N_STDCALL_PTR(NI32, TY103625) (NI16* lpname, NI16* lpvalue);
typedef N_STDCALL_PTR(NI32, TY103611) (NI32 nbufferlength, NI16* lpbuffer);
struct  tfiletime103079  {
NI32 Dwlowdatetime;
NI32 Dwhighdatetime;
};
typedef NI16 TY104028[260];
typedef NI16 TY104032[14];
struct  twin32finddata104019  {
NI32 Dwfileattributes;
tfiletime103079 Ftcreationtime;
tfiletime103079 Ftlastaccesstime;
tfiletime103079 Ftlastwritetime;
NI32 Nfilesizehigh;
NI32 Nfilesizelow;
NI32 Dwreserved0;
NI32 Dwreserved1;
TY104028 Cfilename;
TY104032 Calternatefilename;
};
typedef N_STDCALL_PTR(void, TY104205) (NI hfindfile);
typedef N_STDCALL_PTR(void, TY104432) (NI32 dwmilliseconds);
struct  slice85779  {
NI A;
NI B;
};
typedef NI TY26220[8];
struct  tpagedesc44741  {
tpagedesc44741* Next;
NI Key;
TY26220 Bits;
};
struct  tbasechunk26238  {
NI Prevsize;
NI Size;
NIM_BOOL Used;
};
struct  tsmallchunk26240  {
  tbasechunk26238 Sup;
tsmallchunk26240* Next;
tsmallchunk26240* Prev;
tfreecell26230* Freelist;
NI Free;
NI Acc;
NF Data;
};
struct  tllchunk27004  {
NI Size;
NI Acc;
tllchunk27004* Next;
};
struct  tbigchunk26242  {
  tbasechunk26238 Sup;
tbigchunk26242* Next;
tbigchunk26242* Prev;
NI Align;
NF Data;
};
struct  ttrunk26213  {
ttrunk26213* Next;
NI Key;
TY26220 Bits;
};
typedef tavlnode27008* TY27014[2];
struct  tavlnode27008  {
TY27014 Link;
NI Key;
NI Upperbound;
NI Level;
};
struct  tfreecell26230  {
tfreecell26230* Next;
NI Zerofield;
};
struct TY120608 {
  TGenericSeq Sup;
  NimStringDesc* data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP54)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
N_NIMCALL(NimStringDesc*, oserrormsg_112020)(NI32 errorcode);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(NimStringDesc*, HEX24_79195)(NI16* s);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(tcell44733*, usrtocell_48446)(void* usr);
static N_INLINE(void, rtladdzct_50004)(tcell44733* c);
N_NOINLINE(void, addzct_48417)(tcellseq44749* s, tcell44733* c);
N_NIMCALL(NimStringDesc*, copyStringRC1)(NimStringDesc* src);
static N_INLINE(void, nimGCunrefNoCycle)(void* p);
N_NIMCALL(void, raiseException)(Exception* e, NCSTRING ename);
N_NIMCALL(void, nossplitPath)(NimStringDesc* path, keyvaluepair133008* Result);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI start_74628, 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_116751)(NimStringDesc* s);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
N_NIMCALL(NimStringDesc*, normext_116741)(NimStringDesc* ext);
static N_INLINE(void, appendChar)(NimStringDesc* dest, NIM_CHAR c);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(NI16*, newwidecstring_78824)(NCSTRING source, NI l);
N_NIMCALL(NI16*, newwidecstring_79005)(NimStringDesc* s);
N_NIMCALL(void, raiseoserror_112435)(NI32 errorcode);
N_NIMCALL(NI32, oslasterror_112467)(void);
N_NIMCALL(NimStringDesc*, HEX24_79012)(NI16* w, NI estimate);
N_NIMCALL(void, nossplitFile)(NimStringDesc* path, TY116804* Result);
N_NIMCALL(NimStringDesc*, nosgetAppFilename)(void);
N_NOCONV(void*, alloc_5801)(NI size);
N_NIMCALL(NI, parentdirpos_116566)(NimStringDesc* path);
N_NIMCALL(NimStringDesc*, nosjoinPath)(NimStringDesc* head, NimStringDesc* tail);
N_NIMCALL(NIM_BOOL, nosisAbsolute)(NimStringDesc* path);
N_NIMCALL(void, rawcreatedir_122441)(NimStringDesc* dir);
N_NIMCALL(TY120608*, 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*, incrSeq)(TGenericSeq* seq, NI elemsize);
N_NIMCALL(NimStringDesc*, resizeString)(NimStringDesc* dest, NI addlen);
N_NIMCALL(NimStringDesc*, getenv_121241)(NimStringDesc* key);
N_NIMCALL(NI, findenvvar_121204)(NimStringDesc* key);
N_NIMCALL(void, getenvvarsc_120805)(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_4517)(NimStringDesc* x, NimStringDesc* y);
N_NIMCALL(NI, nsuCmpIgnoreCase)(NimStringDesc* a, NimStringDesc* b);
N_NIMCALL(NI64, ntDiffTime)(time_t a, time_t b);
N_NIMCALL(time_t, nosgetLastModificationTime)(NimStringDesc* file);
N_NIMCALL(NI, findfirstfile_113416)(NimStringDesc* a, twin32finddata104019* b);
N_NIMCALL(time_t, wintimetounixtime_107691)(NI64 t);
N_NIMCALL(NI64, rdfiletime_104404)(tfiletime103079 f);
N_NIMCALL(NimStringDesc*, HEX2F_116499)(NimStringDesc* head, NimStringDesc* tail);
N_NIMCALL(NimStringDesc*, nosgetHomeDir)(void);
static N_INLINE(NimStringDesc*, HEX5BHEX5D_85772)(NimStringDesc* s, slice85779 x);
static N_INLINE(slice85779, HEX2EHEX2E_94499)(NI a_94503, NI b_94505);
STRING_LITERAL(TMP139, "", 0);
STRING_LITERAL(TMP143, "unknown OS error", 16);
STRING_LITERAL(TMP1687, ":\\", 2);
STRING_LITERAL(TMP1688, "\\", 1);
STRING_LITERAL(TMP1689, ".", 1);
STRING_LITERAL(TMP1690, "..\\", 3);
STRING_LITERAL(TMP1694, "USERPROFILE", 11);
STRING_LITERAL(TMP1915, "APPDATA", 7);
NIM_BOOL envcomputed_120607;
TY120608* environment_120609;
TY120608* ownargv_125009;
extern TNimType NTI149; /* string */
TNimType NTI120608; /* seq[string] */
extern TNimType NTI112438; /* ref OSError */
extern TNimType NTI3233; /* OSError */
extern TY103463 Dl_103462;
extern TY103605 Dl_103604;
extern tgcheap46816 gch_46844;
extern TY103458 Dl_103457;
extern TY104211 Dl_104210;
extern TY103629 Dl_103628;
extern TY104040 Dl_104039;
extern TY103618 Dl_103617;
extern TY104218 Dl_104217;
extern TY104235 Dl_104234;
extern TY104230 Dl_104229;
extern TY104232 Dl_104231;
extern TY103625 Dl_103624;
extern TY103611 Dl_103610;
extern TY104205 Dl_104204;
extern TY104432 Dl_104431;
N_NIMCALL(void, TMP54)(void* p, NI op) {
	TY120608* a;
	NI LOC1;
	a = (TY120608*)p;
	LOC1 = 0;
	for (LOC1 = 0; LOC1 < a->Sup.len; LOC1++) {
	nimGCvisit((void*)a->data[LOC1], op);
	}
}

N_NIMCALL(NimStringDesc*, oserrormsg_112020)(NI32 errorcode) {
	NimStringDesc* result;
	result = 0;
	result = copyString(((NimStringDesc*) &TMP139));
	{
		NI16* msgbuf;
		if (!!((errorcode == ((NI32) 0)))) goto LA3;
		msgbuf = 0;
		{
			NI32 LOC7;
			LOC7 = 0;
			LOC7 = Dl_103462(((NI32) 4864), NIM_NIL, errorcode, ((NI32) 0), ((void*) (&msgbuf)), ((NI32) 0), NIM_NIL);
			if (!!((LOC7 == ((NI32) 0)))) goto LA8;
			result = HEX24_79195(msgbuf);
			{
				if (!!((msgbuf == NIM_NIL))) goto LA12;
				Dl_103604(((void*) (msgbuf)));
			}
			LA12: ;
		}
		LA8: ;
	}
	LA3: ;
	return result;
}

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

static N_INLINE(void, rtladdzct_50004)(tcell44733* c) {
	addzct_48417((&gch_46844.Zct), c);
}

static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src) {
	{
		tcell44733* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_48446(src);
		(*c).Refcount += 8;
	}
	LA3: ;
	{
		tcell44733* c;
		if (!!(((*dest) == NIM_NIL))) goto LA7;
		c = usrtocell_48446((*dest));
		{
			(*c).Refcount -= 8;
			if (!((NU64)((*c).Refcount) < (NU64)(8))) goto LA11;
			rtladdzct_50004(c);
		}
		LA11: ;
	}
	LA7: ;
	(*dest) = src;
}

static N_INLINE(void, nimGCunrefNoCycle)(void* p) {
	tcell44733* c;
	c = usrtocell_48446(p);
	{
		(*c).Refcount -= 8;
		if (!((NU64)((*c).Refcount) < (NU64)(8))) goto LA3;
		rtladdzct_50004(c);
	}
	LA3: ;
}

N_NIMCALL(void, raiseoserror_112435)(NI32 errorcode) {
	oserror3233* e;
	e = 0;
	e = (oserror3233*) newObj((&NTI112438), sizeof(oserror3233));
	(*e).Sup.Sup.Sup.m_type = (&NTI3233);
	(*e).Errorcode = errorcode;
	asgnRefNoCycle((void**) (&(*e).Sup.Sup.message), oserrormsg_112020(errorcode));
	{
		NimStringDesc* LOC5;
		if (!(((*e).Sup.Sup.message) && ((*e).Sup.Sup.message)->Sup.len == 0)) goto LA3;
		LOC5 = 0;
		LOC5 = (*e).Sup.Sup.message; (*e).Sup.Sup.message = copyStringRC1(((NimStringDesc*) &TMP143));
		if (LOC5) nimGCunrefNoCycle(LOC5);
	}
	LA3: ;
	raiseException((Exception*)e, "OSError");
}

N_NIMCALL(NI32, oslasterror_112467)(void) {
	NI32 result;
	result = 0;
	result = Dl_103457();
	return result;
}

N_NIMCALL(void, nossplitPath)(NimStringDesc* path, keyvaluepair133008* Result) {
	NI seppos;
	seppos = -1;
	{
		NI i_116531;
		NI HEX3Atmp_116547;
		NI res_116550;
		i_116531 = 0;
		HEX3Atmp_116547 = 0;
		HEX3Atmp_116547 = (NI64)(path->Sup.len - 1);
		res_116550 = HEX3Atmp_116547;
		{
			while (1) {
				if (!(0 <= res_116550)) goto LA3;
				i_116531 = res_116550;
				{
					if (!(((NU8)(path->data[i_116531])) == ((NU8)(92)) || ((NU8)(path->data[i_116531])) == ((NU8)(47)))) goto LA6;
					seppos = i_116531;
					goto LA1;
				}
				LA6: ;
				res_116550 -= 1;
			} LA3: ;
		}
	} LA1: ;
	{
		if (!(0 <= seppos)) goto LA10;
		unsureAsgnRef((void**) (&(*Result).Field0), copyStrLast(path, 0, (NI64)(seppos - 1)));
		unsureAsgnRef((void**) (&(*Result).Field1), copyStr(path, (NI64)(seppos + 1)));
	}
	goto LA8;
	LA10: ;
	{
		unsureAsgnRef((void**) (&(*Result).Field0), copyString(((NimStringDesc*) &TMP139)));
		unsureAsgnRef((void**) (&(*Result).Field1), copyString(path));
	}
	LA8: ;
}

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

N_NIMCALL(NI, searchextpos_116751)(NimStringDesc* s) {
	NI result;
	result = 0;
	result = -1;
	{
		NI i_116766;
		NI HEX3Atmp_116782;
		NI res_116785;
		i_116766 = 0;
		HEX3Atmp_116782 = 0;
		HEX3Atmp_116782 = (NI64)(s->Sup.len - 1);
		res_116785 = HEX3Atmp_116782;
		{
			while (1) {
				if (!(1 <= res_116785)) goto LA3;
				i_116766 = res_116785;
				{
					if (!((NU8)(s->data[i_116766]) == (NU8)(46))) goto LA6;
					result = i_116766;
					goto LA1;
				}
				goto LA4;
				LA6: ;
				{
					if (!(((NU8)(s->data[i_116766])) == ((NU8)(92)) || ((NU8)(s->data[i_116766])) == ((NU8)(47)))) goto LA9;
					goto LA1;
				}
				goto LA4;
				LA9: ;
				LA4: ;
				res_116785 -= 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)), (NI64)((*src).Sup.len + 1));
	(*dest).Sup.len += (*src).Sup.len;
}

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

N_NIMCALL(NimStringDesc*, normext_116741)(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[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_116751(filename);
	{
		NimStringDesc* LOC5;
		NimStringDesc* LOC6;
		if (!(extpos < 0)) goto LA3;
		LOC5 = 0;
		LOC6 = 0;
		LOC6 = normext_116741(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, 0, (NI64)(extpos - 1));
		LOC10 = 0;
		LOC10 = normext_116741(ext);
		LOC8 = rawNewString(LOC9->Sup.len + LOC10->Sup.len + 0);
appendString(LOC8, LOC9);
appendString(LOC8, LOC10);
		result = LOC8;
	}
	LA1: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nosexpandFilename)(NimStringDesc* filename) {
	NimStringDesc* result;
	NI16* unused;
	NI16* res;
	NI32 l;
	NI16* LOC1;
	result = 0;
	unused = 0;
	res = newwidecstring_78824("", 1536);
	LOC1 = 0;
	LOC1 = newwidecstring_79005(filename);
	l = Dl_104210(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_112467();
		raiseoserror_112435(LOC8);
	}
	LA6: ;
	result = HEX24_79012(res, ((NI) (l)));
	return result;
}

N_NIMCALL(void, nossplitFile)(NimStringDesc* path, TY116804* Result) {
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = (path->Sup.len == 0);
		if (LOC3) goto LA4;
		LOC3 = (((NU8)(path->data[(NI64)(path->Sup.len - 1)])) == ((NU8)(92)) || ((NU8)(path->data[(NI64)(path->Sup.len - 1)])) == ((NU8)(47)));
		LA4: ;
		if (!LOC3) goto LA5;
		unsureAsgnRef((void**) (&(*Result).Field0), copyString(path));
		unsureAsgnRef((void**) (&(*Result).Field1), copyString(((NimStringDesc*) &TMP139)));
		unsureAsgnRef((void**) (&(*Result).Field2), copyString(((NimStringDesc*) &TMP139)));
	}
	goto LA1;
	LA5: ;
	{
		NI seppos;
		NI dotpos;
		seppos = -1;
		dotpos = path->Sup.len;
		{
			NI i_116837;
			NI HEX3Atmp_116868;
			NI res_116871;
			i_116837 = 0;
			HEX3Atmp_116868 = 0;
			HEX3Atmp_116868 = (NI64)(path->Sup.len - 1);
			res_116871 = HEX3Atmp_116868;
			{
				while (1) {
					if (!(0 <= res_116871)) goto LA10;
					i_116837 = res_116871;
					{
						if (!((NU8)(path->data[i_116837]) == (NU8)(46))) goto LA13;
						{
							NIM_BOOL LOC17;
							NIM_BOOL LOC18;
							LOC17 = 0;
							LOC18 = 0;
							LOC18 = (dotpos == path->Sup.len);
							if (!(LOC18)) goto LA19;
							LOC18 = (0 < i_116837);
							LA19: ;
							LOC17 = LOC18;
							if (!(LOC17)) goto LA20;
							LOC17 = !((((NU8)(path->data[(NI64)(i_116837 - 1)])) == ((NU8)(92)) || ((NU8)(path->data[(NI64)(i_116837 - 1)])) == ((NU8)(47))));
							LA20: ;
							if (!LOC17) goto LA21;
							dotpos = i_116837;
						}
						LA21: ;
					}
					goto LA11;
					LA13: ;
					{
						if (!(((NU8)(path->data[i_116837])) == ((NU8)(92)) || ((NU8)(path->data[i_116837])) == ((NU8)(47)))) goto LA24;
						seppos = i_116837;
						goto LA8;
					}
					goto LA11;
					LA24: ;
					LA11: ;
					res_116871 -= 1;
				} LA10: ;
			}
		} LA8: ;
		unsureAsgnRef((void**) (&(*Result).Field0), copyStrLast(path, 0, (NI64)(seppos - 1)));
		unsureAsgnRef((void**) (&(*Result).Field1), copyStrLast(path, (NI64)(seppos + 1), (NI64)(dotpos - 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_5801(512);
	buf = ((NI16*) (LOC1));
	len = Dl_103628(0, buf, ((NI32) 256));
	result = HEX24_79012(buf, ((NI) (len)));
	return result;
}

N_NIMCALL(NimStringDesc*, nosgetAppDir)(void) {
	NimStringDesc* result;
	NimStringDesc* LOC1;
	TY116804 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_116566)(NimStringDesc* path) {
	NI result;
	NI q;
	result = 0;
	q = 1;
	{
		if (!(((NU8)(path->data[(NI64)(path->Sup.len - 1)])) == ((NU8)(92)) || ((NU8)(path->data[(NI64)(path->Sup.len - 1)])) == ((NU8)(47)))) goto LA3;
		q = 2;
	}
	LA3: ;
	{
		NI i_116596;
		NI HEX3Atmp_116612;
		NI res_116615;
		i_116596 = 0;
		HEX3Atmp_116612 = 0;
		HEX3Atmp_116612 = (NI64)(path->Sup.len - q);
		res_116615 = HEX3Atmp_116612;
		{
			while (1) {
				if (!(0 <= res_116615)) goto LA7;
				i_116596 = res_116615;
				{
					if (!(((NU8)(path->data[i_116596])) == ((NU8)(92)) || ((NU8)(path->data[i_116596])) == ((NU8)(47)))) goto LA10;
					result = i_116596;
					goto BeforeRet;
				}
				LA10: ;
				res_116615 -= 1;
			} LA7: ;
		}
	}
	result = -1;
	BeforeRet: ;
	return result;
}

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

N_NIMCALL(NimStringDesc*, nosjoinPath)(NimStringDesc* head, NimStringDesc* tail) {
	NimStringDesc* result;
	result = 0;
	{
		if (!(head->Sup.len == 0)) goto LA3;
		result = copyString(tail);
	}
	goto LA1;
	LA3: ;
	{
		if (!(((NU8)(head->data[(NI64)(head->Sup.len - 1)])) == ((NU8)(92)) || ((NU8)(head->data[(NI64)(head->Sup.len - 1)])) == ((NU8)(47)))) goto LA6;
		{
			NimStringDesc* LOC12;
			NimStringDesc* LOC13;
			if (!(((NU8)(tail->data[0])) == ((NU8)(92)) || ((NU8)(tail->data[0])) == ((NU8)(47)))) goto LA10;
			LOC12 = 0;
			LOC13 = 0;
			LOC13 = copyStr(tail, 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[0])) == ((NU8)(92)) || ((NU8)(tail->data[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_116499)(NimStringDesc* head, NimStringDesc* tail) {
	NimStringDesc* result;
	result = 0;
	result = nosjoinPath(head, tail);
	goto BeforeRet;
	BeforeRet: ;
	return result;
}

N_NIMCALL(NI, findfirstfile_113416)(NimStringDesc* a, twin32finddata104019* b) {
	NI result;
	NI16* LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = newwidecstring_79005(a);
	result = Dl_104039(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->Sup.len;
	LOC1 = 0;
	LOC2 = 0;
	LOC2 = (1 < len);
	if (!(LOC2)) goto LA3;
	LOC2 = (((NU8)(path->data[0])) == ((NU8)(47)) || ((NU8)(path->data[0])) == ((NU8)(92)));
	LA3: ;
	LOC1 = LOC2;
	if (LOC1) goto LA4;
	LOC5 = 0;
	LOC6 = 0;
	LOC6 = (2 < len);
	if (!(LOC6)) goto LA7;
	LOC6 = (((NU8)(path->data[0])) >= ((NU8)(65)) && ((NU8)(path->data[0])) <= ((NU8)(90)) || ((NU8)(path->data[0])) >= ((NU8)(97)) && ((NU8)(path->data[0])) <= ((NU8)(122)));
	LA7: ;
	LOC5 = LOC6;
	if (!(LOC5)) goto LA8;
	LOC5 = ((NU8)(path->data[1]) == (NU8)(58));
	LA8: ;
	LOC1 = LOC5;
	LA4: ;
	result = LOC1;
	return result;
}

N_NIMCALL(void, rawcreatedir_122441)(NimStringDesc* dir) {
	NI32 res;
	NI16* LOC1;
	LOC1 = 0;
	LOC1 = newwidecstring_79005(dir);
	res = Dl_103617(LOC1, NIM_NIL);
	{
		NIM_BOOL LOC4;
		NI32 LOC6;
		NI32 LOC9;
		LOC4 = 0;
		LOC4 = (res == ((NI32) 0));
		if (!(LOC4)) goto LA5;
		LOC6 = 0;
		LOC6 = Dl_103457();
		LOC4 = !((LOC6 == ((NI32) 183)));
		LA5: ;
		if (!LOC4) goto LA7;
		LOC9 = 0;
		LOC9 = oslasterror_112467();
		raiseoserror_112435(LOC9);
	}
	LA7: ;
}

N_NIMCALL(void, noscreateDir)(NimStringDesc* dir) {
	NIM_BOOL omitnext;
	omitnext = NIM_FALSE;
	omitnext = nosisAbsolute(dir);
	{
		NI i_123011;
		NI HEX3Atmp_123027;
		NI res_123030;
		i_123011 = 0;
		HEX3Atmp_123027 = 0;
		HEX3Atmp_123027 = (NI64)(dir->Sup.len - 1);
		res_123030 = 1;
		{
			while (1) {
				if (!(res_123030 <= HEX3Atmp_123027)) goto LA3;
				i_123011 = res_123030;
				{
					if (!(((NU8)(dir->data[i_123011])) == ((NU8)(92)) || ((NU8)(dir->data[i_123011])) == ((NU8)(47)))) goto LA6;
					{
						if (!omitnext) goto LA10;
						omitnext = NIM_FALSE;
					}
					goto LA8;
					LA10: ;
					{
						NimStringDesc* LOC13;
						LOC13 = 0;
						LOC13 = copyStrLast(dir, 0, (NI64)(i_123011 - 1));
						rawcreatedir_122441(LOC13);
					}
					LA8: ;
				}
				LA6: ;
				res_123030 += 1;
			} LA3: ;
		}
	}
	rawcreatedir_122441(dir);
}

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

N_NIMCALL(NIM_BOOL, nosexistsFile)(NimStringDesc* filename) {
	NIM_BOOL result;
	NI32 a;
	NI16* LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = newwidecstring_79005(filename);
	a = Dl_104217(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_116751(filename);
	{
		NimStringDesc* LOC5;
		NimStringDesc* LOC6;
		if (!(extpos < 0)) goto LA3;
		LOC5 = 0;
		LOC6 = 0;
		LOC6 = normext_116741(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(TY120608*, nosparseCmdLine)(NimStringDesc* c) {
	TY120608* result;
	NI i;
	NimStringDesc* a;
	result = 0;
	result = (TY120608*) newSeq((&NTI120608), 0);
	i = 0;
	a = copyString(((NimStringDesc*) &TMP139));
	{
		while (1) {
			NIM_BOOL inquote;
			NimStringDesc* LOC49;
			a = setLengthStr(a, 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 += 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 += 1;
							} LA20: ;
						}
						{
							if (!((NU8)(c->data[j]) == (NU8)(34))) goto LA23;
							{
								NI k_124025;
								NI HEX3Atmp_124110;
								NI res_124113;
								k_124025 = 0;
								HEX3Atmp_124110 = 0;
								HEX3Atmp_124110 = (NI64)((NI64)(j - i) / 2);
								res_124113 = 1;
								{
									while (1) {
										if (!(res_124113 <= HEX3Atmp_124110)) goto LA27;
										k_124025 = res_124113;
										a = addChar(a, 92);
										res_124113 += 1;
									} LA27: ;
								}
							}
							{
								if (!(((NI) ((NI64)((NI64)(j - i) % 2))) == 0)) goto LA30;
								i = j;
							}
							goto LA28;
							LA30: ;
							{
								a = addChar(a, 34);
								i = (NI64)(j + 1);
							}
							LA28: ;
						}
						goto LA21;
						LA23: ;
						{
							a = addChar(a, c->data[i]);
							i += 1;
						}
						LA21: ;
					}
					break;
					case 34:
					{
						i += 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 += 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 += 1;
					}
					break;
					default:
					{
						a = addChar(a, c->data[i]);
						i += 1;
					}
					break;
					}
				}
			} LA15: ;
			result = (TY120608*) incrSeq(&(result)->Sup, sizeof(NimStringDesc*));
			LOC49 = 0;
			LOC49 = result->data[result->Sup.len-1]; result->data[result->Sup.len-1] = copyStringRC1(a);
			if (LOC49) nimGCunrefNoCycle(LOC49);
		}
	} LA1: ;
	return result;
}

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

N_NIMCALL(NimStringDesc*, nosparamStr)(NI i) {
	NimStringDesc* result;
	result = 0;
	{
		NI16* LOC5;
		NimStringDesc* LOC6;
		if (!ownargv_125009 == 0) goto LA3;
		LOC5 = 0;
		LOC5 = Dl_104234();
		LOC6 = 0;
		LOC6 = HEX24_79195(LOC5);
		asgnRefNoCycle((void**) (&ownargv_125009), nosparseCmdLine(LOC6));
	}
	LA3: ;
	result = copyString(ownargv_125009->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[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*) &TMP1687));
			result = LOC9;
		}
		goto LA5;
		LA7: ;
		{
			result = copyString(((NimStringDesc*) &TMP1688));
		}
		LA5: ;
		start = 1;
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC12;
		LOC12 = 0;
		LOC12 = ((NU8)(path->data[0]) == (NU8)(46));
		if (!(LOC12)) goto LA13;
		LOC12 = ((NU8)(path->data[1]) == (NU8)(47));
		LA13: ;
		if (!LOC12) goto LA14;
		result = copyString(((NimStringDesc*) &TMP1689));
		start = 2;
	}
	goto LA1;
	LA14: ;
	{
		result = copyString(((NimStringDesc*) &TMP139));
		start = 0;
	}
	LA1: ;
	i = start;
	{
		while (1) {
			if (!(i < path->Sup.len)) 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[(NI64)(i + 1)]) == (NU8)(46));
				LA23: ;
				LOC21 = LOC22;
				if (!(LOC21)) goto LA24;
				LOC21 = ((NU8)(path->data[(NI64)(i + 2)]) == (NU8)(47));
				LA24: ;
				if (!LOC21) goto LA25;
				result = resizeString(result, 3);
appendString(result, ((NimStringDesc*) &TMP1690));
				i += 3;
			}
			goto LA19;
			LA25: ;
			{
				if (!((NU8)(path->data[i]) == (NU8)(47))) goto LA28;
				result = addChar(result, 92);
				i += 1;
			}
			goto LA19;
			LA28: ;
			{
				result = addChar(result, path->data[i]);
				i += 1;
			}
			LA19: ;
		} LA18: ;
	}
	return result;
}

N_NIMCALL(void, getenvvarsc_120805)(void) {
	{
		NI16* env;
		NI16* e;
		NI32 LOC17;
		if (!!(envcomputed_120607)) goto LA3;
		if (environment_120609) nimGCunrefNoCycle(environment_120609);
		environment_120609 = (TY120608*) newSeqRC1((&NTI120608), 0);
		env = Dl_104229();
		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_79195(e);
				environment_120609 = (TY120608*) incrSeq(&(environment_120609)->Sup, sizeof(NimStringDesc*));
				LOC12 = 0;
				LOC12 = environment_120609->data[environment_120609->Sup.len-1]; environment_120609->data[environment_120609->Sup.len-1] = copyStringRC1(LOC11);
				if (LOC12) nimGCunrefNoCycle(LOC12);
				e = ((NI16*) ((NI64)(((NI) (eend)) + 2)));
				{
					if (!(((NI) (eend[(1)- 0])) == 0)) goto LA15;
					goto LA9;
				}
				LA15: ;
			}
		} LA9: ;
		LOC17 = 0;
		LOC17 = Dl_104231(env);
		envcomputed_120607 = NIM_TRUE;
	}
	LA3: ;
	BeforeRet: ;
}

N_NIMCALL(NI, findenvvar_121204)(NimStringDesc* key) {
	NI result;
	NimStringDesc* temp;
	NimStringDesc* LOC1;
	result = 0;
	getenvvarsc_120805();
	LOC1 = 0;
	LOC1 = rawNewString(key->Sup.len + 1);
appendString(LOC1, key);
appendChar(LOC1, 61);
	temp = LOC1;
	{
		NI i_121219;
		NI HEX3Atmp_121221;
		NI res_121224;
		i_121219 = 0;
		HEX3Atmp_121221 = 0;
		HEX3Atmp_121221 = (environment_120609->Sup.len-1);
		res_121224 = 0;
		{
			while (1) {
				if (!(res_121224 <= HEX3Atmp_121221)) goto LA4;
				i_121219 = res_121224;
				{
					NIM_BOOL LOC7;
					LOC7 = 0;
					LOC7 = nsuStartsWith(environment_120609->data[i_121219], temp);
					if (!LOC7) goto LA8;
					result = i_121219;
					goto BeforeRet;
				}
				LA8: ;
				res_121224 += 1;
			} LA4: ;
		}
	}
	result = -1;
	goto BeforeRet;
	BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, getenv_121241)(NimStringDesc* key) {
	NimStringDesc* result;
	NI i;
	result = 0;
	i = findenvvar_121204(key);
	{
		NI LOC5;
		if (!(0 <= i)) goto LA3;
		LOC5 = 0;
		LOC5 = nsuFindChar(environment_120609->data[i], 61, 0);
		result = copyStr(environment_120609->data[i], (NI64)(LOC5 + 1));
		goto BeforeRet;
	}
	goto LA1;
	LA3: ;
	{
		NCSTRING env;
		env = getenv(key->data);
		{
			if (!(env == NIM_NIL)) goto LA9;
			result = copyString(((NimStringDesc*) &TMP139));
			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_121241(((NimStringDesc*) &TMP1694));
	LOC1 = rawNewString(LOC2->Sup.len + 1);
appendString(LOC1, LOC2);
appendString(LOC1, ((NimStringDesc*) &TMP1688));
	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_4517(patha, pathb);
	}
	goto LA1;
	LA3: ;
	{
		result = nsuCmpIgnoreCase(patha, pathb);
	}
	LA1: ;
	return result;
}

N_NIMCALL(void, putenv_121266)(NimStringDesc* key, NimStringDesc* val) {
	NI indx;
	NI16* k;
	NI16* v;
	indx = findenvvar_121204(key);
	{
		NimStringDesc* LOC5;
		if (!(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_120609->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_120609 = (TY120608*) incrSeq(&(environment_120609)->Sup, sizeof(NimStringDesc*));
		LOC8 = 0;
		LOC8 = environment_120609->data[environment_120609->Sup.len-1]; environment_120609->data[environment_120609->Sup.len-1] = copyStringRC1(LOC7);
		if (LOC8) nimGCunrefNoCycle(LOC8);
		indx = (environment_120609->Sup.len-1);
	}
	LA1: ;
	k = newwidecstring_79005(key);
	v = newwidecstring_79005(val);
	{
		NI32 LOC11;
		NI32 LOC14;
		LOC11 = 0;
		LOC11 = Dl_103624(k, v);
		if (!(LOC11 == ((NI32) 0))) goto LA12;
		LOC14 = 0;
		LOC14 = oslasterror_112467();
		raiseoserror_112435(LOC14);
	}
	LA12: ;
}

N_NIMCALL(NimStringDesc*, nosgetCurrentDir)(void) {
	NimStringDesc* result;
	NI16* res;
	NI32 l;
	result = 0;
	res = newwidecstring_78824("", 512);
	l = Dl_103610(((NI32) 512), res);
	{
		NI32 LOC5;
		if (!(l == ((NI32) 0))) goto LA3;
		LOC5 = 0;
		LOC5 = oslasterror_112467();
		raiseoserror_112435(LOC5);
	}
	LA3: ;
	result = HEX24_79012(res, ((NI) (l)));
	return result;
}

N_NIMCALL(NimStringDesc*, nosgetConfigDir)(void) {
	NimStringDesc* result;
	NimStringDesc* LOC1;
	NimStringDesc* LOC2;
	result = 0;
	LOC1 = 0;
	LOC2 = 0;
	LOC2 = getenv_121241(((NimStringDesc*) &TMP1915));
	LOC1 = rawNewString(LOC2->Sup.len + 1);
appendString(LOC1, LOC2);
appendString(LOC1, ((NimStringDesc*) &TMP1688));
	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_116566(path);
	result = (LOC1 < 0);
	return result;
}

N_NIMCALL(NIM_BOOL, existsenv_121256)(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_121204(key);
		result = (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_79005(dir);
	a = Dl_104217(LOC1);
	{
		if (!!((a == ((NI32) -1)))) goto LA4;
		result = !(((NI32)(a & ((NI32) 16)) == ((NI32) 0)));
	}
	LA4: ;
	return result;
}

N_NIMCALL(time_t, nosgetLastModificationTime)(NimStringDesc* file) {
	time_t result;
	twin32finddata104019 f;
	NI h;
	NI64 LOC6;
	result = 0;
	memset((void*)(&f), 0, sizeof(f));
	h = findfirstfile_113416(file, (&f));
	{
		NI32 LOC5;
		if (!(h == -1)) goto LA3;
		LOC5 = 0;
		LOC5 = oslasterror_112467();
		raiseoserror_112435(LOC5);
	}
	LA3: ;
	LOC6 = 0;
	LOC6 = rdfiletime_104404(f.Ftlastwritetime);
	result = wintimetounixtime_107691(LOC6);
	Dl_104204(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_104431(((NI32) (milsecs)));
}

static N_INLINE(NimStringDesc*, HEX5BHEX5D_85772)(NimStringDesc* s, slice85779 x) {
	NimStringDesc* result;
	NI LOC1;
	NI LOC7;
	result = 0;
	LOC1 = 0;
	{
		if (!(0 <= x.A)) goto LA4;
		LOC1 = x.A;
	}
	goto LA2;
	LA4: ;
	{
		LOC1 = (NI64)(s->Sup.len + x.A);
	}
	LA2: ;
	LOC7 = 0;
	{
		if (!(0 <= x.B)) goto LA10;
		LOC7 = x.B;
	}
	goto LA8;
	LA10: ;
	{
		LOC7 = (NI64)(s->Sup.len + x.B);
	}
	LA8: ;
	result = copyStrLast(s, LOC1, LOC7);
	return result;
}

static N_INLINE(slice85779, HEX2EHEX2E_94499)(NI a_94503, NI b_94505) {
	slice85779 result;
	memset((void*)(&result), 0, sizeof(result));
	result.A = a_94503;
	result.B = b_94505;
	return result;
}

N_NIMCALL(NimStringDesc*, expandtilde_126847)(NimStringDesc* path) {
	NimStringDesc* result;
	result = 0;
	{
		NIM_BOOL LOC3;
		NIM_BOOL LOC4;
		NIM_BOOL LOC7;
		NimStringDesc* LOC11;
		slice85779 LOC12;
		NimStringDesc* LOC13;
		LOC3 = 0;
		LOC4 = 0;
		LOC4 = (1 < path->Sup.len);
		if (!(LOC4)) goto LA5;
		LOC4 = ((NU8)(path->data[0]) == (NU8)(126));
		LA5: ;
		LOC3 = LOC4;
		if (!(LOC3)) goto LA6;
		LOC7 = 0;
		LOC7 = ((NU8)(path->data[1]) == (NU8)(47));
		if (LOC7) goto LA8;
		LOC7 = ((NU8)(path->data[1]) == (NU8)(92));
		LA8: ;
		LOC3 = LOC7;
		LA6: ;
		if (!LOC3) goto LA9;
		LOC11 = 0;
		LOC11 = nosgetHomeDir();
		LOC12 = HEX2EHEX2E_94499(2, (NI64)(path->Sup.len - 1));
		LOC13 = 0;
		LOC13 = HEX5BHEX5D_85772(path, LOC12);
		result = HEX2F_116499(LOC11, LOC13);
	}
	goto LA1;
	LA9: ;
	{
		result = copyString(path);
	}
	LA1: ;
	return result;
}
NIM_EXTERNC N_NOINLINE(void, stdlib_osInit)(void) {
}

NIM_EXTERNC N_NOINLINE(void, stdlib_osDatInit)(void) {
NTI120608.size = sizeof(TY120608*);
NTI120608.kind = 24;
NTI120608.base = (&NTI149);
NTI120608.flags = 2;
NTI120608.marker = TMP54;
}

