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

#include <string.h>

#include <stdio.h>
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct trope145007 trope145007;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
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 TY163540 TY163540;
typedef struct tbasechunk22636 tbasechunk22636;
typedef struct tfreecell22628 tfreecell22628;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef struct {
N_NIMCALL_PTR(void, ClPrc) (NU8 err, NimStringDesc* msg, NIM_BOOL usewarning, void* ClEnv);
void* ClEnv;
} TY145103;
typedef trope145007* TY145184[4096];
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  trope145007  {
  TNimObject Sup;
trope145007* Left;
trope145007* Right;
NI Length;
NimStringDesc* Data;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
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;
};
typedef trope145007* TY145497[1];
typedef N_CLOSURE_PTR(void, TMP3131) (NU8 err, NimStringDesc* msg, NIM_BOOL usewarning);
typedef N_CLOSURE_PTR(void, TMP3132) (NU8 err, NimStringDesc* msg, NIM_BOOL usewarning);
typedef N_CLOSURE_PTR(void, TMP3895) (NU8 err, NimStringDesc* msg, NIM_BOOL usewarning);
typedef NI TY144046[256];
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  tfreecell22628  {
tfreecell22628* Next;
NI Zerofield;
};
struct TY163540 {
  TGenericSeq Sup;
  trope145007* data[SEQ_DECL_SIZE];
};
N_NIMCALL(trope145007*, newrope_145135)(NimStringDesc* data);
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP125)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
N_NIMCALL(NimStringDesc*, copyStringRC1)(NimStringDesc* src);
static N_INLINE(void, nimGCunrefNoCycle)(void* p);
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(void, asgnRefNoCycle)(void** dest, void* src);
N_NIMCALL(trope145007*, con_145020)(trope145007* a, trope145007* b);
N_NIMCALL(void, unsureAsgnRef)(void** dest, void* src);
N_NIMCALL(trope145007*, insertincache_145262)(NimStringDesc* s);
N_NIMCALL(NI, hash_119827)(NimStringDesc* x);
static N_INLINE(NIM_BOOL, eqStrings)(NimStringDesc* a, NimStringDesc* b);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(NimStringDesc*, mnewString)(NI len);
N_NIMCALL(NimStringDesc*, mnewString)(NI len);
N_NIMCALL(void, newrecropetostr_145474)(NimStringDesc** result, NI* resultlen, trope145007* r);
N_NIMCALL(void*, newSeq)(TNimType* typ, NI len);
static N_INLINE(trope145007*, pop_145515)(TY163540** s_145523);
N_NIMCALL(TGenericSeq*, setLengthSeq)(TGenericSeq* seq, NI elemsize, NI newlen);
N_NIMCALL(TGenericSeq*, incrSeq)(TGenericSeq* seq, NI elemsize);
N_NIMCALL(trope145007*, con_145025)(trope145007* a, NimStringDesc* b);
N_NIMCALL(trope145007*, torope_145058)(NimStringDesc* s);
N_NIMCALL(void, app_145046)(trope145007** a, NimStringDesc* b);
N_NIMCALL(void, app_145040)(trope145007** a, trope145007* b);
N_NIMCALL(NimStringDesc*, nimIntToStr)(NI x);
N_NIMCALL(NimStringDesc*, nimCharToStr)(NIM_CHAR x);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI start_70624, NI last);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI first, NI last);
N_NIMCALL(NimStringDesc*, nimInt64ToStr)(NI64 x);
N_NIMCALL(trope145007*, ropef_145079)(NimStringDesc* frmt, trope145007** args, NI argsLen0);
N_NIMCALL(NIM_BOOL, open_10203)(FILE** f, NimStringDesc* filename, NU8 mode, NI bufsize);
N_NIMCALL(void, writerope_145993)(FILE* f, trope145007* c);
N_NIMCALL(void, write_10463)(FILE* f, NimStringDesc* s);
N_NIMCALL(NI32, crcfromfile_144031)(NimStringDesc* filename);
N_NIMCALL(NI32, crcfromrope_147226)(trope145007* r);
N_NIMCALL(NI32, newcrcfromropeaux_147063)(trope145007* r, NI32 startval);
static N_INLINE(NI32, updatecrc32_144017)(NIM_CHAR val, NI32 crc);
static N_INLINE(NI32, updatecrc32_144012)(NI8 val, NI32 crc);
N_NIMCALL(void, writerope_146407)(trope145007* head, NimStringDesc* filename, NIM_BOOL usewarning);
STRING_LITERAL(TMP1131, "", 0);
STRING_LITERAL(TMP3130, "$", 1);
extern NIM_CONST TY144046 crc32table_144045;
TY145103 errorhandler_145108;
TY145184 cache_145189;
NI gcachetries_145256;
NI gcachemisses_145258;
NI gcacheinttries_145260;
trope145007* rnl_146434;
extern TNimType NTI2409; /* TObject */
TNimType NTI145007; /* TRope */
extern TNimType NTI106; /* int */
extern TNimType NTI143; /* string */
TNimType NTI145005; /* PRope */
extern tgcheap43016 gch_43044;
extern NimStringDesc* tnl_142593;
trope145007* softrnl_146435;
extern TNimType NTI163540; /* seq[PRope] */
N_NIMCALL(void, TMP125)(void* p, NI op) {
	trope145007* a;
	a = (trope145007*)p;
	nimGCvisit((void*)(*a).Left, op);
	nimGCvisit((void*)(*a).Right, op);
	nimGCvisit((void*)(*a).Data, op);
}

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, nimGCunrefNoCycle)(void* p) {
	tcell41090* c;
	c = usrtocell_44443(p);
	{
		(*c).Refcount -= 8;
		if (!((NU32)((*c).Refcount) < (NU32)(8))) goto LA3;
		rtladdzct_46002(c);
	}
	LA3: ;
}

