/* Generated by Nim Compiler v0.10.2 */
/*   (c) 2014 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 tguid105414 tguid105414;
typedef struct TGenericSeq TGenericSeq;
typedef struct NimStringDesc NimStringDesc;
typedef struct twin32finddata104019 twin32finddata104019;
typedef struct tfiletime103079 tfiletime103079;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct tsecurityattributes103073 tsecurityattributes103073;
typedef struct tstartupinfo103075 tstartupinfo103075;
typedef struct tprocessinformation103077 tprocessinformation103077;
typedef struct addrinfo104668 addrinfo104668;
typedef struct tfdset104664 tfdset104664;
typedef struct timeval104666 timeval104666;
typedef NI8 TY105427[8];
struct  tguid105414  {
NI32 D1;
NI16 D2;
NI16 D3;
TY105427 D4;
};
typedef NI8 TY105508[8];
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef N_STDCALL_PTR(int, TY105041) (NI16 wversionrequired, WSADATA* wsdata);
typedef N_STDCALL_PTR(NI32, TY103463) (NI32 dwflags, void* lpsource, NI32 dwmessageid, NI32 dwlanguageid, void* lpbuffer, NI32 nsize, void* arguments);
typedef N_STDCALL_PTR(void, TY103605) (void* p);
typedef N_STDCALL_PTR(NI32, TY103458) (void);
typedef N_STDCALL_PTR(NI32, TY104211) (NI16* lpfilename, NI32 nbufferlength, NI16* lpbuffer, NI16** lpfilepart);
typedef N_STDCALL_PTR(NI32, TY103629) (NI handle, NI16* buf, NI32 size);
typedef N_STDCALL_PTR(NI, TY104040) (NI16* lpfilename, twin32finddata104019* lpfindfiledata);
typedef N_STDCALL_PTR(NI32, TY104045) (NI hfindfile, twin32finddata104019* lpfindfiledata);
typedef N_STDCALL_PTR(void, TY104205) (NI hfindfile);
typedef N_STDCALL_PTR(NI32, TY103618) (NI16* pathname, void* security);
typedef N_STDCALL_PTR(NI, TY105123) (NI16* lpfilename, NI32 dwdesiredaccess, NI32 dwsharemode, void* lpsecurityattributes, NI32 dwcreationdisposition, NI32 dwflagsandattributes, NI htemplatefile);
typedef N_STDCALL_PTR(NI32, TY103225) (NI hobject);
typedef N_STDCALL_PTR(NI32, TY105211) (NI hfile, NI32 ldistancetomove, NI32* lpdistancetomovehigh, NI32 dwmovemethod);
typedef N_STDCALL_PTR(NI32, TY105205) (NI hfile);
typedef N_STDCALL_PTR(NI, TY105240) (NI hfile, void* lpfilemappingattributes, NI32 flprotect, NI32 dwmaximumsizehigh, NI32 dwmaximumsizelow, void* lpname);
typedef N_STDCALL_PTR(void*, TY105229) (NI hfilemappingobject, NI32 dwdesiredaccess, NI32 dwfileoffsethigh, NI32 dwfileoffsetlow, NI32 dwnumberofbytestomap, void* lpbaseaddress);
typedef N_STDCALL_PTR(NI32, TY105221) (NI hfile, NI32* lpfilesizehigh);
typedef N_STDCALL_PTR(NI32, TY104218) (NI16* lpfilename);
typedef N_STDCALL_PTR(NI32, TY105402) (void* lpbaseaddress);
typedef N_STDCALL_PTR(NI16*, TY104235) (void);
typedef N_STDCALL_PTR(NI16*, TY104230) (void);
typedef N_STDCALL_PTR(NI32, TY104232) (NI16* para1);
typedef N_STDCALL_PTR(NI32, TY103625) (NI16* lpname, NI16* lpvalue);
typedef N_STDCALL_PTR(NI32, TY103611) (NI32 nbufferlength, NI16* lpbuffer);
typedef N_STDCALL_PTR(void, TY104425) (tfiletime103079* lpsystemtimeasfiletime);
struct  tfiletime103079  {
NI32 Dwlowdatetime;
NI32 Dwhighdatetime;
};
typedef N_STDCALL_PTR(int, TY104938) (NI s, void* buf, int len, int flags);
typedef N_NIMCALL_PTR(void, TY3089) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3094) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3089 marker;
TY3094 deepcopy;
};
typedef N_STDCALL_PTR(NI32, TY103253) (NI* hreadpipe, NI* hwritepipe, tsecurityattributes103073* lppipeattributes, NI32 nsize);
typedef N_STDCALL_PTR(NI, TY103439) (NI32 nstdhandle);
typedef N_STDCALL_PTR(NI32, TY103264) (NI16* lpapplicationname, NI16* lpcommandline, tsecurityattributes103073* lpprocessattributes, tsecurityattributes103073* lpthreadattributes, NI32 binherithandles, NI32 dwcreationflags, NI16* lpenvironment, NI16* lpcurrentdirectory, tstartupinfo103075* lpstartupinfo, tprocessinformation103077* lpprocessinformation);
typedef N_STDCALL_PTR(NI32, TY103231) (NI hfile, void* buffer, NI32 nnumberofbytestoread, NI32* lpnumberofbytesread, void* lpoverlapped);
typedef N_STDCALL_PTR(NI32, TY103242) (NI hfile, void* buffer, NI32 nnumberofbytestowrite, NI32* lpnumberofbyteswritten, void* lpoverlapped);
typedef N_STDCALL_PTR(NI32, TY103417) (NI hhandle, NI32 dwmilliseconds);
typedef N_STDCALL_PTR(NI32, TY103431) (NI hprocess, NI32* lpexitcode);
typedef N_STDCALL_PTR(void, TY104432) (NI32 dwmilliseconds);
typedef N_STDCALL_PTR(NI, TY104824) (int af, int typ, int protocol);
typedef N_STDCALL_PTR(int, TY104848) (NI s, SOCKADDR* name, int namelen);
typedef N_STDCALL_PTR(int, TY105049) (NCSTRING nodename, NCSTRING servname, addrinfo104668* hints, addrinfo104668** res);
typedef N_STDCALL_PTR(int, TY104897) (NI s, int backlog);
typedef N_STDCALL_PTR(NI, TY104838) (NI s, SOCKADDR* a, int* addrlen);
typedef N_STDCALL_PTR(NCSTRING, TY105068) (IN_ADDR i);
typedef NI TY104715[64];
struct  tfdset104664  {
int Fdcount;
TY104715 Fdarray;
};
typedef N_STDCALL_PTR(int, TY104926) (int nfds, tfdset104664* readfds, tfdset104664* writefds, tfdset104664* exceptfds, timeval104666* timeout);
typedef N_STDCALL_PTR(NIM_BOOL, TY104985) (NI s, tfdset104664* set);
typedef N_STDCALL_PTR(int, TY104904) (NI s, void* buf, int len, int flags);
typedef N_STDCALL_PTR(int, TY104832) (NI s);
typedef NIM_CHAR TY104673[257];
typedef NIM_CHAR TY104676[129];
typedef NI16 TY104028[260];
typedef NI16 TY104032[14];
struct  twin32finddata104019  {
NI32 Dwfileattributes;
tfiletime103079 Ftcreationtime;
tfiletime103079 Ftlastaccesstime;
tfiletime103079 Ftlastwritetime;
NI32 Nfilesizehigh;
NI32 Nfilesizelow;
NI32 Dwreserved0;
NI32 Dwreserved1;
TY104028 Cfilename;
TY104032 Calternatefilename;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  tsecurityattributes103073  {
NI32 Nlength;
void* Lpsecuritydescriptor;
NI32 Binherithandle;
};
struct  tstartupinfo103075  {
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  tprocessinformation103077  {
NI Hprocess;
NI Hthread;
NI32 Dwprocessid;
NI32 Dwthreadid;
};
typedef NIM_CHAR TY104683[14];
struct  addrinfo104668  {
int Aiflags;
int Aifamily;
int Aisocktype;
int Aiprotocol;
NI Aiaddrlen;
NCSTRING Aicanonname;
SOCKADDR* Aiaddr;
addrinfo104668* Ainext;
};
struct  timeval104666  {
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 TY105508 TMP19 = {((NI8) -114),
((NI8) -23),
((NI8) 118),
((NI8) -27),
((NI8) -116),
((NI8) 116),
((NI8) 6),
((NI8) 62)}
;
NIM_CONST TY105508 TMP20 = {((NI8) -107),
((NI8) -54),
((NI8) 0),
((NI8) -128),
((NI8) 95),
((NI8) 72),
((NI8) -95),
((NI8) -110)}
;
STRING_LITERAL(TMP133, "Ws2_32.dll", 10);
STRING_LITERAL(TMP134, "Ws2_32.dll", 10);
STRING_LITERAL(TMP141, "kernel32", 8);
STRING_LITERAL(TMP142, "kernel32", 8);
tguid105414 wsaidconnectex_105510;
tguid105414 wsaidacceptex_105514;
tguid105414 wsaidgetacceptexsockaddrs_105518;
static void* TMP132;
TY105041 Dl_105040;
static void* TMP140;
TY103463 Dl_103462;
TY103605 Dl_103604;
TY103458 Dl_103457;
TY104211 Dl_104210;
TY103629 Dl_103628;
TY104040 Dl_104039;
TY104045 Dl_104044;
TY104205 Dl_104204;
TY103618 Dl_103617;
TY105123 Dl_105122;
TY103225 Dl_103224;
TY105211 Dl_105210;
TY105205 Dl_105204;
TY105240 Dl_105239;
TY105229 Dl_105228;
TY105221 Dl_105220;
TY104218 Dl_104217;
TY105402 Dl_105401;
TY104235 Dl_104234;
TY104230 Dl_104229;
TY104232 Dl_104231;
TY103625 Dl_103624;
TY103611 Dl_103610;
TY104425 Dl_104424;
TY104938 Dl_104937;
TNimType NTI103053; /* THandle */
TY103253 Dl_103252;
TY103439 Dl_103438;
TY103264 Dl_103263;
TY103231 Dl_103230;
TY103242 Dl_103241;
TY103417 Dl_103416;
TY103431 Dl_103430;
TY104432 Dl_104431;
TY104824 Dl_104823;
TY104848 Dl_104847;
TY105049 Dl_105048;
TY104897 Dl_104896;
TY104838 Dl_104837;
TY105068 Dl_105067;
TY104926 Dl_104925;
TY104985 Dl_104984;
TY104904 Dl_104903;
TY104832 Dl_104831;

