/* 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 Processobj155404 Processobj155404;
typedef struct Stringtableobj145212 Stringtableobj145212;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Streamobj149427 Streamobj149427;
typedef struct TY130408 TY130408;
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 Keyvaluepairseq145210 Keyvaluepairseq145210;
typedef struct Keyvaluepair145208 Keyvaluepair145208;
typedef struct Startprocessdata156948 Startprocessdata156948;
typedef struct Filestreamobj150667 Filestreamobj150667;
typedef struct TY156201 TY156201;
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 TY212407[32];
typedef int TY157024[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  Processobj155404  {
  TNimObject Sup;
int inhandle;
int outhandle;
int errhandle;
Streamobj149427* instream;
Streamobj149427* outstream;
Streamobj149427* errstream;
pid_t id;
int exitcode;
NU8 options;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
typedef NimStringDesc* TY192293[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* TY191421[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  Stringtableobj145212  {
  TNimObject Sup;
NI counter;
Keyvaluepairseq145210* data;
NU8 mode;
};
struct Keyvaluepair145208 {
NimStringDesc* Field0;
NimStringDesc* Field1;
};
struct  Startprocessdata156948  {
NCSTRING syscommand;
NCSTRING* sysargs;
NCSTRING* sysenv;
NCSTRING workingdir;
TY157024 pstdin;
TY157024 pstdout;
TY157024 pstderr;
TY157024 perrorpipe;
NIM_BOOL optionpousepath;
NIM_BOOL optionpoparentstreams;
NIM_BOOL optionpostderrtostdout;
};
typedef NimStringDesc* TY192306[2];
typedef struct {
N_NIMCALL_PTR(void, ClPrc) (NI idx, void* ClEnv);
void* ClEnv;
} TY203876;
typedef struct {
N_NIMCALL_PTR(void, ClPrc) (NI idx, Processobj155404* p, void* ClEnv);
void* ClEnv;
} TY203882;
typedef N_CLOSURE_PTR(void, TMP4598) (NI idx);
typedef NimStringDesc* TY252724[1];
typedef N_CLOSURE_PTR(void, TMP4600) (NI idx, Processobj155404* p);
typedef N_CLOSURE_PTR(void, TMP4601) (NI idx);
typedef N_CLOSURE_PTR(void, TMP4602) (NI idx, Processobj155404* p);
typedef N_CLOSURE_PTR(void, TMP4603) (NI idx);
typedef N_CLOSURE_PTR(void, TMP4604) (NI idx, Processobj155404* p);
typedef N_NIMCALL_PTR(void, TY149428) (Streamobj149427* s);
typedef N_NIMCALL_PTR(NIM_BOOL, TY149432) (Streamobj149427* s);
typedef N_NIMCALL_PTR(void, TY149436) (Streamobj149427* s, NI pos);
typedef N_NIMCALL_PTR(NI, TY149441) (Streamobj149427* s);
typedef N_NIMCALL_PTR(NI, TY149445) (Streamobj149427* s, void* buffer, NI buflen);
typedef N_NIMCALL_PTR(NI, TY149451) (Streamobj149427* s, void* buffer, NI buflen);
typedef N_NIMCALL_PTR(void, TY149457) (Streamobj149427* s, void* buffer, NI buflen);
typedef N_NIMCALL_PTR(void, TY149463) (Streamobj149427* s);
struct  Streamobj149427  {
  TNimObject Sup;
TY149428 closeimpl;
TY149432 atendimpl;
TY149436 setpositionimpl;
TY149441 getpositionimpl;
TY149445 readdataimpl;
TY149451 peekdataimpl;
TY149457 writedataimpl;
TY149463 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  Filestreamobj150667  {
  Streamobj149427 Sup;
FILE* f;
};
struct  Freecell30832  {
Freecell30832* next;
NI zerofield;
};
struct TY130408 {
  TGenericSeq Sup;
  NimStringDesc* data[SEQ_DECL_SIZE];
};
struct TY156201 {
  TGenericSeq Sup;
  Processobj155404* data[SEQ_DECL_SIZE];
};
struct Keyvaluepairseq145210 {
  TGenericSeq Sup;
  Keyvaluepair145208 data[SEQ_DECL_SIZE];
};
N_NIMCALL(NimStringDesc*, nospquoteShellPosix)(NimStringDesc* s);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(NIM_BOOL, allcharsinset_103130)(NimStringDesc* s, TY212407 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_126009)(NI32 errorcode, NimStringDesc* additionalinfo);
N_NIMCALL(NI32, oslasterror_126034)(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_156854)(void);
N_NIMCALL(void, getenvvarsc_130602)(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_156806)(Stringtableobj145212* t);
N_NIMCALL(NI, nstlen)(Stringtableobj145212* t);
N_NIMCALL(pid_t, startprocessauxfork_157001)(Startprocessdata156948* data);
N_CDECL(void, startprocessafterfork_157004)(Startprocessdata156948* data);
N_NIMCALL(void, startprocessfail_157819)(Startprocessdata156948* 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_158641)(Streamobj149427** stream, int* handle, NU8 filemode);
N_NIMCALL(NIM_BOOL, open_16811)(FILE** f, int filehandle, NU8 mode);
N_NIMCALL(Filestreamobj150667*, newfilestream_150743)(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(Processobj155404*, nospstartProcess)(NimStringDesc* command, NimStringDesc* workingdir, NimStringDesc** args, NI argsLen0, Stringtableobj145212* 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)(Processobj155404* p);
N_NIMCALL(NI, nospwaitForExit)(Processobj155404* p, NI timeout);
N_NIMCALL(void, nospclose)(Processobj155404* p);
N_NIMCALL(void, close_149491)(Streamobj149427* s);
STRING_LITERAL(TMP1874, "\'\'", 2);
static NIM_CONST TY212407 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 TY203876 TMP4597 = {NIM_NIL,NIM_NIL};
static NIM_CONST TY203882 TMP4599 = {NIM_NIL,NIM_NIL};
extern TNimType NTI4011; /* RootObj */
TNimType NTI155404; /* ProcessObj */
extern TNimType NTI16408; /* FileHandle */
extern TNimType NTI149425; /* Stream */
extern TNimType NTI113289; /* Pid */
extern TNimType NTI8211; /* cint */
TNimType NTI155402; /* ProcessOption */
TNimType NTI155640; /* set[ProcessOption] */
TNimType NTI155406; /* Process */
extern TNimType NTI130408; /* seq[string] */
extern Gcheap51018 gch_51059;
extern TSafePoint* exchandler_20843;
extern TY130408* environment_130409;
TNimType NTI156201; /* 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) {
	Processobj155404* a;
	a = (Processobj155404*)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_156854)(void) {
	NCSTRING* result;
	NI counter;
	void* LOC5;
	NI i;
	result = 0;
	counter = ((NI) 0);
	{
		NimStringDesc* key_156858;
		NimStringDesc* val_156859;
		key_156858 = 0;
		val_156859 = 0;
		getenvvarsc_130602();
		{
			NI i_156888;
			NI HEX3Atmp_156890;
			NI res_156892;
			i_156888 = 0;
			HEX3Atmp_156890 = 0;
			HEX3Atmp_156890 = (environment_130409 ? (environment_130409->Sup.len-1) : -1);
			res_156892 = ((NI) 0);
			{
				while (1) {
					NI p_156896;
					if (!(res_156892 <= HEX3Atmp_156890)) goto LA4;
					i_156888 = res_156892;
					p_156896 = nsuFindChar(environment_130409->data[i_156888], 61, ((NI) 0));
					key_156858 = copyStrLast(environment_130409->data[i_156888], ((NI) 0), (NI)(p_156896 - ((NI) 1)));
					val_156859 = copyStr(environment_130409->data[i_156888], (NI)(p_156896 + ((NI) 1)));
					counter += ((NI) 1);
					res_156892 += ((NI) 1);
				} LA4: ;
			}
		}
	}
	LOC5 = 0;
	LOC5 = alloc0_8417(((NI) ((NI)((NI)(counter + ((NI) 1)) * ((NI) 4)))));
	result = ((NCSTRING*) (LOC5));
	i = ((NI) 0);
	{
		NimStringDesc* key_156871;
		NimStringDesc* val_156872;
		key_156871 = 0;
		val_156872 = 0;
		getenvvarsc_130602();
		{
			NI i_156909;
			NI HEX3Atmp_156911;
			NI res_156913;
			i_156909 = 0;
			HEX3Atmp_156911 = 0;
			HEX3Atmp_156911 = (environment_130409 ? (environment_130409->Sup.len-1) : -1);
			res_156913 = ((NI) 0);
			{
				while (1) {
					NI p_156917;
					NimStringDesc* x;
					NimStringDesc* LOC10;
					void* LOC11;
					if (!(res_156913 <= HEX3Atmp_156911)) goto LA9;
					i_156909 = res_156913;
					p_156917 = nsuFindChar(environment_130409->data[i_156909], 61, ((NI) 0));
					key_156871 = copyStrLast(environment_130409->data[i_156909], ((NI) 0), (NI)(p_156917 - ((NI) 1)));
					val_156872 = copyStr(environment_130409->data[i_156909], (NI)(p_156917 + ((NI) 1)));
					LOC10 = 0;
					LOC10 = rawNewString(key_156871->Sup.len + val_156872->Sup.len + 1);
appendString(LOC10, key_156871);
appendString(LOC10, ((NimStringDesc*) &TMP3013));
appendString(LOC10, val_156872);
					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_156913 += ((NI) 1);
				} LA9: ;
			}
		}
	}
	return result;
}

N_NIMCALL(NCSTRING*, envtocstringarray_156806)(Stringtableobj145212* 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_156812;
		NimStringDesc* val_156813;
		key_156812 = 0;
		val_156813 = 0;
		{
			NI h_156832;
			NI HEX3Atmp_156834;
			NI res_156836;
			h_156832 = 0;
			HEX3Atmp_156834 = 0;
			HEX3Atmp_156834 = ((*t).data ? ((*t).data->Sup.len-1) : -1);
			res_156836 = ((NI) 0);
			{
				while (1) {
					if (!(res_156836 <= HEX3Atmp_156834)) goto LA6;
					h_156832 = res_156836;
					{
						NimStringDesc* x;
						NimStringDesc* LOC11;
						void* LOC12;
						if (!!((*t).data->data[h_156832].Field0 == 0)) goto LA9;
						key_156812 = (*t).data->data[h_156832].Field0;
						val_156813 = (*t).data->data[h_156832].Field1;
						LOC11 = 0;
						LOC11 = rawNewString(key_156812->Sup.len + val_156813->Sup.len + 1);
appendString(LOC11, key_156812);
appendString(LOC11, ((NimStringDesc*) &TMP3013));
appendString(LOC11, val_156813);
						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_156836 += ((NI) 1);
				} LA6: ;
			}
		}
	}
	return result;
}

N_NIMCALL(void, startprocessfail_157819)(Startprocessdata156948* 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_157004)(Startprocessdata156948* 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_157819(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_157819(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_157819(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_157819(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_157819(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_157819(data);
}

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

N_NIMCALL(pid_t, startprocessauxfork_157001)(Startprocessdata156948* 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_126034();
		raiseoserror_126009(LOC6, ((NimStringDesc*) &TMP3009));
	}
	LA4: ;
	pushSafePoint(&TMP3015);
	TMP3015.status = _setjmp(TMP3015.context);
	if (TMP3015.status == 0) {
		pid_t volatile pid;
		Startprocessdata156948 datacopy;
		int LOC12;
		int error;
		NI sizeread;
		int LOC25;
		pid = 0;
		datacopy = (*data);
		pid = fork();
		{
			if (!(pid == ((NI) 0))) goto LA10;
			startprocessafterfork_157004((&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_126034();
			raiseoserror_126009(LOC17, ((NimStringDesc*) &TMP3009));
		}
		LA15: ;
		error = 0;
		sizeread = read((*data).perrorpipe[(((NI) 0))- 0], ((void*) ((&error))), ((NI) 4));
		{
			TY192306 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(Processobj155404*, nospstartProcess)(NimStringDesc* command, NimStringDesc* workingdir, NimStringDesc** args, NI argsLen0, Stringtableobj145212* env, NU8 options) {
	Processobj155404* result;
	TY157024 pstdin;
	TY157024 pstdout;
	TY157024 pstderr;
	NimStringDesc* syscommand;
	TY130408* 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 = (Processobj155404*) newObj((&NTI155406), sizeof(Processobj155404));
	(*result).Sup.m_type = (&NTI155404);
	(*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_126034();
			raiseoserror_126009(LOC16, ((NimStringDesc*) &TMP3009));
		}
		LA14: ;
	}
	LA3: ;
	syscommand = 0;
	sysargsraw = 0;
	{
		TY192293 LOC21;
		NimStringDesc* LOC22;
		NimStringDesc* LOC23;
		NimStringDesc* LOC24;
		if (!((options &(1<<((((NU8) 2))&7)))!=0)) goto LA19;
		syscommand = copyString(((NimStringDesc*) &TMP3010));
		sysargsraw = (TY130408*) newSeq((&NTI130408), 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: ;
	{
		TY191421 LOC26;
		NimStringDesc* LOC27;
		syscommand = copyString(command);
		sysargsraw = (TY130408*) newSeq((&NTI130408), 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_157222;
			NI i_157479;
			arg_157222 = 0;
			i_157479 = ((NI) 0);
			{
				while (1) {
					NimStringDesc* LOC31;
					if (!(i_157479 < argsLen0)) goto LA30;
					arg_157222 = args[i_157479];
					sysargsraw = (TY130408*) incrSeqV2(&(sysargsraw)->Sup, sizeof(NimStringDesc*));
					LOC31 = 0;
					LOC31 = sysargsraw->data[sysargsraw->Sup.len]; sysargsraw->data[sysargsraw->Sup.len] = copyStringRC1(arg_157222);
					if (LOC31) nimGCunrefNoCycle(LOC31);
					++sysargsraw->Sup.len;
					i_157479 += ((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_156854();
		}
		goto LA33;
		LA35: ;
		{
			sysenv = envtocstringarray_156806(env);
		}
		LA33: ;
		pushSafePoint(&TMP3014);
		TMP3014.status = _setjmp(TMP3014.context);
		if (TMP3014.status == 0) {
			Startprocessdata156948 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(TY157024));
			memcpy((void*)data.pstdout, (NIM_CONST void*)pstdout, sizeof(TY157024));
			memcpy((void*)data.pstderr, (NIM_CONST void*)pstderr, sizeof(TY157024));
			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_157001((&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_158641)(Streamobj149427** stream, int* handle, NU8 filemode) {
	FILE* f;
	Filestreamobj150667* LOC7;
	f = 0;
	{
		NIM_BOOL LOC3;
		NI32 LOC6;
		LOC3 = 0;
		LOC3 = open_16811(&f, (*handle), filemode);
		if (!!(LOC3)) goto LA4;
		LOC6 = 0;
		LOC6 = oslasterror_126034();
		raiseoserror_126009(LOC6, ((NimStringDesc*) &TMP3009));
	}
	LA4: ;
	LOC7 = 0;
	LOC7 = newfilestream_150743(f);
	unsureAsgnRef((void**) (&(*stream)), &LOC7->Sup);
}

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

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

N_NIMCALL(NI, nospwaitForExit)(Processobj155404* 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_126034();
		raiseoserror_126009(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_155725)(Processobj155404* 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) {
	TY156201* a;
	NI LOC1;
	a = (TY156201*)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)(Processobj155404* 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)(Processobj155404* p) {
	int LOC13;
	int LOC14;
	int LOC15;
	{
		if (!!(((*p).instream == NIM_NIL))) goto LA3;
		close_149491((*p).instream);
	}
	LA3: ;
	{
		if (!!(((*p).outstream == NIM_NIL))) goto LA7;
		close_149491((*p).outstream);
	}
	LA7: ;
	{
		if (!!(((*p).errstream == NIM_NIL))) goto LA11;
		close_149491((*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_155793, NI n, TY203876 beforerunevent, TY203882 afterrunevent) {
	NI result;
	NU8 options;
	result = 0;
	options = (options_155793 & ~ 16);
	{
		TY156201* q;
		NI m;
		NI i;
		if (!(((NI) 1) < n)) goto LA3;
		q = 0;
		q = (TY156201*) newSeq((&NTI156201), ((NI) (n)));
		m = ((n <= cmdsLen0) ? n : cmdsLen0);
		{
			NI i_156235;
			NI HEX3Atmp_156555;
			NI res_156558;
			i_156235 = 0;
			HEX3Atmp_156555 = 0;
			HEX3Atmp_156555 = (NI)(m - ((NI) 1));
			res_156558 = ((NI) 0);
			{
				while (1) {
					TY252724 LOC12;
					if (!(res_156558 <= HEX3Atmp_156555)) goto LA7;
					i_156235 = res_156558;
					{
						if (!!((beforerunevent.ClPrc == TMP4597.ClPrc && beforerunevent.ClEnv == TMP4597.ClEnv))) goto LA10;
						beforerunevent.ClEnv? beforerunevent.ClPrc(i_156235, beforerunevent.ClEnv):((TMP4598)(beforerunevent.ClPrc))(i_156235);
					}
					LA10: ;
					memset((void*)LOC12, 0, sizeof(LOC12));
					asgnRef((void**) (&q->data[i_156235]), nospstartProcess(cmds[i_156235], ((NimStringDesc*) &TMP3009), LOC12, 0, NIM_NIL, (options | 4)));
					res_156558 += ((NI) 1);
				} LA7: ;
			}
		}
		i = m;
		{
			while (1) {
				if (!(i <= (cmdsLen0-1))) goto LA14;
				nossleep(((NI) 50));
				{
					NI r_156413;
					NI HEX3Atmp_156564;
					NI res_156567;
					r_156413 = 0;
					HEX3Atmp_156564 = 0;
					HEX3Atmp_156564 = (NI)(n - ((NI) 1));
					res_156567 = ((NI) 0);
					{
						while (1) {
							if (!(res_156567 <= HEX3Atmp_156564)) goto LA17;
							r_156413 = res_156567;
							{
								NIM_BOOL LOC20;
								NI LOC23;
								TY252724 LOC36;
								LOC20 = 0;
								LOC20 = nosprunning(q->data[r_156413]);
								if (!!(LOC20)) goto LA21;
								LOC23 = 0;
								LOC23 = nospwaitForExit(q->data[r_156413], ((NI) -1));
								result = ((LOC23 >= result) ? LOC23 : result);
								{
									if (!!((afterrunevent.ClPrc == TMP4599.ClPrc && afterrunevent.ClEnv == TMP4599.ClEnv))) goto LA26;
									afterrunevent.ClEnv? afterrunevent.ClPrc(r_156413, q->data[r_156413], afterrunevent.ClEnv):((TMP4600)(afterrunevent.ClPrc))(r_156413, q->data[r_156413]);
								}
								LA26: ;
								{
									if (!!((q->data[r_156413] == NIM_NIL))) goto LA30;
									nospclose(q->data[r_156413]);
								}
								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_156413]), 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_156567 += ((NI) 1);
						} LA17: ;
					}
				} LA15: ;
			} LA14: ;
		}
		{
			NI j_156480;
			NI HEX3Atmp_156572;
			NI res_156575;
			j_156480 = 0;
			HEX3Atmp_156572 = 0;
			HEX3Atmp_156572 = (NI)(m - ((NI) 1));
			res_156575 = ((NI) 0);
			{
				while (1) {
					NI LOC44;
					if (!(res_156575 <= HEX3Atmp_156572)) goto LA43;
					j_156480 = res_156575;
					LOC44 = 0;
					LOC44 = nospwaitForExit(q->data[j_156480], ((NI) -1));
					result = ((LOC44 >= result) ? LOC44 : result);
					{
						if (!!((afterrunevent.ClPrc == TMP4599.ClPrc && afterrunevent.ClEnv == TMP4599.ClEnv))) goto LA47;
						afterrunevent.ClEnv? afterrunevent.ClPrc(j_156480, q->data[j_156480], afterrunevent.ClEnv):((TMP4602)(afterrunevent.ClPrc))(j_156480, q->data[j_156480]);
					}
					LA47: ;
					{
						if (!!((q->data[j_156480] == NIM_NIL))) goto LA51;
						nospclose(q->data[j_156480]);
					}
					LA51: ;
					res_156575 += ((NI) 1);
				} LA43: ;
			}
		}
	}
	goto LA1;
	LA3: ;
	{
		{
			NI i_156516;
			NI HEX3Atmp_156580;
			NI res_156583;
			i_156516 = 0;
			HEX3Atmp_156580 = 0;
			HEX3Atmp_156580 = (cmdsLen0-1);
			res_156583 = ((NI) 0);
			{
				while (1) {
					Processobj155404* p;
					TY252724 LOC61;
					NI LOC62;
					if (!(res_156583 <= HEX3Atmp_156580)) goto LA56;
					i_156516 = res_156583;
					{
						if (!!((beforerunevent.ClPrc == TMP4597.ClPrc && beforerunevent.ClEnv == TMP4597.ClEnv))) goto LA59;
						beforerunevent.ClEnv? beforerunevent.ClPrc(i_156516, beforerunevent.ClEnv):((TMP4603)(beforerunevent.ClPrc))(i_156516);
					}
					LA59: ;
					memset((void*)LOC61, 0, sizeof(LOC61));
					p = nospstartProcess(cmds[i_156516], ((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_156516, p, afterrunevent.ClEnv):((TMP4604)(afterrunevent.ClPrc))(i_156516, p);
					}
					LA65: ;
					nospclose(p);
					res_156583 += ((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];
NTI155404.size = sizeof(Processobj155404);
NTI155404.kind = 17;
NTI155404.base = (&NTI4011);
TMP3004[0] = &TMP31[1];
TMP31[1].kind = 1;
TMP31[1].offset = offsetof(Processobj155404, inhandle);
TMP31[1].typ = (&NTI16408);
TMP31[1].name = "inHandle";
TMP3004[1] = &TMP31[2];
TMP31[2].kind = 1;
TMP31[2].offset = offsetof(Processobj155404, outhandle);
TMP31[2].typ = (&NTI16408);
TMP31[2].name = "outHandle";
TMP3004[2] = &TMP31[3];
TMP31[3].kind = 1;
TMP31[3].offset = offsetof(Processobj155404, errhandle);
TMP31[3].typ = (&NTI16408);
TMP31[3].name = "errHandle";
TMP3004[3] = &TMP31[4];
TMP31[4].kind = 1;
TMP31[4].offset = offsetof(Processobj155404, instream);
TMP31[4].typ = (&NTI149425);
TMP31[4].name = "inStream";
TMP3004[4] = &TMP31[5];
TMP31[5].kind = 1;
TMP31[5].offset = offsetof(Processobj155404, outstream);
TMP31[5].typ = (&NTI149425);
TMP31[5].name = "outStream";
TMP3004[5] = &TMP31[6];
TMP31[6].kind = 1;
TMP31[6].offset = offsetof(Processobj155404, errstream);
TMP31[6].typ = (&NTI149425);
TMP31[6].name = "errStream";
TMP3004[6] = &TMP31[7];
TMP31[7].kind = 1;
TMP31[7].offset = offsetof(Processobj155404, id);
TMP31[7].typ = (&NTI113289);
TMP31[7].name = "id";
TMP3004[7] = &TMP31[8];
TMP31[8].kind = 1;
TMP31[8].offset = offsetof(Processobj155404, exitcode);
TMP31[8].typ = (&NTI8211);
TMP31[8].name = "exitCode";
TMP3004[8] = &TMP31[9];
NTI155402.size = sizeof(NU8);
NTI155402.kind = 14;
NTI155402.base = 0;
NTI155402.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];
NTI155402.node = &TMP31[17];
NTI155640.size = sizeof(NU8);
NTI155640.kind = 19;
NTI155640.base = (&NTI155402);
NTI155640.flags = 3;
TMP31[18].len = 0; TMP31[18].kind = 0;
NTI155640.node = &TMP31[18];
TMP31[9].kind = 1;
TMP31[9].offset = offsetof(Processobj155404, options);
TMP31[9].typ = (&NTI155640);
TMP31[9].name = "options";
TMP31[0].len = 9; TMP31[0].kind = 2; TMP31[0].sons = &TMP3004[0];
NTI155404.node = &TMP31[0];
NTI155406.size = sizeof(Processobj155404*);
NTI155406.kind = 22;
NTI155406.base = (&NTI155404);
NTI155406.marker = TMP3008;
NTI156201.size = sizeof(TY156201*);
NTI156201.kind = 24;
NTI156201.base = (&NTI155406);
NTI156201.marker = TMP4596;
}

