/* Generated by Nim Compiler v0.12.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 Tnode227809 Tnode227809;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Ttype227847 Ttype227847;
typedef struct Tlineinfo192352 Tlineinfo192352;
typedef struct Tsym227841 Tsym227841;
typedef struct Tident200021 Tident200021;
typedef struct Tnodeseq227803 Tnodeseq227803;
typedef struct Tllstream215204 Tllstream215204;
typedef struct Tidobj200015 Tidobj200015;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Ttypeseq227843 Ttypeseq227843;
typedef struct Tloc227823 Tloc227823;
typedef struct Ropeobj178009 Ropeobj178009;
typedef struct Tscope227835 Tscope227835;
typedef struct TY227944 TY227944;
typedef struct Tstrtable227813 Tstrtable227813;
typedef struct Tsymseq227811 Tsymseq227811;
typedef struct Tlib227827 Tlib227827;
typedef struct Tinstantiation227831 Tinstantiation227831;
typedef struct Tlistentry143022 Tlistentry143022;
typedef struct TY227932 TY227932;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Tlineinfo192352  {
NI16 line;
NI16 col;
NI32 fileindex;
};
struct  Tnode227809  {
Ttype227847* typ;
Tlineinfo192352 info;
NU16 flags;
NU8 kind;
union{
struct {NI64 intval;
} S1;
struct {NF floatval;
} S2;
struct {NimStringDesc* strval;
} S3;
struct {Tsym227841* sym;
} S4;
struct {Tident200021* ident;
} S5;
struct {Tnodeseq227803* sons;
} S6;
} kindU;
NimStringDesc* comment;
};
typedef NU8 TY215407[32];
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  Tidobj200015  {
  TNimObject Sup;
NI id;
};
struct  Tloc227823  {
NU8 k;
NU8 s;
NU16 flags;
Ttype227847* t;
Ropeobj178009* r;
Ropeobj178009* heaproot;
};
struct  Ttype227847  {
  Tidobj200015 Sup;
NU8 kind;
NU8 callconv;
NU32 flags;
Ttypeseq227843* sons;
Tnode227809* n;
Tsym227841* owner;
Tsym227841* sym;
Tsym227841* destructor;
Tsym227841* deepcopy;
Tsym227841* assignment;
NI64 size;
NI16 align;
NI16 locklevel;
Tloc227823 loc;
};
struct  Tstrtable227813  {
NI counter;
Tsymseq227811* data;
};
struct  Tsym227841  {
  Tidobj200015 Sup;
NU8 kind;
union{
struct {Ttypeseq227843* typeinstcache;
Tscope227835* typscope;
} S1;
struct {TY227944* procinstcache;
Tsym227841* gcunsafetyreason;
} S2;
struct {TY227944* usedgenerics;
Tstrtable227813 tab;
} S3;
struct {Tsym227841* guard;
NI bitsize;
} S4;
} kindU;
NU8 magic;
Ttype227847* typ;
Tident200021* name;
Tlineinfo192352 info;
Tsym227841* owner;
NU32 flags;
Tnode227809* ast;
NU32 options;
NI position;
NI offset;
Tloc227823 loc;
Tlib227827* annex;
Tnode227809* constraint;
};
struct  Tident200021  {
  Tidobj200015 Sup;
NimStringDesc* s;
Tident200021* next;
NI h;
};
struct  Tllstream215204  {
  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  Ropeobj178009  {
  TNimObject Sup;
Ropeobj178009* left;
Ropeobj178009* right;
NI length;
NimStringDesc* data;
};
struct  Tscope227835  {
NI depthlevel;
Tstrtable227813 symbols;
Tnodeseq227803* usingsyms;
Tscope227835* parent;
};
struct  Tlistentry143022  {
  TNimObject Sup;
Tlistentry143022* prev;
Tlistentry143022* next;
};
struct  Tlib227827  {
  Tlistentry143022 Sup;
NU8 kind;
NIM_BOOL generated;
NIM_BOOL isoverriden;
Ropeobj178009* name;
Tnode227809* path;
};
struct  Tinstantiation227831  {
Tsym227841* sym;
Ttypeseq227843* concretetypes;
TY227932* usedby;
NI compilesid;
};
struct Tnodeseq227803 {
  TGenericSeq Sup;
  Tnode227809* data[SEQ_DECL_SIZE];
};
struct Ttypeseq227843 {
  TGenericSeq Sup;
  Ttype227847* data[SEQ_DECL_SIZE];
};
struct TY227944 {
  TGenericSeq Sup;
  Tinstantiation227831* data[SEQ_DECL_SIZE];
};
struct Tsymseq227811 {
  TGenericSeq Sup;
  Tsym227841* data[SEQ_DECL_SIZE];
};
struct TY227932 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
N_NIMCALL(Tnode227809*, getarg_253057)(Tnode227809* n, NimStringDesc* name, NI pos);
N_NIMCALL(NI, sonslen_230387)(Tnode227809* n);
N_NIMCALL(void, invalidpragma_253047)(Tnode227809* n);
N_NIMCALL(void, localerror_198128)(Tlineinfo192352 info, NU16 msg, NimStringDesc* arg);
N_NIMCALL(NimStringDesc*, rendertree_249059)(Tnode227809* n, NU8 renderflags);
N_NIMCALL(NIM_BOOL, identeq_200484)(Tident200021* id, NimStringDesc* name);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(NimStringDesc*, strarg_253029)(Tnode227809* n, NimStringDesc* name, NI pos, NimStringDesc* default_253034);
N_NIMCALL(NIM_BOOL, boolarg_253038)(Tnode227809* n, NimStringDesc* name, NI pos, NIM_BOOL default_253043);
N_NIMCALL(Tllstream215204*, llstreamopen_215220)(NimStringDesc* data);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(NimStringDesc*, rawNewString)(NI cap);
N_NIMCALL(NIM_BOOL, llstreamreadline_215610)(Tllstream215204* s, NimStringDesc** line);
N_NIMCALL(NimStringDesc*, nsuStrip)(NimStringDesc* s, NIM_BOOL leading, NIM_BOOL trailing, TY215407 chars);
N_NIMCALL(NIM_BOOL, nsuStartsWith)(NimStringDesc* s, NimStringDesc* prefix);
N_NIMCALL(void, llstreamwriteln_215686)(Tllstream215204* s, NimStringDesc* data);
N_NIMCALL(void, llstreamclose_215310)(Tllstream215204* s);
N_NIMCALL(NimStringDesc*, nsuReplaceStr)(NimStringDesc* s, NimStringDesc* sub, NimStringDesc* by);
STRING_LITERAL(TMP1516, "startswith", 10);
STRING_LITERAL(TMP1517, "", 0);
STRING_LITERAL(TMP1518, "true", 4);
STRING_LITERAL(TMP1519, "false", 5);
STRING_LITERAL(TMP1520, "leading", 7);
STRING_LITERAL(TMP1521, "trailing", 8);
static NIM_CONST TY215407 TMP1522 = {
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(TMP1523, "sub", 3);
STRING_LITERAL(TMP1524, "by", 2);

N_NIMCALL(void, invalidpragma_253047)(Tnode227809* n) {
	NimStringDesc* LOC1;
	LOC1 = 0;
	LOC1 = rendertree_249059(n, 4);
	localerror_198128((*n).info, ((NU16) 167), LOC1);
}

N_NIMCALL(Tnode227809*, getarg_253057)(Tnode227809* n, NimStringDesc* name, NI pos) {
	Tnode227809* result;
{	result = 0;
	result = NIM_NIL;
	{
		if (!((*n).kind >= ((NU8) 1) && (*n).kind <= ((NU8) 23))) goto LA3;
		goto BeforeRet;
	}
	LA3: ;
	{
		NI i_253086;
		NI HEX3Atmp_253115;
		NI LOC6;
		NI res_253118;
		i_253086 = 0;
		HEX3Atmp_253115 = 0;
		LOC6 = 0;
		LOC6 = sonslen_230387(n);
		HEX3Atmp_253115 = (NI)(LOC6 - ((NI) 1));
		res_253118 = ((NI) 1);
		{
			while (1) {
				if (!(res_253118 <= HEX3Atmp_253115)) goto LA8;
				i_253086 = res_253118;
				{
					if (!((*(*n).kindU.S6.sons->data[i_253086]).kind == ((NU8) 33))) goto LA11;
					{
						if (!!(((*(*(*n).kindU.S6.sons->data[i_253086]).kindU.S6.sons->data[((NI) 0)]).kind == ((NU8) 2)))) goto LA15;
						invalidpragma_253047(n);
					}
					LA15: ;
					{
						NIM_BOOL LOC19;
						LOC19 = 0;
						LOC19 = identeq_200484((*(*(*n).kindU.S6.sons->data[i_253086]).kindU.S6.sons->data[((NI) 0)]).kindU.S5.ident, name);
						if (!LOC19) goto LA20;
						result = (*(*n).kindU.S6.sons->data[i_253086]).kindU.S6.sons->data[((NI) 1)];
						goto BeforeRet;
					}
					LA20: ;
				}
				goto LA9;
				LA11: ;
				{
					if (!(i_253086 == pos)) goto LA23;
					result = (*n).kindU.S6.sons->data[i_253086];
					goto BeforeRet;
				}
				goto LA9;
				LA23: ;
				LA9: ;
				res_253118 += ((NI) 1);
			} LA8: ;
		}
	}
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_CHAR, chararg_253020)(Tnode227809* n, NimStringDesc* name, NI pos, NIM_CHAR default_253025) {
	NIM_CHAR result;
	Tnode227809* x;
	result = 0;
	x = getarg_253057(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = default_253025;
	}
	goto LA1;
	LA3: ;
	{
		if (!((*x).kind == ((NU8) 5))) goto LA6;
		result = ((NIM_CHAR) (((NI) (((NI) ((*x).kindU.S1.intval))))));
	}
	goto LA1;
	LA6: ;
	{
		invalidpragma_253047(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NimStringDesc*, strarg_253029)(Tnode227809* n, NimStringDesc* name, NI pos, NimStringDesc* default_253034) {
	NimStringDesc* result;
	Tnode227809* x;
	result = 0;
	x = getarg_253057(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = copyString(default_253034);
	}
	goto LA1;
	LA3: ;
	{
		if (!((*x).kind >= ((NU8) 20) && (*x).kind <= ((NU8) 22))) goto LA6;
		result = copyString((*x).kindU.S3.strval);
	}
	goto LA1;
	LA6: ;
	{
		invalidpragma_253047(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NIM_BOOL, boolarg_253038)(Tnode227809* n, NimStringDesc* name, NI pos, NIM_BOOL default_253043) {
	NIM_BOOL result;
	Tnode227809* x;
	result = 0;
	x = getarg_253057(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = default_253043;
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC6;
		LOC6 = 0;
		LOC6 = ((*x).kind == ((NU8) 2));
		if (!(LOC6)) goto LA7;
		LOC6 = identeq_200484((*x).kindU.S5.ident, ((NimStringDesc*) &TMP1518));
		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_200484((*x).kindU.S5.ident, ((NimStringDesc*) &TMP1519));
		LA12: ;
		if (!LOC11) goto LA13;
		result = NIM_FALSE;
	}
	goto LA1;
	LA13: ;
	{
		invalidpragma_253047(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(Tllstream215204*, filterstrip_253012)(Tllstream215204* stdin_253014, NimStringDesc* filename, Tnode227809* call) {
	Tllstream215204* result;
	NimStringDesc* pattern;
	NIM_BOOL leading;
	NIM_BOOL trailing;
	NimStringDesc* line;
	result = 0;
	pattern = strarg_253029(call, ((NimStringDesc*) &TMP1516), ((NI) 1), ((NimStringDesc*) &TMP1517));
	leading = boolarg_253038(call, ((NimStringDesc*) &TMP1520), ((NI) 2), NIM_TRUE);
	trailing = boolarg_253038(call, ((NimStringDesc*) &TMP1521), ((NI) 3), NIM_TRUE);
	result = llstreamopen_215220(((NimStringDesc*) &TMP1517));
	line = rawNewString(((NI) 80));
	{
		while (1) {
			NIM_BOOL LOC3;
			NimStringDesc* stripped;
			LOC3 = 0;
			LOC3 = llstreamreadline_215610(stdin_253014, (&line));
			if (!LOC3) goto LA2;
			stripped = nsuStrip(line, leading, trailing, TMP1522);
			{
				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_215686(result, stripped);
			}
			goto LA4;
			LA8: ;
			{
				llstreamwriteln_215686(result, line);
			}
			LA4: ;
		} LA2: ;
	}
	llstreamclose_215310(stdin_253014);
	return result;
}

N_NIMCALL(Tllstream215204*, filterreplace_253004)(Tllstream215204* stdin_253006, NimStringDesc* filename, Tnode227809* call) {
	Tllstream215204* result;
	NimStringDesc* sub;
	NimStringDesc* by;
	NimStringDesc* line;
	result = 0;
	sub = strarg_253029(call, ((NimStringDesc*) &TMP1523), ((NI) 1), ((NimStringDesc*) &TMP1517));
	{
		if (!((sub ? sub->Sup.len : 0) == ((NI) 0))) goto LA3;
		invalidpragma_253047(call);
	}
	LA3: ;
	by = strarg_253029(call, ((NimStringDesc*) &TMP1524), ((NI) 2), ((NimStringDesc*) &TMP1517));
	result = llstreamopen_215220(((NimStringDesc*) &TMP1517));
	line = rawNewString(((NI) 80));
	{
		while (1) {
			NIM_BOOL LOC7;
			NimStringDesc* LOC8;
			LOC7 = 0;
			LOC7 = llstreamreadline_215610(stdin_253006, (&line));
			if (!LOC7) goto LA6;
			LOC8 = 0;
			LOC8 = nsuReplaceStr(line, sub, by);
			llstreamwriteln_215686(result, LOC8);
		} LA6: ;
	}
	llstreamclose_215310(stdin_253006);
	return result;
}
NIM_EXTERNC N_NOINLINE(void, compiler_filtersInit000)(void) {
}

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

