/* 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 tsym224846 tsym224846;
typedef struct tsymseq224818 tsymseq224818;
typedef struct TGenericSeq TGenericSeq;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct NimStringDesc NimStringDesc;
typedef struct TY118808 TY118808;
typedef struct tindexentry358264 tindexentry358264;
typedef struct TY360804 TY360804;
typedef struct tentry417478 tentry417478;
typedef struct TY417485 TY417485;
typedef struct tidobj199015 tidobj199015;
typedef struct TNimObject TNimObject;
typedef struct ttypeseq224848 ttypeseq224848;
typedef struct ttype224852 ttype224852;
typedef struct tscope224840 tscope224840;
typedef struct TY224947 TY224947;
typedef struct tinstantiation224836 tinstantiation224836;
typedef struct tstrtable224820 tstrtable224820;
typedef struct tident199021 tident199021;
typedef struct tlineinfo194539 tlineinfo194539;
typedef struct tnode224816 tnode224816;
typedef struct tloc224830 tloc224830;
typedef struct trope176009 trope176009;
typedef struct tlib224834 tlib224834;
typedef struct tnodeseq224810 tnodeseq224810;
typedef struct TY224936 TY224936;
typedef struct tlistentry126022 tlistentry126022;
typedef struct {
N_NIMCALL_PTR(NI, ClPrc) (tsym224846* x_414632, tsym224846* y_414634, void* ClEnv);
void* ClEnv;
} TY414638;
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, TMP2633) (tsym224846* x_414707, tsym224846* y_414709);
typedef N_CLOSURE_PTR(NI, TMP2634) (tsym224846* x_414707, tsym224846* y_414709);
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef struct {
N_NIMCALL_PTR(NI, ClPrc) (NimStringDesc* x_361565, NimStringDesc* y_361567, void* ClEnv);
void* ClEnv;
} TY361571;
typedef N_CLOSURE_PTR(NI, TMP4792) (NimStringDesc* x_361640, NimStringDesc* y_361642);
typedef N_CLOSURE_PTR(NI, TMP4793) (NimStringDesc* x_361640, NimStringDesc* y_361642);
struct  tindexentry358264  {
NimStringDesc* Keyword;
NimStringDesc* Link;
NimStringDesc* Linktitle;
NimStringDesc* Linkdesc;
};
typedef struct {
N_NIMCALL_PTR(NI, ClPrc) (tindexentry358264 x_359566, tindexentry358264 y_359568, void* ClEnv);
void* ClEnv;
} TY359572;
typedef N_CLOSURE_PTR(NI, TMP4796) (tindexentry358264 x_359641, tindexentry358264 y_359643);
typedef N_CLOSURE_PTR(NI, TMP4797) (tindexentry358264 x_359641, tindexentry358264 y_359643);
struct  tentry417478  {
NI Pos;
tsym224846* Sym;
};
typedef struct {
N_NIMCALL_PTR(NI, ClPrc) (tentry417478 x_418138, tentry417478 y_418140, void* ClEnv);
void* ClEnv;
} TY418144;
typedef N_CLOSURE_PTR(NI, TMP4853) (tentry417478 x_418213, tentry417478 y_418215);
typedef N_CLOSURE_PTR(NI, TMP4854) (tentry417478 x_418213, tentry417478 y_418215);
struct  TNimObject  {
TNimType* m_type;
};
struct  tidobj199015  {
  TNimObject Sup;
NI Id;
};
struct  tstrtable224820  {
NI Counter;
tsymseq224818* Data;
};
struct  tlineinfo194539  {
NI16 Line;
NI16 Col;
NI32 Fileindex;
};
struct  tloc224830  {
NU8 K;
NU8 S;
NU8 Flags;
ttype224852* T;
trope176009* R;
trope176009* Heaproot;
};
struct  tsym224846  {
  tidobj199015 Sup;
NU8 Kind;
union {
struct {ttypeseq224848* Typeinstcache;
tscope224840* Typscope;
} S1;
struct {TY224947* Procinstcache;
tscope224840* Scope;
} S2;
struct {TY224947* Usedgenerics;
tstrtable224820 Tab;
} S3;
struct {tsym224846* Guard;
} S4;
} kindU;
NU16 Magic;
ttype224852* Typ;
tident199021* Name;
tlineinfo194539 Info;
tsym224846* Owner;
NU32 Flags;
tnode224816* Ast;
NU32 Options;
NI Position;
NI Offset;
tloc224830 Loc;
tlib224834* Annex;
tnode224816* Constraint;
};
struct  ttype224852  {
  tidobj199015 Sup;
NU8 Kind;
NU8 Callconv;
NU32 Flags;
ttypeseq224848* Sons;
tnode224816* N;
tsym224846* Owner;
tsym224846* Sym;
tsym224846* Destructor;
tsym224846* Deepcopy;
NI64 Size;
NI16 Align;
NI16 Locklevel;
tloc224830 Loc;
};
struct  tscope224840  {
NI Depthlevel;
tstrtable224820 Symbols;
tnodeseq224810* Usingsyms;
tscope224840* Parent;
};
struct  tinstantiation224836  {
tsym224846* Sym;
ttypeseq224848* Concretetypes;
TY224936* Usedby;
};
struct  tident199021  {
  tidobj199015 Sup;
NimStringDesc* S;
tident199021* Next;
NI H;
};
struct  tnode224816  {
ttype224852* Typ;
tlineinfo194539 Info;
NU16 Flags;
NU8 Kind;
union {
struct {NI64 Intval;
} S1;
struct {NF Floatval;
} S2;
struct {NimStringDesc* Strval;
} S3;
struct {tsym224846* Sym;
} S4;
struct {tident199021* Ident;
} S5;
struct {tnodeseq224810* Sons;
} S6;
} kindU;
NimStringDesc* Comment;
};
struct  trope176009  {
  TNimObject Sup;
trope176009* Left;
trope176009* Right;
NI Length;
NimStringDesc* Data;
};
struct  tlistentry126022  {
  TNimObject Sup;
tlistentry126022* Prev;
tlistentry126022* Next;
};
struct  tlib224834  {
  tlistentry126022 Sup;
NU8 Kind;
NIM_BOOL Generated;
NIM_BOOL Isoverriden;
trope176009* Name;
tnode224816* Path;
};
struct tsymseq224818 {
  TGenericSeq Sup;
  tsym224846* data[SEQ_DECL_SIZE];
};
struct TY118808 {
  TGenericSeq Sup;
  NimStringDesc* data[SEQ_DECL_SIZE];
};
struct TY360804 {
  TGenericSeq Sup;
  tindexentry358264 data[SEQ_DECL_SIZE];
};
struct TY417485 {
  TGenericSeq Sup;
  tentry417478 data[SEQ_DECL_SIZE];
};
struct ttypeseq224848 {
  TGenericSeq Sup;
  ttype224852* data[SEQ_DECL_SIZE];
};
struct TY224947 {
  TGenericSeq Sup;
  tinstantiation224836* data[SEQ_DECL_SIZE];
};
struct tnodeseq224810 {
  TGenericSeq Sup;
  tnode224816* data[SEQ_DECL_SIZE];
};
struct TY224936 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
N_NIMCALL(void*, newSeq)(TNimType* typ, NI len);
N_NIMCALL(void, merge_414680)(tsym224846** a_414688, NI a_414688Len0, tsym224846** b_414696, NI b_414696Len0, NI lo_414700, NI m_414702, NI hi_414704, TY414638 cmp_414712, NU8 order_414715);
static N_INLINE(NI, HEX2A_356020)(NI x, NU8 order);
N_NIMCALL(void, unsureAsgnRef)(void** dest, void* src);
N_NIMCALL(void, merge_361613)(NimStringDesc** a_361621, NI a_361621Len0, NimStringDesc** b_361629, NI b_361629Len0, NI lo_361633, NI m_361635, NI hi_361637, TY361571 cmp_361645, NU8 order_361648);
N_NIMCALL(void, merge_359614)(tindexentry358264* a_359622, NI a_359622Len0, tindexentry358264* b_359630, NI b_359630Len0, NI lo_359634, NI m_359636, NI hi_359638, TY359572 cmp_359646, NU8 order_359649);
N_NIMCALL(void, HEX3CHEX2D_358607)(tindexentry358264* a, tindexentry358264 b);
N_NIMCALL(void, merge_418186)(tentry417478* a_418194, NI a_418194Len0, tentry417478* b_418202, NI b_418202Len0, NI lo_418206, NI m_418208, NI hi_418210, TY418144 cmp_418218, NU8 order_418221);
extern TNimType NTI224818; /* TSymSeq */
extern TNimType NTI108; /* int */
TNimType NTI356033; /* range -1..0(int) */
extern TNimType NTI118808; /* seq[string] */
extern TNimType NTI360804; /* seq[TIndexEntry] */
extern TNimType NTI417485; /* seq[TEntry] */

