/* 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 Tnode215790 Tnode215790;
typedef struct Tsym215822 Tsym215822;
typedef struct Tlineinfo183337 Tlineinfo183337;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Ttype215828 Ttype215828;
typedef struct Tident190012 Tident190012;
typedef struct Tnodeseq215784 Tnodeseq215784;
typedef struct Tidobj190006 Tidobj190006;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Ttypeseq215824 Ttypeseq215824;
typedef struct Tscope215816 Tscope215816;
typedef struct TY215925 TY215925;
typedef struct Tstrtable215794 Tstrtable215794;
typedef struct Tsymseq215792 Tsymseq215792;
typedef struct Tloc215804 Tloc215804;
typedef struct Ropeobj170006 Ropeobj170006;
typedef struct Tlib215808 Tlib215808;
typedef struct Templctx401004 Templctx401004;
typedef struct Tidtable215840 Tidtable215840;
typedef struct Tidpairseq215838 Tidpairseq215838;
typedef struct TY88687 TY88687;
typedef struct Cell47504 Cell47504;
typedef struct Cellseq47520 Cellseq47520;
typedef struct Gcheap49818 Gcheap49818;
typedef struct Gcstack49816 Gcstack49816;
typedef struct Cellset47516 Cellset47516;
typedef struct Pagedesc47512 Pagedesc47512;
typedef struct Memregion29688 Memregion29688;
typedef struct Smallchunk29640 Smallchunk29640;
typedef struct Llchunk29682 Llchunk29682;
typedef struct Bigchunk29642 Bigchunk29642;
typedef struct Intset29614 Intset29614;
typedef struct Trunk29610 Trunk29610;
typedef struct Avlnode29686 Avlnode29686;
typedef struct Gcstat49814 Gcstat49814;
typedef struct Tinstantiation215812 Tinstantiation215812;
typedef struct Tlistentry135010 Tlistentry135010;
typedef struct Tidpair215836 Tidpair215836;
typedef struct Basechunk29638 Basechunk29638;
typedef struct Freecell29630 Freecell29630;
typedef struct TY215913 TY215913;
struct  Tlineinfo183337  {
NI16 line;
NI16 col;
NI32 fileindex;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Tnode215790  {
Ttype215828* typ;
Tlineinfo183337 info;
NU16 flags;
NU8 kind;
union{
struct {NI64 intval;
} S1;
struct {NF floatval;
} S2;
struct {NimStringDesc* strval;
} S3;
struct {Tsym215822* sym;
} S4;
struct {Tident190012* ident;
} S5;
struct {Tnodeseq215784* 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  Tidobj190006  {
  TNimObject Sup;
NI id;
};
struct  Tstrtable215794  {
NI counter;
Tsymseq215792* data;
};
struct  Tloc215804  {
NU8 k;
NU8 s;
NU16 flags;
Ttype215828* t;
Ropeobj170006* r;
Ropeobj170006* heaproot;
};
struct  Tsym215822  {
  Tidobj190006 Sup;
NU8 kind;
union{
struct {Ttypeseq215824* typeinstcache;
Tscope215816* typscope;
} S1;
struct {TY215925* procinstcache;
Tsym215822* gcunsafetyreason;
} S2;
struct {TY215925* usedgenerics;
Tstrtable215794 tab;
} S3;
struct {Tsym215822* guard;
NI bitsize;
} S4;
} kindU;
NU8 magic;
Ttype215828* typ;
Tident190012* name;
Tlineinfo183337 info;
Tsym215822* owner;
NU32 flags;
Tnode215790* ast;
NU32 options;
NI position;
NI offset;
Tloc215804 loc;
Tlib215808* annex;
Tnode215790* constraint;
};
struct  Ttype215828  {
  Tidobj190006 Sup;
NU8 kind;
NU8 callconv;
NU32 flags;
Ttypeseq215824* sons;
Tnode215790* n;
Tsym215822* owner;
Tsym215822* sym;
Tsym215822* destructor;
Tsym215822* deepcopy;
Tsym215822* assignment;
NI64 size;
NI16 align;
NI16 locklevel;
Tloc215804 loc;
};
struct  Tidtable215840  {
NI counter;
Tidpairseq215838* data;
};
struct  Templctx401004  {
Tsym215822* owner;
Tsym215822* gensymowner;
NIM_BOOL instlines;
Tidtable215840 mapping;
};
struct TY88687 {
NimStringDesc* Field0;
NI Field1;
};
struct  Cell47504  {
NI refcount;
TNimType* typ;
};
struct  Cellseq47520  {
NI len;
NI cap;
Cell47504** d;
};
struct  Cellset47516  {
NI counter;
NI max;
Pagedesc47512* head;
Pagedesc47512** data;
};
typedef Smallchunk29640* TY29703[512];
typedef Trunk29610* Trunkbuckets29612[256];
struct  Intset29614  {
Trunkbuckets29612 data;
};
struct  Memregion29688  {
NI minlargeobj;
NI maxlargeobj;
TY29703 freesmallchunks;
Llchunk29682* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk29642* freechunkslist;
Intset29614 chunkstarts;
Avlnode29686* root;
Avlnode29686* deleted;
Avlnode29686* last;
Avlnode29686* 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;
Cellseq47520 zct;
Cellseq47520 decstack;
Cellset47516 cycleroots;
Cellseq47520 tempstack;
NI recgclock;
Memregion29688 region;
Gcstat49814 stat;
};
struct  Tident190012  {
  Tidobj190006 Sup;
NimStringDesc* s;
Tident190012* next;
NI h;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  Tscope215816  {
NI depthlevel;
Tstrtable215794 symbols;
Tnodeseq215784* usingsyms;
Tscope215816* parent;
};
struct  Ropeobj170006  {
  TNimObject Sup;
Ropeobj170006* left;
Ropeobj170006* right;
NI length;
NimStringDesc* data;
};
struct  Tlistentry135010  {
  TNimObject Sup;
Tlistentry135010* prev;
Tlistentry135010* next;
};
struct  Tlib215808  {
  Tlistentry135010 Sup;
NU8 kind;
NIM_BOOL generated;
NIM_BOOL isoverriden;
Ropeobj170006* name;
Tnode215790* path;
};
struct  Tidpair215836  {
Tidobj190006* key;
TNimObject* val;
};
struct  Gcstack49816  {
Gcstack49816* prev;
Gcstack49816* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY29619[8];
struct  Pagedesc47512  {
Pagedesc47512* next;
NI key;
TY29619 bits;
};
struct  Basechunk29638  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk29640  {
  Basechunk29638 Sup;
Smallchunk29640* next;
Smallchunk29640* prev;
Freecell29630* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk29682  {
NI size;
NI acc;
Llchunk29682* next;
};
struct  Bigchunk29642  {
  Basechunk29638 Sup;
Bigchunk29642* next;
Bigchunk29642* prev;
NI align;
NF data;
};
struct  Trunk29610  {
Trunk29610* next;
NI key;
TY29619 bits;
};
typedef Avlnode29686* TY29693[2];
struct  Avlnode29686  {
TY29693 link;
NI key;
NI upperbound;
NI level;
};
struct  Tinstantiation215812  {
Tsym215822* sym;
Ttypeseq215824* concretetypes;
TY215913* usedby;
NI compilesid;
};
struct  Freecell29630  {
Freecell29630* next;
NI zerofield;
};
struct Tnodeseq215784 {
  TGenericSeq Sup;
  Tnode215790* data[SEQ_DECL_SIZE];
};
struct Ttypeseq215824 {
  TGenericSeq Sup;
  Ttype215828* data[SEQ_DECL_SIZE];
};
struct TY215925 {
  TGenericSeq Sup;
  Tinstantiation215812* data[SEQ_DECL_SIZE];
};
struct Tsymseq215792 {
  TGenericSeq Sup;
  Tsym215822* data[SEQ_DECL_SIZE];
};
struct Tidpairseq215838 {
  TGenericSeq Sup;
  Tidpair215836 data[SEQ_DECL_SIZE];
};
struct TY215913 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, globalerror_188071)(Tlineinfo183337 info, NU16 msg, NimStringDesc* arg);
N_NIMCALL(Tnode215790*, evaltemplateargs_401216)(Tnode215790* n, Tsym215822* s);
static N_INLINE(NI, len_216059)(Tnode215790* n);
static N_INLINE(Tnode215790*, HEX5BHEX5D_216238)(Tnode215790* n, NI i);
N_NIMCALL(NI, len_218339)(Ttype215828* n);
N_NIMCALL(Tnode215790*, newnodei_217248)(NU8 kind, Tlineinfo183337 info);
N_NIMCALL(void, addson_217807)(Tnode215790* father, Tnode215790* son);
N_NIMCALL(void, localerror_188080)(Tlineinfo183337 info, NU16 msg, NimStringDesc* arg);
N_NIMCALL(Tnode215790*, copytree_219822)(Tnode215790* src);
N_NIMCALL(void, initidtable_219033)(Tidtable215840* x);
N_NIMCALL(Tnode215790*, getbody_255827)(Tsym215822* s);
static N_INLINE(NIM_BOOL, isatom_220492)(Tnode215790* n);
N_NIMCALL(void, evaltemplateaux_401015)(Tnode215790* templ, Tnode215790* actual, Templctx401004* c, Tnode215790* result);
N_NIMCALL(void, add_216114)(Tnode215790* father, Tnode215790* son);
N_NIMCALL(void, internalerror_188113)(NimStringDesc* errmsg);
N_NIMCALL(NimStringDesc*, HEX24_188183)(TY88687 x);
N_NIMCALL(TNimObject*, idtableget_222107)(Tidtable215840 t, Tidobj190006* key);
N_NIMCALL(Tsym215822*, copysym_218601)(Tsym215822* s, NIM_BOOL keepid);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(Cell47504*, usrtocell_51440)(void* usr);
static N_INLINE(void, rtladdzct_53001)(Cell47504* c);
N_NOINLINE(void, addzct_51417)(Cellseq47520* s, Cell47504* c);
N_NIMCALL(void, idtableput_222115)(Tidtable215840* t, Tidobj190006* key, TNimObject* val);
N_NIMCALL(Tnode215790*, newsymnode_217241)(Tsym215822* sym, Tlineinfo183337 info);
N_NIMCALL(Tnode215790*, copynode_401009)(Templctx401004* ctx, Tnode215790* a, Tnode215790* b);
N_NIMCALL(Tnode215790*, copynode_219542)(Tnode215790* src);
N_NIMCALL(NI, sonslen_218351)(Tnode215790* n);
N_NIMCALL(NimStringDesc*, rendertree_234044)(Tnode215790* n, NU8 renderflags);
static N_INLINE(NI, safelen_216081)(Tnode215790* n);
STRING_LITERAL(TMP2977, "", 0);
STRING_LITERAL(TMP2979, "compiler/evaltempl.nim", 22);
NIM_CONST TY88687 TMP2978 = {((NimStringDesc*) &TMP2979),
((NI) 45)}
;
NI evaltemplatecounter_401328;
extern Tnode215790* emptynode_216801;
extern Gcheap49818 gch_49859;

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

N_NIMCALL(Tnode215790*, evaltemplateargs_401216)(Tnode215790* n, Tsym215822* s) {
	Tnode215790* 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_216059(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: ;
	{
		Tnode215790* LOC9;
		LOC9 = 0;
		LOC9 = HEX5BHEX5D_216238((*s).ast, ((NI) 2));
		genericparams = len_216059(LOC9);
	}
	LA4: ;
	LOC10 = 0;
	LOC10 = len_218339((*s).typ);
	expectedregularparams = (LOC10 - 1);
	givenregularparams = (NI)(totalparams - genericparams);
	{
		if (!((NI)(expectedregularparams + genericparams) < totalparams)) goto LA13;
		globalerror_188071((*n).info, ((NU16) 137), ((NimStringDesc*) &TMP2977));
	}
	LA13: ;
	result = newnodei_217248(((NU8) 152), (*n).info);
	{
		NI i_401257;
		NI res_401309;
		i_401257 = 0;
		res_401309 = ((NI) 1);
		{
			while (1) {
				if (!(res_401309 <= givenregularparams)) goto LA17;
				i_401257 = res_401309;
				addson_217807(result, (*n).kindU.S6.sons->data[i_401257]);
				res_401309 += ((NI) 1);
			} LA17: ;
		}
	}
	{
		NI i_401269;
		NI HEX3Atmp_401314;
		NI res_401317;
		i_401269 = 0;
		HEX3Atmp_401314 = 0;
		HEX3Atmp_401314 = (NI)(givenregularparams + ((NI) 1));
		res_401317 = HEX3Atmp_401314;
		{
			while (1) {
				Tnode215790* default_401274;
				if (!(res_401317 <= expectedregularparams)) goto LA20;
				i_401269 = res_401317;
				default_401274 = (*(*(*(*(*s).typ).n).kindU.S6.sons->data[i_401269]).kindU.S4.sym).ast;
				{
					NIM_BOOL LOC23;
					LOC23 = 0;
					LOC23 = default_401274 == 0;
					if (LOC23) goto LA24;
					LOC23 = ((*default_401274).kind == ((NU8) 1));
					LA24: ;
					if (!LOC23) goto LA25;
					localerror_188080((*n).info, ((NU16) 137), ((NimStringDesc*) &TMP2977));
					addson_217807(result, emptynode_216801);
				}
				goto LA21;
				LA25: ;
				{
					Tnode215790* LOC28;
					LOC28 = 0;
					LOC28 = copytree_219822(default_401274);
					addson_217807(result, LOC28);
				}
				LA21: ;
				res_401317 += ((NI) 1);
			} LA20: ;
		}
	}
	{
		NI i_401303;
		NI res_401324;
		i_401303 = 0;
		res_401324 = ((NI) 1);
		{
			while (1) {
				if (!(res_401324 <= genericparams)) goto LA31;
				i_401303 = res_401324;
				addson_217807(result, (*n).kindU.S6.sons->data[(NI)(givenregularparams + i_401303)]);
				res_401324 += ((NI) 1);
			} LA31: ;
		}
	}
	return result;
}

static N_INLINE(NIM_BOOL, isatom_220492)(Tnode215790* 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(Cell47504*, usrtocell_51440)(void* usr) {
	Cell47504* result;
	result = 0;
	result = ((Cell47504*) ((NI)((NU64)(((NI) (usr))) - (NU64)(((NI)sizeof(Cell47504))))));
	return result;
}

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

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

N_NIMCALL(Tnode215790*, copynode_401009)(Templctx401004* ctx, Tnode215790* a, Tnode215790* b) {
	Tnode215790* result;
	result = 0;
	result = copynode_219542(a);
	{
		if (!(*ctx).instlines) goto LA3;
		(*result).info = (*b).info;
	}
	LA3: ;
	return result;
}

N_NIMCALL(void, evaltemplateaux_401015)(Tnode215790* templ, Tnode215790* actual, Templctx401004* c, Tnode215790* result) {
	switch ((*templ).kind) {
	case ((NU8) 3):
	{
		Tsym215822* s;
		s = (*templ).kindU.S4.sym;
		{
			if (!((*(*s).owner).Sup.id == (*(*c).owner).Sup.id)) goto LA4;
			{
				NIM_BOOL LOC8;
				Tnode215790* x_401059;
				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_401059 = (*actual).kindU.S6.sons->data[(*s).position];
				{
					if (!((*x_401059).kind == ((NU8) 152))) goto LA14;
					{
						Tnode215790* y_401061;
						y_401061 = 0;
						{
							NI i_401190;
							NI HEX3Atmp_401192;
							NI LOC18;
							NI res_401194;
							i_401190 = 0;
							HEX3Atmp_401192 = 0;
							LOC18 = 0;
							LOC18 = len_216059(x_401059);
							HEX3Atmp_401192 = (LOC18 - 1);
							res_401194 = ((NI) 0);
							{
								while (1) {
									if (!(res_401194 <= HEX3Atmp_401192)) goto LA20;
									i_401190 = res_401194;
									y_401061 = (*x_401059).kindU.S6.sons->data[i_401190];
									add_216114(result, y_401061);
									res_401194 += ((NI) 1);
								} LA20: ;
							}
						}
					}
				}
				goto LA12;
				LA14: ;
				{
					Tnode215790* LOC22;
					LOC22 = 0;
					LOC22 = copytree_219822(x_401059);
					add_216114(result, LOC22);
				}
				LA12: ;
			}
			goto LA6;
			LA10: ;
			{
				NIM_BOOL LOC24;
				NIM_BOOL LOC26;
				NIM_BOOL LOC27;
				Tnode215790* x_401117;
				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_218339((*(*s).owner).typ);
				x_401117 = (*actual).kindU.S6.sons->data[(NI)((NI)(LOC32 + (*s).position) - ((NI) 1))];
				{
					if (!((*x_401117).kind == ((NU8) 152))) goto LA35;
					{
						Tnode215790* y_401119;
						y_401119 = 0;
						{
							NI i_401201;
							NI HEX3Atmp_401203;
							NI LOC39;
							NI res_401205;
							i_401201 = 0;
							HEX3Atmp_401203 = 0;
							LOC39 = 0;
							LOC39 = len_216059(x_401117);
							HEX3Atmp_401203 = (LOC39 - 1);
							res_401205 = ((NI) 0);
							{
								while (1) {
									if (!(res_401205 <= HEX3Atmp_401203)) goto LA41;
									i_401201 = res_401205;
									y_401119 = (*x_401117).kindU.S6.sons->data[i_401201];
									add_216114(result, y_401119);
									res_401205 += ((NI) 1);
								} LA41: ;
							}
						}
					}
				}
				goto LA33;
				LA35: ;
				{
					Tnode215790* LOC43;
					LOC43 = 0;
					LOC43 = copytree_219822(x_401117);
					add_216114(result, LOC43);
				}
				LA33: ;
			}
			goto LA6;
			LA30: ;
			{
				Tsym215822* x;
				Tidobj190006* LOC50;
				TNimObject* LOC51;
				Tlineinfo183337 LOC58;
				Tnode215790* LOC64;
				{
					NimStringDesc* LOC49;
					if (!!((((*s).flags &(1U<<((NU)(((NU8) 31))&31U)))!=0))) goto LA47;
					LOC49 = 0;
					LOC49 = HEX24_188183(TMP2978);
					internalerror_188113(LOC49);
				}
				LA47: ;
				LOC50 = 0;
				LOC50 = &s->Sup;
				LOC51 = 0;
				LOC51 = idtableget_222107((*c).mapping, LOC50);
				x = ((Tsym215822*) (LOC51));
				{
					Tidobj190006* LOC56;
					TNimObject* LOC57;
					if (!(x == NIM_NIL)) goto LA54;
					x = copysym_218601(s, NIM_FALSE);
					asgnRefNoCycle((void**) (&(*x).owner), (*c).gensymowner);
					LOC56 = 0;
					LOC56 = &s->Sup;
					LOC57 = 0;
					LOC57 = &x->Sup.Sup;
					idtableput_222115((&(*c).mapping), LOC56, LOC57);
				}
				LA54: ;
				{
					if (!(*c).instlines) goto LA61;
					LOC58 = (*actual).info;
				}
				goto LA59;
				LA61: ;
				{
					LOC58 = (*templ).info;
				}
				LA59: ;
				LOC64 = 0;
				LOC64 = newsymnode_217241(x, LOC58);
				add_216114(result, LOC64);
			}
			LA6: ;
		}
		goto LA2;
		LA4: ;
		{
			Tnode215790* LOC66;
			LOC66 = 0;
			LOC66 = copynode_401009((&(*c)), templ, actual);
			add_216114(result, LOC66);
		}
		LA2: ;
	}
	break;
	case ((NU8) 0) ... ((NU8) 2):
	case ((NU8) 4) ... ((NU8) 23):
	{
		Tnode215790* LOC68;
		LOC68 = 0;
		LOC68 = copynode_401009((&(*c)), templ, actual);
		add_216114(result, LOC68);
	}
	break;
	default:
	{
		Tnode215790* res;
		res = copynode_401009((&(*c)), templ, actual);
		{
			NI i_401183;
			NI HEX3Atmp_401209;
			NI LOC71;
			NI res_401212;
			i_401183 = 0;
			HEX3Atmp_401209 = 0;
			LOC71 = 0;
			LOC71 = sonslen_218351(templ);
			HEX3Atmp_401209 = (NI)(LOC71 - ((NI) 1));
			res_401212 = ((NI) 0);
			{
				while (1) {
					if (!(res_401212 <= HEX3Atmp_401209)) goto LA73;
					i_401183 = res_401212;
					evaltemplateaux_401015((*templ).kindU.S6.sons->data[i_401183], actual, c, res);
					res_401212 += ((NI) 1);
				} LA73: ;
			}
		}
		add_216114(result, res);
	}
	break;
	}
}

static N_INLINE(NI, safelen_216081)(Tnode215790* 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(Tnode215790*, evaltemplate_401329)(Tnode215790* n, Tsym215822* tmpl, Tsym215822* gensymowner) {
	Tnode215790* result;
	Tnode215790* args;
	Templctx401004 ctx;
	Tnode215790* body;
	result = 0;
	evaltemplatecounter_401328 += ((NI) 1);
	{
		if (!(((NI) 100) < evaltemplatecounter_401328)) goto LA3;
		globalerror_188071((*n).info, ((NU16) 188), ((NimStringDesc*) &TMP2977));
		result = n;
	}
	LA3: ;
	args = evaltemplateargs_401216(n, tmpl);
	memset((void*)(&ctx), 0, sizeof(ctx));
	ctx.owner = tmpl;
	ctx.gensymowner = gensymowner;
	initidtable_219033((&ctx.mapping));
	body = getbody_255827(tmpl);
	{
		NIM_BOOL LOC7;
		LOC7 = 0;
		LOC7 = isatom_220492(body);
		if (!LOC7) goto LA8;
		result = newnodei_217248(((NU8) 37), (*body).info);
		evaltemplateaux_401015(body, args, (&ctx), result);
		{
			NI LOC12;
			LOC12 = 0;
			LOC12 = len_216059(result);
			if (!(LOC12 == ((NI) 1))) goto LA13;
			result = (*result).kindU.S6.sons->data[((NI) 0)];
		}
		goto LA10;
		LA13: ;
		{
			NimStringDesc* LOC16;
			LOC16 = 0;
			LOC16 = rendertree_234044(result, 4);
			localerror_188080((*result).info, ((NU16) 1), LOC16);
		}
		LA10: ;
	}
	goto LA5;
	LA8: ;
	{
		result = copynode_219542(body);
		{
			NI i_401365;
			NI HEX3Atmp_401379;
			NI LOC19;
			NI res_401382;
			i_401365 = 0;
			HEX3Atmp_401379 = 0;
			LOC19 = 0;
			LOC19 = safelen_216081(body);
			HEX3Atmp_401379 = (NI)(LOC19 - ((NI) 1));
			res_401382 = ((NI) 0);
			{
				while (1) {
					if (!(res_401382 <= HEX3Atmp_401379)) goto LA21;
					i_401365 = res_401382;
					evaltemplateaux_401015((*body).kindU.S6.sons->data[i_401365], args, (&ctx), result);
					res_401382 += ((NI) 1);
				} LA21: ;
			}
		}
	}
	LA5: ;
	evaltemplatecounter_401328 -= ((NI) 1);
	return result;
}
NIM_EXTERNC N_NOINLINE(void, compiler_evaltemplInit000)(void) {
	evaltemplatecounter_401328 = ((NI) 0);
}

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

