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

#include <string.h>

#include "winsock2.h"
typedef struct Tguid106614 Tguid106614;
typedef struct TGenericSeq TGenericSeq;
typedef struct NimStringDesc NimStringDesc;
typedef struct Twin32finddata105219 Twin32finddata105219;
typedef struct Tfiletime104248 Tfiletime104248;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Tsecurityattributes104242 Tsecurityattributes104242;
typedef struct Tstartupinfo104244 Tstartupinfo104244;
typedef struct Tprocessinformation104246 Tprocessinformation104246;
typedef struct Addrinfo105868 Addrinfo105868;
typedef struct Tfdset105864 Tfdset105864;
typedef struct Timeval105866 Timeval105866;
typedef NI8 TY106627[8];
struct  Tguid106614  {
NI32 D1;
NI16 D2;
NI16 D3;
TY106627 D4;
};
typedef NI8 TY106708[8];
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef N_STDCALL_PTR(int, TY106236) (NI16 wversionrequired, WSADATA* Wsdata);
typedef N_STDCALL_PTR(NI32, TY104663) (NI32 dwflags, void* lpsource, NI32 dwmessageid, NI32 dwlanguageid, void* lpbuffer, NI32 nsize, void* Arguments);
typedef N_STDCALL_PTR(void, TY104805) (void* p);
typedef N_STDCALL_PTR(NI32, TY104658) (void);
typedef N_STDCALL_PTR(NI32, TY105411) (NI16* lpfilename, NI32 nbufferlength, NI16* lpbuffer, NI16** lpfilepart);
typedef N_STDCALL_PTR(NI32, TY104829) (NI handle, NI16* buf, NI32 size);
typedef N_STDCALL_PTR(NI, TY105240) (NI16* lpfilename, Twin32finddata105219* lpfindfiledata);
typedef N_STDCALL_PTR(NI32, TY105245) (NI hfindfile, Twin32finddata105219* lpfindfiledata);
typedef N_STDCALL_PTR(void, TY105405) (NI hfindfile);
typedef N_STDCALL_PTR(NI32, TY104818) (NI16* pathname, void* security);
typedef N_STDCALL_PTR(NI, TY106318) (NI16* lpfilename, NI32 dwdesiredaccess, NI32 dwsharemode, void* lpsecurityattributes, NI32 dwcreationdisposition, NI32 dwflagsandattributes, NI htemplatefile);
typedef N_STDCALL_PTR(NI32, TY104425) (NI hobject);
typedef N_STDCALL_PTR(NI32, TY106411) (NI hfile, NI32 ldistancetomove, NI32* lpdistancetomovehigh, NI32 dwmovemethod);
typedef N_STDCALL_PTR(NI32, TY106405) (NI hfile);
typedef N_STDCALL_PTR(NI, TY106440) (NI hfile, void* lpfilemappingattributes, NI32 flprotect, NI32 dwmaximumsizehigh, NI32 dwmaximumsizelow, void* lpname);
typedef N_STDCALL_PTR(void*, TY106429) (NI hfilemappingobject, NI32 dwdesiredaccess, NI32 dwfileoffsethigh, NI32 dwfileoffsetlow, NI32 dwnumberofbytestomap, void* lpbaseaddress);
typedef N_STDCALL_PTR(NI32, TY106421) (NI hfile, NI32* lpfilesizehigh);
typedef N_STDCALL_PTR(NI32, TY105418) (NI16* lpfilename);
typedef N_STDCALL_PTR(NI32, TY106602) (void* lpbaseaddress);
typedef N_STDCALL_PTR(NI16*, TY105440) (void);
typedef N_STDCALL_PTR(NI16*, TY105435) (void);
typedef N_STDCALL_PTR(NI32, TY105437) (NI16* para1);
typedef N_STDCALL_PTR(NI32, TY104825) (NI16* lpname, NI16* lpvalue);
typedef N_STDCALL_PTR(NI32, TY104811) (NI32 nbufferlength, NI16* lpbuffer);
typedef N_STDCALL_PTR(void, TY105625) (Tfiletime104248* lpsystemtimeasfiletime);
struct  Tfiletime104248  {
NI32 dwlowdatetime;
NI32 dwhighdatetime;
};
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;
};
typedef N_STDCALL_PTR(NI32, TY104453) (NI* hreadpipe, NI* hwritepipe, Tsecurityattributes104242* lppipeattributes, NI32 nsize);
typedef N_STDCALL_PTR(NI, TY104639) (NI32 nstdhandle);
typedef N_STDCALL_PTR(NI32, TY104464) (NI16* lpapplicationname, NI16* lpcommandline, Tsecurityattributes104242* lpprocessattributes, Tsecurityattributes104242* lpthreadattributes, NI32 binherithandles, NI32 dwcreationflags, NI16* lpenvironment, NI16* lpcurrentdirectory, Tstartupinfo104244* lpstartupinfo, Tprocessinformation104246* lpprocessinformation);
typedef N_STDCALL_PTR(NI32, TY104431) (NI hfile, void* Buffer, NI32 nnumberofbytestoread, NI32* lpnumberofbytesread, void* lpoverlapped);
typedef N_STDCALL_PTR(NI32, TY104442) (NI hfile, void* Buffer, NI32 nnumberofbytestowrite, NI32* lpnumberofbyteswritten, void* lpoverlapped);
typedef N_STDCALL_PTR(NI32, TY104617) (NI hhandle, NI32 dwmilliseconds);
typedef N_STDCALL_PTR(NI32, TY104631) (NI hprocess, NI32* lpexitcode);
typedef N_STDCALL_PTR(void, TY105632) (NI32 dwmilliseconds);
typedef N_STDCALL_PTR(NI, TY106024) (int af, int typ, int protocol);
typedef N_STDCALL_PTR(int, TY106048) (NI s, SOCKADDR* name, unsigned int namelen);
typedef N_STDCALL_PTR(int, TY106244) (NCSTRING nodename, NCSTRING servname, Addrinfo105868* hints, Addrinfo105868** res);
typedef N_STDCALL_PTR(void, TY106256) (Addrinfo105868* ai);
typedef N_STDCALL_PTR(int, TY106097) (NI s, int backlog);
typedef N_STDCALL_PTR(int, TY106138) (NI s, void* buf, int len, int flags);
typedef N_STDCALL_PTR(NI, TY106038) (NI s, SOCKADDR* a, unsigned int* addrlen);
typedef N_STDCALL_PTR(NCSTRING, TY106263) (IN_ADDR i);
typedef NI TY105915[64];
struct  Tfdset105864  {
int fdcount;
TY105915 fdarray;
};
typedef N_STDCALL_PTR(int, TY106126) (int nfds, Tfdset105864* readfds, Tfdset105864* writefds, Tfdset105864* exceptfds, Timeval105866* timeout);
typedef N_STDCALL_PTR(NIM_BOOL, TY106185) (NI s, Tfdset105864* set);
typedef N_STDCALL_PTR(int, TY106104) (NI s, void* buf, int len, int flags);
typedef N_STDCALL_PTR(int, TY106032) (NI s);
typedef NIM_CHAR TY105873[257];
typedef NIM_CHAR TY105876[129];
typedef NI16 TY105228[260];
typedef NI16 TY105232[14];
struct  Twin32finddata105219  {
NI32 dwfileattributes;
Tfiletime104248 ftcreationtime;
Tfiletime104248 ftlastaccesstime;
Tfiletime104248 ftlastwritetime;
NI32 nfilesizehigh;
NI32 nfilesizelow;
NI32 dwreserved0;
NI32 dwreserved1;
TY105228 cfilename;
TY105232 calternatefilename;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  Tsecurityattributes104242  {
NI32 nlength;
void* lpsecuritydescriptor;
NI32 binherithandle;
};
struct  Tstartupinfo104244  {
NI32 cb;
NCSTRING lpreserved;
NCSTRING lpdesktop;
NCSTRING lptitle;
NI32 dwx;
NI32 dwy;
NI32 dwxsize;
NI32 dwysize;
NI32 dwxcountchars;
NI32 dwycountchars;
NI32 dwfillattribute;
NI32 dwflags;
NI16 wshowwindow;
NI16 cbreserved2;
void* lpreserved2;
NI hstdinput;
NI hstdoutput;
NI hstderror;
};
struct  Tprocessinformation104246  {
NI hprocess;
NI hthread;
NI32 dwprocessid;
NI32 dwthreadid;
};
typedef NIM_CHAR TY105883[14];
struct  Addrinfo105868  {
int aiflags;
int aifamily;
int aisocktype;
int aiprotocol;
NI aiaddrlen;
NCSTRING aicanonname;
SOCKADDR* aiaddr;
Addrinfo105868* ainext;
};
struct  Timeval105866  {
NI32 tvsec;
NI32 tvusec;
};
N_NIMCALL(void*, nimLoadLibrary)(NimStringDesc* path);
N_NOINLINE(void, nimLoadLibraryError)(NimStringDesc* path);
N_NIMCALL(void*, nimGetProcAddr)(void* lib, NCSTRING name);
NIM_CONST TY106708 TMP19 = {((NI8) -114),
((NI8) -23),
((NI8) 118),
((NI8) -27),
((NI8) -116),
((NI8) 116),
((NI8) 6),
((NI8) 62)}
;
NIM_CONST TY106708 TMP20 = {((NI8) -107),
((NI8) -54),
((NI8) 0),
((NI8) -128),
((NI8) 95),
((NI8) 72),
((NI8) -95),
((NI8) -110)}
;
STRING_LITERAL(TMP1079, "Ws2_32.dll", 10);
STRING_LITERAL(TMP1080, "Ws2_32.dll", 10);
STRING_LITERAL(TMP1086, "kernel32", 8);
STRING_LITERAL(TMP1087, "kernel32", 8);
Tguid106614 Wsaidconnectex_106710;
Tguid106614 Wsaidacceptex_106714;
Tguid106614 Wsaidgetacceptexsockaddrs_106718;
static void* TMP1078;
TY106236 Dl_106235;
static void* TMP1085;
TY104663 Dl_104662;
TY104805 Dl_104804;
TY104658 Dl_104657;
TY105411 Dl_105410;
TY104829 Dl_104828;
TY105240 Dl_105239;
TY105245 Dl_105244;
TY105405 Dl_105404;
TY104818 Dl_104817;
TY106318 Dl_106317;
TY104425 Dl_104424;
TY106411 Dl_106410;
TY106405 Dl_106404;
TY106440 Dl_106439;
TY106429 Dl_106428;
TY106421 Dl_106420;
TY105418 Dl_105417;
TY106602 Dl_106601;
TY105440 Dl_105439;
TY105435 Dl_105434;
TY105437 Dl_105436;
TY104825 Dl_104824;
TY104811 Dl_104810;
TY105625 Dl_105624;
TNimType NTI104222; /* THandle */
TY104453 Dl_104452;
TY104639 Dl_104638;
TY104464 Dl_104463;
TY104431 Dl_104430;
TY104442 Dl_104441;
TY104617 Dl_104616;
TY104631 Dl_104630;
TY105632 Dl_105631;
TY106024 Dl_106023;
TY106048 Dl_106047;
TY106244 Dl_106243;
TY106256 Dl_106255;
TY106097 Dl_106096;
TY106138 Dl_106137;
TY106038 Dl_106037;
TY106263 Dl_106262;
TY106126 Dl_106125;
TY106185 Dl_106184;
TY106104 Dl_106103;
TY106032 Dl_106031;

N_NIMCALL(NI64, rdfiletime_105604)(Tfiletime104248 f) {
	NI64 result;
	result = 0;
	result = (NI64)(((NI64)(NU64)(NU32)(f.dwlowdatetime)) | (NI64)((NU64)(((NI64)(NU64)(NU32)(f.dwhighdatetime))) << (NU64)(IL64(32))));
	return result;
}

N_NIMCALL(void, Fdzero_106225)(Tfdset105864* s) {
	(*s).fdcount = ((int) 0);
}

N_NIMCALL(void, Fdset_106204)(NI socket, Tfdset105864* s) {
	{
		if (!((*s).fdcount < ((NI32) 64))) goto LA3;
		(*s).fdarray[(((NI) ((*s).fdcount)))- 0] = socket;
		(*s).fdcount += ((NI) 1);
	}
	LA3: ;
}

N_NIMCALL(int, Fdisset_106192)(NI socket, Tfdset105864* set) {
	int result;
	result = 0;
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = Dl_106184(socket, set);
		if (!LOC3) goto LA4;
		result = ((NI32) 1);
	}
	goto LA1;
	LA4: ;
	{
		result = ((NI32) 0);
	}
	LA1: ;
	return result;
}
NIM_EXTERNC N_NOINLINE(void, stdlib_winleanInit)(void) {
	Tguid106614 LOC1;
	Tguid106614 LOC2;
	Tguid106614 LOC3;
	memset((void*)(&LOC1), 0, sizeof(LOC1));
	LOC1.D1 = ((NI32) 631375801);
	LOC1.D2 = ((NI16) -8717);
	LOC1.D3 = ((NI16) 18016);
	memcpy((void*)LOC1.D4, (NIM_CONST void*)TMP19, sizeof(LOC1.D4));
	Wsaidconnectex_106710 = LOC1;
	memset((void*)(&LOC2), 0, sizeof(LOC2));
	LOC2.D1 = ((NI32) -1254720015);
	LOC2.D2 = ((NI16) -13396);
	LOC2.D3 = ((NI16) 4559);
	memcpy((void*)LOC2.D4, (NIM_CONST void*)TMP20, sizeof(LOC2.D4));
	Wsaidacceptex_106714 = LOC2;
	memset((void*)(&LOC3), 0, sizeof(LOC3));
	LOC3.D1 = ((NI32) -1254720014);
	LOC3.D2 = ((NI16) -13396);
	LOC3.D3 = ((NI16) 4559);
	memcpy((void*)LOC3.D4, (NIM_CONST void*)TMP20, sizeof(LOC3.D4));
	Wsaidgetacceptexsockaddrs_106718 = LOC3;
}

