/* Generated by Nim Compiler v1.3.5 */
/*   (c) 2020 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 64

/* section: NIM_merge_HEADERS */

#include "nimbase.h"
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
#include <errno.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

/* section: NIM_merge_FRAME_DEFINES */
#define nimfr_(x, y)
#define nimln_(x, y)

/* section: NIM_merge_FORWARD_TYPES */
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw;
typedef struct tyObject_CatchableError__qrLSDoe2oBoAqNtJ9badtnA tyObject_CatchableError__qrLSDoe2oBoAqNtJ9badtnA;
typedef struct Exception Exception;
typedef struct RootObj RootObj;
typedef struct tySequence__uB9b75OUPRENsBAu4AnoePA tySequence__uB9b75OUPRENsBAu4AnoePA;
typedef struct tyObject_EOFError__KGSY1JdrNB7Xi8KDhXFhSg tyObject_EOFError__KGSY1JdrNB7Xi8KDhXFhSg;
typedef struct tyObject_StackTraceEntry__oLyohQ7O2XOvGnflOss8EA tyObject_StackTraceEntry__oLyohQ7O2XOvGnflOss8EA;

/* section: NIM_merge_TYPES */
struct TGenericSeq {
NI len;
NI reserved;
};
struct NimStringDesc {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef NU8 tyEnum_TNimKind__jIBKr1ejBgsfM33Kxw4j7A;
typedef NU8 tySet_tyEnum_TNimTypeFlag__v8QUszD1sWlSIWZz7mC4bQ;
typedef N_NIMCALL_PTR(void, tyProc__ojoeKfW4VYIm36I9cpDTQIg) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, tyProc__WSm2xU5ARYv9aAR4l0z9c9auQ) (void* p);
struct TNimType {
NI size;
NI align;
tyEnum_TNimKind__jIBKr1ejBgsfM33Kxw4j7A kind;
tySet_tyEnum_TNimTypeFlag__v8QUszD1sWlSIWZz7mC4bQ flags;
TNimType* base;
TNimNode* node;
void* finalizer;
tyProc__ojoeKfW4VYIm36I9cpDTQIg marker;
tyProc__WSm2xU5ARYv9aAR4l0z9c9auQ deepcopy;
};
typedef NU8 tyEnum_FileMode__ZJfK20XeZ9bv2j1pZjw9aswg;
typedef NimStringDesc* tyArray__XL8FfPqMNtuU56fW9c8pBtQ[5];
typedef NIM_CHAR tyArray__PbS9a6gkxCuxWEnFq4lOU9aw[24];
typedef NIM_CHAR tyArray__hToc9cajraNwyrQdTvLCS3A[116];
struct RootObj {
TNimType* m_type;
};
struct Exception {
  RootObj Sup;
Exception* parent;
NCSTRING name;
NimStringDesc* message;
tySequence__uB9b75OUPRENsBAu4AnoePA* trace;
Exception* up;
};
struct tyObject_CatchableError__qrLSDoe2oBoAqNtJ9badtnA {
  Exception Sup;
};
struct tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw {
  tyObject_CatchableError__qrLSDoe2oBoAqNtJ9badtnA Sup;
};
typedef NU8 tyEnum_TNimNodeKind__unfNsxrcATrufDZmpBq4HQ;
struct TNimNode {
tyEnum_TNimNodeKind__unfNsxrcATrufDZmpBq4HQ kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
typedef NU8 tyEnum_FileSeekPos__I9aQjuvWxs8BspGbxwsngWw;
struct tyObject_EOFError__KGSY1JdrNB7Xi8KDhXFhSg {
  tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw Sup;
};
struct tyObject_StackTraceEntry__oLyohQ7O2XOvGnflOss8EA {
NCSTRING procname;
NI line;
NCSTRING filename;
};

/* section: NIM_merge_SEQ_TYPES */
struct tySequence__uB9b75OUPRENsBAu4AnoePA {
  TGenericSeq Sup;
  tyObject_StackTraceEntry__oLyohQ7O2XOvGnflOss8EA data[SEQ_DECL_SIZE];
};

/* section: NIM_merge_PROC_HEADERS */
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringDesc* s);
N_LIB_PRIVATE N_NIMCALL(int, getFileHandle__hOwLbM7eXaZgEJrHWLeiNg)(FILE* f);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, modeIsDir__L1LOhUxShkaoXfurkKTXPA)(mode_t m);
N_LIB_PRIVATE N_NIMCALL(void, close__fU6ZlJAtQ9bre04EDZLdGsA)(FILE* f);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(NI, writeBuffer__Y9atVWUcVyKHG9aBP4D0P9czA)(FILE* f, void* buffer, NI len);
N_LIB_PRIVATE N_NIMCALL(void, checkErr__fU6ZlJAtQ9bre04EDZLdGsA_2)(FILE* f);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
static N_INLINE(void, copyMem__i80o3k0SgEI5gTRCzYdyWAsystem)(void* dest, void* source, NI size);
static N_INLINE(void, nimCopyMem)(void* dest, void* source, NI size);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, nimIntToStr)(NI x);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, cstrToNimstr)(NCSTRING str);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_LIB_PRIVATE N_NOINLINE(void, raiseEIO__ZYk14k3sVNZUIjJjtqzFZQ)(NimStringDesc* msg);
N_LIB_PRIVATE N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_LIB_PRIVATE N_NIMCALL(void, raiseExceptionEx)(Exception* e, NCSTRING ename, NCSTRING procname, NCSTRING filename, NI line);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, open__gq12VLhVO0NBzUTnGgz4nw)(FILE** f, NimStringDesc* filename, tyEnum_FileMode__ZJfK20XeZ9bv2j1pZjw9aswg mode, NI bufSize);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, setLengthStr)(NimStringDesc* s, NI newLen);
static N_INLINE(NIM_BOOL, eqeq___aqip9cmQIuefPKdd25wuEEwsystem)(NCSTRING x, NCSTRING y);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, setInheritable__avyDiy1HdQrfaD3Ql9b63EQ)(int f, NIM_BOOL inheritable);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, readAll__mQf9blHFlTwuSvJjirhpY6g)(FILE* file);
N_LIB_PRIVATE N_NIMCALL(NI64, rawFileSize__2ezUTSmBrmr5VkZNxReTYQ)(FILE* file);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, readAllFile__W4tKfHpbz7kHhikLsBc0EA)(FILE* file, NI64 len);
N_NIMCALL(NimStringDesc*, mnewString)(NI len);
N_LIB_PRIVATE N_NIMCALL(NI, readBuffer__Y9atVWUcVyKHG9aBP4D0P9czA_2)(FILE* f, void* buffer, NI len);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, endOfFile__FK5lmHTzEdX6epYBp9bfgMg)(FILE* f);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, readAllBuffer__mQf9blHFlTwuSvJjirhpY6g_2)(FILE* file);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, resizeString)(NimStringDesc* dest, NI addlen);
N_NIMCALL(NimStringDesc*, rawNewString)(NI cap);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, readLine__FbqDHP9bu7nqCh9c04dnSOxw)(FILE* f, NimStringDesc** line);
N_LIB_PRIVATE N_NOINLINE(void, raiseEOF__CA1KPE9bDgvXVjqamZd5T9bQ)(void);