static N_INLINE(NI, HEX2A_356020)(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_414680)(tsym224846** a_414688, NI a_414688Len0, tsym224846** b_414696, NI b_414696Len0, NI lo_414700, NI m_414702, NI hi_414704, TY414638 cmp_414712, NU8 order_414715) {
	NI j;
	NI bb;
	NI i;
	NI k;
	{
		NI LOC3;
		NI LOC4;
		LOC3 = 0;
		LOC3 = cmp_414712.ClEnv? cmp_414712.ClPrc(a_414688[m_414702], a_414688[(NI32)(m_414702 + 1)], cmp_414712.ClEnv):((TMP2633)(cmp_414712.ClPrc))(a_414688[m_414702], a_414688[(NI32)(m_414702 + 1)]);
		LOC4 = 0;
		LOC4 = HEX2A_356020(LOC3, order_414715);
		if (!(LOC4 <= 0)) goto LA5;
		goto BeforeRet;
	}
	LA5: ;
	j = lo_414700;
	bb = 0;
	{
		while (1) {
			if (!(j <= m_414702)) goto LA8;
			unsureAsgnRef((void**) (&b_414696[bb]), a_414688[j]);
			bb += 1;
			j += 1;
		} LA8: ;
	}
	i = 0;
	k = lo_414700;
	{
		while (1) {
			NIM_BOOL LOC11;
			LOC11 = 0;
			LOC11 = (k < j);
			if (!(LOC11)) goto LA12;
			LOC11 = (j <= hi_414704);
			LA12: ;
			if (!LOC11) goto LA10;
			{
				NI LOC15;
				NI LOC16;
				LOC15 = 0;
				LOC15 = cmp_414712.ClEnv? cmp_414712.ClPrc(b_414696[i], a_414688[j], cmp_414712.ClEnv):((TMP2634)(cmp_414712.ClPrc))(b_414696[i], a_414688[j]);
				LOC16 = 0;
				LOC16 = HEX2A_356020(LOC15, order_414715);
				if (!(LOC16 <= 0)) goto LA17;
				unsureAsgnRef((void**) (&a_414688[k]), b_414696[i]);
				i += 1;
			}
			goto LA13;
			LA17: ;
			{
				unsureAsgnRef((void**) (&a_414688[k]), a_414688[j]);
				j += 1;
			}
			LA13: ;
			k += 1;
		} LA10: ;
	}
	{
		while (1) {
			if (!(k < j)) goto LA21;
			unsureAsgnRef((void**) (&a_414688[k]), b_414696[i]);
			k += 1;
			i += 1;
		} LA21: ;
	}
	BeforeRet: ;
}

