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

#include "nimbase.h"
#include <stdio.h>
typedef struct Tnode290802 Tnode290802;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Ttype290840 Ttype290840;
typedef struct Tlineinfo189336 Tlineinfo189336;
typedef struct Tsym290834 Tsym290834;
typedef struct Tident197010 Tident197010;
typedef struct Tnodeseq290796 Tnodeseq290796;
typedef struct Tllstream280204 Tllstream280204;
typedef struct Tidobj197004 Tidobj197004;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Ttypeseq290836 Ttypeseq290836;
typedef struct TY290960 TY290960;
typedef struct Tloc290816 Tloc290816;
typedef struct Ropeobj177006 Ropeobj177006;
typedef struct TY290929 TY290929;
typedef struct Tstrtable290806 Tstrtable290806;
typedef struct Tsymseq290804 Tsymseq290804;
typedef struct Tlib290820 Tlib290820;
typedef struct TY290961 TY290961;
typedef struct Tinstantiation290824 Tinstantiation290824;
typedef struct Tlistentry147007 Tlistentry147007;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Tlineinfo189336  {
NI16 line;
NI16 col;
NI32 fileindex;
};
typedef NU16 Tnodeflag290427Set;
typedef NU8 Tnodekind290020;
struct  Tnode290802  {
Ttype290840* typ;
Tlineinfo189336 info;
Tnodeflag290427Set flags;
Tnodekind290020 kind;
union{
struct {NI64 intval;
} S1;
struct {NF floatval;
} S2;
struct {NimStringDesc* strval;
} S3;
struct {Tsym290834* sym;
} S4;
struct {Tident197010* ident;
} S5;
struct {Tnodeseq290796* sons;
} S6;
} kindU;
NimStringDesc* comment;
};
typedef NU16 Tmsgkind189002;
typedef NU8 Trenderflag309004Set;
typedef NU8 char136Set[32];
typedef NU8 Tnimkind3403;
typedef NU8 Tnimtypeflag3409Set;
typedef N_NIMCALL_PTR(void, TY3489) (void* p0, NI op0);
typedef N_NIMCALL_PTR(void*, TY3494) (void* p0);
struct  TNimType  {
NI size;
Tnimkind3403 kind;
Tnimtypeflag3409Set flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3489 marker;
TY3494 deepcopy;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  Tidobj197004  {
  TNimObject Sup;
NI id;
};
typedef NU8 Ttypekind290244;
typedef NU8 Tcallingconvention290002;
typedef NU32 Ttypeflag290431Set;
typedef NU8 Tlockind290808;
typedef NU8 Tstorageloc290812;
typedef NU16 Tlocflag290810Set;
struct  Tloc290816  {
Tlockind290808 k;
Tstorageloc290812 s;
Tlocflag290810Set flags;
Ttype290840* t;
Ropeobj177006* r;
};
struct  Ttype290840  {
  Tidobj197004 Sup;
Ttypekind290244 kind;
Tcallingconvention290002 callconv;
Ttypeflag290431Set flags;
Ttypeseq290836* sons;
Tnode290802* n;
Tsym290834* owner;
Tsym290834* sym;
Tsym290834* destructor;
Tsym290834* deepcopy;
Tsym290834* assignment;
TY290960* methods;
NI64 size;
NI16 align;
NI16 locklevel;
Tloc290816 loc;
};
typedef NU8 Tsymkind290435;
struct  Tstrtable290806  {
NI counter;
Tsymseq290804* data;
};
typedef NU16 Tmagic290524;
typedef NU32 Tsymflag290184Set;
typedef NU32 Toption168009Set;
struct  Tsym290834  {
  Tidobj197004 Sup;
Tsymkind290435 kind;
union{
struct {Ttypeseq290836* typeinstcache;
} S1;
struct {TY290929* procinstcache;
Tsym290834* gcunsafetyreason;
} S2;
struct {TY290929* usedgenerics;
Tstrtable290806 tab;
} S3;
struct {Tsym290834* guard;
NI bitsize;
} S4;
} kindU;
Tmagic290524 magic;
Ttype290840* typ;
Tident197010* name;
Tlineinfo189336 info;
Tsym290834* owner;
Tsymflag290184Set flags;
Tnode290802* ast;
Toption168009Set options;
NI position;
NI offset;
Tloc290816 loc;
Tlib290820* annex;
Tnode290802* constraint;
};
struct  Tident197010  {
  Tidobj197004 Sup;
NimStringDesc* s;
Tident197010* next;
NI h;
};
typedef NU8 Tllstreamkind280202;
struct  Tllstream280204  {
  TNimObject Sup;
Tllstreamkind280202 kind;
FILE* f;
NimStringDesc* s;
NI rd;
NI wr;
NI lineoffset;
};
typedef NU8 Tnimnodekind3405;
struct  TNimNode  {
Tnimnodekind3405 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct TY290961 {
NI Field0;
Tsym290834* Field1;
};
struct  Ropeobj177006  {
  TNimObject Sup;
Ropeobj177006* left;
Ropeobj177006* right;
NI length;
NimStringDesc* data;
};
struct  Tlistentry147007  {
  TNimObject Sup;
Tlistentry147007* prev;
Tlistentry147007* next;
};
typedef NU8 Tlibkind290818;
struct  Tlib290820  {
  Tlistentry147007 Sup;
Tlibkind290818 kind;
NIM_BOOL generated;
NIM_BOOL isoverriden;
Ropeobj177006* name;
Tnode290802* path;
};
struct  Tinstantiation290824  {
Tsym290834* sym;
Ttypeseq290836* concretetypes;
NI compilesid;
};
struct Tnodeseq290796 {
  TGenericSeq Sup;
  Tnode290802* data[SEQ_DECL_SIZE];
};
struct Ttypeseq290836 {
  TGenericSeq Sup;
  Ttype290840* data[SEQ_DECL_SIZE];
};
struct TY290960 {
  TGenericSeq Sup;
  TY290961 data[SEQ_DECL_SIZE];
};
struct TY290929 {
  TGenericSeq Sup;
  Tinstantiation290824* data[SEQ_DECL_SIZE];
};
struct Tsymseq290804 {
  TGenericSeq Sup;
  Tsym290834* data[SEQ_DECL_SIZE];
};
N_NIMCALL(Tnode290802*, getarg_313033_1413030668)(Tnode290802* n0, NimStringDesc* name0, NI pos0);
N_NIMCALL(NI, sonslen_293351_850551059)(Tnode290802* n0);
N_NIMCALL(void, invalidpragma_313029_1413030668)(Tnode290802* n0);
N_NIMCALL(void, localerror_194080_155036129)(Tlineinfo189336 info0, Tmsgkind189002 msg0, NimStringDesc* arg0);
N_NIMCALL(NimStringDesc*, rendertree_309044_382274130)(Tnode290802* n0, Trenderflag309004Set renderflags0);
N_NIMCALL(NIM_BOOL, identeq_197450_791273810)(Tident197010* id0, NimStringDesc* name0);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src0);
N_NIMCALL(NimStringDesc*, strarg_313017_1413030668)(Tnode290802* n0, NimStringDesc* name0, NI pos0, NimStringDesc* default_313022_1413030668);
N_NIMCALL(NIM_BOOL, boolarg_313023_1413030668)(Tnode290802* n0, NimStringDesc* name0, NI pos0, NIM_BOOL default_313028_1413030668);
N_NIMCALL(Tllstream280204*, llstreamopen_280218_597494479)(NimStringDesc* data0);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space0);
N_NIMCALL(NimStringDesc*, rawNewString)(NI cap0);
N_NIMCALL(NIM_BOOL, llstreamreadline_280550_597494479)(Tllstream280204* s0, NimStringDesc** line0);
N_NIMCALL(NimStringDesc*, nsuStrip)(NimStringDesc* s0, NIM_BOOL leading0, NIM_BOOL trailing0, char136Set chars0);
N_NIMCALL(NIM_BOOL, nsuStartsWith)(NimStringDesc* s0, NimStringDesc* prefix0);
N_NIMCALL(void, llstreamwriteln_280608_597494479)(Tllstream280204* s0, NimStringDesc* data0);
N_NIMCALL(void, llstreamclose_280278_597494479)(Tllstream280204* s0);
N_NIMCALL(NimStringDesc*, nsuReplaceStr)(NimStringDesc* s0, NimStringDesc* sub0, NimStringDesc* by0);
STRING_LITERAL(T1413030668_2, "startswith", 10);
STRING_LITERAL(T1413030668_3, "", 0);
STRING_LITERAL(T1413030668_4, "true", 4);
STRING_LITERAL(T1413030668_5, "false", 5);
STRING_LITERAL(T1413030668_6, "leading", 7);
STRING_LITERAL(T1413030668_7, "trailing", 8);
static NIM_CONST char136Set T1413030668_8 = {
0x00, 0x3E, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
;
STRING_LITERAL(T1413030668_9, "sub", 3);
STRING_LITERAL(T1413030668_10, "by", 2);

N_NIMCALL(void, invalidpragma_313029_1413030668)(Tnode290802* n0) {
	NimStringDesc* LOC1;
	LOC1 = (NimStringDesc*)0;
	LOC1 = rendertree_309044_382274130(n0, 4);
	localerror_194080_155036129((*n0).info, ((Tmsgkind189002) 167), LOC1);
}

N_NIMCALL(Tnode290802*, getarg_313033_1413030668)(Tnode290802* n0, NimStringDesc* name0, NI pos0) {
	Tnode290802* result0;
{	result0 = (Tnode290802*)0;
	result0 = NIM_NIL;
	{
		if (!((*n0).kind >= ((Tnodekind290020) 1) && (*n0).kind <= ((Tnodekind290020) 23))) goto LA3;
		goto BeforeRet;
	}
	LA3: ;
	{
		NI i_313061_1413030668;
		NI HEX3Atmp_313090_1413030668;
		NI LOC6;
		NI res_313093_1413030668;
		i_313061_1413030668 = (NI)0;
		HEX3Atmp_313090_1413030668 = (NI)0;
		LOC6 = (NI)0;
		LOC6 = sonslen_293351_850551059(n0);
		HEX3Atmp_313090_1413030668 = (NI)(LOC6 - ((NI) 1));
		res_313093_1413030668 = ((NI) 1);
		{
			while (1) {
				if (!(res_313093_1413030668 <= HEX3Atmp_313090_1413030668)) goto LA8;
				i_313061_1413030668 = res_313093_1413030668;
				{
					if (!((*(*n0).kindU.S6.sons->data[i_313061_1413030668]).kind == ((Tnodekind290020) 33))) goto LA11;
					{
						if (!!(((*(*(*n0).kindU.S6.sons->data[i_313061_1413030668]).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind290020) 2)))) goto LA15;
						invalidpragma_313029_1413030668(n0);
					}
					LA15: ;
					{
						NIM_BOOL LOC19;
						LOC19 = (NIM_BOOL)0;
						LOC19 = identeq_197450_791273810((*(*(*n0).kindU.S6.sons->data[i_313061_1413030668]).kindU.S6.sons->data[((NI) 0)]).kindU.S5.ident, name0);
						if (!LOC19) goto LA20;
						result0 = (*(*n0).kindU.S6.sons->data[i_313061_1413030668]).kindU.S6.sons->data[((NI) 1)];
						goto BeforeRet;
					}
					LA20: ;
				}
				goto LA9;
				LA11: ;
				{
					if (!(i_313061_1413030668 == pos0)) goto LA23;
					result0 = (*n0).kindU.S6.sons->data[i_313061_1413030668];
					goto BeforeRet;
				}
				goto LA9;
				LA23: ;
				LA9: ;
				res_313093_1413030668 += ((NI) 1);
			} LA8: ;
		}
	}
	}BeforeRet: ;
	return result0;
}

