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

#include "nimbase.h"
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <setjmp.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/wait.h>
#include <stdlib.h>
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Processobj150404 Processobj150404;
typedef struct Stringtableobj140209 Stringtableobj140209;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Streamobj144418 Streamobj144418;
typedef struct TY125202 TY125202;
typedef struct Cell47504 Cell47504;
typedef struct Cellseq47520 Cellseq47520;
typedef struct Gcheap49818 Gcheap49818;
typedef struct Gcstack49816 Gcstack49816;
typedef struct Cellset47516 Cellset47516;
typedef struct Pagedesc47512 Pagedesc47512;
typedef struct Memregion29687 Memregion29687;
typedef struct Smallchunk29639 Smallchunk29639;
typedef struct Llchunk29681 Llchunk29681;
typedef struct Bigchunk29641 Bigchunk29641;
typedef struct Intset29614 Intset29614;
typedef struct Trunk29610 Trunk29610;
typedef struct Avlnode29685 Avlnode29685;
typedef struct Gcstat49814 Gcstat49814;
typedef struct Exception Exception;
typedef struct TSafePoint TSafePoint;
typedef struct Keyvaluepairseq140207 Keyvaluepairseq140207;
typedef struct Keyvaluepair140205 Keyvaluepair140205;
typedef struct Startprocessdata151703 Startprocessdata151703;
typedef struct Filestreamobj145248 Filestreamobj145248;
typedef struct TY151001 TY151001;
typedef struct Basechunk29637 Basechunk29637;
typedef struct Freecell29629 Freecell29629;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef NU8 TY203404[32];
typedef int TY151824[2];
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  TNimObject  {
TNimType* m_type;
};
struct  Processobj150404  {
  TNimObject Sup;
int inhandle;
int outhandle;
int errhandle;
Streamobj144418* instream;
Streamobj144418* outstream;
Streamobj144418* errstream;
pid_t id;
int exitcode;
NU8 options;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
typedef NimStringDesc* TY185156[3];
struct  Cell47504  {
NI refcount;
TNimType* typ;
};
struct  Cellseq47520  {
NI len;
NI cap;
Cell47504** d;
};
struct  Cellset47516  {
NI counter;
NI max;
Pagedesc47512* head;
Pagedesc47512** data;
};
typedef Smallchunk29639* TY29702[512];
typedef Trunk29610* Trunkbuckets29612[256];
struct  Intset29614  {
Trunkbuckets29612 data;
};
struct  Memregion29687  {
NI minlargeobj;
NI maxlargeobj;
TY29702 freesmallchunks;
Llchunk29681* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk29641* freechunkslist;
Intset29614 chunkstarts;
Avlnode29685* root;
Avlnode29685* deleted;
Avlnode29685* last;
Avlnode29685* freeavlnodes;
};
struct  Gcstat49814  {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct  Gcheap49818  {
Gcstack49816* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq47520 zct;
Cellseq47520 decstack;
Cellset47516 cycleroots;
Cellseq47520 tempstack;
NI recgclock;
Memregion29687 region;
Gcstat49814 stat;
};
typedef NimStringDesc* TY184752[1];
struct  Exception  {
  TNimObject Sup;
Exception* parent;
NCSTRING name;
NimStringDesc* message;
NimStringDesc* trace;
};
typedef struct {
N_NIMCALL_PTR(NIM_BOOL, ClPrc) (Exception* e, void* ClEnv);
void* ClEnv;
} TY17811;
struct  TSafePoint  {
TSafePoint* prev;
NI status;
jmp_buf context;
NIM_BOOL hasRaiseAction;
TY17811 raiseAction;
};
struct  Stringtableobj140209  {
  TNimObject Sup;
NI counter;
Keyvaluepairseq140207* data;
NU8 mode;
};
struct Keyvaluepair140205 {
NimStringDesc* Field0;
NimStringDesc* Field1;
};
struct  Startprocessdata151703  {
NCSTRING syscommand;
NCSTRING* sysargs;
NCSTRING* sysenv;
NCSTRING workingdir;
TY151824 pstdin;
TY151824 pstdout;
TY151824 pstderr;
TY151824 perrorpipe;
NIM_BOOL optionpousepath;
NIM_BOOL optionpoparentstreams;
NIM_BOOL optionpostderrtostdout;
};
typedef NimStringDesc* TY185169[2];
typedef struct {
N_NIMCALL_PTR(void, ClPrc) (NI idx, void* ClEnv);
void* ClEnv;
} TY196578;
typedef struct {
N_NIMCALL_PTR(void, ClPrc) (NI idx, Processobj150404* p, void* ClEnv);
void* ClEnv;
} TY196584;
typedef N_CLOSURE_PTR(void, TMP4616) (NI idx);
typedef NimStringDesc* TY239694[1];
typedef N_CLOSURE_PTR(void, TMP4618) (NI idx, Processobj150404* p);
typedef N_CLOSURE_PTR(void, TMP4619) (NI idx);
typedef N_CLOSURE_PTR(void, TMP4620) (NI idx, Processobj150404* p);
typedef N_CLOSURE_PTR(void, TMP4621) (NI idx);
typedef N_CLOSURE_PTR(void, TMP4622) (NI idx, Processobj150404* p);
typedef N_NIMCALL_PTR(void, TY144419) (Streamobj144418* s);
typedef N_NIMCALL_PTR(NIM_BOOL, TY144423) (Streamobj144418* s);
typedef N_NIMCALL_PTR(void, TY144427) (Streamobj144418* s, NI pos);
typedef N_NIMCALL_PTR(NI, TY144432) (Streamobj144418* s);
typedef N_NIMCALL_PTR(NI, TY144436) (Streamobj144418* s, void* buffer, NI buflen);
typedef N_NIMCALL_PTR(NI, TY144442) (Streamobj144418* s, void* buffer, NI buflen);
typedef N_NIMCALL_PTR(void, TY144448) (Streamobj144418* s, void* buffer, NI buflen);
typedef N_NIMCALL_PTR(void, TY144454) (Streamobj144418* s);
struct  Streamobj144418  {
  TNimObject Sup;
TY144419 closeimpl;
TY144423 atendimpl;
TY144427 setpositionimpl;
TY144432 getpositionimpl;
TY144436 readdataimpl;
TY144442 peekdataimpl;
TY144448 writedataimpl;
TY144454 flushimpl;
};
struct  Gcstack49816  {
Gcstack49816* prev;
Gcstack49816* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY29618[16];
struct  Pagedesc47512  {
Pagedesc47512* next;
NI key;
TY29618 bits;
};
struct  Basechunk29637  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk29639  {
  Basechunk29637 Sup;
Smallchunk29639* next;
Smallchunk29639* prev;
Freecell29629* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk29681  {
NI size;
NI acc;
Llchunk29681* next;
};
struct  Bigchunk29641  {
  Basechunk29637 Sup;
Bigchunk29641* next;
Bigchunk29641* prev;
NI align;
NF data;
};
struct  Trunk29610  {
Trunk29610* next;
NI key;
TY29618 bits;
};
typedef Avlnode29685* TY29692[2];
struct  Avlnode29685  {
TY29692 link;
NI key;
NI upperbound;
NI level;
};
struct  Filestreamobj145248  {
  Streamobj144418 Sup;
FILE* f;
};
struct  Freecell29629  {
Freecell29629* next;
NI zerofield;
};
struct TY125202 {
  TGenericSeq Sup;
  NimStringDesc* data[SEQ_DECL_SIZE];
};
struct TY151001 {
  TGenericSeq Sup;
  Processobj150404* data[SEQ_DECL_SIZE];
};
struct Keyvaluepairseq140207 {
  TGenericSeq Sup;
  Keyvaluepair140205 data[SEQ_DECL_SIZE];
};
N_NIMCALL(NimStringDesc*, nospquoteShellPosix)(NimStringDesc* s);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(NIM_BOOL, allcharsinset_100325)(NimStringDesc* s, TY203404 theset);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
N_NIMCALL(NimStringDesc*, nsuReplaceStr)(NimStringDesc* s, NimStringDesc* sub, NimStringDesc* by);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP3051)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
N_NOINLINE(void, raiseoserror_120803)(NI32 errorcode, NimStringDesc* additionalinfo);
N_NIMCALL(NI32, oslasterror_120819)(void);
N_NIMCALL(void*, newSeq)(TNimType* typ, NI len);
N_NIMCALL(NimStringDesc*, copyStringRC1)(NimStringDesc* src);
static N_INLINE(void, nimGCunrefNoCycle)(void* p);
static N_INLINE(Cell47504*, usrtocell_51440)(void* usr);
static N_INLINE(void, rtladdzct_53001)(Cell47504* c);
N_NOINLINE(void, addzct_51417)(Cellseq47520* s, Cell47504* c);
N_NIMCALL(TGenericSeq*, incrSeqV2)(TGenericSeq* seq, NI elemsize);
N_NIMCALL(NCSTRING*, alloccstringarray_16201)(NimStringDesc** a, NI aLen0);
static N_INLINE(void, pushSafePoint)(TSafePoint* s);
N_NIMCALL(NCSTRING*, envtocstringarray_151636)(void);
N_NIMCALL(void, getenvvarsc_125402)(void);
N_NIMCALL(NI, nsuFindChar)(NimStringDesc* s, NIM_CHAR sub, NI start);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI start_79810, NI last);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI first, NI last);
N_NIMCALL(NimStringDesc*, copyStr)(NimStringDesc* s, NI start);
N_NIMCALL(NimStringDesc*, copyStr)(NimStringDesc* s, NI first);
N_NOCONV(void*, alloc0_7417)(NI size);
N_NOCONV(void*, alloc_7401)(NI size);
N_NIMCALL(NCSTRING*, envtocstringarray_151603)(Stringtableobj140209* t);
N_NIMCALL(NI, nstlen)(Stringtableobj140209* t);
N_NIMCALL(pid_t, startprocessauxfork_151801)(Startprocessdata151703* data);
N_CDECL(void, startprocessafterfork_151804)(Startprocessdata151703* data);
N_NIMCALL(void, startprocessfail_152616)(Startprocessdata151703* data);
N_NOINLINE(void, nosraiseOSError)(NimStringDesc* msg);
N_NIMCALL(NimStringDesc*, nsuFormatOpenArray)(NimStringDesc* formatstr, NimStringDesc** a, NI aLen0);
N_NIMCALL(NimStringDesc*, cstrToNimstr)(NCSTRING str);
static N_INLINE(void, popSafePoint)(void);
N_NIMCALL(void, reraiseException)(void);
N_NIMCALL(NimStringDesc*, nsuJoinSep)(NimStringDesc** a, NI aLen0, NimStringDesc* sep);
N_NIMCALL(void, dealloccstringarray_16429)(NCSTRING* a);
N_NIMCALL(void, createstream_153426)(Streamobj144418** stream, int* handle, NU8 filemode);
N_NIMCALL(NIM_BOOL, open_15411)(FILE** f, int filehandle, NU8 mode);
N_NIMCALL(Filestreamobj145248*, newfilestream_145300)(FILE* f);
N_NIMCALL(void, unsureAsgnRef)(void** dest, void* src);
N_NIMCALL(NI, ncpicountProcessors)(void);
N_NIMCALL(void, TMP4614)(void* p, NI op);
N_NIMCALL(Processobj150404*, nospstartProcess)(NimStringDesc* command, NimStringDesc* workingdir, NimStringDesc** args, NI argsLen0, Stringtableobj140209* env, NU8 options);
static N_INLINE(void, asgnRef)(void** dest, void* src);
static N_INLINE(void, incref_53819)(Cell47504* c);
static N_INLINE(NIM_BOOL, canbecycleroot_51458)(Cell47504* c);
static N_INLINE(void, rtladdcycleroot_52220)(Cell47504* c);
N_NOINLINE(void, incl_48247)(Cellset47516* s, Cell47504* cell);
static N_INLINE(void, decref_53401)(Cell47504* c);
N_NIMCALL(void, nossleep)(NI milsecs);
N_NIMCALL(NIM_BOOL, nosprunning)(Processobj150404* p);
N_NIMCALL(NI, nospwaitForExit)(Processobj150404* p, NI timeout);
N_NIMCALL(void, nospclose)(Processobj150404* p);
N_NIMCALL(void, close_144470)(Streamobj144418* s);
STRING_LITERAL(TMP1910, "\'\'", 2);
static NIM_CONST TY203404 TMP1911 = {
0x00, 0x00, 0x00, 0x00, 0x20, 0xE8, 0xFF, 0x27,
0xFF, 0xFF, 0xFF, 0x87, 0xFE, 0xFF, 0xFF, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
;
STRING_LITERAL(TMP1912, "\'", 1);
STRING_LITERAL(TMP1913, "\'\"\'\"\'", 5);
STRING_LITERAL(TMP3052, "", 0);
STRING_LITERAL(TMP3053, "/bin/sh", 7);
STRING_LITERAL(TMP3054, "-c", 2);
STRING_LITERAL(TMP3056, "=", 1);
STRING_LITERAL(TMP3059, "Could not find command: \'$1\'. OS error: $2", 42);
STRING_LITERAL(TMP3060, " ", 1);
static NIM_CONST TY196578 TMP4615 = {NIM_NIL,NIM_NIL};
static NIM_CONST TY196584 TMP4617 = {NIM_NIL,NIM_NIL};
extern TNimType NTI3608; /* RootObj */
TNimType NTI150404; /* ProcessObj */
extern TNimType NTI15008; /* FileHandle */
extern TNimType NTI144416; /* Stream */
extern TNimType NTI110274; /* Pid */
extern TNimType NTI7208; /* cint */
TNimType NTI150402; /* ProcessOption */
TNimType NTI150628; /* set[ProcessOption] */
TNimType NTI150406; /* Process */
extern TNimType NTI125202; /* seq[string] */
extern Gcheap49818 gch_49859;
extern TSafePoint* exchandler_19437;
extern TY125202* environment_125203;
TNimType NTI151001; /* seq[Process] */

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;
}

N_NIMCALL(NimStringDesc*, nospquoteShellPosix)(NimStringDesc* s) {
	NimStringDesc* result;
	NIM_BOOL safe;
{	result = 0;
	{
		if (!((s ? s->Sup.len : 0) == ((NI) 0))) goto LA3;
		result = copyString(((NimStringDesc*) &TMP1910));
		goto BeforeRet;
	}
	LA3: ;
	safe = allcharsinset_100325(s, TMP1911);
	{
		if (!safe) goto LA7;
		result = copyString(s);
		goto BeforeRet;
	}
	goto LA5;
	LA7: ;
	{
		NimStringDesc* LOC10;
		NimStringDesc* LOC11;
		LOC10 = 0;
		LOC11 = 0;
		LOC11 = nsuReplaceStr(s, ((NimStringDesc*) &TMP1912), ((NimStringDesc*) &TMP1913));
		LOC10 = rawNewString(LOC11->Sup.len + 2);
appendString(LOC10, ((NimStringDesc*) &TMP1912));
appendString(LOC10, LOC11);
appendString(LOC10, ((NimStringDesc*) &TMP1912));
		result = LOC10;
		goto BeforeRet;
	}
	LA5: ;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nospquoteShell)(NimStringDesc* s) {
	NimStringDesc* result;
{	result = 0;
	result = nospquoteShellPosix(s);
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}
N_NIMCALL(void, TMP3051)(void* p, NI op) {
	Processobj150404* a;
	a = (Processobj150404*)p;
	nimGCvisit((void*)(*a).instream, op);
	nimGCvisit((void*)(*a).outstream, op);
	nimGCvisit((void*)(*a).errstream, op);
}

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

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

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

static N_INLINE(void, pushSafePoint)(TSafePoint* s) {
	(*s).hasRaiseAction = NIM_FALSE;
	(*s).prev = exchandler_19437;
	exchandler_19437 = s;
}

N_NIMCALL(NCSTRING*, envtocstringarray_151636)(void) {
	NCSTRING* result;
	NI counter;
	void* LOC5;
	NI i;
	result = 0;
	counter = ((NI) 0);
	{
		NimStringDesc* key_151640;
		NimStringDesc* val_151641;
		key_151640 = 0;
		val_151641 = 0;
		getenvvarsc_125402();
		{
			NI i_151670;
			NI HEX3Atmp_151672;
			NI res_151674;
			i_151670 = 0;
			HEX3Atmp_151672 = 0;
			HEX3Atmp_151672 = (environment_125203 ? (environment_125203->Sup.len-1) : -1);
			res_151674 = ((NI) 0);
			{
				while (1) {
					NI p_151678;
					if (!(res_151674 <= HEX3Atmp_151672)) goto LA4;
					i_151670 = res_151674;
					p_151678 = nsuFindChar(environment_125203->data[i_151670], 61, ((NI) 0));
					key_151640 = copyStrLast(environment_125203->data[i_151670], ((NI) 0), (NI)(p_151678 - ((NI) 1)));
					val_151641 = copyStr(environment_125203->data[i_151670], (NI)(p_151678 + ((NI) 1)));
					counter += ((NI) 1);
					res_151674 += ((NI) 1);
				} LA4: ;
			}
		}
	}
	LOC5 = 0;
	LOC5 = alloc0_7417(((NI) ((NI)((NI)(counter + ((NI) 1)) * ((NI) 4)))));
	result = ((NCSTRING*) (LOC5));
	i = ((NI) 0);
	{
		NimStringDesc* key_151653;
		NimStringDesc* val_151654;
		key_151653 = 0;
		val_151654 = 0;
		getenvvarsc_125402();
		{
			NI i_151691;
			NI HEX3Atmp_151693;
			NI res_151695;
			i_151691 = 0;
			HEX3Atmp_151693 = 0;
			HEX3Atmp_151693 = (environment_125203 ? (environment_125203->Sup.len-1) : -1);
			res_151695 = ((NI) 0);
			{
				while (1) {
					NI p_151699;
					NimStringDesc* x;
					NimStringDesc* LOC10;
					void* LOC11;
					if (!(res_151695 <= HEX3Atmp_151693)) goto LA9;
					i_151691 = res_151695;
					p_151699 = nsuFindChar(environment_125203->data[i_151691], 61, ((NI) 0));
					key_151653 = copyStrLast(environment_125203->data[i_151691], ((NI) 0), (NI)(p_151699 - ((NI) 1)));
					val_151654 = copyStr(environment_125203->data[i_151691], (NI)(p_151699 + ((NI) 1)));
					LOC10 = 0;
					LOC10 = rawNewString(key_151653->Sup.len + val_151654->Sup.len + 1);
appendString(LOC10, key_151653);
appendString(LOC10, ((NimStringDesc*) &TMP3056));
appendString(LOC10, val_151654);
					x = LOC10;
					LOC11 = 0;
					LOC11 = alloc_7401(((NI) ((NI)((x ? x->Sup.len : 0) + ((NI) 1)))));
					result[(i)- 0] = ((NCSTRING) (LOC11));
					memcpy(((void*) (result[(i)- 0])), ((void*) ((&x->data[((NI) 0)]))), ((NI) ((NI)((x ? x->Sup.len : 0) + ((NI) 1)))));
					i += ((NI) 1);
					res_151695 += ((NI) 1);
				} LA9: ;
			}
		}
	}
	return result;
}

N_NIMCALL(NCSTRING*, envtocstringarray_151603)(Stringtableobj140209* t) {
	NCSTRING* result;
	NI LOC1;
	void* LOC2;
	NI i;
	result = 0;
	LOC1 = 0;
	LOC1 = nstlen(t);
	LOC2 = 0;
	LOC2 = alloc0_7417(((NI) ((NI)((NI)(LOC1 + ((NI) 1)) * ((NI) 4)))));
	result = ((NCSTRING*) (LOC2));
	i = ((NI) 0);
	{
		NimStringDesc* key_151609;
		NimStringDesc* val_151610;
		key_151609 = 0;
		val_151610 = 0;
		{
			NI h_151629;
			NI HEX3Atmp_151631;
			NI res_151633;
			h_151629 = 0;
			HEX3Atmp_151631 = 0;
			HEX3Atmp_151631 = ((*t).data ? ((*t).data->Sup.len-1) : -1);
			res_151633 = ((NI) 0);
			{
				while (1) {
					if (!(res_151633 <= HEX3Atmp_151631)) goto LA6;
					h_151629 = res_151633;
					{
						NimStringDesc* x;
						NimStringDesc* LOC11;
						void* LOC12;
						if (!!((*t).data->data[h_151629].Field0 == 0)) goto LA9;
						key_151609 = (*t).data->data[h_151629].Field0;
						val_151610 = (*t).data->data[h_151629].Field1;
						LOC11 = 0;
						LOC11 = rawNewString(key_151609->Sup.len + val_151610->Sup.len + 1);
appendString(LOC11, key_151609);
appendString(LOC11, ((NimStringDesc*) &TMP3056));
appendString(LOC11, val_151610);
						x = LOC11;
						LOC12 = 0;
						LOC12 = alloc_7401(((NI) ((NI)((x ? x->Sup.len : 0) + ((NI) 1)))));
						result[(i)- 0] = ((NCSTRING) (LOC12));
						memcpy(((void*) (result[(i)- 0])), ((void*) ((&x->data[((NI) 0)]))), ((NI) ((NI)((x ? x->Sup.len : 0) + ((NI) 1)))));
						i += ((NI) 1);
					}
					LA9: ;
					res_151633 += ((NI) 1);
				} LA6: ;
			}
		}
	}
	return result;
}

N_NIMCALL(void, startprocessfail_152616)(Startprocessdata151703* data) {
	int error;
	NI LOC1;
	error = errno;
	LOC1 = 0;
	LOC1 = write((*data).perrorpipe[(((NI) 1))- 0], ((void*) ((&error))), ((NI) 4));
	_exit(((NI) 1));
}

N_CDECL(void, startprocessafterfork_151804)(Startprocessdata151703* data) {
	int LOC42;
	int LOC43;
	{
		int LOC5;
		int LOC11;
		int LOC17;
		if (!!((*data).optionpoparentstreams)) goto LA3;
		LOC5 = 0;
		LOC5 = close((*data).pstdin[(((NI) 1))- 0]);
		{
			int LOC8;
			LOC8 = 0;
			LOC8 = dup2((*data).pstdin[(((NI) 0))- 0], ((int) 0));
			if (!(LOC8 < ((NI32) 0))) goto LA9;
			startprocessfail_152616(data);
		}
		LA9: ;
		LOC11 = 0;
		LOC11 = close((*data).pstdout[(((NI) 0))- 0]);
		{
			int LOC14;
			LOC14 = 0;
			LOC14 = dup2((*data).pstdout[(((NI) 1))- 0], ((int) 1));
			if (!(LOC14 < ((NI32) 0))) goto LA15;
			startprocessfail_152616(data);
		}
		LA15: ;
		LOC17 = 0;
		LOC17 = close((*data).pstderr[(((NI) 0))- 0]);
		{
			if (!(*data).optionpostderrtostdout) goto LA20;
			{
				int LOC24;
				LOC24 = 0;
				LOC24 = dup2((*data).pstdout[(((NI) 1))- 0], ((int) 2));
				if (!(LOC24 < ((NI32) 0))) goto LA25;
				startprocessfail_152616(data);
			}
			LA25: ;
		}
		goto LA18;
		LA20: ;
		{
			{
				int LOC30;
				LOC30 = 0;
				LOC30 = dup2((*data).pstderr[(((NI) 1))- 0], ((int) 2));
				if (!(LOC30 < ((NI32) 0))) goto LA31;
				startprocessfail_152616(data);
			}
			LA31: ;
		}
		LA18: ;
	}
	LA3: ;
	{
		if (!(((NI) 0) < ((*data).workingdir ? strlen((*data).workingdir) : 0))) goto LA35;
		{
			int LOC39;
			LOC39 = 0;
			LOC39 = chdir((*data).workingdir);
			if (!(LOC39 < ((NI32) 0))) goto LA40;
			startprocessfail_152616(data);
		}
		LA40: ;
	}
	LA35: ;
	LOC42 = 0;
	LOC42 = close((*data).perrorpipe[(((NI) 0))- 0]);
	LOC43 = 0;
	LOC43 = fcntl((*data).perrorpipe[(((NI) 1))- 0], F_SETFD, FD_CLOEXEC);
	{
		int LOC48;
		if (!(*data).optionpousepath) goto LA46;
		LOC48 = 0;
		LOC48 = execvpe((*data).syscommand, (*data).sysargs, (*data).sysenv);
	}
	goto LA44;
	LA46: ;
	{
		int LOC50;
		LOC50 = 0;
		LOC50 = execve((*data).syscommand, (*data).sysargs, (*data).sysenv);
	}
	LA44: ;
	startprocessfail_152616(data);
}

static N_INLINE(void, popSafePoint)(void) {
	exchandler_19437 = (*exchandler_19437).prev;
}

N_NIMCALL(pid_t, startprocessauxfork_151801)(Startprocessdata151703* data) {
	pid_t volatile result;
	TSafePoint TMP3058;
{	result = 0;
	{
		int LOC3;
		NI32 LOC6;
		LOC3 = 0;
		LOC3 = pipe((*data).perrorpipe);
		if (!!((LOC3 == ((NI32) 0)))) goto LA4;
		LOC6 = 0;
		LOC6 = oslasterror_120819();
		raiseoserror_120803(LOC6, ((NimStringDesc*) &TMP3052));
	}
	LA4: ;
	pushSafePoint(&TMP3058);
	TMP3058.status = setjmp(TMP3058.context);
	if (TMP3058.status == 0) {
		pid_t volatile pid;
		Startprocessdata151703 datacopy;
		int LOC12;
		int error;
		NI sizeread;
		int LOC25;
		pid = 0;
		datacopy = (*data);
		pid = fork();
		{
			if (!(pid == ((NI) 0))) goto LA10;
			startprocessafterfork_151804((&datacopy));
			_exit(((NI) 1));
		}
		LA10: ;
		LOC12 = 0;
		LOC12 = close((*data).perrorpipe[(((NI) 1))- 0]);
		{
			NI32 LOC17;
			if (!(pid < ((NI) 0))) goto LA15;
			LOC17 = 0;
			LOC17 = oslasterror_120819();
			raiseoserror_120803(LOC17, ((NimStringDesc*) &TMP3052));
		}
		LA15: ;
		error = 0;
		sizeread = read((*data).perrorpipe[(((NI) 0))- 0], ((void*) ((&error))), ((NI) 4));
		{
			TY185169 LOC22;
			NCSTRING LOC23;
			NimStringDesc* LOC24;
			if (!(sizeread == ((NI) 4))) goto LA20;
			memset((void*)LOC22, 0, sizeof(LOC22));
			LOC22[0] = cstrToNimstr((*data).syscommand);
			LOC23 = 0;
			LOC23 = strerror(error);
			LOC22[1] = cstrToNimstr(LOC23);
			LOC24 = 0;
			LOC24 = nsuFormatOpenArray(((NimStringDesc*) &TMP3059), LOC22, 2);
			nosraiseOSError(LOC24);
		}
		LA20: ;
		result = pid;
		popSafePoint();
		LOC25 = 0;
		LOC25 = close((*data).perrorpipe[(((NI) 0))- 0]);
		goto BeforeRet;
		popSafePoint();
	}
	else {
		popSafePoint();
	}
	{
		int LOC28;
		LOC28 = 0;
		LOC28 = close((*data).perrorpipe[(((NI) 0))- 0]);
	}
	if (TMP3058.status != 0) reraiseException();
	}BeforeRet: ;
	return result;
}

N_NIMCALL(Processobj150404*, nospstartProcess)(NimStringDesc* command, NimStringDesc* workingdir, NimStringDesc** args, NI argsLen0, Stringtableobj140209* env, NU8 options) {
	Processobj150404* result;
	TY151824 pstdin;
	TY151824 pstdout;
	TY151824 pstderr;
	NimStringDesc* syscommand;
	TY125202* sysargsraw;
	pid_t volatile pid;
	NCSTRING* sysargs;
	TSafePoint TMP3055;
	result = 0;
	memset((void*)pstdin, 0, sizeof(pstdin));
	memset((void*)pstdout, 0, sizeof(pstdout));
	memset((void*)pstderr, 0, sizeof(pstderr));
	result = (Processobj150404*) newObj((&NTI150406), sizeof(Processobj150404));
	(*result).Sup.m_type = (&NTI150404);
	(*result).options = options;
	(*result).exitcode = ((int) -3);
	{
		if (!!(((options &(1U<<((NU)(((NU8) 4))&7U)))!=0))) goto LA3;
		{
			NIM_BOOL LOC7;
			NIM_BOOL LOC8;
			int LOC9;
			int LOC11;
			int LOC13;
			NI32 LOC16;
			LOC7 = 0;
			LOC8 = 0;
			LOC9 = 0;
			LOC9 = pipe(pstdin);
			LOC8 = !((LOC9 == ((NI32) 0)));
			if (LOC8) goto LA10;
			LOC11 = 0;
			LOC11 = pipe(pstdout);
			LOC8 = !((LOC11 == ((NI32) 0)));
			LA10: ;
			LOC7 = LOC8;
			if (LOC7) goto LA12;
			LOC13 = 0;
			LOC13 = pipe(pstderr);
			LOC7 = !((LOC13 == ((NI32) 0)));
			LA12: ;
			if (!LOC7) goto LA14;
			LOC16 = 0;
			LOC16 = oslasterror_120819();
			raiseoserror_120803(LOC16, ((NimStringDesc*) &TMP3052));
		}
		LA14: ;
	}
	LA3: ;
	syscommand = 0;
	sysargsraw = 0;
	{
		TY185156 LOC21;
		NimStringDesc* LOC22;
		NimStringDesc* LOC23;
		NimStringDesc* LOC24;
		if (!((options &(1U<<((NU)(((NU8) 2))&7U)))!=0)) goto LA19;
		syscommand = copyString(((NimStringDesc*) &TMP3053));
		sysargsraw = (TY125202*) newSeq((&NTI125202), 3);
		memset((void*)LOC21, 0, sizeof(LOC21));
		LOC21[0] = copyString(syscommand);
		LOC21[1] = copyString(((NimStringDesc*) &TMP3054));
		LOC21[2] = copyString(command);
		LOC22 = 0;
		LOC22 = sysargsraw->data[0]; sysargsraw->data[0] = copyStringRC1(LOC21[0]);
		if (LOC22) nimGCunrefNoCycle(LOC22);
		LOC23 = 0;
		LOC23 = sysargsraw->data[1]; sysargsraw->data[1] = copyStringRC1(LOC21[1]);
		if (LOC23) nimGCunrefNoCycle(LOC23);
		LOC24 = 0;
		LOC24 = sysargsraw->data[2]; sysargsraw->data[2] = copyStringRC1(LOC21[2]);
		if (LOC24) nimGCunrefNoCycle(LOC24);
	}
	goto LA17;
	LA19: ;
	{
		TY184752 LOC26;
		NimStringDesc* LOC27;
		syscommand = copyString(command);
		sysargsraw = (TY125202*) newSeq((&NTI125202), 1);
		memset((void*)LOC26, 0, sizeof(LOC26));
		LOC26[0] = copyString(command);
		LOC27 = 0;
		LOC27 = sysargsraw->data[0]; sysargsraw->data[0] = copyStringRC1(LOC26[0]);
		if (LOC27) nimGCunrefNoCycle(LOC27);
		{
			NimStringDesc* arg_152021;
			NI i_152279;
			arg_152021 = 0;
			i_152279 = ((NI) 0);
			{
				while (1) {
					NimStringDesc* LOC31;
					if (!(i_152279 < argsLen0)) goto LA30;
					arg_152021 = args[i_152279];
					sysargsraw = (TY125202*) incrSeqV2(&(sysargsraw)->Sup, sizeof(NimStringDesc*));
					LOC31 = 0;
					LOC31 = sysargsraw->data[sysargsraw->Sup.len]; sysargsraw->data[sysargsraw->Sup.len] = copyStringRC1(arg_152021);
					if (LOC31) nimGCunrefNoCycle(LOC31);
					++sysargsraw->Sup.len;
					i_152279 += ((NI) 1);
				} LA30: ;
			}
		}
	}
	LA17: ;
	pid = 0;
	sysargs = alloccstringarray_16201(sysargsraw->data, sysargsraw->Sup.len);
	pushSafePoint(&TMP3055);
	TMP3055.status = setjmp(TMP3055.context);
	if (TMP3055.status == 0) {
		NCSTRING* sysenv;
		TSafePoint TMP3057;
		{
			if (!(env == NIM_NIL)) goto LA35;
			sysenv = envtocstringarray_151636();
		}
		goto LA33;
		LA35: ;
		{
			sysenv = envtocstringarray_151603(env);
		}
		LA33: ;
		pushSafePoint(&TMP3057);
		TMP3057.status = setjmp(TMP3057.context);
		if (TMP3057.status == 0) {
			Startprocessdata151703 data;
			memset((void*)(&data), 0, sizeof(data));
			data.syscommand = syscommand->data;
			data.sysargs = sysargs;
			data.sysenv = sysenv;
			memcpy((void*)data.pstdin, (NIM_CONST void*)pstdin, sizeof(TY151824));
			memcpy((void*)data.pstdout, (NIM_CONST void*)pstdout, sizeof(TY151824));
			memcpy((void*)data.pstderr, (NIM_CONST void*)pstderr, sizeof(TY151824));
			data.optionpoparentstreams = ((options &(1U<<((NU)(((NU8) 4))&7U)))!=0);
			data.optionpousepath = ((options &(1U<<((NU)(((NU8) 1))&7U)))!=0);
			data.optionpostderrtostdout = ((options &(1U<<((NU)(((NU8) 3))&7U)))!=0);
			data.workingdir = workingdir->data;
			pid = startprocessauxfork_151801((&data));
			{
				NimStringDesc* LOC43;
				if (!((options &(1U<<((NU)(((NU8) 0))&7U)))!=0)) goto LA41;
				LOC43 = 0;
				LOC43 = nsuJoinSep(args, argsLen0, ((NimStringDesc*) &TMP3060));
				printf("%s%s%s\012", command? (command)->data:"nil", ((NimStringDesc*) &TMP3060)? (((NimStringDesc*) &TMP3060))->data:"nil", LOC43? (LOC43)->data:"nil");
				fflush(stdout);
			}
			LA41: ;
			(*result).id = pid;
			{
				if (!((options &(1U<<((NU)(((NU8) 4))&7U)))!=0)) goto LA46;
				(*result).inhandle = ((int) 0);
				(*result).outhandle = ((int) 1);
				{
					if (!((options &(1U<<((NU)(((NU8) 3))&7U)))!=0)) goto LA50;
					(*result).errhandle = (*result).outhandle;
				}
				goto LA48;
				LA50: ;
				{
					(*result).errhandle = ((int) 2);
				}
				LA48: ;
			}
			goto LA44;
			LA46: ;
			{
				int LOC60;
				int LOC61;
				int LOC62;
				(*result).inhandle = pstdin[(((NI) 1))- 0];
				(*result).outhandle = pstdout[(((NI) 0))- 0];
				{
					int LOC58;
					if (!((options &(1U<<((NU)(((NU8) 3))&7U)))!=0)) goto LA56;
					(*result).errhandle = (*result).outhandle;
					LOC58 = 0;
					LOC58 = close(pstderr[(((NI) 0))- 0]);
				}
				goto LA54;
				LA56: ;
				{
					(*result).errhandle = pstderr[(((NI) 0))- 0];
				}
				LA54: ;
				LOC60 = 0;
				LOC60 = close(pstderr[(((NI) 1))- 0]);
				LOC61 = 0;
				LOC61 = close(pstdin[(((NI) 0))- 0]);
				LOC62 = 0;
				LOC62 = close(pstdout[(((NI) 1))- 0]);
			}
			LA44: ;
			popSafePoint();
		}
		else {
			popSafePoint();
		}
		{
			dealloccstringarray_16429(sysenv);
		}
		if (TMP3057.status != 0) reraiseException();
		popSafePoint();
	}
	else {
		popSafePoint();
	}
	{
		dealloccstringarray_16429(sysargs);
	}
	if (TMP3055.status != 0) reraiseException();
	return result;
}

N_NIMCALL(void, createstream_153426)(Streamobj144418** stream, int* handle, NU8 filemode) {
	FILE* f;
	Filestreamobj145248* LOC7;
	f = 0;
	{
		NIM_BOOL LOC3;
		NI32 LOC6;
		LOC3 = 0;
		LOC3 = open_15411(&f, (*handle), filemode);
		if (!!(LOC3)) goto LA4;
		LOC6 = 0;
		LOC6 = oslasterror_120819();
		raiseoserror_120803(LOC6, ((NimStringDesc*) &TMP3052));
	}
	LA4: ;
	LOC7 = 0;
	LOC7 = newfilestream_145300(f);
	unsureAsgnRef((void**) (&(*stream)), &LOC7->Sup);
}

N_NIMCALL(Streamobj144418*, nospinputStream)(Processobj150404* p) {
	Streamobj144418* result;
{	result = 0;
	{
		if (!((*p).instream == NIM_NIL)) goto LA3;
		createstream_153426(&(*p).instream, (&(*p).inhandle), ((NU8) 1));
	}
	LA3: ;
	result = (*p).instream;
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(Streamobj144418*, nospoutputStream)(Processobj150404* p) {
	Streamobj144418* result;
{	result = 0;
	{
		if (!((*p).outstream == NIM_NIL)) goto LA3;
		createstream_153426(&(*p).outstream, (&(*p).outhandle), ((NU8) 0));
	}
	LA3: ;
	result = (*p).outstream;
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NI, nospwaitForExit)(Processobj150404* p, NI timeout) {
	NI result;
{	result = 0;
	{
		if (!!(((*p).exitcode == ((NI32) -3)))) goto LA3;
		result = ((NI) ((*p).exitcode));
		goto BeforeRet;
	}
	LA3: ;
	{
		pid_t LOC7;
		NI32 LOC10;
		LOC7 = 0;
		LOC7 = waitpid((*p).id, (&(*p).exitcode), ((int) 0));
		if (!(LOC7 < ((NI) 0))) goto LA8;
		(*p).exitcode = ((int) -3);
		LOC10 = 0;
		LOC10 = oslasterror_120819();
		raiseoserror_120803(LOC10, ((NimStringDesc*) &TMP3052));
	}
	LA8: ;
	result = (NI)((NU32)(((NI) ((*p).exitcode))) >> (NU32)(((NI) 8)));
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NI, nospexecCmd)(NimStringDesc* command) {
	NI result;
	int LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = system(command->data);
	result = ((NI) ((NI32)((NU32)(LOC1) >> (NU32)(((NI32) 8)))));
	return result;
}

N_NIMCALL(NI, peekexitcode_150677)(Processobj150404* p) {
	NI result;
	pid_t ret;
	NIM_BOOL b;
{	result = 0;
	{
		if (!!(((*p).exitcode == ((NI32) -3)))) goto LA3;
		result = ((NI) ((*p).exitcode));
		goto BeforeRet;
	}
	LA3: ;
	ret = waitpid((*p).id, (&(*p).exitcode), WNOHANG);
	b = (ret == (*p).id);
	{
		if (!b) goto LA7;
		result = ((NI) -1);
	}
	LA7: ;
	{
		NIM_BOOL LOC11;
		LOC11 = 0;
		LOC11 = WIFEXITED((*p).exitcode);
		if (!!(LOC11)) goto LA12;
		result = ((NI) -1);
	}
	goto LA9;
	LA12: ;
	{
		result = (NI)((NU32)(((NI) ((*p).exitcode))) >> (NU32)(((NI) 8)));
	}
	LA9: ;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NI, nospcountProcessors)(void) {
	NI result;
	result = 0;
	result = ncpicountProcessors();
	return result;
}
N_NIMCALL(void, TMP4614)(void* p, NI op) {
	TY151001* a;
	NI LOC1;
	a = (TY151001*)p;
	LOC1 = 0;
	for (LOC1 = 0; LOC1 < a->Sup.len; LOC1++) {
	nimGCvisit((void*)a->data[LOC1], op);
	}
}

static N_INLINE(NIM_BOOL, canbecycleroot_51458)(Cell47504* c) {
	NIM_BOOL result;
	result = 0;
	result = !((((*(*c).typ).flags &(1U<<((NU)(((NU8) 1))&7U)))!=0));
	return result;
}

static N_INLINE(void, rtladdcycleroot_52220)(Cell47504* c) {
	{
		if (!!((((NI) ((NI)((*c).refcount & ((NI) 3)))) == ((NI) 3)))) goto LA3;
		(*c).refcount = (NI)((NI)((*c).refcount & ((NI) -4)) | ((NI) 3));
		incl_48247((&gch_49859.cycleroots), c);
	}
	LA3: ;
}

static N_INLINE(void, incref_53819)(Cell47504* c) {
	(*c).refcount = (NI)((NU32)((*c).refcount) + (NU32)(((NI) 8)));
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = canbecycleroot_51458(c);
		if (!LOC3) goto LA4;
		rtladdcycleroot_52220(c);
	}
	LA4: ;
}

static N_INLINE(void, decref_53401)(Cell47504* c) {
	{
		(*c).refcount -= ((NI) 8);
		if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA3;
		rtladdzct_53001(c);
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC6;
		LOC6 = 0;
		LOC6 = canbecycleroot_51458(c);
		if (!LOC6) goto LA7;
		rtladdcycleroot_52220(c);
	}
	goto LA1;
	LA7: ;
	LA1: ;
}

static N_INLINE(void, asgnRef)(void** dest, void* src) {
	{
		Cell47504* LOC5;
		if (!!((src == NIM_NIL))) goto LA3;
		LOC5 = 0;
		LOC5 = usrtocell_51440(src);
		incref_53819(LOC5);
	}
	LA3: ;
	{
		Cell47504* LOC10;
		if (!!(((*dest) == NIM_NIL))) goto LA8;
		LOC10 = 0;
		LOC10 = usrtocell_51440((*dest));
		decref_53401(LOC10);
	}
	LA8: ;
	(*dest) = src;
}

N_NIMCALL(NIM_BOOL, nosprunning)(Processobj150404* p) {
	NIM_BOOL result;
	NI ret;
{	result = 0;
	ret = 0;
	ret = waitpid((*p).id, (&(*p).exitcode), WNOHANG);
	{
		if (!(ret == ((NI) 0))) goto LA3;
		result = NIM_TRUE;
		goto BeforeRet;
	}
	LA3: ;
	result = (ret == (*p).id);
	}BeforeRet: ;
	return result;
}

N_NIMCALL(void, nospclose)(Processobj150404* p) {
	{
		if (!!(((*p).instream == NIM_NIL))) goto LA3;
		close_144470((*p).instream);
	}
	LA3: ;
	{
		if (!!(((*p).outstream == NIM_NIL))) goto LA7;
		close_144470((*p).outstream);
	}
	LA7: ;
	{
		if (!!(((*p).errstream == NIM_NIL))) goto LA11;
		close_144470((*p).errstream);
	}
	LA11: ;
	{
		int LOC17;
		int LOC18;
		int LOC19;
		if (!!((((*p).options &(1U<<((NU)(((NU8) 4))&7U)))!=0))) goto LA15;
		LOC17 = 0;
		LOC17 = close((*p).inhandle);
		LOC18 = 0;
		LOC18 = close((*p).outhandle);
		LOC19 = 0;
		LOC19 = close((*p).errhandle);
	}
	LA15: ;
}

N_NIMCALL(NI, nospexecProcesses)(NimStringDesc** cmds, NI cmdsLen0, NU8 options_150709, NI n, TY196578 beforerunevent, TY196584 afterrunevent) {
	NI result;
	NU8 options;
	result = 0;
	options = (options_150709 & ~ 16);
	{
		TY151001* q;
		NI m;
		NI i;
		if (!(((NI) 1) < n)) goto LA3;
		q = 0;
		q = (TY151001*) newSeq((&NTI151001), ((NI) (n)));
		m = ((n <= cmdsLen0) ? n : cmdsLen0);
		{
			NI i_151034;
			NI HEX3Atmp_151352;
			NI res_151355;
			i_151034 = 0;
			HEX3Atmp_151352 = 0;
			HEX3Atmp_151352 = (NI)(m - ((NI) 1));
			res_151355 = ((NI) 0);
			{
				while (1) {
					TY239694 LOC12;
					if (!(res_151355 <= HEX3Atmp_151352)) goto LA7;
					i_151034 = res_151355;
					{
						if (!!((beforerunevent.ClPrc == TMP4615.ClPrc && beforerunevent.ClEnv == TMP4615.ClEnv))) goto LA10;
						beforerunevent.ClEnv? beforerunevent.ClPrc(i_151034, beforerunevent.ClEnv):((TMP4616)(beforerunevent.ClPrc))(i_151034);
					}
					LA10: ;
					memset((void*)LOC12, 0, sizeof(LOC12));
					asgnRef((void**) (&q->data[i_151034]), nospstartProcess(cmds[i_151034], ((NimStringDesc*) &TMP3052), LOC12, 0, NIM_NIL, (options | 4)));
					res_151355 += ((NI) 1);
				} LA7: ;
			}
		}
		i = m;
		{
			while (1) {
				if (!(i <= (cmdsLen0-1))) goto LA14;
				nossleep(((NI) 50));
				{
					NI r_151212;
					NI HEX3Atmp_151361;
					NI res_151364;
					r_151212 = 0;
					HEX3Atmp_151361 = 0;
					HEX3Atmp_151361 = (NI)(n - ((NI) 1));
					res_151364 = ((NI) 0);
					{
						while (1) {
							if (!(res_151364 <= HEX3Atmp_151361)) goto LA17;
							r_151212 = res_151364;
							{
								NIM_BOOL LOC20;
								NI LOC23;
								TY239694 LOC36;
								LOC20 = 0;
								LOC20 = nosprunning(q->data[r_151212]);
								if (!!(LOC20)) goto LA21;
								LOC23 = 0;
								LOC23 = nospwaitForExit(q->data[r_151212], ((NI) -1));
								result = ((LOC23 >= result) ? LOC23 : result);
								{
									if (!!((afterrunevent.ClPrc == TMP4617.ClPrc && afterrunevent.ClEnv == TMP4617.ClEnv))) goto LA26;
									afterrunevent.ClEnv? afterrunevent.ClPrc(r_151212, q->data[r_151212], afterrunevent.ClEnv):((TMP4618)(afterrunevent.ClPrc))(r_151212, q->data[r_151212]);
								}
								LA26: ;
								{
									if (!!((q->data[r_151212] == NIM_NIL))) goto LA30;
									nospclose(q->data[r_151212]);
								}
								LA30: ;
								{
									if (!!((beforerunevent.ClPrc == TMP4615.ClPrc && beforerunevent.ClEnv == TMP4615.ClEnv))) goto LA34;
									beforerunevent.ClEnv? beforerunevent.ClPrc(i, beforerunevent.ClEnv):((TMP4619)(beforerunevent.ClPrc))(i);
								}
								LA34: ;
								memset((void*)LOC36, 0, sizeof(LOC36));
								asgnRef((void**) (&q->data[r_151212]), nospstartProcess(cmds[i], ((NimStringDesc*) &TMP3052), LOC36, 0, NIM_NIL, (options | 4)));
								i += ((NI) 1);
								{
									if (!((cmdsLen0-1) < i)) goto LA39;
									goto LA15;
								}
								LA39: ;
							}
							LA21: ;
							res_151364 += ((NI) 1);
						} LA17: ;
					}
				} LA15: ;
			} LA14: ;
		}
		{
			NI j_151278;
			NI HEX3Atmp_151369;
			NI res_151372;
			j_151278 = 0;
			HEX3Atmp_151369 = 0;
			HEX3Atmp_151369 = (NI)(m - ((NI) 1));
			res_151372 = ((NI) 0);
			{
				while (1) {
					NI LOC44;
					if (!(res_151372 <= HEX3Atmp_151369)) goto LA43;
					j_151278 = res_151372;
					LOC44 = 0;
					LOC44 = nospwaitForExit(q->data[j_151278], ((NI) -1));
					result = ((LOC44 >= result) ? LOC44 : result);
					{
						if (!!((afterrunevent.ClPrc == TMP4617.ClPrc && afterrunevent.ClEnv == TMP4617.ClEnv))) goto LA47;
						afterrunevent.ClEnv? afterrunevent.ClPrc(j_151278, q->data[j_151278], afterrunevent.ClEnv):((TMP4620)(afterrunevent.ClPrc))(j_151278, q->data[j_151278]);
					}
					LA47: ;
					{
						if (!!((q->data[j_151278] == NIM_NIL))) goto LA51;
						nospclose(q->data[j_151278]);
					}
					LA51: ;
					res_151372 += ((NI) 1);
				} LA43: ;
			}
		}
	}
	goto LA1;
	LA3: ;
	{
		{
			NI i_151313;
			NI HEX3Atmp_151377;
			NI res_151380;
			i_151313 = 0;
			HEX3Atmp_151377 = 0;
			HEX3Atmp_151377 = (cmdsLen0-1);
			res_151380 = ((NI) 0);
			{
				while (1) {
					Processobj150404* p;
					TY239694 LOC61;
					NI LOC62;
					if (!(res_151380 <= HEX3Atmp_151377)) goto LA56;
					i_151313 = res_151380;
					{
						if (!!((beforerunevent.ClPrc == TMP4615.ClPrc && beforerunevent.ClEnv == TMP4615.ClEnv))) goto LA59;
						beforerunevent.ClEnv? beforerunevent.ClPrc(i_151313, beforerunevent.ClEnv):((TMP4621)(beforerunevent.ClPrc))(i_151313);
					}
					LA59: ;
					memset((void*)LOC61, 0, sizeof(LOC61));
					p = nospstartProcess(cmds[i_151313], ((NimStringDesc*) &TMP3052), LOC61, 0, NIM_NIL, (options | 4));
					LOC62 = 0;
					LOC62 = nospwaitForExit(p, ((NI) -1));
					result = ((LOC62 >= result) ? LOC62 : result);
					{
						if (!!((afterrunevent.ClPrc == TMP4617.ClPrc && afterrunevent.ClEnv == TMP4617.ClEnv))) goto LA65;
						afterrunevent.ClEnv? afterrunevent.ClPrc(i_151313, p, afterrunevent.ClEnv):((TMP4622)(afterrunevent.ClPrc))(i_151313, p);
					}
					LA65: ;
					nospclose(p);
					res_151380 += ((NI) 1);
				} LA56: ;
			}
		}
	}
	LA1: ;
	return result;
}
NIM_EXTERNC N_NOINLINE(void, stdlib_osprocInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, stdlib_osprocDatInit000)(void) {
static TNimNode* TMP3047[9];
static TNimNode* TMP3048[7];
NI TMP3050;
static char* NIM_CONST TMP3049[7] = {
"poEchoCmd", 
"poUsePath", 
"poEvalCommand", 
"poStdErrToStdOut", 
"poParentStreams", 
"poInteractive", 
"poDemon"};
static TNimNode TMP31[19];
NTI150404.size = sizeof(Processobj150404);
NTI150404.kind = 17;
NTI150404.base = (&NTI3608);
TMP3047[0] = &TMP31[1];
TMP31[1].kind = 1;
TMP31[1].offset = offsetof(Processobj150404, inhandle);
TMP31[1].typ = (&NTI15008);
TMP31[1].name = "inHandle";
TMP3047[1] = &TMP31[2];
TMP31[2].kind = 1;
TMP31[2].offset = offsetof(Processobj150404, outhandle);
TMP31[2].typ = (&NTI15008);
TMP31[2].name = "outHandle";
TMP3047[2] = &TMP31[3];
TMP31[3].kind = 1;
TMP31[3].offset = offsetof(Processobj150404, errhandle);
TMP31[3].typ = (&NTI15008);
TMP31[3].name = "errHandle";
TMP3047[3] = &TMP31[4];
TMP31[4].kind = 1;
TMP31[4].offset = offsetof(Processobj150404, instream);
TMP31[4].typ = (&NTI144416);
TMP31[4].name = "inStream";
TMP3047[4] = &TMP31[5];
TMP31[5].kind = 1;
TMP31[5].offset = offsetof(Processobj150404, outstream);
TMP31[5].typ = (&NTI144416);
TMP31[5].name = "outStream";
TMP3047[5] = &TMP31[6];
TMP31[6].kind = 1;
TMP31[6].offset = offsetof(Processobj150404, errstream);
TMP31[6].typ = (&NTI144416);
TMP31[6].name = "errStream";
TMP3047[6] = &TMP31[7];
TMP31[7].kind = 1;
TMP31[7].offset = offsetof(Processobj150404, id);
TMP31[7].typ = (&NTI110274);
TMP31[7].name = "id";
TMP3047[7] = &TMP31[8];
TMP31[8].kind = 1;
TMP31[8].offset = offsetof(Processobj150404, exitcode);
TMP31[8].typ = (&NTI7208);
TMP31[8].name = "exitCode";
TMP3047[8] = &TMP31[9];
NTI150402.size = sizeof(NU8);
NTI150402.kind = 14;
NTI150402.base = 0;
NTI150402.flags = 3;
for (TMP3050 = 0; TMP3050 < 7; TMP3050++) {
TMP31[TMP3050+10].kind = 1;
TMP31[TMP3050+10].offset = TMP3050;
TMP31[TMP3050+10].name = TMP3049[TMP3050];
TMP3048[TMP3050] = &TMP31[TMP3050+10];
}
TMP31[17].len = 7; TMP31[17].kind = 2; TMP31[17].sons = &TMP3048[0];
NTI150402.node = &TMP31[17];
NTI150628.size = sizeof(NU8);
NTI150628.kind = 19;
NTI150628.base = (&NTI150402);
NTI150628.flags = 3;
TMP31[18].len = 0; TMP31[18].kind = 0;
NTI150628.node = &TMP31[18];
TMP31[9].kind = 1;
TMP31[9].offset = offsetof(Processobj150404, options);
TMP31[9].typ = (&NTI150628);
TMP31[9].name = "options";
TMP31[0].len = 9; TMP31[0].kind = 2; TMP31[0].sons = &TMP3047[0];
NTI150404.node = &TMP31[0];
NTI150406.size = sizeof(Processobj150404*);
NTI150406.kind = 22;
NTI150406.base = (&NTI150404);
NTI150406.marker = TMP3051;
NTI151001.size = sizeof(TY151001*);
NTI151001.kind = 24;
NTI151001.base = (&NTI150406);
NTI151001.marker = TMP4614;
}

