/* Generated by Nim Compiler v2.2.10 */
#define NIM_INTBITS 32

#include "nimbase.h"
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.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__vBePDvr8fj01uTfaJy9aD3Q tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q;
typedef struct tyObject_CatchableError__TCF9b1Y9b2ct0xPZvZnaY7gg tyObject_CatchableError__TCF9b1Y9b2ct0xPZvZnaY7gg;
typedef struct Exception Exception;
typedef struct RootObj RootObj;
typedef struct TNimTypeV2 TNimTypeV2;
typedef struct tySequence__S89cE01OvNjsN9c71FKsSrqQ tySequence__S89cE01OvNjsN9c71FKsSrqQ;
typedef struct tySequence__S89cE01OvNjsN9c71FKsSrqQ_Content tySequence__S89cE01OvNjsN9c71FKsSrqQ_Content;
typedef struct tyObject_EOFError__Gv4QdlVwLTIj1uktzwyKeA tyObject_EOFError__Gv4QdlVwLTIj1uktzwyKeA;
typedef struct tySequence__sM4lkSb7zS6F7OVMvW9cffQ tySequence__sM4lkSb7zS6F7OVMvW9cffQ;
typedef struct tySequence__sM4lkSb7zS6F7OVMvW9cffQ_Content tySequence__sM4lkSb7zS6F7OVMvW9cffQ_Content;
typedef struct tyObject_StackTraceEntry__RcJz5RXFIYjIseutvVFICA tyObject_StackTraceEntry__RcJz5RXFIYjIseutvVFICA;
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__S89cE01OvNjsN9c71FKsSrqQ {
  NI len; tySequence__S89cE01OvNjsN9c71FKsSrqQ_Content* p;
};
struct Exception {
	RootObj Sup;
	Exception* parent;
	NCSTRING name;
	NimStringV2 message;
	tySequence__S89cE01OvNjsN9c71FKsSrqQ trace;
	Exception* up;
};
struct tyObject_CatchableError__TCF9b1Y9b2ct0xPZvZnaY7gg {
	Exception Sup;
};
struct tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q {
	tyObject_CatchableError__TCF9b1Y9b2ct0xPZvZnaY7gg Sup;
};
typedef NU8 tyEnum_FileMode__YkEVJbjDa9aPvYTBr8yiUWg;
typedef NCSTRING tyArray__2J68iTBMUUEsOlI6ErnjHw[5];
struct tyObject_EOFError__Gv4QdlVwLTIj1uktzwyKeA {
	tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q Sup;
};
struct tySequence__sM4lkSb7zS6F7OVMvW9cffQ {
  NI len; tySequence__sM4lkSb7zS6F7OVMvW9cffQ_Content* p;
};
typedef NU8 tyEnum_FileSeekPos__QFEvOmw2SocDVWqi9ciAztA;
struct tyObject_StackTraceEntry__RcJz5RXFIYjIseutvVFICA {
	NCSTRING procname;
	NI line;
	NCSTRING filename;
};
struct tySequence__S89cE01OvNjsN9c71FKsSrqQ_Content { NI cap; tyObject_StackTraceEntry__RcJz5RXFIYjIseutvVFICA data[SEQ_DECL_SIZE]; };
struct tySequence__sM4lkSb7zS6F7OVMvW9cffQ_Content { NI cap; NimStringV2 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_u1742)(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_u24)(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_u2697)(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_NIMCALL(void, eqdestroy___system_u2691)(NimStringV2 dest_p0);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringV2 s_p0);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, open__stdZsyncio_u412)(FILE** f_p0, NimStringV2 filename_p1, tyEnum_FileMode__YkEVJbjDa9aPvYTBr8yiUWg mode_p2, NI bufSize_p3);
N_LIB_PRIVATE N_NIMCALL(int, getFileHandle__stdZsyncio_u280)(FILE* f_p0);
N_LIB_PRIVATE N_NIMCALL(void, setLengthStrV2)(NimStringV2* s_p0, NI newLen_p1);
static N_INLINE(void, nimPrepareStrMutationV2)(NimStringV2* s_p0);
N_LIB_PRIVATE N_NIMCALL(void, nimPrepareStrMutationImpl__system_u2430)(NimStringV2* s_p0);
static N_INLINE(NIM_BOOL, eqeq___system_u8576)(NCSTRING x_p0, NCSTRING y_p1);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, readAll__stdZsyncio_u381)(FILE* file_p0);
N_LIB_PRIVATE N_NIMCALL(NI64, rawFileSize__stdZsyncio_u364)(FILE* file_p0);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, readAllFile__stdZsyncio_u372)(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_u368)(FILE* f_p0);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, readAllBuffer__stdZsyncio_u359)(FILE* file_p0);
N_LIB_PRIVATE N_NIMCALL(void, prepareAdd)(NimStringV2* s_p0, NI addLen_p1);
N_LIB_PRIVATE N_NIMCALL(void, close__stdZsyncio_u268)(FILE* f_p0);
N_NIMCALL(NimStringV2, rawNewString)(NI cap_p0);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, readLine__stdZsyncio_u290)(FILE* f_p0, NimStringV2* line_p1);
N_LIB_PRIVATE N_NOINLINE(void, raiseEOF__stdZsyncio_u95)(void);
N_LIB_PRIVATE N_NIMCALL(void, write__stdZsyncio_u254)(FILE* f_p0, NimStringV2 s_p1);
N_LIB_PRIVATE N_NIMCALL(tySequence__sM4lkSb7zS6F7OVMvW9cffQ, newSeq__stdZsyncio_u571)(NI len_p0);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, setInheritable__stdZsyncio_u286)(int f_p0, NIM_BOOL inheritable_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__vBePDvr8fj01uTfaJy9aD3Q_;
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[0+1];
} TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_12 = { 0 | NIM_STRLIT_FLAG, "" };
static const NimStringV2 TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_13 = {0, (NimStrPayload*)&TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_12};
static const NimStringV2 TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_14 = {13, (NimStrPayload*)&TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_10};
extern TNimTypeV2 NTIv2__Gv4QdlVwLTIj1uktzwyKeA_;
static const struct {
  NI cap; NIM_CHAR data[11+1];
} TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_15 = { 11 | NIM_STRLIT_FLAG, "EOF reached" };
static const NimStringV2 TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_16 = {11, (NimStrPayload*)&TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_15};
static const NimStringV2 TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_17 = {13, (NimStrPayload*)&TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_10};
static const NimStringV2 TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_18 = {13, (NimStrPayload*)&TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_10};
static const struct {
  NI cap; NIM_CHAR data[24+1];
} TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_19 = { 24 | NIM_STRLIT_FLAG, "cannot set file position" };
static const NimStringV2 TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_20 = {24, (NimStrPayload*)&TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_19};
static const struct {
  NI cap; NIM_CHAR data[29+1];
} TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_21 = { 29 | NIM_STRLIT_FLAG, "cannot retrieve file position" };
static const NimStringV2 TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_22 = {29, (NimStrPayload*)&TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_21};
N_LIB_PRIVATE NIM_CONST tyArray__2J68iTBMUUEsOlI6ErnjHw FormatOpen__stdZsyncio_u403 = {"rbe",
"wbe",
"w+be",
"r+be",
"abe"}
;
N_LIB_PRIVATE NIM_CONST tyArray__2J68iTBMUUEsOlI6ErnjHw RawFormatOpen__stdZsyncio_u402 = {"rb",
"wb",
"w+b",
"r+b",
"ab"}
;
extern NIM_BOOL nimInErrorMode__system_u4143;
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_u1742)(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_u1742(((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__vBePDvr8fj01uTfaJy9aD3Q* T1_;
{	T1_ = NIM_NIL;
	T1_ = (tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q*) nimNewObj(sizeof(tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q), NIM_ALIGNOF(tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q));
	(*T1_).Sup.Sup.Sup.m_type = (&NTIv2__vBePDvr8fj01uTfaJy9aD3Q_);
	(*T1_).Sup.Sup.name = "IOError";
	colontmpD_ = eqdup___system_u2697(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_u4143);
	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_u24(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_:;
		}
		{
			eqdestroy___system_u2691(colontmpD__2);
			eqdestroy___system_u2691(colontmpD_);
			eqdestroy___system_u2691(msg_1);
		}
		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_;
		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, open__stdZsyncio_u412)(FILE** f_p0, NimStringV2 filename_p1, tyEnum_FileMode__YkEVJbjDa9aPvYTBr8yiUWg mode_p2, NI bufSize_p3) {
	NIM_BOOL result;
	void* p_1;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	p_1 = fopen(nimToCStringConv(filename_p1), FormatOpen__stdZsyncio_u403[(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_: ;
		result = NIM_TRUE;
		(*f_p0) = ((FILE*) (p_1));
		{
			NIM_BOOL T20_;
			int T24_;
			T20_ = (NIM_BOOL)0;
			T20_ = (((NI)0) < bufSize_p3);
			if (!(T20_)) goto LA21_;
			T20_ = ((NU32)(((NU) (bufSize_p3))) <= (NU32)(((NU)IL64(4294967295))));
LA21_: ;
			if (!T20_) goto LA22_;
			T24_ = (int)0;
			T24_ = setvbuf((*f_p0), NIM_NIL, _IOFBF, ((size_t) (bufSize_p3)));
			(void)(T24_);
		}
		goto LA18_;
LA22_: ;
		{
			int T28_;
			if (!(bufSize_p3 == ((NI)0))) goto LA26_;
			T28_ = (int)0;
			T28_ = setvbuf((*f_p0), NIM_NIL, _IONBF, ((size_t)0));
			(void)(T28_);
		}
		goto LA18_;
LA26_: ;
LA18_: ;
	}
	goto LA1_;
LA3_: ;
	{
		result = NIM_FALSE;
	}
LA1_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(FILE*, open__stdZsyncio_u485)(NimStringV2 filename_p0, tyEnum_FileMode__YkEVJbjDa9aPvYTBr8yiUWg mode_p1, NI bufSize_p2) {
	FILE* result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = 0;
	{
		NIM_BOOL T3_;
		tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q* T6_;
		NimStringV2 T7_;
		T3_ = (NIM_BOOL)0;
		T3_ = open__stdZsyncio_u412(&result, filename_p0, mode_p1, bufSize_p2);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!!(T3_)) goto LA4_;
		T6_ = NIM_NIL;
		T6_ = (tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q*) nimNewObj(sizeof(tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q), NIM_ALIGNOF(tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q));
		(*T6_).Sup.Sup.Sup.m_type = (&NTIv2__vBePDvr8fj01uTfaJy9aD3Q_);
		(*T6_).Sup.Sup.name = "IOError";
		T7_.len = 0; T7_.p = NIM_NIL;
		T7_ = rawNewString(filename_p0.len + 13);
appendString((&T7_), TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_11);
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;
}
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)1073741824)) == ((NI)1073741824));
LA4_: ;
		if (!T3_) goto LA5_;
		nimPrepareStrMutationImpl__system_u2430(s_p0);
	}
LA5_: ;
}
static N_INLINE(NIM_BOOL, eqeq___system_u8576)(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;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, readLine__stdZsyncio_u290)(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));
	setLengthStrV2((&(*line_p1)), (sp_1));
	{
		while (1) {
			NIM_BOOL fgetsSuccess_1;
			void* m_1;
			{
				NI i_1;
				NI i_2;
				i_1 = (NI)0;
				i_2 = ((NI)0);
				{
					while (1) {
						if (!(i_2 < sp_1)) goto LA5;
						i_1 = i_2;
						nimPrepareStrMutationV2((&(*line_p1)));
						(*line_p1).p->data[(NI)(pos_1 + i_1)] = 10;
						i_2 += ((NI)1);
					} LA5: ;
				}
			}
			fgetsSuccess_1 = (NIM_BOOL)0;
			{
				while (1) {
					{
						NCSTRING T9_;
						NIM_BOOL T10_;
						T9_ = (NCSTRING)0;
						T9_ = fgets(((NCSTRING) ((&(*line_p1).p->data[pos_1]))), ((int) (sp_1)), f_p0);
						T10_ = (NIM_BOOL)0;
						T10_ = eqeq___system_u8576(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: ;
			m_1 = memchr(((void*) ((&(*line_p1).p->data[pos_1]))), ((int)10), ((size_t) (sp_1)));
			{
				NI last_1;
				NIM_BOOL T42_;
				if (!!((m_1 == NIM_NIL))) goto LA21_;
				last_1 = (NI)(((NI) (ptrdiff_t) (m_1)) - ((NI) (ptrdiff_t) ((&(*line_p1).p->data[((NI)0)]))));
				{
					NIM_BOOL T25_;
					NIM_BOOL T29_;
					T25_ = (NIM_BOOL)0;
					T25_ = (((NI)0) < last_1);
					if (!(T25_)) goto LA26_;
					T25_ = ((NU8)((*line_p1).p->data[(NI)(last_1 - ((NI)1))]) == (NU8)(13));
LA26_: ;
					if (!T25_) goto LA27_;
					setLengthStrV2((&(*line_p1)), ((NI)(last_1 - ((NI)1))));
					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_;
					T32_ = (NIM_BOOL)0;
					T32_ = (((NI)0) < last_1);
					if (!(T32_)) goto LA33_;
					T32_ = ((NU8)((*line_p1).p->data[(NI)(last_1 - ((NI)1))]) == (NU8)(0));
LA33_: ;
					if (!T32_) goto LA34_;
					{
						NIM_BOOL T38_;
						T38_ = (NIM_BOOL)0;
						T38_ = ((NI)((NI)(pos_1 + sp_1) - ((NI)1)) <= last_1);
						if (T38_) goto LA39_;
						T38_ = !(((NU8)((*line_p1).p->data[(NI)(last_1 + ((NI)1))]) == (NU8)(0)));
LA39_: ;
						if (!T38_) goto LA40_;
						last_1 -= ((NI)1);
					}
LA40_: ;
				}
				goto LA23_;
LA34_: ;
LA23_: ;
				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_: ;
			{
				sp_1 -= ((NI)1);
			}
LA19_: ;
			pos_1 += sp_1;
			sp_1 = ((NI)128);
			setLengthStrV2((&(*line_p1)), ((NI)(pos_1 + sp_1)));
		}
	}
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, close__stdZsyncio_u268)(FILE* f_p0) {
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	{
		int x_1;
		if (!!((f_p0 == 0))) goto LA3_;
		x_1 = fclose(f_p0);
		{
			if (!(x_1 < ((NI32)0))) goto LA7_;
			checkErr__stdZsyncio_u162(f_p0);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		}
LA7_: ;
	}
LA3_: ;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(NI64, rawFileSize__stdZsyncio_u364)(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(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;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, endOfFile__stdZsyncio_u368)(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(NimStringV2, readAllBuffer__stdZsyncio_u359)(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_13;
	buffer_1 = mnewString(((NI)4000));
	{
		while (1) {
			NI bytesRead_1;
			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_: ;
			{
				setLengthStrV2((&buffer_1), (bytesRead_1));
				prepareAdd((&result), buffer_1.len + 0);
appendString((&result), buffer_1);
				goto LA2;
			}
LA4_: ;
		}
	} LA2: ;
	{
		LA1_:;
	}
	{
		eqdestroy___system_u2691(buffer_1);
	}
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, readAllFile__stdZsyncio_u372)(FILE* file_p0, NI64 len_p1) {
	NimStringV2 result;
	NI bytes_1;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result.len = 0; result.p = NIM_NIL;
	result = mnewString(((NI) (len_p1)));
	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_u368(file_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!T3_) goto LA4_;
		{
			if (!(((NI64) (bytes_1)) < len_p1)) goto LA8_;
			setLengthStrV2((&result), (bytes_1));
		}
LA8_: ;
	}
	goto LA1_;
LA4_: ;
	{
		NimStringV2 colontmpD_;
		colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
		colontmpD_ = readAllBuffer__stdZsyncio_u359(file_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto LA11_;
		prepareAdd((&result), colontmpD_.len + 0);
appendString((&result), colontmpD_);
		{
			LA11_:;
		}
		{
			eqdestroy___system_u2691(colontmpD_);
		}
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA1_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, readAll__stdZsyncio_u381)(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 == stdin))) goto LA3_;
		colontmpD_ = rawFileSize__stdZsyncio_u364(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_u372(file_p0, len_1);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	goto LA6_;
LA8_: ;
	{
		result = readAllBuffer__stdZsyncio_u359(file_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA6_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, readFile__stdZsyncio_u527)(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_u412(&f_1, filename_p0, ((tyEnum_FileMode__YkEVJbjDa9aPvYTBr8yiUWg)0), ((NI)-1));
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!T3_) goto LA4_;
		result = readAll__stdZsyncio_u381(f_1);
		if (NIM_UNLIKELY(*nimErr_)) goto LA6_;
		{
			LA6_:;
		}
		{
			oldNimErrFin6_ = *nimErr_; *nimErr_ = NIM_FALSE;
			close__stdZsyncio_u268(f_1);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			*nimErr_ = oldNimErrFin6_;
		}
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	goto LA1_;
LA4_: ;
	{
		tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q* T10_;
		NimStringV2 T11_;
		T10_ = NIM_NIL;
		T10_ = (tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q*) nimNewObj(sizeof(tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q), NIM_ALIGNOF(tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q));
		(*T10_).Sup.Sup.Sup.m_type = (&NTIv2__vBePDvr8fj01uTfaJy9aD3Q_);
		(*T10_).Sup.Sup.name = "IOError";
		T11_.len = 0; T11_.p = NIM_NIL;
		T11_ = rawNewString(filename_p0.len + 13);
appendString((&T11_), TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_14);
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;
	result = readBuffer__stdZsyncio_u165(f_p0, ((void*) ((&a_p1[((NI)0)]))), (a_p1Len_0));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NOINLINE(void, raiseEOF__stdZsyncio_u95)(void) {
	tyObject_EOFError__Gv4QdlVwLTIj1uktzwyKeA* T1_;
{	T1_ = NIM_NIL;
	T1_ = (tyObject_EOFError__Gv4QdlVwLTIj1uktzwyKeA*) nimNewObj(sizeof(tyObject_EOFError__Gv4QdlVwLTIj1uktzwyKeA), NIM_ALIGNOF(tyObject_EOFError__Gv4QdlVwLTIj1uktzwyKeA));
	(*T1_).Sup.Sup.Sup.Sup.m_type = (&NTIv2__Gv4QdlVwLTIj1uktzwyKeA_);
	(*T1_).Sup.Sup.Sup.name = "EOFError";
	(*T1_).Sup.Sup.Sup.message = TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_16;
	(*T1_).Sup.Sup.Sup.parent = ((Exception*) NIM_NIL);
	raiseExceptionEx((Exception*)T1_, "EOFError", "raiseEOF", "syncio.nim", 164);
goto BeforeRet_;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, readLine__stdZsyncio_u319)(FILE* f_p0) {
	NimStringV2 result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = rawNewString(((NI)80));
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = readLine__stdZsyncio_u290(f_p0, (&result));
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!!(T3_)) goto LA4_;
		raiseEOF__stdZsyncio_u95();
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA4_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NI, readBytes__icZrodfiles_u386)(FILE* f_p0, NU8* a_p1, NI a_p1Len_0, NI start_p2, NI len_p3) {
	NI result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NI)0;
	result = readBuffer__stdZsyncio_u165(f_p0, ((void*) ((&a_p1[start_p2]))), len_p3);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, writeFile__stdZsyncio_u532)(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_u412(&f_1, filename_p0, ((tyEnum_FileMode__YkEVJbjDa9aPvYTBr8yiUWg)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_u268(f_1);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			*nimErr_ = oldNimErrFin6_;
		}
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	goto LA1_;
LA4_: ;
	{
		tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q* T10_;
		NimStringV2 T11_;
		T10_ = NIM_NIL;
		T10_ = (tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q*) nimNewObj(sizeof(tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q), NIM_ALIGNOF(tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q));
		(*T10_).Sup.Sup.Sup.m_type = (&NTIv2__vBePDvr8fj01uTfaJy9aD3Q_);
		(*T10_).Sup.Sup.name = "IOError";
		T11_.len = 0; T11_.p = NIM_NIL;
		T11_ = rawNewString(filename_p0.len + 13);
appendString((&T11_), TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_17);
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(tySequence__sM4lkSb7zS6F7OVMvW9cffQ, readLines__stdZsyncio_u550)(NimStringV2 filename_p0, NI n_p1) {
	tySequence__sM4lkSb7zS6F7OVMvW9cffQ 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_u412(&f_1, filename_p0, ((tyEnum_FileMode__YkEVJbjDa9aPvYTBr8yiUWg)0), ((NI)-1));
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!T3_) goto LA4_;
		result = newSeq__stdZsyncio_u571(n_p1);
		{
			NI i_1;
			NI colontmp_;
			NI res_1;
			i_1 = (NI)0;
			colontmp_ = (NI)0;
			colontmp_ = (NI)(n_p1 - ((NI)1));
			res_1 = ((NI)0);
			{
				while (1) {
					if (!(res_1 <= colontmp_)) goto LA9;
					i_1 = ((NI) (res_1));
					{
						NIM_BOOL T12_;
						T12_ = (NIM_BOOL)0;
						T12_ = readLine__stdZsyncio_u290(f_1, (&result.p->data[i_1]));
						if (NIM_UNLIKELY(*nimErr_)) goto LA6_;
						if (!!(T12_)) goto LA13_;
						raiseEOF__stdZsyncio_u95();
						if (NIM_UNLIKELY(*nimErr_)) goto LA6_;
					}
LA13_: ;
					res_1 += ((NI)1);
				} LA9: ;
			}
		}
		{
			LA6_:;
		}
		{
			oldNimErrFin6_ = *nimErr_; *nimErr_ = NIM_FALSE;
			close__stdZsyncio_u268(f_1);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			*nimErr_ = oldNimErrFin6_;
		}
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	goto LA1_;
LA4_: ;
	{
		tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q* T18_;
		NimStringV2 T19_;
		T18_ = NIM_NIL;
		T18_ = (tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q*) nimNewObj(sizeof(tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q), NIM_ALIGNOF(tyObject_IOError__vBePDvr8fj01uTfaJy9aD3Q));
		(*T18_).Sup.Sup.Sup.m_type = (&NTIv2__vBePDvr8fj01uTfaJy9aD3Q_);
		(*T18_).Sup.Sup.name = "IOError";
		T19_.len = 0; T19_.p = NIM_NIL;
		T19_ = rawNewString(filename_p0.len + 13);
appendString((&T19_), TM__xNF6mvRQ4Pd1hTNM9cEHXwQ_18);
appendString((&T19_), filename_p0);
		(*T18_).Sup.Sup.message = T19_;
		(*T18_).Sup.Sup.parent = ((Exception*) NIM_NIL);
		raiseExceptionEx((Exception*)T18_, "IOError", "readLines", "syncio.nim", 924);
goto BeforeRet_;
	}
LA1_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, setInheritable__stdZsyncio_u286)(int f_p0, NIM_BOOL inheritable_p1) {
	NIM_BOOL result;
	int colontmpD_;
	int colontmpD__2;
	int T1_;
	int T7_;
	colontmpD_ = (int)0;
	colontmpD__2 = (int)0;
	T1_ = (int)0;
	{
		if (!inheritable_p1) goto LA4_;
		colontmpD_ = FIONCLEX;
		T1_ = colontmpD_;
	}
	goto LA2_;
LA4_: ;
	{
		colontmpD__2 = FIOCLEX;
		T1_ = colontmpD__2;
	}
LA2_: ;
	T7_ = (int)0;
	T7_ = ioctl(f_p0, T1_);
	result = !((T7_ == ((NI32)-1)));
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, open__stdZsyncio_u475)(FILE** f_p0, int filehandle_p1, tyEnum_FileMode__YkEVJbjDa9aPvYTBr8yiUWg 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_u402[(mode_p2)- 0]);
	result = !(((*f_p0) == ((FILE*) NIM_NIL)));
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, setFilePos__stdZsyncio_u496)(FILE* f_p0, NI64 pos_p1, tyEnum_FileSeekPos__QFEvOmw2SocDVWqi9ciAztA 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_20);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA4_: ;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(NI64, getFilePos__stdZsyncio_u519)(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_22);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA3_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NI, writeBytes__icZrodfiles_u193)(FILE* f_p0, NU8* a_p1, NI a_p1Len_0, NI start_p2, NI len_p3) {
	NI result;
	NI8* x_1;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NI)0;
	x_1 = ((NI8*) (a_p1));
	result = writeBuffer__stdZsyncio_u196(f_p0, ((void*) ((&x_1[start_p2]))), len_p3);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
