/* Generated by Nim Compiler v0.13.0 */
/*   (c) 2015 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 32

#include "nimbase.h"
#include <string.h>
typedef struct Tnode214790 Tnode214790;
typedef struct Tsym214822 Tsym214822;
typedef struct Tlineinfo182337 Tlineinfo182337;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Ttype214828 Ttype214828;
typedef struct Tident189012 Tident189012;
typedef struct Tnodeseq214784 Tnodeseq214784;
typedef struct Tidobj189006 Tidobj189006;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Ttypeseq214824 Ttypeseq214824;
typedef struct Tscope214816 Tscope214816;
typedef struct TY214925 TY214925;
typedef struct Tstrtable214794 Tstrtable214794;
typedef struct Tsymseq214792 Tsymseq214792;
typedef struct Tloc214804 Tloc214804;
typedef struct Ropeobj169006 Ropeobj169006;
typedef struct Tlib214808 Tlib214808;
typedef struct Templctx400004 Templctx400004;
typedef struct Tidtable214840 Tidtable214840;
typedef struct Tidpairseq214838 Tidpairseq214838;
typedef struct TY88487 TY88487;
typedef struct Cell47505 Cell47505;
typedef struct Cellseq47521 Cellseq47521;
typedef struct Gcheap49818 Gcheap49818;
typedef struct Gcstack49816 Gcstack49816;
typedef struct Cellset47517 Cellset47517;
typedef struct Pagedesc47513 Pagedesc47513;
typedef struct Memregion29687 Memregion29687;
typedef struct Smallchunk29639 Smallchunk29639;
typedef struct Llchunk29681 Llchunk29681;
typedef struct Bigchunk29641 Bigchunk29641;
typedef struct Intset29614 Intset29614;
typedef struct Trunk29610 Trunk29610;
typedef struct Avlnode29685 Avlnode29685;
typedef struct Gcstat49814 Gcstat49814;
typedef struct Tinstantiation214812 Tinstantiation214812;
typedef struct Tlistentry135010 Tlistentry135010;
typedef struct Tidpair214836 Tidpair214836;
typedef struct Basechunk29637 Basechunk29637;
typedef struct Freecell29629 Freecell29629;
typedef struct TY214913 TY214913;
struct  Tlineinfo182337  {
NI16 line;
NI16 col;
NI32 fileindex;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Tnode214790  {
Ttype214828* typ;
Tlineinfo182337 info;
NU16 flags;
NU8 kind;
union{
struct {NI64 intval;
} S1;
struct {NF floatval;
} S2;
struct {NimStringDesc* strval;
} S3;
struct {Tsym214822* sym;
} S4;
struct {Tident189012* ident;
} S5;
struct {Tnodeseq214784* sons;
} S6;
} kindU;
NimStringDesc* comment;
};
typedef N_NIMCALL_PTR(void, TY3489) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3494) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3489 marker;
TY3494 deepcopy;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  Tidobj189006  {
  TNimObject Sup;
NI id;
};
struct  Tstrtable214794  {
NI counter;
Tsymseq214792* data;
};
struct  Tloc214804  {
NU8 k;
NU8 s;
NU16 flags;
Ttype214828* t;
Ropeobj169006* r;
Ropeobj169006* heaproot;
};
struct  Tsym214822  {
  Tidobj189006 Sup;
NU8 kind;
union{
struct {Ttypeseq214824* typeinstcache;
Tscope214816* typscope;
} S1;
struct {TY214925* procinstcache;
Tsym214822* gcunsafetyreason;
} S2;
struct {TY214925* usedgenerics;
Tstrtable214794 tab;
} S3;
struct {Tsym214822* guard;
NI bitsize;
} S4;
} kindU;
NU8 magic;
Ttype214828* typ;
Tident189012* name;
Tlineinfo182337 info;
Tsym214822* owner;
NU32 flags;
Tnode214790* ast;
NU32 options;
NI position;
NI offset;
Tloc214804 loc;
Tlib214808* annex;
Tnode214790* constraint;
};
struct  Ttype214828  {
  Tidobj189006 Sup;
NU8 kind;
NU8 callconv;
NU32 flags;
Ttypeseq214824* sons;
Tnode214790* n;
Tsym214822* owner;
Tsym214822* sym;
Tsym214822* destructor;
Tsym214822* deepcopy;
Tsym214822* assignment;
NI64 size;
NI16 align;
NI16 locklevel;
Tloc214804 loc;
};
struct  Tidtable214840  {
NI counter;
Tidpairseq214838* data;
};
struct  Templctx400004  {
Tsym214822* owner;
Tsym214822* gensymowner;
NIM_BOOL instlines;
Tidtable214840 mapping;
};
struct TY88487 {
NimStringDesc* Field0;
NI Field1;
};
struct  Cell47505  {
NI refcount;
TNimType* typ;
};
struct  Cellseq47521  {
NI len;
NI cap;
Cell47505** d;
};
struct  Cellset47517  {
NI counter;
NI max;
Pagedesc47513* head;
Pagedesc47513** data;
};
typedef Smallchunk29639* TY29702[512];
typedef Trunk29610* Trunkbuckets29612[256];
struct  Intset29614  {
Trunkbuckets29612 data;
};
struct  Memregion29687  {
NI minlargeobj;
NI maxlargeobj;
TY29702 freesmallchunks;
Llchunk29681* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk29641* freechunkslist;
Intset29614 chunkstarts;
Avlnode29685* root;
Avlnode29685* deleted;
Avlnode29685* last;
Avlnode29685* freeavlnodes;
};
struct  Gcstat49814  {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct  Gcheap49818  {
Gcstack49816* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq47521 zct;
Cellseq47521 decstack;
Cellset47517 cycleroots;
Cellseq47521 tempstack;
NI recgclock;
Memregion29687 region;
Gcstat49814 stat;
};
struct  Tident189012  {
  Tidobj189006 Sup;
NimStringDesc* s;
Tident189012* next;
NI h;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  Tscope214816  {
NI depthlevel;
Tstrtable214794 symbols;
Tnodeseq214784* usingsyms;
Tscope214816* parent;
};
struct  Ropeobj169006  {
  TNimObject Sup;
Ropeobj169006* left;
Ropeobj169006* right;
NI length;
NimStringDesc* data;
};
struct  Tlistentry135010  {
  TNimObject Sup;
Tlistentry135010* prev;
Tlistentry135010* next;
};
struct  Tlib214808  {
  Tlistentry135010 Sup;
NU8 kind;
NIM_BOOL generated;
NIM_BOOL isoverriden;
Ropeobj169006* name;
Tnode214790* path;
};
struct  Tidpair214836  {
Tidobj189006* key;
TNimObject* val;
};
struct  Gcstack49816  {
Gcstack49816* prev;
Gcstack49816* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY29618[16];
struct  Pagedesc47513  {
Pagedesc47513* next;
NI key;
TY29618 bits;
};
struct  Basechunk29637  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk29639  {
  Basechunk29637 Sup;
Smallchunk29639* next;
Smallchunk29639* prev;
Freecell29629* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk29681  {
NI size;
NI acc;
Llchunk29681* next;
};
struct  Bigchunk29641  {
  Basechunk29637 Sup;
Bigchunk29641* next;
Bigchunk29641* prev;
NI align;
NF data;
};
struct  Trunk29610  {
Trunk29610* next;
NI key;
TY29618 bits;
};
typedef Avlnode29685* TY29692[2];
struct  Avlnode29685  {
TY29692 link;
NI key;
NI upperbound;
NI level;
};
struct  Tinstantiation214812  {
Tsym214822* sym;
Ttypeseq214824* concretetypes;
TY214913* usedby;
NI compilesid;
};
struct  Freecell29629  {
Freecell29629* next;
NI zerofield;
};
struct Tnodeseq214784 {
  TGenericSeq Sup;
  Tnode214790* data[SEQ_DECL_SIZE];
};
struct Ttypeseq214824 {
  TGenericSeq Sup;
  Ttype214828* data[SEQ_DECL_SIZE];
};
struct TY214925 {
  TGenericSeq Sup;
  Tinstantiation214812* data[SEQ_DECL_SIZE];
};
struct Tsymseq214792 {
  TGenericSeq Sup;
  Tsym214822* data[SEQ_DECL_SIZE];
};
struct Tidpairseq214838 {
  TGenericSeq Sup;
  Tidpair214836 data[SEQ_DECL_SIZE];
};
struct TY214913 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, globalerror_187071)(Tlineinfo182337 info, NU16 msg, NimStringDesc* arg);
N_NIMCALL(Tnode214790*, evaltemplateargs_400216)(Tnode214790* n, Tsym214822* s);
static N_INLINE(NI, len_215059)(Tnode214790* n);
static N_INLINE(Tnode214790*, HEX5BHEX5D_215238)(Tnode214790* n, NI i);
N_NIMCALL(NI, len_217339)(Ttype214828* n);
N_NIMCALL(Tnode214790*, newnodei_216248)(NU8 kind, Tlineinfo182337 info);
N_NIMCALL(void, addson_216807)(Tnode214790* father, Tnode214790* son);
N_NIMCALL(void, localerror_187080)(Tlineinfo182337 info, NU16 msg, NimStringDesc* arg);
N_NIMCALL(Tnode214790*, copytree_218822)(Tnode214790* src);
N_NIMCALL(void, initidtable_218033)(Tidtable214840* x);
N_NIMCALL(Tnode214790*, getbody_254828)(Tsym214822* s);
static N_INLINE(NIM_BOOL, isatom_219491)(Tnode214790* n);
N_NIMCALL(void, evaltemplateaux_400015)(Tnode214790* templ, Tnode214790* actual, Templctx400004* c, Tnode214790* result);
N_NIMCALL(void, add_215114)(Tnode214790* father, Tnode214790* son);
N_NIMCALL(void, internalerror_187113)(NimStringDesc* errmsg);
N_NIMCALL(NimStringDesc*, HEX24_187183)(TY88487 x);
N_NIMCALL(TNimObject*, idtableget_221107)(Tidtable214840 t, Tidobj189006* key);
N_NIMCALL(Tsym214822*, copysym_217601)(Tsym214822* s, NIM_BOOL keepid);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(Cell47505*, usrtocell_51440)(void* usr);
static N_INLINE(void, rtladdzct_53001)(Cell47505* c);
N_NOINLINE(void, addzct_51417)(Cellseq47521* s, Cell47505* c);
N_NIMCALL(void, idtableput_221115)(Tidtable214840* t, Tidobj189006* key, TNimObject* val);
N_NIMCALL(Tnode214790*, newsymnode_216241)(Tsym214822* sym, Tlineinfo182337 info);
N_NIMCALL(Tnode214790*, copynode_400009)(Templctx400004* ctx, Tnode214790* a, Tnode214790* b);
N_NIMCALL(Tnode214790*, copynode_218542)(Tnode214790* src);
N_NIMCALL(NI, sonslen_217351)(Tnode214790* n);
N_NIMCALL(NimStringDesc*, rendertree_233044)(Tnode214790* n, NU8 renderflags);
static N_INLINE(NI, safelen_215081)(Tnode214790* n);
STRING_LITERAL(TMP2975, "", 0);
STRING_LITERAL(TMP2977, "compiler/evaltempl.nim", 22);
NIM_CONST TY88487 TMP2976 = {((NimStringDesc*) &TMP2977),
((NI) 45)}
;
NI evaltemplatecounter_400328;
extern Tnode214790* emptynode_215801;
extern Gcheap49818 gch_49859;

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

static N_INLINE(Tnode214790*, HEX5BHEX5D_215238)(Tnode214790* n, NI i) {
	Tnode214790* result;
	result = 0;
	result = (*n).kindU.S6.sons->data[i];
	return result;
}

N_NIMCALL(Tnode214790*, evaltemplateargs_400216)(Tnode214790* n, Tsym214822* s) {
	Tnode214790* result;
	NI totalparams;
	NI genericparams;
	NI expectedregularparams;
	NI LOC10;
	NI givenregularparams;
	result = 0;
	switch ((*n).kind) {
	case ((NU8) 27):
	case ((NU8) 29):
	case ((NU8) 30):
	case ((NU8) 31):
	case ((NU8) 26):
	case ((NU8) 28):
	{
		NI LOC2;
		LOC2 = 0;
		LOC2 = len_215059(n);
		totalparams = (NI)(LOC2 - ((NI) 1));
	}
	break;
	default:
	{
		totalparams = ((NI) 0);
	}
	break;
	}
	{
		if (!(((*s).flags &(1U<<((NU)(((NU8) 25))&31U)))!=0)) goto LA6;
		genericparams = ((NI) 0);
	}
	goto LA4;
	LA6: ;
	{
		Tnode214790* LOC9;
		LOC9 = 0;
		LOC9 = HEX5BHEX5D_215238((*s).ast, ((NI) 2));
		genericparams = len_215059(LOC9);
	}
	LA4: ;
	LOC10 = 0;
	LOC10 = len_217339((*s).typ);
	expectedregularparams = (LOC10 - 1);
	givenregularparams = (NI)(totalparams - genericparams);
	{
		if (!((NI)(expectedregularparams + genericparams) < totalparams)) goto LA13;
		globalerror_187071((*n).info, ((NU16) 137), ((NimStringDesc*) &TMP2975));
	}
	LA13: ;
	result = newnodei_216248(((NU8) 152), (*n).info);
	{
		NI i_400257;
		NI res_400309;
		i_400257 = 0;
		res_400309 = ((NI) 1);
		{
			while (1) {
				if (!(res_400309 <= givenregularparams)) goto LA17;
				i_400257 = res_400309;
				addson_216807(result, (*n).kindU.S6.sons->data[i_400257]);
				res_400309 += ((NI) 1);
			} LA17: ;
		}
	}
	{
		NI i_400269;
		NI HEX3Atmp_400314;
		NI res_400317;
		i_400269 = 0;
		HEX3Atmp_400314 = 0;
		HEX3Atmp_400314 = (NI)(givenregularparams + ((NI) 1));
		res_400317 = HEX3Atmp_400314;
		{
			while (1) {
				Tnode214790* default_400274;
				if (!(res_400317 <= expectedregularparams)) goto LA20;
				i_400269 = res_400317;
				default_400274 = (*(*(*(*(*s).typ).n).kindU.S6.sons->data[i_400269]).kindU.S4.sym).ast;
				{
					NIM_BOOL LOC23;
					LOC23 = 0;
					LOC23 = default_400274 == 0;
					if (LOC23) goto LA24;
					LOC23 = ((*default_400274).kind == ((NU8) 1));
					LA24: ;
					if (!LOC23) goto LA25;
					localerror_187080((*n).info, ((NU16) 137), ((NimStringDesc*) &TMP2975));
					addson_216807(result, emptynode_215801);
				}
				goto LA21;
				LA25: ;
				{
					Tnode214790* LOC28;
					LOC28 = 0;
					LOC28 = copytree_218822(default_400274);
					addson_216807(result, LOC28);
				}
				LA21: ;
				res_400317 += ((NI) 1);
			} LA20: ;
		}
	}
	{
		NI i_400303;
		NI res_400324;
		i_400303 = 0;
		res_400324 = ((NI) 1);
		{
			while (1) {
				if (!(res_400324 <= genericparams)) goto LA31;
				i_400303 = res_400324;
				addson_216807(result, (*n).kindU.S6.sons->data[(NI)(givenregularparams + i_400303)]);
				res_400324 += ((NI) 1);
			} LA31: ;
		}
	}
	return result;
}

static N_INLINE(NIM_BOOL, isatom_219491)(Tnode214790* n) {
	NIM_BOOL result;
	NIM_BOOL LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = (((NU8) 0) <= (*n).kind);
	if (!(LOC1)) goto LA2;
	LOC1 = ((*n).kind <= ((NU8) 23));
	LA2: ;
	result = LOC1;
	return result;
}

static N_INLINE(Cell47505*, usrtocell_51440)(void* usr) {
	Cell47505* result;
	result = 0;
	result = ((Cell47505*) ((NI)((NU32)(((NI) (usr))) - (NU32)(((NI)sizeof(Cell47505))))));
	return result;
}

static N_INLINE(void, rtladdzct_53001)(Cell47505* c) {
	addzct_51417((&gch_49859.zct), c);
}

static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src) {
	{
		Cell47505* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_51440(src);
		(*c).refcount += ((NI) 8);
	}
	LA3: ;
	{
		Cell47505* c;
		if (!!(((*dest) == NIM_NIL))) goto LA7;
		c = usrtocell_51440((*dest));
		{
			(*c).refcount -= ((NI) 8);
			if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA11;
			rtladdzct_53001(c);
		}
		LA11: ;
	}
	LA7: ;
	(*dest) = src;
}

N_NIMCALL(Tnode214790*, copynode_400009)(Templctx400004* ctx, Tnode214790* a, Tnode214790* b) {
	Tnode214790* result;
	result = 0;
	result = copynode_218542(a);
	{
		if (!(*ctx).instlines) goto LA3;
		(*result).info = (*b).info;
	}
	LA3: ;
	return result;
}

N_NIMCALL(void, evaltemplateaux_400015)(Tnode214790* templ, Tnode214790* actual, Templctx400004* c, Tnode214790* result) {
	switch ((*templ).kind) {
	case ((NU8) 3):
	{
		Tsym214822* s;
		s = (*templ).kindU.S4.sym;
		{
			if (!((*(*s).owner).Sup.id == (*(*c).owner).Sup.id)) goto LA4;
			{
				NIM_BOOL LOC8;
				Tnode214790* x_400059;
				LOC8 = 0;
				LOC8 = ((*s).kind == ((NU8) 3));
				if (!(LOC8)) goto LA9;
				LOC8 = !((((*s).flags &(1U<<((NU)(((NU8) 31))&31U)))!=0));
				LA9: ;
				if (!LOC8) goto LA10;
				x_400059 = (*actual).kindU.S6.sons->data[(*s).position];
				{
					if (!((*x_400059).kind == ((NU8) 152))) goto LA14;
					{
						Tnode214790* y_400061;
						y_400061 = 0;
						{
							NI i_400190;
							NI HEX3Atmp_400192;
							NI LOC18;
							NI res_400194;
							i_400190 = 0;
							HEX3Atmp_400192 = 0;
							LOC18 = 0;
							LOC18 = len_215059(x_400059);
							HEX3Atmp_400192 = (LOC18 - 1);
							res_400194 = ((NI) 0);
							{
								while (1) {
									if (!(res_400194 <= HEX3Atmp_400192)) goto LA20;
									i_400190 = res_400194;
									y_400061 = (*x_400059).kindU.S6.sons->data[i_400190];
									add_215114(result, y_400061);
									res_400194 += ((NI) 1);
								} LA20: ;
							}
						}
					}
				}
				goto LA12;
				LA14: ;
				{
					Tnode214790* LOC22;
					LOC22 = 0;
					LOC22 = copytree_218822(x_400059);
					add_215114(result, LOC22);
				}
				LA12: ;
			}
			goto LA6;
			LA10: ;
			{
				NIM_BOOL LOC24;
				NIM_BOOL LOC26;
				NIM_BOOL LOC27;
				Tnode214790* x_400117;
				NI LOC32;
				LOC24 = 0;
				LOC24 = ((*s).kind == ((NU8) 4));
				if (LOC24) goto LA25;
				LOC26 = 0;
				LOC27 = 0;
				LOC27 = ((*s).kind == ((NU8) 7));
				if (!(LOC27)) goto LA28;
				LOC27 = !(((*s).typ == NIM_NIL));
				LA28: ;
				LOC26 = LOC27;
				if (!(LOC26)) goto LA29;
				LOC26 = ((*(*s).typ).kind == ((NU8) 12));
				LA29: ;
				LOC24 = LOC26;
				LA25: ;
				if (!LOC24) goto LA30;
				LOC32 = 0;
				LOC32 = len_217339((*(*s).owner).typ);
				x_400117 = (*actual).kindU.S6.sons->data[(NI)((NI)(LOC32 + (*s).position) - ((NI) 1))];
				{
					if (!((*x_400117).kind == ((NU8) 152))) goto LA35;
					{
						Tnode214790* y_400119;
						y_400119 = 0;
						{
							NI i_400201;
							NI HEX3Atmp_400203;
							NI LOC39;
							NI res_400205;
							i_400201 = 0;
							HEX3Atmp_400203 = 0;
							LOC39 = 0;
							LOC39 = len_215059(x_400117);
							HEX3Atmp_400203 = (LOC39 - 1);
							res_400205 = ((NI) 0);
							{
								while (1) {
									if (!(res_400205 <= HEX3Atmp_400203)) goto LA41;
									i_400201 = res_400205;
									y_400119 = (*x_400117).kindU.S6.sons->data[i_400201];
									add_215114(result, y_400119);
									res_400205 += ((NI) 1);
								} LA41: ;
							}
						}
					}
				}
				goto LA33;
				LA35: ;
				{
					Tnode214790* LOC43;
					LOC43 = 0;
					LOC43 = copytree_218822(x_400117);
					add_215114(result, LOC43);
				}
				LA33: ;
			}
			goto LA6;
			LA30: ;
			{
				Tsym214822* x;
				Tidobj189006* LOC50;
				TNimObject* LOC51;
				Tlineinfo182337 LOC58;
				Tnode214790* LOC64;
				{
					NimStringDesc* LOC49;
					if (!!((((*s).flags &(1U<<((NU)(((NU8) 31))&31U)))!=0))) goto LA47;
					LOC49 = 0;
					LOC49 = HEX24_187183(TMP2976);
					internalerror_187113(LOC49);
				}
				LA47: ;
				LOC50 = 0;
				LOC50 = &s->Sup;
				LOC51 = 0;
				LOC51 = idtableget_221107((*c).mapping, LOC50);
				x = ((Tsym214822*) (LOC51));
				{
					Tidobj189006* LOC56;
					TNimObject* LOC57;
					if (!(x == NIM_NIL)) goto LA54;
					x = copysym_217601(s, NIM_FALSE);
					asgnRefNoCycle((void**) (&(*x).owner), (*c).gensymowner);
					LOC56 = 0;
					LOC56 = &s->Sup;
					LOC57 = 0;
					LOC57 = &x->Sup.Sup;
					idtableput_221115((&(*c).mapping), LOC56, LOC57);
				}
				LA54: ;
				{
					if (!(*c).instlines) goto LA61;
					LOC58 = (*actual).info;
				}
				goto LA59;
				LA61: ;
				{
					LOC58 = (*templ).info;
				}
				LA59: ;
				LOC64 = 0;
				LOC64 = newsymnode_216241(x, LOC58);
				add_215114(result, LOC64);
			}
			LA6: ;
		}
		goto LA2;
		LA4: ;
		{
			Tnode214790* LOC66;
			LOC66 = 0;
			LOC66 = copynode_400009((&(*c)), templ, actual);
			add_215114(result, LOC66);
		}
		LA2: ;
	}
	break;
	case ((NU8) 0) ... ((NU8) 2):
	case ((NU8) 4) ... ((NU8) 23):
	{
		Tnode214790* LOC68;
		LOC68 = 0;
		LOC68 = copynode_400009((&(*c)), templ, actual);
		add_215114(result, LOC68);
	}
	break;
	default:
	{
		Tnode214790* res;
		res = copynode_400009((&(*c)), templ, actual);
		{
			NI i_400183;
			NI HEX3Atmp_400209;
			NI LOC71;
			NI res_400212;
			i_400183 = 0;
			HEX3Atmp_400209 = 0;
			LOC71 = 0;
			LOC71 = sonslen_217351(templ);
			HEX3Atmp_400209 = (NI)(LOC71 - ((NI) 1));
			res_400212 = ((NI) 0);
			{
				while (1) {
					if (!(res_400212 <= HEX3Atmp_400209)) goto LA73;
					i_400183 = res_400212;
					evaltemplateaux_400015((*templ).kindU.S6.sons->data[i_400183], actual, c, res);
					res_400212 += ((NI) 1);
				} LA73: ;
			}
		}
		add_215114(result, res);
	}
	break;
	}
}

static N_INLINE(NI, safelen_215081)(Tnode214790* n) {
	NI result;
	result = 0;
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = ((*n).kind >= ((NU8) 0) && (*n).kind <= ((NU8) 23));
		if (LOC3) goto LA4;
		LOC3 = (*n).kindU.S6.sons == 0;
		LA4: ;
		if (!LOC3) goto LA5;
		result = ((NI) 0);
	}
	goto LA1;
	LA5: ;
	{
		result = ((*n).kindU.S6.sons ? (*n).kindU.S6.sons->Sup.len : 0);
	}
	LA1: ;
	return result;
}

N_NIMCALL(Tnode214790*, evaltemplate_400329)(Tnode214790* n, Tsym214822* tmpl, Tsym214822* gensymowner) {
	Tnode214790* result;
	Tnode214790* args;
	Templctx400004 ctx;
	Tnode214790* body;
	result = 0;
	evaltemplatecounter_400328 += ((NI) 1);
	{
		if (!(((NI) 100) < evaltemplatecounter_400328)) goto LA3;
		globalerror_187071((*n).info, ((NU16) 188), ((NimStringDesc*) &TMP2975));
		result = n;
	}
	LA3: ;
	args = evaltemplateargs_400216(n, tmpl);
	memset((void*)(&ctx), 0, sizeof(ctx));
	ctx.owner = tmpl;
	ctx.gensymowner = gensymowner;
	initidtable_218033((&ctx.mapping));
	body = getbody_254828(tmpl);
	{
		NIM_BOOL LOC7;
		LOC7 = 0;
		LOC7 = isatom_219491(body);
		if (!LOC7) goto LA8;
		result = newnodei_216248(((NU8) 37), (*body).info);
		evaltemplateaux_400015(body, args, (&ctx), result);
		{
			NI LOC12;
			LOC12 = 0;
			LOC12 = len_215059(result);
			if (!(LOC12 == ((NI) 1))) goto LA13;
			result = (*result).kindU.S6.sons->data[((NI) 0)];
		}
		goto LA10;
		LA13: ;
		{
			NimStringDesc* LOC16;
			LOC16 = 0;
			LOC16 = rendertree_233044(result, 4);
			localerror_187080((*result).info, ((NU16) 1), LOC16);
		}
		LA10: ;
	}
	goto LA5;
	LA8: ;
	{
		result = copynode_218542(body);
		{
			NI i_400365;
			NI HEX3Atmp_400379;
			NI LOC19;
			NI res_400382;
			i_400365 = 0;
			HEX3Atmp_400379 = 0;
			LOC19 = 0;
			LOC19 = safelen_215081(body);
			HEX3Atmp_400379 = (NI)(LOC19 - ((NI) 1));
			res_400382 = ((NI) 0);
			{
				while (1) {
					if (!(res_400382 <= HEX3Atmp_400379)) goto LA21;
					i_400365 = res_400382;
					evaltemplateaux_400015((*body).kindU.S6.sons->data[i_400365], args, (&ctx), result);
					res_400382 += ((NI) 1);
				} LA21: ;
			}
		}
	}
	LA5: ;
	evaltemplatecounter_400328 -= ((NI) 1);
	return result;
}
NIM_EXTERNC N_NOINLINE(void, compiler_evaltemplInit000)(void) {
	evaltemplatecounter_400328 = ((NI) 0);
}

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

