/* Generated by Nim Compiler v0.10.2 */
/*   (c) 2014 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 32
#include "nimbase.h"
typedef struct tsym226846 tsym226846;
typedef struct tsymseq226818 tsymseq226818;
typedef struct TGenericSeq TGenericSeq;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct NimStringDesc NimStringDesc;
typedef struct TY119808 TY119808;
typedef struct tindexentry360264 tindexentry360264;
typedef struct TY362804 TY362804;
typedef struct tentry419478 tentry419478;
typedef struct TY419485 TY419485;
typedef struct tidobj201015 tidobj201015;
typedef struct TNimObject TNimObject;
typedef struct ttypeseq226848 ttypeseq226848;
typedef struct ttype226852 ttype226852;
typedef struct tscope226840 tscope226840;
typedef struct TY226947 TY226947;
typedef struct tinstantiation226836 tinstantiation226836;
typedef struct tstrtable226820 tstrtable226820;
typedef struct tident201021 tident201021;
typedef struct tlineinfo196539 tlineinfo196539;
typedef struct tnode226816 tnode226816;
typedef struct tloc226830 tloc226830;
typedef struct trope178009 trope178009;
typedef struct tlib226834 tlib226834;
typedef struct tnodeseq226810 tnodeseq226810;
typedef struct TY226936 TY226936;
typedef struct tlistentry127022 tlistentry127022;
typedef struct {
N_NIMCALL_PTR(NI, ClPrc) (tsym226846* x_416632, tsym226846* y_416634, void* ClEnv);
void* ClEnv;
} TY416638;
struct  TGenericSeq  {
NI len;
NI reserved;
};
typedef N_NIMCALL_PTR(void, TY3089) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3094) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3089 marker;
TY3094 deepcopy;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
typedef N_CLOSURE_PTR(NI, TMP2635) (tsym226846* x_416707, tsym226846* y_416709);
typedef N_CLOSURE_PTR(NI, TMP2636) (tsym226846* x_416707, tsym226846* y_416709);
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef struct {
N_NIMCALL_PTR(NI, ClPrc) (NimStringDesc* x_363565, NimStringDesc* y_363567, void* ClEnv);
void* ClEnv;
} TY363571;
typedef N_CLOSURE_PTR(NI, TMP4794) (NimStringDesc* x_363640, NimStringDesc* y_363642);
typedef N_CLOSURE_PTR(NI, TMP4795) (NimStringDesc* x_363640, NimStringDesc* y_363642);
struct  tindexentry360264  {
NimStringDesc* Keyword;
NimStringDesc* Link;
NimStringDesc* Linktitle;
NimStringDesc* Linkdesc;
};
typedef struct {
N_NIMCALL_PTR(NI, ClPrc) (tindexentry360264 x_361566, tindexentry360264 y_361568, void* ClEnv);
void* ClEnv;
} TY361572;
typedef N_CLOSURE_PTR(NI, TMP4798) (tindexentry360264 x_361641, tindexentry360264 y_361643);
typedef N_CLOSURE_PTR(NI, TMP4799) (tindexentry360264 x_361641, tindexentry360264 y_361643);
struct  tentry419478  {
NI Pos;
tsym226846* Sym;
};
typedef struct {
N_NIMCALL_PTR(NI, ClPrc) (tentry419478 x_420138, tentry419478 y_420140, void* ClEnv);
void* ClEnv;
} TY420144;
typedef N_CLOSURE_PTR(NI, TMP4855) (tentry419478 x_420213, tentry419478 y_420215);
typedef N_CLOSURE_PTR(NI, TMP4856) (tentry419478 x_420213, tentry419478 y_420215);
struct  TNimObject  {
TNimType* m_type;
};
struct  tidobj201015  {
  TNimObject Sup;
NI Id;
};
struct  tstrtable226820  {
NI Counter;
tsymseq226818* Data;
};
struct  tlineinfo196539  {
NI16 Line;
NI16 Col;
NI32 Fileindex;
};
struct  tloc226830  {
NU8 K;
NU8 S;
NU8 Flags;
ttype226852* T;
trope178009* R;
trope178009* Heaproot;
};
struct  tsym226846  {
  tidobj201015 Sup;
NU8 Kind;
union {
struct {ttypeseq226848* Typeinstcache;
tscope226840* Typscope;
} S1;
struct {TY226947* Procinstcache;
tscope226840* Scope;
} S2;
struct {TY226947* Usedgenerics;
tstrtable226820 Tab;
} S3;
struct {tsym226846* Guard;
} S4;
} kindU;
NU16 Magic;
ttype226852* Typ;
tident201021* Name;
tlineinfo196539 Info;
tsym226846* Owner;
NU32 Flags;
tnode226816* Ast;
NU32 Options;
NI Position;
NI Offset;
tloc226830 Loc;
tlib226834* Annex;
tnode226816* Constraint;
};
struct  ttype226852  {
  tidobj201015 Sup;
NU8 Kind;
NU8 Callconv;
NU32 Flags;
ttypeseq226848* Sons;
tnode226816* N;
tsym226846* Owner;
tsym226846* Sym;
tsym226846* Destructor;
tsym226846* Deepcopy;
NI64 Size;
NI16 Align;
NI16 Locklevel;
tloc226830 Loc;
};
struct  tscope226840  {
NI Depthlevel;
tstrtable226820 Symbols;
tnodeseq226810* Usingsyms;
tscope226840* Parent;
};
struct  tinstantiation226836  {
tsym226846* Sym;
ttypeseq226848* Concretetypes;
TY226936* Usedby;
};
struct  tident201021  {
  tidobj201015 Sup;
NimStringDesc* S;
tident201021* Next;
NI H;
};
struct  tnode226816  {
ttype226852* Typ;
tlineinfo196539 Info;
NU16 Flags;
NU8 Kind;
union {
struct {NI64 Intval;
} S1;
struct {NF Floatval;
} S2;
struct {NimStringDesc* Strval;
} S3;
struct {tsym226846* Sym;
} S4;
struct {tident201021* Ident;
} S5;
struct {tnodeseq226810* Sons;
} S6;
} kindU;
NimStringDesc* Comment;
};
struct  trope178009  {
  TNimObject Sup;
trope178009* Left;
trope178009* Right;
NI Length;
NimStringDesc* Data;
};
struct  tlistentry127022  {
  TNimObject Sup;
tlistentry127022* Prev;
tlistentry127022* Next;
};
struct  tlib226834  {
  tlistentry127022 Sup;
NU8 Kind;
NIM_BOOL Generated;
NIM_BOOL Isoverriden;
trope178009* Name;
tnode226816* Path;
};
struct tsymseq226818 {
  TGenericSeq Sup;
  tsym226846* data[SEQ_DECL_SIZE];
};
struct TY119808 {
  TGenericSeq Sup;
  NimStringDesc* data[SEQ_DECL_SIZE];
};
struct TY362804 {
  TGenericSeq Sup;
  tindexentry360264 data[SEQ_DECL_SIZE];
};
struct TY419485 {
  TGenericSeq Sup;
  tentry419478 data[SEQ_DECL_SIZE];
};
struct ttypeseq226848 {
  TGenericSeq Sup;
  ttype226852* data[SEQ_DECL_SIZE];
};
struct TY226947 {
  TGenericSeq Sup;
  tinstantiation226836* data[SEQ_DECL_SIZE];
};
struct tnodeseq226810 {
  TGenericSeq Sup;
  tnode226816* data[SEQ_DECL_SIZE];
};
struct TY226936 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
N_NIMCALL(void*, newSeq)(TNimType* typ, NI len);
N_NIMCALL(void, merge_416680)(tsym226846** a_416688, NI a_416688Len0, tsym226846** b_416696, NI b_416696Len0, NI lo_416700, NI m_416702, NI hi_416704, TY416638 cmp_416712, NU8 order_416715);
static N_INLINE(NI, HEX2A_358020)(NI x, NU8 order);
N_NIMCALL(void, unsureAsgnRef)(void** dest, void* src);
N_NIMCALL(void, merge_363613)(NimStringDesc** a_363621, NI a_363621Len0, NimStringDesc** b_363629, NI b_363629Len0, NI lo_363633, NI m_363635, NI hi_363637, TY363571 cmp_363645, NU8 order_363648);
N_NIMCALL(void, merge_361614)(tindexentry360264* a_361622, NI a_361622Len0, tindexentry360264* b_361630, NI b_361630Len0, NI lo_361634, NI m_361636, NI hi_361638, TY361572 cmp_361646, NU8 order_361649);
N_NIMCALL(void, HEX3CHEX2D_360607)(tindexentry360264* a, tindexentry360264 b);
N_NIMCALL(void, merge_420186)(tentry419478* a_420194, NI a_420194Len0, tentry419478* b_420202, NI b_420202Len0, NI lo_420206, NI m_420208, NI hi_420210, TY420144 cmp_420218, NU8 order_420221);
extern TNimType NTI226818; /* TSymSeq */
extern TNimType NTI108; /* int */
TNimType NTI358033; /* range -1..0(int) */
extern TNimType NTI119808; /* seq[string] */
extern TNimType NTI362804; /* seq[TIndexEntry] */
extern TNimType NTI419485; /* seq[TEntry] */

