/* Generated by Nimrod Compiler v0.9.5 */
/*   (c) 2014 Andreas Rumpf */
/* The generated code is subject to the original license. */
/* Compiled for: Linux, i386, gcc */
/* Command for C compiler:
   gcc -c  -w -O3 -fno-strict-aliasing  -I/build/nimrod/src/nimrod/lib -o compiler/nimcache/rodutils.o compiler/nimcache/rodutils.c */
#define NIM_INTBITS 32
#include "nimbase.h"

#include <string.h>
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef NIM_CHAR TY196024[81];
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(void, hexchar_196064)(NIM_CHAR c, NI* xi);
N_NIMCALL(NimStringDesc*, addChar)(NimStringDesc* s, NIM_CHAR c);
N_NIMCALL(void, encodevintaux_196231)(NI x, NimStringDesc** result);
N_NIMCALL(NimStringDesc*, cstrToNimstr)(NCSTRING str);
static N_INLINE(void, appendChar)(NimStringDesc* dest, NIM_CHAR c);
N_NIMCALL(NimStringDesc*, nsuToHex)(NI64 x, NI len);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(NimStringDesc*, resizeString)(NimStringDesc* dest, NI addlen);
N_NIMCALL(void, encodevbiggestintaux_196198)(NI64 x, NimStringDesc** result);
STRING_LITERAL(TMP1746, "", 0);
STRING_LITERAL(TMP1766, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 62);
STRING_LITERAL(TMP3297, "NAN", 3);
STRING_LITERAL(TMP3298, "0.0", 3);
STRING_LITERAL(TMP3299, "INF", 3);
STRING_LITERAL(TMP3300, "-INF", 4);

N_NIMCALL(NI, decodevint_196305)(NCSTRING s, NI* pos) {
	NI result;
	NI i_196312;
	NI sign_196314;
	result = 0;
	i_196312 = (*pos);
	sign_196314 = -1;
	{
		if (!((NU8)(s[i_196312]) == (NU8)(45))) goto LA3;
		i_196312 += 1;
		sign_196314 = 1;
	}
	LA3: ;
	result = 0;
	while (1) {
		switch (((NU8)(s[i_196312]))) {
		case 48 ... 57:
		{
			result = (NI32)((NI32)(result * 190) - ((NI) ((NI32)(((NI) (((NU8)(s[i_196312])))) - 48))));
		}
		break;
		case 97 ... 122:
		{
			result = (NI32)((NI32)(result * 190) - ((NI) ((NI32)(((NI) ((NI32)(((NI) (((NU8)(s[i_196312])))) - 97))) + 10))));
		}
		break;
		case 65 ... 90:
		{
			result = (NI32)((NI32)(result * 190) - ((NI) ((NI32)(((NI) ((NI32)(((NI) (((NU8)(s[i_196312])))) - 65))) + 36))));
		}
		break;
		case 128 ... 255:
		{
			result = (NI32)((NI32)(result * 190) - ((NI) ((NI32)(((NI) ((NI32)(((NI) (((NU8)(s[i_196312])))) - 128))) + 62))));
		}
		break;
		default:
		{
			goto LA5;
		}
		break;
		}
		i_196312 += 1;
	} LA5: ;
	result = (NI)((NU32)((NI32)(result * sign_196314)) - (NU32)(5));
	(*pos) = i_196312;
	return result;
}

N_NIMCALL(void, hexchar_196064)(NIM_CHAR c, NI* xi) {
	switch (((NU8)(c))) {
	case 48 ... 57:
	{
		(*xi) = (NI)((NI)((NU32)((*xi)) << (NU32)(4)) | ((NI) ((NI32)(((NI) (((NU8)(c)))) - 48))));
	}
	break;
	case 97 ... 102:
	{
		(*xi) = (NI)((NI)((NU32)((*xi)) << (NU32)(4)) | ((NI) ((NI32)(((NI) ((NI32)(((NI) (((NU8)(c)))) - 97))) + 10))));
	}
	break;
	case 65 ... 70:
	{
		(*xi) = (NI)((NI)((NU32)((*xi)) << (NU32)(4)) | ((NI) ((NI32)(((NI) ((NI32)(((NI) (((NU8)(c)))) - 65))) + 10))));
	}
	break;
	default:
	{
	}
	break;
	}
}

