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

#include <time.h>

#include <sys/select.h>

#include <string.h>

#include <sys/time.h>
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct ttimeinfo94003 ttimeinfo94003;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct tkeyvaluepair121806 tkeyvaluepair121806;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
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  ttimeinfo94003  {
  TNimObject Sup;
NI Second;
NI Minute;
NI Hour;
NI Monthday;
NU8 Month;
NI Year;
NU8 Weekday;
NI Yearday;
NIM_BOOL Isdst;
NimStringDesc* Tzname;
NI Timezone;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
typedef NU8 TY94650[7];
struct tkeyvaluepair121806 {
NimStringDesc* Field0;
NimStringDesc* Field1;
};
N_NIMCALL(void, getlocaltime_94040)(time_t t, ttimeinfo94003* Result);
N_NIMCALL(void, tmtotimeinfo_94644)(struct tm* tm, NIM_BOOL local, ttimeinfo94003* Result);
N_NIMCALL(void, gettzname_94103)(tkeyvaluepair121806* Result);
N_NIMCALL(NimStringDesc*, cstrToNimstr)(NCSTRING str);
N_NIMCALL(void, unsureAsgnRef)(void** dest, void* src);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(NI, gettimezone_94202)(void);
N_NIMCALL(void, genericShallowAssign)(void* dest, void* src, TNimType* mt);
N_NOINLINE(void, chckNil)(void* p);
N_NIMCALL(void, genericReset)(void* dest, TNimType* mt);
N_NIMCALL(time_t, gettime_94037)(void);
N_NIMCALL(NimStringDesc*, nimIntToStr)(NI x);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
static N_INLINE(void, appendChar)(NimStringDesc* dest, NIM_CHAR c);
N_NIMCALL(NimStringDesc*, nsuIntToStr)(NI x, NI minchars);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
NIM_CONST TY94650 weekdays_94649 = {((NU8) 6),
((NU8) 0),
((NU8) 1),
((NU8) 2),
((NU8) 3),
((NU8) 4),
((NU8) 5)}
;
STRING_LITERAL(TMP2903, "UTC", 3);
extern TNimType NTI2409; /* TObject */
TNimType NTI94003; /* TTimeInfo */
extern TNimType NTI106; /* int */
TNimType NTI94006; /* range 0..61(int) */
TNimType NTI94009; /* range 0..59(int) */
TNimType NTI94011; /* range 0..23(int) */
TNimType NTI94014; /* range 1..31(int) */
TNimType NTI93804; /* TMonth */
TNimType NTI94017; /* range -10000..10000(int) */
TNimType NTI93806; /* TWeekDay */
TNimType NTI94023; /* range 0..365(int) */
extern TNimType NTI134; /* bool */
extern TNimType NTI143; /* string */

N_NIMCALL(NF, ntepochTime)(void) {
	NF result;
	struct timeval a;
	result = 0;
	memset((void*)&a, 0, sizeof(a));
	gettimeofday(&a, NIM_NIL);
	result = ((NF)(((double) (a.tv_sec))) + (NF)(((NF)(((double) (a.tv_usec))) * (NF)(9.9999999999999995e-07))));
	return result;
}

N_NIMCALL(void, gettzname_94103)(tkeyvaluepair121806* Result) {
	unsureAsgnRef((void**) &(*Result).Field0, cstrToNimstr(tzname[(0)- 0]));
	unsureAsgnRef((void**) &(*Result).Field1, cstrToNimstr(tzname[(1)- 0]));
	goto BeforeRet;
	BeforeRet: ;
}

N_NIMCALL(NI, gettimezone_94202)(void) {
	NI result;
	result = 0;
	result = timezone;
	goto BeforeRet;
	BeforeRet: ;
	return result;
}

N_NIMCALL(void, tmtotimeinfo_94644)(struct tm* tm, NIM_BOOL local, ttimeinfo94003* Result) {
	ttimeinfo94003 LOC1;
	memset((void*)&LOC1, 0, sizeof(LOC1));
	LOC1.Sup.m_type = (&NTI94003);
	memset((void*)&LOC1, 0, sizeof(LOC1));
	LOC1.Sup.m_type = (&NTI94003);
	LOC1.Second = ((NI) (((NI) ((*tm).tm_sec))));
	LOC1.Minute = ((NI) (((NI) ((*tm).tm_min))));
	LOC1.Hour = ((NI) (((NI) ((*tm).tm_hour))));
	LOC1.Monthday = ((NI) (((NI) ((*tm).tm_mday))));
	LOC1.Month = ((NU8) ((*tm).tm_mon));
	LOC1.Year = ((NI) ((NI32)((*tm).tm_year + ((NI32) 1900))));
	LOC1.Weekday = weekdays_94649[(((NI) ((*tm).tm_wday)))- 0];
	LOC1.Yearday = ((NI) (((NI) ((*tm).tm_yday))));
	LOC1.Isdst = (((NI32) 0) < (*tm).tm_isdst);
	{
		if (!local) goto LA4;
		{
			tkeyvaluepair121806 LOC10;
			if (!(((NI32) 0) < (*tm).tm_isdst)) goto LA8;
			memset((void*)&LOC10, 0, sizeof(LOC10));
			gettzname_94103(&LOC10);
			LOC1.Tzname = copyString(LOC10.Field1);
		}
		goto LA6;
		LA8: ;
		{
			tkeyvaluepair121806 LOC12;
			memset((void*)&LOC12, 0, sizeof(LOC12));
			gettzname_94103(&LOC12);
			LOC1.Tzname = copyString(LOC12.Field0);
		}
		LA6: ;
	}
	goto LA2;
	LA4: ;
	{
		LOC1.Tzname = copyString(((NimStringDesc*) &TMP2903));
	}
	LA2: ;
	{
		if (!local) goto LA16;
		LOC1.Timezone = gettimezone_94202();
	}
	goto LA14;
	LA16: ;
	{
		LOC1.Timezone = 0;
	}
	LA14: ;
	genericShallowAssign((void*)Result, (void*)&LOC1, (&NTI94003));
}

N_NIMCALL(void, getlocaltime_94040)(time_t t, ttimeinfo94003* Result) {
	time_t a;
	struct tm* LOC1;
	a = t;
	LOC1 = 0;
	LOC1 = localtime(&a);
	chckNil((void*)Result);
	genericReset((void*)Result, (&NTI94003));
	(*Result).Sup.m_type = (&NTI94003);
	tmtotimeinfo_94644(&(*LOC1), NIM_TRUE, Result);
}

N_NIMCALL(time_t, gettime_94037)(void) {
	time_t result;
	result = 0;
	result = time(NIM_NIL);
	goto BeforeRet;
	BeforeRet: ;
	return result;
}

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;
}

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;
}