static N_INLINE(NI, HEX2A_358020)(NI x, NU8 order) {
	NI result;
	NI y;
	result = 0;
	y = (NI32)(((NI) (order)) - 1);
	result = (NI32)((NI)(x ^ ((NI) (y))) - ((NI) (y)));
	return result;
}

N_NIMCALL(void, merge_416680)(tsym226846** a_416688, NI a_416688Len0, tsym226846** b_416696, NI b_416696Len0, NI lo_416700, NI m_416702, NI hi_416704, TY416638 cmp_416712, NU8 order_416715) {
	NI j;
	NI bb;
	NI i;
	NI k;
	{
		NI LOC3;
		NI LOC4;
		LOC3 = 0;
		LOC3 = cmp_416712.ClEnv? cmp_416712.ClPrc(a_416688[m_416702], a_416688[(NI32)(m_416702 + 1)], cmp_416712.ClEnv):((TMP2635)(cmp_416712.ClPrc))(a_416688[m_416702], a_416688[(NI32)(m_416702 + 1)]);
		LOC4 = 0;
		LOC4 = HEX2A_358020(LOC3, order_416715);
		if (!(LOC4 <= 0)) goto LA5;
		goto BeforeRet;
	}
	LA5: ;
	j = lo_416700;
	bb = 0;
	{
		while (1) {
			if (!(j <= m_416702)) goto LA8;
			unsureAsgnRef((void**) (&b_416696[bb]), a_416688[j]);
			bb += 1;
			j += 1;
		} LA8: ;
	}
	i = 0;
	k = lo_416700;
	{
		while (1) {
			NIM_BOOL LOC11;
			LOC11 = 0;
			LOC11 = (k < j);
			if (!(LOC11)) goto LA12;
			LOC11 = (j <= hi_416704);
			LA12: ;
			if (!LOC11) goto LA10;
			{
				NI LOC15;
				NI LOC16;
				LOC15 = 0;
				LOC15 = cmp_416712.ClEnv? cmp_416712.ClPrc(b_416696[i], a_416688[j], cmp_416712.ClEnv):((TMP2636)(cmp_416712.ClPrc))(b_416696[i], a_416688[j]);
				LOC16 = 0;
				LOC16 = HEX2A_358020(LOC15, order_416715);
				if (!(LOC16 <= 0)) goto LA17;
				unsureAsgnRef((void**) (&a_416688[k]), b_416696[i]);
				i += 1;
			}
			goto LA13;
			LA17: ;
			{
				unsureAsgnRef((void**) (&a_416688[k]), a_416688[j]);
				j += 1;
			}
			LA13: ;
			k += 1;
		} LA10: ;
	}
	{
		while (1) {
			if (!(k < j)) goto LA21;
			unsureAsgnRef((void**) (&a_416688[k]), b_416696[i]);
			k += 1;
			i += 1;
		} LA21: ;
	}
	BeforeRet: ;
}

