/* Generated by Nim Compiler v0.12.0 */
/*   (c) 2015 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 32

#include "nimbase.h"
#include <stdio.h>
#include <setjmp.h>
#include <string.h>
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Streamobj149427 Streamobj149427;
typedef struct TNimObject TNimObject;
typedef struct Filestreamobj150667 Filestreamobj150667;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Exception Exception;
typedef struct TSafePoint TSafePoint;
typedef struct Ioerror4031 Ioerror4031;
typedef struct Systemerror4029 Systemerror4029;
typedef struct Cell48947 Cell48947;
typedef struct Cellseq48963 Cellseq48963;
typedef struct Gcheap51018 Gcheap51018;
typedef struct Gcstack51016 Gcstack51016;
typedef struct Cellset48959 Cellset48959;
typedef struct Pagedesc48955 Pagedesc48955;
typedef struct Memregion30890 Memregion30890;
typedef struct Smallchunk30842 Smallchunk30842;
typedef struct Llchunk30884 Llchunk30884;
typedef struct Bigchunk30844 Bigchunk30844;
typedef struct Intset30817 Intset30817;
typedef struct Trunk30813 Trunk30813;
typedef struct Avlnode30888 Avlnode30888;
typedef struct Gcstat51014 Gcstat51014;
typedef struct Stringstreamobj150511 Stringstreamobj150511;
typedef struct Basechunk30840 Basechunk30840;
typedef struct Freecell30832 Freecell30832;
typedef N_NIMCALL_PTR(void, TY3889) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3894) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3889 marker;
TY3894 deepcopy;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  TNimObject  {
TNimType* m_type;
};
typedef N_NIMCALL_PTR(void, TY149428) (Streamobj149427* s);
typedef N_NIMCALL_PTR(NIM_BOOL, TY149432) (Streamobj149427* s);
typedef N_NIMCALL_PTR(void, TY149436) (Streamobj149427* s, NI pos);
typedef N_NIMCALL_PTR(NI, TY149441) (Streamobj149427* s);
typedef N_NIMCALL_PTR(NI, TY149445) (Streamobj149427* s, void* buffer, NI buflen);
typedef N_NIMCALL_PTR(NI, TY149451) (Streamobj149427* s, void* buffer, NI buflen);
typedef N_NIMCALL_PTR(void, TY149457) (Streamobj149427* s, void* buffer, NI buflen);
typedef N_NIMCALL_PTR(void, TY149463) (Streamobj149427* s);
struct  Streamobj149427  {
  TNimObject Sup;
TY149428 closeimpl;
TY149432 atendimpl;
TY149436 setpositionimpl;
TY149441 getpositionimpl;
TY149445 readdataimpl;
TY149451 peekdataimpl;
TY149457 writedataimpl;
TY149463 flushimpl;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Filestreamobj150667  {
  Streamobj149427 Sup;
FILE* f;
};
struct  Exception  {
  TNimObject Sup;
Exception* parent;
NCSTRING name;
NimStringDesc* message;
NimStringDesc* trace;
};
typedef struct {
N_NIMCALL_PTR(NIM_BOOL, ClPrc) (Exception* e, void* ClEnv);
void* ClEnv;
} TY19211;
struct  TSafePoint  {
TSafePoint* prev;
NI status;
jmp_buf context;
NIM_BOOL hasRaiseAction;
TY19211 raiseAction;
};
struct  Systemerror4029  {
  Exception Sup;
};
struct  Ioerror4031  {
  Systemerror4029 Sup;
};
struct  Cell48947  {
NI refcount;
TNimType* typ;
};
struct  Cellseq48963  {
NI len;
NI cap;
Cell48947** d;
};
struct  Cellset48959  {
NI counter;
NI max;
Pagedesc48955* head;
Pagedesc48955** data;
};
typedef Smallchunk30842* TY30905[512];
typedef Trunk30813* Trunkbuckets30815[256];
struct  Intset30817  {
Trunkbuckets30815 data;
};
struct  Memregion30890  {
NI minlargeobj;
NI maxlargeobj;
TY30905 freesmallchunks;
Llchunk30884* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk30844* freechunkslist;
Intset30817 chunkstarts;
Avlnode30888* root;
Avlnode30888* deleted;
Avlnode30888* last;
Avlnode30888* freeavlnodes;
};
struct  Gcstat51014  {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct  Gcheap51018  {
Gcstack51016* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq48963 zct;
Cellseq48963 decstack;
Cellset48959 cycleroots;
Cellseq48963 tempstack;
NI recgclock;
Memregion30890 region;
Gcstat51014 stat;
};
struct  Stringstreamobj150511  {
  Streamobj149427 Sup;
NimStringDesc* data;
NI pos;
};
struct  Gcstack51016  {
Gcstack51016* prev;
Gcstack51016* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY30821[16];
struct  Pagedesc48955  {
Pagedesc48955* next;
NI key;
TY30821 bits;
};
struct  Basechunk30840  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk30842  {
  Basechunk30840 Sup;
Smallchunk30842* next;
Smallchunk30842* prev;
Freecell30832* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk30884  {
NI size;
NI acc;
Llchunk30884* next;
};
struct  Bigchunk30844  {
  Basechunk30840 Sup;
Bigchunk30844* next;
Bigchunk30844* prev;
NI align;
NF data;
};
struct  Trunk30813  {
Trunk30813* next;
NI key;
TY30821 bits;
};
typedef Avlnode30888* TY30895[2];
struct  Avlnode30888  {
TY30895 link;
NI key;
NI upperbound;
NI level;
};
struct  Freecell30832  {
Freecell30832* next;
NI zerofield;
};
N_NIMCALL(void, TMP2792)(void* p, NI op);
N_NIMCALL(NIM_BOOL, open_16803)(FILE** f, NimStringDesc* filename, NU8 mode, NI bufsize);
N_NIMCALL(Filestreamobj150667*, newfilestream_150743)(FILE* f);
N_NIMCALL(void, TMP2793)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
N_NIMCALL(void, fsclose_150671)(Streamobj149427* s);
N_NIMCALL(NIM_BOOL, fsatend_150695)(Streamobj149427* s);
N_NIMCALL(NIM_BOOL, endoffile_16860)(FILE* f);
N_NIMCALL(void, fssetposition_150702)(Streamobj149427* s, NI pos);
N_NIMCALL(void, setfilepos_16987)(FILE* f, NI64 pos);
N_NIMCALL(NI, fsgetposition_150709)(Streamobj149427* s);
N_NIMCALL(NI64, getfilepos_16991)(FILE* f);
N_NIMCALL(NI, fsreaddata_150716)(Streamobj149427* s, void* buffer, NI buflen);
N_NIMCALL(NI, readbuffer_16960)(FILE* f, void* buffer, NI len);
N_NIMCALL(NI, fspeekdata_150725)(Streamobj149427* s, void* buffer, NI buflen);
static N_INLINE(void, pushSafePoint)(TSafePoint* s);
static N_INLINE(void, popSafePoint)(void);
N_NIMCALL(void, reraiseException)(void);
N_NIMCALL(void, fswritedata_150735)(Streamobj149427* s, void* buffer, NI buflen);
N_NIMCALL(NI, writebuffer_16982)(FILE* f, void* buffer, NI len);
N_NIMCALL(Ioerror4031*, neweio_149405)(NimStringDesc* msg);
N_NIMCALL(NimStringDesc*, copyStringRC1)(NimStringDesc* src);
static N_INLINE(void, nimGCunrefNoCycle)(void* p);
static N_INLINE(Cell48947*, usrtocell_52646)(void* usr);
static N_INLINE(void, rtladdzct_54204)(Cell48947* c);
N_NOINLINE(void, addzct_52617)(Cellseq48963* s, Cell48947* c);
N_NIMCALL(void, raiseException)(Exception* e, NCSTRING ename);
N_NIMCALL(void, fsflush_150689)(Streamobj149427* s);
N_NIMCALL(void, writedata_149648)(Streamobj149427* s, void* buffer, NI buflen);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(NIM_CHAR, readchar_149784)(Streamobj149427* s);
N_NIMCALL(NI, readdata_149580)(Streamobj149427* s, void* buffer, NI buflen);
N_NIMCALL(NimStringDesc*, addChar)(NimStringDesc* s, NIM_CHAR c);
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP3061)(void* p, NI op);
N_NIMCALL(void, ssclose_150636)(Streamobj149427* s_150638);
N_NIMCALL(NIM_BOOL, ssatend_150522)(Streamobj149427* s_150524);
N_NIMCALL(void, sssetposition_150533)(Streamobj149427* s_150535, NI pos);
N_NIMCALL(NI, clamp_150539)(NI x, NI a, NI b);
N_NIMCALL(NI, ssgetposition_150558)(Streamobj149427* s_150560);
N_NIMCALL(NI, ssreaddata_150569)(Streamobj149427* s_150571, void* buffer, NI buflen);
N_NIMCALL(NI, sspeekdata_150596)(Streamobj149427* s_150598, void* buffer, NI buflen);
N_NIMCALL(void, sswritedata_150614)(Streamobj149427* s_150616, void* buffer, NI buflen);
N_NIMCALL(NimStringDesc*, setLengthStr)(NimStringDesc* s, NI newlen);
N_NIMCALL(NimStringDesc*, mnewString)(NI len);
N_NIMCALL(NimStringDesc*, mnewString)(NI len);
STRING_LITERAL(TMP2797, "cannot write to stream", 22);
STRING_LITERAL(TMP3017, "", 0);
extern TNimType NTI4011; /* RootObj */
TNimType NTI149427; /* StreamObj */
TNimType NTI149428; /* proc (s: Stream){.gcsafe.} */
TNimType NTI149432; /* proc (s: Stream): bool{.gcsafe.} */
TNimType NTI149436; /* proc (s: Stream, pos: int){.gcsafe.} */
TNimType NTI149441; /* proc (s: Stream): int{.gcsafe.} */
TNimType NTI149445; /* proc (s: Stream, buffer: pointer, bufLen: int): int{.gcsafe.} */
TNimType NTI149451; /* proc (s: Stream, buffer: pointer, bufLen: int): int{.gcsafe.} */
TNimType NTI149457; /* proc (s: Stream, buffer: pointer, bufLen: int){.gcsafe.} */
TNimType NTI149463; /* proc (s: Stream){.gcsafe.} */
TNimType NTI149425; /* Stream */
TNimType NTI150667; /* FileStreamObj */
extern TNimType NTI16404; /* File */
TNimType NTI150665; /* FileStream */
extern TSafePoint* exchandler_20843;
extern TNimType NTI82817; /* ref IOError */
extern TNimType NTI4031; /* IOError */
extern Gcheap51018 gch_51059;
TNimType NTI150511; /* StringStreamObj */
extern TNimType NTI149; /* string */
extern TNimType NTI108; /* int */
TNimType NTI150509; /* StringStream */
N_NIMCALL(void, TMP2792)(void* p, NI op) {
	Streamobj149427* a;
	a = (Streamobj149427*)p;
}