N_NIMCALL(NimStringDesc*, ntgetDateStr)(void) {
	NimStringDesc* result;
	ttimeinfo94003 ti;
	time_t LOC1;
	NimStringDesc* LOC2;
	NimStringDesc* LOC3;
	NimStringDesc* LOC4;
	NimStringDesc* LOC5;
	result = 0;
	LOC1 = 0;
	LOC1 = gettime_94037();
	chckNil((void*)&ti);
	memset((void*)&ti, 0, sizeof(ti));
	ti.Sup.m_type = (&NTI94003);
	getlocaltime_94040(LOC1, &ti);
	LOC2 = 0;
	LOC3 = 0;
	LOC3 = nimIntToStr(((NI) (ti.Year)));
	LOC4 = 0;
	LOC4 = nsuIntToStr(((NI) ((NI32)(((NI) (ti.Month)) + 1))), 2);
	LOC5 = 0;
	LOC5 = nsuIntToStr(((NI) (ti.Monthday)), 2);
	LOC2 = rawNewString(LOC3->Sup.len + LOC4->Sup.len + LOC5->Sup.len + 2);
appendString(LOC2, LOC3);
appendChar(LOC2, 45);
appendString(LOC2, LOC4);
appendChar(LOC2, 45);
appendString(LOC2, LOC5);
	result = LOC2;
	return result;
}