N_NIMCALL(void, sort_416619)(tsym226846** a_416627, NI a_416627Len0, TY416638 cmp_416637, NU8 order_416640) {
	NI n;
	tsymseq226818* b;
	NI s;
	n = a_416627Len0;
	b = 0;
	b = (tsymseq226818*) newSeq((&NTI226818), (NI32)(n / 2));
	s = 1;
	{
		while (1) {
			NI m;
			if (!(s < n)) goto LA2;
			m = (NI32)((NI32)(n - 1) - s);
			{
				while (1) {
					if (!(0 <= m)) goto LA4;
					merge_416680(a_416627, a_416627Len0, b->data, b->Sup.len, (((NI32)((NI32)(m - s) + 1) >= 0) ? (NI32)((NI32)(m - s) + 1) : 0), m, (NI32)(m + s), cmp_416637, order_416640);
					m -= (NI32)(s * 2);
				} LA4: ;
			}
			s = (NI32)(s * 2);
		} LA2: ;
	}
}

N_NIMCALL(void, merge_363613)(NimStringDesc** a_363621, NI a_363621Len0, NimStringDesc** b_363629, NI b_363629Len0, NI lo_363633, NI m_363635, NI hi_363637, TY363571 cmp_363645, NU8 order_363648) {
	NI j;
	NI bb;
	NI i;
	NI k;
	{
		NI LOC3;
		NI LOC4;
		LOC3 = 0;
		LOC3 = cmp_363645.ClEnv? cmp_363645.ClPrc(a_363621[m_363635], a_363621[(NI32)(m_363635 + 1)], cmp_363645.ClEnv):((TMP4794)(cmp_363645.ClPrc))(a_363621[m_363635], a_363621[(NI32)(m_363635 + 1)]);
		LOC4 = 0;
		LOC4 = HEX2A_358020(LOC3, order_363648);
		if (!(LOC4 <= 0)) goto LA5;
		goto BeforeRet;
	}
	LA5: ;
	j = lo_363633;
	bb = 0;
	{
		while (1) {
			if (!(j <= m_363635)) goto LA8;
			unsureAsgnRef((void**) (&b_363629[bb]), a_363621[j]);
			bb += 1;
			j += 1;
		} LA8: ;
	}
	i = 0;
	k = lo_363633;
	{
		while (1) {
			NIM_BOOL LOC11;
			LOC11 = 0;
			LOC11 = (k < j);
			if (!(LOC11)) goto LA12;
			LOC11 = (j <= hi_363637);
			LA12: ;
			if (!LOC11) goto LA10;
			{
				NI LOC15;
				NI LOC16;
				LOC15 = 0;
				LOC15 = cmp_363645.ClEnv? cmp_363645.ClPrc(b_363629[i], a_363621[j], cmp_363645.ClEnv):((TMP4795)(cmp_363645.ClPrc))(b_363629[i], a_363621[j]);
				LOC16 = 0;
				LOC16 = HEX2A_358020(LOC15, order_363648);
				if (!(LOC16 <= 0)) goto LA17;
				unsureAsgnRef((void**) (&a_363621[k]), b_363629[i]);
				i += 1;
			}
			goto LA13;
			LA17: ;
			{
				unsureAsgnRef((void**) (&a_363621[k]), a_363621[j]);
				j += 1;
			}
			LA13: ;
			k += 1;
		} LA10: ;
	}
	{
		while (1) {
			if (!(k < j)) goto LA21;
			unsureAsgnRef((void**) (&a_363621[k]), b_363629[i]);
			k += 1;
			i += 1;
		} LA21: ;
	}
	BeforeRet: ;
}