N_NIMCALL(NI, readdata_149580)(Streamobj149427* s, void* buffer, NI buflen) {
	NI result;
	result = 0;
	result = (*s).readdataimpl(s, buffer, buflen);
	return result;
}
N_NIMCALL(void, TMP2793)(void* p, NI op) {
	Filestreamobj150667* a;
	a = (Filestreamobj150667*)p;
}

N_NIMCALL(void, fsclose_150671)(Streamobj149427* s) {
	{
		if (!!(((*((Filestreamobj150667*) (s))).f == NIM_NIL))) goto LA3;
		fclose((*((Filestreamobj150667*) (s))).f);
		(*((Filestreamobj150667*) (s))).f = NIM_NIL;
	}
	LA3: ;
}

N_NIMCALL(NIM_BOOL, fsatend_150695)(Streamobj149427* s) {
	NIM_BOOL result;
{	result = 0;
	result = endoffile_16860((*((Filestreamobj150667*) (s))).f);
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(void, fssetposition_150702)(Streamobj149427* s, NI pos) {
	setfilepos_16987((*((Filestreamobj150667*) (s))).f, ((NI64) (pos)));
}

N_NIMCALL(NI, fsgetposition_150709)(Streamobj149427* s) {
	NI result;
	NI64 LOC1;
{	result = 0;
	LOC1 = 0;
	LOC1 = getfilepos_16991((*((Filestreamobj150667*) (s))).f);
	result = ((NI) (LOC1));
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NI, fsreaddata_150716)(Streamobj149427* s, void* buffer, NI buflen) {
	NI result;
	result = 0;
	result = readbuffer_16960((*((Filestreamobj150667*) (s))).f, buffer, ((NI) (buflen)));
	return result;
}

static N_INLINE(void, pushSafePoint)(TSafePoint* s) {
	(*s).hasRaiseAction = NIM_FALSE;
	(*s).prev = exchandler_20843;
	exchandler_20843 = s;
}

static N_INLINE(void, popSafePoint)(void) {
	exchandler_20843 = (*exchandler_20843).prev;
}

N_NIMCALL(NI, fspeekdata_150725)(Streamobj149427* s, void* buffer, NI buflen) {
	NI volatile result;
	NI pos;
	TSafePoint TMP2796;
	result = 0;
	pos = fsgetposition_150709(s);
	pushSafePoint(&TMP2796);
	TMP2796.status = _setjmp(TMP2796.context);
	if (TMP2796.status == 0) {
		result = readbuffer_16960((*((Filestreamobj150667*) (s))).f, buffer, ((NI) (buflen)));
		popSafePoint();
	}
	else {
		popSafePoint();
	}
	{
		fssetposition_150702(s, pos);
	}
	if (TMP2796.status != 0) reraiseException();
	return result;
}

static N_INLINE(Cell48947*, usrtocell_52646)(void* usr) {
	Cell48947* result;
	result = 0;
	result = ((Cell48947*) ((NI)((NU32)(((NI) (usr))) - (NU32)(((NI)sizeof(Cell48947))))));
	return result;
}

static N_INLINE(void, rtladdzct_54204)(Cell48947* c) {
	addzct_52617((&gch_51059.zct), c);
}

static N_INLINE(void, nimGCunrefNoCycle)(void* p) {
	Cell48947* c;
	c = usrtocell_52646(p);
	{
		(*c).refcount -= ((NI) 8);
		if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA3;
		rtladdzct_54204(c);
	}
	LA3: ;
}

N_NIMCALL(Ioerror4031*, neweio_149405)(NimStringDesc* msg) {
	Ioerror4031* result;
	NimStringDesc* LOC1;
	result = 0;
	result = (Ioerror4031*) newObj((&NTI82817), sizeof(Ioerror4031));
	(*result).Sup.Sup.Sup.m_type = (&NTI4031);
	LOC1 = 0;
	LOC1 = (*result).Sup.Sup.message; (*result).Sup.Sup.message = copyStringRC1(msg);
	if (LOC1) nimGCunrefNoCycle(LOC1);
	return result;
}

N_NIMCALL(void, fswritedata_150735)(Streamobj149427* s, void* buffer, NI buflen) {
	{
		NI LOC3;
		Ioerror4031* LOC6;
		LOC3 = 0;
		LOC3 = writebuffer_16982((*((Filestreamobj150667*) (s))).f, buffer, ((NI) (buflen)));
		if (!!((LOC3 == buflen))) goto LA4;
		LOC6 = 0;
		LOC6 = neweio_149405(((NimStringDesc*) &TMP2797));
		raiseException((Exception*)LOC6, "IOError");
	}
	LA4: ;
}

N_NIMCALL(void, fsflush_150689)(Streamobj149427* s) {
	fflush((*((Filestreamobj150667*) (s))).f);
}

N_NIMCALL(Filestreamobj150667*, newfilestream_150743)(FILE* f) {
	Filestreamobj150667* result;
	result = 0;
	result = (Filestreamobj150667*) newObj((&NTI150665), sizeof(Filestreamobj150667));
	(*result).Sup.Sup.m_type = (&NTI150667);
	(*result).f = f;
	(*result).Sup.closeimpl = fsclose_150671;
	(*result).Sup.atendimpl = fsatend_150695;
	(*result).Sup.setpositionimpl = fssetposition_150702;
	(*result).Sup.getpositionimpl = fsgetposition_150709;
	(*result).Sup.readdataimpl = fsreaddata_150716;
	(*result).Sup.peekdataimpl = fspeekdata_150725;
	(*result).Sup.writedataimpl = fswritedata_150735;
	(*result).Sup.flushimpl = fsflush_150689;
	return result;
}

N_NIMCALL(Filestreamobj150667*, newfilestream_150758)(NimStringDesc* filename, NU8 mode) {
	Filestreamobj150667* result;
	FILE* f;
	result = 0;
	f = 0;
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = open_16803(&f, filename, mode, ((NI) -1));
		if (!LOC3) goto LA4;
		result = newfilestream_150743(f);
	}
	LA4: ;
	return result;
}

N_NIMCALL(void, close_149491)(Streamobj149427* s) {
	{
		if (!!((*s).closeimpl == 0)) goto LA3;
		(*s).closeimpl(s);
	}
	LA3: ;
}

N_NIMCALL(void, writedata_149648)(Streamobj149427* s, void* buffer, NI buflen) {
	(*s).writedataimpl(s, buffer, buflen);
}

N_NIMCALL(void, write_149683)(Streamobj149427* s, NimStringDesc* x) {
	writedata_149648(s, ((void*) (x->data)), (x ? x->Sup.len : 0));
}

N_NIMCALL(NIM_BOOL, atend_149517)(Streamobj149427* s) {
	NIM_BOOL result;
	result = 0;
	result = (*s).atendimpl(s);
	return result;
}

N_NIMCALL(NIM_CHAR, readchar_149784)(Streamobj149427* s) {
	NIM_CHAR result;
	result = 0;
	{
		NI LOC3;
		LOC3 = 0;
		LOC3 = readdata_149580(s, ((void*) ((&result))), ((NI) 1));
		if (!!((LOC3 == ((NI) 1)))) goto LA4;
		result = 0;
	}
	LA4: ;
	return result;
}

N_NIMCALL(NimStringDesc*, readline_150477)(Streamobj149427* s) {
	NimStringDesc* result;
	result = 0;
	result = copyString(((NimStringDesc*) &TMP3017));
	{
		while (1) {
			NIM_CHAR c;
			c = readchar_149784(s);
			{
				if (!((NU8)(c) == (NU8)(13))) goto LA5;
				c = readchar_149784(s);
				goto LA1;
			}
			LA5: ;
			{
				NIM_BOOL LOC9;
				LOC9 = 0;
				LOC9 = ((NU8)(c) == (NU8)(10));
				if (LOC9) goto LA10;
				LOC9 = ((NU8)(c) == (NU8)(0));
				LA10: ;
				if (!LOC9) goto LA11;
				goto LA1;
			}
			goto LA7;
			LA11: ;
			{
				result = addChar(result, c);
			}
			LA7: ;
		}
	} LA1: ;
	return result;
}
N_NIMCALL(void, TMP3061)(void* p, NI op) {
	Stringstreamobj150511* a;
	a = (Stringstreamobj150511*)p;
	nimGCvisit((void*)(*a).data, op);
}

N_NIMCALL(void, ssclose_150636)(Streamobj149427* s_150638) {
	Stringstreamobj150511* s;
	NimStringDesc* LOC1;
	s = ((Stringstreamobj150511*) (s_150638));
	LOC1 = 0;
	LOC1 = (*s).data; (*s).data = copyStringRC1(NIM_NIL);
	if (LOC1) nimGCunrefNoCycle(LOC1);
}

N_NIMCALL(NIM_BOOL, ssatend_150522)(Streamobj149427* s_150524) {
	NIM_BOOL result;
	Stringstreamobj150511* s;
{	result = 0;
	s = ((Stringstreamobj150511*) (s_150524));
	result = (((*s).data ? (*s).data->Sup.len : 0) <= (*s).pos);
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(void, sssetposition_150533)(Streamobj149427* s_150535, NI pos) {
	Stringstreamobj150511* s;
	s = ((Stringstreamobj150511*) (s_150535));
	(*s).pos = clamp_150539(pos, ((NI) 0), ((*s).data ? (*s).data->Sup.len : 0));
}

N_NIMCALL(NI, ssgetposition_150558)(Streamobj149427* s_150560) {
	NI result;
	Stringstreamobj150511* s;
{	result = 0;
	s = ((Stringstreamobj150511*) (s_150560));
	result = (*s).pos;
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NI, ssreaddata_150569)(Streamobj149427* s_150571, void* buffer, NI buflen) {
	NI result;
	Stringstreamobj150511* s;
	result = 0;
	s = ((Stringstreamobj150511*) (s_150571));
	result = ((buflen <= (NI)(((*s).data ? (*s).data->Sup.len : 0) - (*s).pos)) ? buflen : (NI)(((*s).data ? (*s).data->Sup.len : 0) - (*s).pos));
	{
		if (!(((NI) 0) < result)) goto LA3;
		memcpy(buffer, ((void*) ((&(*s).data->data[(*s).pos]))), ((NI) (result)));
		(*s).pos += result;
	}
	LA3: ;
	return result;
}

N_NIMCALL(NI, sspeekdata_150596)(Streamobj149427* s_150598, void* buffer, NI buflen) {
	NI result;
	Stringstreamobj150511* s;
	result = 0;
	s = ((Stringstreamobj150511*) (s_150598));
	result = ((buflen <= (NI)(((*s).data ? (*s).data->Sup.len : 0) - (*s).pos)) ? buflen : (NI)(((*s).data ? (*s).data->Sup.len : 0) - (*s).pos));
	{
		if (!(((NI) 0) < result)) goto LA3;
		memcpy(buffer, ((void*) ((&(*s).data->data[(*s).pos]))), ((NI) (result)));
	}
	LA3: ;
	return result;
}

N_NIMCALL(void, sswritedata_150614)(Streamobj149427* s_150616, void* buffer, NI buflen) {
	Stringstreamobj150511* s;
{	s = ((Stringstreamobj150511*) (s_150616));
	{
		if (!(buflen <= ((NI) 0))) goto LA3;
		goto BeforeRet;
	}
	LA3: ;
	{
		if (!(((*s).data ? (*s).data->Sup.len : 0) < (NI)((*s).pos + buflen))) goto LA7;
		(*s).data = setLengthStr((*s).data, ((NI) ((NI)((*s).pos + buflen))));
	}
	LA7: ;
	memcpy(((void*) ((&(*s).data->data[(*s).pos]))), buffer, ((NI) (buflen)));
	(*s).pos += buflen;
	}BeforeRet: ;
}

N_NIMCALL(Stringstreamobj150511*, newstringstream_150646)(NimStringDesc* s) {
	Stringstreamobj150511* result;
	NimStringDesc* LOC1;
	result = 0;
	result = (Stringstreamobj150511*) newObj((&NTI150509), sizeof(Stringstreamobj150511));
	(*result).Sup.Sup.m_type = (&NTI150511);
	LOC1 = 0;
	LOC1 = (*result).data; (*result).data = copyStringRC1(s);
	if (LOC1) nimGCunrefNoCycle(LOC1);
	(*result).pos = ((NI) 0);
	(*result).Sup.closeimpl = ssclose_150636;
	(*result).Sup.atendimpl = ssatend_150522;
	(*result).Sup.setpositionimpl = sssetposition_150533;
	(*result).Sup.getpositionimpl = ssgetposition_150558;
	(*result).Sup.readdataimpl = ssreaddata_150569;
	(*result).Sup.peekdataimpl = sspeekdata_150596;
	(*result).Sup.writedataimpl = sswritedata_150614;
	return result;
}

N_NIMCALL(NimStringDesc*, readall_149592)(Streamobj149427* s) {
	NimStringDesc* result;
	NI r;
	result = 0;
	result = mnewString(((NI) 1000));
	r = ((NI) 0);
	{
		while (1) {
			NI readbytes;
			readbytes = readdata_149580(s, ((void*) ((&result->data[r]))), ((NI) 1000));
			{
				if (!(readbytes < ((NI) 1000))) goto LA5;
				result = setLengthStr(result, ((NI) ((NI)(r + readbytes))));
				goto LA1;
			}
			LA5: ;
			r += ((NI) 1000);
			result = setLengthStr(result, ((NI) ((NI)(r + ((NI) 1000)))));
		}
	} LA1: ;
	return result;
}
NIM_EXTERNC N_NOINLINE(void, stdlib_streamsInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, stdlib_streamsDatInit000)(void) {
static TNimNode* TMP2791[8];
static TNimNode* TMP3060[2];
static TNimNode TMP33[13];
NTI149427.size = sizeof(Streamobj149427);
NTI149427.kind = 17;
NTI149427.base = (&NTI4011);
NTI149427.flags = 1;
TMP2791[0] = &TMP33[1];
NTI149428.size = sizeof(TY149428);
NTI149428.kind = 25;
NTI149428.base = 0;
NTI149428.flags = 3;
TMP33[1].kind = 1;
TMP33[1].offset = offsetof(Streamobj149427, closeimpl);
TMP33[1].typ = (&NTI149428);
TMP33[1].name = "closeImpl";
TMP2791[1] = &TMP33[2];
NTI149432.size = sizeof(TY149432);
NTI149432.kind = 25;
NTI149432.base = 0;
NTI149432.flags = 3;
TMP33[2].kind = 1;
TMP33[2].offset = offsetof(Streamobj149427, atendimpl);
TMP33[2].typ = (&NTI149432);
TMP33[2].name = "atEndImpl";
TMP2791[2] = &TMP33[3];
NTI149436.size = sizeof(TY149436);
NTI149436.kind = 25;
NTI149436.base = 0;
NTI149436.flags = 3;
TMP33[3].kind = 1;
TMP33[3].offset = offsetof(Streamobj149427, setpositionimpl);
TMP33[3].typ = (&NTI149436);
TMP33[3].name = "setPositionImpl";
TMP2791[3] = &TMP33[4];
NTI149441.size = sizeof(TY149441);
NTI149441.kind = 25;
NTI149441.base = 0;
NTI149441.flags = 3;
TMP33[4].kind = 1;
TMP33[4].offset = offsetof(Streamobj149427, getpositionimpl);
TMP33[4].typ = (&NTI149441);
TMP33[4].name = "getPositionImpl";
TMP2791[4] = &TMP33[5];
NTI149445.size = sizeof(TY149445);
NTI149445.kind = 25;
NTI149445.base = 0;
NTI149445.flags = 3;
TMP33[5].kind = 1;
TMP33[5].offset = offsetof(Streamobj149427, readdataimpl);
TMP33[5].typ = (&NTI149445);
TMP33[5].name = "readDataImpl";
TMP2791[5] = &TMP33[6];
NTI149451.size = sizeof(TY149451);
NTI149451.kind = 25;
NTI149451.base = 0;
NTI149451.flags = 3;
TMP33[6].kind = 1;
TMP33[6].offset = offsetof(Streamobj149427, peekdataimpl);
TMP33[6].typ = (&NTI149451);
TMP33[6].name = "peekDataImpl";
TMP2791[6] = &TMP33[7];
NTI149457.size = sizeof(TY149457);
NTI149457.kind = 25;
NTI149457.base = 0;
NTI149457.flags = 3;
TMP33[7].kind = 1;
TMP33[7].offset = offsetof(Streamobj149427, writedataimpl);
TMP33[7].typ = (&NTI149457);
TMP33[7].name = "writeDataImpl";
TMP2791[7] = &TMP33[8];
NTI149463.size = sizeof(TY149463);
NTI149463.kind = 25;
NTI149463.base = 0;
NTI149463.flags = 3;
TMP33[8].kind = 1;
TMP33[8].offset = offsetof(Streamobj149427, flushimpl);
TMP33[8].typ = (&NTI149463);
TMP33[8].name = "flushImpl";
TMP33[0].len = 8; TMP33[0].kind = 2; TMP33[0].sons = &TMP2791[0];
NTI149427.node = &TMP33[0];
NTI149425.size = sizeof(Streamobj149427*);
NTI149425.kind = 22;
NTI149425.base = (&NTI149427);
NTI149425.marker = TMP2792;
NTI150667.size = sizeof(Filestreamobj150667);
NTI150667.kind = 17;
NTI150667.base = (&NTI149427);
NTI150667.flags = 1;
TMP33[9].kind = 1;
TMP33[9].offset = offsetof(Filestreamobj150667, f);
TMP33[9].typ = (&NTI16404);
TMP33[9].name = "f";
NTI150667.node = &TMP33[9];
NTI150665.size = sizeof(Filestreamobj150667*);
NTI150665.kind = 22;
NTI150665.base = (&NTI150667);
NTI150665.marker = TMP2793;
NTI150511.size = sizeof(Stringstreamobj150511);
NTI150511.kind = 17;
NTI150511.base = (&NTI149427);
TMP3060[0] = &TMP33[11];
TMP33[11].kind = 1;
TMP33[11].offset = offsetof(Stringstreamobj150511, data);
TMP33[11].typ = (&NTI149);
TMP33[11].name = "data";
TMP3060[1] = &TMP33[12];
TMP33[12].kind = 1;
TMP33[12].offset = offsetof(Stringstreamobj150511, pos);
TMP33[12].typ = (&NTI108);
TMP33[12].name = "pos";
TMP33[10].len = 2; TMP33[10].kind = 2; TMP33[10].sons = &TMP3060[0];
NTI150511.node = &TMP33[10];
NTI150509.size = sizeof(Stringstreamobj150511*);
NTI150509.kind = 22;
NTI150509.base = (&NTI150511);
NTI150509.marker = TMP3061;
}

