/* Generated by Nim Compiler v0.12.0 */
/*   (c) 2015 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 32

#include "nimbase.h"
#include <string.h>
#include <stdio.h>
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Valueerror4049 Valueerror4049;
typedef struct Exception Exception;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Cell48946 Cell48946;
typedef struct Cellseq48962 Cellseq48962;
typedef struct Gcheap51018 Gcheap51018;
typedef struct Gcstack51016 Gcstack51016;
typedef struct Cellset48958 Cellset48958;
typedef struct Pagedesc48954 Pagedesc48954;
typedef struct Memregion30890 Memregion30890;
typedef struct Smallchunk30842 Smallchunk30842;
typedef struct Llchunk30884 Llchunk30884;
typedef struct Bigchunk30844 Bigchunk30844;
typedef struct Intset30817 Intset30817;
typedef struct Trunk30813 Trunk30813;
typedef struct Avlnode30888 Avlnode30888;
typedef struct Gcstat51014 Gcstat51014;
typedef struct TY130408 TY130408;
typedef struct Slice90365 Slice90365;
typedef struct Basechunk30840 Basechunk30840;
typedef struct Freecell30832 Freecell30832;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef N_NIMCALL_PTR(void, TY3889) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3894) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3889 marker;
TY3894 deepcopy;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  Exception  {
  TNimObject Sup;
Exception* parent;
NCSTRING name;
NimStringDesc* message;
NimStringDesc* trace;
};
struct  Valueerror4049  {
  Exception Sup;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  Cell48946  {
NI refcount;
TNimType* typ;
};
struct  Cellseq48962  {
NI len;
NI cap;
Cell48946** d;
};
struct  Cellset48958  {
NI counter;
NI max;
Pagedesc48954* head;
Pagedesc48954** data;
};
typedef Smallchunk30842* TY30905[512];
typedef Trunk30813* Trunkbuckets30815[256];
struct  Intset30817  {
Trunkbuckets30815 data;
};
struct  Memregion30890  {
NI minlargeobj;
NI maxlargeobj;
TY30905 freesmallchunks;
Llchunk30884* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk30844* freechunkslist;
Intset30817 chunkstarts;
Avlnode30888* root;
Avlnode30888* deleted;
Avlnode30888* last;
Avlnode30888* freeavlnodes;
};
struct  Gcstat51014  {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct  Gcheap51018  {
Gcstack51016* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq48962 zct;
Cellseq48962 decstack;
Cellset48958 cycleroots;
Cellseq48962 tempstack;
NI recgclock;
Memregion30890 region;
Gcstat51014 stat;
};
typedef NimStringDesc* TY191421[1];
typedef NI Skiptable103393[256];
typedef NU8 TY212407[32];
typedef NIM_CHAR TY105274[6];
typedef NIM_CHAR TY105278[2501];
typedef NIM_CHAR TY105270[3];
struct  Slice90365  {
NI a;
NI b;
};
struct  Gcstack51016  {
Gcstack51016* prev;
Gcstack51016* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY30821[16];
struct  Pagedesc48954  {
Pagedesc48954* next;
NI key;
TY30821 bits;
};
struct  Basechunk30840  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk30842  {
  Basechunk30840 Sup;
Smallchunk30842* next;
Smallchunk30842* prev;
Freecell30832* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk30884  {
NI size;
NI acc;
Llchunk30884* next;
};
struct  Bigchunk30844  {
  Basechunk30840 Sup;
Bigchunk30844* next;
Bigchunk30844* prev;
NI align;
NF data;
};
struct  Trunk30813  {
Trunk30813* next;
NI key;
TY30821 bits;
};
typedef Avlnode30888* TY30895[2];
struct  Avlnode30888  {
TY30895 link;
NI key;
NI upperbound;
NI level;
};
struct  Freecell30832  {
Freecell30832* next;
NI zerofield;
};
struct TY130408 {
  TGenericSeq Sup;
  NimStringDesc* data[SEQ_DECL_SIZE];
};
N_NIMCALL(NIM_CHAR, nsuToLowerChar)(NIM_CHAR c);
N_NIMCALL(NimStringDesc*, mnewString)(NI len);
N_NIMCALL(NimStringDesc*, mnewString)(NI len);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(NimStringDesc*, rawNewString)(NI cap);
N_NIMCALL(void, nsuAddf)(NimStringDesc** s, NimStringDesc* formatstr, NimStringDesc** a, NI aLen0);
N_NOINLINE(void, invalidformatstring_105467)(void);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
N_NIMCALL(NimStringDesc*, copyStringRC1)(NimStringDesc* src);
static N_INLINE(void, nimGCunrefNoCycle)(void* p);
static N_INLINE(Cell48946*, usrtocell_52646)(void* usr);
static N_INLINE(void, rtladdzct_54204)(Cell48946* c);
N_NOINLINE(void, addzct_52617)(Cellseq48962* s, Cell48946* c);
N_NIMCALL(void, raiseException)(Exception* e, NCSTRING ename);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
N_NIMCALL(NimStringDesc*, resizeString)(NimStringDesc* dest, NI addlen);
N_NIMCALL(NimStringDesc*, addChar)(NimStringDesc* s, NIM_CHAR c);
N_NIMCALL(NI, findnormalized_105438)(NimStringDesc* x, NimStringDesc** inarray, NI inarrayLen0);
N_NIMCALL(NI, nsuCmpIgnoreStyle)(NimStringDesc* a, NimStringDesc* b);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI start_81016, NI last);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI first, NI last);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(NI, npuParseFloat)(NimStringDesc* s, NF* number, NI start);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
N_NIMCALL(NI, npuParseBiggestInt)(NimStringDesc* s, NI64* number, NI start);
N_NIMCALL(void, preprocesssub_103399)(NimStringDesc* sub, NI* a);
N_NIMCALL(NI, findaux_103467)(NimStringDesc* s, NimStringDesc* sub, NI start, Skiptable103393 a);
N_NIMCALL(NimStringDesc*, copyStr)(NimStringDesc* s, NI start);
N_NIMCALL(NimStringDesc*, copyStr)(NimStringDesc* s, NI first);
N_NIMCALL(NI, nsuFindCharSet)(NimStringDesc* s, TY212407 chars, NI start);
N_NIMCALL(NI, npuParseInt)(NimStringDesc* s, NI* number, NI start);
N_NIMCALL(NimStringDesc*, setLengthStr)(NimStringDesc* s, NI newlen);
N_NIMCALL(NI, nsuFindChar)(NimStringDesc* s, NIM_CHAR sub, NI start);
N_NIMCALL(void*, newSeq)(TNimType* typ, NI len);
N_NIMCALL(TGenericSeq*, incrSeqV2)(TGenericSeq* seq, NI elemsize);
N_NIMCALL(NimStringDesc*, nsuToHex)(NI64 x, NI len);
N_NIMCALL(NimStringDesc*, nimIntToStr)(NI x);
static N_INLINE(void, appendChar)(NimStringDesc* dest, NIM_CHAR c);
N_NIMCALL(NimStringDesc*, nsuformatBiggestFloat)(NF f, NU8 format, NI precision, NIM_CHAR decimalsep);
static N_INLINE(Slice90365, HEX2EHEX2E_105290)(NI a, NI b);
N_NIMCALL(NimStringDesc*, nimInt64ToStr)(NI64 x);
N_NIMCALL(NimStringDesc*, nsuInsertSep)(NimStringDesc* s, NIM_CHAR sep, NI digits);
STRING_LITERAL(TMP153, "invalid format string", 21);
STRING_LITERAL(TMP1074, "invalid float: ", 15);
STRING_LITERAL(TMP1232, "invalid integer: ", 17);
STRING_LITERAL(TMP1377, "0123456789ABCDEF", 16);
STRING_LITERAL(TMP1379, "", 0);
STRING_LITERAL(TMP2072, "\\x", 2);
STRING_LITERAL(TMP2073, "\\\\", 2);
STRING_LITERAL(TMP2074, "\\\'", 2);
STRING_LITERAL(TMP2075, "\\\"", 2);
NIM_CONST TY105270 floatformattochar_105267 = {103,
102,
101}
;
STRING_LITERAL(TMP5272, "GB", 2);
STRING_LITERAL(TMP5273, "MB", 2);
STRING_LITERAL(TMP5274, "KB", 2);
STRING_LITERAL(TMP5275, "B", 1);
extern TNimType NTI25028; /* ref ValueError */
extern TNimType NTI4049; /* ValueError */
extern Gcheap51018 gch_51059;
extern TNimType NTI130408; /* seq[string] */
extern TNimType NTI108; /* int */
TNimType NTI103393; /* SkipTable */