/* section: NIM_merge_DATA */
N_LIB_PRIVATE TNimType NTI__MAWzaQJYFu3mlxj0Ppxhmw_;
N_LIB_PRIVATE TNimType NTI__XBeRj4rw9bUuE7CB3DS1rgg_;
STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_2, "rbe", 3);
STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_3, "wbe", 3);
STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_4, "w+be", 4);
STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_5, "r+be", 4);
STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_6, "abe", 3);
N_LIB_PRIVATE NIM_CONST tyArray__XL8FfPqMNtuU56fW9c8pBtQ FormatOpen__iWZDMxVvD1FETfmW09b8gFQ = {((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_2),
((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_3),
((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_4),
((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_5),
((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_6)}
;
STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_7, "errno: ", 7);
STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_8, " `", 2);
STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_9, "`", 1);
extern TNimType NTI__HMIVdYjdZYWskTmTQVo5BQ_;
extern TNimType NTI__iLZrPn9anoh9ad1MmO0RczFw_;
STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_10, "cannot write string to file", 27);
STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_11, "cannot open: ", 13);
N_LIB_PRIVATE TNimType NTI__2gIj3gQlK3HZJjQaYCP6ZQ_;
STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_12, "cannot set file position", 24);
STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_13, "cannot retrieve file position", 29);
extern TNimType NTI__LEclZrWX2FQAodlapxGITw_;
extern TNimType NTI__KGSY1JdrNB7Xi8KDhXFhSg_;
STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_14, "EOF reached", 11);

/* section: NIM_merge_VARS */
extern NIM_BOOL nimInErrorMode__759bT87luu8XGcbkw13FUjA;

