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

/* section: NIM_merge_HEADERS */

#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

/* section: NIM_merge_FRAME_DEFINES */
#define nimfr_(x, y)
#define nimln_(x, y)

/* section: NIM_merge_FORWARD_TYPES */
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw;
typedef struct tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ;
typedef struct tyObject_RtArray__3dAfOhmMnD56kQD3eeo0Lg tyObject_RtArray__3dAfOhmMnD56kQD3eeo0Lg;
typedef struct tySequence__9apztJSmgERYU8fZOjI4pOg tySequence__9apztJSmgERYU8fZOjI4pOg;
typedef struct tyObject_Pcre__bGVj3RgRlNY6kwJpiYI9b3A tyObject_Pcre__bGVj3RgRlNY6kwJpiYI9b3A;
typedef struct tyObject_ExtraData__aRbi7557vgG4KV47nk1CWQ tyObject_ExtraData__aRbi7557vgG4KV47nk1CWQ;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct tyObject_RegexError__eXUKe0yimErFvWt9bGtwijw tyObject_RegexError__eXUKe0yimErFvWt9bGtwijw;
typedef struct tyObject_ValueError__yoNlBGx0D2tRizIdhQuENw tyObject_ValueError__yoNlBGx0D2tRizIdhQuENw;
typedef struct tyObject_CatchableError__qrLSDoe2oBoAqNtJ9badtnA tyObject_CatchableError__qrLSDoe2oBoAqNtJ9badtnA;
typedef struct Exception Exception;
typedef struct RootObj RootObj;
typedef struct tySequence__uB9b75OUPRENsBAu4AnoePA tySequence__uB9b75OUPRENsBAu4AnoePA;
typedef struct tyObject_StackTraceEntry__oLyohQ7O2XOvGnflOss8EA tyObject_StackTraceEntry__oLyohQ7O2XOvGnflOss8EA;