N_NIMCALL(NimStringDesc*, ntgetClockStr)(void) {
	NimStringDesc* result;
	ttimeinfo94003 ti;
	time_t LOC1;
	NimStringDesc* LOC2;
	NimStringDesc* LOC3;
	NimStringDesc* LOC4;
	NimStringDesc* LOC5;
	result = 0;
	LOC1 = 0;
	LOC1 = gettime_94037();
	chckNil((void*)&ti);
	memset((void*)&ti, 0, sizeof(ti));
	ti.Sup.m_type = (&NTI94003);
	getlocaltime_94040(LOC1, &ti);
	LOC2 = 0;
	LOC3 = 0;
	LOC3 = nsuIntToStr(((NI) (ti.Hour)), 2);
	LOC4 = 0;
	LOC4 = nsuIntToStr(((NI) (ti.Minute)), 2);
	LOC5 = 0;
	LOC5 = nsuIntToStr(((NI) (ti.Second)), 2);
	LOC2 = rawNewString(LOC3->Sup.len + LOC4->Sup.len + LOC5->Sup.len + 2);
appendString(LOC2, LOC3);
appendChar(LOC2, 58);
appendString(LOC2, LOC4);
appendChar(LOC2, 58);
appendString(LOC2, LOC5);
	result = LOC2;
	return result;
}

N_NIMCALL(NI64, ntDiffTime)(time_t a, time_t b) {
	NI64 result;
	NF LOC1;
	result = 0;
	LOC1 = 0;
	LOC1 = difftime(a, b);
	result = float64ToInt64(LOC1);
	goto BeforeRet;
	BeforeRet: ;
	return result;
}
N_NOINLINE(void, stdlibtimesInit)(void) {
}

