/* 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 <string.h>
#include "winsock2.h"
typedef struct Guid108611 Guid108611;
typedef struct TGenericSeq TGenericSeq;
typedef struct NimStringDesc NimStringDesc;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Win32finddata107213 Win32finddata107213;
typedef struct Securityattributes106249 Securityattributes106249;
typedef struct Startupinfo106251 Startupinfo106251;
typedef struct Processinformation106253 Processinformation106253;
typedef struct Filetime106255 Filetime106255;
typedef struct Addrinfo107850 Addrinfo107850;
typedef struct Tfdset107846 Tfdset107846;
typedef struct Timeval107848 Timeval107848;
typedef NI8 TY108625[8];
struct  Guid108611  {
NI32 D1;
NI16 D2;
NI16 D3;
TY108625 D4;
};
typedef NI8 TY108689[8];
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef N_STDCALL_PTR(NI, TY106621) (NI32 nstdhandle);
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;
};
typedef N_STDCALL_PTR(int, TY108129) (NI16 wversionrequired, WSADATA* Wsdata);
typedef N_STDCALL_PTR(NI32, TY106633) (NI32 dwflags, void* lpsource, NI32 dwmessageid, NI32 dwlanguageid, void* lpbuffer, NI32 nsize, void* Arguments);
typedef N_STDCALL_PTR(void, TY106802) (void* p);
typedef N_STDCALL_PTR(NI32, TY106631) (void);
typedef N_STDCALL_PTR(NI32, TY107405) (NI16* lpfilename, NI32 nbufferlength, NI16* lpbuffer, NI16** lpfilepart);
typedef N_STDCALL_PTR(NI32, TY106823) (NI handle, NI16* buf, NI32 size);
typedef N_STDCALL_PTR(NI, TY107231) (NI16* lpfilename, Win32finddata107213* lpfindfiledata);
typedef N_STDCALL_PTR(NI32, TY107236) (NI hfindfile, Win32finddata107213* lpfindfiledata);
typedef N_STDCALL_PTR(void, TY107402) (NI hfindfile);
typedef N_STDCALL_PTR(NI32, TY106812) (NI16* pathname, void* security);
typedef N_STDCALL_PTR(NI, TY108206) (NI16* lpfilename, NI32 dwdesiredaccess, NI32 dwsharemode, void* lpsecurityattributes, NI32 dwcreationdisposition, NI32 dwflagsandattributes, NI htemplatefile);
typedef N_STDCALL_PTR(NI32, TY106426) (NI hobject);
typedef N_STDCALL_PTR(NI32, TY108405) (NI hfile, NI32 ldistancetomove, NI32* lpdistancetomovehigh, NI32 dwmovemethod);
typedef N_STDCALL_PTR(NI32, TY108402) (NI hfile);
typedef N_STDCALL_PTR(NI, TY108425) (NI hfile, void* lpfilemappingattributes, NI32 flprotect, NI32 dwmaximumsizehigh, NI32 dwmaximumsizelow, void* lpname);
typedef N_STDCALL_PTR(void*, TY108417) (NI hfilemappingobject, NI32 dwdesiredaccess, NI32 dwfileoffsethigh, NI32 dwfileoffsetlow, NI32 dwnumberofbytestomap, void* lpbaseaddress);
typedef N_STDCALL_PTR(NI32, TY108412) (NI hfile, NI32* lpfilesizehigh);
typedef N_STDCALL_PTR(NI32, TY107412) (NI16* lpfilename);
typedef N_STDCALL_PTR(NI32, TY108602) (void* lpbaseaddress);
typedef N_STDCALL_PTR(NI16*, TY107434) (void);
typedef N_STDCALL_PTR(NI16*, TY107429) (void);
typedef N_STDCALL_PTR(NI32, TY107431) (NI16* para1);
typedef N_STDCALL_PTR(NI32, TY106819) (NI16* lpname, NI16* lpvalue);
typedef N_STDCALL_PTR(NI32, TY106805) (NI32 nbufferlength, NI16* lpbuffer);
typedef N_STDCALL_PTR(NI32, TY106445) (NI* hreadpipe, NI* hwritepipe, Securityattributes106249* lppipeattributes, NI32 nsize);
typedef N_STDCALL_PTR(NI, TY106453) (NI16* lpname, NI32 dwopenmode, NI32 dwpipemode, NI32 nmaxinstances, NI32 noutbuffersize, NI32 ninbuffersize, NI32 ndefaulttimeout, Securityattributes106249* lpsecurityattributes);
typedef N_STDCALL_PTR(NI, TY108204) (void);
typedef N_STDCALL_PTR(NI32, TY108194) (NI hsourceprocesshandle, NI hsourcehandle, NI htargetprocesshandle, NI* lptargethandle, NI32 dwdesiredaccess, NI32 binherithandle, NI32 dwoptions);
typedef N_STDCALL_PTR(NI32, TY106475) (NI16* lpapplicationname, NI16* lpcommandline, Securityattributes106249* lpprocessattributes, Securityattributes106249* lpthreadattributes, NI32 binherithandles, NI32 dwcreationflags, NI16* lpenvironment, NI16* lpcurrentdirectory, Startupinfo106251* lpstartupinfo, Processinformation106253* lpprocessinformation);
typedef N_STDCALL_PTR(NI32, TY106429) (NI hfile, void* Buffer, NI32 nnumberofbytestoread, NI32* lpnumberofbytesread, void* lpoverlapped);
typedef N_STDCALL_PTR(NI32, TY106437) (NI hfile, void* Buffer, NI32 nnumberofbytestowrite, NI32* lpnumberofbyteswritten, void* lpoverlapped);
typedef N_STDCALL_PTR(NI32, TY106608) (NI hhandle, NI32 dwmilliseconds);
typedef N_STDCALL_PTR(NI32, TY106616) (NI hprocess, NI32* lpexitcode);
typedef N_STDCALL_PTR(NI32, TY108215) (NI16* pathname);
typedef N_STDCALL_PTR(NI32, TY107415) (NI16* lpfilename, NI32 dwfileattributes);
typedef N_STDCALL_PTR(NI32, TY106816) (NI16* lppathname);
typedef N_STDCALL_PTR(NI32, TY106809) (NI16* lppathname);
typedef N_STDCALL_PTR(int, TY107424) (NI16* lpexistingfilename, NI16* lpnewfilename, int bfailifexists);
typedef N_STDCALL_PTR(int, TY107419) (NI16* lpexistingfilename, NI16* lpnewfilename, int bfailifexists);
struct  Filetime106255  {
NI32 dwlowdatetime;
NI32 dwhighdatetime;
};
typedef N_STDCALL_PTR(void, TY107610) (Filetime106255* lpsystemtimeasfiletime);
typedef N_STDCALL_PTR(void, TY107614) (NI32 dwmilliseconds);
typedef N_STDCALL_PTR(NI, TY107982) (int af, int typ, int protocol);
typedef N_STDCALL_PTR(int, TY107997) (NI s, SOCKADDR* name, unsigned int namelen);
typedef N_STDCALL_PTR(int, TY108134) (NCSTRING nodename, NCSTRING servname, Addrinfo107850* hints, Addrinfo107850** res);
typedef N_STDCALL_PTR(void, TY108143) (Addrinfo107850* ai);
typedef N_STDCALL_PTR(int, TY108038) (NI s, int backlog);
typedef N_STDCALL_PTR(int, TY108067) (NI s, void* buf, int len, int flags);
typedef N_STDCALL_PTR(NI, TY107990) (NI s, SOCKADDR* a, unsigned int* addrlen);
typedef N_STDCALL_PTR(NCSTRING, TY108147) (IN_ADDR i);
typedef NI TY107898[64];
struct  Tfdset107846  {
int fdcount;
TY107898 fdarray;
};
typedef N_STDCALL_PTR(int, TY108058) (int nfds, Tfdset107846* readfds, Tfdset107846* writefds, Tfdset107846* exceptfds, Timeval107848* timeout);
typedef N_STDCALL_PTR(NIM_BOOL, TY108099) (NI s, Tfdset107846* set);
typedef N_STDCALL_PTR(int, TY108042) (NI s, void* buf, int len, int flags);
typedef N_STDCALL_PTR(int, TY107987) (NI s);
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
typedef NIM_CHAR TY107856[257];
typedef NIM_CHAR TY107859[129];
typedef NI16 TY107224[260];
typedef NI16 TY107227[14];
struct  Win32finddata107213  {
NI32 dwfileattributes;
Filetime106255 ftcreationtime;
Filetime106255 ftlastaccesstime;
Filetime106255 ftlastwritetime;
NI32 nfilesizehigh;
NI32 nfilesizelow;
NI32 dwreserved0;
NI32 dwreserved1;
TY107224 cfilename;
TY107227 calternatefilename;
};
struct  Securityattributes106249  {
NI32 nlength;
void* lpsecuritydescriptor;
NI32 binherithandle;
};
struct  Startupinfo106251  {
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  Processinformation106253  {
NI hprocess;
NI hthread;
NI32 dwprocessid;
NI32 dwthreadid;
};
typedef NIM_CHAR TY107866[14];
struct  Addrinfo107850  {
int aiflags;
int aifamily;
int aisocktype;
int aiprotocol;
NI aiaddrlen;
NCSTRING aicanonname;
SOCKADDR* aiaddr;
Addrinfo107850* ainext;
};
struct  Timeval107848  {
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 TY108689 TMP19 = {((NI8) -114),
((NI8) -23),
((NI8) 118),
((NI8) -27),
((NI8) -116),
((NI8) 116),
((NI8) 6),
((NI8) 62)}
;
NIM_CONST TY108689 TMP20 = {((NI8) -107),
((NI8) -54),
((NI8) 0),
((NI8) -128),
((NI8) 95),
((NI8) 72),
((NI8) -95),
((NI8) -110)}
;
STRING_LITERAL(TMP139, "kernel32", 8);
STRING_LITERAL(TMP140, "kernel32", 8);
STRING_LITERAL(TMP1204, "Ws2_32.dll", 10);
STRING_LITERAL(TMP1205, "Ws2_32.dll", 10);
Guid108611 Wsaidconnectex_108691;
Guid108611 Wsaidacceptex_108695;
Guid108611 Wsaidgetacceptexsockaddrs_108699;
static void* TMP138;
TY106621 Dl_106620;
TNimType NTI106229; /* Handle */
static void* TMP1203;
TY108129 Dl_108128;
TY106633 Dl_106632;
TY106802 Dl_106801;
TY106631 Dl_106630;
TY107405 Dl_107404;
TY106823 Dl_106822;
TY107231 Dl_107230;
TY107236 Dl_107235;
TY107402 Dl_107401;
TY106812 Dl_106811;
TY108206 Dl_108205;
TY106426 Dl_106425;
TY108405 Dl_108404;
TY108402 Dl_108401;
TY108425 Dl_108424;
TY108417 Dl_108416;
TY108412 Dl_108411;
TY107412 Dl_107411;
TY108602 Dl_108601;
TY107434 Dl_107433;
TY107429 Dl_107428;
TY107431 Dl_107430;
TY106819 Dl_106818;
TY106805 Dl_106804;
TY106445 Dl_106444;
TY106453 Dl_106452;
TY108204 Dl_108203;
TY108194 Dl_108193;
TY106475 Dl_106474;
TY106429 Dl_106428;
TY106437 Dl_106436;
TY106608 Dl_106607;
TY106616 Dl_106615;
TY108215 Dl_108214;
TY107415 Dl_107414;
TY106816 Dl_106815;
TY106809 Dl_106808;
TY107424 Dl_107423;
TY107419 Dl_107418;
TY107610 Dl_107609;
TY107614 Dl_107613;
TY107982 Dl_107981;
TY107997 Dl_107996;
TY108134 Dl_108133;
TY108143 Dl_108142;
TY108038 Dl_108037;
TY108067 Dl_108066;
TY107990 Dl_107989;
TY108147 Dl_108146;
TY108058 Dl_108057;
TY108099 Dl_108098;
TY108042 Dl_108041;
TY107987 Dl_107986;

