/* Generated by Nim Compiler v1.2.4 */
/*   (c) 2020 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 32
#define NIM_EmulateOverflowChecks

#include "nimbase.h"
#include <string.h>
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
#define nimfr_(x, y)
#define nimln_(x, y)
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
struct TGenericSeq {
NI len;
NI reserved;
};
struct NimStringDesc {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
N_NIMCALL(NimStringDesc*, rawNewString)(NI cap);
N_LIB_PRIVATE N_NOINLINE(void, raiseRangeErrorI)(NI64 i, NI64 a, NI64 b);
N_LIB_PRIVATE N_NIMCALL(void, addEscaped__6C2AvGe9brWF3cZheLyMXgA)(NimStringDesc** result, NimStringDesc* s);
N_LIB_PRIVATE N_NOINLINE(void, raiseIndexError2)(NI i, NI n);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
static N_INLINE(void, copyMem__M04YC71iJg1N7gBF3HZTngsystem)(void* dest, void* source, NI size);
static N_INLINE(void, nimCopyMem)(void* dest, void* source, NI size);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, resizeString)(NimStringDesc* dest, NI addlen);
N_LIB_PRIVATE N_NIMCALL(void, unsureAsgnRef)(void** dest, void* src);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, addChar)(NimStringDesc* s, NIM_CHAR c);
static N_INLINE(NIM_BOOL, nimAddInt)(NI a, NI b, NI* res);
N_LIB_PRIVATE N_NOINLINE(void, raiseOverflow)(void);
N_LIB_PRIVATE N_NIMCALL(void, failedAssertImpl__W9cjVocn1tjhW7p7xohJj6A)(NimStringDesc* msg);
STRING_LITERAL(TM__qYyKc6OpDWHHaBXL9bX9aQ2A_2, "&lt;", 4);
STRING_LITERAL(TM__qYyKc6OpDWHHaBXL9bX9aQ2A_3, "&gt;", 4);
STRING_LITERAL(TM__qYyKc6OpDWHHaBXL9bX9aQ2A_4, "&amp;", 5);
STRING_LITERAL(TM__qYyKc6OpDWHHaBXL9bX9aQ2A_5, "&quot;", 6);
STRING_LITERAL(TM__qYyKc6OpDWHHaBXL9bX9aQ2A_6, "&apos;", 6);
STRING_LITERAL(TM__qYyKc6OpDWHHaBXL9bX9aQ2A_8, "iterators.nim(207, 11) `len(a) == L` the length of the string c"
"hanged while iterating over it", 93);
static N_INLINE(void, nimCopyMem)(void* dest, void* source, NI size) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memcpy(dest, source, ((size_t) (size)));
}
static N_INLINE(void, copyMem__M04YC71iJg1N7gBF3HZTngsystem)(void* dest, void* source, NI size) {
	nimCopyMem(dest, source, size);
}
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src) {
	{
		if (!!((src == NIM_NIL))) goto LA3_;
		copyMem__M04YC71iJg1N7gBF3HZTngsystem(((void*) ((&(*dest).data[(*dest).Sup.len]))), ((void*) ((*src).data)), ((NI) ((NI)((*src).Sup.len + ((NI) 1)))));
		(*dest).Sup.len += (*src).Sup.len;
	}
	LA3_: ;
}
static N_INLINE(NIM_BOOL, nimAddInt)(NI a, NI b, NI* res) {
	NIM_BOOL result;
	NI r;
	result = (NIM_BOOL)0;
	r = ((NI) ((NU)((NU32)(((NU) (a))) + (NU32)(((NU) (b))))));
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = (((NI) 0) <= (NI)(r ^ a));
		if (T3_) goto LA4_;
		T3_ = (((NI) 0) <= (NI)(r ^ b));
		LA4_: ;
		if (!T3_) goto LA5_;
		(*res) = r;
	}
	goto LA1_;
	LA5_: ;
	{
		result = NIM_TRUE;
	}
	LA1_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, addEscaped__6C2AvGe9brWF3cZheLyMXgA)(NimStringDesc** result, NimStringDesc* s) {
	{
		NIM_CHAR c;
		NI i;
		NI L;
		c = (NIM_CHAR)0;
		i = ((NI) 0);
		L = (s ? s->Sup.len : 0);
		{
			while (1) {
				NI TM__qYyKc6OpDWHHaBXL9bX9aQ2A_7;
				if (!(i < L)) goto LA3;
				if ((NU)(i) >= (NU)(s ? s->Sup.len : 0)){ raiseIndexError2(i,(s ? s->Sup.len : 0)-1); }
				c = s->data[i];
				switch (((NU8)(c))) {
				case 60:
				{
					unsureAsgnRef((void**) (&(*result)), resizeString((*result), 4));
appendString((*result), ((NimStringDesc*) &TM__qYyKc6OpDWHHaBXL9bX9aQ2A_2));
				}
				break;
				case 62:
				{
					unsureAsgnRef((void**) (&(*result)), resizeString((*result), 4));
appendString((*result), ((NimStringDesc*) &TM__qYyKc6OpDWHHaBXL9bX9aQ2A_3));
				}
				break;
				case 38:
				{
					unsureAsgnRef((void**) (&(*result)), resizeString((*result), 5));
appendString((*result), ((NimStringDesc*) &TM__qYyKc6OpDWHHaBXL9bX9aQ2A_4));
				}
				break;
				case 34:
				{
					unsureAsgnRef((void**) (&(*result)), resizeString((*result), 6));
appendString((*result), ((NimStringDesc*) &TM__qYyKc6OpDWHHaBXL9bX9aQ2A_5));
				}
				break;
				case 39:
				{
					unsureAsgnRef((void**) (&(*result)), resizeString((*result), 6));
appendString((*result), ((NimStringDesc*) &TM__qYyKc6OpDWHHaBXL9bX9aQ2A_6));
				}
				break;
				default:
				{
					unsureAsgnRef((void**) (&(*result)), addChar((*result), c));
				}
				break;
				}
				if (nimAddInt(i, ((NI) 1), &TM__qYyKc6OpDWHHaBXL9bX9aQ2A_7)) { raiseOverflow(); };
				i = (NI)(TM__qYyKc6OpDWHHaBXL9bX9aQ2A_7);
				{
					if (!!(((s ? s->Sup.len : 0) == L))) goto LA12_;
					failedAssertImpl__W9cjVocn1tjhW7p7xohJj6A(((NimStringDesc*) &TM__qYyKc6OpDWHHaBXL9bX9aQ2A_8));
				}
				LA12_: ;
			} LA3: ;
		}
	}
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, escape__MqjZ9c9b479ayFgA5h9aAscAFA)(NimStringDesc* s) {
	NimStringDesc* result;
	result = (NimStringDesc*)0;
	if (((s ? s->Sup.len : 0)) < ((NI) 0) || ((s ? s->Sup.len : 0)) > ((NI) 2147483647)){ raiseRangeErrorI((s ? s->Sup.len : 0), ((NI) 0), ((NI) 2147483647)); }
	result = rawNewString(((NI) ((s ? s->Sup.len : 0))));
	addEscaped__6C2AvGe9brWF3cZheLyMXgA((&result), s);
	return result;
}
