/* Generated by Nim Compiler v2.2.10 */
/* Compiled for: MacOSX, arm64, clang */
/* Command for C compiler:
   clang -c  -w -ferror-limit=3 -fno-strict-aliasing -pthread -isysroot /Applications/Xcode_16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -target arm64-apple-darwin24.2.0 -O3   -I/Users/runner/work/nightlies/nightlies/nim-2.2.10/lib -I/Users/runner/work/nightlies/nightlies/nim-2.2.10/dist/atlas/src -o /Users/runner/work/nightlies/nightlies/nim-2.2.10/dist/atlas/.nimcache/@pstrformat.nim.c.o /Users/runner/work/nightlies/nightlies/nim-2.2.10/dist/atlas/.nimcache/@pstrformat.nim.c */
#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_LIB_PRIVATE N_NIMCALL(NimStringV2, alignString__pureZstrformat_u20)(NimStringV2 s_p0, NI minimumWidth_p1, NIM_CHAR align_p2, NIM_CHAR fill_p3);
N_LIB_PRIVATE N_NIMCALL(void, eqcopy___system_u2754)(NimStringV2* dest_p0, NimStringV2 src_p1);
static N_INLINE(NI, validateUtf8__pureZunicode_u7339)(NimStringV2 s_p0);
N_LIB_PRIVATE N_NIMCALL(NI, validateUtf8__pureZunicode_u342)(NIM_CHAR* s_p0, NI s_p0Len_0);
N_LIB_PRIVATE N_NOINLINE(void, raiseIndexError4)(NI l1_p0, NI h1_p1, NI h2_p2);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
static N_INLINE(NI, runeLen__pureZunicode_u7167)(NimStringV2 s_p0);
N_LIB_PRIVATE N_NIMCALL(NI, nucruneLen)(NIM_CHAR* s_p0, NI s_p0Len_0);
static N_INLINE(NIM_BOOL, nimSubInt)(NI a_p0, NI b_p1, NI* res_p2);
N_LIB_PRIVATE N_NOINLINE(void, raiseOverflow)(void);
static N_INLINE(void, appendString)(NimStringV2* dest_p0, NimStringV2 src_p1);
static N_INLINE(void, copyMem__system_u1755)(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_NOINLINE(void, raiseRangeErrorI)(NI64 i_p0, NI64 a_p1, NI64 b_p2);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, rawNewString)(NI space_p0);
N_LIB_PRIVATE N_NOCONV(void, deallocShared)(void* p_p0);
N_LIB_PRIVATE N_NIMCALL(void, prepareAdd)(NimStringV2* s_p0, NI addLen_p1);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, dollar___systemZdollars_u14)(NI xX60gensym0__p0);
extern NIM_THREADVAR NIM_BOOL nimInErrorMode__system_u4198;
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (&nimInErrorMode__system_u4198);
	return result;
}
static N_INLINE(NI, validateUtf8__pureZunicode_u7339)(NimStringV2 s_p0) {
	NI result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NI)0;
	if ((s_p0.len-1)-((NI)0) != -1 && (((NI)0) < 0 || ((NI)0) >= s_p0.len || (s_p0.len-1) < 0 || (s_p0.len-1) >= s_p0.len)){ raiseIndexError4(((NI)0), (s_p0.len-1), s_p0.len); goto BeforeRet_;
	}
	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_u7167)(NimStringV2 s_p0) {
	NI result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NI)0;
	if ((s_p0.len-1)-((NI)0) != -1 && (((NI)0) < 0 || ((NI)0) >= s_p0.len || (s_p0.len-1) < 0 || (s_p0.len-1) >= s_p0.len)){ raiseIndexError4(((NI)0), (s_p0.len-1), s_p0.len); goto BeforeRet_;
	}
	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(NIM_BOOL, nimSubInt)(NI a_p0, NI b_p1, NI* res_p2) {
	NIM_BOOL result;
	NI r_1;
	result = (NIM_BOOL)0;
	r_1 = ((NI) ((NU)((NU64)(((NU) (a_p0))) - (NU64)(((NU) (b_p1))))));
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = (((NI)0) <= (NI)(r_1 ^ a_p0));
		if (T3_) goto LA4_;
		T3_ = (((NI)0) <= (NI)(r_1 ^ (NI)((NU64) ~(b_p1))));
LA4_: ;
		if (!T3_) goto LA5_;
		(*res_p2) = r_1;
	}
	goto LA1_;
LA5_: ;
	{
		result = NIM_TRUE;
	}
