/* 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 Tidobj196015 Tidobj196015;
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* TY190421[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  Tidobj196015  {
  TNimObject Sup;
NI id;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
N_NIMCALL(NIM_BOOL, open_16803)(FILE** f, NimStringDesc* filename, NU8 mode, NI bufsize);
N_NIMCALL(NimStringDesc*, togid_222462)(NimStringDesc* f);
N_NIMCALL(NimStringDesc*, completegeneratedfilepath_166201)(NimStringDesc* f, NIM_BOOL createsubdir);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(NimStringDesc*, rawNewString)(NI cap);
N_NIMCALL(NIM_BOOL, readline_16919)(FILE* f, NimStringDesc** line);
N_NIMCALL(NI, nsuParseInt)(NimStringDesc* s);
N_NIMCALL(FILE*, open_16817)(NimStringDesc* filename, NU8 mode, NI bufsize);
static N_INLINE(void, writeline_166405)(FILE* f, NimStringDesc** x, NI xLen0);
N_NIMCALL(void, write_16895)(FILE* f, NimStringDesc* s);
N_NIMCALL(NimStringDesc*, nimIntToStr)(NI x);
STRING_LITERAL(TMP1528, "nimrod.gid", 10);
STRING_LITERAL(TMP4520, "\012", 1);
NI gfrontendid_222012;
NI gbackendid_222013;

N_NIMCALL(void, registerid_222201)(Tidobj196015* id) {
}

N_NIMCALL(NimStringDesc*, togid_222462)(NimStringDesc* f) {
	NimStringDesc* result;
	result = 0;
	result = completegeneratedfilepath_166201(((NimStringDesc*) &TMP1528), NIM_TRUE);
	return result;
}

N_NIMCALL(void, loadmaxids_222506)(NimStringDesc* project) {
	FILE* f;
	f = 0;
	{
		NimStringDesc* LOC3;
		NIM_BOOL LOC4;
		NimStringDesc* line;
		LOC3 = 0;
		LOC3 = togid_222462(project);
		LOC4 = 0;
		LOC4 = open_16803(&f, LOC3, ((NU8) 0), ((NI) -1));
		if (!LOC4) goto LA5;
		line = rawNewString(((NI) 20));
		{
			NIM_BOOL LOC9;
			NI frontendid;
			LOC9 = 0;
			LOC9 = readline_16919(f, (&line));
			if (!LOC9) goto LA10;
			frontendid = nsuParseInt(line);
			{
				NIM_BOOL LOC14;
				NI backendid;
				LOC14 = 0;
				LOC14 = readline_16919(f, (&line));
				if (!LOC14) goto LA15;
				backendid = nsuParseInt(line);
				gfrontendid_222012 = ((gfrontendid_222012 >= frontendid) ? gfrontendid_222012 : frontendid);
				gbackendid_222013 = ((gbackendid_222013 >= backendid) ? gbackendid_222013 : backendid);
			}
			LA15: ;
		}
		LA10: ;
		fclose(f);
	}
	LA5: ;
}

N_NIMCALL(void, idsynchronizationpoint_222453)(NI idrange) {
	gfrontendid_222012 = (NI)((NI)((NI)((NI)(gfrontendid_222012 / idrange) + ((NI) 1)) * idrange) + ((NI) 1));
}

static N_INLINE(void, writeline_166405)(FILE* f, NimStringDesc** x, NI xLen0) {
	{
		NimStringDesc* i_166421;
		NI i_166429;
		i_166421 = 0;
		i_166429 = ((NI) 0);
		{
			while (1) {
				if (!(i_166429 < xLen0)) goto LA3;
				i_166421 = x[i_166429];
				write_16895(f, i_166421);
				i_166429 += ((NI) 1);
			} LA3: ;
		}
	}
	write_16895(f, ((NimStringDesc*) &TMP4520));
}

N_NIMCALL(void, savemaxids_222472)(NimStringDesc* project) {
	FILE* f;
	NimStringDesc* LOC1;
	TY190421 LOC2;
	TY190421 LOC3;
	LOC1 = 0;
	LOC1 = togid_222462(project);
	f = open_16817(LOC1, ((NU8) 1), ((NI) -1));
	memset((void*)LOC2, 0, sizeof(LOC2));
	LOC2[0] = nimIntToStr(gfrontendid_222012);
	writeline_166405(f, LOC2, 1);
	memset((void*)LOC3, 0, sizeof(LOC3));
	LOC3[0] = nimIntToStr(gbackendid_222013);
	writeline_166405(f, LOC3, 1);
	fclose(f);
}
NIM_EXTERNC N_NOINLINE(void, compiler_idgenInit000)(void) {
}

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