N_NIMCALL(void, sort_414619)(tsym224846** a_414627, NI a_414627Len0, TY414638 cmp_414637, NU8 order_414640) {
	NI n;
	tsymseq224818* b;
	NI s;
	n = a_414627Len0;
	b = 0;
	b = (tsymseq224818*) newSeq((&NTI224818), (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_414680(a_414627, a_414627Len0, b->data, b->Sup.len, (((NI32)((NI32)(m - s) + 1) >= 0) ? (NI32)((NI32)(m - s) + 1) : 0), m, (NI32)(m + s), cmp_414637, order_414640);
					m -= (NI32)(s * 2);
				} LA4: ;
			}
			s = (NI32)(s * 2);
		} LA2: ;
	}
}

N_NIMCALL(void, merge_361613)(NimStringDesc** a_361621, NI a_361621Len0, NimStringDesc** b_361629, NI b_361629Len0, NI lo_361633, NI m_361635, NI hi_361637, TY361571 cmp_361645, NU8 order_361648) {
	NI j;
	NI bb;
	NI i;
	NI k;
	{
		NI LOC3;
		NI LOC4;
		LOC3 = 0;
		LOC3 = cmp_361645.ClEnv? cmp_361645.ClPrc(a_361621[m_361635], a_361621[(NI32)(m_361635 + 1)], cmp_361645.ClEnv):((TMP4792)(cmp_361645.ClPrc))(a_361621[m_361635], a_361621[(NI32)(m_361635 + 1)]);
		LOC4 = 0;
		LOC4 = HEX2A_356020(LOC3, order_361648);
		if (!(LOC4 <= 0)) goto LA5;
		goto BeforeRet;
	}
	LA5: ;
	j = lo_361633;
	bb = 0;
	{
		while (1) {
			if (!(j <= m_361635)) goto LA8;
			unsureAsgnRef((void**) (&b_361629[bb]), a_361621[j]);
			bb += 1;
			j += 1;
		} LA8: ;
	}
	i = 0;
	k = lo_361633;
	{
		while (1) {
			NIM_BOOL LOC11;
			LOC11 = 0;
			LOC11 = (k < j);
			if (!(LOC11)) goto LA12;
			LOC11 = (j <= hi_361637);
			LA12: ;
			if (!LOC11) goto LA10;
			{
				NI LOC15;
				NI LOC16;
				LOC15 = 0;
				LOC15 = cmp_361645.ClEnv? cmp_361645.ClPrc(b_361629[i], a_361621[j], cmp_361645.ClEnv):((TMP4793)(cmp_361645.ClPrc))(b_361629[i], a_361621[j]);
				LOC16 = 0;
				LOC16 = HEX2A_356020(LOC15, order_361648);
				if (!(LOC16 <= 0)) goto LA17;
				unsureAsgnRef((void**) (&a_361621[k]), b_361629[i]);
				i += 1;
			}
			goto LA13;
			LA17: ;
			{
				unsureAsgnRef((void**) (&a_361621[k]), a_361621[j]);
				j += 1;
			}
			LA13: ;
			k += 1;
		} LA10: ;
	}
	{
		while (1) {
			if (!(k < j)) goto LA21;
			unsureAsgnRef((void**) (&a_361621[k]), b_361629[i]);
			k += 1;
			i += 1;
		} LA21: ;
	}
	BeforeRet: ;
}

