/* Generated by Nim Compiler v0.12.0 */
/*   (c) 2015 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 64

#include "nimbase.h"
#include <stdio.h>
#include <string.h>
typedef struct Tidobj198015 Tidobj198015;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef NimStringDesc* TY192421[1];
typedef N_NIMCALL_PTR(void, TY3889) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3894) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3889 marker;
TY3894 deepcopy;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  Tidobj198015  {
  TNimObject Sup;
NI id;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
N_NIMCALL(NIM_BOOL, open_17003)(FILE** f, NimStringDesc* filename, NU8 mode, NI bufsize);
N_NIMCALL(NimStringDesc*, togid_224462)(NimStringDesc* f);
N_NIMCALL(NimStringDesc*, completegeneratedfilepath_168201)(NimStringDesc* f, NIM_BOOL createsubdir);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(NimStringDesc*, rawNewString)(NI cap);
N_NIMCALL(NIM_BOOL, readline_17119)(FILE* f, NimStringDesc** line);
N_NIMCALL(NI, nsuParseInt)(NimStringDesc* s);
N_NIMCALL(FILE*, open_17017)(NimStringDesc* filename, NU8 mode, NI bufsize);
static N_INLINE(void, writeline_168405)(FILE* f, NimStringDesc** x, NI xLen0);
N_NIMCALL(void, write_17095)(FILE* f, NimStringDesc* s);
N_NIMCALL(NimStringDesc*, nimIntToStr)(NI x);
STRING_LITERAL(TMP1524, "nimrod.gid", 10);
STRING_LITERAL(TMP4516, "\012", 1);
NI gfrontendid_224012;
NI gbackendid_224013;

N_NIMCALL(void, registerid_224201)(Tidobj198015* id) {
}

N_NIMCALL(NimStringDesc*, togid_224462)(NimStringDesc* f) {
	NimStringDesc* result;
	result = 0;
	result = completegeneratedfilepath_168201(((NimStringDesc*) &TMP1524), NIM_TRUE);
	return result;
}

N_NIMCALL(void, loadmaxids_224506)(NimStringDesc* project) {
	FILE* f;
	f = 0;
	{
		NimStringDesc* LOC3;
		NIM_BOOL LOC4;
		NimStringDesc* line;
		LOC3 = 0;
		LOC3 = togid_224462(project);
		LOC4 = 0;
		LOC4 = open_17003(&f, LOC3, ((NU8) 0), ((NI) -1));
		if (!LOC4) goto LA5;
		line = rawNewString(((NI) 20));
		{
			NIM_BOOL LOC9;
			NI frontendid;
			LOC9 = 0;
			LOC9 = readline_17119(f, (&line));
			if (!LOC9) goto LA10;
			frontendid = nsuParseInt(line);
			{
				NIM_BOOL LOC14;
				NI backendid;
				LOC14 = 0;
				LOC14 = readline_17119(f, (&line));
				if (!LOC14) goto LA15;
				backendid = nsuParseInt(line);
				gfrontendid_224012 = ((gfrontendid_224012 >= frontendid) ? gfrontendid_224012 : frontendid);
				gbackendid_224013 = ((gbackendid_224013 >= backendid) ? gbackendid_224013 : backendid);
			}
			LA15: ;
		}
		LA10: ;
		fclose(f);
	}
	LA5: ;
}

N_NIMCALL(void, idsynchronizationpoint_224453)(NI idrange) {
	gfrontendid_224012 = (NI)((NI)((NI)((NI)(gfrontendid_224012 / idrange) + ((NI) 1)) * idrange) + ((NI) 1));
}

static N_INLINE(void, writeline_168405)(FILE* f, NimStringDesc** x, NI xLen0) {
	{
		NimStringDesc* i_168421;
		NI i_168429;
		i_168421 = 0;
		i_168429 = ((NI) 0);
		{
			while (1) {
				if (!(i_168429 < xLen0)) goto LA3;
				i_168421 = x[i_168429];
				write_17095(f, i_168421);
				i_168429 += ((NI) 1);
			} LA3: ;
		}
	}
	write_17095(f, ((NimStringDesc*) &TMP4516));
}

N_NIMCALL(void, savemaxids_224472)(NimStringDesc* project) {
	FILE* f;
	NimStringDesc* LOC1;
	TY192421 LOC2;
	TY192421 LOC3;
	LOC1 = 0;
	LOC1 = togid_224462(project);
	f = open_17017(LOC1, ((NU8) 1), ((NI) -1));
	memset((void*)LOC2, 0, sizeof(LOC2));
	LOC2[0] = nimIntToStr(gfrontendid_224012);
	writeline_168405(f, LOC2, 1);
	memset((void*)LOC3, 0, sizeof(LOC3));
	LOC3[0] = nimIntToStr(gbackendid_224013);
	writeline_168405(f, LOC3, 1);
	fclose(f);
}
NIM_EXTERNC N_NOINLINE(void, compiler_idgenInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, compiler_idgenDatInit000)(void) {
}

