/* Generated by Nim Compiler v2.2.4 */
#define NIM_INTBITS 64

#include "nimbase.h"
#include <stdlib.h>
#include <string.h>
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
typedef struct NimStrPayload NimStrPayload;
typedef struct NimStringV2 NimStringV2;
typedef struct tyTuple__UV3llMMYFckfui8YMBuUZA tyTuple__UV3llMMYFckfui8YMBuUZA;
typedef struct tySequence__4eQHGndY6XBYpFOH09apV8Q tySequence__4eQHGndY6XBYpFOH09apV8Q;
typedef struct tySequence__4eQHGndY6XBYpFOH09apV8Q_Content tySequence__4eQHGndY6XBYpFOH09apV8Q_Content;
typedef struct tyObject_NimRawSeq__Tvl1urqmI1tXqzkHPbWVJQ tyObject_NimRawSeq__Tvl1urqmI1tXqzkHPbWVJQ;
struct NimStrPayload {
	NI cap;
	NIM_CHAR data[SEQ_DECL_SIZE];
};
struct NimStringV2 {
	NI len;
	NimStrPayload* p;
};
struct tyTuple__UV3llMMYFckfui8YMBuUZA {
	NimStringV2 Field0;
	NimStringV2 Field1;
};
struct tySequence__4eQHGndY6XBYpFOH09apV8Q {
  NI len; tySequence__4eQHGndY6XBYpFOH09apV8Q_Content* p;
};
struct tyObject_NimRawSeq__Tvl1urqmI1tXqzkHPbWVJQ {
	NI len;
	void* p;
};
struct tySequence__4eQHGndY6XBYpFOH09apV8Q_Content { NI cap; tyTuple__UV3llMMYFckfui8YMBuUZA data[SEQ_DECL_SIZE]; };
N_LIB_PRIVATE N_NIMCALL(NCSTRING, getEnvImpl__stdZenvvars_u13)(NCSTRING env_p0);
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringV2 s_p0);
static N_INLINE(NIM_BOOL, eqeq___system_u8371)(NCSTRING x_p0, NCSTRING y_p1);
N_LIB_PRIVATE N_NIMCALL(void, eqcopy___system_u2630)(NimStringV2* dest_p0, NimStringV2 src_p1);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, cstrToNimstr)(NCSTRING str_p0);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
N_LIB_PRIVATE N_NOINLINE(void, raiseOSError__stdZoserrors_u119)(NI32 errorCode_p0, NimStringV2 additionalInfo_p1);
N_LIB_PRIVATE N_NIMCALL(NI32, osLastError__stdZoserrors_u122)(void);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, dollar___stdZprivateZoscommon_u94)(tyTuple__UV3llMMYFckfui8YMBuUZA* x_p0);
N_LIB_PRIVATE N_NIMCALL(void, eqdestroy___system_u2627)(NimStringV2 dest_p0);
N_LIB_PRIVATE N_NIMCALL(void, alignedDealloc)(void* p_p0, NI align_p1);
N_LIB_PRIVATE N_NIMCALL(void, setLen__stdZenvvars_u103)(tySequence__4eQHGndY6XBYpFOH09apV8Q* s_p0, NI newlen_p1);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, eqdup___system_u2633)(NimStringV2 src_p0);
static N_INLINE(NIM_BOOL, sameSeqPayload)(void* x_p0, void* y_p1);
extern NCSTRING* environ;
extern NIM_BOOL nimInErrorMode__system_u4302;
N_LIB_PRIVATE N_NIMCALL(NCSTRING, getEnvImpl__stdZenvvars_u13)(NCSTRING env_p0) {
	NCSTRING result;
	result = getenv(env_p0);
	return result;
}
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringV2 s_p0) {
	NCSTRING result;
	{
		if (!(s_p0.len == ((NI)0))) goto LA3_;
		result = "";
	}
	goto LA1_;
LA3_: ;
	{
		result = ((NCSTRING) ((*s_p0.p).data));
	}
LA1_: ;
	return result;
}
static N_INLINE(NIM_BOOL, eqeq___system_u8371)(NCSTRING x_p0, NCSTRING y_p1) {
	NIM_BOOL result;
	{
		if (!(((void*) (x_p0)) == ((void*) (y_p1)))) goto LA3_;
		result = NIM_TRUE;
	}
	goto LA1_;
LA3_: ;
	{
		NIM_BOOL T6_;
		T6_ = (NIM_BOOL)0;
		T6_ = (((void*) (x_p0)) == NIM_NIL);
		if (T6_) goto LA7_;
		T6_ = (((void*) (y_p1)) == NIM_NIL);
LA7_: ;
		if (!T6_) goto LA8_;
		result = NIM_FALSE;
	}
	goto LA1_;
LA8_: ;
	{
		int T11_;
		T11_ = (int)0;
		T11_ = strcmp(x_p0, y_p1);
		result = (T11_ == ((NI32)0));
	}
LA1_: ;
	return result;
}
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (&nimInErrorMode__system_u4302);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, getEnv__stdZenvvars_u16)(NimStringV2 key_p0, NimStringV2 default_p1) {
	NimStringV2 result;
	NCSTRING env_1;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result.len = 0; result.p = NIM_NIL;
	env_1 = getEnvImpl__stdZenvvars_u13(nimToCStringConv(key_p0));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = eqeq___system_u8371(env_1, ((NCSTRING) NIM_NIL));
		if (!T3_) goto LA4_;
		eqcopy___system_u2630((&result), default_p1);
	}
	goto LA1_;
LA4_: ;
	{
		result = cstrToNimstr(env_1);
	}