N_NIMCALL(trope145007*, newrope_145135)(NimStringDesc* data) {
	trope145007* result;
	result = 0;
	result = (trope145007*) newObj((&NTI145005), sizeof(trope145007));
	(*result).Sup.m_type = (&NTI145007);
	{
		NimStringDesc* LOC5;
		if (!!((data == NIM_NIL))) goto LA3;
		(*result).Length = data->Sup.len;
		LOC5 = 0;
		LOC5 = (*result).Data; (*result).Data = copyStringRC1(data);
		if (LOC5) nimGCunrefNoCycle(LOC5);
	}
	LA3: ;
	return result;
}

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

N_NIMCALL(trope145007*, con_145020)(trope145007* a, trope145007* b) {
	trope145007* result;
	result = 0;
	{
		if (!(a == NIM_NIL)) goto LA3;
		result = b;
	}
	goto LA1;
	LA3: ;
	{
		if (!(b == NIM_NIL)) goto LA6;
		result = a;
	}
	goto LA1;
	LA6: ;
	{
		result = newrope_145135(NIM_NIL);
		(*result).Length = (NI32)((*a).Length + (*b).Length);
		asgnRefNoCycle((void**) &(*result).Left, a);
		asgnRefNoCycle((void**) &(*result).Right, b);
	}
	LA1: ;
	return result;
}

N_NIMCALL(void, app_145040)(trope145007** a, trope145007* b) {
	unsureAsgnRef((void**) &(*a), con_145020((*a), b));
}

static N_INLINE(NIM_BOOL, eqStrings)(NimStringDesc* a, NimStringDesc* b) {
	NIM_BOOL result;
	NIM_BOOL LOC11;
	int LOC13;
	result = 0;
	{
		if (!(a == b)) goto LA3;
		result = NIM_TRUE;
		goto BeforeRet;
	}
	LA3: ;
	{
		NIM_BOOL LOC7;
		LOC7 = 0;
		LOC7 = (a == NIM_NIL);
		if (LOC7) goto LA8;
		LOC7 = (b == NIM_NIL);
		LA8: ;
		if (!LOC7) goto LA9;
		result = NIM_FALSE;
		goto BeforeRet;
	}
	LA9: ;
	LOC11 = 0;
	LOC11 = ((*a).Sup.len == (*b).Sup.len);
	if (!(LOC11)) goto LA12;
	LOC13 = 0;
	LOC13 = memcmp(((NCSTRING) ((*a).data)), ((NCSTRING) ((*b).data)), (NI32)((*a).Sup.len * 1));
	LOC11 = (LOC13 == ((NI32) 0));
	LA12: ;
	result = LOC11;
	goto BeforeRet;
	BeforeRet: ;
	return result;
}

