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

#include "nimbase.h"
#include <time.h>
#include <string.h>
#include <sys/select.h>
#include <sys/time.h>
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Timeinfo105404 Timeinfo105404;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Keyvaluepair140205 Keyvaluepair140205;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef N_NIMCALL_PTR(void, TY3489) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3494) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3489 marker;
TY3494 deepcopy;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  Timeinfo105404  {
  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 TY106052[7];
struct Keyvaluepair140205 {
NimStringDesc* Field0;
NimStringDesc* Field1;
};
N_NIMCALL(void, getlocaltime_105440)(time_t t, Timeinfo105404* Result);
N_NIMCALL(void, tmtotimeinfo_106045)(struct tm* tm, NIM_BOOL local, Timeinfo105404* Result);
N_NIMCALL(void, gettzname_105485)(Keyvaluepair140205* 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_105601)(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_105438)(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 TY106052 weekdays_106050 = {((NU8) 6),
((NU8) 0),
((NU8) 1),
((NU8) 2),
((NU8) 3),
((NU8) 4),
((NU8) 5)}
;
STRING_LITERAL(TMP3400, "UTC", 3);
extern TNimType NTI3608; /* RootObj */
TNimType NTI105404; /* TimeInfo */
extern TNimType NTI104; /* int */
TNimType NTI105407; /* range 0..61(int) */
TNimType NTI105410; /* range 0..59(int) */
TNimType NTI105412; /* range 0..23(int) */
TNimType NTI105415; /* range 1..31(int) */
TNimType NTI105203; /* Month */
TNimType NTI105205; /* WeekDay */
TNimType NTI105420; /* range 0..365(int) */
extern TNimType NTI130; /* bool */
extern TNimType NTI138; /* string */

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

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

N_NIMCALL(void, tmtotimeinfo_106045)(struct tm* tm, NIM_BOOL local, Timeinfo105404* Result) {
	Timeinfo105404 LOC1;
	memset((void*)(&LOC1), 0, sizeof(LOC1));
	LOC1.Sup.m_type = (&NTI105404);
	memset((void*)(&LOC1), 0, sizeof(LOC1));
	LOC1.Sup.m_type = (&NTI105404);
	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_106050[(((NI) ((*tm).tm_wday)))- 0];
	LOC1.yearday = ((NI) (((NI) ((*tm).tm_yday))));
	LOC1.isdst = (((NI32) 0) < (*tm).tm_isdst);
	{
		if (!local) goto LA4;
		{
			Keyvaluepair140205 LOC10;
			if (!(((NI32) 0) < (*tm).tm_isdst)) goto LA8;
			memset((void*)(&LOC10), 0, sizeof(LOC10));
			gettzname_105485((&LOC10));
			LOC1.tzname = copyString(LOC10.Field1);
		}
		goto LA6;
		LA8: ;
		{
			Keyvaluepair140205 LOC12;
			memset((void*)(&LOC12), 0, sizeof(LOC12));
			gettzname_105485((&LOC12));
			LOC1.tzname = copyString(LOC12.Field0);
		}
		LA6: ;
	}
	goto LA2;
	LA4: ;
	{
		LOC1.tzname = copyString(((NimStringDesc*) &TMP3400));
	}
	LA2: ;
	{
		if (!local) goto LA16;
		LOC1.timezone = gettimezone_105601();
	}
	goto LA14;
	LA16: ;
	{
		LOC1.timezone = ((NI) 0);
	}
	LA14: ;
	genericShallowAssign((void*)Result, (void*)(&LOC1), (&NTI105404));
}

N_NIMCALL(void, getlocaltime_105440)(time_t t, Timeinfo105404* Result) {
	time_t a;
	struct tm* lt;
	a = t;
	lt = localtime((&a));
	chckNil((void*)Result);
	genericReset((void*)Result, (&NTI105404));
	(*Result).Sup.m_type = (&NTI105404);
	tmtotimeinfo_106045((&(*lt)), NIM_TRUE, Result);
}

N_NIMCALL(time_t, gettime_105438)(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)), (NI)((*src).Sup.len + ((NI) 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[((NI)((*dest).Sup.len + ((NI) 1)))- 0] = 0;
	(*dest).Sup.len += ((NI) 1);
}

N_NIMCALL(NimStringDesc*, ntgetDateStr)(void) {
	NimStringDesc* result;
	Timeinfo105404 ti;
	time_t LOC1;
	NimStringDesc* LOC2;
	NimStringDesc* LOC3;
	NimStringDesc* LOC4;
	NimStringDesc* LOC5;
	result = 0;
	memset((void*)(&ti), 0, sizeof(ti));
	ti.Sup.m_type = (&NTI105404);
	LOC1 = 0;
	LOC1 = gettime_105438();
	chckNil((void*)(&ti));
	memset((void*)(&ti), 0, sizeof(ti));
	ti.Sup.m_type = (&NTI105404);
	getlocaltime_105440(LOC1, (&ti));
	LOC2 = 0;
	LOC3 = 0;
	LOC3 = nimIntToStr(ti.year);
	LOC4 = 0;
	LOC4 = nsuIntToStr(((NI) ((NI)(((NI) (ti.month)) + ((NI) 1)))), ((NI) 2));
	LOC5 = 0;
	LOC5 = nsuIntToStr(((NI) (ti.monthday)), ((NI) 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;
	Timeinfo105404 ti;
	time_t LOC1;
	NimStringDesc* LOC2;
	NimStringDesc* LOC3;
	NimStringDesc* LOC4;
	NimStringDesc* LOC5;
	result = 0;
	memset((void*)(&ti), 0, sizeof(ti));
	ti.Sup.m_type = (&NTI105404);
	LOC1 = 0;
	LOC1 = gettime_105438();
	chckNil((void*)(&ti));
	memset((void*)(&ti), 0, sizeof(ti));
	ti.Sup.m_type = (&NTI105404);
	getlocaltime_105440(LOC1, (&ti));
	LOC2 = 0;
	LOC3 = 0;
	LOC3 = nsuIntToStr(((NI) (ti.hour)), ((NI) 2));
	LOC4 = 0;
	LOC4 = nsuIntToStr(((NI) (ti.minute)), ((NI) 2));
	LOC5 = 0;
	LOC5 = nsuIntToStr(((NI) (ti.second)), ((NI) 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(NF, toseconds_105457)(time_t time) {
	NF result;
	result = 0;
	result = ((NF) (time));
	return result;
}

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(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;
}
NIM_EXTERNC N_NOINLINE(void, stdlib_timesInit000)(void) {
	tzset();
}

NIM_EXTERNC N_NOINLINE(void, stdlib_timesDatInit000)(void) {
static TNimNode* TMP3393[11];
static TNimNode* TMP3394[12];
NI TMP3396;
static char* NIM_CONST TMP3395[12] = {
"mJan", 
"mFeb", 
"mMar", 
"mApr", 
"mMay", 
"mJun", 
"mJul", 
"mAug", 
"mSep", 
"mOct", 
"mNov", 
"mDec"};
static TNimNode* TMP3397[7];
NI TMP3399;
static char* NIM_CONST TMP3398[7] = {
"dMon", 
"dTue", 
"dWed", 
"dThu", 
"dFri", 
"dSat", 
"dSun"};
static TNimNode TMP15[33];
NTI105404.size = sizeof(Timeinfo105404);
NTI105404.kind = 17;
NTI105404.base = (&NTI3608);
TMP3393[0] = &TMP15[1];
NTI105407.size = sizeof(NI);
NTI105407.kind = 20;
NTI105407.base = (&NTI104);
NTI105407.flags = 3;
TMP15[1].kind = 1;
TMP15[1].offset = offsetof(Timeinfo105404, second);
TMP15[1].typ = (&NTI105407);
TMP15[1].name = "second";
TMP3393[1] = &TMP15[2];
NTI105410.size = sizeof(NI);
NTI105410.kind = 20;
NTI105410.base = (&NTI104);
NTI105410.flags = 3;
TMP15[2].kind = 1;
TMP15[2].offset = offsetof(Timeinfo105404, minute);
TMP15[2].typ = (&NTI105410);
TMP15[2].name = "minute";
TMP3393[2] = &TMP15[3];
NTI105412.size = sizeof(NI);
NTI105412.kind = 20;
NTI105412.base = (&NTI104);
NTI105412.flags = 3;
TMP15[3].kind = 1;
TMP15[3].offset = offsetof(Timeinfo105404, hour);
TMP15[3].typ = (&NTI105412);
TMP15[3].name = "hour";
TMP3393[3] = &TMP15[4];
NTI105415.size = sizeof(NI);
NTI105415.kind = 20;
NTI105415.base = (&NTI104);
NTI105415.flags = 3;
TMP15[4].kind = 1;
TMP15[4].offset = offsetof(Timeinfo105404, monthday);
TMP15[4].typ = (&NTI105415);
TMP15[4].name = "monthday";
TMP3393[4] = &TMP15[5];
NTI105203.size = sizeof(NU8);
NTI105203.kind = 14;
NTI105203.base = 0;
NTI105203.flags = 3;
for (TMP3396 = 0; TMP3396 < 12; TMP3396++) {
TMP15[TMP3396+6].kind = 1;
TMP15[TMP3396+6].offset = TMP3396;
TMP15[TMP3396+6].name = TMP3395[TMP3396];
TMP3394[TMP3396] = &TMP15[TMP3396+6];
}
TMP15[18].len = 12; TMP15[18].kind = 2; TMP15[18].sons = &TMP3394[0];
NTI105203.node = &TMP15[18];
TMP15[5].kind = 1;
TMP15[5].offset = offsetof(Timeinfo105404, month);
TMP15[5].typ = (&NTI105203);
TMP15[5].name = "month";
TMP3393[5] = &TMP15[19];
TMP15[19].kind = 1;
TMP15[19].offset = offsetof(Timeinfo105404, year);
TMP15[19].typ = (&NTI104);
TMP15[19].name = "year";
TMP3393[6] = &TMP15[20];
NTI105205.size = sizeof(NU8);
NTI105205.kind = 14;
NTI105205.base = 0;
NTI105205.flags = 3;
for (TMP3399 = 0; TMP3399 < 7; TMP3399++) {
TMP15[TMP3399+21].kind = 1;
TMP15[TMP3399+21].offset = TMP3399;
TMP15[TMP3399+21].name = TMP3398[TMP3399];
TMP3397[TMP3399] = &TMP15[TMP3399+21];
}
TMP15[28].len = 7; TMP15[28].kind = 2; TMP15[28].sons = &TMP3397[0];
NTI105205.node = &TMP15[28];
TMP15[20].kind = 1;
TMP15[20].offset = offsetof(Timeinfo105404, weekday);
TMP15[20].typ = (&NTI105205);
TMP15[20].name = "weekday";
TMP3393[7] = &TMP15[29];
NTI105420.size = sizeof(NI);
NTI105420.kind = 20;
NTI105420.base = (&NTI104);
NTI105420.flags = 3;
TMP15[29].kind = 1;
TMP15[29].offset = offsetof(Timeinfo105404, yearday);
TMP15[29].typ = (&NTI105420);
TMP15[29].name = "yearday";
TMP3393[8] = &TMP15[30];
TMP15[30].kind = 1;
TMP15[30].offset = offsetof(Timeinfo105404, isdst);
TMP15[30].typ = (&NTI130);
TMP15[30].name = "isDST";
TMP3393[9] = &TMP15[31];
TMP15[31].kind = 1;
TMP15[31].offset = offsetof(Timeinfo105404, tzname);
TMP15[31].typ = (&NTI138);
TMP15[31].name = "tzname";
TMP3393[10] = &TMP15[32];
TMP15[32].kind = 1;
TMP15[32].offset = offsetof(Timeinfo105404, timezone);
TMP15[32].typ = (&NTI104);
TMP15[32].name = "timezone";
TMP15[0].len = 11; TMP15[0].kind = 2; TMP15[0].sons = &TMP3393[0];
NTI105404.node = &TMP15[0];
}

