/* Generated by Nim Compiler v2.2.10 */
#define NIM_INTBITS 64

#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_LIB_PRIVATE N_NIMCALL(NimStringV2, alignString__pureZstrformat_u19)(NimStringV2 s_p0, NI minimumWidth_p1, NIM_CHAR align_p2, NIM_CHAR fill_p3);
N_LIB_PRIVATE N_NIMCALL(void, eqcopy___system_u2694)(NimStringV2* dest_p0, NimStringV2 src_p1);
static N_INLINE(NI, validateUtf8__pureZunicode_u7337)(NimStringV2 s_p0);
N_LIB_PRIVATE N_NIMCALL(NI, validateUtf8__pureZunicode_u342)(NIM_CHAR* s_p0, NI s_p0Len_0);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
static N_INLINE(NI, runeLen__pureZunicode_u7165)(NimStringV2 s_p0);
N_LIB_PRIVATE N_NIMCALL(NI, nucruneLen)(NIM_CHAR* s_p0, NI s_p0Len_0);
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, nsuRepeatChar)(NIM_CHAR c_p0, NI count_p1);
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, prepareAdd)(NimStringV2* s_p0, NI addLen_p1);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, dollar___systemZdollars_u9)(NI xX60gensym0__p0);
extern NIM_BOOL nimInErrorMode__system_u4146;
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (&nimInErrorMode__system_u4146);
	return result;
}
static N_INLINE(NI, validateUtf8__pureZunicode_u7337)(NimStringV2 s_p0) {
	NI result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NI)0;
	result = validateUtf8__pureZunicode_u342((((s_p0).p) ? ((NIM_CHAR*)s_p0.p->data+(((NI)0))) : NIM_NIL), ((s_p0.len-1))-(((NI)0))+1);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
static N_INLINE(NI, runeLen__pureZunicode_u7165)(NimStringV2 s_p0) {
	NI result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NI)0;
	result = nucruneLen((((s_p0).p) ? ((NIM_CHAR*)s_p0.p->data+(((NI)0))) : NIM_NIL), ((s_p0.len-1))-(((NI)0))+1);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
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_: ;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, alignString__pureZstrformat_u19)(NimStringV2 s_p0, NI minimumWidth_p1, NIM_CHAR align_p2, NIM_CHAR fill_p3) {
	NimStringV2 result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result.len = 0; result.p = NIM_NIL;
	{
		if (!(minimumWidth_p1 == ((NI)0))) goto LA3_;
		eqcopy___system_u2694((&result), s_p0);
	}
	goto LA1_;
LA3_: ;
	{
		NI colontmpD_;
		NI colontmpD__2;
		NI sRuneLen_1;
		NI toFill_1;
		colontmpD_ = (NI)0;
		colontmpD__2 = (NI)0;
		{
			NI T8_;
			T8_ = (NI)0;
			T8_ = validateUtf8__pureZunicode_u7337(s_p0);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			if (!(T8_ == ((NI)-1))) goto LA9_;
			colontmpD_ = runeLen__pureZunicode_u7165(s_p0);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			sRuneLen_1 = colontmpD_;
		}
		goto LA6_;
LA9_: ;
		{
			colontmpD__2 = s_p0.len;
			sRuneLen_1 = colontmpD__2;
		}
LA6_: ;
		toFill_1 = (NI)(minimumWidth_p1 - sRuneLen_1);
		{
			if (!(toFill_1 <= ((NI)0))) goto LA14_;
			eqcopy___system_u2694((&result), s_p0);
		}
		goto LA12_;
LA14_: ;
		{
			NIM_BOOL T17_;
			NimStringV2 colontmpD__3;
			NimStringV2 T21_;
			T17_ = (NIM_BOOL)0;
			T17_ = ((NU8)(align_p2) == (NU8)(60));
			if (T17_) goto LA18_;
			T17_ = ((NU8)(align_p2) == (NU8)(0));
LA18_: ;
			if (!T17_) goto LA19_;
			colontmpD__3.len = 0; colontmpD__3.p = NIM_NIL;
			T21_.len = 0; T21_.p = NIM_NIL;
			colontmpD__3 = nsuRepeatChar(fill_p3, (toFill_1));
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			T21_ = rawNewString(s_p0.len + colontmpD__3.len + 0);
appendString((&T21_), s_p0);
appendString((&T21_), colontmpD__3);
			result = T21_;
			eqdestroy___system_u2691(colontmpD__3);
		}
		goto LA12_;
LA19_: ;
		{
			NimStringV2 colontmpD__4;
			NimStringV2 colontmpD__5;
			NI half_1;
			NimStringV2 T25_;
			if (!((NU8)(align_p2) == (NU8)(94))) goto LA23_;
			colontmpD__4.len = 0; colontmpD__4.p = NIM_NIL;
			colontmpD__5.len = 0; colontmpD__5.p = NIM_NIL;
			half_1 = (NI)(toFill_1 / ((NI)2));
			T25_.len = 0; T25_.p = NIM_NIL;
			colontmpD__4 = nsuRepeatChar(fill_p3, (half_1));
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			colontmpD__5 = nsuRepeatChar(fill_p3, ((NI)(toFill_1 - half_1)));
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			T25_ = rawNewString(colontmpD__4.len + s_p0.len + colontmpD__5.len + 0);
appendString((&T25_), colontmpD__4);
appendString((&T25_), s_p0);
appendString((&T25_), colontmpD__5);
			result = T25_;
			eqdestroy___system_u2691(colontmpD__5);
			eqdestroy___system_u2691(colontmpD__4);
		}
		goto LA12_;
LA23_: ;
		{
			NimStringV2 colontmpD__6;
			NimStringV2 T27_;
			colontmpD__6.len = 0; colontmpD__6.p = NIM_NIL;
			T27_.len = 0; T27_.p = NIM_NIL;
			colontmpD__6 = nsuRepeatChar(fill_p3, (toFill_1));
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			T27_ = rawNewString(colontmpD__6.len + s_p0.len + 0);
appendString((&T27_), colontmpD__6);
appendString((&T27_), s_p0);
			result = T27_;
			eqdestroy___system_u2691(colontmpD__6);
		}
LA12_: ;
	}
LA1_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, formatValue__pureZterminal_u266)(NimStringV2* result_p0, NimStringV2 value_p1) {
	NimStringV2 value_2;
	NimStringV2 colontmpD_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	value_2.len = 0; value_2.p = NIM_NIL;
	colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
	value_2 = value_p1;
	colontmpD_ = alignString__pureZstrformat_u19(value_2, ((NI)0), 0, 32);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	prepareAdd((&(*result_p0)), colontmpD_.len + 0);
appendString((&(*result_p0)), colontmpD_);
	eqdestroy___system_u2691(colontmpD_);
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(void, formatValue__pureZterminal_u279)(NimStringV2* result_p0, NI value_p1) {
	NimStringV2 colontmpD_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
	colontmpD_ = dollar___systemZdollars_u9(value_p1);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	prepareAdd((&(*result_p0)), colontmpD_.len + 0);
appendString((&(*result_p0)), colontmpD_);
	eqdestroy___system_u2691(colontmpD_);
	}BeforeRet_: ;
}