N_NIMCALL(trope145007*, insertincache_145262)(NimStringDesc* s) {
	trope145007* result;
	NI h;
	NI LOC1;
	result = 0;
	gcachetries_145256 += 1;
	LOC1 = 0;
	LOC1 = hash_119827(s);
	h = (NI)(LOC1 & 4095);
	result = cache_145189[(h)- 0];
	{
		NIM_BOOL LOC4;
		LOC4 = 0;
		LOC4 = result == 0;
		if (LOC4) goto LA5;
		LOC4 = !(eqStrings((*result).Data, s));
		LA5: ;
		if (!LOC4) goto LA6;
		gcachemisses_145258 += 1;
		result = newrope_145135(s);
		asgnRefNoCycle((void**) &cache_145189[(h)- 0], result);
	}
	LA6: ;
	return result;
}

N_NIMCALL(trope145007*, torope_145058)(NimStringDesc* s) {
	trope145007* result;
	result = 0;
	{
		if (!(s->Sup.len == 0)) goto LA3;
		result = NIM_NIL;
	}
	goto LA1;
	LA3: ;
	{
		result = insertincache_145262(s);
	}
	LA1: ;
	return result;
}

static N_INLINE(trope145007*, pop_145515)(TY163540** s_145523) {
	trope145007* result;
	NI l;
	result = 0;
	l = (NI32)((*s_145523)->Sup.len - 1);
	result = (*s_145523)->data[l];
	(*s_145523) = (TY163540*) setLengthSeq(&((*s_145523))->Sup, sizeof(trope145007*), l);
	return result;
}

N_NIMCALL(void, newrecropetostr_145474)(NimStringDesc** result, NI* resultlen, trope145007* r) {
	TY163540* stack;
	TY145497 LOC1;
	stack = (TY163540*) newSeq((&NTI163540), 1);
	memset((void*)LOC1, 0, sizeof(LOC1));
	LOC1[0] = r;
	asgnRefNoCycle((void**) &stack->data[0], LOC1[0]);
	while (1) {
		trope145007* it;
		if (!(0 < stack->Sup.len)) goto LA2;
		it = pop_145515(&stack);
		while (1) {
			if (!((*it).Data == NIM_NIL)) goto LA3;
			stack = (TY163540*) incrSeq(&(stack)->Sup, sizeof(trope145007*));
			asgnRefNoCycle((void**) &stack->data[stack->Sup.len-1], (*it).Right);
			it = (*it).Left;
		} LA3: ;
		memcpy(((void*) (&(*result)->data[(*resultlen)])), ((void*) (&(*it).Data->data[0])), (*it).Length);
		(*resultlen) += (*it).Length;
	} LA2: ;
}

N_NIMCALL(NimStringDesc*, ropetostr_145075)(trope145007* p) {
	NimStringDesc* result;
	result = 0;
	{
		if (!(p == NIM_NIL)) goto LA3;
		result = copyString(((NimStringDesc*) &TMP1131));
	}
	goto LA1;
	LA3: ;
	{
		NI resultlen;
		result = mnewString((*p).Length);
		resultlen = 0;
		newrecropetostr_145474(&result, &resultlen, p);
	}
	LA1: ;
	return result;
}

N_NIMCALL(trope145007*, con_145025)(trope145007* a, NimStringDesc* b) {
	trope145007* result;
	trope145007* LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = torope_145058(b);
	result = con_145020(a, LOC1);
	return result;
}

N_NIMCALL(void, app_145046)(trope145007** a, NimStringDesc* b) {
	unsureAsgnRef((void**) &(*a), con_145025((*a), b));
}

