/* 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;

/* section: NIM_merge_TYPES */
struct TGenericSeq {
NI len;
NI reserved;
};
struct NimStringDesc {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};

/* section: NIM_merge_PROC_HEADERS */
N_LIB_PRIVATE N_NIMCALL(void, setLen__RERja5IIeMonpTtt9bmLiFg)(NimStringDesc** result, NI n, NIM_BOOL isInit);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, setLengthStr)(NimStringDesc* s, NI newLen);
static N_INLINE(void, zeroMem__FsvhfMqbswETmyMWtamDewsystem)(void* p, NI size);
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);
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(void*, dataPointer__AnU4WGNDB4UiqbYYlJW8wA)(NimStringDesc* a);
static N_INLINE(NIM_BOOL, isUpperAscii__ZJUnX4wT9cnomzZSYoQ6Ngwstrutils2)(NIM_CHAR c);

/* section: NIM_merge_VARS */
extern NIM_BOOL nimInErrorMode__759bT87luu8XGcbkw13FUjA;

/* 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_: ;
}
static N_INLINE(void, zeroMem__FsvhfMqbswETmyMWtamDewsystem)(void* p, NI size) {
	nimZeroMem(p, size);
}
N_LIB_PRIVATE N_NIMCALL(void, setLen__RERja5IIeMonpTtt9bmLiFg)(NimStringDesc** result, NI n, NIM_BOOL isInit) {
	NI n0;
	n0 = ((*result) ? (*result)->Sup.len : 0);
	(*result) = setLengthStr((*result), ((NI) (n)));
	{
		NIM_BOOL T3_;
		void* T7_;
		T3_ = (NIM_BOOL)0;
		T3_ = isInit;
		if (!(T3_)) goto LA4_;
		T3_ = (n0 < n);
		LA4_: ;
		if (!T3_) goto LA5_;
		T7_ = (void*)0;
		T7_ = ((void*) ((&(*result)->data[n0])));
		zeroMem__FsvhfMqbswETmyMWtamDewsystem(T7_, ((NI) ((NI)(n - n0))));
	}
	LA5_: ;
}
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);
}
N_LIB_PRIVATE N_NIMCALL(void*, dataPointer__AnU4WGNDB4UiqbYYlJW8wA)(NimStringDesc* a) {
	void* result;
	result = (void*)0;
	{
		if (!((a ? a->Sup.len : 0) == ((NI) 0))) goto LA3_;
		result = NIM_NIL;
	}
	goto LA1_;
	LA3_: ;
	{
		result = ((void*) ((&a->data[((NI) 0)])));
	}
	LA1_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, forceCopy__9aS5wD8MwJoemnVo59bh54Sg)(NimStringDesc** result, NimStringDesc* a) {
	NI n;
	void* T1_;
	void* T2_;
	void* T3_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	n = (a ? a->Sup.len : 0);
	setLen__RERja5IIeMonpTtt9bmLiFg(result, n, NIM_FALSE);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	T1_ = (void*)0;
	T1_ = dataPointer__AnU4WGNDB4UiqbYYlJW8wA((*result));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	T2_ = (void*)0;
	T2_ = T1_;
	T3_ = (void*)0;
	T3_ = dataPointer__AnU4WGNDB4UiqbYYlJW8wA(a);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	copyMem__i80o3k0SgEI5gTRCzYdyWAsystem(T2_, T3_, ((NI) (n)));
	}BeforeRet_: ;
}
static N_INLINE(NIM_BOOL, isUpperAscii__ZJUnX4wT9cnomzZSYoQ6Ngwstrutils2)(NIM_CHAR c) {
	NIM_BOOL result;
	result = (NIM_BOOL)0;
	result = (((NU8)(c)) >= ((NU8)(65)) && ((NU8)(c)) <= ((NU8)(90)));
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, toLowerAscii__I234FTAl36mfiUP0mS9cMVg)(NimStringDesc** a) {
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	{
		NIM_CHAR* c;
		NI i;
		NI L;
		c = (NIM_CHAR*)0;
		i = ((NI) 0);
		L = ((*a) ? (*a)->Sup.len : 0);
		{
			while (1) {
				NI T4_;
				if (!(i < L)) goto LA3;
				c = (&(*a)->data[i]);
				T4_ = (NI)0;
				{
					NIM_BOOL T7_;
					T7_ = (NIM_BOOL)0;
					T7_ = isUpperAscii__ZJUnX4wT9cnomzZSYoQ6Ngwstrutils2((*c));
					if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
					if (!T7_) goto LA8_;
					T4_ = ((NI) 32);
				}
				goto LA5_;
				LA8_: ;
				{
					T4_ = ((NI) 0);
				}
				LA5_: ;
				(*c) = ((NIM_CHAR) (((NI) ((NI)(((NU8)((*c))) + T4_)))));
				i += ((NI) 1);
			} LA3: ;
		}
	}
	}BeforeRet_: ;
}