N_NIMCALL(void, sort_363552)(NimStringDesc** a_363560, NI a_363560Len0, TY363571 cmp_363570, NU8 order_363573) {
	NI n;
	TY119808* b;
	NI s;
	n = a_363560Len0;
	b = 0;
	b = (TY119808*) newSeq((&NTI119808), (NI32)(n / 2));
	s = 1;
	{
		while (1) {
			NI m;
			if (!(s < n)) goto LA2;
			m = (NI32)((NI32)(n - 1) - s);
			{
				while (1) {
					if (!(0 <= m)) goto LA4;
					merge_363613(a_363560, a_363560Len0, b->data, b->Sup.len, (((NI32)((NI32)(m - s) + 1) >= 0) ? (NI32)((NI32)(m - s) + 1) : 0), m, (NI32)(m + s), cmp_363570, order_363573);
					m -= (NI32)(s * 2);
				} LA4: ;
			}
			s = (NI32)(s * 2);
		} LA2: ;
	}
}

N_NIMCALL(void, merge_361614)(tindexentry360264* a_361622, NI a_361622Len0, tindexentry360264* b_361630, NI b_361630Len0, NI lo_361634, NI m_361636, NI hi_361638, TY361572 cmp_361646, NU8 order_361649) {
	NI j;
	NI bb;
	NI i;
	NI k;
	{
		NI LOC3;
		NI LOC4;
		LOC3 = 0;
		LOC3 = cmp_361646.ClEnv? cmp_361646.ClPrc(a_361622[m_361636], a_361622[(NI32)(m_361636 + 1)], cmp_361646.ClEnv):((TMP4798)(cmp_361646.ClPrc))(a_361622[m_361636], a_361622[(NI32)(m_361636 + 1)]);
		LOC4 = 0;
		LOC4 = HEX2A_358020(LOC3, order_361649);
		if (!(LOC4 <= 0)) goto LA5;
		goto BeforeRet;
	}
	LA5: ;
	j = lo_361634;
	bb = 0;
	{
		while (1) {
			if (!(j <= m_361636)) goto LA8;
			HEX3CHEX2D_360607((&b_361630[bb]), a_361622[j]);
			bb += 1;
			j += 1;
		} LA8: ;
	}
	i = 0;
	k = lo_361634;
	{
		while (1) {
			NIM_BOOL LOC11;
			LOC11 = 0;
			LOC11 = (k < j);
			if (!(LOC11)) goto LA12;
			LOC11 = (j <= hi_361638);
			LA12: ;
			if (!LOC11) goto LA10;
			{
				NI LOC15;
				NI LOC16;
				LOC15 = 0;
				LOC15 = cmp_361646.ClEnv? cmp_361646.ClPrc(b_361630[i], a_361622[j], cmp_361646.ClEnv):((TMP4799)(cmp_361646.ClPrc))(b_361630[i], a_361622[j]);
				LOC16 = 0;
				LOC16 = HEX2A_358020(LOC15, order_361649);
				if (!(LOC16 <= 0)) goto LA17;
				HEX3CHEX2D_360607((&a_361622[k]), b_361630[i]);
				i += 1;
			}
			goto LA13;
			LA17: ;
			{
				HEX3CHEX2D_360607((&a_361622[k]), a_361622[j]);
				j += 1;
			}
			LA13: ;
			k += 1;
		} LA10: ;
	}
	{
		while (1) {
			if (!(k < j)) goto LA21;
			HEX3CHEX2D_360607((&a_361622[k]), b_361630[i]);
			k += 1;
			i += 1;
		} LA21: ;
	}
	BeforeRet: ;
}