N_NIMCALL(trope145007*, ropef_145079)(NimStringDesc* frmt, trope145007** args, NI argsLen0) {
	trope145007* result;
	NI i;
	NI length;
	NI num;
	result = 0;
	i = 0;
	length = frmt->Sup.len;
	result = NIM_NIL;
	num = 0;
	while (1) {
		NI start;
		if (!(i <= (NI32)(length - 1))) goto LA1;
		{
			if (!((NU8)(frmt->data[i]) == (NU8)(36))) goto LA4;
			i += 1;
			switch (((NU8)(frmt->data[i]))) {
			case 36:
			{
				app_145046(&result, ((NimStringDesc*) &TMP3130));
				i += 1;
			}
			break;
			case 35:
			{
				i += 1;
				app_145040(&result, args[num]);
				num += 1;
			}
			break;
			case 48 ... 57:
			{
				NI j;
				j = 0;
				while (1) {
					j = (NI32)((NI32)((NI32)(j * 10) + ((NI) (((NU8)(frmt->data[i]))))) - 48);
					i += 1;
					{
						NIM_BOOL LOC12;
						LOC12 = 0;
						LOC12 = ((NI32)((NI32)(length + 0) - 1) < i);
						if (LOC12) goto LA13;
						LOC12 = !((((NU8)(frmt->data[i])) >= ((NU8)(48)) && ((NU8)(frmt->data[i])) <= ((NU8)(57))));
						LA13: ;
						if (!LOC12) goto LA14;
						goto LA9;
					}
					LA14: ;
				} LA9: ;
				num = j;
				{
					NimStringDesc* LOC20;
					if (!((NI32)((argsLen0-1) + 1) < j)) goto LA18;
					LOC20 = 0;
					LOC20 = nimIntToStr(j);
					errorhandler_145108.ClEnv? errorhandler_145108.ClPrc(((NU8) 1), LOC20, NIM_FALSE, errorhandler_145108.ClEnv):((TMP3131)(errorhandler_145108.ClPrc))(((NU8) 1), LOC20, NIM_FALSE);
				}
				goto LA16;
				LA18: ;
				{
					app_145040(&result, args[(NI32)(j - 1)]);
				}
				LA16: ;
			}
			break;
			case 110:
			{
				app_145040(&result, softrnl_146435);
				i += 1;
			}
			break;
			case 78:
			{
				app_145040(&result, rnl_146434);
				i += 1;
			}
			break;
			default:
			{
				NimStringDesc* LOC25;
				LOC25 = 0;
				LOC25 = nimCharToStr(frmt->data[i]);
				errorhandler_145108.ClEnv? errorhandler_145108.ClPrc(((NU8) 1), LOC25, NIM_FALSE, errorhandler_145108.ClEnv):((TMP3132)(errorhandler_145108.ClPrc))(((NU8) 1), LOC25, NIM_FALSE);
			}
			break;
			}
		}
		LA4: ;
		start = i;
		while (1) {
			if (!(i < length)) goto LA26;
			{
				if (!!(((NU8)(frmt->data[i]) == (NU8)(36)))) goto LA29;
				i += 1;
			}
			goto LA27;
			LA29: ;
			{
				goto LA26;
			}
			LA27: ;
		} LA26: ;
		{
			NimStringDesc* LOC36;
			if (!(start <= (NI32)(i - 1))) goto LA34;
			LOC36 = 0;
			LOC36 = copyStrLast(frmt, start, (NI32)(i - 1));
			app_145046(&result, LOC36);
		}
		LA34: ;
	} LA1: ;
	return result;
}

N_NIMCALL(trope145007*, torope_145062)(NI64 i) {
	trope145007* result;
	NimStringDesc* LOC1;
	result = 0;
	gcacheinttries_145260 += 1;
	LOC1 = 0;
	LOC1 = nimInt64ToStr(i);
	result = torope_145058(LOC1);
	return result;
}