N_NIMCALL(NIM_CHAR, nsuToLowerChar)(NIM_CHAR c) {
	NIM_CHAR result;
	result = 0;
	{
		if (!(((NU8)(c)) >= ((NU8)(65)) && ((NU8)(c)) <= ((NU8)(90)))) goto LA3;
		result = ((NIM_CHAR) (((NI) ((NI)(((NI) (((NU8)(c)))) + ((NI) 32))))));
	}
	goto LA1;
	LA3: ;
	{
		result = c;
	}
	LA1: ;
	return result;
}

N_NIMCALL(NI, nsuCmpIgnoreStyle)(NimStringDesc* a, NimStringDesc* b) {
	NI result;
	NI i;
	NI j;
	result = 0;
	i = ((NI) 0);
	j = ((NI) 0);
	{
		while (1) {
			NIM_CHAR aa;
			NIM_CHAR bb;
			{
				while (1) {
					if (!((NU8)(a->data[i]) == (NU8)(95))) goto LA4;
					i += ((NI) 1);
				} LA4: ;
			}
			{
				while (1) {
					if (!((NU8)(b->data[j]) == (NU8)(95))) goto LA6;
					j += ((NI) 1);
				} LA6: ;
			}
			aa = nsuToLowerChar(a->data[i]);
			bb = nsuToLowerChar(b->data[j]);
			result = (NI)(((NI) (((NU8)(aa)))) - ((NI) (((NU8)(bb)))));
			{
				NIM_BOOL LOC9;
				LOC9 = 0;
				LOC9 = !((result == ((NI) 0)));
				if (LOC9) goto LA10;
				LOC9 = ((NU8)(aa) == (NU8)(0));
				LA10: ;
				if (!LOC9) goto LA11;
				goto LA1;
			}
			LA11: ;
			i += ((NI) 1);
			j += ((NI) 1);
		}
	} LA1: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nsuToOctal)(NIM_CHAR c) {
	NimStringDesc* result;
	NI val;
	result = 0;
	result = mnewString(((NI) 3));
	val = ((NU8)(c));
	{
		NI i_101039;
		NI res_101054;
		i_101039 = 0;
		res_101054 = ((NI) 2);
		{
			while (1) {
				if (!(((NI) 0) <= res_101054)) goto LA3;
				i_101039 = res_101054;
				result->data[i_101039] = ((NIM_CHAR) (((NI) ((NI)(((NI) ((NI)(((NI) (val)) % ((NI) 8)))) + ((NI) 48))))));
				val = ((NI) ((NI)(((NI) (val)) / ((NI) 8))));
				res_101054 -= ((NI) 1);
			} LA3: ;
		}
	}
	return result;
}

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

static N_INLINE(void, rtladdzct_54204)(Cell48946* c) {
	addzct_52617((&gch_51059.zct), c);
}

static N_INLINE(void, nimGCunrefNoCycle)(void* p) {
	Cell48946* c;
	c = usrtocell_52646(p);
	{
		(*c).refcount -= ((NI) 8);
		if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA3;
		rtladdzct_54204(c);
	}
	LA3: ;
}

N_NOINLINE(void, invalidformatstring_105467)(void) {
	Valueerror4049* e_105472;
	NimStringDesc* LOC1;
	e_105472 = 0;
	e_105472 = (Valueerror4049*) newObj((&NTI25028), sizeof(Valueerror4049));
	(*e_105472).Sup.Sup.m_type = (&NTI4049);
	LOC1 = 0;
	LOC1 = (*e_105472).Sup.message; (*e_105472).Sup.message = copyStringRC1(((NimStringDesc*) &TMP153));
	if (LOC1) nimGCunrefNoCycle(LOC1);
	raiseException((Exception*)e_105472, "ValueError");
}

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