N_NIMCALL(NimStringDesc*, decodestr_196126)(NCSTRING s, NI* pos) {
	NimStringDesc* result;
	NI i;
	result = 0;
	i = (*pos);
	result = copyString(((NimStringDesc*) &TMP1746));
	while (1) {
		switch (((NU8)(s[i]))) {
		case 92:
		{
			NI xi;
			i += 3;
			xi = 0;
			hexchar_196064(s[(NI32)(i - 2)], &xi);
			hexchar_196064(s[(NI32)(i - 1)], &xi);
			result = addChar(result, ((NIM_CHAR) (((NI) (xi)))));
		}
		break;
		case 97 ... 122:
		case 65 ... 90:
		case 48 ... 57:
		case 95:
		{
			result = addChar(result, s[i]);
			i += 1;
		}
		break;
		default:
		{
			goto LA1;
		}
		break;
		}
	} LA1: ;
	(*pos) = i;
	return result;
}

N_NIMCALL(void, encodevintaux_196231)(NI x, NimStringDesc** result) {
	NIM_CHAR d_196237;
	NI v_196239;
	NI rem_196241;
	NI idx_196243;
	d_196237 = 0;
	v_196239 = x;
	rem_196241 = (NI32)(v_196239 % 190);
	{
		if (!(((NI) (rem_196241)) < 0)) goto LA3;
		(*result) = addChar((*result), 45);
		v_196239 = ((NI32)-((NI32)(v_196239 / 190)));
		rem_196241 = ((NI32)-(((NI) (rem_196241))));
	}
	goto LA1;
	LA3: ;
	{
		v_196239 = (NI32)(v_196239 / 190);
	}
	LA1: ;
	idx_196243 = ((NI) (rem_196241));
	{
		if (!(idx_196243 < 62)) goto LA8;
		d_196237 = ((NimStringDesc*) &TMP1766)->data[idx_196243];
	}
	goto LA6;
	LA8: ;
	{
		d_196237 = ((NIM_CHAR) (((NI) ((NI32)((NI32)(idx_196243 - 62) + 128)))));
	}
	LA6: ;
	{
		if (!!((v_196239 == 0))) goto LA13;
		encodevintaux_196231(v_196239, result);
	}
	LA13: ;
	(*result) = addChar((*result), d_196237);
}

N_NIMCALL(void, encodevint_196256)(NI x, NimStringDesc** result) {
	encodevintaux_196231((NI)((NU32)(x) + (NU32)(5)), result);
}

N_NIMCALL(NI64, decodevbiggestint_196516)(NCSTRING s, NI* pos) {
	NI64 result;
	NI i_196523;
	NI sign_196525;
	result = 0;
	i_196523 = (*pos);
	sign_196525 = -1;
	{
		if (!((NU8)(s[i_196523]) == (NU8)(45))) goto LA3;
		i_196523 += 1;
		sign_196525 = 1;
	}
	LA3: ;
	result = 0;
	while (1) {
		switch (((NU8)(s[i_196523]))) {
		case 48 ... 57:
		{
			result = (NI64)((NI64)(result * 190) - ((NI64) ((NI32)(((NI) (((NU8)(s[i_196523])))) - 48))));
		}
		break;
		case 97 ... 122:
		{
			result = (NI64)((NI64)(result * 190) - ((NI64) ((NI32)(((NI) ((NI32)(((NI) (((NU8)(s[i_196523])))) - 97))) + 10))));
		}
		break;
		case 65 ... 90:
		{
			result = (NI64)((NI64)(result * 190) - ((NI64) ((NI32)(((NI) ((NI32)(((NI) (((NU8)(s[i_196523])))) - 65))) + 36))));
		}
		break;
		case 128 ... 255:
		{
			result = (NI64)((NI64)(result * 190) - ((NI64) ((NI32)(((NI) ((NI32)(((NI) (((NU8)(s[i_196523])))) - 128))) + 62))));
		}
		break;
		default:
		{
			goto LA5;
		}
		break;
		}
		i_196523 += 1;
	} LA5: ;
	result = (NI64)((NU64)((NI64)(result * ((NI64) (sign_196525)))) - (NU64)(5));
	(*pos) = i_196523;
	return result;
}