/* section: NIM_merge_TYPES */
struct TGenericSeq {
NI len;
NI reserved;
};
struct NimStringDesc {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ {
NI Field0;
NI Field1;
};
typedef int tyArray__hlIpJIfs8ECqDyETXoMStg[10];
struct tyObject_RtArray__3dAfOhmMnD56kQD3eeo0Lg {
NI L;
tySequence__9apztJSmgERYU8fZOjI4pOg* spart;
tyArray__hlIpJIfs8ECqDyETXoMStg apart;
};
typedef N_CDECL_PTR(int, tyProc__y4Iy0gL1MDnSGVt43uUAgQ) (tyObject_Pcre__bGVj3RgRlNY6kwJpiYI9b3A* code, tyObject_ExtraData__aRbi7557vgG4KV47nk1CWQ* extra, NCSTRING subject, int length, int startoffset, int options, int* ovector, int ovecsize);
struct tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw {
tyObject_Pcre__bGVj3RgRlNY6kwJpiYI9b3A* h;
tyObject_ExtraData__aRbi7557vgG4KV47nk1CWQ* e;
};
typedef NU8 tySet_tyEnum_RegexFlag__gA189bEOtGhLt2cCHGW4ywg;
typedef N_CDECL_PTR(void, tyProc__5cp59bim9aJ4WupX5aVaD1Sg) (NCSTRING stringptr);
typedef N_CDECL_PTR(void, tyProc__hMR3nXvmHGbyZzcDul78bg) (tyObject_ExtraData__aRbi7557vgG4KV47nk1CWQ* extra);
typedef NU8 tyEnum_TNimKind__jIBKr1ejBgsfM33Kxw4j7A;
typedef NU8 tySet_tyEnum_TNimTypeFlag__v8QUszD1sWlSIWZz7mC4bQ;
typedef N_NIMCALL_PTR(void, tyProc__ojoeKfW4VYIm36I9cpDTQIg) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, tyProc__WSm2xU5ARYv9aAR4l0z9c9auQ) (void* p);
struct TNimType {
NI size;
NI align;
tyEnum_TNimKind__jIBKr1ejBgsfM33Kxw4j7A kind;
tySet_tyEnum_TNimTypeFlag__v8QUszD1sWlSIWZz7mC4bQ flags;
TNimType* base;
TNimNode* node;
void* finalizer;
tyProc__ojoeKfW4VYIm36I9cpDTQIg marker;
tyProc__WSm2xU5ARYv9aAR4l0z9c9auQ deepcopy;
};
typedef NU8 tyEnum_TNimNodeKind__unfNsxrcATrufDZmpBq4HQ;
struct TNimNode {
tyEnum_TNimNodeKind__unfNsxrcATrufDZmpBq4HQ kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct tyObject_Pcre__bGVj3RgRlNY6kwJpiYI9b3A {
char dummy;
};
typedef N_CDECL_PTR(tyObject_Pcre__bGVj3RgRlNY6kwJpiYI9b3A*, tyProc__OMNNRjh8IIE9bAc9btZcg0NA) (NCSTRING pattern, int options, NCSTRING* errptr, int* erroffset, void* tableptr);
struct RootObj {
TNimType* m_type;
};
struct Exception {
  RootObj Sup;
Exception* parent;
NCSTRING name;
NimStringDesc* message;
tySequence__uB9b75OUPRENsBAu4AnoePA* trace;
Exception* up;
};
struct tyObject_CatchableError__qrLSDoe2oBoAqNtJ9badtnA {
  Exception Sup;
};
struct tyObject_ValueError__yoNlBGx0D2tRizIdhQuENw {
  tyObject_CatchableError__qrLSDoe2oBoAqNtJ9badtnA Sup;
};
struct tyObject_RegexError__eXUKe0yimErFvWt9bGtwijw {
  tyObject_ValueError__yoNlBGx0D2tRizIdhQuENw Sup;
};
typedef NU8 tyEnum_RegexFlag__gA189bEOtGhLt2cCHGW4ywg;
typedef N_CDECL_PTR(int, tyProc__KqPl2ltkjnSoyb04zAVCAQ) (int what, void* where);
struct tyObject_ExtraData__aRbi7557vgG4KV47nk1CWQ {
long flags;
void* study_data;
long match_limit;
void* callout_data;
void* tables;
long match_limit_recursion;
void* mark;
void* executable_jit;
};
typedef N_CDECL_PTR(tyObject_ExtraData__aRbi7557vgG4KV47nk1CWQ*, tyProc__qU2uMIyWirSwn1Nd4hJjDw) (tyObject_Pcre__bGVj3RgRlNY6kwJpiYI9b3A* code, int options, NCSTRING* errptr);
typedef NimStringDesc* tyArray__Qdg3zgcNlmwGTTeVxyC9bbw[20];
struct tyObject_StackTraceEntry__oLyohQ7O2XOvGnflOss8EA {
NCSTRING procname;
NI line;
NCSTRING filename;
};

/* section: NIM_merge_SEQ_TYPES */
struct tySequence__9apztJSmgERYU8fZOjI4pOg {
  TGenericSeq Sup;
  int data[SEQ_DECL_SIZE];
};
struct tySequence__uB9b75OUPRENsBAu4AnoePA {
  TGenericSeq Sup;
  tyObject_StackTraceEntry__oLyohQ7O2XOvGnflOss8EA data[SEQ_DECL_SIZE];
};

/* section: NIM_merge_PROC_HEADERS */
static N_INLINE(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ, findBounds__ZvBW7oBQW0AL9bVNHeQYhIQre)(NimStringDesc* s, tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw* pattern, NI start);
static N_INLINE(void, nimZeroMem)(void* p, NI size);
static N_INLINE(void, nimSetMem__zxfKBYntu9cBapkhrCOk1fgmemory)(void* a, int v, NI size);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ, findBounds__h9bDVC3slPvpTdoiuHp3Q2A)(NCSTRING buf, tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw* pattern, NI start, NI bufSize);
N_LIB_PRIVATE N_NIMCALL(void, initRtArray__dgRhxurJYSkIc9bzLmhcMfQ)(NI len, tyObject_RtArray__3dAfOhmMnD56kQD3eeo0Lg* Result);
N_LIB_PRIVATE N_NIMCALL(int*, getRawData__P13NCPA0zhaXrvo9bVrTd9bw)(tyObject_RtArray__3dAfOhmMnD56kQD3eeo0Lg* x);
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringDesc* s);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, substr__2yh9cer0ymNRHlOOg8P7IuA)(NimStringDesc* s, NI first, NI last);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
static N_INLINE(void, copyMem__i80o3k0SgEI5gTRCzYdyWAsystem)(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(NimStringDesc*, substr__iGg0RIKceRvsmvq8FUHOEw)(NimStringDesc* s, NI first);
N_LIB_PRIVATE N_NIMCALL(void, finalizeRegEx__4SdnqaehCmfUiW6zxHfMFw)(tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw* x);
static N_NIMCALL(void, Marker_tyRef__dkhOdInu11QXB2HnNpgmJQ)(void* p, NI op);
N_LIB_PRIVATE N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
N_LIB_PRIVATE N_NIMCALL(tyObject_Pcre__bGVj3RgRlNY6kwJpiYI9b3A*, rawCompile__rlKpWhYxks9aCWeSwmjOpCA)(NimStringDesc* pattern, int flags);
N_LIB_PRIVATE N_NOINLINE(void, raiseInvalidRegex__TdB6gTnZgnp1MW3lpWDu3w)(NimStringDesc* msg);
N_LIB_PRIVATE N_NIMCALL(void, nimGCvisit)(void* d, NI op);
static N_NIMCALL(void, Marker_tyRef__9aOkmtaUNuD5bHWcVuLdIoQ)(void* p, NI op);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_LIB_PRIVATE N_NIMCALL(void, raiseExceptionEx)(Exception* e, NCSTRING ename, NCSTRING procname, NCSTRING filename, NI line);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, cstrToNimstr)(NCSTRING str);
static N_INLINE(NimStringDesc*, spaces__rssDy7zs9cDeoYTeCoIy0Wgstrutils)(NI n);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, nsuRepeatChar)(NIM_CHAR c, NI count);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
static N_INLINE(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ, findBounds__ErPsn1xgCi9aXFBAJU0VM3Qre)(NimStringDesc* s, tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw* pattern, NimStringDesc** matches, NI matchesLen_0, NI start);
N_LIB_PRIVATE N_NIMCALL(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ, findBounds__9b9c65p7ndnR5YgK5UQCtsFg)(NCSTRING buf, tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw* pattern, NimStringDesc** matches, NI matchesLen_0, NI start, NI bufSize);
static N_INLINE(NimStringDesc*, bufSubstr__VsoPEEMURtH3vOYlZ89cahwre)(NCSTRING b, NI sPos, NI ePos);
N_NIMCALL(NimStringDesc*, mnewString)(NI len);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, setLengthStr)(NimStringDesc* s, NI newLen);
N_LIB_PRIVATE N_NIMCALL(void, nsuAddf)(NimStringDesc** s, NimStringDesc* formatstr, NimStringDesc** a, NI aLen_0);

