/* Generated by Nim Compiler v2.2.10 */
#define NIM_INTBITS 64
#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
typedef struct NimStrPayload NimStrPayload;
typedef struct NimStringV2 NimStringV2;
struct NimStrPayload {
	NI cap;
	NIM_CHAR data[SEQ_DECL_SIZE];
};
struct NimStringV2 {
	NI len;
	NimStrPayload* p;
};
N_NIMCALL(NimStringV2, rawNewString)(NI cap_p0);
N_LIB_PRIVATE N_NIMCALL(void, addEscaped__pureZxmltree_u1065)(NimStringV2* result_p0, NimStringV2 s_p1);
static N_INLINE(void, appendString)(NimStringV2* dest_p0, NimStringV2 src_p1);
static N_INLINE(void, copyMem__system_u1742)(void* dest_p0, void* source_p1, NI size_p2);
static N_INLINE(void, nimCopyMem)(void* dest_p0, void* source_p1, NI size_p2);
N_LIB_PRIVATE N_NIMCALL(void, prepareAdd)(NimStringV2* s_p0, NI addLen_p1);
static N_INLINE(void, nimAddCharV1)(NimStringV2* s_p0, NIM_CHAR c_p1);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
static const struct {
  NI cap; NIM_CHAR data[4+1];
} TM__qYyKc6OpDWHHaBXL9bX9aQ2A_2 = { 4 | NIM_STRLIT_FLAG, "&lt;" };
static const NimStringV2 TM__qYyKc6OpDWHHaBXL9bX9aQ2A_3 = {4, (NimStrPayload*)&TM__qYyKc6OpDWHHaBXL9bX9aQ2A_2};
static const struct {
  NI cap; NIM_CHAR data[4+1];
} TM__qYyKc6OpDWHHaBXL9bX9aQ2A_4 = { 4 | NIM_STRLIT_FLAG, "&gt;" };
static const NimStringV2 TM__qYyKc6OpDWHHaBXL9bX9aQ2A_5 = {4, (NimStrPayload*)&TM__qYyKc6OpDWHHaBXL9bX9aQ2A_4};
static const struct {
  NI cap; NIM_CHAR data[5+1];
} TM__qYyKc6OpDWHHaBXL9bX9aQ2A_6 = { 5 | NIM_STRLIT_FLAG, "&amp;" };
static const NimStringV2 TM__qYyKc6OpDWHHaBXL9bX9aQ2A_7 = {5, (NimStrPayload*)&TM__qYyKc6OpDWHHaBXL9bX9aQ2A_6};
static const struct {
  NI cap; NIM_CHAR data[6+1];
} TM__qYyKc6OpDWHHaBXL9bX9aQ2A_8 = { 6 | NIM_STRLIT_FLAG, "&quot;" };
static const NimStringV2 TM__qYyKc6OpDWHHaBXL9bX9aQ2A_9 = {6, (NimStrPayload*)&TM__qYyKc6OpDWHHaBXL9bX9aQ2A_8};
static const struct {
  NI cap; NIM_CHAR data[6+1];
} TM__qYyKc6OpDWHHaBXL9bX9aQ2A_10 = { 6 | NIM_STRLIT_FLAG, "&apos;" };
static const NimStringV2 TM__qYyKc6OpDWHHaBXL9bX9aQ2A_11 = {6, (NimStrPayload*)&TM__qYyKc6OpDWHHaBXL9bX9aQ2A_10};
extern NIM_BOOL nimInErrorMode__system_u4138;
static N_INLINE(void, nimCopyMem)(void* dest_p0, void* source_p1, NI size_p2) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memcpy(dest_p0, source_p1, ((size_t) (size_p2)));
}
static N_INLINE(void, copyMem__system_u1742)(void* dest_p0, void* source_p1, NI size_p2) {
	nimCopyMem(dest_p0, source_p1, size_p2);
}
static N_INLINE(void, appendString)(NimStringV2* dest_p0, NimStringV2 src_p1) {
	{
		if (!(((NI)0) < src_p1.len)) goto LA3_;
		copyMem__system_u1742(((void*) ((&(*(*dest_p0).p).data[(*dest_p0).len]))), ((void*) ((&(*src_p1.p).data[((NI)0)]))), (src_p1.len));
		(*dest_p0).len += src_p1.len;
		(*(*dest_p0).p).data[(*dest_p0).len] = 0;
	}
LA3_: ;
}
static N_INLINE(void, nimAddCharV1)(NimStringV2* s_p0, NIM_CHAR c_p1) {
	prepareAdd(s_p0, ((NI)1));
	(*(*s_p0).p).data[(*s_p0).len] = c_p1;
	(*s_p0).len += ((NI)1);
	(*(*s_p0).p).data[(*s_p0).len] = 0;
}
N_LIB_PRIVATE N_NIMCALL(void, addEscaped__pureZxmltree_u1065)(NimStringV2* result_p0, NimStringV2 s_p1) {
	{
		NIM_CHAR c_1;
		NI i_1;
		NI L_1;
		c_1 = (NIM_CHAR)0;
		i_1 = ((NI)0);
		L_1 = s_p1.len;
		{
			while (1) {
				if (!(i_1 < L_1)) goto LA3;
				c_1 = s_p1.p->data[i_1];
				switch (((NU8)(c_1))) {
				case 60:
				{
					prepareAdd((&(*result_p0)), 4);
appendString((&(*result_p0)), TM__qYyKc6OpDWHHaBXL9bX9aQ2A_3);
				}
				break;
				case 62:
				{
					prepareAdd((&(*result_p0)), 4);
appendString((&(*result_p0)), TM__qYyKc6OpDWHHaBXL9bX9aQ2A_5);
				}
				break;
				case 38:
				{
					prepareAdd((&(*result_p0)), 5);
appendString((&(*result_p0)), TM__qYyKc6OpDWHHaBXL9bX9aQ2A_7);
				}
				break;
				case 34:
				{
					prepareAdd((&(*result_p0)), 6);
appendString((&(*result_p0)), TM__qYyKc6OpDWHHaBXL9bX9aQ2A_9);
				}
				break;
				case 39:
				{
					prepareAdd((&(*result_p0)), 6);
appendString((&(*result_p0)), TM__qYyKc6OpDWHHaBXL9bX9aQ2A_11);
				}
				break;
				default:
				{
					nimAddCharV1((&(*result_p0)), c_1);
				}
				break;
				}
				i_1 += ((NI)1);
			} LA3: ;
		}
	}
}
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (&nimInErrorMode__system_u4138);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, escape__pureZxmltree_u1069)(NimStringV2 s_p0) {
	NimStringV2 result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result.len = 0; result.p = NIM_NIL;
	result = rawNewString((s_p0.len));
	addEscaped__pureZxmltree_u1065((&result), s_p0);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
