/* 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;
typedef struct tySequence__sM4lkSb7zS6F7OVMvW9cffQ tySequence__sM4lkSb7zS6F7OVMvW9cffQ;
typedef struct tySequence__sM4lkSb7zS6F7OVMvW9cffQ_Content tySequence__sM4lkSb7zS6F7OVMvW9cffQ_Content;
struct NimStrPayload {
	NI cap;
	NIM_CHAR data[SEQ_DECL_SIZE];
};
struct NimStringV2 {
	NI len;
	NimStrPayload* p;
};
struct tySequence__sM4lkSb7zS6F7OVMvW9cffQ {
  NI len; tySequence__sM4lkSb7zS6F7OVMvW9cffQ_Content* p;
};
struct tySequence__sM4lkSb7zS6F7OVMvW9cffQ_Content { NI cap; NimStringV2 data[SEQ_DECL_SIZE]; };
N_LIB_PRIVATE N_NIMCALL(NI, nsuFindChar)(NimStringV2 s_p0, NIM_CHAR sub_p1, NI start_p2, NI last_p3);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, substr__system_u8680)(NimStringV2 s_p0, NI first_p1, NI last_p2);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, substr__system_u8693)(NimStringV2 s_p0, NI first_p1);
N_LIB_PRIVATE N_NIMCALL(void, eqsink___system_u2700)(NimStringV2* dest_p0, NimStringV2 src_p1);
N_LIB_PRIVATE N_NIMCALL(void, libCandidates__pureZdynlib_u81)(NimStringV2 s_p0, tySequence__sM4lkSb7zS6F7OVMvW9cffQ* dest_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(NimStringV2, rawNewString)(NI space_p0);
N_LIB_PRIVATE N_NIMCALL(void, eqdestroy___system_u2691)(NimStringV2 dest_p0);
N_LIB_PRIVATE N_NIMCALL(void, add__stdZenumutils_u71)(tySequence__sM4lkSb7zS6F7OVMvW9cffQ* x_p0, NimStringV2 y_p1);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, eqdup___system_u2697)(NimStringV2 src_p0);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
extern NIM_BOOL nimInErrorMode__system_u4143;
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(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (&nimInErrorMode__system_u4143);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, libCandidates__pureZdynlib_u81)(NimStringV2 s_p0, tySequence__sM4lkSb7zS6F7OVMvW9cffQ* dest_p1) {
	NI le_1;
	NI ri_1;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	le_1 = nsuFindChar(s_p0, 40, ((NI)0), ((NI)-1));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	ri_1 = nsuFindChar(s_p0, 41, ((NI)(le_1 + ((NI)1))), ((NI)-1));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	{
		NIM_BOOL T3_;
		NimStringV2 prefix_1;
		NimStringV2 suffix_1;
		T3_ = (NIM_BOOL)0;
		T3_ = (((NI)0) <= le_1);
		if (!(T3_)) goto LA4_;
		T3_ = (le_1 < ri_1);
LA4_: ;
		if (!T3_) goto LA5_;
		prefix_1.len = 0; prefix_1.p = NIM_NIL;
		suffix_1.len = 0; suffix_1.p = NIM_NIL;
		prefix_1 = substr__system_u8680(s_p0, ((NI)0), (NI)(le_1 - ((NI)1)));
		suffix_1 = substr__system_u8693(s_p0, (NI)(ri_1 + ((NI)1)));
		{
			NimStringV2 middle_1;
			NimStringV2 colontmp_;
			NI lastX60gensym34__1;
			NI splitsX60gensym34__1;
			middle_1.len = 0; middle_1.p = NIM_NIL;
			colontmp_.len = 0; colontmp_.p = NIM_NIL;
			colontmp_ = substr__system_u8680(s_p0, (NI)(le_1 + ((NI)1)), (NI)(ri_1 - ((NI)1)));
			lastX60gensym34__1 = ((NI)0);
			splitsX60gensym34__1 = ((NI)-1);
			{
				while (1) {
					NimStringV2 colontmpD_;
					NI firstX60gensym34__1;
					NimStringV2 T21_;
					NimStringV2 T22_;
					if (!(lastX60gensym34__1 <= colontmp_.len)) goto LA11;
					colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
					firstX60gensym34__1 = lastX60gensym34__1;
					{
						while (1) {
							NIM_BOOL T15_;
							T15_ = (NIM_BOOL)0;
							T15_ = (lastX60gensym34__1 < colontmp_.len);
							if (!(T15_)) goto LA16_;
							T15_ = !(((NU8)(colontmp_.p->data[lastX60gensym34__1]) == (NU8)(124)));
LA16_: ;
							if (!T15_) goto LA14;
							lastX60gensym34__1 += ((NI)1);
						} LA14: ;
					}
					{
						if (!(splitsX60gensym34__1 == ((NI)0))) goto LA19_;
						lastX60gensym34__1 = colontmp_.len;
					}
LA19_: ;
					T21_.len = 0; T21_.p = NIM_NIL;
					T21_ = substr__system_u8680(colontmp_, firstX60gensym34__1, (NI)(lastX60gensym34__1 - ((NI)1)));
					eqsink___system_u2700((&middle_1), T21_);
					T22_.len = 0; T22_.p = NIM_NIL;
					T22_ = rawNewString(prefix_1.len + middle_1.len + suffix_1.len + 0);
appendString((&T22_), prefix_1);
appendString((&T22_), middle_1);
appendString((&T22_), suffix_1);
					colontmpD_ = T22_;
					libCandidates__pureZdynlib_u81(colontmpD_, dest_p1);
					if (NIM_UNLIKELY(*nimErr_)) goto LA12_;
					{
						if (!(splitsX60gensym34__1 == ((NI)0))) goto LA25_;
						eqdestroy___system_u2691(colontmpD_);
						goto LA10;
					}
LA25_: ;
					splitsX60gensym34__1 -= ((NI)1);
					lastX60gensym34__1 += ((NI)1);
					{
						LA12_:;
					}
					{
						eqdestroy___system_u2691(colontmpD_);
					}
					if (NIM_UNLIKELY(*nimErr_)) goto LA9_;
				} LA11: ;
			} LA10: ;
			{
				LA9_:;
			}
			{
				eqdestroy___system_u2691(colontmp_);
				eqdestroy___system_u2691(middle_1);
			}
			if (NIM_UNLIKELY(*nimErr_)) goto LA7_;
		}
		{
			LA7_:;
		}
		{
			eqdestroy___system_u2691(suffix_1);
			eqdestroy___system_u2691(prefix_1);
		}
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	goto LA1_;
LA5_: ;
	{
		NimStringV2 colontmpD__2;
		colontmpD__2 = eqdup___system_u2697(s_p0);
		add__stdZenumutils_u71((&(*dest_p1)), colontmpD__2);
	}
LA1_: ;
	}BeforeRet_: ;
}