N_NIMCALL(trope145007*, con_145035)(trope145007** a, NI aLen0) {
	trope145007* result;
	NI i_145907;
	NI HEX3Atmp_145910;
	NI res_145912;
	result = 0;
	i_145907 = 0;
	HEX3Atmp_145910 = 0;
	HEX3Atmp_145910 = (aLen0-1);
	res_145912 = 0;
	while (1) {
		if (!(res_145912 <= HEX3Atmp_145910)) goto LA1;
		i_145907 = res_145912;
		result = con_145020(result, a[i_145907]);
		res_145912 += 1;
	} LA1: ;
	return result;
}

N_NIMCALL(void, appf_145085)(trope145007** c, NimStringDesc* frmt, trope145007** args, NI argsLen0) {
	trope145007* LOC1;
	LOC1 = 0;
	LOC1 = ropef_145079(frmt, args, argsLen0);
	app_145040(c, LOC1);
}

N_NIMCALL(trope145007*, con_145030)(NimStringDesc* a, trope145007* b) {
	trope145007* result;
	trope145007* LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = torope_145058(a);
	result = con_145020(LOC1, b);
	return result;
}

N_NIMCALL(void, prepend_145052)(trope145007** a, trope145007* b) {
	unsureAsgnRef((void**) &(*a), con_145020(b, (*a)));
}

N_NIMCALL(void, writerope_145993)(FILE* f, trope145007* c) {
	TY163540* stack;
	TY145497 LOC1;
	stack = (TY163540*) newSeq((&NTI163540), 1);
	memset((void*)LOC1, 0, sizeof(LOC1));
	LOC1[0] = c;
	asgnRefNoCycle((void**) &stack->data[0], LOC1[0]);
	while (1) {
		trope145007* it;
		if (!(0 < stack->Sup.len)) goto LA2;
		it = pop_145515(&stack);
		while (1) {
			if (!((*it).Data == NIM_NIL)) goto LA3;
			stack = (TY163540*) incrSeq(&(stack)->Sup, sizeof(trope145007*));
			asgnRefNoCycle((void**) &stack->data[stack->Sup.len-1], (*it).Right);
			it = (*it).Left;
		} LA3: ;
		write_10463(f, (*it).Data);
	} LA2: ;
}

N_NIMCALL(void, writerope_146407)(trope145007* head, NimStringDesc* filename, NIM_BOOL usewarning) {
	FILE* f;
	f = 0;
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = open_10203(&f, filename, ((NU8) 1), -1);
		if (!LOC3) goto LA4;
		{
			if (!!((head == NIM_NIL))) goto LA8;
			writerope_145993(f, head);
		}
		LA8: ;
		fclose(f);
	}
	goto LA1;
	LA4: ;
	{
		errorhandler_145108.ClEnv? errorhandler_145108.ClPrc(((NU8) 0), filename, usewarning, errorhandler_145108.ClEnv):((TMP3895)(errorhandler_145108.ClPrc))(((NU8) 0), filename, usewarning);
	}
	LA1: ;
}

static N_INLINE(NI32, updatecrc32_144012)(NI8 val, NI32 crc) {
	NI32 result;
	result = 0;
	result = (NI32)(((NI32) (crc32table_144045[((NI)((NI)(((NI) (crc)) ^ ((NI) ((NI)(((NI) (val)) & 255)))) & 255))- 0])) ^ (NI32)((NU32)(crc) >> (NU32)(((NI32) 8))));
	return result;
}

static N_INLINE(NI32, updatecrc32_144017)(NIM_CHAR val, NI32 crc) {
	NI32 result;
	result = 0;
	result = updatecrc32_144012(((NI8)(NU8)(NU)(((NI) (((NU8)(val)))))), crc);
	return result;
}

