/* Generated by Nim Compiler v0.10.2 */
/*   (c) 2014 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 64
#include "nimbase.h"

#include <stdio.h>
typedef struct tnode224816 tnode224816;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct ttype224852 ttype224852;
typedef struct tlineinfo194539 tlineinfo194539;
typedef struct tsym224846 tsym224846;
typedef struct tident199021 tident199021;
typedef struct tnodeseq224810 tnodeseq224810;
typedef struct tllstream210204 tllstream210204;
typedef struct tidobj199015 tidobj199015;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct ttypeseq224848 ttypeseq224848;
typedef struct tloc224830 tloc224830;
typedef struct trope176009 trope176009;
typedef struct tscope224840 tscope224840;
typedef struct TY224947 TY224947;
typedef struct tinstantiation224836 tinstantiation224836;
typedef struct tstrtable224820 tstrtable224820;
typedef struct tsymseq224818 tsymseq224818;
typedef struct tlib224834 tlib224834;
typedef struct TY224936 TY224936;
typedef struct tlistentry126022 tlistentry126022;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  tlineinfo194539  {
NI16 Line;
NI16 Col;
NI32 Fileindex;
};
struct  tnode224816  {
ttype224852* Typ;
tlineinfo194539 Info;
NU16 Flags;
NU8 Kind;
union {
struct {NI64 Intval;
} S1;
struct {NF Floatval;
} S2;
struct {NimStringDesc* Strval;
} S3;
struct {tsym224846* Sym;
} S4;
struct {tident199021* Ident;
} S5;
struct {tnodeseq224810* Sons;
} S6;
} kindU;
NimStringDesc* Comment;
};
typedef N_NIMCALL_PTR(void, TY3089) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3094) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3089 marker;
TY3094 deepcopy;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  tidobj199015  {
  TNimObject Sup;
NI Id;
};
struct  tloc224830  {
NU8 K;
NU8 S;
NU8 Flags;
ttype224852* T;
trope176009* R;
trope176009* Heaproot;
};
struct  ttype224852  {
  tidobj199015 Sup;
NU8 Kind;
NU8 Callconv;
NU32 Flags;
ttypeseq224848* Sons;
tnode224816* N;
tsym224846* Owner;
tsym224846* Sym;
tsym224846* Destructor;
tsym224846* Deepcopy;
NI64 Size;
NI16 Align;
NI16 Locklevel;
tloc224830 Loc;
};
struct  tstrtable224820  {
NI Counter;
tsymseq224818* Data;
};
struct  tsym224846  {
  tidobj199015 Sup;
NU8 Kind;
union {
struct {ttypeseq224848* Typeinstcache;
tscope224840* Typscope;
} S1;
struct {TY224947* Procinstcache;
tscope224840* Scope;
} S2;
struct {TY224947* Usedgenerics;
tstrtable224820 Tab;
} S3;
struct {tsym224846* Guard;
} S4;
} kindU;
NU16 Magic;
ttype224852* Typ;
tident199021* Name;
tlineinfo194539 Info;
tsym224846* Owner;
NU32 Flags;
tnode224816* Ast;
NU32 Options;
NI Position;
NI Offset;
tloc224830 Loc;
tlib224834* Annex;
tnode224816* Constraint;
};
struct  tident199021  {
  tidobj199015 Sup;
NimStringDesc* S;
tident199021* Next;
NI H;
};
struct  tllstream210204  {
  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  trope176009  {
  TNimObject Sup;
trope176009* Left;
trope176009* Right;
NI Length;
NimStringDesc* Data;
};
struct  tscope224840  {
NI Depthlevel;
tstrtable224820 Symbols;
tnodeseq224810* Usingsyms;
tscope224840* Parent;
};
struct  tinstantiation224836  {
tsym224846* Sym;
ttypeseq224848* Concretetypes;
TY224936* Usedby;
};
struct  tlistentry126022  {
  TNimObject Sup;
tlistentry126022* Prev;
tlistentry126022* Next;
};
struct  tlib224834  {
  tlistentry126022 Sup;
NU8 Kind;
NIM_BOOL Generated;
NIM_BOOL Isoverriden;
trope176009* Name;
tnode224816* Path;
};
struct tnodeseq224810 {
  TGenericSeq Sup;
  tnode224816* data[SEQ_DECL_SIZE];
};
struct ttypeseq224848 {
  TGenericSeq Sup;
  ttype224852* data[SEQ_DECL_SIZE];
};
struct TY224947 {
  TGenericSeq Sup;
  tinstantiation224836* data[SEQ_DECL_SIZE];
};
struct tsymseq224818 {
  TGenericSeq Sup;
  tsym224846* data[SEQ_DECL_SIZE];
};
struct TY224936 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
N_NIMCALL(tnode224816*, getarg_257057)(tnode224816* n, NimStringDesc* name, NI pos);
static N_INLINE(NI, sonslen_225249)(tnode224816* n);
N_NIMCALL(void, invalidpragma_257047)(tnode224816* n);
N_NIMCALL(void, localerror_196955)(tlineinfo194539 info, NU16 msg, NimStringDesc* arg);
N_NIMCALL(NimStringDesc*, rendertree_249058)(tnode224816* n, NU8 renderflags);
N_NIMCALL(NIM_BOOL, identeq_199493)(tident199021* id, NimStringDesc* name);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(NimStringDesc*, strarg_257029)(tnode224816* n, NimStringDesc* name, NI pos, NimStringDesc* default_257034);
N_NIMCALL(NIM_BOOL, boolarg_257038)(tnode224816* n, NimStringDesc* name, NI pos, NIM_BOOL default_257043);
N_NIMCALL(tllstream210204*, llstreamopen_210220)(NimStringDesc* data);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(NimStringDesc*, rawNewString)(NI cap);
N_NIMCALL(NIM_BOOL, llstreamreadline_210264)(tllstream210204* s, NimStringDesc** line);
N_NIMCALL(NimStringDesc*, nsuStrip)(NimStringDesc* s, NIM_BOOL leading, NIM_BOOL trailing);
N_NIMCALL(NIM_BOOL, nsuStartsWith)(NimStringDesc* s, NimStringDesc* prefix);
N_NIMCALL(void, llstreamwriteln_210300)(tllstream210204* s, NimStringDesc* data);
N_NIMCALL(void, llstreamclose_210250)(tllstream210204* s);
N_NIMCALL(NimStringDesc*, nsuReplaceStr)(NimStringDesc* s, NimStringDesc* sub, NimStringDesc* by);
STRING_LITERAL(TMP1349, "startswith", 10);
STRING_LITERAL(TMP1350, "", 0);
STRING_LITERAL(TMP1351, "true", 4);
STRING_LITERAL(TMP1352, "false", 5);
STRING_LITERAL(TMP1353, "leading", 7);
STRING_LITERAL(TMP1354, "trailing", 8);
STRING_LITERAL(TMP1355, "sub", 3);
STRING_LITERAL(TMP1356, "by", 2);

static N_INLINE(NI, sonslen_225249)(tnode224816* n) {
	NI result;
	result = 0;
	{
		if (!(*n).kindU.S6.Sons == 0) goto LA3;
		result = 0;
	}
	goto LA1;
	LA3: ;
	{
		result = (*n).kindU.S6.Sons->Sup.len;
	}
	LA1: ;
	return result;
}

N_NIMCALL(void, invalidpragma_257047)(tnode224816* n) {
	NimStringDesc* LOC1;
	LOC1 = 0;
	LOC1 = rendertree_249058(n, 4);
	localerror_196955((*n).Info, ((NU16) 163), LOC1);
}

N_NIMCALL(tnode224816*, getarg_257057)(tnode224816* n, NimStringDesc* name, NI pos) {
	tnode224816* result;
	result = 0;
	result = NIM_NIL;
	{
		if (!((*n).Kind >= ((NU8) 1) && (*n).Kind <= ((NU8) 23))) goto LA3;
		goto BeforeRet;
	}
	LA3: ;
	{
		NI i_257089;
		NI HEX3Atmp_257235;
		NI LOC6;
		NI res_257238;
		i_257089 = 0;
		HEX3Atmp_257235 = 0;
		LOC6 = 0;
		LOC6 = sonslen_225249(n);
		HEX3Atmp_257235 = (NI64)(LOC6 - 1);
		res_257238 = 1;
		{
			while (1) {
				if (!(res_257238 <= HEX3Atmp_257235)) goto LA8;
				i_257089 = res_257238;
				{
					if (!((*(*n).kindU.S6.Sons->data[i_257089]).Kind == ((NU8) 33))) goto LA11;
					{
						if (!!(((*(*(*n).kindU.S6.Sons->data[i_257089]).kindU.S6.Sons->data[0]).Kind == ((NU8) 2)))) goto LA15;
						invalidpragma_257047(n);
					}
					LA15: ;
					{
						NIM_BOOL LOC19;
						LOC19 = 0;
						LOC19 = identeq_199493((*(*(*n).kindU.S6.Sons->data[i_257089]).kindU.S6.Sons->data[0]).kindU.S5.Ident, name);
						if (!LOC19) goto LA20;
						result = (*(*n).kindU.S6.Sons->data[i_257089]).kindU.S6.Sons->data[1];
						goto BeforeRet;
					}
					LA20: ;
				}
				goto LA9;
				LA11: ;
				{
					if (!(i_257089 == pos)) goto LA23;
					result = (*n).kindU.S6.Sons->data[i_257089];
					goto BeforeRet;
				}
				goto LA9;
				LA23: ;
				LA9: ;
				res_257238 += 1;
			} LA8: ;
		}
	}
	BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_CHAR, chararg_257020)(tnode224816* n, NimStringDesc* name, NI pos, NIM_CHAR default_257025) {
	NIM_CHAR result;
	tnode224816* x;
	result = 0;
	x = getarg_257057(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = default_257025;
	}
	goto LA1;
	LA3: ;
	{
		if (!((*x).Kind == ((NU8) 5))) goto LA6;
		result = ((NIM_CHAR) (((NI) (((NI) ((*x).kindU.S1.Intval))))));
	}
	goto LA1;
	LA6: ;
	{
		invalidpragma_257047(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NimStringDesc*, strarg_257029)(tnode224816* n, NimStringDesc* name, NI pos, NimStringDesc* default_257034) {
	NimStringDesc* result;
	tnode224816* x;
	result = 0;
	x = getarg_257057(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = copyString(default_257034);
	}
	goto LA1;
	LA3: ;
	{
		if (!((*x).Kind >= ((NU8) 20) && (*x).Kind <= ((NU8) 22))) goto LA6;
		result = copyString((*x).kindU.S3.Strval);
	}
	goto LA1;
	LA6: ;
	{
		invalidpragma_257047(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NIM_BOOL, boolarg_257038)(tnode224816* n, NimStringDesc* name, NI pos, NIM_BOOL default_257043) {
	NIM_BOOL result;
	tnode224816* x;
	result = 0;
	x = getarg_257057(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = default_257043;
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC6;
		LOC6 = 0;
		LOC6 = ((*x).Kind == ((NU8) 2));
		if (!(LOC6)) goto LA7;
		LOC6 = identeq_199493((*x).kindU.S5.Ident, ((NimStringDesc*) &TMP1351));
		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_199493((*x).kindU.S5.Ident, ((NimStringDesc*) &TMP1352));
		LA12: ;
		if (!LOC11) goto LA13;
		result = NIM_FALSE;
	}
	goto LA1;
	LA13: ;
	{
		invalidpragma_257047(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(tllstream210204*, filterstrip_257012)(tllstream210204* stdin_257014, NimStringDesc* filename, tnode224816* call) {
	tllstream210204* result;
	NimStringDesc* pattern;
	NIM_BOOL leading;
	NIM_BOOL trailing;
	NimStringDesc* line;
	result = 0;
	pattern = strarg_257029(call, ((NimStringDesc*) &TMP1349), 1, ((NimStringDesc*) &TMP1350));
	leading = boolarg_257038(call, ((NimStringDesc*) &TMP1353), 2, NIM_TRUE);
	trailing = boolarg_257038(call, ((NimStringDesc*) &TMP1354), 3, NIM_TRUE);
	result = llstreamopen_210220(((NimStringDesc*) &TMP1350));
	line = rawNewString(80);
	{
		while (1) {
			NIM_BOOL LOC3;
			NimStringDesc* stripped;
			LOC3 = 0;
			LOC3 = llstreamreadline_210264(stdin_257014, (&line));
			if (!LOC3) goto LA2;
			stripped = nsuStrip(line, leading, trailing);
			{
				NIM_BOOL LOC6;
				LOC6 = 0;
				LOC6 = (pattern->Sup.len == 0);
				if (LOC6) goto LA7;
				LOC6 = nsuStartsWith(stripped, pattern);
				LA7: ;
				if (!LOC6) goto LA8;
				llstreamwriteln_210300(result, stripped);
			}
			goto LA4;
			LA8: ;
			{
				llstreamwriteln_210300(result, line);
			}
			LA4: ;
		} LA2: ;
	}
	llstreamclose_210250(stdin_257014);
	return result;
}

N_NIMCALL(tllstream210204*, filterreplace_257004)(tllstream210204* stdin_257006, NimStringDesc* filename, tnode224816* call) {
	tllstream210204* result;
	NimStringDesc* sub;
	NimStringDesc* by;
	NimStringDesc* line;
	result = 0;
	sub = strarg_257029(call, ((NimStringDesc*) &TMP1355), 1, ((NimStringDesc*) &TMP1350));
	{
		if (!(sub->Sup.len == 0)) goto LA3;
		invalidpragma_257047(call);
	}
	LA3: ;
	by = strarg_257029(call, ((NimStringDesc*) &TMP1356), 2, ((NimStringDesc*) &TMP1350));
	result = llstreamopen_210220(((NimStringDesc*) &TMP1350));
	line = rawNewString(80);
	{
		while (1) {
			NIM_BOOL LOC7;
			NimStringDesc* LOC8;
			LOC7 = 0;
			LOC7 = llstreamreadline_210264(stdin_257006, (&line));
			if (!LOC7) goto LA6;
			LOC8 = 0;
			LOC8 = nsuReplaceStr(line, sub, by);
			llstreamwriteln_210300(result, LOC8);
		} LA6: ;
	}
	llstreamclose_210250(stdin_257006);
	return result;
}
NIM_EXTERNC N_NOINLINE(void, HEX00_filtersInit)(void) {
}

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