N_NIMCALL(NIM_CHAR, chararg_313011_1413030668)(Tnode290802* n0, NimStringDesc* name0, NI pos0, NIM_CHAR default_313016_1413030668) {
	NIM_CHAR result0;
	Tnode290802* x0;
	result0 = (NIM_CHAR)0;
	x0 = getarg_313033_1413030668(n0, name0, pos0);
	{
		if (!(x0 == NIM_NIL)) goto LA3;
		result0 = default_313016_1413030668;
	}
	goto LA1;
	LA3: ;
	{
		if (!((*x0).kind == ((Tnodekind290020) 5))) goto LA6;
		result0 = ((NIM_CHAR) (((NI) (((NI) ((*x0).kindU.S1.intval))))));
	}
	goto LA1;
	LA6: ;
	{
		invalidpragma_313029_1413030668(n0);
	}
	LA1: ;
	return result0;
}

N_NIMCALL(NimStringDesc*, strarg_313017_1413030668)(Tnode290802* n0, NimStringDesc* name0, NI pos0, NimStringDesc* default_313022_1413030668) {
	NimStringDesc* result0;
	Tnode290802* x0;
	result0 = (NimStringDesc*)0;
	x0 = getarg_313033_1413030668(n0, name0, pos0);
	{
		if (!(x0 == NIM_NIL)) goto LA3;
		result0 = copyString(default_313022_1413030668);
	}
	goto LA1;
	LA3: ;
	{
		if (!((*x0).kind >= ((Tnodekind290020) 20) && (*x0).kind <= ((Tnodekind290020) 22))) goto LA6;
		result0 = copyString((*x0).kindU.S3.strval);
	}
	goto LA1;
	LA6: ;
	{
		invalidpragma_313029_1413030668(n0);
	}
	LA1: ;
	return result0;
}