LA1_: ;
	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_u1755)(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_u1755(((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_u20)(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_u2754((&result), s_p0);
	}
	goto LA1_;
LA3_: ;
	{
		NI colontmpD_;
		NI colontmpD__2;
		NI sRuneLen_1;
		NI toFill_1;
		NI TM__qDXzsifTQdn8ucTam9cFp4w_2;
		colontmpD_ = (NI)0;
		colontmpD__2 = (NI)0;
		{
			NI T8_;
			T8_ = (NI)0;
			T8_ = validateUtf8__pureZunicode_u7339(s_p0);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			if (!(T8_ == ((NI)-1))) goto LA9_;
			colontmpD_ = runeLen__pureZunicode_u7167(s_p0);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			sRuneLen_1 = colontmpD_;
		}
		goto LA6_;
LA9_: ;
		{
			colontmpD__2 = s_p0.len;
			sRuneLen_1 = colontmpD__2;
		}
LA6_: ;
		if (nimSubInt(minimumWidth_p1, sRuneLen_1, &TM__qDXzsifTQdn8ucTam9cFp4w_2)) { raiseOverflow(); goto BeforeRet_;
		};
		toFill_1 = (NI)(TM__qDXzsifTQdn8ucTam9cFp4w_2);
		{
			if (!(toFill_1 <= ((NI)0))) goto LA14_;
			eqcopy___system_u2754((&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;
			if ((toFill_1) < ((NI)0) || (toFill_1) > ((NI)IL64(9223372036854775807))){ raiseRangeErrorI(toFill_1, ((NI)0), ((NI)IL64(9223372036854775807))); goto BeforeRet_;
			}
			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_;
			if (colontmpD__3.p && !(colontmpD__3.p->cap & NIM_STRLIT_FLAG)) {
 deallocShared(colontmpD__3.p);
}
		}
		goto LA12_;
LA19_: ;
		{
			NimStringV2 colontmpD__4;
			NimStringV2 colontmpD__5;
			NI half_1;
			NimStringV2 T25_;
			NI TM__qDXzsifTQdn8ucTam9cFp4w_3;
			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;
			if ((half_1) < ((NI)0) || (half_1) > ((NI)IL64(9223372036854775807))){ raiseRangeErrorI(half_1, ((NI)0), ((NI)IL64(9223372036854775807))); goto BeforeRet_;
			}
			colontmpD__4 = nsuRepeatChar(fill_p3, (half_1));
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			if (nimSubInt(toFill_1, half_1, &TM__qDXzsifTQdn8ucTam9cFp4w_3)) { raiseOverflow(); goto BeforeRet_;
			};
			if (((NI)(TM__qDXzsifTQdn8ucTam9cFp4w_3)) < ((NI)0) || ((NI)(TM__qDXzsifTQdn8ucTam9cFp4w_3)) > ((NI)IL64(9223372036854775807))){ raiseRangeErrorI((NI)(TM__qDXzsifTQdn8ucTam9cFp4w_3), ((NI)0), ((NI)IL64(9223372036854775807))); goto BeforeRet_;
			}
			colontmpD__5 = nsuRepeatChar(fill_p3, ((NI)(TM__qDXzsifTQdn8ucTam9cFp4w_3)));
			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_;
			if (colontmpD__5.p && !(colontmpD__5.p->cap & NIM_STRLIT_FLAG)) {
 deallocShared(colontmpD__5.p);
}
			if (colontmpD__4.p && !(colontmpD__4.p->cap & NIM_STRLIT_FLAG)) {
 deallocShared(colontmpD__4.p);
}
		}
		goto LA12_;
LA23_: ;
		{
			NimStringV2 colontmpD__6;
			NimStringV2 T27_;
			colontmpD__6.len = 0; colontmpD__6.p = NIM_NIL;
			T27_.len = 0; T27_.p = NIM_NIL;
			if ((toFill_1) < ((NI)0) || (toFill_1) > ((NI)IL64(9223372036854775807))){ raiseRangeErrorI(toFill_1, ((NI)0), ((NI)IL64(9223372036854775807))); goto BeforeRet_;
			}
			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_;
			if (colontmpD__6.p && !(colontmpD__6.p->cap & NIM_STRLIT_FLAG)) {
 deallocShared(colontmpD__6.p);
}
		}
LA12_: ;
	}
LA1_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, formatValue__pureZterminal_u264)(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_u20(value_2, ((NI)0), 0, 32);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	prepareAdd((&(*result_p0)), colontmpD_.len + 0);
appendString((&(*result_p0)), colontmpD_);
	if (colontmpD_.p && !(colontmpD_.p->cap & NIM_STRLIT_FLAG)) {
 deallocShared(colontmpD_.p);
}
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(void, formatValue__pureZterminal_u277)(NimStringV2* result_p0, NI value_p1) {
	NimStringV2 colontmpD_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
	colontmpD_ = dollar___systemZdollars_u14(value_p1);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	prepareAdd((&(*result_p0)), colontmpD_.len + 0);
appendString((&(*result_p0)), colontmpD_);
	if (colontmpD_.p && !(colontmpD_.p->cap & NIM_STRLIT_FLAG)) {
 deallocShared(colontmpD_.p);
}
	}BeforeRet_: ;
}
