/* Generated by Nim Compiler v0.12.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 Processobj154404 Processobj154404;
typedef struct Stringtableobj144212 Stringtableobj144212;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Streamobj148427 Streamobj148427;
typedef struct TY129408 TY129408;
typedef struct Cell48947 Cell48947;
typedef struct Cellseq48963 Cellseq48963;
typedef struct Gcheap51018 Gcheap51018;
typedef struct Gcstack51016 Gcstack51016;
typedef struct Cellset48959 Cellset48959;
typedef struct Pagedesc48955 Pagedesc48955;
typedef struct Memregion30890 Memregion30890;
typedef struct Smallchunk30842 Smallchunk30842;
typedef struct Llchunk30884 Llchunk30884;
typedef struct Bigchunk30844 Bigchunk30844;
typedef struct Intset30817 Intset30817;
typedef struct Trunk30813 Trunk30813;
typedef struct Avlnode30888 Avlnode30888;
typedef struct Gcstat51014 Gcstat51014;
typedef struct Exception Exception;
typedef struct TSafePoint TSafePoint;
typedef struct Keyvaluepairseq144210 Keyvaluepairseq144210;
typedef struct Keyvaluepair144208 Keyvaluepair144208;
typedef struct Startprocessdata155948 Startprocessdata155948;
typedef struct Filestreamobj149667 Filestreamobj149667;
typedef struct TY155201 TY155201;
typedef struct Basechunk30840 Basechunk30840;
typedef struct Freecell30832 Freecell30832;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef NU8 TY211407[32];
typedef int TY156024[2];
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  TNimObject  {
TNimType* m_type;
};
struct  Processobj154404  {
  TNimObject Sup;
int inhandle;
int outhandle;
int errhandle;
Streamobj148427* instream;
Streamobj148427* outstream;
Streamobj148427* errstream;
pid_t id;
int exitcode;
NU8 options;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
typedef NimStringDesc* TY191293[3];
struct  Cell48947  {
NI refcount;
TNimType* typ;
};
struct  Cellseq48963  {
NI len;
NI cap;
Cell48947** d;
};
struct  Cellset48959  {
NI counter;
NI max;
Pagedesc48955* head;
Pagedesc48955** data;
};
typedef Smallchunk30842* TY30905[512];
typedef Trunk30813* Trunkbuckets30815[256];
struct  Intset30817  {
Trunkbuckets30815 data;
};
struct  Memregion30890  {
NI minlargeobj;
NI maxlargeobj;
TY30905 freesmallchunks;
Llchunk30884* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk30844* freechunkslist;
Intset30817 chunkstarts;
Avlnode30888* root;
Avlnode30888* deleted;
Avlnode30888* last;
Avlnode30888* 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;
Cellseq48963 zct;
Cellseq48963 decstack;
Cellset48959 cycleroots;
Cellseq48963 tempstack;
NI recgclock;
Memregion30890 region;
Gcstat51014 stat;
};
typedef NimStringDesc* TY190421[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;
} TY19211;
struct  TSafePoint  {
TSafePoint* prev;
NI status;
jmp_buf context;
NIM_BOOL hasRaiseAction;
TY19211 raiseAction;
};
struct  Stringtableobj144212  {
  TNimObject Sup;
NI counter;
Keyvaluepairseq144210* data;
NU8 mode;
};
struct Keyvaluepair144208 {
NimStringDesc* Field0;
NimStringDesc* Field1;
};
struct  Startprocessdata155948  {
NCSTRING syscommand;
NCSTRING* sysargs;
NCSTRING* sysenv;
NCSTRING workingdir;
TY156024 pstdin;
TY156024 pstdout;
TY156024 pstderr;
TY156024 perrorpipe;
NIM_BOOL optionpousepath;
NIM_BOOL optionpoparentstreams;
NIM_BOOL optionpostderrtostdout;
};
typedef NimStringDesc* TY191306[2];
typedef struct {
N_NIMCALL_PTR(void, ClPrc) (NI idx, void* ClEnv);
void* ClEnv;
} TY202876;
typedef struct {
N_NIMCALL_PTR(void, ClPrc) (NI idx, Processobj154404* p, void* ClEnv);
void* ClEnv;
} TY202882;
typedef N_CLOSURE_PTR(void, TMP4598) (NI idx);
typedef NimStringDesc* TY251724[1];
typedef N_CLOSURE_PTR(void, TMP4600) (NI idx, Processobj154404* p);
typedef N_CLOSURE_PTR(void, TMP4601) (NI idx);
typedef N_CLOSURE_PTR(void, TMP4602) (NI idx, Processobj154404* p);
typedef N_CLOSURE_PTR(void, TMP4603) (NI idx);
typedef N_CLOSURE_PTR(void, TMP4604) (NI idx, Processobj154404* p);
typedef N_NIMCALL_PTR(void, TY148428) (Streamobj148427* s);
typedef N_NIMCALL_PTR(NIM_BOOL, TY148432) (Streamobj148427* s);
typedef N_NIMCALL_PTR(void, TY148436) (Streamobj148427* s, NI pos);
typedef N_NIMCALL_PTR(NI, TY148441) (Streamobj148427* s);
typedef N_NIMCALL_PTR(NI, TY148445) (Streamobj148427* s, void* buffer, NI buflen);
typedef N_NIMCALL_PTR(NI, TY148451) (Streamobj148427* s, void* buffer, NI buflen);
typedef N_NIMCALL_PTR(void, TY148457) (Streamobj148427* s, void* buffer, NI buflen);
typedef N_NIMCALL_PTR(void, TY148463) (Streamobj148427* s);
struct  Streamobj148427  {
  TNimObject Sup;
TY148428 closeimpl;
TY148432 atendimpl;
TY148436 setpositionimpl;
TY148441 getpositionimpl;
TY148445 readdataimpl;
TY148451 peekdataimpl;
TY148457 writedataimpl;
TY148463 flushimpl;
};
struct  Gcstack51016  {
Gcstack51016* prev;
Gcstack51016* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY30821[16];
struct  Pagedesc48955  {
Pagedesc48955* next;
NI key;
TY30821 bits;
};
struct  Basechunk30840  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk30842  {
  Basechunk30840 Sup;
Smallchunk30842* next;
Smallchunk30842* prev;
Freecell30832* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk30884  {
NI size;
NI acc;
Llchunk30884* next;
};
struct  Bigchunk30844  {
  Basechunk30840 Sup;
Bigchunk30844* next;
Bigchunk30844* prev;
NI align;
NF data;
};
struct  Trunk30813  {
Trunk30813* next;
NI key;
TY30821 bits;
};
typedef Avlnode30888* TY30895[2];
struct  Avlnode30888  {
TY30895 link;
NI key;
NI upperbound;
NI level;
};
struct  Filestreamobj149667  {
  Streamobj148427 Sup;
FILE* f;
};
struct  Freecell30832  {
Freecell30832* next;
NI zerofield;
};
struct TY129408 {
  TGenericSeq Sup;
  NimStringDesc* data[SEQ_DECL_SIZE];
};
struct TY155201 {
  TGenericSeq Sup;
  Processobj154404* data[SEQ_DECL_SIZE];
};
struct Keyvaluepairseq144210 {
  TGenericSeq Sup;
  Keyvaluepair144208 data[SEQ_DECL_SIZE];
};
N_NIMCALL(NimStringDesc*, nospquoteShellPosix)(NimStringDesc* s);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(NIM_BOOL, allcharsinset_103130)(NimStringDesc* s, TY211407 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, TMP3008)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
N_NOINLINE(void, raiseoserror_125009)(NI32 errorcode, NimStringDesc* additionalinfo);
N_NIMCALL(NI32, oslasterror_125034)(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(Cell48947*, usrtocell_52646)(void* usr);
static N_INLINE(void, rtladdzct_54204)(Cell48947* c);
N_NOINLINE(void, addzct_52617)(Cellseq48963* s, Cell48947* c);
N_NIMCALL(TGenericSeq*, incrSeqV2)(TGenericSeq* seq, NI elemsize);
N_NIMCALL(NCSTRING*, alloccstringarray_17601)(NimStringDesc** a, NI aLen0);
static N_INLINE(void, pushSafePoint)(TSafePoint* s);
N_NIMCALL(NCSTRING*, envtocstringarray_155854)(void);
N_NIMCALL(void, getenvvarsc_129602)(void);
N_NIMCALL(NI, nsuFindChar)(NimStringDesc* s, NIM_CHAR sub, NI start);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI start_81016, 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_8417)(NI size);
N_NOCONV(void*, alloc_8401)(NI size);
N_NIMCALL(NCSTRING*, envtocstringarray_155806)(Stringtableobj144212* t);
N_NIMCALL(NI, nstlen)(Stringtableobj144212* t);
N_NIMCALL(pid_t, startprocessauxfork_156001)(Startprocessdata155948* data);
N_CDECL(void, startprocessafterfork_156004)(Startprocessdata155948* data);
N_NIMCALL(void, startprocessfail_156819)(Startprocessdata155948* 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_17850)(NCSTRING* a);
N_NIMCALL(void, createstream_157641)(Streamobj148427** stream, int* handle, NU8 filemode);
N_NIMCALL(NIM_BOOL, open_16811)(FILE** f, int filehandle, NU8 mode);
N_NIMCALL(Filestreamobj149667*, newfilestream_149743)(FILE* f);
N_NIMCALL(void, unsureAsgnRef)(void** dest, void* src);
N_NIMCALL(NI, ncpicountProcessors)(void);
N_NIMCALL(void, TMP4596)(void* p, NI op);
N_NIMCALL(Processobj154404*, nospstartProcess)(NimStringDesc* command, NimStringDesc* workingdir, NimStringDesc** args, NI argsLen0, Stringtableobj144212* env, NU8 options);
static N_INLINE(void, asgnRef)(void** dest, void* src);
static N_INLINE(void, incref_55022)(Cell48947* c);
static N_INLINE(NIM_BOOL, canbecycleroot_52667)(Cell48947* c);
static N_INLINE(void, rtladdcycleroot_53423)(Cell48947* c);
N_NOINLINE(void, incl_49665)(Cellset48959* s, Cell48947* cell);
static N_INLINE(void, decref_54604)(Cell48947* c);
N_NIMCALL(void, nossleep)(NI milsecs);
N_NIMCALL(NIM_BOOL, nosprunning)(Processobj154404* p);
N_NIMCALL(NI, nospwaitForExit)(Processobj154404* p, NI timeout);
N_NIMCALL(void, nospclose)(Processobj154404* p);
N_NIMCALL(void, close_148491)(Streamobj148427* s);
STRING_LITERAL(TMP1874, "\'\'", 2);
static NIM_CONST TY211407 TMP1875 = {
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(TMP1876, "\'", 1);
STRING_LITERAL(TMP1877, "\'\"\'\"\'", 5);
STRING_LITERAL(TMP3009, "", 0);
STRING_LITERAL(TMP3010, "/bin/sh", 7);
STRING_LITERAL(TMP3011, "-c", 2);
STRING_LITERAL(TMP3013, "=", 1);
STRING_LITERAL(TMP3016, "Could not find command: \'$1\'. OS error: $2", 42);
STRING_LITERAL(TMP3017, " ", 1);
static NIM_CONST TY202876 TMP4597 = {NIM_NIL,NIM_NIL};
static NIM_CONST TY202882 TMP4599 = {NIM_NIL,NIM_NIL};
extern TNimType NTI4011; /* RootObj */
TNimType NTI154404; /* ProcessObj */
extern TNimType NTI16408; /* FileHandle */
extern TNimType NTI148425; /* Stream */
extern TNimType NTI113289; /* Pid */
extern TNimType NTI8211; /* cint */
TNimType NTI154402; /* ProcessOption */
TNimType NTI154640; /* set[ProcessOption] */
TNimType NTI154406; /* Process */
extern TNimType NTI129408; /* seq[string] */
extern Gcheap51018 gch_51059;
extern TSafePoint* exchandler_20843;
extern TY129408* environment_129409;
TNimType NTI155201; /* 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*) &TMP1874));
		goto BeforeRet;
	}
	LA3: ;
	safe = allcharsinset_103130(s, TMP1875);
	{
		if (!safe) goto LA7;
		result = copyString(s);
		goto BeforeRet;
	}
	goto LA5;
	LA7: ;
	{
		NimStringDesc* LOC10;
		NimStringDesc* LOC11;
		LOC10 = 0;
		LOC11 = 0;
		LOC11 = nsuReplaceStr(s, ((NimStringDesc*) &TMP1876), ((NimStringDesc*) &TMP1877));
		LOC10 = rawNewString(LOC11->Sup.len + 2);
appendString(LOC10, ((NimStringDesc*) &TMP1876));
appendString(LOC10, LOC11);
appendString(LOC10, ((NimStringDesc*) &TMP1876));
		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, TMP3008)(void* p, NI op) {
	Processobj154404* a;
	a = (Processobj154404*)p;
	nimGCvisit((void*)(*a).instream, op);
	nimGCvisit((void*)(*a).outstream, op);
	nimGCvisit((void*)(*a).errstream, op);
}

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

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

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

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

N_NIMCALL(NCSTRING*, envtocstringarray_155854)(void) {
	NCSTRING* result;
	NI counter;
	void* LOC5;
	NI i;
	result = 0;
	counter = ((NI) 0);
	{
		NimStringDesc* key_155858;
		NimStringDesc* val_155859;
		key_155858 = 0;
		val_155859 = 0;
		getenvvarsc_129602();
		{
			NI i_155888;
			NI HEX3Atmp_155890;
			NI res_155892;
			i_155888 = 0;
			HEX3Atmp_155890 = 0;
			HEX3Atmp_155890 = (environment_129409 ? (environment_129409->Sup.len-1) : -1);
			res_155892 = ((NI) 0);
			{
				while (1) {
					NI p_155896;
					if (!(res_155892 <= HEX3Atmp_155890)) goto LA4;
					i_155888 = res_155892;
					p_155896 = nsuFindChar(environment_129409->data[i_155888], 61, ((NI) 0));
					key_155858 = copyStrLast(environment_129409->data[i_155888], ((NI) 0), (NI)(p_155896 - ((NI) 1)));
					val_155859 = copyStr(environment_129409->data[i_155888], (NI)(p_155896 + ((NI) 1)));
					counter += ((NI) 1);
					res_155892 += ((NI) 1);
				} LA4: ;
			}
		}
	}
	LOC5 = 0;
	LOC5 = alloc0_8417(((NI) ((NI)((NI)(counter + ((NI) 1)) * ((NI) 4)))));
	result = ((NCSTRING*) (LOC5));
	i = ((NI) 0);
	{
		NimStringDesc* key_155871;
		NimStringDesc* val_155872;
		key_155871 = 0;
		val_155872 = 0;
		getenvvarsc_129602();
		{
			NI i_155909;
			NI HEX3Atmp_155911;
			NI res_155913;
			i_155909 = 0;
			HEX3Atmp_155911 = 0;
			HEX3Atmp_155911 = (environment_129409 ? (environment_129409->Sup.len-1) : -1);
			res_155913 = ((NI) 0);
			{
				while (1) {
					NI p_155917;
					NimStringDesc* x;
					NimStringDesc* LOC10;
					void* LOC11;
					if (!(res_155913 <= HEX3Atmp_155911)) goto LA9;
					i_155909 = res_155913;
					p_155917 = nsuFindChar(environment_129409->data[i_155909], 61, ((NI) 0));
					key_155871 = copyStrLast(environment_129409->data[i_155909], ((NI) 0), (NI)(p_155917 - ((NI) 1)));
					val_155872 = copyStr(environment_129409->data[i_155909], (NI)(p_155917 + ((NI) 1)));
					LOC10 = 0;
					LOC10 = rawNewString(key_155871->Sup.len + val_155872->Sup.len + 1);
appendString(LOC10, key_155871);
appendString(LOC10, ((NimStringDesc*) &TMP3013));
appendString(LOC10, val_155872);
					x = LOC10;
					LOC11 = 0;
					LOC11 = alloc_8401(((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_155913 += ((NI) 1);
				} LA9: ;
			}
		}
	}
	return result;
}

N_NIMCALL(NCSTRING*, envtocstringarray_155806)(Stringtableobj144212* t) {
	NCSTRING* result;
	NI LOC1;
	void* LOC2;
	NI i;
	result = 0;
	LOC1 = 0;
	LOC1 = nstlen(t);
	LOC2 = 0;
	LOC2 = alloc0_8417(((NI) ((NI)((NI)(LOC1 + ((NI) 1)) * ((NI) 4)))));
	result = ((NCSTRING*) (LOC2));
	i = ((NI) 0);
	{
		NimStringDesc* key_155812;
		NimStringDesc* val_155813;
		key_155812 = 0;
		val_155813 = 0;
		{
			NI h_155832;
			NI HEX3Atmp_155834;
			NI res_155836;
			h_155832 = 0;
			HEX3Atmp_155834 = 0;
			HEX3Atmp_155834 = ((*t).data ? ((*t).data->Sup.len-1) : -1);
			res_155836 = ((NI) 0);
			{
				while (1) {
					if (!(res_155836 <= HEX3Atmp_155834)) goto LA6;
					h_155832 = res_155836;
					{
						NimStringDesc* x;
						NimStringDesc* LOC11;
						void* LOC12;
						if (!!((*t).data->data[h_155832].Field0 == 0)) goto LA9;
						key_155812 = (*t).data->data[h_155832].Field0;
						val_155813 = (*t).data->data[h_155832].Field1;
						LOC11 = 0;
						LOC11 = rawNewString(key_155812->Sup.len + val_155813->Sup.len + 1);
appendString(LOC11, key_155812);
appendString(LOC11, ((NimStringDesc*) &TMP3013));
appendString(LOC11, val_155813);
						x = LOC11;
						LOC12 = 0;
						LOC12 = alloc_8401(((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_155836 += ((NI) 1);
				} LA6: ;
			}
		}
	}
	return result;
}

N_NIMCALL(void, startprocessfail_156819)(Startprocessdata155948* 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_156004)(Startprocessdata155948* 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_156819(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_156819(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_156819(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_156819(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_156819(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_156819(data);
}

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

N_NIMCALL(pid_t, startprocessauxfork_156001)(Startprocessdata155948* data) {
	pid_t volatile result;
	TSafePoint TMP3015;
{	result = 0;
	{
		int LOC3;
		NI32 LOC6;
		LOC3 = 0;
		LOC3 = pipe((*data).perrorpipe);
		if (!!((LOC3 == ((NI32) 0)))) goto LA4;
		LOC6 = 0;
		LOC6 = oslasterror_125034();
		raiseoserror_125009(LOC6, ((NimStringDesc*) &TMP3009));
	}
	LA4: ;
	pushSafePoint(&TMP3015);
	TMP3015.status = setjmp(TMP3015.context);
	if (TMP3015.status == 0) {
		pid_t volatile pid;
		Startprocessdata155948 datacopy;
		int LOC12;
		int error;
		NI sizeread;
		int LOC25;
		pid = 0;
		datacopy = (*data);
		pid = fork();
		{
			if (!(pid == ((NI) 0))) goto LA10;
			startprocessafterfork_156004((&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_125034();
			raiseoserror_125009(LOC17, ((NimStringDesc*) &TMP3009));
		}
		LA15: ;
		error = 0;
		sizeread = read((*data).perrorpipe[(((NI) 0))- 0], ((void*) ((&error))), ((NI) 4));
		{
			TY191306 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*) &TMP3016), 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 (TMP3015.status != 0) reraiseException();
	}BeforeRet: ;
	return result;
}

N_NIMCALL(Processobj154404*, nospstartProcess)(NimStringDesc* command, NimStringDesc* workingdir, NimStringDesc** args, NI argsLen0, Stringtableobj144212* env, NU8 options) {
	Processobj154404* result;
	TY156024 pstdin;
	TY156024 pstdout;
	TY156024 pstderr;
	NimStringDesc* syscommand;
	TY129408* sysargsraw;
	pid_t volatile pid;
	NCSTRING* sysargs;
	TSafePoint TMP3012;
	result = 0;
	memset((void*)pstdin, 0, sizeof(pstdin));
	memset((void*)pstdout, 0, sizeof(pstdout));
	memset((void*)pstderr, 0, sizeof(pstderr));
	result = (Processobj154404*) newObj((&NTI154406), sizeof(Processobj154404));
	(*result).Sup.m_type = (&NTI154404);
	(*result).options = options;
	(*result).exitcode = ((int) -3);
	{
		if (!!(((options &(1<<((((NU8) 4))&7)))!=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_125034();
			raiseoserror_125009(LOC16, ((NimStringDesc*) &TMP3009));
		}
		LA14: ;
	}
	LA3: ;
	syscommand = 0;
	sysargsraw = 0;
	{
		TY191293 LOC21;
		NimStringDesc* LOC22;
		NimStringDesc* LOC23;
		NimStringDesc* LOC24;
		if (!((options &(1<<((((NU8) 2))&7)))!=0)) goto LA19;
		syscommand = copyString(((NimStringDesc*) &TMP3010));
		sysargsraw = (TY129408*) newSeq((&NTI129408), 3);
		memset((void*)LOC21, 0, sizeof(LOC21));
		LOC21[0] = copyString(syscommand);
		LOC21[1] = copyString(((NimStringDesc*) &TMP3011));
		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: ;
	{
		TY190421 LOC26;
		NimStringDesc* LOC27;
		syscommand = copyString(command);
		sysargsraw = (TY129408*) newSeq((&NTI129408), 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_156222;
			NI i_156479;
			arg_156222 = 0;
			i_156479 = ((NI) 0);
			{
				while (1) {
					NimStringDesc* LOC31;
					if (!(i_156479 < argsLen0)) goto LA30;
					arg_156222 = args[i_156479];
					sysargsraw = (TY129408*) incrSeqV2(&(sysargsraw)->Sup, sizeof(NimStringDesc*));
					LOC31 = 0;
					LOC31 = sysargsraw->data[sysargsraw->Sup.len]; sysargsraw->data[sysargsraw->Sup.len] = copyStringRC1(arg_156222);
					if (LOC31) nimGCunrefNoCycle(LOC31);
					++sysargsraw->Sup.len;
					i_156479 += ((NI) 1);
				} LA30: ;
			}
		}
	}
	LA17: ;
	pid = 0;
	sysargs = alloccstringarray_17601(sysargsraw->data, sysargsraw->Sup.len);
	pushSafePoint(&TMP3012);
	TMP3012.status = setjmp(TMP3012.context);
	if (TMP3012.status == 0) {
		NCSTRING* sysenv;
		TSafePoint TMP3014;
		{
			if (!(env == NIM_NIL)) goto LA35;
			sysenv = envtocstringarray_155854();
		}
		goto LA33;
		LA35: ;
		{
			sysenv = envtocstringarray_155806(env);
		}
		LA33: ;
		pushSafePoint(&TMP3014);
		TMP3014.status = setjmp(TMP3014.context);
		if (TMP3014.status == 0) {
			Startprocessdata155948 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(TY156024));
			memcpy((void*)data.pstdout, (NIM_CONST void*)pstdout, sizeof(TY156024));
			memcpy((void*)data.pstderr, (NIM_CONST void*)pstderr, sizeof(TY156024));
			data.optionpoparentstreams = ((options &(1<<((((NU8) 4))&7)))!=0);
			data.optionpousepath = ((options &(1<<((((NU8) 1))&7)))!=0);
			data.optionpostderrtostdout = ((options &(1<<((((NU8) 3))&7)))!=0);
			data.workingdir = workingdir->data;
			pid = startprocessauxfork_156001((&data));
			{
				NimStringDesc* LOC43;
				if (!((options &(1<<((((NU8) 0))&7)))!=0)) goto LA41;
				LOC43 = 0;
				LOC43 = nsuJoinSep(args, argsLen0, ((NimStringDesc*) &TMP3017));
				printf("%s%s%s\012", command? (command)->data:"nil", ((NimStringDesc*) &TMP3017)? (((NimStringDesc*) &TMP3017))->data:"nil", LOC43? (LOC43)->data:"nil");
			}
			LA41: ;
			(*result).id = pid;
			{
				if (!((options &(1<<((((NU8) 4))&7)))!=0)) goto LA46;
				(*result).inhandle = ((int) 0);
				(*result).outhandle = ((int) 1);
				{
					if (!((options &(1<<((((NU8) 3))&7)))!=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 &(1<<((((NU8) 3))&7)))!=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_17850(sysenv);
		}
		if (TMP3014.status != 0) reraiseException();
		popSafePoint();
	}
	else {
		popSafePoint();
	}
	{
		dealloccstringarray_17850(sysargs);
	}
	if (TMP3012.status != 0) reraiseException();
	return result;
}

N_NIMCALL(void, createstream_157641)(Streamobj148427** stream, int* handle, NU8 filemode) {
	FILE* f;
	Filestreamobj149667* LOC7;
	f = 0;
	{
		NIM_BOOL LOC3;
		NI32 LOC6;
		LOC3 = 0;
		LOC3 = open_16811(&f, (*handle), filemode);
		if (!!(LOC3)) goto LA4;
		LOC6 = 0;
		LOC6 = oslasterror_125034();
		raiseoserror_125009(LOC6, ((NimStringDesc*) &TMP3009));
	}
	LA4: ;
	LOC7 = 0;
	LOC7 = newfilestream_149743(f);
	unsureAsgnRef((void**) (&(*stream)), &LOC7->Sup);
}

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

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

N_NIMCALL(NI, nospwaitForExit)(Processobj154404* 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_125034();
		raiseoserror_125009(LOC10, ((NimStringDesc*) &TMP3009));
	}
	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) (LOC1));
	return result;
}

N_NIMCALL(NI, peekexitcode_154725)(Processobj154404* 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, TMP4596)(void* p, NI op) {
	TY155201* a;
	NI LOC1;
	a = (TY155201*)p;
	LOC1 = 0;
	for (LOC1 = 0; LOC1 < a->Sup.len; LOC1++) {
	nimGCvisit((void*)a->data[LOC1], op);
	}
}

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

static N_INLINE(void, rtladdcycleroot_53423)(Cell48947* c) {
	{
		if (!!((((NI) ((NI)((*c).refcount & ((NI) 3)))) == ((NI) 3)))) goto LA3;
		(*c).refcount = (NI)((NI)((*c).refcount & ((NI) -4)) | ((NI) 3));
		incl_49665((&gch_51059.cycleroots), c);
	}
	LA3: ;
}

static N_INLINE(void, incref_55022)(Cell48947* c) {
	(*c).refcount = (NI)((NU32)((*c).refcount) + (NU32)(((NI) 8)));
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = canbecycleroot_52667(c);
		if (!LOC3) goto LA4;
		rtladdcycleroot_53423(c);
	}
	LA4: ;
}

static N_INLINE(void, decref_54604)(Cell48947* c) {
	{
		(*c).refcount -= ((NI) 8);
		if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA3;
		rtladdzct_54204(c);
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC6;
		LOC6 = 0;
		LOC6 = canbecycleroot_52667(c);
		if (!LOC6) goto LA7;
		rtladdcycleroot_53423(c);
	}
	goto LA1;
	LA7: ;
	LA1: ;
}

static N_INLINE(void, asgnRef)(void** dest, void* src) {
	{
		Cell48947* LOC5;
		if (!!((src == NIM_NIL))) goto LA3;
		LOC5 = 0;
		LOC5 = usrtocell_52646(src);
		incref_55022(LOC5);
	}
	LA3: ;
	{
		Cell48947* LOC10;
		if (!!(((*dest) == NIM_NIL))) goto LA8;
		LOC10 = 0;
		LOC10 = usrtocell_52646((*dest));
		decref_54604(LOC10);
	}
	LA8: ;
	(*dest) = src;
}

N_NIMCALL(NIM_BOOL, nosprunning)(Processobj154404* 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)(Processobj154404* p) {
	int LOC13;
	int LOC14;
	int LOC15;
	{
		if (!!(((*p).instream == NIM_NIL))) goto LA3;
		close_148491((*p).instream);
	}
	LA3: ;
	{
		if (!!(((*p).outstream == NIM_NIL))) goto LA7;
		close_148491((*p).outstream);
	}
	LA7: ;
	{
		if (!!(((*p).errstream == NIM_NIL))) goto LA11;
		close_148491((*p).errstream);
	}
	LA11: ;
	LOC13 = 0;
	LOC13 = close((*p).inhandle);
	LOC14 = 0;
	LOC14 = close((*p).outhandle);
	LOC15 = 0;
	LOC15 = close((*p).errhandle);
}

N_NIMCALL(NI, nospexecProcesses)(NimStringDesc** cmds, NI cmdsLen0, NU8 options_154793, NI n, TY202876 beforerunevent, TY202882 afterrunevent) {
	NI result;
	NU8 options;
	result = 0;
	options = (options_154793 & ~ 16);
	{
		TY155201* q;
		NI m;
		NI i;
		if (!(((NI) 1) < n)) goto LA3;
		q = 0;
		q = (TY155201*) newSeq((&NTI155201), ((NI) (n)));
		m = ((n <= cmdsLen0) ? n : cmdsLen0);
		{
			NI i_155235;
			NI HEX3Atmp_155555;
			NI res_155558;
			i_155235 = 0;
			HEX3Atmp_155555 = 0;
			HEX3Atmp_155555 = (NI)(m - ((NI) 1));
			res_155558 = ((NI) 0);
			{
				while (1) {
					TY251724 LOC12;
					if (!(res_155558 <= HEX3Atmp_155555)) goto LA7;
					i_155235 = res_155558;
					{
						if (!!((beforerunevent.ClPrc == TMP4597.ClPrc && beforerunevent.ClEnv == TMP4597.ClEnv))) goto LA10;
						beforerunevent.ClEnv? beforerunevent.ClPrc(i_155235, beforerunevent.ClEnv):((TMP4598)(beforerunevent.ClPrc))(i_155235);
					}
					LA10: ;
					memset((void*)LOC12, 0, sizeof(LOC12));
					asgnRef((void**) (&q->data[i_155235]), nospstartProcess(cmds[i_155235], ((NimStringDesc*) &TMP3009), LOC12, 0, NIM_NIL, (options | 4)));
					res_155558 += ((NI) 1);
				} LA7: ;
			}
		}
		i = m;
		{
			while (1) {
				if (!(i <= (cmdsLen0-1))) goto LA14;
				nossleep(((NI) 50));
				{
					NI r_155413;
					NI HEX3Atmp_155564;
					NI res_155567;
					r_155413 = 0;
					HEX3Atmp_155564 = 0;
					HEX3Atmp_155564 = (NI)(n - ((NI) 1));
					res_155567 = ((NI) 0);
					{
						while (1) {
							if (!(res_155567 <= HEX3Atmp_155564)) goto LA17;
							r_155413 = res_155567;
							{
								NIM_BOOL LOC20;
								NI LOC23;
								TY251724 LOC36;
								LOC20 = 0;
								LOC20 = nosprunning(q->data[r_155413]);
								if (!!(LOC20)) goto LA21;
								LOC23 = 0;
								LOC23 = nospwaitForExit(q->data[r_155413], ((NI) -1));
								result = ((LOC23 >= result) ? LOC23 : result);
								{
									if (!!((afterrunevent.ClPrc == TMP4599.ClPrc && afterrunevent.ClEnv == TMP4599.ClEnv))) goto LA26;
									afterrunevent.ClEnv? afterrunevent.ClPrc(r_155413, q->data[r_155413], afterrunevent.ClEnv):((TMP4600)(afterrunevent.ClPrc))(r_155413, q->data[r_155413]);
								}
								LA26: ;
								{
									if (!!((q->data[r_155413] == NIM_NIL))) goto LA30;
									nospclose(q->data[r_155413]);
								}
								LA30: ;
								{
									if (!!((beforerunevent.ClPrc == TMP4597.ClPrc && beforerunevent.ClEnv == TMP4597.ClEnv))) goto LA34;
									beforerunevent.ClEnv? beforerunevent.ClPrc(i, beforerunevent.ClEnv):((TMP4601)(beforerunevent.ClPrc))(i);
								}
								LA34: ;
								memset((void*)LOC36, 0, sizeof(LOC36));
								asgnRef((void**) (&q->data[r_155413]), nospstartProcess(cmds[i], ((NimStringDesc*) &TMP3009), LOC36, 0, NIM_NIL, (options | 4)));
								i += ((NI) 1);
								{
									if (!((cmdsLen0-1) < i)) goto LA39;
									goto LA15;
								}
								LA39: ;
							}
							LA21: ;
							res_155567 += ((NI) 1);
						} LA17: ;
					}
				} LA15: ;
			} LA14: ;
		}
		{
			NI j_155480;
			NI HEX3Atmp_155572;
			NI res_155575;
			j_155480 = 0;
			HEX3Atmp_155572 = 0;
			HEX3Atmp_155572 = (NI)(m - ((NI) 1));
			res_155575 = ((NI) 0);
			{
				while (1) {
					NI LOC44;
					if (!(res_155575 <= HEX3Atmp_155572)) goto LA43;
					j_155480 = res_155575;
					LOC44 = 0;
					LOC44 = nospwaitForExit(q->data[j_155480], ((NI) -1));
					result = ((LOC44 >= result) ? LOC44 : result);
					{
						if (!!((afterrunevent.ClPrc == TMP4599.ClPrc && afterrunevent.ClEnv == TMP4599.ClEnv))) goto LA47;
						afterrunevent.ClEnv? afterrunevent.ClPrc(j_155480, q->data[j_155480], afterrunevent.ClEnv):((TMP4602)(afterrunevent.ClPrc))(j_155480, q->data[j_155480]);
					}
					LA47: ;
					{
						if (!!((q->data[j_155480] == NIM_NIL))) goto LA51;
						nospclose(q->data[j_155480]);
					}
					LA51: ;
					res_155575 += ((NI) 1);
				} LA43: ;
			}
		}
	}
	goto LA1;
	LA3: ;
	{
		{
			NI i_155516;
			NI HEX3Atmp_155580;
			NI res_155583;
			i_155516 = 0;
			HEX3Atmp_155580 = 0;
			HEX3Atmp_155580 = (cmdsLen0-1);
			res_155583 = ((NI) 0);
			{
				while (1) {
					Processobj154404* p;
					TY251724 LOC61;
					NI LOC62;
					if (!(res_155583 <= HEX3Atmp_155580)) goto LA56;
					i_155516 = res_155583;
					{
						if (!!((beforerunevent.ClPrc == TMP4597.ClPrc && beforerunevent.ClEnv == TMP4597.ClEnv))) goto LA59;
						beforerunevent.ClEnv? beforerunevent.ClPrc(i_155516, beforerunevent.ClEnv):((TMP4603)(beforerunevent.ClPrc))(i_155516);
					}
					LA59: ;
					memset((void*)LOC61, 0, sizeof(LOC61));
					p = nospstartProcess(cmds[i_155516], ((NimStringDesc*) &TMP3009), LOC61, 0, NIM_NIL, (options | 4));
					LOC62 = 0;
					LOC62 = nospwaitForExit(p, ((NI) -1));
					result = ((LOC62 >= result) ? LOC62 : result);
					{
						if (!!((afterrunevent.ClPrc == TMP4599.ClPrc && afterrunevent.ClEnv == TMP4599.ClEnv))) goto LA65;
						afterrunevent.ClEnv? afterrunevent.ClPrc(i_155516, p, afterrunevent.ClEnv):((TMP4604)(afterrunevent.ClPrc))(i_155516, p);
					}
					LA65: ;
					nospclose(p);
					res_155583 += ((NI) 1);
				} LA56: ;
			}
		}
	}
	LA1: ;
	return result;
}
NIM_EXTERNC N_NOINLINE(void, stdlib_osprocInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, stdlib_osprocDatInit000)(void) {
static TNimNode* TMP3004[9];
static TNimNode* TMP3005[7];
NI TMP3007;
static char* NIM_CONST TMP3006[7] = {
"poEchoCmd", 
"poUsePath", 
"poEvalCommand", 
"poStdErrToStdOut", 
"poParentStreams", 
"poInteractive", 
"poDemon"};
static TNimNode TMP31[19];
NTI154404.size = sizeof(Processobj154404);
NTI154404.kind = 17;
NTI154404.base = (&NTI4011);
TMP3004[0] = &TMP31[1];
TMP31[1].kind = 1;
TMP31[1].offset = offsetof(Processobj154404, inhandle);
TMP31[1].typ = (&NTI16408);
TMP31[1].name = "inHandle";
TMP3004[1] = &TMP31[2];
TMP31[2].kind = 1;
TMP31[2].offset = offsetof(Processobj154404, outhandle);
TMP31[2].typ = (&NTI16408);
TMP31[2].name = "outHandle";
TMP3004[2] = &TMP31[3];
TMP31[3].kind = 1;
TMP31[3].offset = offsetof(Processobj154404, errhandle);
TMP31[3].typ = (&NTI16408);
TMP31[3].name = "errHandle";
TMP3004[3] = &TMP31[4];
TMP31[4].kind = 1;
TMP31[4].offset = offsetof(Processobj154404, instream);
TMP31[4].typ = (&NTI148425);
TMP31[4].name = "inStream";
TMP3004[4] = &TMP31[5];
TMP31[5].kind = 1;
TMP31[5].offset = offsetof(Processobj154404, outstream);
TMP31[5].typ = (&NTI148425);
TMP31[5].name = "outStream";
TMP3004[5] = &TMP31[6];
TMP31[6].kind = 1;
TMP31[6].offset = offsetof(Processobj154404, errstream);
TMP31[6].typ = (&NTI148425);
TMP31[6].name = "errStream";
TMP3004[6] = &TMP31[7];
TMP31[7].kind = 1;
TMP31[7].offset = offsetof(Processobj154404, id);
TMP31[7].typ = (&NTI113289);
TMP31[7].name = "id";
TMP3004[7] = &TMP31[8];
TMP31[8].kind = 1;
TMP31[8].offset = offsetof(Processobj154404, exitcode);
TMP31[8].typ = (&NTI8211);
TMP31[8].name = "exitCode";
TMP3004[8] = &TMP31[9];
NTI154402.size = sizeof(NU8);
NTI154402.kind = 14;
NTI154402.base = 0;
NTI154402.flags = 3;
for (TMP3007 = 0; TMP3007 < 7; TMP3007++) {
TMP31[TMP3007+10].kind = 1;
TMP31[TMP3007+10].offset = TMP3007;
TMP31[TMP3007+10].name = TMP3006[TMP3007];
TMP3005[TMP3007] = &TMP31[TMP3007+10];
}
TMP31[17].len = 7; TMP31[17].kind = 2; TMP31[17].sons = &TMP3005[0];
NTI154402.node = &TMP31[17];
NTI154640.size = sizeof(NU8);
NTI154640.kind = 19;
NTI154640.base = (&NTI154402);
NTI154640.flags = 3;
TMP31[18].len = 0; TMP31[18].kind = 0;
NTI154640.node = &TMP31[18];
TMP31[9].kind = 1;
TMP31[9].offset = offsetof(Processobj154404, options);
TMP31[9].typ = (&NTI154640);
TMP31[9].name = "options";
TMP31[0].len = 9; TMP31[0].kind = 2; TMP31[0].sons = &TMP3004[0];
NTI154404.node = &TMP31[0];
NTI154406.size = sizeof(Processobj154404*);
NTI154406.kind = 22;
NTI154406.base = (&NTI154404);
NTI154406.marker = TMP3008;
NTI155201.size = sizeof(TY155201*);
NTI155201.kind = 24;
NTI155201.base = (&NTI154406);
NTI155201.marker = TMP4596;
}