N_NIMCALL(NIM_BOOL, boolarg_313023_1413030668)(Tnode290802* n0, NimStringDesc* name0, NI pos0, NIM_BOOL default_313028_1413030668) {
	NIM_BOOL result0;
	Tnode290802* x0;
	result0 = (NIM_BOOL)0;
	x0 = getarg_313033_1413030668(n0, name0, pos0);
	{
		if (!(x0 == NIM_NIL)) goto LA3;
		result0 = default_313028_1413030668;
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC6;
		LOC6 = (NIM_BOOL)0;
		LOC6 = ((*x0).kind == ((Tnodekind290020) 2));
		if (!(LOC6)) goto LA7;
		LOC6 = identeq_197450_791273810((*x0).kindU.S5.ident, ((NimStringDesc*) &T1413030668_4));
		LA7: ;
		if (!LOC6) goto LA8;
		result0 = NIM_TRUE;
	}
	goto LA1;
	LA8: ;
	{
		NIM_BOOL LOC11;
		LOC11 = (NIM_BOOL)0;
		LOC11 = ((*x0).kind == ((Tnodekind290020) 2));
		if (!(LOC11)) goto LA12;
		LOC11 = identeq_197450_791273810((*x0).kindU.S5.ident, ((NimStringDesc*) &T1413030668_5));
		LA12: ;
		if (!LOC11) goto LA13;
		result0 = NIM_FALSE;
	}
	goto LA1;
	LA13: ;
	{
		invalidpragma_313029_1413030668(n0);
	}
	LA1: ;
	return result0;
}

