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

#include "nimbase.h"
#include <stdio.h>
typedef struct Tnode216790 Tnode216790;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Ttype216828 Ttype216828;
typedef struct Tlineinfo184337 Tlineinfo184337;
typedef struct Tsym216822 Tsym216822;
typedef struct Tident191012 Tident191012;
typedef struct Tnodeseq216784 Tnodeseq216784;
typedef struct Tllstream204204 Tllstream204204;
typedef struct Tidobj191006 Tidobj191006;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Ttypeseq216824 Ttypeseq216824;
typedef struct Tloc216804 Tloc216804;
typedef struct Ropeobj172006 Ropeobj172006;
typedef struct Tscope216816 Tscope216816;
typedef struct TY216925 TY216925;
typedef struct Tstrtable216794 Tstrtable216794;
typedef struct Tsymseq216792 Tsymseq216792;
typedef struct Tlib216808 Tlib216808;
typedef struct Tinstantiation216812 Tinstantiation216812;
typedef struct Tlistentry138010 Tlistentry138010;
typedef struct TY216913 TY216913;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Tlineinfo184337  {
NI16 line;
NI16 col;
NI32 fileindex;
};
struct  Tnode216790  {
Ttype216828* typ;
Tlineinfo184337 info;
NU16 flags;
NU8 kind;
union{
struct {NI64 intval;
} S1;
struct {NF floatval;
} S2;
struct {NimStringDesc* strval;
} S3;
struct {Tsym216822* sym;
} S4;
struct {Tident191012* ident;
} S5;
struct {Tnodeseq216784* sons;
} S6;
} kindU;
NimStringDesc* comment;
};
typedef NU8 TY204404[32];
typedef N_NIMCALL_PTR(void, TY3489) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3494) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3489 marker;
TY3494 deepcopy;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  Tidobj191006  {
  TNimObject Sup;
NI id;
};
struct  Tloc216804  {
NU8 k;
NU8 s;
NU16 flags;
Ttype216828* t;
Ropeobj172006* r;
Ropeobj172006* heaproot;
};
struct  Ttype216828  {
  Tidobj191006 Sup;
NU8 kind;
NU8 callconv;
NU32 flags;
Ttypeseq216824* sons;
Tnode216790* n;
Tsym216822* owner;
Tsym216822* sym;
Tsym216822* destructor;
Tsym216822* deepcopy;
Tsym216822* assignment;
NI64 size;
NI16 align;
NI16 locklevel;
Tloc216804 loc;
};
struct  Tstrtable216794  {
NI counter;
Tsymseq216792* data;
};
struct  Tsym216822  {
  Tidobj191006 Sup;
NU8 kind;
union{
struct {Ttypeseq216824* typeinstcache;
Tscope216816* typscope;
} S1;
struct {TY216925* procinstcache;
Tsym216822* gcunsafetyreason;
} S2;
struct {TY216925* usedgenerics;
Tstrtable216794 tab;
} S3;
struct {Tsym216822* guard;
NI bitsize;
} S4;
} kindU;
NU8 magic;
Ttype216828* typ;
Tident191012* name;
Tlineinfo184337 info;
Tsym216822* owner;
NU32 flags;
Tnode216790* ast;
NU32 options;
NI position;
NI offset;
Tloc216804 loc;
Tlib216808* annex;
Tnode216790* constraint;
};
struct  Tident191012  {
  Tidobj191006 Sup;
NimStringDesc* s;
Tident191012* next;
NI h;
};
struct  Tllstream204204  {
  TNimObject Sup;
NU8 kind;
FILE* f;
NimStringDesc* s;
NI rd;
NI wr;
NI lineoffset;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  Ropeobj172006  {
  TNimObject Sup;
Ropeobj172006* left;
Ropeobj172006* right;
NI length;
NimStringDesc* data;
};
struct  Tscope216816  {
NI depthlevel;
Tstrtable216794 symbols;
Tnodeseq216784* usingsyms;
Tscope216816* parent;
};
struct  Tlistentry138010  {
  TNimObject Sup;
Tlistentry138010* prev;
Tlistentry138010* next;
};
struct  Tlib216808  {
  Tlistentry138010 Sup;
NU8 kind;
NIM_BOOL generated;
NIM_BOOL isoverriden;
Ropeobj172006* name;
Tnode216790* path;
};
struct  Tinstantiation216812  {
Tsym216822* sym;
Ttypeseq216824* concretetypes;
TY216913* usedby;
NI compilesid;
};
struct Tnodeseq216784 {
  TGenericSeq Sup;
  Tnode216790* data[SEQ_DECL_SIZE];
};
struct Ttypeseq216824 {
  TGenericSeq Sup;
  Ttype216828* data[SEQ_DECL_SIZE];
};
struct TY216925 {
  TGenericSeq Sup;
  Tinstantiation216812* data[SEQ_DECL_SIZE];
};
struct Tsymseq216792 {
  TGenericSeq Sup;
  Tsym216822* data[SEQ_DECL_SIZE];
};
struct TY216913 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
N_NIMCALL(Tnode216790*, getarg_238033)(Tnode216790* n, NimStringDesc* name, NI pos);
N_NIMCALL(NI, sonslen_219351)(Tnode216790* n);
N_NIMCALL(void, invalidpragma_238029)(Tnode216790* n);
N_NIMCALL(void, localerror_189080)(Tlineinfo184337 info, NU16 msg, NimStringDesc* arg);
N_NIMCALL(NimStringDesc*, rendertree_235044)(Tnode216790* n, NU8 renderflags);
N_NIMCALL(NIM_BOOL, identeq_191450)(Tident191012* id, NimStringDesc* name);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(NimStringDesc*, strarg_238017)(Tnode216790* n, NimStringDesc* name, NI pos, NimStringDesc* default_238022);
N_NIMCALL(NIM_BOOL, boolarg_238023)(Tnode216790* n, NimStringDesc* name, NI pos, NIM_BOOL default_238028);
N_NIMCALL(Tllstream204204*, llstreamopen_204217)(NimStringDesc* data);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(NimStringDesc*, rawNewString)(NI cap);
N_NIMCALL(NIM_BOOL, llstreamreadline_204550)(Tllstream204204* s, NimStringDesc** line);
N_NIMCALL(NimStringDesc*, nsuStrip)(NimStringDesc* s, NIM_BOOL leading, NIM_BOOL trailing, TY204404 chars);
N_NIMCALL(NIM_BOOL, nsuStartsWith)(NimStringDesc* s, NimStringDesc* prefix);
N_NIMCALL(void, llstreamwriteln_204608)(Tllstream204204* s, NimStringDesc* data);
N_NIMCALL(void, llstreamclose_204277)(Tllstream204204* s);
N_NIMCALL(NimStringDesc*, nsuReplaceStr)(NimStringDesc* s, NimStringDesc* sub, NimStringDesc* by);
STRING_LITERAL(TMP1552, "startswith", 10);
STRING_LITERAL(TMP1553, "", 0);
STRING_LITERAL(TMP1554, "true", 4);
STRING_LITERAL(TMP1555, "false", 5);
STRING_LITERAL(TMP1556, "leading", 7);
STRING_LITERAL(TMP1557, "trailing", 8);
static NIM_CONST TY204404 TMP1558 = {
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(TMP1559, "sub", 3);
STRING_LITERAL(TMP1560, "by", 2);

N_NIMCALL(void, invalidpragma_238029)(Tnode216790* n) {
	NimStringDesc* LOC1;
	LOC1 = 0;
	LOC1 = rendertree_235044(n, 4);
	localerror_189080((*n).info, ((NU16) 167), LOC1);
}

N_NIMCALL(Tnode216790*, getarg_238033)(Tnode216790* n, NimStringDesc* name, NI pos) {
	Tnode216790* result;
{	result = 0;
	result = NIM_NIL;
	{
		if (!((*n).kind >= ((NU8) 1) && (*n).kind <= ((NU8) 23))) goto LA3;
		goto BeforeRet;
	}
	LA3: ;
	{
		NI i_238061;
		NI HEX3Atmp_238090;
		NI LOC6;
		NI res_238093;
		i_238061 = 0;
		HEX3Atmp_238090 = 0;
		LOC6 = 0;
		LOC6 = sonslen_219351(n);
		HEX3Atmp_238090 = (NI)(LOC6 - ((NI) 1));
		res_238093 = ((NI) 1);
		{
			while (1) {
				if (!(res_238093 <= HEX3Atmp_238090)) goto LA8;
				i_238061 = res_238093;
				{
					if (!((*(*n).kindU.S6.sons->data[i_238061]).kind == ((NU8) 33))) goto LA11;
					{
						if (!!(((*(*(*n).kindU.S6.sons->data[i_238061]).kindU.S6.sons->data[((NI) 0)]).kind == ((NU8) 2)))) goto LA15;
						invalidpragma_238029(n);
					}
					LA15: ;
					{
						NIM_BOOL LOC19;
						LOC19 = 0;
						LOC19 = identeq_191450((*(*(*n).kindU.S6.sons->data[i_238061]).kindU.S6.sons->data[((NI) 0)]).kindU.S5.ident, name);
						if (!LOC19) goto LA20;
						result = (*(*n).kindU.S6.sons->data[i_238061]).kindU.S6.sons->data[((NI) 1)];
						goto BeforeRet;
					}
					LA20: ;
				}
				goto LA9;
				LA11: ;
				{
					if (!(i_238061 == pos)) goto LA23;
					result = (*n).kindU.S6.sons->data[i_238061];
					goto BeforeRet;
				}
				goto LA9;
				LA23: ;
				LA9: ;
				res_238093 += ((NI) 1);
			} LA8: ;
		}
	}
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_CHAR, chararg_238011)(Tnode216790* n, NimStringDesc* name, NI pos, NIM_CHAR default_238016) {
	NIM_CHAR result;
	Tnode216790* x;
	result = 0;
	x = getarg_238033(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = default_238016;
	}
	goto LA1;
	LA3: ;
	{
		if (!((*x).kind == ((NU8) 5))) goto LA6;
		result = ((NIM_CHAR) (((NI) (((NI) ((*x).kindU.S1.intval))))));
	}
	goto LA1;
	LA6: ;
	{
		invalidpragma_238029(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NimStringDesc*, strarg_238017)(Tnode216790* n, NimStringDesc* name, NI pos, NimStringDesc* default_238022) {
	NimStringDesc* result;
	Tnode216790* x;
	result = 0;
	x = getarg_238033(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = copyString(default_238022);
	}
	goto LA1;
	LA3: ;
	{
		if (!((*x).kind >= ((NU8) 20) && (*x).kind <= ((NU8) 22))) goto LA6;
		result = copyString((*x).kindU.S3.strval);
	}
	goto LA1;
	LA6: ;
	{
		invalidpragma_238029(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NIM_BOOL, boolarg_238023)(Tnode216790* n, NimStringDesc* name, NI pos, NIM_BOOL default_238028) {
	NIM_BOOL result;
	Tnode216790* x;
	result = 0;
	x = getarg_238033(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = default_238028;
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC6;
		LOC6 = 0;
		LOC6 = ((*x).kind == ((NU8) 2));
		if (!(LOC6)) goto LA7;
		LOC6 = identeq_191450((*x).kindU.S5.ident, ((NimStringDesc*) &TMP1554));
		LA7: ;
		if (!LOC6) goto LA8;
		result = NIM_TRUE;
	}
	goto LA1;
	LA8: ;
	{
		NIM_BOOL LOC11;
		LOC11 = 0;
		LOC11 = ((*x).kind == ((NU8) 2));
		if (!(LOC11)) goto LA12;
		LOC11 = identeq_191450((*x).kindU.S5.ident, ((NimStringDesc*) &TMP1555));
		LA12: ;
		if (!LOC11) goto LA13;
		result = NIM_FALSE;
	}
	goto LA1;
	LA13: ;
	{
		invalidpragma_238029(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(Tllstream204204*, filterstrip_238006)(Tllstream204204* stdin_238008, NimStringDesc* filename, Tnode216790* call) {
	Tllstream204204* result;
	NimStringDesc* pattern;
	NIM_BOOL leading;
	NIM_BOOL trailing;
	NimStringDesc* line;
	result = 0;
	pattern = strarg_238017(call, ((NimStringDesc*) &TMP1552), ((NI) 1), ((NimStringDesc*) &TMP1553));
	leading = boolarg_238023(call, ((NimStringDesc*) &TMP1556), ((NI) 2), NIM_TRUE);
	trailing = boolarg_238023(call, ((NimStringDesc*) &TMP1557), ((NI) 3), NIM_TRUE);
	result = llstreamopen_204217(((NimStringDesc*) &TMP1553));
	line = rawNewString(((NI) 80));
	{
		while (1) {
			NIM_BOOL LOC3;
			NimStringDesc* stripped;
			LOC3 = 0;
			LOC3 = llstreamreadline_204550(stdin_238008, (&line));
			if (!LOC3) goto LA2;
			stripped = nsuStrip(line, leading, trailing, TMP1558);
			{
				NIM_BOOL LOC6;
				LOC6 = 0;
				LOC6 = ((pattern ? pattern->Sup.len : 0) == ((NI) 0));
				if (LOC6) goto LA7;
				LOC6 = nsuStartsWith(stripped, pattern);
				LA7: ;
				if (!LOC6) goto LA8;
				llstreamwriteln_204608(result, stripped);
			}
			goto LA4;
			LA8: ;
			{
				llstreamwriteln_204608(result, line);
			}
			LA4: ;
		} LA2: ;
	}
	llstreamclose_204277(stdin_238008);
	return result;
}

N_NIMCALL(Tllstream204204*, filterreplace_238001)(Tllstream204204* stdin_238003, NimStringDesc* filename, Tnode216790* call) {
	Tllstream204204* result;
	NimStringDesc* sub;
	NimStringDesc* by;
	NimStringDesc* line;
	result = 0;
	sub = strarg_238017(call, ((NimStringDesc*) &TMP1559), ((NI) 1), ((NimStringDesc*) &TMP1553));
	{
		if (!((sub ? sub->Sup.len : 0) == ((NI) 0))) goto LA3;
		invalidpragma_238029(call);
	}
	LA3: ;
	by = strarg_238017(call, ((NimStringDesc*) &TMP1560), ((NI) 2), ((NimStringDesc*) &TMP1553));
	result = llstreamopen_204217(((NimStringDesc*) &TMP1553));
	line = rawNewString(((NI) 80));
	{
		while (1) {
			NIM_BOOL LOC7;
			NimStringDesc* LOC8;
			LOC7 = 0;
			LOC7 = llstreamreadline_204550(stdin_238003, (&line));
			if (!LOC7) goto LA6;
			LOC8 = 0;
			LOC8 = nsuReplaceStr(line, sub, by);
			llstreamwriteln_204608(result, LOC8);
		} LA6: ;
	}
	llstreamclose_204277(stdin_238003);
	return result;
}
NIM_EXTERNC N_NOINLINE(void, compiler_filtersInit000)(void) {
}

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

