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

#include "nimbase.h"
#include <string.h>
typedef struct Tnode213790 Tnode213790;
typedef struct Tsym213822 Tsym213822;
typedef struct Tlineinfo181337 Tlineinfo181337;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Ttype213828 Ttype213828;
typedef struct Tident188012 Tident188012;
typedef struct Tnodeseq213784 Tnodeseq213784;
typedef struct Tidobj188006 Tidobj188006;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Ttypeseq213824 Ttypeseq213824;
typedef struct Tscope213816 Tscope213816;
typedef struct TY213925 TY213925;
typedef struct Tstrtable213794 Tstrtable213794;
typedef struct Tsymseq213792 Tsymseq213792;
typedef struct Tloc213804 Tloc213804;
typedef struct Ropeobj168006 Ropeobj168006;
typedef struct Tlib213808 Tlib213808;
typedef struct Templctx399004 Templctx399004;
typedef struct Tidtable213840 Tidtable213840;
typedef struct Tidpairseq213838 Tidpairseq213838;
typedef struct TY88887 TY88887;
typedef struct Cell47705 Cell47705;
typedef struct Cellseq47721 Cellseq47721;
typedef struct Gcheap50018 Gcheap50018;
typedef struct Gcstack50016 Gcstack50016;
typedef struct Cellset47717 Cellset47717;
typedef struct Pagedesc47713 Pagedesc47713;
typedef struct Memregion29888 Memregion29888;
typedef struct Smallchunk29840 Smallchunk29840;
typedef struct Llchunk29882 Llchunk29882;
typedef struct Bigchunk29842 Bigchunk29842;
typedef struct Intset29814 Intset29814;
typedef struct Trunk29810 Trunk29810;
typedef struct Avlnode29886 Avlnode29886;
typedef struct Gcstat50014 Gcstat50014;
typedef struct Tinstantiation213812 Tinstantiation213812;
typedef struct Tlistentry135010 Tlistentry135010;
typedef struct Tidpair213836 Tidpair213836;
typedef struct Basechunk29838 Basechunk29838;
typedef struct Freecell29830 Freecell29830;
typedef struct TY213913 TY213913;
struct  Tlineinfo181337  {
NI16 line;
NI16 col;
NI32 fileindex;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Tnode213790  {
Ttype213828* typ;
Tlineinfo181337 info;
NU16 flags;
NU8 kind;
union{
struct {NI64 intval;
} S1;
struct {NF floatval;
} S2;
struct {NimStringDesc* strval;
} S3;
struct {Tsym213822* sym;
} S4;
struct {Tident188012* ident;
} S5;
struct {Tnodeseq213784* 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  Tidobj188006  {
  TNimObject Sup;
NI id;
};
struct  Tstrtable213794  {
NI counter;
Tsymseq213792* data;
};
struct  Tloc213804  {
NU8 k;
NU8 s;
NU16 flags;
Ttype213828* t;
Ropeobj168006* r;
Ropeobj168006* heaproot;
};
struct  Tsym213822  {
  Tidobj188006 Sup;
NU8 kind;
union{
struct {Ttypeseq213824* typeinstcache;
Tscope213816* typscope;
} S1;
struct {TY213925* procinstcache;
Tsym213822* gcunsafetyreason;
} S2;
struct {TY213925* usedgenerics;
Tstrtable213794 tab;
} S3;
struct {Tsym213822* guard;
NI bitsize;
} S4;
} kindU;
NU8 magic;
Ttype213828* typ;
Tident188012* name;
Tlineinfo181337 info;
Tsym213822* owner;
NU32 flags;
Tnode213790* ast;
NU32 options;
NI position;
NI offset;
Tloc213804 loc;
Tlib213808* annex;
Tnode213790* constraint;
};
struct  Ttype213828  {
  Tidobj188006 Sup;
NU8 kind;
NU8 callconv;
NU32 flags;
Ttypeseq213824* sons;
Tnode213790* n;
Tsym213822* owner;
Tsym213822* sym;
Tsym213822* destructor;
Tsym213822* deepcopy;
Tsym213822* assignment;
NI64 size;
NI16 align;
NI16 locklevel;
Tloc213804 loc;
};
struct  Tidtable213840  {
NI counter;
Tidpairseq213838* data;
};
struct  Templctx399004  {
Tsym213822* owner;
Tsym213822* gensymowner;
NIM_BOOL instlines;
Tidtable213840 mapping;
};
struct TY88887 {
NimStringDesc* Field0;
NI Field1;
};
struct  Cell47705  {
NI refcount;
TNimType* typ;
};
struct  Cellseq47721  {
NI len;
NI cap;
Cell47705** d;
};
struct  Cellset47717  {
NI counter;
NI max;
Pagedesc47713* head;
Pagedesc47713** data;
};
typedef Smallchunk29840* TY29903[512];
typedef Trunk29810* Trunkbuckets29812[256];
struct  Intset29814  {
Trunkbuckets29812 data;
};
struct  Memregion29888  {
NI minlargeobj;
NI maxlargeobj;
TY29903 freesmallchunks;
Llchunk29882* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk29842* freechunkslist;
Intset29814 chunkstarts;
Avlnode29886* root;
Avlnode29886* deleted;
Avlnode29886* last;
Avlnode29886* freeavlnodes;
};
struct  Gcstat50014  {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct  Gcheap50018  {
Gcstack50016* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq47721 zct;
Cellseq47721 decstack;
Cellset47717 cycleroots;
Cellseq47721 tempstack;
NI recgclock;
Memregion29888 region;
Gcstat50014 stat;
};
struct  Tident188012  {
  Tidobj188006 Sup;
NimStringDesc* s;
Tident188012* next;
NI h;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  Tscope213816  {
NI depthlevel;
Tstrtable213794 symbols;
Tnodeseq213784* usingsyms;
Tscope213816* parent;
};
struct  Ropeobj168006  {
  TNimObject Sup;
Ropeobj168006* left;
Ropeobj168006* right;
NI length;
NimStringDesc* data;
};
struct  Tlistentry135010  {
  TNimObject Sup;
Tlistentry135010* prev;
Tlistentry135010* next;
};
struct  Tlib213808  {
  Tlistentry135010 Sup;
NU8 kind;
NIM_BOOL generated;
NIM_BOOL isoverriden;
Ropeobj168006* name;
Tnode213790* path;
};
struct  Tidpair213836  {
Tidobj188006* key;
TNimObject* val;
};
struct  Gcstack50016  {
Gcstack50016* prev;
Gcstack50016* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY29819[8];
struct  Pagedesc47713  {
Pagedesc47713* next;
NI key;
TY29819 bits;
};
struct  Basechunk29838  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk29840  {
  Basechunk29838 Sup;
Smallchunk29840* next;
Smallchunk29840* prev;
Freecell29830* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk29882  {
NI size;
NI acc;
Llchunk29882* next;
};
struct  Bigchunk29842  {
  Basechunk29838 Sup;
Bigchunk29842* next;
Bigchunk29842* prev;
NI align;
NF data;
};
struct  Trunk29810  {
Trunk29810* next;
NI key;
TY29819 bits;
};
typedef Avlnode29886* TY29893[2];
struct  Avlnode29886  {
TY29893 link;
NI key;
NI upperbound;
NI level;
};
struct  Tinstantiation213812  {
Tsym213822* sym;
Ttypeseq213824* concretetypes;
TY213913* usedby;
NI compilesid;
};
struct  Freecell29830  {
Freecell29830* next;
NI zerofield;
};
struct Tnodeseq213784 {
  TGenericSeq Sup;
  Tnode213790* data[SEQ_DECL_SIZE];
};
struct Ttypeseq213824 {
  TGenericSeq Sup;
  Ttype213828* data[SEQ_DECL_SIZE];
};
struct TY213925 {
  TGenericSeq Sup;
  Tinstantiation213812* data[SEQ_DECL_SIZE];
};
struct Tsymseq213792 {
  TGenericSeq Sup;
  Tsym213822* data[SEQ_DECL_SIZE];
};
struct Tidpairseq213838 {
  TGenericSeq Sup;
  Tidpair213836 data[SEQ_DECL_SIZE];
};
struct TY213913 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, globalerror_186071)(Tlineinfo181337 info, NU16 msg, NimStringDesc* arg);
N_NIMCALL(Tnode213790*, evaltemplateargs_399216)(Tnode213790* n, Tsym213822* s);
static N_INLINE(NI, len_214059)(Tnode213790* n);
static N_INLINE(Tnode213790*, HEX5BHEX5D_214238)(Tnode213790* n, NI i);
N_NIMCALL(NI, len_216339)(Ttype213828* n);
N_NIMCALL(Tnode213790*, newnodei_215248)(NU8 kind, Tlineinfo181337 info);
N_NIMCALL(void, addson_215807)(Tnode213790* father, Tnode213790* son);
N_NIMCALL(void, localerror_186080)(Tlineinfo181337 info, NU16 msg, NimStringDesc* arg);
N_NIMCALL(Tnode213790*, copytree_217822)(Tnode213790* src);
N_NIMCALL(void, initidtable_217033)(Tidtable213840* x);
N_NIMCALL(Tnode213790*, getbody_253827)(Tsym213822* s);
static N_INLINE(NIM_BOOL, isatom_218492)(Tnode213790* n);
N_NIMCALL(void, evaltemplateaux_399015)(Tnode213790* templ, Tnode213790* actual, Templctx399004* c, Tnode213790* result);
N_NIMCALL(void, add_214114)(Tnode213790* father, Tnode213790* son);
N_NIMCALL(void, internalerror_186113)(NimStringDesc* errmsg);
N_NIMCALL(NimStringDesc*, HEX24_186183)(TY88887 x);
N_NIMCALL(TNimObject*, idtableget_220107)(Tidtable213840 t, Tidobj188006* key);
N_NIMCALL(Tsym213822*, copysym_216601)(Tsym213822* s, NIM_BOOL keepid);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(Cell47705*, usrtocell_51640)(void* usr);
static N_INLINE(void, rtladdzct_53201)(Cell47705* c);
N_NOINLINE(void, addzct_51617)(Cellseq47721* s, Cell47705* c);
N_NIMCALL(void, idtableput_220115)(Tidtable213840* t, Tidobj188006* key, TNimObject* val);
N_NIMCALL(Tnode213790*, newsymnode_215241)(Tsym213822* sym, Tlineinfo181337 info);
N_NIMCALL(Tnode213790*, copynode_399009)(Templctx399004* ctx, Tnode213790* a, Tnode213790* b);
N_NIMCALL(Tnode213790*, copynode_217542)(Tnode213790* src);
N_NIMCALL(NI, sonslen_216351)(Tnode213790* n);
N_NIMCALL(NimStringDesc*, rendertree_232044)(Tnode213790* n, NU8 renderflags);
static N_INLINE(NI, safelen_214081)(Tnode213790* n);
STRING_LITERAL(TMP2974, "", 0);
STRING_LITERAL(TMP2976, "compiler/evaltempl.nim", 22);
NIM_CONST TY88887 TMP2975 = {((NimStringDesc*) &TMP2976),
((NI) 45)}
;
NI evaltemplatecounter_399328;
extern Tnode213790* emptynode_214801;
extern Gcheap50018 gch_50059;

static N_INLINE(NI, len_214059)(Tnode213790* 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(Tnode213790*, HEX5BHEX5D_214238)(Tnode213790* n, NI i) {
	Tnode213790* result;
	result = 0;
	result = (*n).kindU.S6.sons->data[i];
	return result;
}

N_NIMCALL(Tnode213790*, evaltemplateargs_399216)(Tnode213790* n, Tsym213822* s) {
	Tnode213790* 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_214059(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: ;
	{
		Tnode213790* LOC9;
		LOC9 = 0;
		LOC9 = HEX5BHEX5D_214238((*s).ast, ((NI) 2));
		genericparams = len_214059(LOC9);
	}
	LA4: ;
	LOC10 = 0;
	LOC10 = len_216339((*s).typ);
	expectedregularparams = (LOC10 - 1);
	givenregularparams = (NI)(totalparams - genericparams);
	{
		if (!((NI)(expectedregularparams + genericparams) < totalparams)) goto LA13;
		globalerror_186071((*n).info, ((NU16) 137), ((NimStringDesc*) &TMP2974));
	}
	LA13: ;
	result = newnodei_215248(((NU8) 152), (*n).info);
	{
		NI i_399257;
		NI res_399309;
		i_399257 = 0;
		res_399309 = ((NI) 1);
		{
			while (1) {
				if (!(res_399309 <= givenregularparams)) goto LA17;
				i_399257 = res_399309;
				addson_215807(result, (*n).kindU.S6.sons->data[i_399257]);
				res_399309 += ((NI) 1);
			} LA17: ;
		}
	}
	{
		NI i_399269;
		NI HEX3Atmp_399314;
		NI res_399317;
		i_399269 = 0;
		HEX3Atmp_399314 = 0;
		HEX3Atmp_399314 = (NI)(givenregularparams + ((NI) 1));
		res_399317 = HEX3Atmp_399314;
		{
			while (1) {
				Tnode213790* default_399274;
				if (!(res_399317 <= expectedregularparams)) goto LA20;
				i_399269 = res_399317;
				default_399274 = (*(*(*(*(*s).typ).n).kindU.S6.sons->data[i_399269]).kindU.S4.sym).ast;
				{
					NIM_BOOL LOC23;
					LOC23 = 0;
					LOC23 = default_399274 == 0;
					if (LOC23) goto LA24;
					LOC23 = ((*default_399274).kind == ((NU8) 1));
					LA24: ;
					if (!LOC23) goto LA25;
					localerror_186080((*n).info, ((NU16) 137), ((NimStringDesc*) &TMP2974));
					addson_215807(result, emptynode_214801);
				}
				goto LA21;
				LA25: ;
				{
					Tnode213790* LOC28;
					LOC28 = 0;
					LOC28 = copytree_217822(default_399274);
					addson_215807(result, LOC28);
				}
				LA21: ;
				res_399317 += ((NI) 1);
			} LA20: ;
		}
	}
	{
		NI i_399303;
		NI res_399324;
		i_399303 = 0;
		res_399324 = ((NI) 1);
		{
			while (1) {
				if (!(res_399324 <= genericparams)) goto LA31;
				i_399303 = res_399324;
				addson_215807(result, (*n).kindU.S6.sons->data[(NI)(givenregularparams + i_399303)]);
				res_399324 += ((NI) 1);
			} LA31: ;
		}
	}
	return result;
}

static N_INLINE(NIM_BOOL, isatom_218492)(Tnode213790* 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(Cell47705*, usrtocell_51640)(void* usr) {
	Cell47705* result;
	result = 0;
	result = ((Cell47705*) ((NI)((NU64)(((NI) (usr))) - (NU64)(((NI)sizeof(Cell47705))))));
	return result;
}

static N_INLINE(void, rtladdzct_53201)(Cell47705* c) {
	addzct_51617((&gch_50059.zct), c);
}

static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src) {
	{
		Cell47705* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_51640(src);
		(*c).refcount += ((NI) 8);
	}
	LA3: ;
	{
		Cell47705* c;
		if (!!(((*dest) == NIM_NIL))) goto LA7;
		c = usrtocell_51640((*dest));
		{
			(*c).refcount -= ((NI) 8);
			if (!((NU64)((*c).refcount) < (NU64)(((NI) 8)))) goto LA11;
			rtladdzct_53201(c);
		}
		LA11: ;
	}
	LA7: ;
	(*dest) = src;
}

N_NIMCALL(Tnode213790*, copynode_399009)(Templctx399004* ctx, Tnode213790* a, Tnode213790* b) {
	Tnode213790* result;
	result = 0;
	result = copynode_217542(a);
	{
		if (!(*ctx).instlines) goto LA3;
		(*result).info = (*b).info;
	}
	LA3: ;
	return result;
}

N_NIMCALL(void, evaltemplateaux_399015)(Tnode213790* templ, Tnode213790* actual, Templctx399004* c, Tnode213790* result) {
	switch ((*templ).kind) {
	case ((NU8) 3):
	{
		Tsym213822* s;
		s = (*templ).kindU.S4.sym;
		{
			if (!((*(*s).owner).Sup.id == (*(*c).owner).Sup.id)) goto LA4;
			{
				NIM_BOOL LOC8;
				Tnode213790* x_399059;
				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_399059 = (*actual).kindU.S6.sons->data[(*s).position];
				{
					if (!((*x_399059).kind == ((NU8) 152))) goto LA14;
					{
						Tnode213790* y_399061;
						y_399061 = 0;
						{
							NI i_399190;
							NI HEX3Atmp_399192;
							NI LOC18;
							NI res_399194;
							i_399190 = 0;
							HEX3Atmp_399192 = 0;
							LOC18 = 0;
							LOC18 = len_214059(x_399059);
							HEX3Atmp_399192 = (LOC18 - 1);
							res_399194 = ((NI) 0);
							{
								while (1) {
									if (!(res_399194 <= HEX3Atmp_399192)) goto LA20;
									i_399190 = res_399194;
									y_399061 = (*x_399059).kindU.S6.sons->data[i_399190];
									add_214114(result, y_399061);
									res_399194 += ((NI) 1);
								} LA20: ;
							}
						}
					}
				}
				goto LA12;
				LA14: ;
				{
					Tnode213790* LOC22;
					LOC22 = 0;
					LOC22 = copytree_217822(x_399059);
					add_214114(result, LOC22);
				}
				LA12: ;
			}
			goto LA6;
			LA10: ;
			{
				NIM_BOOL LOC24;
				NIM_BOOL LOC26;
				NIM_BOOL LOC27;
				Tnode213790* x_399117;
				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_216339((*(*s).owner).typ);
				x_399117 = (*actual).kindU.S6.sons->data[(NI)((NI)(LOC32 + (*s).position) - ((NI) 1))];
				{
					if (!((*x_399117).kind == ((NU8) 152))) goto LA35;
					{
						Tnode213790* y_399119;
						y_399119 = 0;
						{
							NI i_399201;
							NI HEX3Atmp_399203;
							NI LOC39;
							NI res_399205;
							i_399201 = 0;
							HEX3Atmp_399203 = 0;
							LOC39 = 0;
							LOC39 = len_214059(x_399117);
							HEX3Atmp_399203 = (LOC39 - 1);
							res_399205 = ((NI) 0);
							{
								while (1) {
									if (!(res_399205 <= HEX3Atmp_399203)) goto LA41;
									i_399201 = res_399205;
									y_399119 = (*x_399117).kindU.S6.sons->data[i_399201];
									add_214114(result, y_399119);
									res_399205 += ((NI) 1);
								} LA41: ;
							}
						}
					}
				}
				goto LA33;
				LA35: ;
				{
					Tnode213790* LOC43;
					LOC43 = 0;
					LOC43 = copytree_217822(x_399117);
					add_214114(result, LOC43);
				}
				LA33: ;
			}
			goto LA6;
			LA30: ;
			{
				Tsym213822* x;
				Tidobj188006* LOC50;
				TNimObject* LOC51;
				Tlineinfo181337 LOC58;
				Tnode213790* LOC64;
				{
					NimStringDesc* LOC49;
					if (!!((((*s).flags &(1U<<((NU)(((NU8) 31))&31U)))!=0))) goto LA47;
					LOC49 = 0;
					LOC49 = HEX24_186183(TMP2975);
					internalerror_186113(LOC49);
				}
				LA47: ;
				LOC50 = 0;
				LOC50 = &s->Sup;
				LOC51 = 0;
				LOC51 = idtableget_220107((*c).mapping, LOC50);
				x = ((Tsym213822*) (LOC51));
				{
					Tidobj188006* LOC56;
					TNimObject* LOC57;
					if (!(x == NIM_NIL)) goto LA54;
					x = copysym_216601(s, NIM_FALSE);
					asgnRefNoCycle((void**) (&(*x).owner), (*c).gensymowner);
					LOC56 = 0;
					LOC56 = &s->Sup;
					LOC57 = 0;
					LOC57 = &x->Sup.Sup;
					idtableput_220115((&(*c).mapping), LOC56, LOC57);
				}
				LA54: ;
				{
					if (!(*c).instlines) goto LA61;
					LOC58 = (*actual).info;
				}
				goto LA59;
				LA61: ;
				{
					LOC58 = (*templ).info;
				}
				LA59: ;
				LOC64 = 0;
				LOC64 = newsymnode_215241(x, LOC58);
				add_214114(result, LOC64);
			}
			LA6: ;
		}
		goto LA2;
		LA4: ;
		{
			Tnode213790* LOC66;
			LOC66 = 0;
			LOC66 = copynode_399009((&(*c)), templ, actual);
			add_214114(result, LOC66);
		}
		LA2: ;
	}
	break;
	case ((NU8) 0) ... ((NU8) 2):
	case ((NU8) 4) ... ((NU8) 23):
	{
		Tnode213790* LOC68;
		LOC68 = 0;
		LOC68 = copynode_399009((&(*c)), templ, actual);
		add_214114(result, LOC68);
	}
	break;
	default:
	{
		Tnode213790* res;
		res = copynode_399009((&(*c)), templ, actual);
		{
			NI i_399183;
			NI HEX3Atmp_399209;
			NI LOC71;
			NI res_399212;
			i_399183 = 0;
			HEX3Atmp_399209 = 0;
			LOC71 = 0;
			LOC71 = sonslen_216351(templ);
			HEX3Atmp_399209 = (NI)(LOC71 - ((NI) 1));
			res_399212 = ((NI) 0);
			{
				while (1) {
					if (!(res_399212 <= HEX3Atmp_399209)) goto LA73;
					i_399183 = res_399212;
					evaltemplateaux_399015((*templ).kindU.S6.sons->data[i_399183], actual, c, res);
					res_399212 += ((NI) 1);
				} LA73: ;
			}
		}
		add_214114(result, res);
	}
	break;
	}
}

static N_INLINE(NI, safelen_214081)(Tnode213790* 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(Tnode213790*, evaltemplate_399329)(Tnode213790* n, Tsym213822* tmpl, Tsym213822* gensymowner) {
	Tnode213790* result;
	Tnode213790* args;
	Templctx399004 ctx;
	Tnode213790* body;
	result = 0;
	evaltemplatecounter_399328 += ((NI) 1);
	{
		if (!(((NI) 100) < evaltemplatecounter_399328)) goto LA3;
		globalerror_186071((*n).info, ((NU16) 188), ((NimStringDesc*) &TMP2974));
		result = n;
	}
	LA3: ;
	args = evaltemplateargs_399216(n, tmpl);
	memset((void*)(&ctx), 0, sizeof(ctx));
	ctx.owner = tmpl;
	ctx.gensymowner = gensymowner;
	initidtable_217033((&ctx.mapping));
	body = getbody_253827(tmpl);
	{
		NIM_BOOL LOC7;
		LOC7 = 0;
		LOC7 = isatom_218492(body);
		if (!LOC7) goto LA8;
		result = newnodei_215248(((NU8) 37), (*body).info);
		evaltemplateaux_399015(body, args, (&ctx), result);
		{
			NI LOC12;
			LOC12 = 0;
			LOC12 = len_214059(result);
			if (!(LOC12 == ((NI) 1))) goto LA13;
			result = (*result).kindU.S6.sons->data[((NI) 0)];
		}
		goto LA10;
		LA13: ;
		{
			NimStringDesc* LOC16;
			LOC16 = 0;
			LOC16 = rendertree_232044(result, 4);
			localerror_186080((*result).info, ((NU16) 1), LOC16);
		}
		LA10: ;
	}
	goto LA5;
	LA8: ;
	{
		result = copynode_217542(body);
		{
			NI i_399365;
			NI HEX3Atmp_399379;
			NI LOC19;
			NI res_399382;
			i_399365 = 0;
			HEX3Atmp_399379 = 0;
			LOC19 = 0;
			LOC19 = safelen_214081(body);
			HEX3Atmp_399379 = (NI)(LOC19 - ((NI) 1));
			res_399382 = ((NI) 0);
			{
				while (1) {
					if (!(res_399382 <= HEX3Atmp_399379)) goto LA21;
					i_399365 = res_399382;
					evaltemplateaux_399015((*body).kindU.S6.sons->data[i_399365], args, (&ctx), result);
					res_399382 += ((NI) 1);
				} LA21: ;
			}
		}
	}
	LA5: ;
	evaltemplatecounter_399328 -= ((NI) 1);
	return result;
}
NIM_EXTERNC N_NOINLINE(void, compiler_evaltemplInit000)(void) {
	evaltemplatecounter_399328 = ((NI) 0);
}

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