N_NIMCALL(void, sort_361552)(NimStringDesc** a_361560, NI a_361560Len0, TY361571 cmp_361570, NU8 order_361573) {
	NI n;
	TY118808* b;
	NI s;
	n = a_361560Len0;
	b = 0;
	b = (TY118808*) newSeq((&NTI118808), (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_361613(a_361560, a_361560Len0, b->data, b->Sup.len, (((NI32)((NI32)(m - s) + 1) >= 0) ? (NI32)((NI32)(m - s) + 1) : 0), m, (NI32)(m + s), cmp_361570, order_361573);
					m -= (NI32)(s * 2);
				} LA4: ;
			}
			s = (NI32)(s * 2);
		} LA2: ;
	}
}

N_NIMCALL(void, merge_359614)(tindexentry358264* a_359622, NI a_359622Len0, tindexentry358264* b_359630, NI b_359630Len0, NI lo_359634, NI m_359636, NI hi_359638, TY359572 cmp_359646, NU8 order_359649) {
	NI j;
	NI bb;
	NI i;
	NI k;
	{
		NI LOC3;
		NI LOC4;
		LOC3 = 0;
		LOC3 = cmp_359646.ClEnv? cmp_359646.ClPrc(a_359622[m_359636], a_359622[(NI32)(m_359636 + 1)], cmp_359646.ClEnv):((TMP4796)(cmp_359646.ClPrc))(a_359622[m_359636], a_359622[(NI32)(m_359636 + 1)]);
		LOC4 = 0;
		LOC4 = HEX2A_356020(LOC3, order_359649);
		if (!(LOC4 <= 0)) goto LA5;
		goto BeforeRet;
	}
	LA5: ;
	j = lo_359634;
	bb = 0;
	{
		while (1) {
			if (!(j <= m_359636)) goto LA8;
			HEX3CHEX2D_358607((&b_359630[bb]), a_359622[j]);
			bb += 1;
			j += 1;
		} LA8: ;
	}
	i = 0;
	k = lo_359634;
	{
		while (1) {
			NIM_BOOL LOC11;
			LOC11 = 0;
			LOC11 = (k < j);
			if (!(LOC11)) goto LA12;
			LOC11 = (j <= hi_359638);
			LA12: ;
			if (!LOC11) goto LA10;
			{
				NI LOC15;
				NI LOC16;
				LOC15 = 0;
				LOC15 = cmp_359646.ClEnv? cmp_359646.ClPrc(b_359630[i], a_359622[j], cmp_359646.ClEnv):((TMP4797)(cmp_359646.ClPrc))(b_359630[i], a_359622[j]);
				LOC16 = 0;
				LOC16 = HEX2A_356020(LOC15, order_359649);
				if (!(LOC16 <= 0)) goto LA17;
				HEX3CHEX2D_358607((&a_359622[k]), b_359630[i]);
				i += 1;
			}
			goto LA13;
			LA17: ;
			{
				HEX3CHEX2D_358607((&a_359622[k]), a_359622[j]);
				j += 1;
			}
			LA13: ;
			k += 1;
		} LA10: ;
	}
	{
		while (1) {
			if (!(k < j)) goto LA21;
			HEX3CHEX2D_358607((&a_359622[k]), b_359630[i]);
			k += 1;
			i += 1;
		} LA21: ;
	}
	BeforeRet: ;
}

