/* 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/semmacrosanity.o compiler/nimcache/semmacrosanity.c */
#define NIM_INTBITS 32
#include "nimbase.h"

#include <string.h>
typedef struct tnode188803 tnode188803;
typedef struct ttype188837 ttype188837;
typedef struct tlineinfo163527 tlineinfo163527;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct tsym188833 tsym188833;
typedef struct tident167019 tident167019;
typedef struct tnodeseq188797 tnodeseq188797;
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 tcell41090 tcell41090;
typedef struct tcellseq41106 tcellseq41106;
typedef struct tgcheap43016 tgcheap43016;
typedef struct tcellset41102 tcellset41102;
typedef struct tpagedesc41098 tpagedesc41098;
typedef struct tmemregion23410 tmemregion23410;
typedef struct tsmallchunk22638 tsmallchunk22638;
typedef struct tllchunk23404 tllchunk23404;
typedef struct tbigchunk22640 tbigchunk22640;
typedef struct tintset22615 tintset22615;
typedef struct ttrunk22611 ttrunk22611;
typedef struct tavlnode23408 tavlnode23408;
typedef struct tgcstat43014 tgcstat43014;
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 tbasechunk22636 tbasechunk22636;
typedef struct tfreecell22628 tfreecell22628;
typedef struct TY188922 TY188922;
typedef struct tlistentry118017 tlistentry118017;
struct  tlineinfo163527  {
NI16 Line;
NI16 Col;
NI32 Fileindex;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
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  tcell41090  {
NI Refcount;
TNimType* Typ;
};
struct  tcellseq41106  {
NI Len;
NI Cap;
tcell41090** D;
};
struct  tcellset41102  {
NI Counter;
NI Max;
tpagedesc41098* Head;
tpagedesc41098** Data;
};
typedef tsmallchunk22638* TY23422[512];
typedef ttrunk22611* ttrunkbuckets22613[256];
struct  tintset22615  {
ttrunkbuckets22613 Data;
};
struct  tmemregion23410  {
NI Minlargeobj;
NI Maxlargeobj;
TY23422 Freesmallchunks;
tllchunk23404* Llmem;
NI Currmem;
NI Maxmem;
NI Freemem;
NI Lastsize;
tbigchunk22640* Freechunkslist;
tintset22615 Chunkstarts;
tavlnode23408* Root;
tavlnode23408* Deleted;
tavlnode23408* Last;
tavlnode23408* Freeavlnodes;
};
struct  tgcstat43014  {
NI Stackscans;
NI Cyclecollections;
NI Maxthreshold;
NI Maxstacksize;
NI Maxstackcells;
NI Cycletablesize;
NI64 Maxpause;
};
struct  tgcheap43016  {
void* Stackbottom;
NI Cyclethreshold;
tcellseq41106 Zct;
tcellseq41106 Decstack;
tcellset41102 Cycleroots;
tcellseq41106 Tempstack;
NI Recgclock;
tmemregion23410 Region;
tgcstat43014 Stat;
};
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  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;
};
typedef NI TY22618[16];
struct  tpagedesc41098  {
tpagedesc41098* Next;
NI Key;
TY22618 Bits;
};
struct  tbasechunk22636  {
NI Prevsize;
NI Size;
NIM_BOOL Used;
};
struct  tsmallchunk22638  {
  tbasechunk22636 Sup;
tsmallchunk22638* Next;
tsmallchunk22638* Prev;
tfreecell22628* Freelist;
NI Free;
NI Acc;
NF Data;
};
struct  tllchunk23404  {
NI Size;
NI Acc;
tllchunk23404* Next;
};
struct  tbigchunk22640  {
  tbasechunk22636 Sup;
tbigchunk22640* Next;
tbigchunk22640* Prev;
NI Align;
NF Data;
};
struct  ttrunk22611  {
ttrunk22611* Next;
NI Key;
TY22618 Bits;
};
typedef tavlnode23408* TY23414[2];
struct  tavlnode23408  {
TY23414 Link;
NI Key;
NI Upperbound;
NI Level;
};
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  tfreecell22628  {
tfreecell22628* Next;
NI Zerofield;
};
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(ttype188837*, skiptypes_192793)(ttype188837* t, NU64 kinds);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(tcell41090*, usrtocell_44443)(void* usr);
static N_INLINE(void, rtladdzct_46002)(tcell41090* c);
N_NOINLINE(void, addzct_44418)(tcellseq41106* s, tcell41090* c);
static N_INLINE(NI, len_189264)(tnode188803* n);
N_NIMCALL(tsym188833*, ithfield_415007)(tnode188803* n, NI field);
static N_INLINE(NI, sonslen_189181)(tnode188803* n);
N_NIMCALL(void, internalerror_165591)(tlineinfo163527 info, NimStringDesc* errmsg);
static N_INLINE(tnode188803*, lastson_189189)(tnode188803* n);
N_NIMCALL(void, globalerror_165565)(tlineinfo163527 info, NimStringDesc* arg);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
N_NIMCALL(NimStringDesc*, nimIntToStr)(NI x);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(void, annotatetype_415194)(tnode188803* n, ttype188837* t);
N_NIMCALL(NI, len_192569)(ttype188837* n);
N_NIMCALL(ttype188837*, elemtype_223559)(ttype188837* t);
STRING_LITERAL(TMP2958, "ithField", 8);
STRING_LITERAL(TMP2959, "ithField(record case branch)", 28);
STRING_LITERAL(TMP2960, "invalid field at index ", 23);
STRING_LITERAL(TMP2961, "() must have an object or tuple type", 36);
STRING_LITERAL(TMP2962, "[] must have some form of array type", 36);
STRING_LITERAL(TMP2963, "{} must have the set type", 25);
STRING_LITERAL(TMP2964, "float literal must have some float type", 39);
STRING_LITERAL(TMP2965, "integer literal must have some int type", 39);
STRING_LITERAL(TMP2966, "string literal must be of some string type", 42);
STRING_LITERAL(TMP2967, "nil literal must be of some pointer type", 40);
extern tgcheap43016 gch_43044;

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