/* section: NIM_merge_PROCS */
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringDesc* s) {
	NCSTRING result;
	result = (NCSTRING)0;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = (s == NIM_NIL);
		if (T3_) goto LA4_;
		T3_ = ((*s).Sup.len == ((NI) 0));
		LA4_: ;
		if (!T3_) goto LA5_;
		result = "";
	}
	goto LA1_;
	LA5_: ;
	{
		result = ((NCSTRING) ((*s).data));
	}
	LA1_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, echoBinSafe)(NimStringDesc** args, NI argsLen_0) {
	int T6_;
	int T7_;
	flockfile(stdout);
	{
		NimStringDesc** s;
		NI i;
		s = (NimStringDesc**)0;
		i = ((NI) 0);
		{
			while (1) {
				void* T4_;
				int T5_;
				if (!(i < argsLen_0)) goto LA3;
				s = (&args[i]);
				T4_ = (void*)0;
				T4_ = ((void*) (nimToCStringConv((*s))));
				T5_ = (int)0;
				T5_ = fwrite(T4_, ((size_t) (((*s) ? (*s)->Sup.len : 0))), ((size_t) 1), stdout);
				(void)(T5_);
				i += ((NI) 1);
			} LA3: ;
		}
	}
	T6_ = (int)0;
	T6_ = fwrite(((void*) ("\012")), ((size_t) 1), ((size_t) 1), stdout);
	(void)(T6_);
	T7_ = (int)0;
	T7_ = fflush(stdout);
	(void)(T7_);
	funlockfile(stdout);
}
N_LIB_PRIVATE N_NIMCALL(int, getFileHandle__hOwLbM7eXaZgEJrHWLeiNg)(FILE* f) {
	int result;
	result = (int)0;
	result = fileno(f);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, modeIsDir__L1LOhUxShkaoXfurkKTXPA)(mode_t m) {
	NIM_BOOL result;
	result = (NIM_BOOL)0;
	result = ((NI32)(m & ((NI32) 61440)) == ((NI32) 16384));
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, close__fU6ZlJAtQ9bre04EDZLdGsA)(FILE* f) {
	{
		int T5_;
		if (!!((f == 0))) goto LA3_;
		T5_ = (int)0;
		T5_ = fclose(f);
		(void)(T5_);
	}
	LA3_: ;
}
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (NIM_BOOL*)0;
	result = (&nimInErrorMode__759bT87luu8XGcbkw13FUjA);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, open__gq12VLhVO0NBzUTnGgz4nw)(FILE** f, NimStringDesc* filename, tyEnum_FileMode__ZJfK20XeZ9bv2j1pZjw9aswg mode, NI bufSize) {
	NIM_BOOL result;
	void* p;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NIM_BOOL)0;
	p = fopen(nimToCStringConv(filename), nimToCStringConv(FormatOpen__iWZDMxVvD1FETfmW09b8gFQ[(mode)- 0]));
	{
		FILE* f2;
		struct stat res;
		if (!!((p == NIM_NIL))) goto LA3_;
		f2 = ((FILE*) (p));
		{
			NIM_BOOL T7_;
			int T8_;
			int T9_;
			T7_ = (NIM_BOOL)0;
			T8_ = (int)0;
			T8_ = getFileHandle__hOwLbM7eXaZgEJrHWLeiNg(f2);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			T9_ = (int)0;
			T9_ = fstat(T8_, (&res));
			T7_ = (((NI32) 0) <= T9_);
			if (!(T7_)) goto LA10_;
			T7_ = modeIsDir__L1LOhUxShkaoXfurkKTXPA(res.st_mode);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			LA10_: ;
			if (!T7_) goto LA11_;
			close__fU6ZlJAtQ9bre04EDZLdGsA(f2);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			result = NIM_FALSE;
			goto BeforeRet_;
		}
		LA11_: ;
		result = NIM_TRUE;
		(*f) = ((FILE*) (p));
		{
			NIM_BOOL T15_;
			int T19_;
			T15_ = (NIM_BOOL)0;
			T15_ = (((NI) 0) < bufSize);
			if (!(T15_)) goto LA16_;
			T15_ = (bufSize <= ((NI) 2147483647));
			LA16_: ;
			if (!T15_) goto LA17_;
			T19_ = (int)0;
			T19_ = setvbuf((*f), NIM_NIL, _IOFBF, ((size_t) (bufSize)));
			(void)(T19_);
		}
		goto LA13_;
		LA17_: ;
		{
			int T23_;
			if (!(bufSize == ((NI) 0))) goto LA21_;
			T23_ = (int)0;
			T23_ = setvbuf((*f), NIM_NIL, _IONBF, ((size_t) 0));
			(void)(T23_);
		}
		goto LA13_;
		LA21_: ;
		LA13_: ;
	}
	LA3_: ;
	}BeforeRet_: ;
	return result;
}
static N_INLINE(void, nimCopyMem)(void* dest, void* source, NI size) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memcpy(dest, source, ((size_t) (size)));
}
static N_INLINE(void, copyMem__i80o3k0SgEI5gTRCzYdyWAsystem)(void* dest, void* source, NI size) {
	nimCopyMem(dest, source, size);
}
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src) {
	{
		void* T5_;
		void* T6_;
		if (!!((src == NIM_NIL))) goto LA3_;
		T5_ = (void*)0;
		T5_ = ((void*) ((&(*dest).data[(*dest).Sup.len])));
		T6_ = (void*)0;
		T6_ = ((void*) ((*src).data));
		copyMem__i80o3k0SgEI5gTRCzYdyWAsystem(T5_, T6_, ((NI) ((NI)((*src).Sup.len + ((NI) 1)))));
		(*dest).Sup.len += (*src).Sup.len;
	}
	LA3_: ;
}
N_LIB_PRIVATE N_NOINLINE(void, raiseEIO__ZYk14k3sVNZUIjJjtqzFZQ)(NimStringDesc* msg) {
	tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw* T1_;
{	T1_ = (tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw*)0;
	T1_ = (tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw*) newObj((&NTI__HMIVdYjdZYWskTmTQVo5BQ_), sizeof(tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw));
	(*T1_).Sup.Sup.Sup.m_type = (&NTI__iLZrPn9anoh9ad1MmO0RczFw_);
	(*T1_).Sup.Sup.name = "IOError";
	(*T1_).Sup.Sup.message = copyString(msg);
	(*T1_).Sup.Sup.parent = NIM_NIL;
	raiseExceptionEx((Exception*)T1_, "IOError", "raiseEIO", "io.nim", 139);
	goto BeforeRet_;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(void, checkErr__fU6ZlJAtQ9bre04EDZLdGsA_2)(FILE* f) {
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	{
		int T3_;
		NimStringDesc* msg;
		NimStringDesc* T6_;
		NimStringDesc* T7_;
		NCSTRING T8_;
		NimStringDesc* T9_;
		T3_ = (int)0;
		T3_ = ferror(f);
		if (!!((T3_ == ((NI32) 0)))) goto LA4_;
		T6_ = (NimStringDesc*)0;
		T7_ = (NimStringDesc*)0;
		T7_ = nimIntToStr(((NI) (errno)));
		T8_ = (NCSTRING)0;
		T8_ = strerror(errno);
		T9_ = (NimStringDesc*)0;
		T9_ = cstrToNimstr(T8_);
		T6_ = rawNewString((T7_ ? T7_->Sup.len : 0) + (T9_ ? T9_->Sup.len : 0) + 10);
appendString(T6_, ((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_7));
appendString(T6_, T7_);
appendString(T6_, ((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_8));
appendString(T6_, T9_);
appendString(T6_, ((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_9));
		msg = T6_;
		clearerr(f);
		raiseEIO__ZYk14k3sVNZUIjJjtqzFZQ(msg);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	LA4_: ;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(NI, writeBuffer__Y9atVWUcVyKHG9aBP4D0P9czA)(FILE* f, void* buffer, NI len) {
	NI result;
	int T1_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NI)0;
	T1_ = (int)0;
	T1_ = fwrite(buffer, ((size_t) 1), ((size_t) (len)), f);
	result = ((NI) (T1_));
	checkErr__fU6ZlJAtQ9bre04EDZLdGsA_2(f);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, write__PArlm09bKklm2BLsCg6YtaA)(FILE* f, NimStringDesc* s) {
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	{
		void* T3_;
		NI T4_;
		T3_ = (void*)0;
		T3_ = ((void*) (nimToCStringConv(s)));
		T4_ = (NI)0;
		T4_ = writeBuffer__Y9atVWUcVyKHG9aBP4D0P9czA(f, T3_, ((NI) ((s ? s->Sup.len : 0))));
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!!((T4_ == (s ? s->Sup.len : 0)))) goto LA5_;
		raiseEIO__ZYk14k3sVNZUIjJjtqzFZQ(((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_10));
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	LA5_: ;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(void, flushFile__fU6ZlJAtQ9bre04EDZLdGsA_3)(FILE* f) {
	int T1_;
	T1_ = (int)0;
	T1_ = fflush(f);
	(void)(T1_);
}
N_LIB_PRIVATE N_NIMCALL(FILE*, open__cb1k9citqyT9a9brBSJAz8pkg)(NimStringDesc* filename, tyEnum_FileMode__ZJfK20XeZ9bv2j1pZjw9aswg mode, NI bufSize) {
	FILE* result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (FILE*)0;
	{
		NIM_BOOL T3_;
		tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw* T6_;
		NimStringDesc* T7_;
		T3_ = (NIM_BOOL)0;
		T3_ = open__gq12VLhVO0NBzUTnGgz4nw(&result, filename, mode, bufSize);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!!(T3_)) goto LA4_;
		T6_ = (tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw*)0;
		T6_ = (tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw*) newObj((&NTI__HMIVdYjdZYWskTmTQVo5BQ_), sizeof(tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw));
		(*T6_).Sup.Sup.Sup.m_type = (&NTI__iLZrPn9anoh9ad1MmO0RczFw_);
		(*T6_).Sup.Sup.name = "IOError";
		T7_ = (NimStringDesc*)0;
		T7_ = rawNewString((filename ? filename->Sup.len : 0) + 13);
appendString(T7_, ((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_11));
appendString(T7_, filename);
		(*T6_).Sup.Sup.message = T7_;
		(*T6_).Sup.Sup.parent = NIM_NIL;
		raiseExceptionEx((Exception*)T6_, "IOError", "open", "io.nim", 734);
		goto BeforeRet_;
	}
	LA4_: ;
	}BeforeRet_: ;
	return result;
}
static N_INLINE(NIM_BOOL, eqeq___aqip9cmQIuefPKdd25wuEEwsystem)(NCSTRING x, NCSTRING y) {
	NIM_BOOL result;
	result = (NIM_BOOL)0;
	{
		if (!(((void*) (x)) == ((void*) (y)))) goto LA3_;
		result = NIM_TRUE;
	}
	goto LA1_;
	LA3_: ;
	{
		NIM_BOOL T6_;
		T6_ = (NIM_BOOL)0;
		T6_ = (x == 0);
		if (T6_) goto LA7_;
		T6_ = (y == 0);
		LA7_: ;
		if (!T6_) goto LA8_;
		result = NIM_FALSE;
	}
	goto LA1_;
	LA8_: ;
	{
		int T11_;
		T11_ = (int)0;
		T11_ = strcmp(x, y);
		result = (T11_ == ((NI32) 0));
	}
	LA1_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, readLine__FbqDHP9bu7nqCh9c04dnSOxw)(FILE* f, NimStringDesc** line) {
	NIM_BOOL result;
	NI pos;
	NI sp;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NIM_BOOL)0;
	pos = ((NI) 0);
	sp = ((((*line) ? (*line)->Sup.len : 0) >= ((NI) 80)) ? ((*line) ? (*line)->Sup.len : 0) : ((NI) 80));
	(*line) = setLengthStr((*line), ((NI) (sp)));
	{
		while (1) {
			NIM_BOOL fgetsSuccess;
			void* m;
			{
				NI i;
				NI i_2;
				i = (NI)0;
				i_2 = ((NI) 0);
				{
					while (1) {
						if (!(i_2 < sp)) goto LA5;
						i = i_2;
						(*line)->data[(NI)(pos + i)] = 10;
						i_2 += ((NI) 1);
					} LA5: ;
				}
			}
			fgetsSuccess = (NIM_BOOL)0;
			{
				while (1) {
					{
						NCSTRING T9_;
						NIM_BOOL T10_;
						T9_ = (NCSTRING)0;
						T9_ = fgets(((NCSTRING) ((&(*line)->data[pos]))), ((int) (sp)), f);
						T10_ = (NIM_BOOL)0;
						T10_ = eqeq___aqip9cmQIuefPKdd25wuEEwsystem(T9_, NIM_NIL);
						fgetsSuccess = !(T10_);
						{
							if (!fgetsSuccess) goto LA13_;
							goto LA6;
						}
						LA13_: ;
						{
							if (!(errno == EINTR)) goto LA17_;
							errno = ((int) 0);
							clearerr(f);
							goto LA8;
						}
						LA17_: ;
						checkErr__fU6ZlJAtQ9bre04EDZLdGsA_2(f);
						if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
						goto LA6;
					} LA8: ;
				}
			} LA6: ;
			m = memchr(((void*) ((&(*line)->data[pos]))), ((int) 10), ((size_t) (sp)));
			{
				NI last;
				NIM_BOOL T42_;
				if (!!((m == NIM_NIL))) goto LA21_;
				last = (NI)(((NI) (ptrdiff_t) (m)) - ((NI) (ptrdiff_t) ((&(*line)->data[((NI) 0)]))));
				{
					NIM_BOOL T25_;
					NIM_BOOL T29_;
					T25_ = (NIM_BOOL)0;
					T25_ = (((NI) 0) < last);
					if (!(T25_)) goto LA26_;
					T25_ = ((NU8)((*line)->data[(NI)(last - ((NI) 1))]) == (NU8)(13));
					LA26_: ;
					if (!T25_) goto LA27_;
					(*line) = setLengthStr((*line), ((NI) ((NI)(last - ((NI) 1)))));
					T29_ = (NIM_BOOL)0;
					T29_ = (((NI) 1) < last);
					if (T29_) goto LA30_;
					T29_ = fgetsSuccess;
					LA30_: ;
					result = T29_;
					goto BeforeRet_;
				}
				goto LA23_;
				LA27_: ;
				{
					NIM_BOOL T32_;
					T32_ = (NIM_BOOL)0;
					T32_ = (((NI) 0) < last);
					if (!(T32_)) goto LA33_;
					T32_ = ((NU8)((*line)->data[(NI)(last - ((NI) 1))]) == (NU8)(0));
					LA33_: ;
					if (!T32_) goto LA34_;
					{
						NIM_BOOL T38_;
						T38_ = (NIM_BOOL)0;
						T38_ = (last < (NI)((NI)(pos + sp) - ((NI) 1)));
						if (!(T38_)) goto LA39_;
						T38_ = !(((NU8)((*line)->data[(NI)(last + ((NI) 1))]) == (NU8)(0)));
						LA39_: ;
						if (!T38_) goto LA40_;
						last -= ((NI) 1);
					}
					LA40_: ;
				}
				goto LA23_;
				LA34_: ;
				LA23_: ;
				(*line) = setLengthStr((*line), ((NI) (last)));
				T42_ = (NIM_BOOL)0;
				T42_ = (((NI) 0) < last);
				if (T42_) goto LA43_;
				T42_ = fgetsSuccess;
				LA43_: ;
				result = T42_;
				goto BeforeRet_;
			}
			goto LA19_;
			LA21_: ;
			{
				sp -= ((NI) 1);
			}
			LA19_: ;
			pos += sp;
			sp = ((NI) 128);
			(*line) = setLengthStr((*line), ((NI) ((NI)(pos + sp))));
		}
	}
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NI, readBuffer__Y9atVWUcVyKHG9aBP4D0P9czA_2)(FILE* f, void* buffer, NI len) {
	NI result;
	size_t T1_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NI)0;
	T1_ = (size_t)0;
	T1_ = fread(buffer, ((size_t) 1), ((size_t) (len)), f);
	result = ((NI) (T1_));
	{
		if (!!((result == ((NI) (len))))) goto LA4_;
		checkErr__fU6ZlJAtQ9bre04EDZLdGsA_2(f);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	LA4_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, setInheritable__avyDiy1HdQrfaD3Ql9b63EQ)(int f, NIM_BOOL inheritable) {
	NIM_BOOL result;
	int T1_;
	int T7_;
	result = (NIM_BOOL)0;
	T1_ = (int)0;
	{
		if (!inheritable) goto LA4_;
		T1_ = FIONCLEX;
	}
	goto LA2_;
	LA4_: ;
	{
		T1_ = FIOCLEX;
	}
	LA2_: ;
	T7_ = (int)0;
	T7_ = ioctl(f, T1_);
	result = !((T7_ == ((NI32) -1)));
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, open__NY67RvH2AlO9b9a83QFwNNag)(FILE** f, int filehandle, tyEnum_FileMode__ZJfK20XeZ9bv2j1pZjw9aswg mode) {
	NIM_BOOL result;
	int oshandle;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NIM_BOOL)0;
	oshandle = filehandle;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = setInheritable__avyDiy1HdQrfaD3Ql9b63EQ(oshandle, NIM_FALSE);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!!(T3_)) goto LA4_;
		result = NIM_FALSE;
		goto BeforeRet_;
	}
	LA4_: ;
	(*f) = fdopen(filehandle, nimToCStringConv(FormatOpen__iWZDMxVvD1FETfmW09b8gFQ[(mode)- 0]));
	result = !(((*f) == NIM_NIL));
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, endOfFile__FK5lmHTzEdX6epYBp9bfgMg)(FILE* f) {
	NIM_BOOL result;
	int c;
	int T1_;
{	result = (NIM_BOOL)0;
	c = fgetc(f);
	T1_ = (int)0;
	T1_ = ungetc(c, f);
	(void)(T1_);
	result = (c < ((NI32) 0));
	goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, setFilePos__FA7rp0y5drPpfGuceb3IJg)(FILE* f, NI64 pos, tyEnum_FileSeekPos__I9aQjuvWxs8BspGbxwsngWw relativeTo) {
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	{
		int T3_;
		T3_ = (int)0;
		T3_ = fseeko(f, pos, ((int) (relativeTo)));
		if (!!((T3_ == ((NI32) 0)))) goto LA4_;
		raiseEIO__ZYk14k3sVNZUIjJjtqzFZQ(((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_12));
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	LA4_: ;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(NI64, getFilePos__ihE3HyH1VBDfrPO1nZT7RQ)(FILE* f) {
	NI64 result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NI64)0;
	result = ftello(f);
	{
		if (!(result < IL64(0))) goto LA3_;
		raiseEIO__ZYk14k3sVNZUIjJjtqzFZQ(((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_13));
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	LA3_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NI64, rawFileSize__2ezUTSmBrmr5VkZNxReTYQ)(FILE* file) {
	NI64 result;
	NI64 oldPos;
	int T1_;
	int T2_;
	result = (NI64)0;
	oldPos = ftello(file);
	T1_ = (int)0;
	T1_ = fseeko(file, IL64(0), ((int) 2));
	(void)(T1_);
	result = ftello(file);
	T2_ = (int)0;
	T2_ = fseeko(file, oldPos, ((int) 0));
	(void)(T2_);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, readAllBuffer__mQf9blHFlTwuSvJjirhpY6g_2)(FILE* file) {
	NimStringDesc* result;
	NimStringDesc* buffer;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NimStringDesc*)0;
	result = ((NimStringDesc*) NIM_NIL);
	buffer = mnewString(((NI) 4000));
	{
		while (1) {
			NI bytesRead;
			bytesRead = readBuffer__Y9atVWUcVyKHG9aBP4D0P9czA_2(file, ((void*) ((&buffer->data[((NI) 0)]))), ((NI) 4000));
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			{
				if (!(bytesRead == ((NI) 4000))) goto LA5_;
				result = resizeString(result, (buffer ? buffer->Sup.len : 0) + 0);
appendString(result, buffer);
			}
			goto LA3_;
			LA5_: ;
			{
				buffer = setLengthStr(buffer, ((NI) (bytesRead)));
				result = resizeString(result, (buffer ? buffer->Sup.len : 0) + 0);
appendString(result, buffer);
				goto LA1;
			}
			LA3_: ;
		}
	} LA1: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, readAllFile__W4tKfHpbz7kHhikLsBc0EA)(FILE* file, NI64 len) {
	NimStringDesc* result;
	NI bytes;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NimStringDesc*)0;
	result = mnewString(((NI) (len)));
	bytes = readBuffer__Y9atVWUcVyKHG9aBP4D0P9czA_2(file, ((void*) ((&result->data[((NI) 0)]))), ((NI) (len)));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = endOfFile__FK5lmHTzEdX6epYBp9bfgMg(file);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!T3_) goto LA4_;
		{
			if (!(((NI64) (bytes)) < len)) goto LA8_;
			result = setLengthStr(result, ((NI) (bytes)));
		}
		LA8_: ;
	}
	goto LA1_;
	LA4_: ;
	{
		NimStringDesc* T11_;
		T11_ = (NimStringDesc*)0;
		T11_ = readAllBuffer__mQf9blHFlTwuSvJjirhpY6g_2(file);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		result = resizeString(result, (T11_ ? T11_->Sup.len : 0) + 0);
appendString(result, T11_);
	}
	LA1_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, readAll__mQf9blHFlTwuSvJjirhpY6g)(FILE* file) {
	NimStringDesc* result;
	NI64 len;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NimStringDesc*)0;
	{
		if (!!((file == stdin))) goto LA3_;
		len = rawFileSize__2ezUTSmBrmr5VkZNxReTYQ(file);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	goto LA1_;
	LA3_: ;
	{
		len = IL64(-1);
	}
	LA1_: ;
	{
		if (!(IL64(0) < len)) goto LA8_;
		result = readAllFile__W4tKfHpbz7kHhikLsBc0EA(file, len);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	goto LA6_;
	LA8_: ;
	{
		result = readAllBuffer__mQf9blHFlTwuSvJjirhpY6g_2(file);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	LA6_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, readFile__4PGnM9bWmsH0Nu7dnr3XzgA)(NimStringDesc* filename) {
	NimStringDesc* result;
	FILE* f;
NIM_BOOL oldNimErrFin6_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NimStringDesc*)0;
	f = NIM_NIL;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = open__gq12VLhVO0NBzUTnGgz4nw(&f, filename, ((tyEnum_FileMode__ZJfK20XeZ9bv2j1pZjw9aswg) 0), ((NI) -1));
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!T3_) goto LA4_;
		result = readAll__mQf9blHFlTwuSvJjirhpY6g(f);
		if (NIM_UNLIKELY(*nimErr_)) goto LA6_;
		{
			LA6_:;
		}
		{
			oldNimErrFin6_ = *nimErr_; *nimErr_ = NIM_FALSE;
			close__fU6ZlJAtQ9bre04EDZLdGsA(f);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			*nimErr_ = oldNimErrFin6_;
		}
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	goto LA1_;
	LA4_: ;
	{
		tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw* T10_;
		NimStringDesc* T11_;
		T10_ = (tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw*)0;
		T10_ = (tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw*) newObj((&NTI__HMIVdYjdZYWskTmTQVo5BQ_), sizeof(tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw));
		(*T10_).Sup.Sup.Sup.m_type = (&NTI__iLZrPn9anoh9ad1MmO0RczFw_);
		(*T10_).Sup.Sup.name = "IOError";
		T11_ = (NimStringDesc*)0;
		T11_ = rawNewString((filename ? filename->Sup.len : 0) + 13);
appendString(T11_, ((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_11));
appendString(T11_, filename);
		(*T10_).Sup.Sup.message = T11_;
		(*T10_).Sup.Sup.parent = NIM_NIL;
		raiseExceptionEx((Exception*)T10_, "IOError", "readFile", "io.nim", 842);
		goto BeforeRet_;
	}
	LA1_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NOINLINE(void, raiseEOF__CA1KPE9bDgvXVjqamZd5T9bQ)(void) {
	tyObject_EOFError__KGSY1JdrNB7Xi8KDhXFhSg* T1_;
{	T1_ = (tyObject_EOFError__KGSY1JdrNB7Xi8KDhXFhSg*)0;
	T1_ = (tyObject_EOFError__KGSY1JdrNB7Xi8KDhXFhSg*) newObj((&NTI__LEclZrWX2FQAodlapxGITw_), sizeof(tyObject_EOFError__KGSY1JdrNB7Xi8KDhXFhSg));
	(*T1_).Sup.Sup.Sup.Sup.m_type = (&NTI__KGSY1JdrNB7Xi8KDhXFhSg_);
	(*T1_).Sup.Sup.Sup.name = "EOFError";
	(*T1_).Sup.Sup.Sup.message = copyString(((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_14));
	(*T1_).Sup.Sup.Sup.parent = NIM_NIL;
	raiseExceptionEx((Exception*)T1_, "EOFError", "raiseEOF", "io.nim", 142);
	goto BeforeRet_;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, readLine__IfmAdseskhTUnfEYpOo5fA)(FILE* f) {
	NimStringDesc* result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NimStringDesc*)0;
	result = rawNewString(((NI) 80));
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = readLine__FbqDHP9bu7nqCh9c04dnSOxw(f, (&result));
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!!(T3_)) goto LA4_;
		raiseEOF__CA1KPE9bDgvXVjqamZd5T9bQ();
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	LA4_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, stdlib_ioDatInit000)(void) {

/* section: NIM_merge_TYPE_INIT1 */
static TNimNode TM__MnCJ0VAmeZ9aTATUB39cx60Q_0[1];

/* section: NIM_merge_TYPE_INIT3 */
NTI__MAWzaQJYFu3mlxj0Ppxhmw_.size = sizeof(void*);
NTI__MAWzaQJYFu3mlxj0Ppxhmw_.align = NIM_ALIGNOF(void*);
NTI__MAWzaQJYFu3mlxj0Ppxhmw_.kind = 18;
NTI__MAWzaQJYFu3mlxj0Ppxhmw_.base = 0;
NTI__MAWzaQJYFu3mlxj0Ppxhmw_.flags = 3;
NTI__MAWzaQJYFu3mlxj0Ppxhmw_.node = &TM__MnCJ0VAmeZ9aTATUB39cx60Q_0[0];
NTI__XBeRj4rw9bUuE7CB3DS1rgg_.size = sizeof(FILE*);
NTI__XBeRj4rw9bUuE7CB3DS1rgg_.align = NIM_ALIGNOF(FILE*);
NTI__XBeRj4rw9bUuE7CB3DS1rgg_.kind = 21;
NTI__XBeRj4rw9bUuE7CB3DS1rgg_.base = (&NTI__MAWzaQJYFu3mlxj0Ppxhmw_);
NTI__XBeRj4rw9bUuE7CB3DS1rgg_.flags = 3;
NTI__2gIj3gQlK3HZJjQaYCP6ZQ_.size = sizeof(int);
NTI__2gIj3gQlK3HZJjQaYCP6ZQ_.align = NIM_ALIGNOF(int);
NTI__2gIj3gQlK3HZJjQaYCP6ZQ_.kind = 34;
NTI__2gIj3gQlK3HZJjQaYCP6ZQ_.base = 0;
NTI__2gIj3gQlK3HZJjQaYCP6ZQ_.flags = 3;
}

