/* Generated by Nimrod Compiler v0.9.5 */
/*   (c) 2014 Andreas Rumpf */
/* The generated code is subject to the original license. */
/* Compiled for: Linux, i386, gcc */
/* Command for C compiler:
   gcc -c  -w -O3 -fno-strict-aliasing  -I/build/nimrod/src/nimrod/lib -o compiler/nimcache/filters.o compiler/nimcache/filters.c */
#define NIM_INTBITS 32
#include "nimbase.h"

#include <stdio.h>
typedef struct tnode188803 tnode188803;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct ttype188837 ttype188837;
typedef struct tlineinfo163527 tlineinfo163527;
typedef struct tsym188833 tsym188833;
typedef struct tident167019 tident167019;
typedef struct tnodeseq188797 tnodeseq188797;
typedef struct tllstream176204 tllstream176204;
typedef struct tidobj167013 tidobj167013;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct ttypeseq188835 ttypeseq188835;
typedef struct tloc188817 tloc188817;
typedef struct trope145007 trope145007;
typedef struct tscope188827 tscope188827;
typedef struct TY188933 TY188933;
typedef struct tinstantiation188823 tinstantiation188823;
typedef struct tstrtable188807 tstrtable188807;
typedef struct tsymseq188805 tsymseq188805;
typedef struct tlib188821 tlib188821;
typedef struct TY188922 TY188922;
typedef struct tlistentry118017 tlistentry118017;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  tlineinfo163527  {
NI16 Line;
NI16 Col;
NI32 Fileindex;
};
struct  tnode188803  {
ttype188837* Typ;
tlineinfo163527 Info;
NU16 Flags;
NU8 Kind;
union {
struct {NI64 Intval;
} S1;
struct {NF Floatval;
} S2;
struct {NimStringDesc* Strval;
} S3;
struct {tsym188833* Sym;
} S4;
struct {tident167019* Ident;
} S5;
struct {tnodeseq188797* Sons;
} S6;
} kindU;
NimStringDesc* Comment;
};
typedef N_NIMCALL_PTR(void, TY2289) (void* p, NI op);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY2289 marker;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  tidobj167013  {
  TNimObject Sup;
NI Id;
};
struct  tloc188817  {
NU8 K;
NU8 S;
NU8 Flags;
ttype188837* T;
trope145007* R;
trope145007* Heaproot;
NI A;
};
struct  ttype188837  {
  tidobj167013 Sup;
NU8 Kind;
NU8 Callconv;
NU32 Flags;
ttypeseq188835* Sons;
tnode188803* N;
tsym188833* Destructor;
tsym188833* Owner;
tsym188833* Sym;
NI64 Size;
NI Align;
tloc188817 Loc;
};
struct  tstrtable188807  {
NI Counter;
tsymseq188805* Data;
};
struct  tsym188833  {
  tidobj167013 Sup;
NU8 Kind;
union {
struct {ttypeseq188835* Typeinstcache;
tscope188827* Typscope;
} S1;
struct {TY188933* Procinstcache;
tscope188827* Scope;
} S2;
struct {TY188933* Usedgenerics;
tstrtable188807 Tab;
} S3;
} kindU;
NU16 Magic;
ttype188837* Typ;
tident167019* Name;
tlineinfo163527 Info;
tsym188833* Owner;
NU32 Flags;
tnode188803* Ast;
NU32 Options;
NI Position;
NI Offset;
tloc188817 Loc;
tlib188821* Annex;
tnode188803* Constraint;
};
struct  tident167019  {
  tidobj167013 Sup;
NimStringDesc* S;
tident167019* Next;
NI H;
};
struct  tllstream176204  {
  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  trope145007  {
  TNimObject Sup;
trope145007* Left;
trope145007* Right;
NI Length;
NimStringDesc* Data;
};
struct  tscope188827  {
NI Depthlevel;
tstrtable188807 Symbols;
tnodeseq188797* Usingsyms;
tscope188827* Parent;
};
struct  tinstantiation188823  {
tsym188833* Sym;
ttypeseq188835* Concretetypes;
TY188922* Usedby;
};
struct  tlistentry118017  {
  TNimObject Sup;
tlistentry118017* Prev;
tlistentry118017* Next;
};
struct  tlib188821  {
  tlistentry118017 Sup;
NU8 Kind;
NIM_BOOL Generated;
NIM_BOOL Isoverriden;
trope145007* Name;
tnode188803* Path;
};
struct tnodeseq188797 {
  TGenericSeq Sup;
  tnode188803* data[SEQ_DECL_SIZE];
};
struct ttypeseq188835 {
  TGenericSeq Sup;
  ttype188837* data[SEQ_DECL_SIZE];
};
struct TY188933 {
  TGenericSeq Sup;
  tinstantiation188823* data[SEQ_DECL_SIZE];
};
struct tsymseq188805 {
  TGenericSeq Sup;
  tsym188833* data[SEQ_DECL_SIZE];
};
struct TY188922 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
N_NIMCALL(tnode188803*, getarg_218042)(tnode188803* n, NimStringDesc* name, NI pos);
static N_INLINE(NI, sonslen_189181)(tnode188803* n);
N_NIMCALL(void, invalidpragma_218036)(tnode188803* n);
N_NIMCALL(void, localerror_165571)(tlineinfo163527 info, NU16 msg, NimStringDesc* arg);
N_NIMCALL(NimStringDesc*, rendertree_211051)(tnode188803* n, NU8 renderflags);
N_NIMCALL(NIM_BOOL, identeq_167469)(tident167019* id, NimStringDesc* name);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(NimStringDesc*, strarg_218021)(tnode188803* n, NimStringDesc* name, NI pos, NimStringDesc* default_218026);
N_NIMCALL(NIM_BOOL, boolarg_218028)(tnode188803* n, NimStringDesc* name, NI pos, NIM_BOOL default_218033);
N_NIMCALL(tllstream176204*, llstreamopen_176218)(NimStringDesc* data);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(NimStringDesc*, rawNewString)(NI cap);
N_NIMCALL(NIM_BOOL, llstreamreadline_176248)(tllstream176204* 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_176274)(tllstream176204* s, NimStringDesc* data);
N_NIMCALL(void, llstreamclose_176238)(tllstream176204* s);
N_NIMCALL(NimStringDesc*, nsuReplaceStr)(NimStringDesc* s, NimStringDesc* sub, NimStringDesc* by);
STRING_LITERAL(TMP1711, "startswith", 10);
STRING_LITERAL(TMP1712, "", 0);
STRING_LITERAL(TMP1713, "true", 4);
STRING_LITERAL(TMP1714, "false", 5);
STRING_LITERAL(TMP1715, "leading", 7);
STRING_LITERAL(TMP1716, "trailing", 8);
STRING_LITERAL(TMP1717, "sub", 3);
STRING_LITERAL(TMP1718, "by", 2);

static N_INLINE(NI, sonslen_189181)(tnode188803* 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_218036)(tnode188803* n) {
	NimStringDesc* LOC1;
	LOC1 = 0;
	LOC1 = rendertree_211051(n, 4);
	localerror_165571((*n).Info, ((NU16) 163), LOC1);
}

N_NIMCALL(tnode188803*, getarg_218042)(tnode188803* n, NimStringDesc* name, NI pos) {
	tnode188803* result;
	NI i_218074;
	NI HEX3Atmp_218219;
	NI LOC5;
	NI res_218221;
	result = 0;
	result = NIM_NIL;
	{
		if (!((*n).Kind >= ((NU8) 1) && (*n).Kind <= ((NU8) 23))) goto LA3;
		goto BeforeRet;
	}
	LA3: ;
	i_218074 = 0;
	HEX3Atmp_218219 = 0;
	LOC5 = 0;
	LOC5 = sonslen_189181(n);
	HEX3Atmp_218219 = (NI32)(LOC5 - 1);
	res_218221 = 1;
	while (1) {
		if (!(res_218221 <= HEX3Atmp_218219)) goto LA6;
		i_218074 = res_218221;
		{
			if (!((*(*n).kindU.S6.Sons->data[i_218074]).Kind == ((NU8) 33))) goto LA9;
			{
				if (!!(((*(*(*n).kindU.S6.Sons->data[i_218074]).kindU.S6.Sons->data[0]).Kind == ((NU8) 2)))) goto LA13;
				invalidpragma_218036(n);
			}
			LA13: ;
			{
				NIM_BOOL LOC17;
				LOC17 = 0;
				LOC17 = identeq_167469((*(*(*n).kindU.S6.Sons->data[i_218074]).kindU.S6.Sons->data[0]).kindU.S5.Ident, name);
				if (!LOC17) goto LA18;
				result = (*(*n).kindU.S6.Sons->data[i_218074]).kindU.S6.Sons->data[1];
				goto BeforeRet;
			}
			LA18: ;
		}
		goto LA7;
		LA9: ;
		{
			if (!(i_218074 == pos)) goto LA21;
			result = (*n).kindU.S6.Sons->data[i_218074];
			goto BeforeRet;
		}
		goto LA7;
		LA21: ;
		LA7: ;
		res_218221 += 1;
	} LA6: ;
	BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_CHAR, chararg_218014)(tnode188803* n, NimStringDesc* name, NI pos, NIM_CHAR default_218019) {
	NIM_CHAR result;
	tnode188803* x;
	result = 0;
	x = getarg_218042(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = default_218019;
	}
	goto LA1;
	LA3: ;
	{
		if (!((*x).Kind == ((NU8) 5))) goto LA6;
		result = ((NIM_CHAR) (((NI) (((NI) ((*x).kindU.S1.Intval))))));
	}
	goto LA1;
	LA6: ;
	{
		invalidpragma_218036(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NimStringDesc*, strarg_218021)(tnode188803* n, NimStringDesc* name, NI pos, NimStringDesc* default_218026) {
	NimStringDesc* result;
	tnode188803* x;
	result = 0;
	x = getarg_218042(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = copyString(default_218026);
	}
	goto LA1;
	LA3: ;
	{
		if (!((*x).Kind >= ((NU8) 20) && (*x).Kind <= ((NU8) 22))) goto LA6;
		result = copyString((*x).kindU.S3.Strval);
	}
	goto LA1;
	LA6: ;
	{
		invalidpragma_218036(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(NIM_BOOL, boolarg_218028)(tnode188803* n, NimStringDesc* name, NI pos, NIM_BOOL default_218033) {
	NIM_BOOL result;
	tnode188803* x;
	result = 0;
	x = getarg_218042(n, name, pos);
	{
		if (!(x == NIM_NIL)) goto LA3;
		result = default_218033;
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC6;
		LOC6 = 0;
		LOC6 = ((*x).Kind == ((NU8) 2));
		if (!(LOC6)) goto LA7;
		LOC6 = identeq_167469((*x).kindU.S5.Ident, ((NimStringDesc*) &TMP1713));
		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_167469((*x).kindU.S5.Ident, ((NimStringDesc*) &TMP1714));
		LA12: ;
		if (!LOC11) goto LA13;
		result = NIM_FALSE;
	}
	goto LA1;
	LA13: ;
	{
		invalidpragma_218036(n);
	}
	LA1: ;
	return result;
}

N_NIMCALL(tllstream176204*, filterstrip_218008)(tllstream176204* stdin_218010, NimStringDesc* filename, tnode188803* call) {
	tllstream176204* result;
	NimStringDesc* pattern;
	NIM_BOOL leading;
	NIM_BOOL trailing;
	NimStringDesc* line;
	result = 0;
	pattern = strarg_218021(call, ((NimStringDesc*) &TMP1711), 1, ((NimStringDesc*) &TMP1712));
	leading = boolarg_218028(call, ((NimStringDesc*) &TMP1715), 2, NIM_TRUE);
	trailing = boolarg_218028(call, ((NimStringDesc*) &TMP1716), 3, NIM_TRUE);
	result = llstreamopen_176218(((NimStringDesc*) &TMP1712));
	line = rawNewString(80);
	while (1) {
		NIM_BOOL LOC2;
		NimStringDesc* stripped;
		LOC2 = 0;
		LOC2 = llstreamreadline_176248(stdin_218010, &line);
		if (!LOC2) goto LA1;
		stripped = nsuStrip(line, leading, trailing);
		{
			NIM_BOOL LOC5;
			LOC5 = 0;
			LOC5 = (pattern->Sup.len == 0);
			if (LOC5) goto LA6;
			LOC5 = nsuStartsWith(stripped, pattern);
			LA6: ;
			if (!LOC5) goto LA7;
			llstreamwriteln_176274(result, stripped);
		}
		goto LA3;
		LA7: ;
		{
			llstreamwriteln_176274(result, line);
		}
		LA3: ;
	} LA1: ;
	llstreamclose_176238(stdin_218010);
	return result;
}

N_NIMCALL(tllstream176204*, filterreplace_218002)(tllstream176204* stdin_218004, NimStringDesc* filename, tnode188803* call) {
	tllstream176204* result;
	NimStringDesc* sub;
	NimStringDesc* by;
	NimStringDesc* line;
	result = 0;
	sub = strarg_218021(call, ((NimStringDesc*) &TMP1717), 1, ((NimStringDesc*) &TMP1712));
	{
		if (!(sub->Sup.len == 0)) goto LA3;
		invalidpragma_218036(call);
	}
	LA3: ;
	by = strarg_218021(call, ((NimStringDesc*) &TMP1718), 2, ((NimStringDesc*) &TMP1712));
	result = llstreamopen_176218(((NimStringDesc*) &TMP1712));
	line = rawNewString(80);
	while (1) {
		NIM_BOOL LOC6;
		NimStringDesc* LOC7;
		LOC6 = 0;
		LOC6 = llstreamreadline_176248(stdin_218004, &line);
		if (!LOC6) goto LA5;
		LOC7 = 0;
		LOC7 = nsuReplaceStr(line, sub, by);
		llstreamwriteln_176274(result, LOC7);
	} LA5: ;
	llstreamclose_176238(stdin_218004);
	return result;
}
N_NOINLINE(void, filtersInit)(void) {
}

N_NOINLINE(void, filtersDatInit)(void) {
}