/* section: NIM_merge_DATA */
N_LIB_PRIVATE TNimType NTI__jxMAPyr9aBYX9b0g7iZ2E8zw_;
extern TNimType NTI__WH9aVfHDhtZbU6Y5QgauqZQ_;
extern TNimType NTI__z1uZWlkSdiDfd9ahW9a6Ibug_;
N_LIB_PRIVATE TNimType NTI__dkhOdInu11QXB2HnNpgmJQ_;
extern TNimType NTI__yoNlBGx0D2tRizIdhQuENw_;
N_LIB_PRIVATE TNimType NTI__eXUKe0yimErFvWt9bGtwijw_;
N_LIB_PRIVATE TNimType NTI__9aOkmtaUNuD5bHWcVuLdIoQ_;
STRING_LITERAL(TM__EFUBs0zJOEvQ2SEKsixA2w_3, "\012", 1);
STRING_LITERAL(TM__EFUBs0zJOEvQ2SEKsixA2w_4, "^\012", 2);

/* section: NIM_merge_VARS */
extern NIM_THREADVAR NIM_BOOL nimInErrorMode__759bT87luu8XGcbkw13FUjA;
extern tyProc__y4Iy0gL1MDnSGVt43uUAgQ Dl_24812276_;
extern tyProc__5cp59bim9aJ4WupX5aVaD1Sg Dl_24812304_;
extern tyProc__hMR3nXvmHGbyZzcDul78bg Dl_24812371_;
extern tyProc__OMNNRjh8IIE9bAc9btZcg0NA Dl_24812214_;
extern tyProc__KqPl2ltkjnSoyb04zAVCAQ Dl_24812236_;
extern tyProc__qU2uMIyWirSwn1Nd4hJjDw Dl_24812363_;