N_NOINLINE(void, stdlibtimesDatInit)(void) {
static TNimNode* TMP2896[11];
static TNimNode* TMP2897[12];
NI TMP2899;
static char* NIM_CONST TMP2898[12] = {
"mJan", 
"mFeb", 
"mMar", 
"mApr", 
"mMay", 
"mJun", 
"mJul", 
"mAug", 
"mSep", 
"mOct", 
"mNov", 
"mDec"};
static TNimNode* TMP2900[7];
NI TMP2902;
static char* NIM_CONST TMP2901[7] = {
"dMon", 
"dTue", 
"dWed", 
"dThu", 
"dFri", 
"dSat", 
"dSun"};
static TNimNode TMP15[33];
NTI94003.size = sizeof(ttimeinfo94003);
NTI94003.kind = 17;
NTI94003.base = (&NTI2409);
TMP2896[0] = &TMP15[1];
NTI94006.size = sizeof(NI);
NTI94006.kind = 20;
NTI94006.base = (&NTI106);
NTI94006.flags = 3;
TMP15[1].kind = 1;
TMP15[1].offset = offsetof(ttimeinfo94003, Second);
TMP15[1].typ = (&NTI94006);
TMP15[1].name = "second";
TMP2896[1] = &TMP15[2];
NTI94009.size = sizeof(NI);
NTI94009.kind = 20;
NTI94009.base = (&NTI106);
NTI94009.flags = 3;
TMP15[2].kind = 1;
TMP15[2].offset = offsetof(ttimeinfo94003, Minute);
TMP15[2].typ = (&NTI94009);
TMP15[2].name = "minute";
TMP2896[2] = &TMP15[3];
NTI94011.size = sizeof(NI);
NTI94011.kind = 20;
NTI94011.base = (&NTI106);
NTI94011.flags = 3;
TMP15[3].kind = 1;
TMP15[3].offset = offsetof(ttimeinfo94003, Hour);
TMP15[3].typ = (&NTI94011);
TMP15[3].name = "hour";
TMP2896[3] = &TMP15[4];
NTI94014.size = sizeof(NI);
NTI94014.kind = 20;
NTI94014.base = (&NTI106);
NTI94014.flags = 3;
TMP15[4].kind = 1;
TMP15[4].offset = offsetof(ttimeinfo94003, Monthday);
TMP15[4].typ = (&NTI94014);
TMP15[4].name = "monthday";
TMP2896[4] = &TMP15[5];
NTI93804.size = sizeof(NU8);
NTI93804.kind = 14;
NTI93804.base = 0;
NTI93804.flags = 3;
for (TMP2899 = 0; TMP2899 < 12; TMP2899++) {
TMP15[TMP2899+6].kind = 1;
TMP15[TMP2899+6].offset = TMP2899;
TMP15[TMP2899+6].name = TMP2898[TMP2899];
TMP2897[TMP2899] = &TMP15[TMP2899+6];
}
TMP15[18].len = 12; TMP15[18].kind = 2; TMP15[18].sons = &TMP2897[0];
NTI93804.node = &TMP15[18];
TMP15[5].kind = 1;
TMP15[5].offset = offsetof(ttimeinfo94003, Month);
TMP15[5].typ = (&NTI93804);
TMP15[5].name = "month";
TMP2896[5] = &TMP15[19];
NTI94017.size = sizeof(NI);
NTI94017.kind = 20;
NTI94017.base = (&NTI106);
NTI94017.flags = 3;
TMP15[19].kind = 1;
TMP15[19].offset = offsetof(ttimeinfo94003, Year);
TMP15[19].typ = (&NTI94017);
TMP15[19].name = "year";
TMP2896[6] = &TMP15[20];
NTI93806.size = sizeof(NU8);
NTI93806.kind = 14;
NTI93806.base = 0;
NTI93806.flags = 3;
for (TMP2902 = 0; TMP2902 < 7; TMP2902++) {
TMP15[TMP2902+21].kind = 1;
TMP15[TMP2902+21].offset = TMP2902;
TMP15[TMP2902+21].name = TMP2901[TMP2902];
TMP2900[TMP2902] = &TMP15[TMP2902+21];
}
TMP15[28].len = 7; TMP15[28].kind = 2; TMP15[28].sons = &TMP2900[0];
NTI93806.node = &TMP15[28];
TMP15[20].kind = 1;
TMP15[20].offset = offsetof(ttimeinfo94003, Weekday);
TMP15[20].typ = (&NTI93806);
TMP15[20].name = "weekday";
TMP2896[7] = &TMP15[29];
NTI94023.size = sizeof(NI);
NTI94023.kind = 20;
NTI94023.base = (&NTI106);
NTI94023.flags = 3;
TMP15[29].kind = 1;
TMP15[29].offset = offsetof(ttimeinfo94003, Yearday);
TMP15[29].typ = (&NTI94023);
TMP15[29].name = "yearday";
TMP2896[8] = &TMP15[30];
TMP15[30].kind = 1;
TMP15[30].offset = offsetof(ttimeinfo94003, Isdst);
TMP15[30].typ = (&NTI134);
TMP15[30].name = "isDST";
TMP2896[9] = &TMP15[31];
TMP15[31].kind = 1;
TMP15[31].offset = offsetof(ttimeinfo94003, Tzname);
TMP15[31].typ = (&NTI143);
TMP15[31].name = "tzname";
TMP2896[10] = &TMP15[32];
TMP15[32].kind = 1;
TMP15[32].offset = offsetof(ttimeinfo94003, Timezone);
TMP15[32].typ = (&NTI106);
TMP15[32].name = "timezone";
TMP15[0].len = 11; TMP15[0].kind = 2; TMP15[0].sons = &TMP2896[0];
NTI94003.node = &TMP15[0];
}