N_NIMCALL(NI, findnormalized_105438)(NimStringDesc* x, NimStringDesc** inarray, NI inarrayLen0) {
	NI result;
	NI i;
{	result = 0;
	i = ((NI) 0);
	{
		while (1) {
			if (!(i < (inarrayLen0-1))) goto LA2;
			{
				NI LOC5;
				LOC5 = 0;
				LOC5 = nsuCmpIgnoreStyle(x, inarray[i]);
				if (!(LOC5 == ((NI) 0))) goto LA6;
				result = i;
				goto BeforeRet;
			}
			LA6: ;
			i += ((NI) 2);
		} LA2: ;
	}
	result = ((NI) -1);
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(void, nsuAddf)(NimStringDesc** s, NimStringDesc* formatstr, NimStringDesc** a, NI aLen0) {
	NI i;
	NI num;
	i = ((NI) 0);
	num = ((NI) 0);
	{
		while (1) {
			if (!(i < (formatstr ? formatstr->Sup.len : 0))) goto LA2;
			{
				if (!((NU8)(formatstr->data[i]) == (NU8)(36))) goto LA5;
				switch (((NU8)(formatstr->data[(NI)(i + ((NI) 1))]))) {
				case 35:
				{
					{
						if (!((NU32)((aLen0-1)) < (NU32)(num))) goto LA10;
						invalidformatstring_105467();
					}
					LA10: ;
					(*s) = resizeString((*s), a[num]->Sup.len + 0);
appendString((*s), a[num]);
					i += ((NI) 2);
					num += ((NI) 1);
				}
				break;
				case 36:
				{
					(*s) = addChar((*s), 36);
					i += ((NI) 2);
				}
				break;
				case 49 ... 57:
				case 45:
				{
					NI j;
					NIM_BOOL negative;
					NI idx;
					j = ((NI) 0);
					i += ((NI) 1);
					negative = ((NU8)(formatstr->data[i]) == (NU8)(45));
					{
						if (!negative) goto LA16;
						i += ((NI) 1);
					}
					LA16: ;
					{
						while (1) {
							if (!(((NU8)(formatstr->data[i])) >= ((NU8)(48)) && ((NU8)(formatstr->data[i])) <= ((NU8)(57)))) goto LA19;
							j = (NI)((NI)((NI)(j * ((NI) 10)) + ((NI) (((NU8)(formatstr->data[i]))))) - ((NI) 48));
							i += ((NI) 1);
						} LA19: ;
					}
					{
						if (!!(negative)) goto LA22;
						idx = (NI)(j - ((NI) 1));
					}
					goto LA20;
					LA22: ;
					{
						idx = (NI)(aLen0 - j);
					}
					LA20: ;
					{
						if (!((NU32)((aLen0-1)) < (NU32)(idx))) goto LA27;
						invalidformatstring_105467();
					}
					LA27: ;
					(*s) = resizeString((*s), a[idx]->Sup.len + 0);
appendString((*s), a[idx]);
				}
				break;
				case 123:
				{
					NI j;
					NI x;
					NimStringDesc* LOC32;
					j = (NI)(i + ((NI) 1));
					{
						while (1) {
							if (!!((((NU8)(formatstr->data[j])) == ((NU8)(0)) || ((NU8)(formatstr->data[j])) == ((NU8)(125))))) goto LA31;
							j += ((NI) 1);
						} LA31: ;
					}
					LOC32 = 0;
					LOC32 = copyStrLast(formatstr, (NI)(i + ((NI) 2)), (NI)(j - ((NI) 1)));
					x = findnormalized_105438(LOC32, a, aLen0);
					{
						NIM_BOOL LOC35;
						LOC35 = 0;
						LOC35 = (((NI) 0) <= x);
						if (!(LOC35)) goto LA36;
						LOC35 = (x < (aLen0-1));
						LA36: ;
						if (!LOC35) goto LA37;
						(*s) = resizeString((*s), a[(NI)(x + ((NI) 1))]->Sup.len + 0);
appendString((*s), a[(NI)(x + ((NI) 1))]);
					}
					goto LA33;
					LA37: ;
					{
						invalidformatstring_105467();
					}
					LA33: ;
					i = (NI)(j + ((NI) 1));
				}
				break;
				case 97 ... 122:
				case 65 ... 90:
				case 128 ... 255:
				case 95:
				{
					NI j;
					NI x;
					NimStringDesc* LOC43;
					j = (NI)(i + ((NI) 1));
					{
						while (1) {
							if (!(((NU8)(formatstr->data[j])) >= ((NU8)(97)) && ((NU8)(formatstr->data[j])) <= ((NU8)(122)) || ((NU8)(formatstr->data[j])) >= ((NU8)(65)) && ((NU8)(formatstr->data[j])) <= ((NU8)(90)) || ((NU8)(formatstr->data[j])) >= ((NU8)(48)) && ((NU8)(formatstr->data[j])) <= ((NU8)(57)) || ((NU8)(formatstr->data[j])) >= ((NU8)(128)) && ((NU8)(formatstr->data[j])) <= ((NU8)(255)) || ((NU8)(formatstr->data[j])) == ((NU8)(95)))) goto LA42;
							j += ((NI) 1);
						} LA42: ;
					}
					LOC43 = 0;
					LOC43 = copyStrLast(formatstr, (NI)(i + ((NI) 1)), (NI)(j - ((NI) 1)));
					x = findnormalized_105438(LOC43, a, aLen0);
					{
						NIM_BOOL LOC46;
						LOC46 = 0;
						LOC46 = (((NI) 0) <= x);
						if (!(LOC46)) goto LA47;
						LOC46 = (x < (aLen0-1));
						LA47: ;
						if (!LOC46) goto LA48;
						(*s) = resizeString((*s), a[(NI)(x + ((NI) 1))]->Sup.len + 0);
appendString((*s), a[(NI)(x + ((NI) 1))]);
					}
					goto LA44;
					LA48: ;
					{
						invalidformatstring_105467();
					}
					LA44: ;
					i = j;
				}
				break;
				default:
				{
					invalidformatstring_105467();
				}
				break;
				}
			}
			goto LA3;
			LA5: ;
			{
				(*s) = addChar((*s), formatstr->data[i]);
				i += ((NI) 1);
			}
			LA3: ;
		} LA2: ;
	}
}

N_NIMCALL(NimStringDesc*, nsuFormatOpenArray)(NimStringDesc* formatstr, NimStringDesc** a, NI aLen0) {
	NimStringDesc* result;
	result = 0;
	result = rawNewString(((NI) ((NI)((formatstr ? formatstr->Sup.len : 0) + (NI)((NU32)(aLen0) << (NU32)(((NI) 4)))))));
	nsuAddf((&result), formatstr, a, aLen0);
	return result;
}

N_NIMCALL(NimStringDesc*, nsuFormatSingleElem)(NimStringDesc* formatstr, NimStringDesc* a) {
	NimStringDesc* result;
	TY191421 LOC1;
	result = 0;
	result = rawNewString(((NI) ((NI)((formatstr ? formatstr->Sup.len : 0) + (a ? a->Sup.len : 0)))));
	memset((void*)LOC1, 0, sizeof(LOC1));
	LOC1[0] = copyString(a);
	nsuAddf((&result), formatstr, LOC1, 1);
	return result;
}

N_NIMCALL(NimStringDesc*, nsuRepeatChar)(NIM_CHAR c, NI count) {
	NimStringDesc* result;
	result = 0;
	result = mnewString(count);
	{
		NI i_102378;
		NI HEX3Atmp_102380;
		NI res_102383;
		i_102378 = 0;
		HEX3Atmp_102380 = 0;
		HEX3Atmp_102380 = (NI)(((NI) (count)) - ((NI) 1));
		res_102383 = ((NI) 0);
		{
			while (1) {
				if (!(res_102383 <= ((NI) (HEX3Atmp_102380)))) goto LA3;
				i_102378 = ((NI) (res_102383));
				result->data[i_102378] = c;
				res_102383 += ((NI) 1);
			} LA3: ;
		}
	}
	return result;
}

static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src) {
	{
		Cell48946* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_52646(src);
		(*c).refcount += ((NI) 8);
	}
	LA3: ;
	{
		Cell48946* c;
		if (!!(((*dest) == NIM_NIL))) goto LA7;
		c = usrtocell_52646((*dest));
		{
			(*c).refcount -= ((NI) 8);
			if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA11;
			rtladdzct_54204(c);
		}
		LA11: ;
	}
	LA7: ;
	(*dest) = src;
}

N_NIMCALL(NF, nsuParseFloat)(NimStringDesc* s) {
	NF result;
	NI L;
	result = 0;
	L = npuParseFloat(s, (&result), ((NI) 0));
	{
		NIM_BOOL LOC3;
		Valueerror4049* e_102147;
		NimStringDesc* LOC7;
		LOC3 = 0;
		LOC3 = !((L == (s ? s->Sup.len : 0)));
		if (LOC3) goto LA4;
		LOC3 = (L == ((NI) 0));
		LA4: ;
		if (!LOC3) goto LA5;
		e_102147 = 0;
		e_102147 = (Valueerror4049*) newObj((&NTI25028), sizeof(Valueerror4049));
		(*e_102147).Sup.Sup.m_type = (&NTI4049);
		LOC7 = 0;
		LOC7 = rawNewString(s->Sup.len + 15);
appendString(LOC7, ((NimStringDesc*) &TMP1074));
appendString(LOC7, s);
		asgnRefNoCycle((void**) (&(*e_102147).Sup.message), LOC7);
		raiseException((Exception*)e_102147, "ValueError");
	}
	LA5: ;
	return result;
}

N_NIMCALL(NIM_BOOL, nsuStartsWith)(NimStringDesc* s, NimStringDesc* prefix) {
	NIM_BOOL result;
	NI i;
{	result = 0;
	i = ((NI) 0);
	{
		while (1) {
			{
				if (!((NU8)(prefix->data[i]) == (NU8)(0))) goto LA5;
				result = NIM_TRUE;
				goto BeforeRet;
			}
			LA5: ;
			{
				if (!!(((NU8)(s->data[i]) == (NU8)(prefix->data[i])))) goto LA9;
				result = NIM_FALSE;
				goto BeforeRet;
			}
			LA9: ;
			i += ((NI) 1);
		}
	}
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NI, nsuFindChar)(NimStringDesc* s, NIM_CHAR sub, NI start) {
	NI result;
{	result = 0;
	{
		NI i_103624;
		NI HEX3Atmp_103626;
		NI res_103629;
		i_103624 = 0;
		HEX3Atmp_103626 = 0;
		HEX3Atmp_103626 = (NI)((s ? s->Sup.len : 0) - ((NI) 1));
		res_103629 = ((NI) (start));
		{
			while (1) {
				if (!(res_103629 <= HEX3Atmp_103626)) goto LA3;
				i_103624 = res_103629;
				{
					if (!((NU8)(sub) == (NU8)(s->data[i_103624]))) goto LA6;
					result = i_103624;
					goto BeforeRet;
				}
				LA6: ;
				res_103629 += ((NI) 1);
			} LA3: ;
		}
	}
	result = ((NI) -1);
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NI64, nsuParseBiggestInt)(NimStringDesc* s) {
	NI64 result;
	NI L;
	result = 0;
	L = npuParseBiggestInt(s, (&result), ((NI) 0));
	{
		NIM_BOOL LOC3;
		Valueerror4049* e_102121;
		NimStringDesc* LOC7;
		LOC3 = 0;
		LOC3 = !((L == (s ? s->Sup.len : 0)));
		if (LOC3) goto LA4;
		LOC3 = (L == ((NI) 0));
		LA4: ;
		if (!LOC3) goto LA5;
		e_102121 = 0;
		e_102121 = (Valueerror4049*) newObj((&NTI25028), sizeof(Valueerror4049));
		(*e_102121).Sup.Sup.m_type = (&NTI4049);
		LOC7 = 0;
		LOC7 = rawNewString(s->Sup.len + 17);
appendString(LOC7, ((NimStringDesc*) &TMP1232));
appendString(LOC7, s);
		asgnRefNoCycle((void**) (&(*e_102121).Sup.message), LOC7);
		raiseException((Exception*)e_102121, "ValueError");
	}
	LA5: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nsuToHex)(NI64 x, NI len) {
	NimStringDesc* result;
	NI64 n;
	result = 0;
	n = x;
	result = mnewString(((NI) (len)));
	{
		NI j_102023;
		NI HEX3Atmp_102026;
		NI res_102029;
		j_102023 = 0;
		HEX3Atmp_102026 = 0;
		HEX3Atmp_102026 = (NI)(((NI) (len)) - ((NI) 1));
		res_102029 = ((NI) (HEX3Atmp_102026));
		{
			while (1) {
				if (!(((NI) 0) <= res_102029)) goto LA3;
				j_102023 = ((NI) (res_102029));
				result->data[j_102023] = ((NimStringDesc*) &TMP1377)->data[(NI64)(n & IL64(15))];
				n = (NI64)((NU64)(n) >> (NU64)(IL64(4)));
				{
					NIM_BOOL LOC6;
					LOC6 = 0;
					LOC6 = (n == IL64(0));
					if (!(LOC6)) goto LA7;
					LOC6 = (x < IL64(0));
					LA7: ;
					if (!LOC6) goto LA8;
					n = IL64(-1);
				}
				LA8: ;
				res_102029 -= ((NI) 1);
			} LA3: ;
		}
	}
	return result;
}

N_NIMCALL(void, preprocesssub_103399)(NimStringDesc* sub, NI* a) {
	NI m;
	m = (sub ? sub->Sup.len : 0);
	{
		NI i_103416;
		NI res_103431;
		i_103416 = 0;
		res_103431 = ((NI) 0);
		{
			while (1) {
				if (!(res_103431 <= ((NI) 255))) goto LA3;
				i_103416 = res_103431;
				a[(((NU8)(((NIM_CHAR) (((NI) (i_103416)))))))- 0] = (NI)(m + ((NI) 1));
				res_103431 += ((NI) 1);
			} LA3: ;
		}
	}
	{
		NI i_103427;
		NI HEX3Atmp_103436;
		NI res_103439;
		i_103427 = 0;
		HEX3Atmp_103436 = 0;
		HEX3Atmp_103436 = (NI)(m - ((NI) 1));
		res_103439 = ((NI) 0);
		{
			while (1) {
				if (!(res_103439 <= HEX3Atmp_103436)) goto LA6;
				i_103427 = res_103439;
				a[(((NU8)(sub->data[i_103427])))- 0] = (NI)(m - i_103427);
				res_103439 += ((NI) 1);
			} LA6: ;
		}
	}
}

N_NIMCALL(NI, findaux_103467)(NimStringDesc* s, NimStringDesc* sub, NI start, Skiptable103393 a) {
	NI result;
	NI m;
	NI n;
	NI j;
{	result = 0;
	m = (sub ? sub->Sup.len : 0);
	n = (s ? s->Sup.len : 0);
	j = start;
	{
		while (1) {
			if (!(j <= (NI)(n - m))) goto LA2;
			{
				{
					NI k_103488;
					NI HEX3Atmp_103500;
					NI res_103503;
					k_103488 = 0;
					HEX3Atmp_103500 = 0;
					HEX3Atmp_103500 = (NI)(m - ((NI) 1));
					res_103503 = ((NI) 0);
					{
						while (1) {
							if (!(res_103503 <= HEX3Atmp_103500)) goto LA6;
							k_103488 = res_103503;
							{
								if (!!(((NU8)(sub->data[k_103488]) == (NU8)(s->data[(NI)(k_103488 + j)])))) goto LA9;
								goto LA3;
							}
							LA9: ;
							res_103503 += ((NI) 1);
						} LA6: ;
					}
				}
				result = j;
				goto BeforeRet;
			} LA3: ;
			j += a[(((NU8)(s->data[(NI)(j + m)])))- 0];
		} LA2: ;
	}
	result = ((NI) -1);
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nsuReplaceStr)(NimStringDesc* s, NimStringDesc* sub, NimStringDesc* by) {
	NimStringDesc* result;
	Skiptable103393 a;
	NI i;
	NimStringDesc* LOC8;
	result = 0;
	result = copyString(((NimStringDesc*) &TMP1379));
	preprocesssub_103399(sub, a);
	i = ((NI) 0);
	{
		while (1) {
			NI j;
			NimStringDesc* LOC7;
			j = findaux_103467(s, sub, i, a);
			{
				if (!(j < ((NI) 0))) goto LA5;
				goto LA1;
			}
			LA5: ;
			LOC7 = 0;
			LOC7 = copyStrLast(s, i, (NI)(j - ((NI) 1)));
			result = resizeString(result, LOC7->Sup.len + 0);
appendString(result, LOC7);
			result = resizeString(result, by->Sup.len + 0);
appendString(result, by);
			i = (NI)(j + (sub ? sub->Sup.len : 0));
		}
	} LA1: ;
	LOC8 = 0;
	LOC8 = copyStr(s, i);
	result = resizeString(result, LOC8->Sup.len + 0);
appendString(result, LOC8);
	return result;
}

N_NIMCALL(NimStringDesc*, nsuToBin)(NI64 x, NI len) {
	NimStringDesc* result;
	NI64 mask;
	NI64 shift;
	result = 0;
	mask = IL64(1);
	shift = IL64(0);
	result = mnewString(((NI) (len)));
	{
		NI j_104613;
		NI HEX3Atmp_104625;
		NI res_104628;
		j_104613 = 0;
		HEX3Atmp_104625 = 0;
		HEX3Atmp_104625 = (NI)(((NI) (len)) - ((NI) 1));
		res_104628 = ((NI) (HEX3Atmp_104625));
		{
			while (1) {
				if (!(((NI) 0) <= res_104628)) goto LA3;
				j_104613 = ((NI) (res_104628));
				result->data[j_104613] = ((NIM_CHAR) (((NI) ((NI)(((NI) ((NI64)((NU64)((NI64)(x & mask)) >> (NU64)(shift)))) + ((NI) 48))))));
				shift = (NI64)(shift + IL64(1));
				mask = (NI64)((NU64)(mask) << (NU64)(IL64(1)));
				res_104628 -= ((NI) 1);
			} LA3: ;
		}
	}
	return result;
}

N_NIMCALL(NimStringDesc*, nsuToOct)(NI64 x, NI len) {
	NimStringDesc* result;
	NI64 mask;
	NI64 shift;
	result = 0;
	mask = IL64(7);
	shift = IL64(0);
	result = mnewString(((NI) (len)));
	{
		NI j_104413;
		NI HEX3Atmp_104425;
		NI res_104428;
		j_104413 = 0;
		HEX3Atmp_104425 = 0;
		HEX3Atmp_104425 = (NI)(((NI) (len)) - ((NI) 1));
		res_104428 = ((NI) (HEX3Atmp_104425));
		{
			while (1) {
				if (!(((NI) 0) <= res_104428)) goto LA3;
				j_104413 = ((NI) (res_104428));
				result->data[j_104413] = ((NIM_CHAR) (((NI) ((NI)(((NI) ((NI64)((NU64)((NI64)(x & mask)) >> (NU64)(shift)))) + ((NI) 48))))));
				shift = (NI64)(shift + IL64(3));
				mask = (NI64)((NU64)(mask) << (NU64)(IL64(3)));
				res_104428 -= ((NI) 1);
			} LA3: ;
		}
	}
	return result;
}

N_NIMCALL(NI, nsuFindCharSet)(NimStringDesc* s, TY212407 chars, NI start) {
	NI result;
{	result = 0;
	{
		NI i_103665;
		NI HEX3Atmp_103677;
		NI res_103680;
		i_103665 = 0;
		HEX3Atmp_103677 = 0;
		HEX3Atmp_103677 = (NI)((s ? s->Sup.len : 0) - ((NI) 1));
		res_103680 = ((NI) (start));
		{
			while (1) {
				if (!(res_103680 <= HEX3Atmp_103677)) goto LA3;
				i_103665 = res_103680;
				{
					if (!((chars[((NU8)(s->data[i_103665]))/8] &(1<<(((NU8)(s->data[i_103665]))%8)))!=0)) goto LA6;
					result = i_103665;
					goto BeforeRet;
				}
				LA6: ;
				res_103680 += ((NI) 1);
			} LA3: ;
		}
	}
	result = ((NI) -1);
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_BOOL, contains_103975)(NimStringDesc* s, TY212407 chars) {
	NIM_BOOL result;
	NI LOC1;
{	result = 0;
	LOC1 = 0;
	LOC1 = nsuFindCharSet(s, chars, ((NI) 0));
	result = (((NI) 0) <= LOC1);
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nsuStrip)(NimStringDesc* s, NIM_BOOL leading, NIM_BOOL trailing, TY212407 chars) {
	NimStringDesc* result;
	NI first;
	NI last;
	result = 0;
	first = ((NI) 0);
	last = (NI)((s ? s->Sup.len : 0) - ((NI) 1));
	{
		if (!leading) goto LA3;
		{
			while (1) {
				if (!((chars[((NU8)(s->data[first]))/8] &(1<<(((NU8)(s->data[first]))%8)))!=0)) goto LA6;
				first += ((NI) 1);
			} LA6: ;
		}
	}
	LA3: ;
	{
		if (!trailing) goto LA9;
		{
			while (1) {
				NIM_BOOL LOC13;
				LOC13 = 0;
				LOC13 = (((NI) 0) <= last);
				if (!(LOC13)) goto LA14;
				LOC13 = ((chars[((NU8)(s->data[last]))/8] &(1<<(((NU8)(s->data[last]))%8)))!=0);
				LA14: ;
				if (!LOC13) goto LA12;
				last -= ((NI) 1);
			} LA12: ;
		}
	}
	LA9: ;
	result = copyStrLast(s, first, last);
	return result;
}

N_NIMCALL(NI, nsuCmpIgnoreCase)(NimStringDesc* a, NimStringDesc* b) {
	NI result;
	NI i;
	NI m;
{	result = 0;
	i = ((NI) 0);
	m = (((a ? a->Sup.len : 0) <= (b ? b->Sup.len : 0)) ? (a ? a->Sup.len : 0) : (b ? b->Sup.len : 0));
	{
		while (1) {
			NIM_CHAR LOC3;
			NIM_CHAR LOC4;
			if (!(i < m)) goto LA2;
			LOC3 = 0;
			LOC3 = nsuToLowerChar(a->data[i]);
			LOC4 = 0;
			LOC4 = nsuToLowerChar(b->data[i]);
			result = (NI)(((NI) (((NU8)(LOC3)))) - ((NI) (((NU8)(LOC4)))));
			{
				if (!!((result == ((NI) 0)))) goto LA7;
				goto BeforeRet;
			}
			LA7: ;
			i += ((NI) 1);
		} LA2: ;
	}
	result = (NI)((a ? a->Sup.len : 0) - (b ? b->Sup.len : 0));
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NI, nsuParseInt)(NimStringDesc* s) {
	NI result;
	NI L;
	result = 0;
	L = npuParseInt(s, (&result), ((NI) 0));
	{
		NIM_BOOL LOC3;
		Valueerror4049* e_102095;
		NimStringDesc* LOC7;
		LOC3 = 0;
		LOC3 = !((L == (s ? s->Sup.len : 0)));
		if (LOC3) goto LA4;
		LOC3 = (L == ((NI) 0));
		LA4: ;
		if (!LOC3) goto LA5;
		e_102095 = 0;
		e_102095 = (Valueerror4049*) newObj((&NTI25028), sizeof(Valueerror4049));
		(*e_102095).Sup.Sup.m_type = (&NTI4049);
		LOC7 = 0;
		LOC7 = rawNewString(s->Sup.len + 17);
appendString(LOC7, ((NimStringDesc*) &TMP1232));
appendString(LOC7, s);
		asgnRefNoCycle((void**) (&(*e_102095).Sup.message), LOC7);
		raiseException((Exception*)e_102095, "ValueError");
	}
	LA5: ;
	return result;
}

N_NIMCALL(NI, nsuParseHexInt)(NimStringDesc* s) {
	NI result;
	NI i;
	result = 0;
	i = ((NI) 0);
	{
		NIM_BOOL LOC3;
		NIM_BOOL LOC5;
		LOC3 = 0;
		LOC3 = ((NU8)(s->data[i]) == (NU8)(48));
		if (!(LOC3)) goto LA4;
		LOC5 = 0;
		LOC5 = ((NU8)(s->data[(NI)(i + ((NI) 1))]) == (NU8)(120));
		if (LOC5) goto LA6;
		LOC5 = ((NU8)(s->data[(NI)(i + ((NI) 1))]) == (NU8)(88));
		LA6: ;
		LOC3 = LOC5;
		LA4: ;
		if (!LOC3) goto LA7;
		i += ((NI) 2);
	}
	goto LA1;
	LA7: ;
	{
		if (!((NU8)(s->data[i]) == (NU8)(35))) goto LA10;
		i += ((NI) 1);
	}
	goto LA1;
	LA10: ;
	LA1: ;
	{
		while (1) {
			switch (((NU8)(s->data[i]))) {
			case 95:
			{
				i += ((NI) 1);
			}
			break;
			case 48 ... 57:
			{
				result = (NI)((NI)((NU32)(result) << (NU32)(((NI) 4))) | ((NI) ((NI)(((NI) (((NU8)(s->data[i])))) - ((NI) 48)))));
				i += ((NI) 1);
			}
			break;
			case 97 ... 102:
			{
				result = (NI)((NI)((NU32)(result) << (NU32)(((NI) 4))) | ((NI) ((NI)(((NI) ((NI)(((NI) (((NU8)(s->data[i])))) - ((NI) 97)))) + ((NI) 10)))));
				i += ((NI) 1);
			}
			break;
			case 65 ... 70:
			{
				result = (NI)((NI)((NU32)(result) << (NU32)(((NI) 4))) | ((NI) ((NI)(((NI) ((NI)(((NI) (((NU8)(s->data[i])))) - ((NI) 65)))) + ((NI) 10)))));
				i += ((NI) 1);
			}
			break;
			case 0:
			{
				goto LA12;
			}
			break;
			default:
			{
				Valueerror4049* e_102281;
				NimStringDesc* LOC20;
				e_102281 = 0;
				e_102281 = (Valueerror4049*) newObj((&NTI25028), sizeof(Valueerror4049));
				(*e_102281).Sup.Sup.m_type = (&NTI4049);
				LOC20 = 0;
				LOC20 = rawNewString(s->Sup.len + 17);
appendString(LOC20, ((NimStringDesc*) &TMP1232));
appendString(LOC20, s);
				asgnRefNoCycle((void**) (&(*e_102281).Sup.message), LOC20);
				raiseException((Exception*)e_102281, "ValueError");
			}
			break;
			}
		}
	} LA12: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nsuNormalize)(NimStringDesc* s) {
	NimStringDesc* result;
	NI j;
	result = 0;
	result = mnewString(((NI) ((s ? s->Sup.len : 0))));
	j = ((NI) 0);
	{
		NI i_100727;
		NI HEX3Atmp_100785;
		NI res_100788;
		i_100727 = 0;
		HEX3Atmp_100785 = 0;
		HEX3Atmp_100785 = (NI)((s ? s->Sup.len : 0) - ((NI) 1));
		res_100788 = ((NI) 0);
		{
			while (1) {
				if (!(res_100788 <= HEX3Atmp_100785)) goto LA3;
				i_100727 = res_100788;
				{
					if (!(((NU8)(s->data[i_100727])) >= ((NU8)(65)) && ((NU8)(s->data[i_100727])) <= ((NU8)(90)))) goto LA6;
					result->data[j] = ((NIM_CHAR) (((NI) ((NI)(((NI) (((NU8)(s->data[i_100727])))) + ((NI) 32))))));
					j += ((NI) 1);
				}
				goto LA4;
				LA6: ;
				{
					if (!!(((NU8)(s->data[i_100727]) == (NU8)(95)))) goto LA9;
					result->data[j] = s->data[i_100727];
					j += ((NI) 1);
				}
				goto LA4;
				LA9: ;
				LA4: ;
				res_100788 += ((NI) 1);
			} LA3: ;
		}
	}
	{
		if (!!((j == (s ? s->Sup.len : 0)))) goto LA13;
		result = setLengthStr(result, ((NI) (j)));
	}
	LA13: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nsuToLowerStr)(NimStringDesc* s) {
	NimStringDesc* result;
	result = 0;
	result = mnewString(((NI) ((s ? s->Sup.len : 0))));
	{
		NI i_100592;
		NI HEX3Atmp_100594;
		NI res_100597;
		i_100592 = 0;
		HEX3Atmp_100594 = 0;
		HEX3Atmp_100594 = (NI)((s ? s->Sup.len : 0) - ((NI) 1));
		res_100597 = ((NI) 0);
		{
			while (1) {
				if (!(res_100597 <= HEX3Atmp_100594)) goto LA3;
				i_100592 = res_100597;
				result->data[i_100592] = nsuToLowerChar(s->data[i_100592]);
				res_100597 += ((NI) 1);
			} LA3: ;
		}
	}
	return result;
}

N_NIMCALL(NIM_BOOL, nsuEndsWith)(NimStringDesc* s, NimStringDesc* suffix) {
	NIM_BOOL result;
	NI i;
	NI j;
{	result = 0;
	i = ((NI) 0);
	j = (NI)((s ? s->Sup.len : 0) - (suffix ? suffix->Sup.len : 0));
	{
		while (1) {
			if (!((NU32)((NI)(i + j)) < (NU32)((s ? s->Sup.len : 0)))) goto LA2;
			{
				if (!!(((NU8)(s->data[(NI)(i + j)]) == (NU8)(suffix->data[i])))) goto LA5;
				result = NIM_FALSE;
				goto BeforeRet;
			}
			LA5: ;
			i += ((NI) 1);
		} LA2: ;
	}
	{
		if (!((NU8)(suffix->data[i]) == (NU8)(0))) goto LA9;
		result = NIM_TRUE;
		goto BeforeRet;
	}
	LA9: ;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_BOOL, contains_103953)(NimStringDesc* s, NIM_CHAR c) {
	NIM_BOOL result;
	NI LOC1;
{	result = 0;
	LOC1 = 0;
	LOC1 = nsuFindChar(s, c, ((NI) 0));
	result = (((NI) 0) <= LOC1);
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_BOOL, allcharsinset_103130)(NimStringDesc* s, TY212407 theset) {
	NIM_BOOL result;
{	result = 0;
	{
		NIM_CHAR c_103137;
		NI i_103151;
		NI L_103153;
		c_103137 = 0;
		i_103151 = ((NI) 0);
		L_103153 = (s ? s->Sup.len : 0);
		{
			while (1) {
				if (!(i_103151 < L_103153)) goto LA3;
				c_103137 = s->data[i_103151];
				{
					if (!!(((theset[((NU8)(c_103137))/8] &(1<<(((NU8)(c_103137))%8)))!=0))) goto LA6;
					result = NIM_FALSE;
					goto BeforeRet;
				}
				LA6: ;
				i_103151 += ((NI) 1);
			} LA3: ;
		}
	}
	result = NIM_TRUE;
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nsuJoin)(NimStringDesc** a, NI aLen0) {
	NimStringDesc* result;
	result = 0;
	{
		NI L;
		if (!(((NI) 0) < aLen0)) goto LA3;
		L = ((NI) 0);
		{
			NI i_103331;
			NI HEX3Atmp_103353;
			NI res_103356;
			i_103331 = 0;
			HEX3Atmp_103353 = 0;
			HEX3Atmp_103353 = (aLen0-1);
			res_103356 = ((NI) 0);
			{
				while (1) {
					if (!(res_103356 <= HEX3Atmp_103353)) goto LA7;
					i_103331 = res_103356;
					L += (a[i_103331] ? a[i_103331]->Sup.len : 0);
					res_103356 += ((NI) 1);
				} LA7: ;
			}
		}
		result = rawNewString(((NI) (L)));
		{
			NI i_103351;
			NI HEX3Atmp_103361;
			NI res_103364;
			i_103351 = 0;
			HEX3Atmp_103361 = 0;
			HEX3Atmp_103361 = (aLen0-1);
			res_103364 = ((NI) 0);
			{
				while (1) {
					if (!(res_103364 <= HEX3Atmp_103361)) goto LA10;
					i_103351 = res_103364;
					result = resizeString(result, a[i_103351]->Sup.len + 0);
appendString(result, a[i_103351]);
					res_103364 += ((NI) 1);
				} LA10: ;
			}
		}
	}
	goto LA1;
	LA3: ;
	{
		result = copyString(((NimStringDesc*) &TMP1379));
	}
	LA1: ;
	return result;
}

N_NIMCALL(NI, nsuFindStr)(NimStringDesc* s, NimStringDesc* sub, NI start) {
	NI result;
	Skiptable103393 a;
	result = 0;
	preprocesssub_103399(sub, a);
	result = findaux_103467(s, sub, ((NI) (start)), a);
	return result;
}

N_NIMCALL(TY130408*, nsuSplitChar)(NimStringDesc* s, NIM_CHAR sep) {
	TY130408* result;
	result = 0;
	result = (TY130408*) newSeq((&NTI130408), 0);
	{
		NimStringDesc* x_101758;
		NI last_101789;
		x_101758 = 0;
		last_101789 = ((NI) 0);
		{
			if (!(((NI) 0) < (s ? s->Sup.len : 0))) goto LA4;
			{
				while (1) {
					NI first_101791;
					NimStringDesc* LOC12;
					if (!(last_101789 <= (s ? s->Sup.len : 0))) goto LA7;
					first_101791 = last_101789;
					{
						while (1) {
							NIM_BOOL LOC10;
							LOC10 = 0;
							LOC10 = (last_101789 < (s ? s->Sup.len : 0));
							if (!(LOC10)) goto LA11;
							LOC10 = !(((NU8)(s->data[last_101789]) == (NU8)(sep)));
							LA11: ;
							if (!LOC10) goto LA9;
							last_101789 += ((NI) 1);
						} LA9: ;
					}
					x_101758 = copyStrLast(s, first_101791, (NI)(last_101789 - ((NI) 1)));
					result = (TY130408*) incrSeqV2(&(result)->Sup, sizeof(NimStringDesc*));
					LOC12 = 0;
					LOC12 = result->data[result->Sup.len]; result->data[result->Sup.len] = copyStringRC1(x_101758);
					if (LOC12) nimGCunrefNoCycle(LOC12);
					++result->Sup.len;
					last_101789 += ((NI) 1);
				} LA7: ;
			}
		}
		LA4: ;
	}
	return result;
}

N_NIMCALL(NimStringDesc*, nsuJoinSep)(NimStringDesc** a, NI aLen0, NimStringDesc* sep) {
	NimStringDesc* result;
	result = 0;
	{
		NI L;
		if (!(((NI) 0) < aLen0)) goto LA3;
		L = (NI)((sep ? sep->Sup.len : 0) * (NI)(aLen0 - ((NI) 1)));
		{
			NI i_103247;
			NI HEX3Atmp_103269;
			NI res_103272;
			i_103247 = 0;
			HEX3Atmp_103269 = 0;
			HEX3Atmp_103269 = (aLen0-1);
			res_103272 = ((NI) 0);
			{
				while (1) {
					if (!(res_103272 <= HEX3Atmp_103269)) goto LA7;
					i_103247 = res_103272;
					L += (a[i_103247] ? a[i_103247]->Sup.len : 0);
					res_103272 += ((NI) 1);
				} LA7: ;
			}
		}
		result = rawNewString(((NI) (L)));
		result = resizeString(result, a[((NI) 0)]->Sup.len + 0);
appendString(result, a[((NI) 0)]);
		{
			NI i_103267;
			NI HEX3Atmp_103277;
			NI res_103280;
			i_103267 = 0;
			HEX3Atmp_103277 = 0;
			HEX3Atmp_103277 = (aLen0-1);
			res_103280 = ((NI) 1);
			{
				while (1) {
					if (!(res_103280 <= HEX3Atmp_103277)) goto LA10;
					i_103267 = res_103280;
					result = resizeString(result, sep->Sup.len + 0);
appendString(result, sep);
					result = resizeString(result, a[i_103267]->Sup.len + 0);
appendString(result, a[i_103267]);
					res_103280 += ((NI) 1);
				} LA10: ;
			}
		}
	}
	goto LA1;
	LA3: ;
	{
		result = copyString(((NimStringDesc*) &TMP1379));
	}
	LA1: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nsuEscape)(NimStringDesc* s, NimStringDesc* prefix, NimStringDesc* suffix) {
	NimStringDesc* result;
	result = 0;
	result = rawNewString(((NI) ((NI)((s ? s->Sup.len : 0) + (NI)((NU32)((s ? s->Sup.len : 0)) >> (NU32)(((NI) 2)))))));
	result = resizeString(result, prefix->Sup.len + 0);
appendString(result, prefix);
	{
		NIM_CHAR c_104732;
		NI i_104744;
		NI L_104746;
		c_104732 = 0;
		i_104744 = ((NI) 0);
		L_104746 = (s ? s->Sup.len : 0);
		{
			while (1) {
				if (!(i_104744 < L_104746)) goto LA3;
				c_104732 = s->data[i_104744];
				switch (((NU8)(c_104732))) {
				case 0 ... 31:
				case 128 ... 255:
				{
					NimStringDesc* LOC5;
					result = resizeString(result, 2);
appendString(result, ((NimStringDesc*) &TMP2072));
					LOC5 = 0;
					LOC5 = nsuToHex(((NI64) (((NU8)(c_104732)))), ((NI) 2));
					result = resizeString(result, LOC5->Sup.len + 0);
appendString(result, LOC5);
				}
				break;
				case 92:
				{
					result = resizeString(result, 2);
appendString(result, ((NimStringDesc*) &TMP2073));
				}
				break;
				case 39:
				{
					result = resizeString(result, 2);
appendString(result, ((NimStringDesc*) &TMP2074));
				}
				break;
				case 34:
				{
					result = resizeString(result, 2);
appendString(result, ((NimStringDesc*) &TMP2075));
				}
				break;
				default:
				{
					result = addChar(result, c_104732);
				}
				break;
				}
				i_104744 += ((NI) 1);
			} LA3: ;
		}
	}
	result = resizeString(result, suffix->Sup.len + 0);
appendString(result, suffix);
	return result;
}

N_NIMCALL(void, nsuDelete)(NimStringDesc** s, NI first, NI last) {
	NI i;
	NI j;
	NI newlen;
	i = first;
	j = (NI)(last + ((NI) 1));
	newlen = (NI)((NI)(((*s) ? (*s)->Sup.len : 0) - j) + i);
	{
		while (1) {
			if (!(i < newlen)) goto LA2;
			(*s)->data[i] = (*s)->data[j];
			i += ((NI) 1);
			j += ((NI) 1);
		} LA2: ;
	}
	(*s) = setLengthStr((*s), ((NI) (newlen)));
}

N_NIMCALL(NI, nsuCountLines)(NimStringDesc* s) {
	NI result;
	NI i;
	result = 0;
	i = ((NI) 0);
	{
		while (1) {
			if (!(i < (s ? s->Sup.len : 0))) goto LA2;
			switch (((NU8)(s->data[i]))) {
			case 13:
			{
				{
					if (!((NU8)(s->data[(NI)(i + ((NI) 1))]) == (NU8)(10))) goto LA6;
					i += ((NI) 1);
				}
				LA6: ;
				result += ((NI) 1);
			}
			break;
			case 10:
			{
				result += ((NI) 1);
			}
			break;
			default:
			{
			}
			break;
			}
			i += ((NI) 1);
		} LA2: ;
	}
	return result;
}

N_NIMCALL(NIM_BOOL, nsuContinuesWith)(NimStringDesc* s, NimStringDesc* substr, NI start) {
	NIM_BOOL result;
	NI i;
{	result = 0;
	i = ((NI) 0);
	{
		while (1) {
			{
				if (!((NU8)(substr->data[i]) == (NU8)(0))) goto LA5;
				result = NIM_TRUE;
				goto BeforeRet;
			}
			LA5: ;
			{
				if (!!(((NU8)(s->data[(NI)(i + ((NI) (start)))]) == (NU8)(substr->data[i])))) goto LA9;
				result = NIM_FALSE;
				goto BeforeRet;
			}
			LA9: ;
			i += ((NI) 1);
		}
	}
	}BeforeRet: ;
	return result;
}

static N_INLINE(void, appendChar)(NimStringDesc* dest, NIM_CHAR c) {
	(*dest).data[((*dest).Sup.len)- 0] = c;
	(*dest).data[((NI)((*dest).Sup.len + ((NI) 1)))- 0] = 0;
	(*dest).Sup.len += ((NI) 1);
}

N_NIMCALL(NimStringDesc*, nsuIntToStr)(NI x, NI minchars) {
	NimStringDesc* result;
	result = 0;
	result = nimIntToStr((x > 0? (x) : -(x)));
	{
		NI i_102062;
		NI HEX3Atmp_102064;
		NI res_102067;
		i_102062 = 0;
		HEX3Atmp_102064 = 0;
		HEX3Atmp_102064 = (NI)(((NI) (minchars)) - (result ? result->Sup.len : 0));
		res_102067 = ((NI) 1);
		{
			while (1) {
				NimStringDesc* LOC4;
				if (!(res_102067 <= HEX3Atmp_102064)) goto LA3;
				i_102062 = res_102067;
				LOC4 = 0;
				LOC4 = rawNewString(result->Sup.len + 1);
appendChar(LOC4, 48);
appendString(LOC4, result);
				result = LOC4;
				res_102067 += ((NI) 1);
			} LA3: ;
		}
	}
	{
		NimStringDesc* LOC9;
		if (!(x < ((NI) 0))) goto LA7;
		LOC9 = 0;
		LOC9 = rawNewString(result->Sup.len + 1);
appendChar(LOC9, 45);
appendString(LOC9, result);
		result = LOC9;
	}
	LA7: ;
	return result;
}

N_NIMCALL(NIM_CHAR, nsuToUpperChar)(NIM_CHAR c) {
	NIM_CHAR result;
	result = 0;
	{
		if (!(((NU8)(c)) >= ((NU8)(97)) && ((NU8)(c)) <= ((NU8)(122)))) goto LA3;
		result = ((NIM_CHAR) (((NI) ((NI)(((NI) (((NU8)(c)))) - ((NI) 32))))));
	}
	goto LA1;
	LA3: ;
	{
		result = c;
	}
	LA1: ;
	return result;
}

N_NIMCALL(NimStringDesc*, nsuRepeatStr)(NimStringDesc* s, NI n) {
	NimStringDesc* result;
	result = 0;
	result = rawNewString(((NI) ((NI)(((NI) (n)) * (s ? s->Sup.len : 0)))));
	{
		NI i_102623;
		NI res_102627;
		i_102623 = 0;
		res_102627 = ((NI) 1);
		{
			while (1) {
				if (!(res_102627 <= ((NI) (n)))) goto LA3;
				i_102623 = ((NI) (res_102627));
				result = resizeString(result, s->Sup.len + 0);
appendString(result, s);
				res_102627 += ((NI) 1);
			} LA3: ;
		}
	}
	return result;
}

N_NIMCALL(NimStringDesc*, nsuReplaceChar)(NimStringDesc* s, NIM_CHAR sub, NIM_CHAR by) {
	NimStringDesc* result;
	NI i;
	result = 0;
	result = mnewString(((NI) ((s ? s->Sup.len : 0))));
	i = ((NI) 0);
	{
		while (1) {
			if (!(i < (s ? s->Sup.len : 0))) goto LA2;
			{
				if (!((NU8)(s->data[i]) == (NU8)(sub))) goto LA5;
				result->data[i] = by;
			}
			goto LA3;
			LA5: ;
			{
				result->data[i] = s->data[i];
			}
			LA3: ;
			i += ((NI) 1);
		} LA2: ;
	}
	return result;
}

static N_INLINE(Slice90365, HEX2EHEX2E_105290)(NI a, NI b) {
	Slice90365 result;
	memset((void*)(&result), 0, sizeof(result));
	result.a = a;
	result.b = b;
	return result;
}

N_NIMCALL(NimStringDesc*, nsuformatBiggestFloat)(NF f, NU8 format, NI precision, NIM_CHAR decimalsep) {
	NimStringDesc* result;
	TY105274 frmtstr;
	TY105278 buf;
	int L;
	result = 0;
	L = 0;
	frmtstr[(((NI) 0))- 0] = 37;
	{
		if (!(((NI) 0) < ((NI) (precision)))) goto LA3;
		frmtstr[(((NI) 1))- 0] = 35;
		frmtstr[(((NI) 2))- 0] = 46;
		frmtstr[(((NI) 3))- 0] = 42;
		frmtstr[(((NI) 4))- 0] = floatformattochar_105267[(format)- 0];
		frmtstr[(((NI) 5))- 0] = 0;
		L = sprintf(((NCSTRING) (buf)), ((NCSTRING) (frmtstr)), precision, f);
	}
	goto LA1;
	LA3: ;
	{
		frmtstr[(((NI) 1))- 0] = floatformattochar_105267[(format)- 0];
		frmtstr[(((NI) 2))- 0] = 0;
		L = sprintf(((NCSTRING) (buf)), ((NCSTRING) (frmtstr)), f);
	}
	LA1: ;
	result = mnewString(((NI) (L)));
	{
		NI i_105342;
		Slice90365 HEX3Atmp_105358;
		i_105342 = 0;
		memset((void*)(&HEX3Atmp_105358), 0, sizeof(HEX3Atmp_105358));
		HEX3Atmp_105358 = HEX2EHEX2E_105290(((NI) 0), ((NI) ((L - 1))));
		{
			NI x_105362;
			NI HEX3Atmp_105364;
			NI HEX3Atmp_105366;
			NI res_105368;
			x_105362 = 0;
			HEX3Atmp_105364 = 0;
			HEX3Atmp_105366 = 0;
			HEX3Atmp_105364 = HEX3Atmp_105358.a;
			HEX3Atmp_105366 = HEX3Atmp_105358.b;
			res_105368 = HEX3Atmp_105364;
			{
				while (1) {
					if (!(res_105368 <= HEX3Atmp_105366)) goto LA9;
					x_105362 = res_105368;
					i_105342 = x_105362;
					{
						if (!(((NU8)(buf[(i_105342)- 0])) == ((NU8)(46)) || ((NU8)(buf[(i_105342)- 0])) == ((NU8)(44)))) goto LA12;
						result->data[i_105342] = decimalsep;
					}
					goto LA10;
					LA12: ;
					{
						result->data[i_105342] = buf[(i_105342)- 0];
					}
					LA10: ;
					res_105368 += ((NI) 1);
				} LA9: ;
			}
		}
	}
	return result;
}

N_NIMCALL(NimStringDesc*, nsuformatFloat)(NF f, NU8 format, NI precision, NIM_CHAR decimalsep) {
	NimStringDesc* result;
	result = 0;
	result = nsuformatBiggestFloat(f, format, precision, decimalsep);
	return result;
}

N_NIMCALL(NimStringDesc*, nsuInsertSep)(NimStringDesc* s, NIM_CHAR sep, NI digits) {
	NimStringDesc* result;
	NI L;
	NI j;
	result = 0;
	L = (NI)((NI)((NI)((s ? s->Sup.len : 0) - ((NI) 1)) / digits) + (s ? s->Sup.len : 0));
	result = mnewString(((NI) (L)));
	j = ((NI) 0);
	L -= ((NI) 1);
	{
		NI i_104674;
		NI HEX3Atmp_104703;
		NI res_104706;
		i_104674 = 0;
		HEX3Atmp_104703 = 0;
		HEX3Atmp_104703 = (NI)((s ? s->Sup.len : 0) - ((NI) 1));
		res_104706 = HEX3Atmp_104703;
		{
			while (1) {
				if (!(((NI) 0) <= res_104706)) goto LA3;
				i_104674 = res_104706;
				{
					if (!(j == digits)) goto LA6;
					result->data[L] = sep;
					L -= ((NI) 1);
					j = ((NI) 0);
				}
				LA6: ;
				result->data[L] = s->data[i_104674];
				j += ((NI) 1);
				L -= ((NI) 1);
				res_104706 -= ((NI) 1);
			} LA3: ;
		}
	}
	return result;
}

N_NIMCALL(NimStringDesc*, formatsize_105404)(NI64 bytes, NIM_CHAR decimalsep) {
	NimStringDesc* result;
	NI64 gigabytes;
	NI64 megabytes;
	NI64 kilobytes;
	result = 0;
	gigabytes = (NI64)((NU64)(bytes) >> (NU64)(IL64(30)));
	megabytes = (NI64)((NU64)(bytes) >> (NU64)(IL64(20)));
	kilobytes = (NI64)((NU64)(bytes) >> (NU64)(IL64(10)));
	{
		NimStringDesc* bs_105427;
		NimStringDesc* LOC5;
		NimStringDesc* LOC6;
		NimStringDesc* LOC7;
		NimStringDesc* LOC8;
		if (!!((gigabytes == IL64(0)))) goto LA3;
		bs_105427 = nimInt64ToStr(megabytes);
		LOC5 = 0;
		LOC6 = 0;
		LOC6 = nimInt64ToStr(gigabytes);
		LOC7 = 0;
		LOC7 = nsuInsertSep(LOC6, 95, ((NI) 3));
		LOC8 = 0;
		LOC8 = copyStrLast(bs_105427, ((NI) 0), ((NI) 2));
		LOC5 = rawNewString(LOC7->Sup.len + LOC8->Sup.len + 3);
appendString(LOC5, LOC7);
appendChar(LOC5, decimalsep);
appendString(LOC5, LOC8);
appendString(LOC5, ((NimStringDesc*) &TMP5272));
		result = LOC5;
	}
	goto LA1;
	LA3: ;
	{
		NimStringDesc* bs_105429;
		NimStringDesc* LOC12;
		NimStringDesc* LOC13;
		NimStringDesc* LOC14;
		NimStringDesc* LOC15;
		if (!!((megabytes == IL64(0)))) goto LA10;
		bs_105429 = nimInt64ToStr(kilobytes);
		LOC12 = 0;
		LOC13 = 0;
		LOC13 = nimInt64ToStr(megabytes);
		LOC14 = 0;
		LOC14 = nsuInsertSep(LOC13, 95, ((NI) 3));
		LOC15 = 0;
		LOC15 = copyStrLast(bs_105429, ((NI) 0), ((NI) 2));
		LOC12 = rawNewString(LOC14->Sup.len + LOC15->Sup.len + 3);
appendString(LOC12, LOC14);
appendChar(LOC12, decimalsep);
appendString(LOC12, LOC15);
appendString(LOC12, ((NimStringDesc*) &TMP5273));
		result = LOC12;
	}
	goto LA1;
	LA10: ;
	{
		NimStringDesc* bs_105431;
		NimStringDesc* LOC19;
		NimStringDesc* LOC20;
		NimStringDesc* LOC21;
		NimStringDesc* LOC22;
		if (!!((kilobytes == IL64(0)))) goto LA17;
		bs_105431 = nimInt64ToStr(bytes);
		LOC19 = 0;
		LOC20 = 0;
		LOC20 = nimInt64ToStr(kilobytes);
		LOC21 = 0;
		LOC21 = nsuInsertSep(LOC20, 95, ((NI) 3));
		LOC22 = 0;
		LOC22 = copyStrLast(bs_105431, ((NI) 0), ((NI) 2));
		LOC19 = rawNewString(LOC21->Sup.len + LOC22->Sup.len + 3);
appendString(LOC19, LOC21);
appendChar(LOC19, decimalsep);
appendString(LOC19, LOC22);
appendString(LOC19, ((NimStringDesc*) &TMP5274));
		result = LOC19;
	}
	goto LA1;
	LA17: ;
	{
		NimStringDesc* LOC24;
		NimStringDesc* LOC25;
		NimStringDesc* LOC26;
		LOC24 = 0;
		LOC25 = 0;
		LOC25 = nimInt64ToStr(bytes);
		LOC26 = 0;
		LOC26 = nsuInsertSep(LOC25, 95, ((NI) 3));
		LOC24 = rawNewString(LOC26->Sup.len + 1);
appendString(LOC24, LOC26);
appendString(LOC24, ((NimStringDesc*) &TMP5275));
		result = LOC24;
	}
	LA1: ;
	return result;
}
NIM_EXTERNC N_NOINLINE(void, stdlib_strutilsInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, stdlib_strutilsDatInit000)(void) {
NTI103393.size = sizeof(Skiptable103393);
NTI103393.kind = 16;
NTI103393.base = (&NTI108);
NTI103393.flags = 3;
}