N_NIMCALL(NimStringDesc*, tostrmaxprecision_196017)(NF f) {
	NimStringDesc* result;
	result = 0;
	{
		if (!!((f == f))) goto LA3;
		result = copyString(((NimStringDesc*) &TMP3297));
	}
	goto LA1;
	LA3: ;
	{
		if (!(f == 0.0)) goto LA6;
		result = copyString(((NimStringDesc*) &TMP3298));
	}
	goto LA1;
	LA6: ;
	{
		if (!(f == ((NF)(5.0000000000000000e-01) * (NF)(f)))) goto LA9;
		{
			if (!(0.0 < f)) goto LA13;
			result = copyString(((NimStringDesc*) &TMP3299));
		}
		goto LA11;
		LA13: ;
		{
			result = copyString(((NimStringDesc*) &TMP3300));
		}
		LA11: ;
	}
	goto LA1;
	LA9: ;
	{
		TY196024 buf;
		memset((void*)buf, 0, sizeof(buf));
		sprintf(((NCSTRING) (buf)), "%#.16e", f);
		result = cstrToNimstr(((NCSTRING) (buf)));
	}
	LA1: ;
	return result;
}

static N_INLINE(void, appendChar)(NimStringDesc* dest, NIM_CHAR c) {
	(*dest).data[((*dest).Sup.len)- 0] = c;
	(*dest).data[((NI32)((*dest).Sup.len + 1))- 0] = 0;
	(*dest).Sup.len += 1;
}

static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src) {
	memcpy(((NCSTRING) (&(*dest).data[((*dest).Sup.len)- 0])), ((NCSTRING) ((*src).data)), (NI32)((*src).Sup.len + 1));
	(*dest).Sup.len += (*src).Sup.len;
}

N_NIMCALL(void, encodestr_196031)(NimStringDesc* s, NimStringDesc** result) {
	NI i_196048;
	NI HEX3Atmp_196057;
	NI res_196059;
	i_196048 = 0;
	HEX3Atmp_196057 = 0;
	HEX3Atmp_196057 = (NI32)(s->Sup.len - 1);
	res_196059 = 0;
	while (1) {
		if (!(res_196059 <= HEX3Atmp_196057)) goto LA1;
		i_196048 = res_196059;
		switch (((NU8)(s->data[i_196048]))) {
		case 97 ... 122:
		case 65 ... 90:
		case 48 ... 57:
		case 95:
		{
			(*result) = addChar((*result), s->data[i_196048]);
		}
		break;
		default:
		{
			NimStringDesc* LOC4;
			NimStringDesc* LOC5;
			LOC4 = 0;
			LOC5 = 0;
			LOC5 = nsuToHex(((NI64) (((NU8)(s->data[i_196048])))), 2);
			LOC4 = rawNewString(LOC5->Sup.len + 1);
appendChar(LOC4, 92);
appendString(LOC4, LOC5);
			(*result) = resizeString((*result), LOC4->Sup.len + 0);
appendString((*result), LOC4);
		}
		break;
		}
		res_196059 += 1;
	} LA1: ;
}

N_NIMCALL(void, encodevbiggestintaux_196198)(NI64 x, NimStringDesc** result) {
	NIM_CHAR d_196204;
	NI64 v_196206;
	NI64 rem_196208;
	NI idx_196210;
	d_196204 = 0;
	v_196206 = x;
	rem_196208 = (NI64)(v_196206 % 190);
	{
		if (!(((NI) (rem_196208)) < 0)) goto LA3;
		(*result) = addChar((*result), 45);
		v_196206 = -((NI64)(v_196206 / 190));
		rem_196208 = -(((NI64) (rem_196208)));
	}
	goto LA1;
	LA3: ;
	{
		v_196206 = (NI64)(v_196206 / 190);
	}
	LA1: ;
	idx_196210 = ((NI) (rem_196208));
	{
		if (!(idx_196210 < 62)) goto LA8;
		d_196204 = ((NimStringDesc*) &TMP1766)->data[idx_196210];
	}
	goto LA6;
	LA8: ;
	{
		d_196204 = ((NIM_CHAR) (((NI) ((NI32)((NI32)(idx_196210 - 62) + 128)))));
	}
	LA6: ;
	{
		if (!!((v_196206 == 0))) goto LA13;
		encodevbiggestintaux_196198(v_196206, result);
	}
	LA13: ;
	(*result) = addChar((*result), d_196204);
}

N_NIMCALL(void, encodevbiggestint_196224)(NI64 x, NimStringDesc** result) {
	encodevbiggestintaux_196198((NI64)((NU64)(x) + (NU64)(5)), result);
}
N_NOINLINE(void, rodutilsInit)(void) {
}

N_NOINLINE(void, rodutilsDatInit)(void) {
}