N_NIMCALL(NI64, rdfiletime_104404)(tfiletime103079 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_105030)(tfdset104664* s) {
	(*s).Fdcount = ((int) 0);
}

N_NIMCALL(void, fdset_105004)(NI socket, tfdset104664* s) {
	{
		if (!((*s).Fdcount < ((NI32) 64))) goto LA3;
		(*s).Fdarray[(((NI) ((*s).Fdcount)))- 0] = socket;
		(*s).Fdcount += 1;
	}
	LA3: ;
}

N_NIMCALL(int, fdisset_104992)(NI socket, tfdset104664* set) {
	int result;
	result = 0;
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = Dl_104984(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) {
	tguid105414 LOC1;
	tguid105414 LOC2;
	tguid105414 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_105510 = 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_105514 = 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_105518 = LOC3;
}

NIM_EXTERNC N_NOINLINE(void, stdlib_winleanDatInit)(void) {
NTI103053.size = sizeof(NI);
NTI103053.kind = 31;
NTI103053.base = 0;
NTI103053.flags = 3;
if (!((TMP132 = nimLoadLibrary((NimStringDesc*) &TMP133))
)) nimLoadLibraryError((NimStringDesc*) &TMP134);
	Dl_105040 = (TY105041) nimGetProcAddr(TMP132, "WSAStartup");
if (!((TMP140 = nimLoadLibrary((NimStringDesc*) &TMP141))
)) nimLoadLibraryError((NimStringDesc*) &TMP142);
	Dl_103462 = (TY103463) nimGetProcAddr(TMP140, "FormatMessageW");
	Dl_103604 = (TY103605) nimGetProcAddr(TMP140, "LocalFree");
	Dl_103457 = (TY103458) nimGetProcAddr(TMP140, "GetLastError");
	Dl_104210 = (TY104211) nimGetProcAddr(TMP140, "GetFullPathNameW");
	Dl_103628 = (TY103629) nimGetProcAddr(TMP140, "GetModuleFileNameW");
	Dl_104039 = (TY104040) nimGetProcAddr(TMP140, "FindFirstFileW");
	Dl_104044 = (TY104045) nimGetProcAddr(TMP140, "FindNextFileW");
	Dl_104204 = (TY104205) nimGetProcAddr(TMP140, "FindClose");
	Dl_103617 = (TY103618) nimGetProcAddr(TMP140, "CreateDirectoryW");
	Dl_105122 = (TY105123) nimGetProcAddr(TMP140, "CreateFileW");
	Dl_103224 = (TY103225) nimGetProcAddr(TMP140, "CloseHandle");
	Dl_105210 = (TY105211) nimGetProcAddr(TMP140, "SetFilePointer");
	Dl_105204 = (TY105205) nimGetProcAddr(TMP140, "SetEndOfFile");
	Dl_105239 = (TY105240) nimGetProcAddr(TMP140, "CreateFileMappingW");
	Dl_105228 = (TY105229) nimGetProcAddr(TMP140, "MapViewOfFileEx");
	Dl_105220 = (TY105221) nimGetProcAddr(TMP140, "GetFileSize");
	Dl_104217 = (TY104218) nimGetProcAddr(TMP140, "GetFileAttributesW");
	Dl_105401 = (TY105402) nimGetProcAddr(TMP140, "UnmapViewOfFile");
	Dl_104234 = (TY104235) nimGetProcAddr(TMP140, "GetCommandLineW");
	Dl_104229 = (TY104230) nimGetProcAddr(TMP140, "GetEnvironmentStringsW");
	Dl_104231 = (TY104232) nimGetProcAddr(TMP140, "FreeEnvironmentStringsW");
	Dl_103624 = (TY103625) nimGetProcAddr(TMP140, "SetEnvironmentVariableW");
	Dl_103610 = (TY103611) nimGetProcAddr(TMP140, "GetCurrentDirectoryW");
	Dl_104424 = (TY104425) nimGetProcAddr(TMP140, "GetSystemTimeAsFileTime");
	Dl_104937 = (TY104938) nimGetProcAddr(TMP132, "send");
	Dl_103252 = (TY103253) nimGetProcAddr(TMP140, "CreatePipe");
	Dl_103438 = (TY103439) nimGetProcAddr(TMP140, "GetStdHandle");
	Dl_103263 = (TY103264) nimGetProcAddr(TMP140, "CreateProcessW");
	Dl_103230 = (TY103231) nimGetProcAddr(TMP140, "ReadFile");
	Dl_103241 = (TY103242) nimGetProcAddr(TMP140, "WriteFile");
	Dl_103416 = (TY103417) nimGetProcAddr(TMP140, "WaitForSingleObject");
	Dl_103430 = (TY103431) nimGetProcAddr(TMP140, "GetExitCodeProcess");
	Dl_104431 = (TY104432) nimGetProcAddr(TMP140, "Sleep");
	Dl_104823 = (TY104824) nimGetProcAddr(TMP132, "socket");
	Dl_104847 = (TY104848) nimGetProcAddr(TMP132, "bind");
	Dl_105048 = (TY105049) nimGetProcAddr(TMP132, "getaddrinfo");
	Dl_104896 = (TY104897) nimGetProcAddr(TMP132, "listen");
	Dl_104837 = (TY104838) nimGetProcAddr(TMP132, "accept");
	Dl_105067 = (TY105068) nimGetProcAddr(TMP132, "inet_ntoa");
	Dl_104925 = (TY104926) nimGetProcAddr(TMP132, "select");
	Dl_104984 = (TY104985) nimGetProcAddr(TMP132, "__WSAFDIsSet");
	Dl_104903 = (TY104904) nimGetProcAddr(TMP132, "recv");
	Dl_104831 = (TY104832) nimGetProcAddr(TMP132, "closesocket");
}