N_NIMCALL(void, sort_361553)(tindexentry360264* a_361561, NI a_361561Len0, TY361572 cmp_361571, NU8 order_361574) {
	NI n;
	TY362804* b;
	NI s;
	n = a_361561Len0;
	b = 0;
	b = (TY362804*) newSeq((&NTI362804), (NI32)(n / 2));
	s = 1;
	{
		while (1) {
			NI m;
			if (!(s < n)) goto LA2;
			m = (NI32)((NI32)(n - 1) - s);
			{
				while (1) {
					if (!(0 <= m)) goto LA4;
					merge_361614(a_361561, a_361561Len0, b->data, b->Sup.len, (((NI32)((NI32)(m - s) + 1) >= 0) ? (NI32)((NI32)(m - s) + 1) : 0), m, (NI32)(m + s), cmp_361571, order_361574);
					m -= (NI32)(s * 2);
				} LA4: ;
			}
			s = (NI32)(s * 2);
		} LA2: ;
	}
}

N_NIMCALL(void, merge_420186)(tentry419478* a_420194, NI a_420194Len0, tentry419478* b_420202, NI b_420202Len0, NI lo_420206, NI m_420208, NI hi_420210, TY420144 cmp_420218, NU8 order_420221) {
	NI j;
	NI bb;
	NI i;
	NI k;
	{
		NI LOC3;
		NI LOC4;
		LOC3 = 0;
		LOC3 = cmp_420218.ClEnv? cmp_420218.ClPrc(a_420194[m_420208], a_420194[(NI32)(m_420208 + 1)], cmp_420218.ClEnv):((TMP4855)(cmp_420218.ClPrc))(a_420194[m_420208], a_420194[(NI32)(m_420208 + 1)]);
		LOC4 = 0;
		LOC4 = HEX2A_358020(LOC3, order_420221);
		if (!(LOC4 <= 0)) goto LA5;
		goto BeforeRet;
	}
	LA5: ;
	j = lo_420206;
	bb = 0;
	{
		while (1) {
			if (!(j <= m_420208)) goto LA8;
			b_420202[bb].Pos = a_420194[j].Pos;
			unsureAsgnRef((void**) (&b_420202[bb].Sym), a_420194[j].Sym);
			bb += 1;
			j += 1;
		} LA8: ;
	}
	i = 0;
	k = lo_420206;
	{
		while (1) {
			NIM_BOOL LOC11;
			LOC11 = 0;
			LOC11 = (k < j);
			if (!(LOC11)) goto LA12;
			LOC11 = (j <= hi_420210);
			LA12: ;
			if (!LOC11) goto LA10;
			{
				NI LOC15;
				NI LOC16;
				LOC15 = 0;
				LOC15 = cmp_420218.ClEnv? cmp_420218.ClPrc(b_420202[i], a_420194[j], cmp_420218.ClEnv):((TMP4856)(cmp_420218.ClPrc))(b_420202[i], a_420194[j]);
				LOC16 = 0;
				LOC16 = HEX2A_358020(LOC15, order_420221);
				if (!(LOC16 <= 0)) goto LA17;
				a_420194[k].Pos = b_420202[i].Pos;
				unsureAsgnRef((void**) (&a_420194[k].Sym), b_420202[i].Sym);
				i += 1;
			}
			goto LA13;
			LA17: ;
			{
				a_420194[k].Pos = a_420194[j].Pos;
				unsureAsgnRef((void**) (&a_420194[k].Sym), a_420194[j].Sym);
				j += 1;
			}
			LA13: ;
			k += 1;
		} LA10: ;
	}
	{
		while (1) {
			if (!(k < j)) goto LA21;
			a_420194[k].Pos = b_420202[i].Pos;
			unsureAsgnRef((void**) (&a_420194[k].Sym), b_420202[i].Sym);
			k += 1;
			i += 1;
		} LA21: ;
	}
	BeforeRet: ;
}

