/* 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/idgen.o compiler/nimcache/idgen.c */
#define NIM_INTBITS 32
#include "nimbase.h"

#include <stdio.h>

#include <string.h>
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct tidobj167013 tidobj167013;
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* TY165002[1];
typedef N_NIMCALL_PTR(void, TY2289) (void* p, NI op);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY2289 marker;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  tidobj167013  {
  TNimObject Sup;
NI Id;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
N_NIMCALL(NIM_BOOL, open_10203)(FILE** f, NimStringDesc* filename, NU8 mode, NI bufsize);
N_NIMCALL(NimStringDesc*, togid_187457)(NimStringDesc* f);
N_NIMCALL(NimStringDesc*, completegeneratedfilepath_138001)(NimStringDesc* f, NIM_BOOL createsubdir);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(NimStringDesc*, rawNewString)(NI cap);
N_NIMCALL(NIM_BOOL, readline_10487)(FILE* f, NimStringDesc** line);
N_NIMCALL(NI, nsuParseInt)(NimStringDesc* s);
N_NIMCALL(FILE*, open_10217)(NimStringDesc* filename, NU8 mode, NI bufsize);
static N_INLINE(void, writeln_138205)(FILE* f_138209, NimStringDesc** x_138213, NI x_138213Len0);
N_NIMCALL(void, write_10463)(FILE* f, NimStringDesc* s);
N_NIMCALL(NimStringDesc*, nimIntToStr)(NI x);
STRING_LITERAL(TMP1720, "nimrod.gid", 10);
STRING_LITERAL(TMP3841, "\012", 1);
NI gfrontendid_187007;
NI gbackendid_187008;

N_NIMCALL(NimStringDesc*, togid_187457)(NimStringDesc* f) {
	NimStringDesc* result;
	result = 0;
	result = completegeneratedfilepath_138001(((NimStringDesc*) &TMP1720), NIM_TRUE);
	return result;
}

N_NIMCALL(void, loadmaxids_187501)(NimStringDesc* project) {
	FILE* f;
	f = 0;
	{
		NimStringDesc* LOC3;
		NIM_BOOL LOC4;
		NimStringDesc* line;
		LOC3 = 0;
		LOC3 = togid_187457(project);
		LOC4 = 0;
		LOC4 = open_10203(&f, LOC3, ((NU8) 0), -1);
		if (!LOC4) goto LA5;
		line = rawNewString(20);
		{
			NIM_BOOL LOC9;
			NI frontendid;
			LOC9 = 0;
			LOC9 = readline_10487(f, &line);
			if (!LOC9) goto LA10;
			frontendid = nsuParseInt(line);
			{
				NIM_BOOL LOC14;
				NI backendid;
				LOC14 = 0;
				LOC14 = readline_10487(f, &line);
				if (!LOC14) goto LA15;
				backendid = nsuParseInt(line);
				gfrontendid_187007 = ((gfrontendid_187007 >= frontendid) ? gfrontendid_187007 : frontendid);
				gbackendid_187008 = ((gbackendid_187008 >= backendid) ? gbackendid_187008 : backendid);
			}
			LA15: ;
		}
		LA10: ;
		fclose(f);
	}
	LA5: ;
}

N_NIMCALL(void, registerid_187201)(tidobj167013* id) {
}

N_NIMCALL(void, idsynchronizationpoint_187452)(NI idrange) {
	gfrontendid_187007 = (NI32)((NI32)((NI32)((NI32)(gfrontendid_187007 / idrange) + 1) * idrange) + 1);
}

static N_INLINE(void, writeln_138205)(FILE* f_138209, NimStringDesc** x_138213, NI x_138213Len0) {
	NimStringDesc* i_138226;
	NI i_138232;
	i_138226 = 0;
	i_138232 = 0;
	while (1) {
		if (!(i_138232 < x_138213Len0)) goto LA1;
		i_138226 = x_138213[i_138232];
		write_10463(f_138209, i_138226);
		i_138232 += 1;
	} LA1: ;
	write_10463(f_138209, ((NimStringDesc*) &TMP3841));
}

N_NIMCALL(void, savemaxids_187463)(NimStringDesc* project) {
	FILE* f;
	NimStringDesc* LOC1;
	TY165002 LOC2;
	TY165002 LOC3;
	LOC1 = 0;
	LOC1 = togid_187457(project);
	f = open_10217(LOC1, ((NU8) 1), -1);
	memset((void*)LOC2, 0, sizeof(LOC2));
	LOC2[0] = nimIntToStr(gfrontendid_187007);
	writeln_138205(f, LOC2, 1);
	memset((void*)LOC3, 0, sizeof(LOC3));
	LOC3[0] = nimIntToStr(gbackendid_187008);
	writeln_138205(f, LOC3, 1);
	fclose(f);
}
N_NOINLINE(void, idgenInit)(void) {
}

N_NOINLINE(void, idgenDatInit)(void) {
}