/* section: NIM_merge_PROCS */
static N_INLINE(void, nimSetMem__zxfKBYntu9cBapkhrCOk1fgmemory)(void* a, int v, NI size) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memset(a, v, ((size_t) (size)));
}
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (NIM_BOOL*)0;
	result = (&nimInErrorMode__759bT87luu8XGcbkw13FUjA);
	return result;
}
static N_INLINE(void, nimZeroMem)(void* p, NI size) {
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	nimSetMem__zxfKBYntu9cBapkhrCOk1fgmemory(p, ((int) 0), size);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ, findBounds__h9bDVC3slPvpTdoiuHp3Q2A)(NCSTRING buf, tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw* pattern, NI start, NI bufSize) {
	tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ result;
	tyObject_RtArray__3dAfOhmMnD56kQD3eeo0Lg rtarray;
	int* rawMatches;
	int res;
	NI colontmp__3;
	NI colontmp__4;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	nimZeroMem((void*)(&result), sizeof(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ));
	nimZeroMem((void*)(&rtarray), sizeof(tyObject_RtArray__3dAfOhmMnD56kQD3eeo0Lg));
	initRtArray__dgRhxurJYSkIc9bzLmhcMfQ(((NI) 3), (&rtarray));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	rawMatches = getRawData__P13NCPA0zhaXrvo9bVrTd9bw((&rtarray));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	res = Dl_24812276_((*pattern).h, (*pattern).e, buf, ((int) (bufSize)), ((int) (start)), ((NI32) 0), ((int*) (rawMatches)), ((int) 3));
	{
		NI colontmp_;
		NI colontmp__2;
		if (!(res < ((NI32) 0))) goto LA3_;
		colontmp_ = ((NI) (res));
		colontmp__2 = ((NI) 0);
		result.Field0 = colontmp_;
		result.Field1 = colontmp__2;
		goto BeforeRet_;
	}
	LA3_: ;
	colontmp__3 = ((NI) (rawMatches[((NI) 0)]));
	colontmp__4 = ((NI) ((NI32)(rawMatches[((NI) 1)] - ((NI32) 1))));
	result.Field0 = colontmp__3;
	result.Field1 = colontmp__4;
	goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringDesc* s) {
	NCSTRING result;
	result = (NCSTRING)0;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = (s == NIM_NIL);
		if (T3_) goto LA4_;
		T3_ = ((*s).Sup.len == ((NI) 0));
		LA4_: ;
		if (!T3_) goto LA5_;
		result = "";
	}
	goto LA1_;
	LA5_: ;
	{
		result = ((NCSTRING) ((*s).data));
	}
	LA1_: ;
	return result;
}
static N_INLINE(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ, findBounds__ZvBW7oBQW0AL9bVNHeQYhIQre)(NimStringDesc* s, tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw* pattern, NI start) {
	tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ result;
	NimStringDesc* T1_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	nimZeroMem((void*)(&result), sizeof(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ));
	T1_ = (NimStringDesc*)0;
	T1_ = s;
	result = findBounds__h9bDVC3slPvpTdoiuHp3Q2A(nimToCStringConv(T1_), pattern, start, (s ? s->Sup.len : 0));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
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__i80o3k0SgEI5gTRCzYdyWAsystem)(void* dest, void* source, NI size) {
	nimCopyMem(dest, source, size);
}
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src) {
	{
		void* T5_;
		void* T6_;
		if (!!((src == NIM_NIL))) goto LA3_;
		T5_ = (void*)0;
		T5_ = ((void*) ((&(*dest).data[(*dest).Sup.len])));
		T6_ = (void*)0;
		T6_ = ((void*) ((*src).data));
		copyMem__i80o3k0SgEI5gTRCzYdyWAsystem(T5_, T6_, ((NI) ((NI)((*src).Sup.len + ((NI) 1)))));
		(*dest).Sup.len += (*src).Sup.len;
	}
	LA3_: ;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, replace__xph9cKzqe9aWKZ0mnKnfmGHg)(NimStringDesc* s, tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw* sub, NimStringDesc* by) {
	NimStringDesc* result;
	NI prev;
	NimStringDesc* T12_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NimStringDesc*)0;
	result = ((NimStringDesc*) NIM_NIL);
	prev = ((NI) 0);
	{
		while (1) {
			tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ match;
			NimStringDesc* T7_;
			if (!(prev < (s ? s->Sup.len : 0))) goto LA2;
			match = findBounds__ZvBW7oBQW0AL9bVNHeQYhIQre(s, sub, prev);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			{
				if (!(match.Field0 < ((NI) 0))) goto LA5_;
				goto LA1;
			}
			LA5_: ;
			T7_ = (NimStringDesc*)0;
			T7_ = substr__2yh9cer0ymNRHlOOg8P7IuA(s, prev, (NI)(match.Field0 - ((NI) 1)));
			result = resizeString(result, (T7_ ? T7_->Sup.len : 0) + 0);
appendString(result, T7_);
			result = resizeString(result, (by ? by->Sup.len : 0) + 0);
appendString(result, by);
			{
				if (!((NI)(match.Field1 + ((NI) 1)) == prev)) goto LA10_;
				goto LA1;
			}
			LA10_: ;
			prev = (NI)(match.Field1 + ((NI) 1));
		} LA2: ;
	} LA1: ;
	T12_ = (NimStringDesc*)0;
	T12_ = substr__iGg0RIKceRvsmvq8FUHOEw(s, prev);
	result = resizeString(result, (T12_ ? T12_->Sup.len : 0) + 0);