N_NIMCALL(void, sort_359553)(tindexentry358264* a_359561, NI a_359561Len0, TY359572 cmp_359571, NU8 order_359574) {
	NI n;
	TY360804* b;
	NI s;
	n = a_359561Len0;
	b = 0;
	b = (TY360804*) newSeq((&NTI360804), (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_359614(a_359561, a_359561Len0, b->data, b->Sup.len, (((NI32)((NI32)(m - s) + 1) >= 0) ? (NI32)((NI32)(m - s) + 1) : 0), m, (NI32)(m + s), cmp_359571, order_359574);
					m -= (NI32)(s * 2);
				} LA4: ;
			}
			s = (NI32)(s * 2);
		} LA2: ;
	}
}

N_NIMCALL(void, merge_418186)(tentry417478* a_418194, NI a_418194Len0, tentry417478* b_418202, NI b_418202Len0, NI lo_418206, NI m_418208, NI hi_418210, TY418144 cmp_418218, NU8 order_418221) {
	NI j;
	NI bb;
	NI i;
	NI k;
	{
		NI LOC3;
		NI LOC4;
		LOC3 = 0;
		LOC3 = cmp_418218.ClEnv? cmp_418218.ClPrc(a_418194[m_418208], a_418194[(NI32)(m_418208 + 1)], cmp_418218.ClEnv):((TMP4853)(cmp_418218.ClPrc))(a_418194[m_418208], a_418194[(NI32)(m_418208 + 1)]);
		LOC4 = 0;
		LOC4 = HEX2A_356020(LOC3, order_418221);
		if (!(LOC4 <= 0)) goto LA5;
		goto BeforeRet;
	}
	LA5: ;
	j = lo_418206;
	bb = 0;
	{
		while (1) {
			if (!(j <= m_418208)) goto LA8;
			b_418202[bb].Pos = a_418194[j].Pos;
			unsureAsgnRef((void**) (&b_418202[bb].Sym), a_418194[j].Sym);
			bb += 1;
			j += 1;
		} LA8: ;
	}
	i = 0;
	k = lo_418206;
	{
		while (1) {
			NIM_BOOL LOC11;
			LOC11 = 0;
			LOC11 = (k < j);
			if (!(LOC11)) goto LA12;
			LOC11 = (j <= hi_418210);
			LA12: ;
			if (!LOC11) goto LA10;
			{
				NI LOC15;
				NI LOC16;
				LOC15 = 0;
				LOC15 = cmp_418218.ClEnv? cmp_418218.ClPrc(b_418202[i], a_418194[j], cmp_418218.ClEnv):((TMP4854)(cmp_418218.ClPrc))(b_418202[i], a_418194[j]);
				LOC16 = 0;
				LOC16 = HEX2A_356020(LOC15, order_418221);
				if (!(LOC16 <= 0)) goto LA17;
				a_418194[k].Pos = b_418202[i].Pos;
				unsureAsgnRef((void**) (&a_418194[k].Sym), b_418202[i].Sym);
				i += 1;
			}
			goto LA13;
			LA17: ;
			{
				a_418194[k].Pos = a_418194[j].Pos;
				unsureAsgnRef((void**) (&a_418194[k].Sym), a_418194[j].Sym);
				j += 1;
			}
			LA13: ;
			k += 1;
		} LA10: ;
	}
	{
		while (1) {
			if (!(k < j)) goto LA21;
			a_418194[k].Pos = b_418202[i].Pos;
			unsureAsgnRef((void**) (&a_418194[k].Sym), b_418202[i].Sym);
			k += 1;
			i += 1;
		} LA21: ;
	}
	BeforeRet: ;
}

N_NIMCALL(void, sort_418125)(tentry417478* a_418133, NI a_418133Len0, TY418144 cmp_418143, NU8 order_418146) {
	NI n;
	TY417485* b;
	NI s;
	n = a_418133Len0;
	b = 0;
	b = (TY417485*) newSeq((&NTI417485), (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_418186(a_418133, a_418133Len0, b->data, b->Sup.len, (((NI32)((NI32)(m - s) + 1) >= 0) ? (NI32)((NI32)(m - s) + 1) : 0), m, (NI32)(m + s), cmp_418143, order_418146);
					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) {
NTI356033.size = sizeof(NI);
NTI356033.kind = 20;
NTI356033.base = (&NTI108);
NTI356033.flags = 3;
}