N_NIMCALL(NI32, newcrcfromropeaux_147063)(trope145007* r, NI32 startval) {
	NI32 result;
	TY163540* stack;
	TY145497 LOC1;
	result = 0;
	stack = (TY163540*) newSeq((&NTI163540), 1);
	memset((void*)LOC1, 0, sizeof(LOC1));
	LOC1[0] = r;
	asgnRefNoCycle((void**) &stack->data[0], LOC1[0]);
	result = startval;
	while (1) {
		trope145007* it;
		NI i;
		NI l;
		if (!(0 < stack->Sup.len)) goto LA2;
		it = pop_145515(&stack);
		while (1) {
			if (!((*it).Data == NIM_NIL)) goto LA3;
			stack = (TY163540*) incrSeq(&(stack)->Sup, sizeof(trope145007*));
			asgnRefNoCycle((void**) &stack->data[stack->Sup.len-1], (*it).Right);
			it = (*it).Left;
		} LA3: ;
		i = 0;
		l = (*it).Data->Sup.len;
		while (1) {
			if (!(i < l)) goto LA4;
			result = updatecrc32_144017((*it).Data->data[i], result);
			i += 1;
		} LA4: ;
	} LA2: ;
	return result;
}

N_NIMCALL(NI32, crcfromrope_147226)(trope145007* r) {
	NI32 result;
	result = 0;
	result = newcrcfromropeaux_147063(r, ((NI32) -1));
	return result;
}

N_NIMCALL(NIM_BOOL, writeropeifnotequal_145070)(trope145007* r, NimStringDesc* filename) {
	NIM_BOOL result;
	NI32 c;
	result = 0;
	c = 0;
	c = crcfromfile_144031(filename);
	{
		NI32 LOC3;
		LOC3 = 0;
		LOC3 = crcfromrope_147226(r);
		if (!!((c == LOC3))) goto LA4;
		writerope_146407(r, filename, NIM_FALSE);
		result = NIM_TRUE;
	}
	goto LA1;
	LA4: ;
	{
		result = NIM_FALSE;
	}
	LA1: ;
	return result;
}

N_NIMCALL(void, resetropecache_145192)(void) {
	NI i_145225;
	NI res_145228;
	i_145225 = 0;
	res_145228 = 0;
	while (1) {
		if (!(((NI) (res_145228)) <= 4095)) goto LA1;
		i_145225 = res_145228;
		asgnRefNoCycle((void**) &cache_145189[(i_145225)- 0], NIM_NIL);
		res_145228 += 1;
	} LA1: ;
}
N_NOINLINE(void, ropesInit)(void) {
	gcachetries_145256 = 0;
	gcachemisses_145258 = 0;
	gcacheinttries_145260 = 0;
	asgnRefNoCycle((void**) &rnl_146434, newrope_145135(tnl_142593));
	asgnRefNoCycle((void**) &softrnl_146435, newrope_145135(tnl_142593));
}

N_NOINLINE(void, ropesDatInit)(void) {
static TNimNode* TMP124[4];
static TNimNode TMP55[5];
NTI145007.size = sizeof(trope145007);
NTI145007.kind = 17;
NTI145007.base = (&NTI2409);
NTI145007.flags = 2;
TMP124[0] = &TMP55[1];
TMP55[1].kind = 1;
TMP55[1].offset = offsetof(trope145007, Left);
TMP55[1].typ = (&NTI145005);
TMP55[1].name = "left";
TMP124[1] = &TMP55[2];
TMP55[2].kind = 1;
TMP55[2].offset = offsetof(trope145007, Right);
TMP55[2].typ = (&NTI145005);
TMP55[2].name = "right";
TMP124[2] = &TMP55[3];
TMP55[3].kind = 1;
TMP55[3].offset = offsetof(trope145007, Length);
TMP55[3].typ = (&NTI106);
TMP55[3].name = "length";
TMP124[3] = &TMP55[4];
TMP55[4].kind = 1;
TMP55[4].offset = offsetof(trope145007, Data);
TMP55[4].typ = (&NTI143);
TMP55[4].name = "data";
TMP55[0].len = 4; TMP55[0].kind = 2; TMP55[0].sons = &TMP124[0];
NTI145007.node = &TMP55[0];
NTI145005.size = sizeof(trope145007*);
NTI145005.kind = 22;
NTI145005.base = (&NTI145007);
NTI145005.flags = 2;
NTI145005.marker = TMP125;
}