appendString(result, T12_);
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, finalizeRegEx__4SdnqaehCmfUiW6zxHfMFw)(tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw* x) {
	Dl_24812304_(((NCSTRING) ((*x).h)));
	{
		if (!!(((*x).e == 0))) goto LA3_;
		Dl_24812371_((*x).e);
	}
	LA3_: ;
}
static N_NIMCALL(void, Marker_tyRef__dkhOdInu11QXB2HnNpgmJQ)(void* p, NI op) {
	tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw* a;
	a = (tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw*)p;
}
static N_NIMCALL(void, Marker_tyRef__9aOkmtaUNuD5bHWcVuLdIoQ)(void* p, NI op) {
	tyObject_RegexError__eXUKe0yimErFvWt9bGtwijw* a;
	a = (tyObject_RegexError__eXUKe0yimErFvWt9bGtwijw*)p;
	nimGCvisit((void*)(*a).Sup.Sup.Sup.parent, op);
	nimGCvisit((void*)(*a).Sup.Sup.Sup.message, op);
	nimGCvisit((void*)(*a).Sup.Sup.Sup.trace, op);
	nimGCvisit((void*)(*a).Sup.Sup.Sup.up, op);
}
N_LIB_PRIVATE N_NOINLINE(void, raiseInvalidRegex__TdB6gTnZgnp1MW3lpWDu3w)(NimStringDesc* msg) {
	tyObject_RegexError__eXUKe0yimErFvWt9bGtwijw* e;
{	e = (tyObject_RegexError__eXUKe0yimErFvWt9bGtwijw*)0;
	e = (tyObject_RegexError__eXUKe0yimErFvWt9bGtwijw*) newObj((&NTI__9aOkmtaUNuD5bHWcVuLdIoQ_), sizeof(tyObject_RegexError__eXUKe0yimErFvWt9bGtwijw));
	(*e).Sup.Sup.Sup.Sup.m_type = (&NTI__eXUKe0yimErFvWt9bGtwijw_);
	(*e).Sup.Sup.Sup.name = "RegexError";
	(*e).Sup.Sup.Sup.message = copyString(msg);
	raiseExceptionEx((Exception*)e, "RegexError", "raiseInvalidRegex", "re.nim", 70);
	goto BeforeRet_;
	}BeforeRet_: ;
}
static N_INLINE(NimStringDesc*, spaces__rssDy7zs9cDeoYTeCoIy0Wgstrutils)(NI n) {
	NimStringDesc* result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NimStringDesc*)0;
	result = nsuRepeatChar(32, n);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(tyObject_Pcre__bGVj3RgRlNY6kwJpiYI9b3A*, rawCompile__rlKpWhYxks9aCWeSwmjOpCA)(NimStringDesc* pattern, int flags) {
	tyObject_Pcre__bGVj3RgRlNY6kwJpiYI9b3A* result;
	NCSTRING msg;
	int offset;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (tyObject_Pcre__bGVj3RgRlNY6kwJpiYI9b3A*)0;
	msg = "";
	offset = ((int) 0);
	result = Dl_24812214_(nimToCStringConv(pattern), flags, (&msg), (&offset), NIM_NIL);
	{
		NimStringDesc* T5_;
		NimStringDesc* T6_;
		NimStringDesc* T7_;
		if (!(result == NIM_NIL)) goto LA3_;
		T5_ = (NimStringDesc*)0;
		T6_ = (NimStringDesc*)0;
		T6_ = cstrToNimstr(msg);
		T7_ = (NimStringDesc*)0;
		T7_ = spaces__rssDy7zs9cDeoYTeCoIy0Wgstrutils(((NI) (offset)));
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		T5_ = rawNewString((T6_ ? T6_->Sup.len : 0) + (pattern ? pattern->Sup.len : 0) + (T7_ ? T7_->Sup.len : 0) + 4);
appendString(T5_, T6_);
appendString(T5_, ((NimStringDesc*) &TM__EFUBs0zJOEvQ2SEKsixA2w_3));
appendString(T5_, pattern);
appendString(T5_, ((NimStringDesc*) &TM__EFUBs0zJOEvQ2SEKsixA2w_3));
appendString(T5_, T7_);
appendString(T5_, ((NimStringDesc*) &TM__EFUBs0zJOEvQ2SEKsixA2w_4));
		raiseInvalidRegex__TdB6gTnZgnp1MW3lpWDu3w(T5_);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	LA3_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw*, re__BHdoI8AriYxT9bGXrX9c7EhQ)(NimStringDesc* s, tySet_tyEnum_RegexFlag__gA189bEOtGhLt2cCHGW4ywg flags) {
	tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw* result;
	tyObject_Pcre__bGVj3RgRlNY6kwJpiYI9b3A* T1_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw*)0;
	result = (tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw*) newObj((&NTI__dkhOdInu11QXB2HnNpgmJQ_), sizeof(tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw));
	T1_ = (tyObject_Pcre__bGVj3RgRlNY6kwJpiYI9b3A*)0;
	T1_ = rawCompile__rlKpWhYxks9aCWeSwmjOpCA(s, ((int) ((flags & ~ 16))));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	(*result).h = T1_;
	{
		NCSTRING msg;
		int options;
		int hasJit;
		if (!((flags &(1U<<((NU)(((tyEnum_RegexFlag__gA189bEOtGhLt2cCHGW4ywg) 4))&7U)))!=0)) goto LA4_;
		msg = "";
		options = ((int) 0);
		hasJit = ((int) 0);
		{
			int T8_;
			T8_ = (int)0;
			T8_ = Dl_24812236_(((int) 9), ((void*) ((&hasJit))));
			if (!(T8_ == ((NI32) 0))) goto LA9_;
			{
				if (!(hasJit == ((NI32) 1))) goto LA13_;
				options = ((int) 1);
			}
			LA13_: ;
		}
		LA9_: ;
		(*result).e = Dl_24812363_((*result).h, options, (&msg));
		{
			NimStringDesc* T19_;
			if (!!((msg == 0))) goto LA17_;
			T19_ = (NimStringDesc*)0;
			T19_ = cstrToNimstr(msg);
			raiseInvalidRegex__TdB6gTnZgnp1MW3lpWDu3w(T19_);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		}
		LA17_: ;
	}
	LA4_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(int, matchOrFind__jpcUBS27e6bot0QabDwvkw)(NCSTRING buf, tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw* pattern, NI start, NI bufSize, int flags) {
	int result;
	tyObject_RtArray__3dAfOhmMnD56kQD3eeo0Lg rtarray;
	int* rawMatches;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (int)0;
	nimZeroMem((void*)(&rtarray), sizeof(tyObject_RtArray__3dAfOhmMnD56kQD3eeo0Lg));
	initRtArray__dgRhxurJYSkIc9bzLmhcMfQ(((NI) 3), (&rtarray));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	rawMatches = getRawData__P13NCPA0zhaXrvo9bVrTd9bw((&rtarray));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	result = Dl_24812276_((*pattern).h, (*pattern).e, buf, ((int) (bufSize)), ((int) (start)), flags, ((int*) (rawMatches)), ((int) 3));
	{
		if (!(((NI32) 0) <= result)) goto LA3_;
		result = (NI32)(rawMatches[((NI) 1)] - rawMatches[((NI) 0)]);
	}
	LA3_: ;
	}BeforeRet_: ;
	return result;
}
static N_INLINE(NimStringDesc*, bufSubstr__VsoPEEMURtH3vOYlZ89cahwre)(NCSTRING b, NI sPos, NI ePos) {
	NimStringDesc* result;
	NI sz;
	result = (NimStringDesc*)0;
	sz = (NI)(ePos - sPos);
	result = mnewString(((NI) ((NI)(sz + ((NI) 1)))));
	copyMem__i80o3k0SgEI5gTRCzYdyWAsystem(((void*) ((&result->data[((NI) 0)]))), ((void*) ((&b[sPos]))), ((NI) (sz)));
	result = setLengthStr(result, ((NI) (sz)));
	return result;
}
N_LIB_PRIVATE N_NIMCALL(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ, findBounds__9b9c65p7ndnR5YgK5UQCtsFg)(NCSTRING buf, tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw* pattern, NimStringDesc** matches, NI matchesLen_0, NI start, NI bufSize) {
	tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ result;
	tyObject_RtArray__3dAfOhmMnD56kQD3eeo0Lg rtarray;
	int* rawMatches;
	int res;
	NI colontmp__4;
	NI colontmp__5;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	nimZeroMem((void*)(&result), sizeof(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ));
	nimZeroMem((void*)(&rtarray), sizeof(tyObject_RtArray__3dAfOhmMnD56kQD3eeo0Lg));
	initRtArray__dgRhxurJYSkIc9bzLmhcMfQ(((NI) ((NI)((NI)(matchesLen_0 + ((NI) 1)) * ((NI) 3)))), (&rtarray));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	rawMatches = getRawData__P13NCPA0zhaXrvo9bVrTd9bw((&rtarray));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	res = Dl_24812276_((*pattern).h, (*pattern).e, buf, ((int) (bufSize)), ((int) (start)), ((NI32) 0), ((int*) (rawMatches)), (NI32)(((int) ((NI)(matchesLen_0 + ((NI) 1)))) * ((NI32) 3)));
	{
		NI colontmp_;
		NI colontmp__2;
		if (!(res < ((NI32) 0))) goto LA3_;
		colontmp_ = ((NI) -1);
		colontmp__2 = ((NI) 0);
		result.Field0 = colontmp_;
		result.Field1 = colontmp__2;
		goto BeforeRet_;
	}
	LA3_: ;
	{
		NI i;
		NI colontmp__3;
		NI res_2;
		i = (NI)0;
		colontmp__3 = (NI)0;
		colontmp__3 = (NI)(((NI) (res)) - ((NI) 1));
		res_2 = ((NI) 1);
		{
			while (1) {
				int a;
				int b;
				if (!(res_2 <= colontmp__3)) goto LA7;
				i = res_2;
				a = rawMatches[(NI)(i * ((NI) 2))];
				b = rawMatches[(NI)((NI)(i * ((NI) 2)) + ((NI) 1))];
				{
					NimStringDesc* T12_;
					if (!(((NI32) 0) <= a)) goto LA10_;
					T12_ = (NimStringDesc*)0;
					T12_ = bufSubstr__VsoPEEMURtH3vOYlZ89cahwre(buf, ((NI) (a)), ((NI) (b)));
					if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
					matches[(NI)(i - ((NI) 1))] = T12_;
				}
				goto LA8_;
				LA10_: ;
				{
					matches[(NI)(i - ((NI) 1))] = ((NimStringDesc*) NIM_NIL);
				}
				LA8_: ;
				res_2 += ((NI) 1);
			} LA7: ;
		}
	}
	colontmp__4 = ((NI) (rawMatches[((NI) 0)]));
	colontmp__5 = (NI)(((NI) (rawMatches[((NI) 1)])) - ((NI) 1));
	result.Field0 = colontmp__4;
	result.Field1 = colontmp__5;
	goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
static N_INLINE(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ, findBounds__ErPsn1xgCi9aXFBAJU0VM3Qre)(NimStringDesc* s, tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw* pattern, NimStringDesc** matches, NI matchesLen_0, NI start) {
	tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ result;
	NimStringDesc* T1_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	nimZeroMem((void*)(&result), sizeof(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ));
	T1_ = (NimStringDesc*)0;
	T1_ = s;
	result = findBounds__9b9c65p7ndnR5YgK5UQCtsFg(nimToCStringConv(T1_), pattern, matches, matchesLen_0, start, (s ? s->Sup.len : 0));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, replacef__xph9cKzqe9aWKZ0mnKnfmGHg_2)(NimStringDesc* s, tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw* sub, NimStringDesc* by) {
	NimStringDesc* result;
	tyArray__Qdg3zgcNlmwGTTeVxyC9bbw caps;
	NI prev;
	NimStringDesc* T12_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NimStringDesc*)0;
	result = ((NimStringDesc*) NIM_NIL);
	nimZeroMem((void*)caps, sizeof(tyArray__Qdg3zgcNlmwGTTeVxyC9bbw));
	prev = ((NI) 0);
	{
		while (1) {
			tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ match;
			NimStringDesc* T7_;
			if (!(prev < (s ? s->Sup.len : 0))) goto LA2;
			match = findBounds__ErPsn1xgCi9aXFBAJU0VM3Qre(s, sub, caps, 20, prev);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			{
				if (!(match.Field0 < ((NI) 0))) goto LA5_;
				goto LA1;
			}
			LA5_: ;
			T7_ = (NimStringDesc*)0;
			T7_ = substr__2yh9cer0ymNRHlOOg8P7IuA(s, prev, (NI)(match.Field0 - ((NI) 1)));
			result = resizeString(result, (T7_ ? T7_->Sup.len : 0) + 0);
appendString(result, T7_);
			nsuAddf((&result), by, caps, 20);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			{
				if (!((NI)(match.Field1 + ((NI) 1)) == prev)) goto LA10_;
				goto LA1;
			}
			LA10_: ;
			prev = (NI)(match.Field1 + ((NI) 1));
		} LA2: ;
	} LA1: ;
	T12_ = (NimStringDesc*)0;
	T12_ = substr__iGg0RIKceRvsmvq8FUHOEw(s, prev);
	result = resizeString(result, (T12_ ? T12_->Sup.len : 0) + 0);
appendString(result, T12_);
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, stdlib_reDatInit000)(void) {

/* section: NIM_merge_TYPE_INIT1 */
static TNimNode* TM__EFUBs0zJOEvQ2SEKsixA2w_2_2[2];
static TNimNode TM__EFUBs0zJOEvQ2SEKsixA2w_0[4];

/* section: NIM_merge_TYPE_INIT3 */
NTI__jxMAPyr9aBYX9b0g7iZ2E8zw_.size = sizeof(tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw);
NTI__jxMAPyr9aBYX9b0g7iZ2E8zw_.align = NIM_ALIGNOF(tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw);
NTI__jxMAPyr9aBYX9b0g7iZ2E8zw_.kind = 18;
NTI__jxMAPyr9aBYX9b0g7iZ2E8zw_.base = 0;
NTI__jxMAPyr9aBYX9b0g7iZ2E8zw_.flags = 3;
TM__EFUBs0zJOEvQ2SEKsixA2w_2_2[0] = &TM__EFUBs0zJOEvQ2SEKsixA2w_0[1];
TM__EFUBs0zJOEvQ2SEKsixA2w_0[1].kind = 1;
TM__EFUBs0zJOEvQ2SEKsixA2w_0[1].offset = offsetof(tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw, h);
TM__EFUBs0zJOEvQ2SEKsixA2w_0[1].typ = (&NTI__WH9aVfHDhtZbU6Y5QgauqZQ_);
TM__EFUBs0zJOEvQ2SEKsixA2w_0[1].name = "h";
TM__EFUBs0zJOEvQ2SEKsixA2w_2_2[1] = &TM__EFUBs0zJOEvQ2SEKsixA2w_0[2];
TM__EFUBs0zJOEvQ2SEKsixA2w_0[2].kind = 1;
TM__EFUBs0zJOEvQ2SEKsixA2w_0[2].offset = offsetof(tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw, e);
TM__EFUBs0zJOEvQ2SEKsixA2w_0[2].typ = (&NTI__z1uZWlkSdiDfd9ahW9a6Ibug_);
TM__EFUBs0zJOEvQ2SEKsixA2w_0[2].name = "e";
TM__EFUBs0zJOEvQ2SEKsixA2w_0[0].len = 2; TM__EFUBs0zJOEvQ2SEKsixA2w_0[0].kind = 2; TM__EFUBs0zJOEvQ2SEKsixA2w_0[0].sons = &TM__EFUBs0zJOEvQ2SEKsixA2w_2_2[0];
NTI__jxMAPyr9aBYX9b0g7iZ2E8zw_.node = &TM__EFUBs0zJOEvQ2SEKsixA2w_0[0];
NTI__dkhOdInu11QXB2HnNpgmJQ_.size = sizeof(tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw*);
NTI__dkhOdInu11QXB2HnNpgmJQ_.align = NIM_ALIGNOF(tyObject_RegexDesc__jxMAPyr9aBYX9b0g7iZ2E8zw*);
NTI__dkhOdInu11QXB2HnNpgmJQ_.kind = 22;
NTI__dkhOdInu11QXB2HnNpgmJQ_.base = (&NTI__jxMAPyr9aBYX9b0g7iZ2E8zw_);
NTI__dkhOdInu11QXB2HnNpgmJQ_.flags = 2;
NTI__dkhOdInu11QXB2HnNpgmJQ_.marker = Marker_tyRef__dkhOdInu11QXB2HnNpgmJQ;
(&NTI__dkhOdInu11QXB2HnNpgmJQ_)->finalizer = (void*)finalizeRegEx__4SdnqaehCmfUiW6zxHfMFw;
NTI__eXUKe0yimErFvWt9bGtwijw_.size = sizeof(tyObject_RegexError__eXUKe0yimErFvWt9bGtwijw);
NTI__eXUKe0yimErFvWt9bGtwijw_.align = NIM_ALIGNOF(tyObject_RegexError__eXUKe0yimErFvWt9bGtwijw);
NTI__eXUKe0yimErFvWt9bGtwijw_.kind = 17;
NTI__eXUKe0yimErFvWt9bGtwijw_.base = (&NTI__yoNlBGx0D2tRizIdhQuENw_);
TM__EFUBs0zJOEvQ2SEKsixA2w_0[3].len = 0; TM__EFUBs0zJOEvQ2SEKsixA2w_0[3].kind = 2;
NTI__eXUKe0yimErFvWt9bGtwijw_.node = &TM__EFUBs0zJOEvQ2SEKsixA2w_0[3];
NTI__9aOkmtaUNuD5bHWcVuLdIoQ_.size = sizeof(tyObject_RegexError__eXUKe0yimErFvWt9bGtwijw*);
NTI__9aOkmtaUNuD5bHWcVuLdIoQ_.align = NIM_ALIGNOF(tyObject_RegexError__eXUKe0yimErFvWt9bGtwijw*);
NTI__9aOkmtaUNuD5bHWcVuLdIoQ_.kind = 22;
NTI__9aOkmtaUNuD5bHWcVuLdIoQ_.base = (&NTI__eXUKe0yimErFvWt9bGtwijw_);
NTI__9aOkmtaUNuD5bHWcVuLdIoQ_.marker = Marker_tyRef__9aOkmtaUNuD5bHWcVuLdIoQ;
}