N_NIMCALL(void, sort_420125)(tentry419478* a_420133, NI a_420133Len0, TY420144 cmp_420143, NU8 order_420146) {
	NI n;
	TY419485* b;
	NI s;
	n = a_420133Len0;
	b = 0;
	b = (TY419485*) newSeq((&NTI419485), (NI32)(n / 2));
	s = 1;
	{
		while (1) {
			NI m;
			if (!(s < n)) goto LA2;
			m = (NI32)((NI32)(n - 1) - s);
			{
				while (1) {
					if (!(0 <= m)) goto LA4;
					merge_420186(a_420133, a_420133Len0, b->data, b->Sup.len, (((NI32)((NI32)(m - s) + 1) >= 0) ? (NI32)((NI32)(m - s) + 1) : 0), m, (NI32)(m + s), cmp_420143, order_420146);
					m -= (NI32)(s * 2);
				} LA4: ;
			}
			s = (NI32)(s * 2);
		} LA2: ;
	}
}
NIM_EXTERNC N_NOINLINE(void, stdlib_algorithmInit)(void) {
}

NIM_EXTERNC N_NOINLINE(void, stdlib_algorithmDatInit)(void) {
NTI358033.size = sizeof(NI);
NTI358033.kind = 20;
NTI358033.base = (&NTI108);
NTI358033.flags = 3;
}