LA1_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, putEnv__stdZenvvars_u24)(NimStringV2 key_p0, NimStringV2 val_p1) {
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	{
		int T3_;
		NimStringV2 colontmpD_;
		NI32 T7_;
		tyTuple__UV3llMMYFckfui8YMBuUZA T8_;
		T3_ = (int)0;
		T3_ = setenv(nimToCStringConv(key_p0), nimToCStringConv(val_p1), ((NI32)1));
		if (!!((T3_ == ((NI32)0)))) goto LA4_;
		colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
		T7_ = (NI32)0;
		T7_ = osLastError__stdZoserrors_u122();
		if (NIM_UNLIKELY(*nimErr_)) goto LA6_;
		T8_.Field0 = key_p0;
		T8_.Field1 = val_p1;
		colontmpD_ = dollar___stdZprivateZoscommon_u94((&T8_));
		if (NIM_UNLIKELY(*nimErr_)) goto LA6_;
		raiseOSError__stdZoserrors_u119(T7_, colontmpD_);
		if (NIM_UNLIKELY(*nimErr_)) goto LA6_;
		{
			LA6_:;
		}
		{
			eqdestroy___system_u2627(colontmpD_);
		}
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA4_: ;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, existsEnv__stdZenvvars_u21)(NimStringV2 key_p0) {
	NIM_BOOL result;
	NCSTRING T1_;
	NIM_BOOL T2_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NIM_BOOL)0;
	T1_ = (NCSTRING)0;
	T1_ = getEnvImpl__stdZenvvars_u13(nimToCStringConv(key_p0));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	T2_ = (NIM_BOOL)0;
	T2_ = eqeq___system_u8371(T1_, ((NCSTRING) NIM_NIL));
	result = !(T2_);
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, delEnv__stdZenvvars_u30)(NimStringV2 key_p0) {
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	{
		int T3_;
		NI32 T6_;
		T3_ = (int)0;
		T3_ = unsetenv(nimToCStringConv(key_p0));
		if (!!((T3_ == ((NI32)0)))) goto LA4_;
		T6_ = (NI32)0;
		T6_ = osLastError__stdZoserrors_u122();
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		raiseOSError__stdZoserrors_u119(T6_, key_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA4_: ;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(void, eqdestroy___stdZenvvars_u82)(tySequence__4eQHGndY6XBYpFOH09apV8Q dest_p0) {
	NI colontmp_;
	colontmp_ = ((NI)0);
	{
		while (1) {
			NI T3_;
			T3_ = dest_p0.len;
			if (!(colontmp_ < T3_)) goto LA2;
			eqdestroy___system_u2627(dest_p0.p->data[colontmp_].Field0);
			eqdestroy___system_u2627(dest_p0.p->data[colontmp_].Field1);
			colontmp_ += ((NI)1);
		} LA2: ;
	}
	if (dest_p0.p && !(dest_p0.p->cap & NIM_STRLIT_FLAG)) {
 alignedDealloc(dest_p0.p, NIM_ALIGNOF(tyTuple__UV3llMMYFckfui8YMBuUZA));
}
}
N_LIB_PRIVATE N_NIMCALL(tySequence__4eQHGndY6XBYpFOH09apV8Q, eqdup___stdZenvvars_u88)(tySequence__4eQHGndY6XBYpFOH09apV8Q src_p0) {
	tySequence__4eQHGndY6XBYpFOH09apV8Q result;
	NI T1_;
	NI colontmp_;
	result.len = 0; result.p = NIM_NIL;
	T1_ = src_p0.len;
	setLen__stdZenvvars_u103((&result), T1_);
	colontmp_ = ((NI)0);
	{
		while (1) {
			NI T4_;
			T4_ = result.len;
			if (!(colontmp_ < T4_)) goto LA3;
			result.p->data[colontmp_].Field0 = eqdup___system_u2633(src_p0.p->data[colontmp_].Field0);
			result.p->data[colontmp_].Field1 = eqdup___system_u2633(src_p0.p->data[colontmp_].Field1);
			colontmp_ += ((NI)1);
		} LA3: ;
	}
	return result;
}
static N_INLINE(NIM_BOOL, sameSeqPayload)(void* x_p0, void* y_p1) {
	NIM_BOOL result;
	result = ((*((tyObject_NimRawSeq__Tvl1urqmI1tXqzkHPbWVJQ*) (x_p0))).p == (*((tyObject_NimRawSeq__Tvl1urqmI1tXqzkHPbWVJQ*) (y_p1))).p);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, eqcopy___stdZenvvars_u85)(tySequence__4eQHGndY6XBYpFOH09apV8Q* dest_p0, tySequence__4eQHGndY6XBYpFOH09apV8Q src_p1) {
	NI T6_;
	NI colontmp_;
{	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = sameSeqPayload(dest_p0, (&src_p1));
		if (!T3_) goto LA4_;
		goto BeforeRet_;
	}
LA4_: ;
	T6_ = src_p1.len;
	setLen__stdZenvvars_u103((&(*dest_p0)), T6_);
	colontmp_ = ((NI)0);
	{
		while (1) {
			NI T9_;
			T9_ = (*dest_p0).len;
			if (!(colontmp_ < T9_)) goto LA8;
			eqcopy___system_u2630((&(*dest_p0).p->data[colontmp_].Field0), src_p1.p->data[colontmp_].Field0);
			eqcopy___system_u2630((&(*dest_p0).p->data[colontmp_].Field1), src_p1.p->data[colontmp_].Field1);
			colontmp_ += ((NI)1);
		} LA8: ;
	}
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(void, eqwasMoved___stdZenvvars_u79)(tySequence__4eQHGndY6XBYpFOH09apV8Q* dest_p0) {
	(*dest_p0).len = 0; (*dest_p0).p = NIM_NIL;
}