static N_INLINE(void, rtladdzct_46002)(tcell41090* c) {
	addzct_44418(&gch_43044.Zct, c);
}

static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src) {
	{
		tcell41090* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_44443(src);
		(*c).Refcount += 8;
	}
	LA3: ;
	{
		tcell41090* c;
		if (!!(((*dest) == NIM_NIL))) goto LA7;
		c = usrtocell_44443((*dest));
		{
			(*c).Refcount -= 8;
			if (!((NU32)((*c).Refcount) < (NU32)(8))) goto LA11;
			rtladdzct_46002(c);
		}
		LA11: ;
	}
	LA7: ;
	(*dest) = src;
}

static N_INLINE(NI, len_189264)(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;
}

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;
}

static N_INLINE(tnode188803*, lastson_189189)(tnode188803* n) {
	tnode188803* result;
	NI LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = sonslen_189181(n);
	result = (*n).kindU.S6.Sons->data[(NI32)(LOC1 - 1)];
	return result;
}

N_NIMCALL(tsym188833*, ithfield_415007)(tnode188803* n, NI field) {
	tsym188833* result;
	result = 0;
	result = NIM_NIL;
	switch ((*n).Kind) {
	case ((NU8) 136):
	{
		NI i_415024;
		NI HEX3Atmp_415182;
		NI LOC2;
		NI res_415184;
		i_415024 = 0;
		HEX3Atmp_415182 = 0;
		LOC2 = 0;
		LOC2 = sonslen_189181(n);
		HEX3Atmp_415182 = (NI32)(LOC2 - 1);
		res_415184 = 0;
		while (1) {
			if (!(res_415184 <= HEX3Atmp_415182)) goto LA3;
			i_415024 = res_415184;
			result = ithfield_415007((*n).kindU.S6.Sons->data[i_415024], (NI32)(field - i_415024));
			{
				if (!!((result == NIM_NIL))) goto LA6;
				goto BeforeRet;
			}
			LA6: ;
			res_415184 += 1;
		} LA3: ;
	}
	break;
	case ((NU8) 137):
	{
		NI i_415122;
		NI HEX3Atmp_415186;
		NI LOC17;
		NI res_415188;
		{
			if (!!(((*(*n).kindU.S6.Sons->data[0]).Kind == ((NU8) 3)))) goto LA11;
			internalerror_165591((*n).Info, ((NimStringDesc*) &TMP2958));
		}
		LA11: ;
		result = ithfield_415007((*n).kindU.S6.Sons->data[0], (NI32)(field - 1));
		{
			if (!!((result == NIM_NIL))) goto LA15;
			goto BeforeRet;
		}
		LA15: ;
		i_415122 = 0;
		HEX3Atmp_415186 = 0;
		LOC17 = 0;
		LOC17 = sonslen_189181(n);
		HEX3Atmp_415186 = (NI32)(LOC17 - 1);
		res_415188 = 1;
		while (1) {
			if (!(res_415188 <= HEX3Atmp_415186)) goto LA18;
			i_415122 = res_415188;
			switch ((*(*n).kindU.S6.Sons->data[i_415122]).Kind) {
			case ((NU8) 85):
			case ((NU8) 88):
			{
				tnode188803* LOC20;
				LOC20 = 0;
				LOC20 = lastson_189189((*n).kindU.S6.Sons->data[i_415122]);
				result = ithfield_415007(LOC20, (NI32)(field - 1));
				{
					if (!!((result == NIM_NIL))) goto LA23;
					goto BeforeRet;
				}
				LA23: ;
			}
			break;
			default:
			{
				internalerror_165591((*n).Info, ((NimStringDesc*) &TMP2959));
			}
			break;
			}
			res_415188 += 1;
		} LA18: ;
	}
	break;
	case ((NU8) 3):
	{
		{
			if (!(field == 0)) goto LA29;
			result = (*n).kindU.S4.Sym;
		}
		LA29: ;
	}
	break;
	default:
	{
	}
	break;
	}
	BeforeRet: ;
	return result;
}

