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

#include <string.h>

#include <time.h>
typedef struct Tfiletime104248 Tfiletime104248;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Timeinfo107405 Timeinfo107405;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Keyvaluepair136008 Keyvaluepair136008;
struct  Tfiletime104248  {
NI32 dwlowdatetime;
NI32 dwhighdatetime;
};
typedef N_STDCALL_PTR(void, TY105625) (Tfiletime104248* lpsystemtimeasfiletime);
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef N_NIMCALL_PTR(void, TY3289) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3294) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3289 marker;
TY3294 deepcopy;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  Timeinfo107405  {
  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 TY108054[7];
struct Keyvaluepair136008 {
NimStringDesc* Field0;
NimStringDesc* Field1;
};
N_NIMCALL(NI64, rdfiletime_105604)(Tfiletime104248 f);
N_NIMCALL(void, getlocaltime_107453)(time_t t, Timeinfo107405* Result);
N_NIMCALL(void, tmtotimeinfo_108048)(struct tm* tm, NIM_BOOL local, Timeinfo107405* Result);
N_NIMCALL(void, gettzname_107546)(Keyvaluepair136008* 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_107604)(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_107448)(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 TY108054 weekdays_108053 = {((NU8) 6),
((NU8) 0),
((NU8) 1),
((NU8) 2),
((NU8) 3),
((NU8) 4),
((NU8) 5)}
;
STRING_LITERAL(TMP3221, "UTC", 3);
extern TY105625 Dl_105624;
extern TNimType NTI3411; /* RootObj */
TNimType NTI107405; /* TimeInfo */
extern TNimType NTI108; /* int */
TNimType NTI107408; /* range 0..61(int) */
TNimType NTI107410; /* range 0..59(int) */
TNimType NTI107412; /* range 0..23(int) */
TNimType NTI107415; /* range 1..31(int) */
TNimType NTI104006; /* Month */
TNimType NTI107418; /* range -10000..10000(int) */
TNimType NTI104008; /* WeekDay */
TNimType NTI107424; /* range 0..365(int) */
extern TNimType NTI138; /* bool */
extern TNimType NTI149; /* string */

N_NIMCALL(NF, ntepochTime)(void) {
	NF result;
	Tfiletime104248 f;
	NI64 i64;
	NI64 LOC1;
	NI64 secs;
	NI64 subsecs;
	result = 0;
	memset((void*)(&f), 0, sizeof(f));
	Dl_105624((&f));
	LOC1 = 0;
	LOC1 = rdfiletime_105604(f);
	i64 = (NI64)(LOC1 - IL64(116444736000000000));
	secs = (NI64)(i64 / IL64(10000000));
	subsecs = (NI64)(i64 % IL64(10000000));
	result = ((NF)(((double) (((NI) (secs))))) + (NF)(((NF)(((double) (((NI) (subsecs))))) * (NF)(9.9999999999999995e-008))));
	return result;
}

N_NIMCALL(void, gettzname_107546)(Keyvaluepair136008* 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_107604)(void) {
	NI result;
{	result = 0;
	result = timezone;
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(void, tmtotimeinfo_108048)(struct tm* tm, NIM_BOOL local, Timeinfo107405* Result) {
	Timeinfo107405 LOC1;
	memset((void*)(&LOC1), 0, sizeof(LOC1));
	LOC1.Sup.m_type = (&NTI107405);
	memset((void*)(&LOC1), 0, sizeof(LOC1));
	LOC1.Sup.m_type = (&NTI107405);
	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_108053[(((NI) ((*tm).tm_wday)))- 0];
	LOC1.yearday = ((NI) (((NI) ((*tm).tm_yday))));
	LOC1.isdst = (((NI32) 0) < (*tm).tm_isdst);
	{
		if (!local) goto LA4;
		{
			Keyvaluepair136008 LOC10;
			if (!(((NI32) 0) < (*tm).tm_isdst)) goto LA8;
			memset((void*)(&LOC10), 0, sizeof(LOC10));
			gettzname_107546((&LOC10));
			LOC1.tzname = copyString(LOC10.Field1);
		}
		goto LA6;
		LA8: ;
		{
			Keyvaluepair136008 LOC12;
			memset((void*)(&LOC12), 0, sizeof(LOC12));
			gettzname_107546((&LOC12));
			LOC1.tzname = copyString(LOC12.Field0);
		}
		LA6: ;
	}
	goto LA2;
	LA4: ;
	{
		LOC1.tzname = copyString(((NimStringDesc*) &TMP3221));
	}
	LA2: ;
	{
		if (!local) goto LA16;
		LOC1.timezone = gettimezone_107604();
	}
	goto LA14;
	LA16: ;
	{
		LOC1.timezone = ((NI) 0);
	}
	LA14: ;
	genericShallowAssign((void*)Result, (void*)(&LOC1), (&NTI107405));
}

N_NIMCALL(void, getlocaltime_107453)(time_t t, Timeinfo107405* Result) {
	time_t a;
	struct tm* LOC1;
	a = t;
	LOC1 = 0;
	LOC1 = localtime((&a));
	chckNil((void*)Result);
	genericReset((void*)Result, (&NTI107405));
	(*Result).Sup.m_type = (&NTI107405);
	tmtotimeinfo_108048((&(*LOC1)), NIM_TRUE, Result);
}

N_NIMCALL(time_t, gettime_107448)(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;
	Timeinfo107405 ti;
	time_t LOC1;
	NimStringDesc* LOC2;
	NimStringDesc* LOC3;
	NimStringDesc* LOC4;
	NimStringDesc* LOC5;
	result = 0;
	memset((void*)(&ti), 0, sizeof(ti));
	ti.Sup.m_type = (&NTI107405);
	LOC1 = 0;
	LOC1 = gettime_107448();
	chckNil((void*)(&ti));
	memset((void*)(&ti), 0, sizeof(ti));
	ti.Sup.m_type = (&NTI107405);
	getlocaltime_107453(LOC1, (&ti));
	LOC2 = 0;
	LOC3 = 0;
	LOC3 = nimIntToStr(((NI) (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;
	Timeinfo107405 ti;
	time_t LOC1;
	NimStringDesc* LOC2;
	NimStringDesc* LOC3;
	NimStringDesc* LOC4;
	NimStringDesc* LOC5;
	result = 0;
	memset((void*)(&ti), 0, sizeof(ti));
	ti.Sup.m_type = (&NTI107405);
	LOC1 = 0;
	LOC1 = gettime_107448();
	chckNil((void*)(&ti));
	memset((void*)(&ti), 0, sizeof(ti));
	ti.Sup.m_type = (&NTI107405);
	getlocaltime_107453(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(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_NIMCALL(time_t, wintimetounixtime_108688)(NI64 t) {
	time_t result;
	result = 0;
	result = ((time_t) ((NI64)((NI64)(t - IL64(116444736000000000)) / IL64(10000000))));
	return result;
}
NIM_EXTERNC N_NOINLINE(void, stdlib_timesInit)(void) {
}

NIM_EXTERNC N_NOINLINE(void, stdlib_timesDatInit)(void) {
static TNimNode* TMP3214[11];
static TNimNode* TMP3215[12];
NI TMP3217;
static char* NIM_CONST TMP3216[12] = {
"mJan", 
"mFeb", 
"mMar", 
"mApr", 
"mMay", 
"mJun", 
"mJul", 
"mAug", 
"mSep", 
"mOct", 
"mNov", 
"mDec"};
static TNimNode* TMP3218[7];
NI TMP3220;
static char* NIM_CONST TMP3219[7] = {
"dMon", 
"dTue", 
"dWed", 
"dThu", 
"dFri", 
"dSat", 
"dSun"};
static TNimNode TMP15[33];
NTI107405.size = sizeof(Timeinfo107405);
NTI107405.kind = 17;
NTI107405.base = (&NTI3411);
TMP3214[0] = &TMP15[1];
NTI107408.size = sizeof(NI);
NTI107408.kind = 20;
NTI107408.base = (&NTI108);
NTI107408.flags = 3;
TMP15[1].kind = 1;
TMP15[1].offset = offsetof(Timeinfo107405, second);
TMP15[1].typ = (&NTI107408);
TMP15[1].name = "second";
TMP3214[1] = &TMP15[2];
NTI107410.size = sizeof(NI);
NTI107410.kind = 20;
NTI107410.base = (&NTI108);
NTI107410.flags = 3;
TMP15[2].kind = 1;
TMP15[2].offset = offsetof(Timeinfo107405, minute);
TMP15[2].typ = (&NTI107410);
TMP15[2].name = "minute";
TMP3214[2] = &TMP15[3];
NTI107412.size = sizeof(NI);
NTI107412.kind = 20;
NTI107412.base = (&NTI108);
NTI107412.flags = 3;
TMP15[3].kind = 1;
TMP15[3].offset = offsetof(Timeinfo107405, hour);
TMP15[3].typ = (&NTI107412);
TMP15[3].name = "hour";
TMP3214[3] = &TMP15[4];
NTI107415.size = sizeof(NI);
NTI107415.kind = 20;
NTI107415.base = (&NTI108);
NTI107415.flags = 3;
TMP15[4].kind = 1;
TMP15[4].offset = offsetof(Timeinfo107405, monthday);
TMP15[4].typ = (&NTI107415);
TMP15[4].name = "monthday";
TMP3214[4] = &TMP15[5];
NTI104006.size = sizeof(NU8);
NTI104006.kind = 14;
NTI104006.base = 0;
NTI104006.flags = 3;
for (TMP3217 = 0; TMP3217 < 12; TMP3217++) {
TMP15[TMP3217+6].kind = 1;
TMP15[TMP3217+6].offset = TMP3217;
TMP15[TMP3217+6].name = TMP3216[TMP3217];
TMP3215[TMP3217] = &TMP15[TMP3217+6];
}
TMP15[18].len = 12; TMP15[18].kind = 2; TMP15[18].sons = &TMP3215[0];
NTI104006.node = &TMP15[18];
TMP15[5].kind = 1;
TMP15[5].offset = offsetof(Timeinfo107405, month);
TMP15[5].typ = (&NTI104006);
TMP15[5].name = "month";
TMP3214[5] = &TMP15[19];
NTI107418.size = sizeof(NI);
NTI107418.kind = 20;
NTI107418.base = (&NTI108);
NTI107418.flags = 3;
TMP15[19].kind = 1;
TMP15[19].offset = offsetof(Timeinfo107405, year);
TMP15[19].typ = (&NTI107418);
TMP15[19].name = "year";
TMP3214[6] = &TMP15[20];
NTI104008.size = sizeof(NU8);
NTI104008.kind = 14;
NTI104008.base = 0;
NTI104008.flags = 3;
for (TMP3220 = 0; TMP3220 < 7; TMP3220++) {
TMP15[TMP3220+21].kind = 1;
TMP15[TMP3220+21].offset = TMP3220;
TMP15[TMP3220+21].name = TMP3219[TMP3220];
TMP3218[TMP3220] = &TMP15[TMP3220+21];
}
TMP15[28].len = 7; TMP15[28].kind = 2; TMP15[28].sons = &TMP3218[0];
NTI104008.node = &TMP15[28];
TMP15[20].kind = 1;
TMP15[20].offset = offsetof(Timeinfo107405, weekday);
TMP15[20].typ = (&NTI104008);
TMP15[20].name = "weekday";
TMP3214[7] = &TMP15[29];
NTI107424.size = sizeof(NI);
NTI107424.kind = 20;
NTI107424.base = (&NTI108);
NTI107424.flags = 3;
TMP15[29].kind = 1;
TMP15[29].offset = offsetof(Timeinfo107405, yearday);
TMP15[29].typ = (&NTI107424);
TMP15[29].name = "yearday";
TMP3214[8] = &TMP15[30];
TMP15[30].kind = 1;
TMP15[30].offset = offsetof(Timeinfo107405, isdst);
TMP15[30].typ = (&NTI138);
TMP15[30].name = "isDST";
TMP3214[9] = &TMP15[31];
TMP15[31].kind = 1;
TMP15[31].offset = offsetof(Timeinfo107405, tzname);
TMP15[31].typ = (&NTI149);
TMP15[31].name = "tzname";
TMP3214[10] = &TMP15[32];
TMP15[32].kind = 1;
TMP15[32].offset = offsetof(Timeinfo107405, timezone);
TMP15[32].typ = (&NTI108);
TMP15[32].name = "timezone";
TMP15[0].len = 11; TMP15[0].kind = 2; TMP15[0].sons = &TMP3214[0];
NTI107405.node = &TMP15[0];
}