N_NIMCALL(NI64, rdfiletime_107601)(Filetime106255 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_108124)(Tfdset107846* s) {
	(*s).fdcount = ((int) 0);
}

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

N_NIMCALL(int, Fdisset_108103)(NI socket, Tfdset107846* set) {
	int result;
	result = 0;
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = Dl_108098(socket, set);
		if (!LOC3) goto LA4;
		result = ((NI32) 1);
	}
	goto LA1;
	LA4: ;
	{
		result = ((NI32) 0);
	}
	LA1: ;
	return result;
}
NIM_EXTERNC N_NOINLINE(void, stdlib_winleanInit000)(void) {
	Guid108611 LOC1;
	Guid108611 LOC2;
	Guid108611 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(TY108625));
	Wsaidconnectex_108691 = 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(TY108625));
	Wsaidacceptex_108695 = 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(TY108625));
	Wsaidgetacceptexsockaddrs_108699 = LOC3;
}

NIM_EXTERNC N_NOINLINE(void, stdlib_winleanDatInit000)(void) {
NTI106229.size = sizeof(NI);
NTI106229.kind = 31;
NTI106229.base = 0;
NTI106229.flags = 3;
if (!((TMP138 = nimLoadLibrary((NimStringDesc*) &TMP139))
)) nimLoadLibraryError((NimStringDesc*) &TMP140);
	Dl_106620 = (TY106621) nimGetProcAddr(TMP138, "GetStdHandle");
if (!((TMP1203 = nimLoadLibrary((NimStringDesc*) &TMP1204))
)) nimLoadLibraryError((NimStringDesc*) &TMP1205);
	Dl_108128 = (TY108129) nimGetProcAddr(TMP1203, "WSAStartup");
	Dl_106632 = (TY106633) nimGetProcAddr(TMP138, "FormatMessageW");
	Dl_106801 = (TY106802) nimGetProcAddr(TMP138, "LocalFree");
	Dl_106630 = (TY106631) nimGetProcAddr(TMP138, "GetLastError");
	Dl_107404 = (TY107405) nimGetProcAddr(TMP138, "GetFullPathNameW");
	Dl_106822 = (TY106823) nimGetProcAddr(TMP138, "GetModuleFileNameW");
	Dl_107230 = (TY107231) nimGetProcAddr(TMP138, "FindFirstFileW");
	Dl_107235 = (TY107236) nimGetProcAddr(TMP138, "FindNextFileW");
	Dl_107401 = (TY107402) nimGetProcAddr(TMP138, "FindClose");
	Dl_106811 = (TY106812) nimGetProcAddr(TMP138, "CreateDirectoryW");
	Dl_108205 = (TY108206) nimGetProcAddr(TMP138, "CreateFileW");
	Dl_106425 = (TY106426) nimGetProcAddr(TMP138, "CloseHandle");
	Dl_108404 = (TY108405) nimGetProcAddr(TMP138, "SetFilePointer");
	Dl_108401 = (TY108402) nimGetProcAddr(TMP138, "SetEndOfFile");
	Dl_108424 = (TY108425) nimGetProcAddr(TMP138, "CreateFileMappingW");
	Dl_108416 = (TY108417) nimGetProcAddr(TMP138, "MapViewOfFileEx");
	Dl_108411 = (TY108412) nimGetProcAddr(TMP138, "GetFileSize");
	Dl_107411 = (TY107412) nimGetProcAddr(TMP138, "GetFileAttributesW");
	Dl_108601 = (TY108602) nimGetProcAddr(TMP138, "UnmapViewOfFile");
	Dl_107433 = (TY107434) nimGetProcAddr(TMP138, "GetCommandLineW");
	Dl_107428 = (TY107429) nimGetProcAddr(TMP138, "GetEnvironmentStringsW");
	Dl_107430 = (TY107431) nimGetProcAddr(TMP138, "FreeEnvironmentStringsW");
	Dl_106818 = (TY106819) nimGetProcAddr(TMP138, "SetEnvironmentVariableW");
	Dl_106804 = (TY106805) nimGetProcAddr(TMP138, "GetCurrentDirectoryW");
	Dl_106444 = (TY106445) nimGetProcAddr(TMP138, "CreatePipe");
	Dl_106452 = (TY106453) nimGetProcAddr(TMP138, "CreateNamedPipeW");
	Dl_108203 = (TY108204) nimGetProcAddr(TMP138, "GetCurrentProcess");
	Dl_108193 = (TY108194) nimGetProcAddr(TMP138, "DuplicateHandle");
	Dl_106474 = (TY106475) nimGetProcAddr(TMP138, "CreateProcessW");
	Dl_106428 = (TY106429) nimGetProcAddr(TMP138, "ReadFile");
	Dl_106436 = (TY106437) nimGetProcAddr(TMP138, "WriteFile");
	Dl_106607 = (TY106608) nimGetProcAddr(TMP138, "WaitForSingleObject");
	Dl_106615 = (TY106616) nimGetProcAddr(TMP138, "GetExitCodeProcess");
	Dl_108214 = (TY108215) nimGetProcAddr(TMP138, "DeleteFileW");
	Dl_107414 = (TY107415) nimGetProcAddr(TMP138, "SetFileAttributesW");
	Dl_106815 = (TY106816) nimGetProcAddr(TMP138, "RemoveDirectoryW");
	Dl_106808 = (TY106809) nimGetProcAddr(TMP138, "SetCurrentDirectoryW");
	Dl_107423 = (TY107424) nimGetProcAddr(TMP138, "MoveFileW");
	Dl_107418 = (TY107419) nimGetProcAddr(TMP138, "CopyFileW");
	Dl_107609 = (TY107610) nimGetProcAddr(TMP138, "GetSystemTimeAsFileTime");
	Dl_107613 = (TY107614) nimGetProcAddr(TMP138, "Sleep");
	Dl_107981 = (TY107982) nimGetProcAddr(TMP1203, "socket");
	Dl_107996 = (TY107997) nimGetProcAddr(TMP1203, "bind");
	Dl_108133 = (TY108134) nimGetProcAddr(TMP1203, "getaddrinfo");
	Dl_108142 = (TY108143) nimGetProcAddr(TMP1203, "freeaddrinfo");
	Dl_108037 = (TY108038) nimGetProcAddr(TMP1203, "listen");
	Dl_108066 = (TY108067) nimGetProcAddr(TMP1203, "send");
	Dl_107989 = (TY107990) nimGetProcAddr(TMP1203, "accept");
	Dl_108146 = (TY108147) nimGetProcAddr(TMP1203, "inet_ntoa");
	Dl_108057 = (TY108058) nimGetProcAddr(TMP1203, "select");
	Dl_108098 = (TY108099) nimGetProcAddr(TMP1203, "__WSAFDIsSet");
	Dl_108041 = (TY108042) nimGetProcAddr(TMP1203, "recv");
	Dl_107986 = (TY107987) nimGetProcAddr(TMP1203, "closesocket");
}