static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src) {
	memcpy(((NCSTRING) (&(*dest).data[((*dest).Sup.len)- 0])), ((NCSTRING) ((*src).data)), (NI32)((*src).Sup.len + 1));
	(*dest).Sup.len += (*src).Sup.len;
}

N_NIMCALL(void, annotatetype_415194)(tnode188803* n, ttype188837* t) {
	ttype188837* x;
	x = skiptypes_192793(t, IL64(211106232576256));
	switch ((*n).Kind) {
	case ((NU8) 37):
	{
		{
			NI i_415229;
			NI HEX3Atmp_415404;
			NI LOC6;
			NI res_415406;
			if (!((*x).Kind == ((NU8) 17))) goto LA4;
			asgnRefNoCycle((void**) &(*n).Typ, t);
			i_415229 = 0;
			HEX3Atmp_415404 = 0;
			LOC6 = 0;
			LOC6 = len_189264(n);
			HEX3Atmp_415404 = LOC6 - 1;
			res_415406 = 0;
			while (1) {
				tsym188833* field;
				if (!(res_415406 <= HEX3Atmp_415404)) goto LA7;
				i_415229 = res_415406;
				field = ithfield_415007((*x).N, i_415229);
				{
					NimStringDesc* LOC12;
					NimStringDesc* LOC13;
					if (!field == 0) goto LA10;
					LOC12 = 0;
					LOC13 = 0;
					LOC13 = nimIntToStr(i_415229);
					LOC12 = rawNewString(LOC13->Sup.len + 23);
appendString(LOC12, ((NimStringDesc*) &TMP2960));
appendString(LOC12, LOC13);
					globalerror_165565((*n).Info, LOC12);
				}
				goto LA8;
				LA10: ;
				{
					annotatetype_415194((*n).kindU.S6.Sons->data[i_415229], (*field).Typ);
				}
				LA8: ;
				res_415406 += 1;
			} LA7: ;
		}
		goto LA2;
		LA4: ;
		{
			NI i_415286;
			NI HEX3Atmp_415408;
			NI LOC18;
			NI res_415410;
			if (!((*x).Kind == ((NU8) 18))) goto LA16;
			asgnRefNoCycle((void**) &(*n).Typ, t);
			i_415286 = 0;
			HEX3Atmp_415408 = 0;
			LOC18 = 0;
			LOC18 = len_189264(n);
			HEX3Atmp_415408 = LOC18 - 1;
			res_415410 = 0;
			while (1) {
				if (!(res_415410 <= HEX3Atmp_415408)) goto LA19;
				i_415286 = res_415410;
				{
					NI LOC22;
					NimStringDesc* LOC25;
					NimStringDesc* LOC26;
					LOC22 = 0;
					LOC22 = len_192569(x);
					if (!(LOC22 <= i_415286)) goto LA23;
					LOC25 = 0;
					LOC26 = 0;
					LOC26 = nimIntToStr(i_415286);
					LOC25 = rawNewString(LOC26->Sup.len + 23);
appendString(LOC25, ((NimStringDesc*) &TMP2960));
appendString(LOC25, LOC26);
					globalerror_165565((*n).Info, LOC25);
				}
				goto LA20;
				LA23: ;
				{
					annotatetype_415194((*n).kindU.S6.Sons->data[i_415286], (*x).Sons->data[i_415286]);
				}
				LA20: ;
				res_415410 += 1;
			} LA19: ;
		}
		goto LA2;
		LA16: ;
		{
			NIM_BOOL LOC29;
			LOC29 = 0;
			LOC29 = ((*x).Kind == ((NU8) 25));
			if (!(LOC29)) goto LA30;
			LOC29 = ((*x).Callconv == ((NU8) 8));
			LA30: ;
			if (!LOC29) goto LA31;
			asgnRefNoCycle((void**) &(*n).Typ, t);
		}
		goto LA2;
		LA31: ;
		{
			globalerror_165565((*n).Info, ((NimStringDesc*) &TMP2961));
		}
		LA2: ;
	}
	break;
	case ((NU8) 41):
	{
		{
			tnode188803* m_415333;
			NI i_415413;
			NI HEX3Atmp_415415;
			NI LOC39;
			NI res_415417;
			if (!((*x).Kind == ((NU8) 4) || (*x).Kind == ((NU8) 16) || (*x).Kind == ((NU8) 24) || (*x).Kind == ((NU8) 27))) goto LA37;
			asgnRefNoCycle((void**) &(*n).Typ, t);
			m_415333 = 0;
			i_415413 = 0;
			HEX3Atmp_415415 = 0;
			LOC39 = 0;
			LOC39 = len_189264(n);
			HEX3Atmp_415415 = LOC39 - 1;
			res_415417 = 0;
			while (1) {
				ttype188837* LOC41;
				if (!(res_415417 <= HEX3Atmp_415415)) goto LA40;
				i_415413 = res_415417;
				m_415333 = (*n).kindU.S6.Sons->data[i_415413];
				LOC41 = 0;
				LOC41 = elemtype_223559(x);
				annotatetype_415194(m_415333, LOC41);
				res_415417 += 1;
			} LA40: ;
		}
		goto LA35;
		LA37: ;
		{
			globalerror_165565((*n).Info, ((NimStringDesc*) &TMP2962));
		}
		LA35: ;
	}
	break;
	case ((NU8) 39):
	{
		{
			tnode188803* m_415348;
			NI i_415419;
			NI HEX3Atmp_415421;
			NI LOC48;
			NI res_415423;
			if (!((*x).Kind == ((NU8) 19))) goto LA46;
			asgnRefNoCycle((void**) &(*n).Typ, t);
			m_415348 = 0;
			i_415419 = 0;
			HEX3Atmp_415421 = 0;
			LOC48 = 0;
			LOC48 = len_189264(n);
			HEX3Atmp_415421 = LOC48 - 1;
			res_415423 = 0;
			while (1) {
				ttype188837* LOC50;
				if (!(res_415423 <= HEX3Atmp_415421)) goto LA49;
				i_415419 = res_415423;
				m_415348 = (*n).kindU.S6.Sons->data[i_415419];
				LOC50 = 0;
				LOC50 = elemtype_223559(x);
				annotatetype_415194(m_415348, LOC50);
				res_415423 += 1;
			} LA49: ;
		}
		goto LA44;
		LA46: ;
		{
			globalerror_165565((*n).Info, ((NimStringDesc*) &TMP2963));
		}
		LA44: ;
	}
	break;
	case ((NU8) 16) ... ((NU8) 19):
	{
		{
			if (!((*x).Kind >= ((NU8) 36) && (*x).Kind <= ((NU8) 39))) goto LA55;
			asgnRefNoCycle((void**) &(*n).Typ, t);
		}
		goto LA53;
		LA55: ;
		{
			globalerror_165565((*n).Info, ((NimStringDesc*) &TMP2964));
		}
		LA53: ;
	}
	break;
	case ((NU8) 5) ... ((NU8) 15):
	{
		{
			if (!((*x).Kind >= ((NU8) 31) && (*x).Kind <= ((NU8) 44) || (*x).Kind == ((NU8) 1) || (*x).Kind == ((NU8) 2) || (*x).Kind == ((NU8) 14))) goto LA61;
			asgnRefNoCycle((void**) &(*n).Typ, t);
		}
		goto LA59;
		LA61: ;
		{
			globalerror_165565((*n).Info, ((NimStringDesc*) &TMP2965));
		}
		LA59: ;
	}
	break;
	case ((NU8) 20) ... ((NU8) 22):
	{
		{
			if (!((*x).Kind == ((NU8) 28) || (*x).Kind == ((NU8) 29))) goto LA67;
			asgnRefNoCycle((void**) &(*n).Typ, t);
		}
		goto LA65;
		LA67: ;
		{
			globalerror_165565((*n).Info, ((NimStringDesc*) &TMP2966));
		}
		LA65: ;
	}
	break;
	case ((NU8) 23):
	{
		{
			if (!((*x).Kind == ((NU8) 26) || (*x).Kind == ((NU8) 29) || (*x).Kind == ((NU8) 22) || (*x).Kind == ((NU8) 21) || (*x).Kind == ((NU8) 24) || (*x).Kind == ((NU8) 25) || (*x).Kind == ((NU8) 28) || (*x).Kind == ((NU8) 50))) goto LA73;
			asgnRefNoCycle((void**) &(*n).Typ, t);
		}
		goto LA71;
		LA73: ;
		{
			globalerror_165565((*n).Info, ((NimStringDesc*) &TMP2967));
		}
		LA71: ;
	}
	break;
	default:
	{
	}
	break;
	}
}
N_NOINLINE(void, semmacrosanityInit)(void) {
}

N_NOINLINE(void, semmacrosanityDatInit)(void) {
}

