/* Generated by Nim Compiler v2.2.10 */
/* Compiled for: MacOSX, arm64, clang */
/* Command for C compiler:
   clang -c  -w -ferror-limit=3 -fno-strict-aliasing -pthread -isysroot /Applications/Xcode_16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -target arm64-apple-darwin24.2.0 -O3   -I/Users/runner/work/nightlies/nightlies/nim-2.2.10/lib -I/Users/runner/work/nightlies/nightlies/nim-2.2.10/dist/atlas/src -o /Users/runner/work/nightlies/nightlies/nim-2.2.10/dist/atlas/.nimcache/@pstd@ssyncio.nim.c.o /Users/runner/work/nightlies/nightlies/nim-2.2.10/dist/atlas/.nimcache/@pstd@ssyncio.nim.c */
#define NIM_INTBITS 64
#define NIM_EmulateOverflowChecks

#include "nimbase.h"
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
typedef struct NimStrPayload NimStrPayload;
typedef struct NimStringV2 NimStringV2;
typedef struct tyObject_IOError__FsM2LSiW5usgjecIvsloBA tyObject_IOError__FsM2LSiW5usgjecIvsloBA;
typedef struct tyObject_CatchableError__liO6E8JNJNTVmf9cnXKZiug tyObject_CatchableError__liO6E8JNJNTVmf9cnXKZiug;
typedef struct Exception Exception;
typedef struct RootObj RootObj;
typedef struct TNimTypeV2 TNimTypeV2;
typedef struct tySequence__3EvzHGO0xyXGnJBUggwfKQ tySequence__3EvzHGO0xyXGnJBUggwfKQ;
typedef struct tySequence__3EvzHGO0xyXGnJBUggwfKQ_Content tySequence__3EvzHGO0xyXGnJBUggwfKQ_Content;
typedef struct tyObject_StackTraceEntry__lcKzdyiD6sm3eeh28rx7fw tyObject_StackTraceEntry__lcKzdyiD6sm3eeh28rx7fw;
struct NimStrPayload {
	NI cap;
	NIM_CHAR data[SEQ_DECL_SIZE];
};
struct NimStringV2 {
	NI len;
	NimStrPayload* p;
};
struct TNimTypeV2 {
	void* destructor;
	NI size;
	NI16 align;
	NI16 depth;
	NU32* display;
	void* traceImpl;
	void* typeInfoV1;
	NI flags;
	void* vTable[SEQ_DECL_SIZE];
};
struct RootObj {
	TNimTypeV2* m_type;
};
struct tySequence__3EvzHGO0xyXGnJBUggwfKQ {
  NI len; tySequence__3EvzHGO0xyXGnJBUggwfKQ_Content* p;
};
struct Exception {
	RootObj Sup;
	Exception* parent;
	NCSTRING name;
	NimStringV2 message;
	tySequence__3EvzHGO0xyXGnJBUggwfKQ trace;
	Exception* up;
};
struct tyObject_CatchableError__liO6E8JNJNTVmf9cnXKZiug {
	Exception Sup;
};
struct tyObject_IOError__FsM2LSiW5usgjecIvsloBA {
	tyObject_CatchableError__liO6E8JNJNTVmf9cnXKZiug Sup;
};
typedef NU8 tyEnum_FileMode__wjF0STQGT1PBuQEl3p0tng;
typedef NCSTRING tyArray__qc9axIU9ars9amFjBSnG7Kiqg[5];
typedef NU8 tyEnum_FileSeekPos__sobaHT4orl7Vk3X9cLPriwg;
struct tyObject_StackTraceEntry__lcKzdyiD6sm3eeh28rx7fw {
	NCSTRING procname;
	NI line;
	NCSTRING filename;
};
struct tySequence__3EvzHGO0xyXGnJBUggwfKQ_Content { NI cap; tyObject_StackTraceEntry__lcKzdyiD6sm3eeh28rx7fw data[SEQ_DECL_SIZE]; };
N_LIB_PRIVATE N_NIMCALL(NI, writeBuffer__stdZsyncio_u196)(FILE* f_p0, void* buffer_p1, NI len_p2);
N_LIB_PRIVATE N_NIMCALL(void, checkErr__stdZsyncio_u162)(FILE* f_p0);
static N_INLINE(void, appendString)(NimStringV2* dest_p0, NimStringV2 src_p1);
static N_INLINE(void, copyMem__system_u1755)(void* dest_p0, void* source_p1, NI size_p2);
static N_INLINE(void, nimCopyMem)(void* dest_p0, void* source_p1, NI size_p2);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, dollar___systemZdollars_u29)(NI32 xX60gensym3__p0);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, cstrToNimstr)(NCSTRING str_p0);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, rawNewString)(NI space_p0);
N_LIB_PRIVATE N_NOINLINE(void, raiseEIO__stdZsyncio_u92)(NimStringV2 msg_p0);
N_LIB_PRIVATE N_NIMCALL(void*, nimNewObj)(NI size_p0, NI alignment_p1);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, eqdup___system_u2757)(NimStringV2 src_p0);
N_LIB_PRIVATE N_NIMCALL(void, raiseExceptionEx)(Exception* e_p0, NCSTRING ename_p1, NCSTRING procname_p2, NCSTRING filename_p3, NI line_p4);
N_LIB_PRIVATE N_NOCONV(void, deallocShared)(void* p_p0);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringV2 s_p0);
N_LIB_PRIVATE N_NOINLINE(void, raiseRangeErrorI)(NI64 i_p0, NI64 a_p1, NI64 b_p2);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, open__stdZsyncio_u413)(FILE** f_p0, NimStringV2 filename_p1, tyEnum_FileMode__wjF0STQGT1PBuQEl3p0tng mode_p2, NI bufSize_p3);
N_LIB_PRIVATE N_NIMCALL(int, getFileHandle__stdZsyncio_u280)(FILE* f_p0);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, setInheritable__stdZsyncio_u286)(int f_p0, NIM_BOOL inheritable_p1);
N_LIB_PRIVATE N_NIMCALL(int, getOsFileHandle__stdZsyncio_u283)(FILE* f_p0);
N_LIB_PRIVATE N_NIMCALL(void, write__stdZsyncio_u254)(FILE* f_p0, NimStringV2 s_p1);
N_LIB_PRIVATE N_NIMCALL(void, close__stdZsyncio_u269)(FILE* f_p0);
N_LIB_PRIVATE N_NIMCALL(void, setLengthStrV2)(NimStringV2* s_p0, NI newLen_p1);
static N_INLINE(NIM_BOOL, nimAddInt)(NI a_p0, NI b_p1, NI* res_p2);
N_LIB_PRIVATE N_NOINLINE(void, raiseOverflow)(void);
N_LIB_PRIVATE N_NOINLINE(void, raiseIndexError2)(NI i_p0, NI n_p1);
static N_INLINE(void, nimPrepareStrMutationV2)(NimStringV2* s_p0);
N_LIB_PRIVATE N_NIMCALL(void, nimPrepareStrMutationImpl__system_u2493)(NimStringV2* s_p0);
static N_INLINE(NIM_BOOL, eqeq___system_u9048)(NCSTRING x_p0, NCSTRING y_p1);
static N_INLINE(NIM_BOOL, nimSubInt)(NI a_p0, NI b_p1, NI* res_p2);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, readAll__stdZsyncio_u382)(FILE* file_p0);
N_LIB_PRIVATE N_NIMCALL(NI64, rawFileSize__stdZsyncio_u365)(FILE* file_p0);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, readAllFile__stdZsyncio_u373)(FILE* file_p0, NI64 len_p1);
N_NIMCALL(NimStringV2, mnewString)(NI len_p0);
N_LIB_PRIVATE N_NIMCALL(NI, readBuffer__stdZsyncio_u165)(FILE* f_p0, void* buffer_p1, NI len_p2);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, endOfFile__stdZsyncio_u369)(FILE* f_p0);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, readAllBuffer__stdZsyncio_u360)(FILE* file_p0);
N_LIB_PRIVATE N_NIMCALL(void, prepareAdd)(NimStringV2* s_p0, NI addLen_p1);
static const struct {
  NI cap; NIM_CHAR data[7+1];
} TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_2 = { 7 | NIM_STRLIT_FLAG, "errno: " };
static const NimStringV2 TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_3 = {7, (NimStrPayload*)&TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_2};
static const struct {
  NI cap; NIM_CHAR data[2+1];
} TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_4 = { 2 | NIM_STRLIT_FLAG, " `" };
static const NimStringV2 TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_5 = {2, (NimStrPayload*)&TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_4};
static const struct {
  NI cap; NIM_CHAR data[1+1];
} TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_6 = { 1 | NIM_STRLIT_FLAG, "`" };
static const NimStringV2 TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_7 = {1, (NimStrPayload*)&TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_6};
extern TNimTypeV2 NTIv2__FsM2LSiW5usgjecIvsloBA_;
static const struct {
  NI cap; NIM_CHAR data[27+1];
} TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_8 = { 27 | NIM_STRLIT_FLAG, "cannot write string to file" };
static const NimStringV2 TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_9 = {27, (NimStrPayload*)&TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_8};
static const struct {
  NI cap; NIM_CHAR data[13+1];
} TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_10 = { 13 | NIM_STRLIT_FLAG, "cannot open: " };
static const NimStringV2 TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_11 = {13, (NimStrPayload*)&TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_10};
static const struct {
  NI cap; NIM_CHAR data[24+1];
} TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_12 = { 24 | NIM_STRLIT_FLAG, "cannot set file position" };
static const NimStringV2 TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_13 = {24, (NimStrPayload*)&TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_12};
static const struct {
  NI cap; NIM_CHAR data[29+1];
} TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_14 = { 29 | NIM_STRLIT_FLAG, "cannot retrieve file position" };
static const NimStringV2 TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_15 = {29, (NimStrPayload*)&TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_14};
static const NimStringV2 TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_29 = {13, (NimStrPayload*)&TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_10};
static const struct {
  NI cap; NIM_CHAR data[0+1];
} TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_30 = { 0 | NIM_STRLIT_FLAG, "" };
static const NimStringV2 TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_31 = {0, (NimStrPayload*)&TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_30};
static const NimStringV2 TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_32 = {13, (NimStrPayload*)&TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_10};
N_LIB_PRIVATE NIM_CONST tyArray__qc9axIU9ars9amFjBSnG7Kiqg FormatOpen__stdZsyncio_u404 = {"rb",
"wb",
"w+b",
"r+b",
"ab"}
;
N_LIB_PRIVATE NIM_CONST tyArray__qc9axIU9ars9amFjBSnG7Kiqg RawFormatOpen__stdZsyncio_u403 = {"rb",
"wb",
"w+b",
"r+b",
"ab"}
;
extern NIM_THREADVAR NIM_BOOL nimInErrorMode__system_u4198;
N_LIB_PRIVATE N_NIMCALL(int, getFileHandle__stdZsyncio_u280)(FILE* f_p0) {
	int result;
	int T1_;
	T1_ = (int)0;
	T1_ = fileno(f_p0);
	result = ((int) (T1_));
	return result;
}
static N_INLINE(void, nimCopyMem)(void* dest_p0, void* source_p1, NI size_p2) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memcpy(dest_p0, source_p1, ((size_t) (size_p2)));
}
static N_INLINE(void, copyMem__system_u1755)(void* dest_p0, void* source_p1, NI size_p2) {
	nimCopyMem(dest_p0, source_p1, size_p2);
}
static N_INLINE(void, appendString)(NimStringV2* dest_p0, NimStringV2 src_p1) {
	{
		if (!(((NI)0) < src_p1.len)) goto LA3_;
		copyMem__system_u1755(((void*) ((&(*(*dest_p0).p).data[(*dest_p0).len]))), ((void*) ((&(*src_p1.p).data[((NI)0)]))), (src_p1.len));
		(*dest_p0).len += src_p1.len;
		(*(*dest_p0).p).data[(*dest_p0).len] = 0;
	}
LA3_: ;
}
N_LIB_PRIVATE N_NOINLINE(void, raiseEIO__stdZsyncio_u92)(NimStringV2 msg_p0) {
	NimStringV2 colontmpD_;
	tyObject_IOError__FsM2LSiW5usgjecIvsloBA* T1_;
{	T1_ = NIM_NIL;
	T1_ = (tyObject_IOError__FsM2LSiW5usgjecIvsloBA*) nimNewObj(sizeof(tyObject_IOError__FsM2LSiW5usgjecIvsloBA), NIM_ALIGNOF(tyObject_IOError__FsM2LSiW5usgjecIvsloBA));
	(*T1_).Sup.Sup.Sup.m_type = (&NTIv2__FsM2LSiW5usgjecIvsloBA_);
	(*T1_).Sup.Sup.name = "IOError";
	colontmpD_ = eqdup___system_u2757(msg_p0);
	(*T1_).Sup.Sup.message = colontmpD_;
	(*T1_).Sup.Sup.parent = ((Exception*) NIM_NIL);
	raiseExceptionEx((Exception*)T1_, "IOError", "raiseEIO", "syncio.nim", 161);
goto BeforeRet_;
	}BeforeRet_: ;
}
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (&nimInErrorMode__system_u4198);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, checkErr__stdZsyncio_u162)(FILE* f_p0) {
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	{
		int T3_;
		NimStringV2 msg_1;
		NimStringV2 colontmpD_;
		NimStringV2 colontmpD__2;
		NimStringV2 T7_;
		NCSTRING T8_;
		T3_ = (int)0;
		T3_ = ferror(f_p0);
		if (!!((T3_ == ((NI32)0)))) goto LA4_;
		msg_1.len = 0; msg_1.p = NIM_NIL;
		colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
		colontmpD__2.len = 0; colontmpD__2.p = NIM_NIL;
		T7_.len = 0; T7_.p = NIM_NIL;
		colontmpD_ = dollar___systemZdollars_u29(errno);
		if (NIM_UNLIKELY(*nimErr_)) goto LA6_;
		T8_ = (NCSTRING)0;
		T8_ = strerror(errno);
		colontmpD__2 = cstrToNimstr(T8_);
		T7_ = rawNewString(colontmpD_.len + colontmpD__2.len + 10);
appendString((&T7_), TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_3);
appendString((&T7_), colontmpD_);
appendString((&T7_), TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_5);
appendString((&T7_), colontmpD__2);
appendString((&T7_), TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_7);
		msg_1 = T7_;
		clearerr(f_p0);
		raiseEIO__stdZsyncio_u92(msg_1);
		if (NIM_UNLIKELY(*nimErr_)) goto LA6_;
		{
			LA6_:;
		}
		{
			if (colontmpD__2.p && !(colontmpD__2.p->cap & NIM_STRLIT_FLAG)) {
 deallocShared(colontmpD__2.p);
}
			if (colontmpD_.p && !(colontmpD_.p->cap & NIM_STRLIT_FLAG)) {
 deallocShared(colontmpD_.p);
}
			if (msg_1.p && !(msg_1.p->cap & NIM_STRLIT_FLAG)) {
 deallocShared(msg_1.p);
}
		}
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA4_: ;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(NI, writeBuffer__stdZsyncio_u196)(FILE* f_p0, void* buffer_p1, NI len_p2) {
	NI result;
	size_t T1_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	T1_ = (size_t)0;
	T1_ = fwrite(buffer_p1, ((size_t)1), ((size_t) (len_p2)), f_p0);
	result = ((NI) (T1_));
	checkErr__stdZsyncio_u162(f_p0);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringV2 s_p0) {
	NCSTRING result;
	{
		if (!(s_p0.len == ((NI)0))) goto LA3_;
		result = "";
	}
	goto LA1_;
LA3_: ;
	{
		result = ((NCSTRING) ((*s_p0.p).data));
	}
LA1_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, write__stdZsyncio_u254)(FILE* f_p0, NimStringV2 s_p1) {
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	{
		NI T3_;
		if ((s_p1.len) < ((NI)0) || (s_p1.len) > ((NI)IL64(9223372036854775807))){ raiseRangeErrorI(s_p1.len, ((NI)0), ((NI)IL64(9223372036854775807))); goto BeforeRet_;
		}
		T3_ = (NI)0;
		T3_ = writeBuffer__stdZsyncio_u196(f_p0, ((void*) (nimToCStringConv(s_p1))), (s_p1.len));
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!!((T3_ == s_p1.len))) goto LA4_;
		raiseEIO__stdZsyncio_u92(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_9);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA4_: ;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(void, flushFile__stdZsyncio_u278)(FILE* f_p0) {
	int T1_;
	T1_ = (int)0;
	T1_ = fflush(f_p0);
	(void)(T1_);
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, setInheritable__stdZsyncio_u286)(int f_p0, NIM_BOOL inheritable_p1) {
	NIM_BOOL result;
	int flags_1;
	NI32 T5_;
	int T11_;
{	flags_1 = fcntl(f_p0, F_GETFD);
	{
		if (!(flags_1 == ((NI32)-1))) goto LA3_;
		result = NIM_FALSE;
		goto BeforeRet_;
	}
LA3_: ;
	T5_ = (NI32)0;
	{
		if (!inheritable_p1) goto LA8_;
		flags_1 = (NI32)(flags_1 & (NI32)((NU32) ~(FD_CLOEXEC)));
	}
	goto LA6_;
LA8_: ;
	{
		flags_1 = (NI32)(flags_1 | FD_CLOEXEC);
	}
LA6_: ;
	T11_ = (int)0;
	T11_ = fcntl(f_p0, F_SETFD, flags_1);
	result = !((T11_ == ((NI32)-1)));
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(int, getOsFileHandle__stdZsyncio_u283)(FILE* f_p0) {
	int result;
	result = fileno(f_p0);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, open__stdZsyncio_u413)(FILE** f_p0, NimStringV2 filename_p1, tyEnum_FileMode__wjF0STQGT1PBuQEl3p0tng mode_p2, NI bufSize_p3) {
	NIM_BOOL result;
	void* p_1;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	p_1 = fopen(nimToCStringConv(filename_p1), FormatOpen__stdZsyncio_u404[(mode_p2)- 0]);
	{
		FILE* f2_1;
		struct stat res_1;
		if (!!((p_1 == NIM_NIL))) goto LA3_;
		f2_1 = ((FILE*) (p_1));
		{
			NIM_BOOL T7_;
			int T8_;
			int T9_;
			T7_ = (NIM_BOOL)0;
			T8_ = (int)0;
			T8_ = getFileHandle__stdZsyncio_u280(f2_1);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			T9_ = (int)0;
			T9_ = fstat(T8_, (&res_1));
			T7_ = (((NI32)0) <= T9_);
			if (!(T7_)) goto LA10_;
			T7_ = S_ISDIR(res_1.st_mode);
LA10_: ;
			if (!T7_) goto LA11_;
			{
				int T17_;
				if (!!((f2_1 == 0))) goto LA15_;
				T17_ = (int)0;
				T17_ = fclose(f2_1);
				(void)(T17_);
			}
LA15_: ;
			result = NIM_FALSE;
			goto BeforeRet_;
		}
LA11_: ;
		{
			int T20_;
			NIM_BOOL T21_;
			T20_ = (int)0;
			T20_ = getOsFileHandle__stdZsyncio_u283(f2_1);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			T21_ = (NIM_BOOL)0;
			T21_ = setInheritable__stdZsyncio_u286(T20_, NIM_FALSE);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			if (!!(T21_)) goto LA22_;
			{
				int T28_;
				if (!!((f2_1 == 0))) goto LA26_;
				T28_ = (int)0;
				T28_ = fclose(f2_1);
				(void)(T28_);
			}
LA26_: ;
			result = NIM_FALSE;
			goto BeforeRet_;
		}
LA22_: ;
		result = NIM_TRUE;
		(*f_p0) = ((FILE*) (p_1));
		{
			NIM_BOOL T31_;
			int T35_;
			T31_ = (NIM_BOOL)0;
			T31_ = (((NI)0) < bufSize_p3);
			if (!(T31_)) goto LA32_;
			T31_ = ((NU64)(((NU) (bufSize_p3))) <= (NU64)(((NU)-1)));
LA32_: ;
			if (!T31_) goto LA33_;
			T35_ = (int)0;
			T35_ = setvbuf((*f_p0), NIM_NIL, _IOFBF, ((size_t) (bufSize_p3)));
			(void)(T35_);
		}
		goto LA29_;
LA33_: ;
		{
			int T39_;
			if (!(bufSize_p3 == ((NI)0))) goto LA37_;
			T39_ = (int)0;
			T39_ = setvbuf((*f_p0), NIM_NIL, _IONBF, ((size_t)0));
			(void)(T39_);
		}
		goto LA29_;
LA37_: ;
LA29_: ;
	}
	goto LA1_;
LA3_: ;
	{
		result = NIM_FALSE;
	}
LA1_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, close__stdZsyncio_u269)(FILE* f_p0) {
	{
		int T5_;
		if (!!((f_p0 == 0))) goto LA3_;
		T5_ = (int)0;
		T5_ = fclose(f_p0);
		(void)(T5_);
	}
LA3_: ;
}
N_LIB_PRIVATE N_NIMCALL(void, writeFile__stdZsyncio_u539)(NimStringV2 filename_p0, NimStringV2 content_p1) {
	FILE* f_1;
NIM_BOOL oldNimErrFin6_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	f_1 = ((FILE*) NIM_NIL);
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = open__stdZsyncio_u413(&f_1, filename_p0, ((tyEnum_FileMode__wjF0STQGT1PBuQEl3p0tng)1), ((NI)-1));
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!T3_) goto LA4_;
		write__stdZsyncio_u254(f_1, content_p1);
		if (NIM_UNLIKELY(*nimErr_)) goto LA6_;
		{
			LA6_:;
		}
		{
			oldNimErrFin6_ = *nimErr_; *nimErr_ = NIM_FALSE;
			close__stdZsyncio_u269(f_1);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			*nimErr_ = oldNimErrFin6_;
		}
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	goto LA1_;
LA4_: ;
	{
		tyObject_IOError__FsM2LSiW5usgjecIvsloBA* T10_;
		NimStringV2 T11_;
		T10_ = NIM_NIL;
		T10_ = (tyObject_IOError__FsM2LSiW5usgjecIvsloBA*) nimNewObj(sizeof(tyObject_IOError__FsM2LSiW5usgjecIvsloBA), NIM_ALIGNOF(tyObject_IOError__FsM2LSiW5usgjecIvsloBA));
		(*T10_).Sup.Sup.Sup.m_type = (&NTIv2__FsM2LSiW5usgjecIvsloBA_);
		(*T10_).Sup.Sup.name = "IOError";
		T11_.len = 0; T11_.p = NIM_NIL;
		T11_ = rawNewString(filename_p0.len + 13);
appendString((&T11_), TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_11);
appendString((&T11_), filename_p0);
		(*T10_).Sup.Sup.message = T11_;
		(*T10_).Sup.Sup.parent = ((Exception*) NIM_NIL);
		raiseExceptionEx((Exception*)T10_, "IOError", "writeFile", "syncio.nim", 894);
goto BeforeRet_;
	}
LA1_: ;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, endOfFile__stdZsyncio_u369)(FILE* f_p0) {
	NIM_BOOL result;
	int c_1;
	int T1_;
{	c_1 = fgetc(f_p0);
	T1_ = (int)0;
	T1_ = ungetc(c_1, f_p0);
	(void)(T1_);
	result = (c_1 < ((NI32)0));
	goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, setFilePos__stdZsyncio_u503)(FILE* f_p0, NI64 pos_p1, tyEnum_FileSeekPos__sobaHT4orl7Vk3X9cLPriwg relativeTo_p2) {
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	{
		int T3_;
		T3_ = (int)0;
		T3_ = fseeko(f_p0, pos_p1, ((int) (relativeTo_p2)));
		if (!!((T3_ == ((NI32)0)))) goto LA4_;
		raiseEIO__stdZsyncio_u92(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_13);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA4_: ;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(NI64, getFilePos__stdZsyncio_u526)(FILE* f_p0) {
	NI64 result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = ftello(f_p0);
	{
		if (!(result < IL64(0))) goto LA3_;
		raiseEIO__stdZsyncio_u92(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_15);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA3_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NI, readBuffer__stdZsyncio_u165)(FILE* f_p0, void* buffer_p1, NI len_p2) {
	NI result;
	size_t T1_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	T1_ = (size_t)0;
	T1_ = fread(buffer_p1, ((size_t)1), ((size_t) (len_p2)), f_p0);
	result = ((NI) (T1_));
	{
		if (!!((result == len_p2))) goto LA4_;
		checkErr__stdZsyncio_u162(f_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA4_: ;
	}BeforeRet_: ;
	return result;
}
static N_INLINE(NIM_BOOL, nimAddInt)(NI a_p0, NI b_p1, NI* res_p2) {
	NIM_BOOL result;
	NI r_1;
	result = (NIM_BOOL)0;
	r_1 = ((NI) ((NU)((NU64)(((NU) (a_p0))) + (NU64)(((NU) (b_p1))))));
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = (((NI)0) <= (NI)(r_1 ^ a_p0));
		if (T3_) goto LA4_;
		T3_ = (((NI)0) <= (NI)(r_1 ^ b_p1));
LA4_: ;
		if (!T3_) goto LA5_;
		(*res_p2) = r_1;
	}
	goto LA1_;
LA5_: ;
	{
		result = NIM_TRUE;
	}
LA1_: ;
	return result;
}
static N_INLINE(void, nimPrepareStrMutationV2)(NimStringV2* s_p0) {
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = !(((*s_p0).p == ((NimStrPayload*) NIM_NIL)));
		if (!(T3_)) goto LA4_;
		T3_ = ((NI)((*(*s_p0).p).cap & ((NI)IL64(4611686018427387904))) == ((NI)IL64(4611686018427387904)));
LA4_: ;
		if (!T3_) goto LA5_;
		nimPrepareStrMutationImpl__system_u2493(s_p0);
	}
LA5_: ;
}
static N_INLINE(NIM_BOOL, eqeq___system_u9048)(NCSTRING x_p0, NCSTRING y_p1) {
	NIM_BOOL result;
	{
		if (!(((void*) (x_p0)) == ((void*) (y_p1)))) goto LA3_;
		result = NIM_TRUE;
	}
	goto LA1_;
LA3_: ;
	{
		NIM_BOOL T6_;
		T6_ = (NIM_BOOL)0;
		T6_ = (((void*) (x_p0)) == NIM_NIL);
		if (T6_) goto LA7_;
		T6_ = (((void*) (y_p1)) == NIM_NIL);
LA7_: ;
		if (!T6_) goto LA8_;
		result = NIM_FALSE;
	}
	goto LA1_;
LA8_: ;
	{
		int T11_;
		T11_ = (int)0;
		T11_ = strcmp(x_p0, y_p1);
		result = (T11_ == ((NI32)0));
	}
LA1_: ;
	return result;
}
static N_INLINE(NIM_BOOL, nimSubInt)(NI a_p0, NI b_p1, NI* res_p2) {
	NIM_BOOL result;
	NI r_1;
	result = (NIM_BOOL)0;
	r_1 = ((NI) ((NU)((NU64)(((NU) (a_p0))) - (NU64)(((NU) (b_p1))))));
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = (((NI)0) <= (NI)(r_1 ^ a_p0));
		if (T3_) goto LA4_;
		T3_ = (((NI)0) <= (NI)(r_1 ^ (NI)((NU64) ~(b_p1))));
LA4_: ;
		if (!T3_) goto LA5_;
		(*res_p2) = r_1;
	}
	goto LA1_;
LA5_: ;
	{
		result = NIM_TRUE;
	}
LA1_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, readLine__stdZsyncio_u291)(FILE* f_p0, NimStringV2* line_p1) {
	NIM_BOOL result;
	NI pos_1;
	NI sp_1;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = NIM_FALSE;
	pos_1 = ((NI)0);
	sp_1 = (((*line_p1).len >= ((NI)80)) ? (*line_p1).len : ((NI)80));
	if ((sp_1) < ((NI)0) || (sp_1) > ((NI)IL64(9223372036854775807))){ raiseRangeErrorI(sp_1, ((NI)0), ((NI)IL64(9223372036854775807))); goto BeforeRet_;
	}
	setLengthStrV2((&(*line_p1)), (sp_1));
	{
		while (1) {
			NIM_BOOL fgetsSuccess_1;
			void* m_1;
			NI TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_27;
			NI TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_28;
			{
				NI i_1;
				NI i_2;
				i_1 = (NI)0;
				i_2 = ((NI)0);
				{
					while (1) {
						NI TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_16;
						NI TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_17;
						if (!(i_2 < sp_1)) goto LA5;
						i_1 = i_2;
						if (nimAddInt(pos_1, i_1, &TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_16)) { raiseOverflow(); goto BeforeRet_;
						};
						if ((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_16) < 0 || (NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_16) >= (*line_p1).len){ raiseIndexError2((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_16),(*line_p1).len-1); goto BeforeRet_;
						}
						nimPrepareStrMutationV2((&(*line_p1)));
						(*line_p1).p->data[(NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_16)] = 10;
						if (nimAddInt(i_2, ((NI)1), &TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_17)) { raiseOverflow(); goto BeforeRet_;
						};
						i_2 = (NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_17);
					} LA5: ;
				}
			}
			fgetsSuccess_1 = (NIM_BOOL)0;
			{
				while (1) {
					{
						NCSTRING T9_;
						NIM_BOOL T10_;
						if (pos_1 < 0 || pos_1 >= (*line_p1).len){ raiseIndexError2(pos_1,(*line_p1).len-1); goto BeforeRet_;
						}
						if ((sp_1) < ((int)(-2147483647 -1)) || (sp_1) > ((int)2147483647)){ raiseRangeErrorI(sp_1, ((int)(-2147483647 -1)), ((int)2147483647)); goto BeforeRet_;
						}
						T9_ = (NCSTRING)0;
						T9_ = fgets(((NCSTRING) ((&(*line_p1).p->data[pos_1]))), ((int) (sp_1)), f_p0);
						T10_ = (NIM_BOOL)0;
						T10_ = eqeq___system_u9048(T9_, ((NCSTRING) NIM_NIL));
						fgetsSuccess_1 = !(T10_);
						{
							if (!fgetsSuccess_1) goto LA13_;
							goto LA6;
						}
LA13_: ;
						{
							if (!(errno == EINTR)) goto LA17_;
							errno = ((int)0);
							clearerr(f_p0);
							goto LA8;
						}
LA17_: ;
						checkErr__stdZsyncio_u162(f_p0);
						if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
						goto LA6;
					} LA8: ;
				}
			} LA6: ;
			if (pos_1 < 0 || pos_1 >= (*line_p1).len){ raiseIndexError2(pos_1,(*line_p1).len-1); goto BeforeRet_;
			}
			m_1 = memchr(((void*) ((&(*line_p1).p->data[pos_1]))), ((int)10), ((size_t) (sp_1)));
			{
				NI last_1;
				NI TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_18;
				NIM_BOOL T42_;
				if (!!((m_1 == NIM_NIL))) goto LA21_;
				if (((NI)0) < 0 || ((NI)0) >= (*line_p1).len){ raiseIndexError2(((NI)0),(*line_p1).len-1); goto BeforeRet_;
				}
				if (nimSubInt(((NI) (ptrdiff_t) (m_1)), ((NI) (ptrdiff_t) ((&(*line_p1).p->data[((NI)0)]))), &TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_18)) { raiseOverflow(); goto BeforeRet_;
				};
				last_1 = (NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_18);
				{
					NIM_BOOL T25_;
					NI TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_19;
					NI TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_20;
					NIM_BOOL T29_;
					T25_ = (NIM_BOOL)0;
					T25_ = (((NI)0) < last_1);
					if (!(T25_)) goto LA26_;
					if (nimSubInt(last_1, ((NI)1), &TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_19)) { raiseOverflow(); goto BeforeRet_;
					};
					if ((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_19) < 0 || (NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_19) >= (*line_p1).len){ raiseIndexError2((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_19),(*line_p1).len-1); goto BeforeRet_;
					}
					T25_ = ((NU8)((*line_p1).p->data[(NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_19)]) == (NU8)(13));
LA26_: ;
					if (!T25_) goto LA27_;
					if (nimSubInt(last_1, ((NI)1), &TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_20)) { raiseOverflow(); goto BeforeRet_;
					};
					if (((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_20)) < ((NI)0) || ((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_20)) > ((NI)IL64(9223372036854775807))){ raiseRangeErrorI((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_20), ((NI)0), ((NI)IL64(9223372036854775807))); goto BeforeRet_;
					}
					setLengthStrV2((&(*line_p1)), ((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_20)));
					T29_ = (NIM_BOOL)0;
					T29_ = (((NI)1) < last_1);
					if (T29_) goto LA30_;
					T29_ = fgetsSuccess_1;
LA30_: ;
					result = T29_;
					goto BeforeRet_;
				}
				goto LA23_;
LA27_: ;
				{
					NIM_BOOL T32_;
					NI TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_21;
					T32_ = (NIM_BOOL)0;
					T32_ = (((NI)0) < last_1);
					if (!(T32_)) goto LA33_;
					if (nimSubInt(last_1, ((NI)1), &TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_21)) { raiseOverflow(); goto BeforeRet_;
					};
					if ((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_21) < 0 || (NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_21) >= (*line_p1).len){ raiseIndexError2((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_21),(*line_p1).len-1); goto BeforeRet_;
					}
					T32_ = ((NU8)((*line_p1).p->data[(NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_21)]) == (NU8)(0));
LA33_: ;
					if (!T32_) goto LA34_;
					{
						NIM_BOOL T38_;
						NI TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_22;
						NI TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_23;
						NI TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_24;
						NI TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_25;
						T38_ = (NIM_BOOL)0;
						if (nimAddInt(pos_1, sp_1, &TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_22)) { raiseOverflow(); goto BeforeRet_;
						};
						if (nimSubInt((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_22), ((NI)1), &TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_23)) { raiseOverflow(); goto BeforeRet_;
						};
						T38_ = ((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_23) <= last_1);
						if (T38_) goto LA39_;
						if (nimAddInt(last_1, ((NI)1), &TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_24)) { raiseOverflow(); goto BeforeRet_;
						};
						if ((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_24) < 0 || (NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_24) >= (*line_p1).len){ raiseIndexError2((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_24),(*line_p1).len-1); goto BeforeRet_;
						}
						T38_ = !(((NU8)((*line_p1).p->data[(NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_24)]) == (NU8)(0)));
LA39_: ;
						if (!T38_) goto LA40_;
						if (nimSubInt(last_1, ((NI)1), &TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_25)) { raiseOverflow(); goto BeforeRet_;
						};
						last_1 = (NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_25);
					}
LA40_: ;
				}
				goto LA23_;
LA34_: ;
LA23_: ;
				if ((last_1) < ((NI)0) || (last_1) > ((NI)IL64(9223372036854775807))){ raiseRangeErrorI(last_1, ((NI)0), ((NI)IL64(9223372036854775807))); goto BeforeRet_;
				}
				setLengthStrV2((&(*line_p1)), (last_1));
				T42_ = (NIM_BOOL)0;
				T42_ = (((NI)0) < last_1);
				if (T42_) goto LA43_;
				T42_ = fgetsSuccess_1;
LA43_: ;
				result = T42_;
				goto BeforeRet_;
			}
			goto LA19_;
LA21_: ;
			{
				NI TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_26;
				if (nimSubInt(sp_1, ((NI)1), &TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_26)) { raiseOverflow(); goto BeforeRet_;
				};
				sp_1 = (NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_26);
			}
LA19_: ;
			if (nimAddInt(pos_1, sp_1, &TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_27)) { raiseOverflow(); goto BeforeRet_;
			};
			pos_1 = (NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_27);
			sp_1 = ((NI)128);
			if (nimAddInt(pos_1, sp_1, &TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_28)) { raiseOverflow(); goto BeforeRet_;
			};
			if (((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_28)) < ((NI)0) || ((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_28)) > ((NI)IL64(9223372036854775807))){ raiseRangeErrorI((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_28), ((NI)0), ((NI)IL64(9223372036854775807))); goto BeforeRet_;
			}
			setLengthStrV2((&(*line_p1)), ((NI)(TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_28)));
		}
	}
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(FILE*, open__stdZsyncio_u492)(NimStringV2 filename_p0, tyEnum_FileMode__wjF0STQGT1PBuQEl3p0tng mode_p1, NI bufSize_p2) {
	FILE* result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = 0;
	{
		NIM_BOOL T3_;
		tyObject_IOError__FsM2LSiW5usgjecIvsloBA* T6_;
		NimStringV2 T7_;
		T3_ = (NIM_BOOL)0;
		T3_ = open__stdZsyncio_u413(&result, filename_p0, mode_p1, bufSize_p2);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!!(T3_)) goto LA4_;
		T6_ = NIM_NIL;
		T6_ = (tyObject_IOError__FsM2LSiW5usgjecIvsloBA*) nimNewObj(sizeof(tyObject_IOError__FsM2LSiW5usgjecIvsloBA), NIM_ALIGNOF(tyObject_IOError__FsM2LSiW5usgjecIvsloBA));
		(*T6_).Sup.Sup.Sup.m_type = (&NTIv2__FsM2LSiW5usgjecIvsloBA_);
		(*T6_).Sup.Sup.name = "IOError";
		T7_.len = 0; T7_.p = NIM_NIL;
		T7_ = rawNewString(filename_p0.len + 13);
appendString((&T7_), TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_29);
appendString((&T7_), filename_p0);
		(*T6_).Sup.Sup.message = T7_;
		(*T6_).Sup.Sup.parent = ((Exception*) NIM_NIL);
		raiseExceptionEx((Exception*)T6_, "IOError", "open", "syncio.nim", 793);
goto BeforeRet_;
	}
LA4_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, open__stdZsyncio_u482)(FILE** f_p0, int filehandle_p1, tyEnum_FileMode__wjF0STQGT1PBuQEl3p0tng mode_p2) {
	NIM_BOOL result;
	int oshandle_1;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	oshandle_1 = filehandle_p1;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = setInheritable__stdZsyncio_u286(oshandle_1, NIM_FALSE);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!!(T3_)) goto LA4_;
		result = NIM_FALSE;
		goto BeforeRet_;
	}
LA4_: ;
	(*f_p0) = fdopen(((int) (filehandle_p1)), RawFormatOpen__stdZsyncio_u403[(mode_p2)- 0]);
	result = !(((*f_p0) == ((FILE*) NIM_NIL)));
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NI64, rawFileSize__stdZsyncio_u365)(FILE* file_p0) {
	NI64 result;
	NI64 oldPos_1;
	int T1_;
	int T2_;
	oldPos_1 = ftello(file_p0);
	T1_ = (int)0;
	T1_ = fseeko(file_p0, IL64(0), ((int)2));
	(void)(T1_);
	result = ftello(file_p0);
	T2_ = (int)0;
	T2_ = fseeko(file_p0, oldPos_1, ((int)0));
	(void)(T2_);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, readAllBuffer__stdZsyncio_u360)(FILE* file_p0) {
	NimStringV2 result;
	NimStringV2 buffer_1;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result.len = 0; result.p = NIM_NIL;
	buffer_1.len = 0; buffer_1.p = NIM_NIL;
	result = TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_31;
	buffer_1 = mnewString(((NI)4000));
	{
		while (1) {
			NI bytesRead_1;
			if (((NI)0) < 0 || ((NI)0) >= buffer_1.len){ raiseIndexError2(((NI)0),buffer_1.len-1); goto LA1_;
			}
			bytesRead_1 = readBuffer__stdZsyncio_u165(file_p0, ((void*) ((&buffer_1.p->data[((NI)0)]))), ((NI)4000));
			if (NIM_UNLIKELY(*nimErr_)) goto LA1_;
			{
				if (!(bytesRead_1 == ((NI)4000))) goto LA6_;
				prepareAdd((&result), buffer_1.len + 0);
appendString((&result), buffer_1);
			}
			goto LA4_;
LA6_: ;
			{
				if ((bytesRead_1) < ((NI)0) || (bytesRead_1) > ((NI)IL64(9223372036854775807))){ raiseRangeErrorI(bytesRead_1, ((NI)0), ((NI)IL64(9223372036854775807))); goto LA1_;
				}
				setLengthStrV2((&buffer_1), (bytesRead_1));
				prepareAdd((&result), buffer_1.len + 0);
appendString((&result), buffer_1);
				goto LA2;
			}
LA4_: ;
		}
	} LA2: ;
	{
		LA1_:;
	}
	{
		if (buffer_1.p && !(buffer_1.p->cap & NIM_STRLIT_FLAG)) {
 deallocShared(buffer_1.p);
}
	}
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, readAllFile__stdZsyncio_u373)(FILE* file_p0, NI64 len_p1) {
	NimStringV2 result;
	NI bytes_1;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result.len = 0; result.p = NIM_NIL;
	if ((len_p1) < ((NI)0) || (len_p1) > ((NI)IL64(9223372036854775807))){ raiseRangeErrorI(len_p1, ((NI)0), ((NI)IL64(9223372036854775807))); goto BeforeRet_;
	}
	result = mnewString(((NI) (len_p1)));
	if (((NI)0) < 0 || ((NI)0) >= result.len){ raiseIndexError2(((NI)0),result.len-1); goto BeforeRet_;
	}
	if ((len_p1) < ((NI)0) || (len_p1) > ((NI)IL64(9223372036854775807))){ raiseRangeErrorI(len_p1, ((NI)0), ((NI)IL64(9223372036854775807))); goto BeforeRet_;
	}
	bytes_1 = readBuffer__stdZsyncio_u165(file_p0, ((void*) ((&result.p->data[((NI)0)]))), ((NI) (len_p1)));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = endOfFile__stdZsyncio_u369(file_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!T3_) goto LA4_;
		{
			if (!(((NI64) (bytes_1)) < len_p1)) goto LA8_;
			if ((bytes_1) < ((NI)0) || (bytes_1) > ((NI)IL64(9223372036854775807))){ raiseRangeErrorI(bytes_1, ((NI)0), ((NI)IL64(9223372036854775807))); goto BeforeRet_;
			}
			setLengthStrV2((&result), (bytes_1));
		}
LA8_: ;
	}
	goto LA1_;
LA4_: ;
	{
		NimStringV2 colontmpD_;
		colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
		colontmpD_ = readAllBuffer__stdZsyncio_u360(file_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto LA11_;
		prepareAdd((&result), colontmpD_.len + 0);
appendString((&result), colontmpD_);
		{
			LA11_:;
		}
		{
			if (colontmpD_.p && !(colontmpD_.p->cap & NIM_STRLIT_FLAG)) {
 deallocShared(colontmpD_.p);
}
		}
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA1_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, readAll__stdZsyncio_u382)(FILE* file_p0) {
	NimStringV2 result;
	NI64 colontmpD_;
	NI64 colontmpD__2;
	NI64 len_1;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result.len = 0; result.p = NIM_NIL;
	colontmpD_ = (NI64)0;
	colontmpD__2 = (NI64)0;
	{
		if (!!((file_p0 == __stdinp))) goto LA3_;
		colontmpD_ = rawFileSize__stdZsyncio_u365(file_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		len_1 = colontmpD_;
	}
	goto LA1_;
LA3_: ;
	{
		colontmpD__2 = IL64(-1);
		len_1 = colontmpD__2;
	}
LA1_: ;
	{
		if (!(IL64(0) < len_1)) goto LA8_;
		result = readAllFile__stdZsyncio_u373(file_p0, len_1);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	goto LA6_;
LA8_: ;
	{
		result = readAllBuffer__stdZsyncio_u360(file_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA6_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, readFile__stdZsyncio_u534)(NimStringV2 filename_p0) {
	NimStringV2 result;
	FILE* f_1;
NIM_BOOL oldNimErrFin6_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result.len = 0; result.p = NIM_NIL;
	f_1 = ((FILE*) NIM_NIL);
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = open__stdZsyncio_u413(&f_1, filename_p0, ((tyEnum_FileMode__wjF0STQGT1PBuQEl3p0tng)0), ((NI)-1));
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!T3_) goto LA4_;
		result = readAll__stdZsyncio_u382(f_1);
		if (NIM_UNLIKELY(*nimErr_)) goto LA6_;
		{
			LA6_:;
		}
		{
			oldNimErrFin6_ = *nimErr_; *nimErr_ = NIM_FALSE;
			close__stdZsyncio_u269(f_1);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			*nimErr_ = oldNimErrFin6_;
		}
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	goto LA1_;
LA4_: ;
	{
		tyObject_IOError__FsM2LSiW5usgjecIvsloBA* T10_;
		NimStringV2 T11_;
		T10_ = NIM_NIL;
		T10_ = (tyObject_IOError__FsM2LSiW5usgjecIvsloBA*) nimNewObj(sizeof(tyObject_IOError__FsM2LSiW5usgjecIvsloBA), NIM_ALIGNOF(tyObject_IOError__FsM2LSiW5usgjecIvsloBA));
		(*T10_).Sup.Sup.Sup.m_type = (&NTIv2__FsM2LSiW5usgjecIvsloBA_);
		(*T10_).Sup.Sup.name = "IOError";
		T11_.len = 0; T11_.p = NIM_NIL;
		T11_ = rawNewString(filename_p0.len + 13);
appendString((&T11_), TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_32);
appendString((&T11_), filename_p0);
		(*T10_).Sup.Sup.message = T11_;
		(*T10_).Sup.Sup.parent = ((Exception*) NIM_NIL);
		raiseExceptionEx((Exception*)T10_, "IOError", "readFile", "syncio.nim", 881);
goto BeforeRet_;
	}
LA1_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NI, readChars__stdZsyncio_u177)(FILE* f_p0, NIM_CHAR* a_p1, NI a_p1Len_0) {
	NI result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NI)0;
	if (((NI)0) < 0 || ((NI)0) >= a_p1Len_0){ raiseIndexError2(((NI)0),a_p1Len_0-1); goto BeforeRet_;
	}
	if ((a_p1Len_0) < ((NI)0) || (a_p1Len_0) > ((NI)IL64(9223372036854775807))){ raiseRangeErrorI(a_p1Len_0, ((NI)0), ((NI)IL64(9223372036854775807))); goto BeforeRet_;
	}
	result = readBuffer__stdZsyncio_u165(f_p0, ((void*) ((&a_p1[((NI)0)]))), (a_p1Len_0));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
