/* 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 <stdio.h>
typedef struct Tnode225809 Tnode225809;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Ttype225847 Ttype225847;
typedef struct Tlineinfo190352 Tlineinfo190352;
typedef struct Tsym225841 Tsym225841;
typedef struct Tident198021 Tident198021;
typedef struct Tnodeseq225803 Tnodeseq225803;
typedef struct Tllstream213204 Tllstream213204;
typedef struct Tidobj198015 Tidobj198015;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Ttypeseq225843 Ttypeseq225843;
typedef struct Tloc225823 Tloc225823;
typedef struct Ropeobj176009 Ropeobj176009;
typedef struct Tscope225835 Tscope225835;
typedef struct TY225944 TY225944;
typedef struct Tstrtable225813 Tstrtable225813;
typedef struct Tsymseq225811 Tsymseq225811;
typedef struct Tlib225827 Tlib225827;
typedef struct Tinstantiation225831 Tinstantiation225831;
typedef struct Tlistentry141022 Tlistentry141022;
typedef struct TY225932 TY225932;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Tlineinfo190352  {
NI16 line;
NI16 col;
NI32 fileindex;
};
struct  Tnode225809  {
Ttype225847* typ;
Tlineinfo190352 info;
NU16 flags;
NU8 kind;
union{
struct {NI64 intval;
} S1;
struct {NF floatval;
} S2;
struct {NimStringDesc* strval;
} S3;
struct {Tsym225841* sym;
} S4;
struct {Tident198021* ident;
} S5;
struct {Tnodeseq225803* sons;
} S6;
} kindU;
NimStringDesc* comment;
};
typedef NU8 TY213407[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  Tidobj198015  {
  TNimObject Sup;
NI id;
};
struct  Tloc225823  {
NU8 k;
NU8 s;
NU16 flags;
Ttype225847* t;
Ropeobj176009* r;
Ropeobj176009* heaproot;
};
struct  Ttype225847  {
  Tidobj198015 Sup;
NU8 kind;
NU8 callconv;
NU32 flags;
Ttypeseq225843* sons;
Tnode225809* n;
Tsym225841* owner;
Tsym225841* sym;
Tsym225841* destructor;
Tsym225841* deepcopy;
Tsym225841* assignment;
NI64 size;
NI16 align;
NI16 locklevel;
Tloc225823 loc;
};
struct  Tstrtable225813  {
NI counter;
Tsymseq225811* data;
};
struct  Tsym225841  {
  Tidobj198015 Sup;
NU8 kind;
union{
struct {Ttypeseq225843* typeinstcache;
Tscope225835* typscope;
} S1;
struct {TY225944* procinstcache;
Tsym225841* gcunsafetyreason;
} S2;
struct {TY225944* usedgenerics;
Tstrtable225813 tab;
} S3;
struct {Tsym225841* guard;
NI bitsize;
} S4;
} kindU;
NU8 magic;
Ttype225847* typ;
Tident198021* name;
Tlineinfo190352 info;
Tsym225841* owner;
NU32 flags;
Tnode225809* ast;
NU32 options;
NI position;
NI offset;
Tloc225823 loc;
Tlib225827* annex;
Tnode225809* constraint;
};
struct  Tident198021  {
  Tidobj198015 Sup;
NimStringDesc* s;
Tident198021* next;
NI h;
};
struct  Tllstream213204  {
  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  Ropeobj176009  {
  TNimObject Sup;
Ropeobj176009* left;
Ropeobj176009* right;
NI length;
NimStringDesc* data;
};
struct  Tscope225835  {
NI depthlevel;
Tstrtable225813 symbols;
Tnodeseq225803* usingsyms;
Tscope225835* parent;
};
struct  Tlistentry141022  {
  TNimObject Sup;
Tlistentry141022* prev;
Tlistentry141022* next;
};
struct  Tlib225827  {
  Tlistentry141022 Sup;
NU8 kind;
NIM_BOOL generated;
NIM_BOOL isoverriden;
Ropeobj176009* name;
Tnode225809* path;
};
struct  Tinstantiation225831  {
Tsym225841* sym;
Ttypeseq225843* concretetypes;
TY225932* usedby;
NI compilesid;
};
struct Tnodeseq225803 {
  TGenericSeq Sup;
  Tnode225809* data[SEQ_DECL_SIZE];
};
struct Ttypeseq225843 {
  TGenericSeq Sup;
  Ttype225847* data[SEQ_DECL_SIZE];
};
struct TY225944 {
  TGenericSeq Sup;
  Tinstantiation225831* data[SEQ_DECL_SIZE];
};
struct Tsymseq225811 {
  TGenericSeq Sup;
  Tsym225841* data[SEQ_DECL_SIZE];
};
struct TY225932 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
N_NIMCALL(Tnode225809*, getarg_251057)(Tnode225809* n, NimStringDesc* name, NI pos);
N_NIMCALL(NI, sonslen_228387)(Tnode225809* n);
N_NIMCALL(void, invalidpragma_251047)(Tnode225809* n);
N_NIMCALL(void, localerror_196128)(Tlineinfo190352 info, NU16 msg, NimStringDesc* arg);
N_NIMCALL(NimStringDesc*, rendertree_247059)(Tnode225809* n, NU8 renderflags);
N_NIMCALL(NIM_BOOL, identeq_198484)(Tident198021* id, NimStringDesc* name);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(NimStringDesc*, strarg_251029)(Tnode225809* n, NimStringDesc* name, NI pos, NimStringDesc* default_251034);
N_NIMCALL(NIM_BOOL, boolarg_251038)(Tnode225809* n, NimStringDesc* name, NI pos, NIM_BOOL default_251043);
N_NIMCALL(Tllstream213204*, llstreamopen_213220)(NimStringDesc* data);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(NimStringDesc*, rawNewString)(NI cap);
N_NIMCALL(NIM_BOOL, llstreamreadline_213610)(Tllstream213204* s, NimStringDesc** line);
N_NIMCALL(NimStringDesc*, nsuStrip)(NimStringDesc* s, NIM_BOOL leading, NIM_BOOL trailing, TY213407 chars);
N_NIMCALL(NIM_BOOL, nsuStartsWith)(NimStringDesc* s, NimStringDesc* prefix);
N_NIMCALL(void, llstreamwriteln_213686)(Tllstream213204* s, NimStringDesc* data);
N_NIMCALL(void, llstreamclose_213310)(Tllstream213204* s);
N_NIMCALL(NimStringDesc*, nsuReplaceStr)(NimStringDesc* s, NimStringDesc* sub, NimStringDesc* by);
STRING_LITERAL(TMP1504, "startswith", 10);
STRING_LITERAL(TMP1505, "", 0);
STRING_LITERAL(TMP1506, "true", 4);
STRING_LITERAL(TMP1507, "false", 5);
STRING_LITERAL(TMP1508, "leading", 7);
STRING_LITERAL(TMP1509, "trailing", 8);
static NIM_CONST TY213407 TMP1510 = {
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(TMP1511, "sub", 3);
STRING_LITERAL(TMP1512, "by", 2);

N_NIMCALL(void, invalidpragma_251047)(Tnode225809* n) {
	NimStringDesc* LOC1;
	LOC1 = 0;
	LOC1 = rendertree_247059(n, 4);
	localerror_196128((*n).info, ((NU16) 167), LOC1);
}

N_NIMCALL(Tnode225809*, getarg_251057)(Tnode225809* n, NimStringDesc* name, NI pos) {
	Tnode225809* result;
{	result = 0;
	result = NIM_NIL;
	{
		if (!((*n).kind >= ((NU8) 1) && (*n).kind <= ((NU8) 23))) goto LA3;
		goto BeforeRet;
	}
	LA3: ;
	{
		NI i_251086;
		NI HEX3Atmp_251115;
		NI LOC6;
		NI res_251118;
		i_251086 = 0;
		HEX3Atmp_251115 = 0;
		LOC6 = 0;
		LOC6 = sonslen_228387(n);
		HEX3Atmp_251115 = (NI)(LOC6 - ((NI) 1));
		res_251118 = ((NI) 1);
		{
			while (1) {
				if (!(res_251118 <= HEX3Atmp_251115)) goto LA8;
				i_251086 = res_251118;
				{
					if (!((*(*n).kindU.S6.sons->data[i_251086]).kind == ((NU8) 33))) goto LA11;
					{
						if (!!(((*(*(*n).kindU.S6.sons->data[i_251086]).kindU.S6.sons->data[((NI) 0)]).kind == ((NU8) 2)))) goto LA15;
						invalidpragma_251047(n);
					}
					LA15: ;
					{
						NIM_BOOL LOC19;
						LOC19 = 0;
						LOC19 = identeq_198484((*(*(*n).kindU.S6.sons->data[i_251086]).kindU.S6.sons->data[((NI) 0)]).kindU.S5.ident, name);
						if (!LOC19) goto LA20;
						result = (*(*n).kindU.S6.sons->data[i_251086]).kindU.S6.sons->data[((NI) 1)];
						goto BeforeRet;
					}
					LA20: ;
				}
				goto LA9;
				LA11: ;
				{
					if (!(i_251086 == pos)) goto LA23;
					result = (*n).kindU.S6.sons->data[i_251086];
					goto BeforeRet;
				}
				goto LA9;
				LA23: ;
				LA9: ;
				res_251118 += ((NI) 1);
			} LA8: ;
		}
	}
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_CHAR, chararg_251020)(Tnode225809* n, NimStringDesc* name, NI pos, NIM_CHAR default_251025) {
	NIM_CHAR result;
	Tnode225809* x;
	result = 0;
	x = getarg_251057(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = default_251025;
	}
	goto LA1;
	LA3: ;
	{
		if (!((*x).kind == ((NU8) 5))) goto LA6;
		result = ((NIM_CHAR) (((NI) (((NI) ((*x).kindU.S1.intval))))));
	}
	goto LA1;
	LA6: ;
	{
		invalidpragma_251047(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NimStringDesc*, strarg_251029)(Tnode225809* n, NimStringDesc* name, NI pos, NimStringDesc* default_251034) {
	NimStringDesc* result;
	Tnode225809* x;
	result = 0;
	x = getarg_251057(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = copyString(default_251034);
	}
	goto LA1;
	LA3: ;
	{
		if (!((*x).kind >= ((NU8) 20) && (*x).kind <= ((NU8) 22))) goto LA6;
		result = copyString((*x).kindU.S3.strval);
	}
	goto LA1;
	LA6: ;
	{
		invalidpragma_251047(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NIM_BOOL, boolarg_251038)(Tnode225809* n, NimStringDesc* name, NI pos, NIM_BOOL default_251043) {
	NIM_BOOL result;
	Tnode225809* x;
	result = 0;
	x = getarg_251057(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = default_251043;
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC6;
		LOC6 = 0;
		LOC6 = ((*x).kind == ((NU8) 2));
		if (!(LOC6)) goto LA7;
		LOC6 = identeq_198484((*x).kindU.S5.ident, ((NimStringDesc*) &TMP1506));
		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_198484((*x).kindU.S5.ident, ((NimStringDesc*) &TMP1507));
		LA12: ;
		if (!LOC11) goto LA13;
		result = NIM_FALSE;
	}
	goto LA1;
	LA13: ;
	{
		invalidpragma_251047(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(Tllstream213204*, filterstrip_251012)(Tllstream213204* stdin_251014, NimStringDesc* filename, Tnode225809* call) {
	Tllstream213204* result;
	NimStringDesc* pattern;
	NIM_BOOL leading;
	NIM_BOOL trailing;
	NimStringDesc* line;
	result = 0;
	pattern = strarg_251029(call, ((NimStringDesc*) &TMP1504), ((NI) 1), ((NimStringDesc*) &TMP1505));
	leading = boolarg_251038(call, ((NimStringDesc*) &TMP1508), ((NI) 2), NIM_TRUE);
	trailing = boolarg_251038(call, ((NimStringDesc*) &TMP1509), ((NI) 3), NIM_TRUE);
	result = llstreamopen_213220(((NimStringDesc*) &TMP1505));
	line = rawNewString(((NI) 80));
	{
		while (1) {
			NIM_BOOL LOC3;
			NimStringDesc* stripped;
			LOC3 = 0;
			LOC3 = llstreamreadline_213610(stdin_251014, (&line));
			if (!LOC3) goto LA2;
			stripped = nsuStrip(line, leading, trailing, TMP1510);
			{
				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_213686(result, stripped);
			}
			goto LA4;
			LA8: ;
			{
				llstreamwriteln_213686(result, line);
			}
			LA4: ;
		} LA2: ;
	}
	llstreamclose_213310(stdin_251014);
	return result;
}

N_NIMCALL(Tllstream213204*, filterreplace_251004)(Tllstream213204* stdin_251006, NimStringDesc* filename, Tnode225809* call) {
	Tllstream213204* result;
	NimStringDesc* sub;
	NimStringDesc* by;
	NimStringDesc* line;
	result = 0;
	sub = strarg_251029(call, ((NimStringDesc*) &TMP1511), ((NI) 1), ((NimStringDesc*) &TMP1505));
	{
		if (!((sub ? sub->Sup.len : 0) == ((NI) 0))) goto LA3;
		invalidpragma_251047(call);
	}
	LA3: ;
	by = strarg_251029(call, ((NimStringDesc*) &TMP1512), ((NI) 2), ((NimStringDesc*) &TMP1505));
	result = llstreamopen_213220(((NimStringDesc*) &TMP1505));
	line = rawNewString(((NI) 80));
	{
		while (1) {
			NIM_BOOL LOC7;
			NimStringDesc* LOC8;
			LOC7 = 0;
			LOC7 = llstreamreadline_213610(stdin_251006, (&line));
			if (!LOC7) goto LA6;
			LOC8 = 0;
			LOC8 = nsuReplaceStr(line, sub, by);
			llstreamwriteln_213686(result, LOC8);
		} LA6: ;
	}
	llstreamclose_213310(stdin_251006);
	return result;
}
NIM_EXTERNC N_NOINLINE(void, compiler_filtersInit000)(void) {
}

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