NIM_EXTERNC N_NOINLINE(void, stdlib_winleanDatInit)(void) {
NTI104222.size = sizeof(NI);
NTI104222.kind = 31;
NTI104222.base = 0;
NTI104222.flags = 3;
if (!((TMP1078 = nimLoadLibrary((NimStringDesc*) &TMP1079))
)) nimLoadLibraryError((NimStringDesc*) &TMP1080);
	Dl_106235 = (TY106236) nimGetProcAddr(TMP1078, "WSAStartup");
if (!((TMP1085 = nimLoadLibrary((NimStringDesc*) &TMP1086))
)) nimLoadLibraryError((NimStringDesc*) &TMP1087);
	Dl_104662 = (TY104663) nimGetProcAddr(TMP1085, "FormatMessageW");
	Dl_104804 = (TY104805) nimGetProcAddr(TMP1085, "LocalFree");
	Dl_104657 = (TY104658) nimGetProcAddr(TMP1085, "GetLastError");
	Dl_105410 = (TY105411) nimGetProcAddr(TMP1085, "GetFullPathNameW");
	Dl_104828 = (TY104829) nimGetProcAddr(TMP1085, "GetModuleFileNameW");
	Dl_105239 = (TY105240) nimGetProcAddr(TMP1085, "FindFirstFileW");
	Dl_105244 = (TY105245) nimGetProcAddr(TMP1085, "FindNextFileW");
	Dl_105404 = (TY105405) nimGetProcAddr(TMP1085, "FindClose");
	Dl_104817 = (TY104818) nimGetProcAddr(TMP1085, "CreateDirectoryW");
	Dl_106317 = (TY106318) nimGetProcAddr(TMP1085, "CreateFileW");
	Dl_104424 = (TY104425) nimGetProcAddr(TMP1085, "CloseHandle");
	Dl_106410 = (TY106411) nimGetProcAddr(TMP1085, "SetFilePointer");
	Dl_106404 = (TY106405) nimGetProcAddr(TMP1085, "SetEndOfFile");
	Dl_106439 = (TY106440) nimGetProcAddr(TMP1085, "CreateFileMappingW");
	Dl_106428 = (TY106429) nimGetProcAddr(TMP1085, "MapViewOfFileEx");
	Dl_106420 = (TY106421) nimGetProcAddr(TMP1085, "GetFileSize");
	Dl_105417 = (TY105418) nimGetProcAddr(TMP1085, "GetFileAttributesW");
	Dl_106601 = (TY106602) nimGetProcAddr(TMP1085, "UnmapViewOfFile");
	Dl_105439 = (TY105440) nimGetProcAddr(TMP1085, "GetCommandLineW");
	Dl_105434 = (TY105435) nimGetProcAddr(TMP1085, "GetEnvironmentStringsW");
	Dl_105436 = (TY105437) nimGetProcAddr(TMP1085, "FreeEnvironmentStringsW");
	Dl_104824 = (TY104825) nimGetProcAddr(TMP1085, "SetEnvironmentVariableW");
	Dl_104810 = (TY104811) nimGetProcAddr(TMP1085, "GetCurrentDirectoryW");
	Dl_105624 = (TY105625) nimGetProcAddr(TMP1085, "GetSystemTimeAsFileTime");
	Dl_104452 = (TY104453) nimGetProcAddr(TMP1085, "CreatePipe");
	Dl_104638 = (TY104639) nimGetProcAddr(TMP1085, "GetStdHandle");
	Dl_104463 = (TY104464) nimGetProcAddr(TMP1085, "CreateProcessW");
	Dl_104430 = (TY104431) nimGetProcAddr(TMP1085, "ReadFile");
	Dl_104441 = (TY104442) nimGetProcAddr(TMP1085, "WriteFile");
	Dl_104616 = (TY104617) nimGetProcAddr(TMP1085, "WaitForSingleObject");
	Dl_104630 = (TY104631) nimGetProcAddr(TMP1085, "GetExitCodeProcess");
	Dl_105631 = (TY105632) nimGetProcAddr(TMP1085, "Sleep");
	Dl_106023 = (TY106024) nimGetProcAddr(TMP1078, "socket");
	Dl_106047 = (TY106048) nimGetProcAddr(TMP1078, "bind");
	Dl_106243 = (TY106244) nimGetProcAddr(TMP1078, "getaddrinfo");
	Dl_106255 = (TY106256) nimGetProcAddr(TMP1078, "freeaddrinfo");
	Dl_106096 = (TY106097) nimGetProcAddr(TMP1078, "listen");
	Dl_106137 = (TY106138) nimGetProcAddr(TMP1078, "send");
	Dl_106037 = (TY106038) nimGetProcAddr(TMP1078, "accept");
	Dl_106262 = (TY106263) nimGetProcAddr(TMP1078, "inet_ntoa");
	Dl_106125 = (TY106126) nimGetProcAddr(TMP1078, "select");
	Dl_106184 = (TY106185) nimGetProcAddr(TMP1078, "__WSAFDIsSet");
	Dl_106103 = (TY106104) nimGetProcAddr(TMP1078, "recv");
	Dl_106031 = (TY106032) nimGetProcAddr(TMP1078, "closesocket");
}