N_NIMCALL(Tllstream280204*, filterstrip_313006_1413030668)(Tllstream280204* stdin_313008_1413030668, NimStringDesc* filename0, Tnode290802* call0) {
	Tllstream280204* result0;
	NimStringDesc* pattern0;
	NIM_BOOL leading0;
	NIM_BOOL trailing0;
	NimStringDesc* line0;
	result0 = (Tllstream280204*)0;
	pattern0 = strarg_313017_1413030668(call0, ((NimStringDesc*) &T1413030668_2), ((NI) 1), ((NimStringDesc*) &T1413030668_3));
	leading0 = boolarg_313023_1413030668(call0, ((NimStringDesc*) &T1413030668_6), ((NI) 2), NIM_TRUE);
	trailing0 = boolarg_313023_1413030668(call0, ((NimStringDesc*) &T1413030668_7), ((NI) 3), NIM_TRUE);
	result0 = llstreamopen_280218_597494479(((NimStringDesc*) &T1413030668_3));
	line0 = rawNewString(((NI) 80));
	{
		while (1) {
			NIM_BOOL LOC3;
			NimStringDesc* stripped0;
			LOC3 = (NIM_BOOL)0;
			LOC3 = llstreamreadline_280550_597494479(stdin_313008_1413030668, (&line0));
			if (!LOC3) goto LA2;
			stripped0 = nsuStrip(line0, leading0, trailing0, T1413030668_8);
			{
				NIM_BOOL LOC6;
				LOC6 = (NIM_BOOL)0;
				LOC6 = ((pattern0 ? pattern0->Sup.len : 0) == ((NI) 0));
				if (LOC6) goto LA7;
				LOC6 = nsuStartsWith(stripped0, pattern0);
				LA7: ;
				if (!LOC6) goto LA8;
				llstreamwriteln_280608_597494479(result0, stripped0);
			}
			goto LA4;
			LA8: ;
			{
				llstreamwriteln_280608_597494479(result0, line0);
			}
			LA4: ;
		} LA2: ;
	}
	llstreamclose_280278_597494479(stdin_313008_1413030668);
	return result0;
}

N_NIMCALL(Tllstream280204*, filterreplace_313001_1413030668)(Tllstream280204* stdin_313003_1413030668, NimStringDesc* filename0, Tnode290802* call0) {
	Tllstream280204* result0;
	NimStringDesc* sub0;
	NimStringDesc* by0;
	NimStringDesc* line0;
	result0 = (Tllstream280204*)0;
	sub0 = strarg_313017_1413030668(call0, ((NimStringDesc*) &T1413030668_9), ((NI) 1), ((NimStringDesc*) &T1413030668_3));
	{
		if (!((sub0 ? sub0->Sup.len : 0) == ((NI) 0))) goto LA3;
		invalidpragma_313029_1413030668(call0);
	}
	LA3: ;
	by0 = strarg_313017_1413030668(call0, ((NimStringDesc*) &T1413030668_10), ((NI) 2), ((NimStringDesc*) &T1413030668_3));
	result0 = llstreamopen_280218_597494479(((NimStringDesc*) &T1413030668_3));
	line0 = rawNewString(((NI) 80));
	{
		while (1) {
			NIM_BOOL LOC7;
			NimStringDesc* LOC8;
			LOC7 = (NIM_BOOL)0;
			LOC7 = llstreamreadline_280550_597494479(stdin_313003_1413030668, (&line0));
			if (!LOC7) goto LA6;
			LOC8 = (NimStringDesc*)0;
			LOC8 = nsuReplaceStr(line0, sub0, by0);
			llstreamwriteln_280608_597494479(result0, LOC8);
		} LA6: ;
	}
	llstreamclose_280278_597494479(stdin_313003_1413030668);
	return result0;
}
NIM_EXTERNC N_NOINLINE(void, compiler_filtersInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, compiler_filtersDatInit000)(void) {
}

