/* 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 tnode226816 tnode226816;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct ttype226852 ttype226852;
typedef struct tlineinfo196539 tlineinfo196539;
typedef struct tsym226846 tsym226846;
typedef struct tident201021 tident201021;
typedef struct tnodeseq226810 tnodeseq226810;
typedef struct tllstream212204 tllstream212204;
typedef struct tidobj201015 tidobj201015;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct ttypeseq226848 ttypeseq226848;
typedef struct tloc226830 tloc226830;
typedef struct trope178009 trope178009;
typedef struct tscope226840 tscope226840;
typedef struct TY226947 TY226947;
typedef struct tinstantiation226836 tinstantiation226836;
typedef struct tstrtable226820 tstrtable226820;
typedef struct tsymseq226818 tsymseq226818;
typedef struct tlib226834 tlib226834;
typedef struct TY226936 TY226936;
typedef struct tlistentry129022 tlistentry129022;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  tlineinfo196539  {
NI16 Line;
NI16 Col;
NI32 Fileindex;
};
struct  tnode226816  {
ttype226852* Typ;
tlineinfo196539 Info;
NU16 Flags;
NU8 Kind;
union {
struct {NI64 Intval;
} S1;
struct {NF Floatval;
} S2;
struct {NimStringDesc* Strval;
} S3;
struct {tsym226846* Sym;
} S4;
struct {tident201021* Ident;
} S5;
struct {tnodeseq226810* 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  tidobj201015  {
  TNimObject Sup;
NI Id;
};
struct  tloc226830  {
NU8 K;
NU8 S;
NU8 Flags;
ttype226852* T;
trope178009* R;
trope178009* Heaproot;
};
struct  ttype226852  {
  tidobj201015 Sup;
NU8 Kind;
NU8 Callconv;
NU32 Flags;
ttypeseq226848* Sons;
tnode226816* N;
tsym226846* Owner;
tsym226846* Sym;
tsym226846* Destructor;
tsym226846* Deepcopy;
NI64 Size;
NI16 Align;
NI16 Locklevel;
tloc226830 Loc;
};
struct  tstrtable226820  {
NI Counter;
tsymseq226818* Data;
};
struct  tsym226846  {
  tidobj201015 Sup;
NU8 Kind;
union {
struct {ttypeseq226848* Typeinstcache;
tscope226840* Typscope;
} S1;
struct {TY226947* Procinstcache;
tscope226840* Scope;
} S2;
struct {TY226947* Usedgenerics;
tstrtable226820 Tab;
} S3;
struct {tsym226846* Guard;
} S4;
} kindU;
NU16 Magic;
ttype226852* Typ;
tident201021* Name;
tlineinfo196539 Info;
tsym226846* Owner;
NU32 Flags;
tnode226816* Ast;
NU32 Options;
NI Position;
NI Offset;
tloc226830 Loc;
tlib226834* Annex;
tnode226816* Constraint;
};
struct  tident201021  {
  tidobj201015 Sup;
NimStringDesc* S;
tident201021* Next;
NI H;
};
struct  tllstream212204  {
  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  trope178009  {
  TNimObject Sup;
trope178009* Left;
trope178009* Right;
NI Length;
NimStringDesc* Data;
};
struct  tscope226840  {
NI Depthlevel;
tstrtable226820 Symbols;
tnodeseq226810* Usingsyms;
tscope226840* Parent;
};
struct  tinstantiation226836  {
tsym226846* Sym;
ttypeseq226848* Concretetypes;
TY226936* Usedby;
};
struct  tlistentry129022  {
  TNimObject Sup;
tlistentry129022* Prev;
tlistentry129022* Next;
};
struct  tlib226834  {
  tlistentry129022 Sup;
NU8 Kind;
NIM_BOOL Generated;
NIM_BOOL Isoverriden;
trope178009* Name;
tnode226816* Path;
};
struct tnodeseq226810 {
  TGenericSeq Sup;
  tnode226816* data[SEQ_DECL_SIZE];
};
struct ttypeseq226848 {
  TGenericSeq Sup;
  ttype226852* data[SEQ_DECL_SIZE];
};
struct TY226947 {
  TGenericSeq Sup;
  tinstantiation226836* data[SEQ_DECL_SIZE];
};
struct tsymseq226818 {
  TGenericSeq Sup;
  tsym226846* data[SEQ_DECL_SIZE];
};
struct TY226936 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
N_NIMCALL(tnode226816*, getarg_259057)(tnode226816* n, NimStringDesc* name, NI pos);
static N_INLINE(NI, sonslen_227249)(tnode226816* n);
N_NIMCALL(void, invalidpragma_259047)(tnode226816* n);
N_NIMCALL(void, localerror_198955)(tlineinfo196539 info, NU16 msg, NimStringDesc* arg);
N_NIMCALL(NimStringDesc*, rendertree_251058)(tnode226816* n, NU8 renderflags);
N_NIMCALL(NIM_BOOL, identeq_201493)(tident201021* id, NimStringDesc* name);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(NimStringDesc*, strarg_259029)(tnode226816* n, NimStringDesc* name, NI pos, NimStringDesc* default_259034);
N_NIMCALL(NIM_BOOL, boolarg_259038)(tnode226816* n, NimStringDesc* name, NI pos, NIM_BOOL default_259043);
N_NIMCALL(tllstream212204*, llstreamopen_212220)(NimStringDesc* data);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(NimStringDesc*, rawNewString)(NI cap);
N_NIMCALL(NIM_BOOL, llstreamreadline_212264)(tllstream212204* 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_212300)(tllstream212204* s, NimStringDesc* data);
N_NIMCALL(void, llstreamclose_212250)(tllstream212204* s);
N_NIMCALL(NimStringDesc*, nsuReplaceStr)(NimStringDesc* s, NimStringDesc* sub, NimStringDesc* by);
STRING_LITERAL(TMP1357, "startswith", 10);
STRING_LITERAL(TMP1358, "", 0);
STRING_LITERAL(TMP1359, "true", 4);
STRING_LITERAL(TMP1360, "false", 5);
STRING_LITERAL(TMP1361, "leading", 7);
STRING_LITERAL(TMP1362, "trailing", 8);
STRING_LITERAL(TMP1363, "sub", 3);
STRING_LITERAL(TMP1364, "by", 2);

static N_INLINE(NI, sonslen_227249)(tnode226816* 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_259047)(tnode226816* n) {
	NimStringDesc* LOC1;
	LOC1 = 0;
	LOC1 = rendertree_251058(n, 4);
	localerror_198955((*n).Info, ((NU16) 163), LOC1);
}

N_NIMCALL(tnode226816*, getarg_259057)(tnode226816* n, NimStringDesc* name, NI pos) {
	tnode226816* result;
	result = 0;
	result = NIM_NIL;
	{
		if (!((*n).Kind >= ((NU8) 1) && (*n).Kind <= ((NU8) 23))) goto LA3;
		goto BeforeRet;
	}
	LA3: ;
	{
		NI i_259089;
		NI HEX3Atmp_259235;
		NI LOC6;
		NI res_259238;
		i_259089 = 0;
		HEX3Atmp_259235 = 0;
		LOC6 = 0;
		LOC6 = sonslen_227249(n);
		HEX3Atmp_259235 = (NI64)(LOC6 - 1);
		res_259238 = 1;
		{
			while (1) {
				if (!(res_259238 <= HEX3Atmp_259235)) goto LA8;
				i_259089 = res_259238;
				{
					if (!((*(*n).kindU.S6.Sons->data[i_259089]).Kind == ((NU8) 33))) goto LA11;
					{
						if (!!(((*(*(*n).kindU.S6.Sons->data[i_259089]).kindU.S6.Sons->data[0]).Kind == ((NU8) 2)))) goto LA15;
						invalidpragma_259047(n);
					}
					LA15: ;
					{
						NIM_BOOL LOC19;
						LOC19 = 0;
						LOC19 = identeq_201493((*(*(*n).kindU.S6.Sons->data[i_259089]).kindU.S6.Sons->data[0]).kindU.S5.Ident, name);
						if (!LOC19) goto LA20;
						result = (*(*n).kindU.S6.Sons->data[i_259089]).kindU.S6.Sons->data[1];
						goto BeforeRet;
					}
					LA20: ;
				}
				goto LA9;
				LA11: ;
				{
					if (!(i_259089 == pos)) goto LA23;
					result = (*n).kindU.S6.Sons->data[i_259089];
					goto BeforeRet;
				}
				goto LA9;
				LA23: ;
				LA9: ;
				res_259238 += 1;
			} LA8: ;
		}
	}
	BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_CHAR, chararg_259020)(tnode226816* n, NimStringDesc* name, NI pos, NIM_CHAR default_259025) {
	NIM_CHAR result;
	tnode226816* x;
	result = 0;
	x = getarg_259057(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = default_259025;
	}
	goto LA1;
	LA3: ;
	{
		if (!((*x).Kind == ((NU8) 5))) goto LA6;
		result = ((NIM_CHAR) (((NI) (((NI) ((*x).kindU.S1.Intval))))));
	}
	goto LA1;
	LA6: ;
	{
		invalidpragma_259047(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NimStringDesc*, strarg_259029)(tnode226816* n, NimStringDesc* name, NI pos, NimStringDesc* default_259034) {
	NimStringDesc* result;
	tnode226816* x;
	result = 0;
	x = getarg_259057(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = copyString(default_259034);
	}
	goto LA1;
	LA3: ;
	{
		if (!((*x).Kind >= ((NU8) 20) && (*x).Kind <= ((NU8) 22))) goto LA6;
		result = copyString((*x).kindU.S3.Strval);
	}
	goto LA1;
	LA6: ;
	{
		invalidpragma_259047(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NIM_BOOL, boolarg_259038)(tnode226816* n, NimStringDesc* name, NI pos, NIM_BOOL default_259043) {
	NIM_BOOL result;
	tnode226816* x;
	result = 0;
	x = getarg_259057(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = default_259043;
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC6;
		LOC6 = 0;
		LOC6 = ((*x).Kind == ((NU8) 2));
		if (!(LOC6)) goto LA7;
		LOC6 = identeq_201493((*x).kindU.S5.Ident, ((NimStringDesc*) &TMP1359));
		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_201493((*x).kindU.S5.Ident, ((NimStringDesc*) &TMP1360));
		LA12: ;
		if (!LOC11) goto LA13;
		result = NIM_FALSE;
	}
	goto LA1;
	LA13: ;
	{
		invalidpragma_259047(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(tllstream212204*, filterstrip_259012)(tllstream212204* stdin_259014, NimStringDesc* filename, tnode226816* call) {
	tllstream212204* result;
	NimStringDesc* pattern;
	NIM_BOOL leading;
	NIM_BOOL trailing;
	NimStringDesc* line;
	result = 0;
	pattern = strarg_259029(call, ((NimStringDesc*) &TMP1357), 1, ((NimStringDesc*) &TMP1358));
	leading = boolarg_259038(call, ((NimStringDesc*) &TMP1361), 2, NIM_TRUE);
	trailing = boolarg_259038(call, ((NimStringDesc*) &TMP1362), 3, NIM_TRUE);
	result = llstreamopen_212220(((NimStringDesc*) &TMP1358));
	line = rawNewString(80);
	{
		while (1) {
			NIM_BOOL LOC3;
			NimStringDesc* stripped;
			LOC3 = 0;
			LOC3 = llstreamreadline_212264(stdin_259014, (&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_212300(result, stripped);
			}
			goto LA4;
			LA8: ;
			{
				llstreamwriteln_212300(result, line);
			}
			LA4: ;
		} LA2: ;
	}
	llstreamclose_212250(stdin_259014);
	return result;
}

N_NIMCALL(tllstream212204*, filterreplace_259004)(tllstream212204* stdin_259006, NimStringDesc* filename, tnode226816* call) {
	tllstream212204* result;
	NimStringDesc* sub;
	NimStringDesc* by;
	NimStringDesc* line;
	result = 0;
	sub = strarg_259029(call, ((NimStringDesc*) &TMP1363), 1, ((NimStringDesc*) &TMP1358));
	{
		if (!(sub->Sup.len == 0)) goto LA3;
		invalidpragma_259047(call);
	}
	LA3: ;
	by = strarg_259029(call, ((NimStringDesc*) &TMP1364), 2, ((NimStringDesc*) &TMP1358));
	result = llstreamopen_212220(((NimStringDesc*) &TMP1358));
	line = rawNewString(80);
	{
		while (1) {
			NIM_BOOL LOC7;
			NimStringDesc* LOC8;
			LOC7 = 0;
			LOC7 = llstreamreadline_212264(stdin_259006, (&line));
			if (!LOC7) goto LA6;
			LOC8 = 0;
			LOC8 = nsuReplaceStr(line, sub, by);
			llstreamwriteln_212300(result, LOC8);
		} LA6: ;
	}
	llstreamclose_212250(stdin_259006);
	return result;
}
NIM_EXTERNC N_NOINLINE(void, HEX00_filtersInit)(void) {
}

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

